Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bdk_electrum = { version = "0.24.0", default-features = false, features = ["use-
bdk_wallet = { version = "3.2.0", default-features = false, features = ["std", "keys-bip39"]}

bitreq = { version = "0.3", default-features = false, features = ["async-https", "json-using-serde"] }
rustls = { version = "0.23", default-features = false }
rustls = { version = "0.23", default-features = false, features = ["ring"] }
# rusqlite 0.40.0 and 0.40.1 do not compile on our MSRV.
rusqlite = { version = ">=0.31.0, <0.40.0", features = ["bundled"], optional = true }
bitcoin = "0.32.7"
Expand Down
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,7 @@ fn build_with_store_internal(
})
}

fn optionally_install_rustls_cryptoprovider() {
pub(crate) fn optionally_install_rustls_cryptoprovider() {
// 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();
Expand Down
5 changes: 5 additions & 0 deletions src/io/vss_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use vss_client::util::retry::{
};
use vss_client::util::storable_builder::{EntropySource, StorableBuilder};

use crate::builder::optionally_install_rustls_cryptoprovider;
use crate::entropy::NodeEntropy;
use crate::io::utils::check_namespace_key_validity;
use crate::lnurl_auth::LNURL_AUTH_HARDENED_CHILD_INDEX;
Expand Down Expand Up @@ -99,6 +100,10 @@ impl VssStore {
base_url: String, store_id: String, vss_seed: [u8; 32],
header_provider: Arc<dyn VssHeaderProvider>,
) -> io::Result<Self> {
// Setting up the store already issues requests to the VSS server, which requires a
// `CryptoProvider` to be available for TLS connections.
optionally_install_rustls_cryptoprovider();

let next_version = AtomicU64::new(1);
let internal_runtime =
Arc::new(StoreRuntime::new("ldk-node-vss-runtime", INTERNAL_RUNTIME_WORKERS, "VSS")?);
Expand Down
58 changes: 58 additions & 0 deletions tests/vss_crypto_provider_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(feature = "storage-vss")]

use std::collections::HashMap;
use std::io::{Read, Write};
use std::net::TcpListener;

use ldk_node::entropy::NodeEntropy;
use ldk_node::Builder;

// This needs to remain the only test in this file: the `CryptoProvider` default is process-global,
// so any other test building a `Node` in the same process would install it for us.
#[test]
fn crypto_provider_is_installed_before_vss_store_setup() {
assert!(rustls::crypto::CryptoProvider::get_default().is_none());

// Serve a single response with an unsupported protocol version, which makes the VSS store
// setup fail without retrying.
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let vss_url = format!("http://{}", listener.local_addr().unwrap());
let server = std::thread::spawn(move || {
let (mut stream, _) = listener.accept().unwrap();
let mut request = Vec::new();
while !request.windows(4).any(|w| w == b"\r\n\r\n") {
let mut buffer = [0; 1024];
let bytes_read = stream.read(&mut buffer).unwrap();
assert!(bytes_read > 0, "HTTP request ended before its headers");
request.extend_from_slice(&buffer[..bytes_read]);
}
let response =
"HTTP/1.1 200 OK\r\ncontent-length: 0\r\nvss-protocol-version: 999\r\nconnection: close\r\n\r\n";
stream.write_all(response.as_bytes()).unwrap();
});

#[cfg(not(feature = "uniffi"))]
let node_entropy = NodeEntropy::from_seed_bytes([42u8; 64]);
Comment thread
tnull marked this conversation as resolved.
Resolved
#[cfg(feature = "uniffi")]
let node_entropy = std::sync::Arc::new(NodeEntropy::from_seed_bytes(vec![42u8; 64]).unwrap());
let res = Builder::new().build_with_vss_store_and_fixed_headers(
node_entropy,
vss_url,
"store_id".to_owned(),
HashMap::new(),
);
assert!(res.is_err());
server.join().unwrap();

assert!(
rustls::crypto::CryptoProvider::get_default().is_some(),
"The CryptoProvider must be installed before the VSS store makes its first request"
);
}
Loading