Skip to content

Commit 41c5228

Browse files
committed
Install rustls's CryptoProvider based on features
Previously, we'd already assume `use-rustls` to use the default `aws-lc-rs` provider and `use-rustls-ring` to use the `ring` `CryptoProvider`, e.g., for `NoCertificateVerification`. However, we **wouldn't** actually install the respective provider based on the features, leading to a **reachable** panic at runtime when user tried to access `ssl://` Electrum servers. Here, we fix this omission and install the default provider according to the configured features.
1 parent 7de4cb7 commit 41c5228

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/raw_client.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,25 @@ impl RawClient<ElectrumSslStream> {
406406
) -> Result<Self, Error> {
407407
use std::convert::TryFrom;
408408

409+
// We install a crypto provider depending on the set feature.
410+
#[cfg(feature = "use-rustls")]
411+
rustls::crypto::CryptoProvider::install_default(
412+
rustls::crypto::aws_lc_rs::default_provider(),
413+
)
414+
.map_err(|_| {
415+
Error::CouldNotCreateConnection(rustls::Error::General(
416+
"Failed to install CryptoProvider".to_string(),
417+
))
418+
})?;
419+
420+
#[cfg(feature = "use-rustls-ring")]
421+
rustls::crypto::CryptoProvider::install_default(rustls::crypto::ring::default_provider())
422+
.map_err(|_| {
423+
Error::CouldNotCreateConnection(rustls::Error::General(
424+
"Failed to install CryptoProvider".to_string(),
425+
))
426+
})?;
427+
409428
let builder = ClientConfig::builder();
410429

411430
let config = if validate_domain {

0 commit comments

Comments
 (0)