Skip to content

Ensure we always startup with a rustls CryptoProvider #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ bdk_electrum = { version = "0.23.0", default-features = false, features = ["use-
bdk_wallet = { version = "2.0.0", default-features = false, features = ["std", "keys-bip39"]}

reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
rustls = { version = "0.23", default-features = false }
rusqlite = { version = "0.31.0", features = ["bundled"] }
bitcoin = "0.32.4"
bip39 = "2.0.0"
Expand Down
23 changes: 22 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ use std::fmt;
use std::fs;
use std::path::PathBuf;
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex, RwLock};
use std::sync::{Arc, Mutex, Once, RwLock};
use std::time::SystemTime;
use vss_client::headers::{FixedHeaders, LnurlAuthToJwtProvider, VssHeaderProvider};

Expand Down Expand Up @@ -936,6 +936,8 @@ fn build_with_store_internal(
liquidity_source_config: Option<&LiquiditySourceConfig>, seed_bytes: [u8; 64],
logger: Arc<Logger>, kv_store: Arc<DynStore>,
) -> Result<Node, BuildError> {
optionally_install_rustls_cryptoprovider();

if let Err(err) = may_announce_channel(&config) {
if config.announcement_addresses.is_some() {
log_error!(logger, "Announcement addresses were set but some required configuration options for node announcement are missing: {}", err);
Expand Down Expand Up @@ -1525,6 +1527,25 @@ fn build_with_store_internal(
})
}

fn optionally_install_rustls_cryptoprovider() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add doc when this can be removed again (when a newer version of rust-electrum-client is used)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh, given how messy this is, we might keep it in for a while longer just to be sure no user ever again panics at runtime because of this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is in the rust electrum client, is this still possible? Assuming rustls is messy, then still if we makes sure to install either in ldk-node or in rust-electrum-client, than we are equally good?

// Acquire a global Mutex, ensuring that only one process at a time install the provider. This
// is mostly required for running tests concurrently.
static INIT_CRYPTO: Once = Once::new();

INIT_CRYPTO.call_once(|| {
// Ensure we always install a `CryptoProvider` for `rustls` if it was somehow not previously installed by now.
if rustls::crypto::CryptoProvider::get_default().is_none() {
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
}

// Refuse to startup without TLS support. Better to catch it now than even later at runtime.
assert!(
rustls::crypto::CryptoProvider::get_default().is_some(),
"We need to have a CryptoProvider"
);
});
}

/// Sets up the node logger.
fn setup_logger(
log_writer_config: &Option<LogWriterConfig>, config: &Config,
Expand Down
Loading