Skip to content

Commit c7566e6

Browse files
authored
fix(sui-http): use explicit rustls::CryptoProvider (#25106) (#25147)
If multiple crypto-provider related features are enabled on `rustls`, it will panic because it doesn't know how to pick a default one. We should not rely on the default, choosing instead fo pick an explicit provider. CI --- Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] gRPC: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] Indexing Framework: ## Description Describe the changes or additions included in this PR. ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] gRPC: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] Indexing Framework:
1 parent 7eb553b commit c7566e6

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

crates/sui-http/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ impl Builder {
7272

7373
let certs = CertificateDer::pem_file_iter(cert_file)?.collect::<Result<_, _>>()?;
7474
let private_key = PrivateKeyDer::from_pem_file(private_key_file)?;
75-
let tls_config = rustls::ServerConfig::builder()
76-
.with_no_client_auth()
77-
.with_single_cert(certs, private_key)?;
75+
let tls_config = rustls::ServerConfig::builder_with_provider(Arc::new(
76+
rustls::crypto::ring::default_provider(),
77+
))
78+
.with_protocol_versions(rustls::DEFAULT_VERSIONS)?
79+
.with_no_client_auth()
80+
.with_single_cert(certs, private_key)?;
7881

7982
Ok(self.tls_config(tls_config))
8083
}

crates/sui-types/src/multisig_legacy.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ impl TryFrom<MultiSigPublicKeyLegacy> for MultiSigPublicKey {
150150

151151
/// Convert a roaring bitmap to plain bitmap.
152152
pub fn bitmap_to_u16(roaring: RoaringBitmap) -> Result<u16, FastCryptoError> {
153-
let indices: Vec<u32> = roaring.into_iter().collect();
154153
let mut val = 0;
155-
for i in indices {
154+
for i in roaring {
156155
if i >= 10 {
157156
return Err(FastCryptoError::InvalidInput);
158157
}

crates/sui-types/src/sui_serde.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use serde_with::{Bytes, DeserializeAs, SerializeAs};
2121

2222
use sui_protocol_config::ProtocolVersion;
2323

24+
use crate::governance::MAX_VALIDATOR_COUNT;
2425
use crate::{
2526
DEEPBOOK_ADDRESS, SUI_CLOCK_ADDRESS, SUI_FRAMEWORK_ADDRESS, SUI_SYSTEM_ADDRESS,
2627
SUI_SYSTEM_STATE_ADDRESS, parse_sui_struct_tag, parse_sui_type_tag,
@@ -343,6 +344,19 @@ impl<'de> DeserializeAs<'de, roaring::RoaringBitmap> for SuiBitmap {
343344
// So this function is needed to sanitize the bitmap to ensure unique entries.
344345
pub(crate) fn deserialize_sui_bitmap(bytes: &[u8]) -> std::io::Result<roaring::RoaringBitmap> {
345346
let orig_bitmap = roaring::RoaringBitmap::deserialize_from(bytes)?;
347+
348+
// Check cardinality before iteration.
349+
if orig_bitmap.len() > MAX_VALIDATOR_COUNT {
350+
return Err(std::io::Error::new(
351+
std::io::ErrorKind::InvalidData,
352+
format!(
353+
"bitmap cardinality {} exceeds max {}",
354+
orig_bitmap.len(),
355+
MAX_VALIDATOR_COUNT
356+
),
357+
));
358+
}
359+
346360
// Ensure there is no duplicated entries in the bitmap.
347361
let mut seen = std::collections::BTreeSet::new();
348362
let mut new_bitmap = roaring::RoaringBitmap::new();

0 commit comments

Comments
 (0)