Skip to content

Commit 1372898

Browse files
committed
Merge #171: Install rustls's CryptoProvider based on features
f244582 Install `rustls`'s `CryptoProvider` based on features (Elias Rohrer) Pull request description: 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. (cc @oleonardolima @thunderbiscuit) ACKs for top commit: ValuedMammal: ACK f244582 oleonardolima: ACK f244582 Tree-SHA512: b502b97e4162c0dd46e17ccf1c0a0a8461158dbec06833d7d8715072fa4feeb87beb3ee2dd93c594689ef0c2ecd84ed52a4f9309d826bebb95f3c9e57dd933fb
2 parents 7de4cb7 + f244582 commit 1372898

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/raw_client.rs

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

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

411434
let config = if validate_domain {

0 commit comments

Comments
 (0)