Skip to content

Commit 3de8b1d

Browse files
authored
Merge pull request #601 from tnull/2025-08-fix-rustls-crypto-provider-main
Ensure we always startup with a `rustls` `CryptoProvider` (main)
2 parents a147ad0 + 1d06c7a commit 3de8b1d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ bdk_electrum = { version = "0.23.0", default-features = false, features = ["use-
6767
bdk_wallet = { version = "2.0.0", default-features = false, features = ["std", "keys-bip39"]}
6868

6969
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
70+
rustls = { version = "0.23", default-features = false }
7071
rusqlite = { version = "0.31.0", features = ["bundled"] }
7172
bitcoin = "0.32.4"
7273
bip39 = "2.0.0"

src/builder.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use std::fmt;
7575
use std::fs;
7676
use std::path::PathBuf;
7777
use std::sync::atomic::AtomicBool;
78-
use std::sync::{Arc, Mutex, RwLock};
78+
use std::sync::{Arc, Mutex, Once, RwLock};
7979
use std::time::SystemTime;
8080
use vss_client::headers::{FixedHeaders, LnurlAuthToJwtProvider, VssHeaderProvider};
8181

@@ -1051,6 +1051,8 @@ fn build_with_store_internal(
10511051
liquidity_source_config: Option<&LiquiditySourceConfig>, seed_bytes: [u8; 64],
10521052
logger: Arc<Logger>, kv_store: Arc<DynStore>,
10531053
) -> Result<Node, BuildError> {
1054+
optionally_install_rustls_cryptoprovider();
1055+
10541056
if let Err(err) = may_announce_channel(&config) {
10551057
if config.announcement_addresses.is_some() {
10561058
log_error!(logger, "Announcement addresses were set but some required configuration options for node announcement are missing: {}", err);
@@ -1663,6 +1665,25 @@ fn build_with_store_internal(
16631665
})
16641666
}
16651667

1668+
fn optionally_install_rustls_cryptoprovider() {
1669+
// Acquire a global Mutex, ensuring that only one process at a time install the provider. This
1670+
// is mostly required for running tests concurrently.
1671+
static INIT_CRYPTO: Once = Once::new();
1672+
1673+
INIT_CRYPTO.call_once(|| {
1674+
// Ensure we always install a `CryptoProvider` for `rustls` if it was somehow not previously installed by now.
1675+
if rustls::crypto::CryptoProvider::get_default().is_none() {
1676+
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
1677+
}
1678+
1679+
// Refuse to startup without TLS support. Better to catch it now than even later at runtime.
1680+
assert!(
1681+
rustls::crypto::CryptoProvider::get_default().is_some(),
1682+
"We need to have a CryptoProvider"
1683+
);
1684+
});
1685+
}
1686+
16661687
/// Sets up the node logger.
16671688
fn setup_logger(
16681689
log_writer_config: &Option<LogWriterConfig>, config: &Config,

0 commit comments

Comments
 (0)