Skip to content

Commit ca4702a

Browse files
committed
raw_client: Use rustls crypto provider based on features
Potential solution to bitcoindevkit#171 that uses the default crypto provider based on the enabled features, but does not call `install_default`.
1 parent 7de4cb7 commit ca4702a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/raw_client.rs

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

409-
let builder = ClientConfig::builder();
409+
#[cfg(feature = "use-rustls")]
410+
use rustls::crypto::aws_lc_rs as crypto_provider;
411+
#[cfg(feature = "use-rustls-ring")]
412+
use rustls::crypto::ring as crypto_provider;
413+
414+
let builder =
415+
ClientConfig::builder_with_provider(Arc::new(crypto_provider::default_provider()))
416+
.with_safe_default_protocol_versions()
417+
.map_err(Error::CouldNotCreateConnection)?;
410418

411419
let config = if validate_domain {
412420
socket_addr.domain().ok_or(Error::MissingDomain)?;
@@ -426,10 +434,7 @@ impl RawClient<ElectrumSslStream> {
426434
builder
427435
.dangerous()
428436
.with_custom_certificate_verifier(std::sync::Arc::new(
429-
#[cfg(feature = "use-rustls")]
430-
danger::NoCertificateVerification::new(rustls::crypto::aws_lc_rs::default_provider()),
431-
#[cfg(feature = "use-rustls-ring")]
432-
danger::NoCertificateVerification::new(rustls::crypto::ring::default_provider()),
437+
danger::NoCertificateVerification::new(crypto_provider::default_provider()),
433438
))
434439
.with_no_client_auth()
435440
};

0 commit comments

Comments
 (0)