lianad(electrum): add an option to not validate SSL domain in order to work w/ self signed certificates

This commit is contained in:
pythcoiner 2024-12-16 09:42:10 +01:00
parent ecce76ab3f
commit efb23300da
4 changed files with 85 additions and 11 deletions

65
Cargo.lock generated
View File

@ -965,7 +965,7 @@ dependencies = [
"bitflags 1.3.2",
"core-foundation 0.9.4",
"core-graphics-types 0.1.3",
"foreign-types",
"foreign-types 0.5.0",
"libc",
]
@ -978,7 +978,7 @@ dependencies = [
"bitflags 2.6.0",
"core-foundation 0.10.0",
"core-graphics-types 0.2.0",
"foreign-types",
"foreign-types 0.5.0",
"libc",
]
@ -1359,6 +1359,7 @@ dependencies = [
"byteorder",
"libc",
"log",
"openssl",
"rustls",
"serde",
"serde_json",
@ -1598,6 +1599,15 @@ dependencies = [
"ttf-parser 0.19.2",
]
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared 0.1.1",
]
[[package]]
name = "foreign-types"
version = "0.5.0"
@ -1605,7 +1615,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
dependencies = [
"foreign-types-macros",
"foreign-types-shared",
"foreign-types-shared 0.3.1",
]
[[package]]
@ -1619,6 +1629,12 @@ dependencies = [
"syn 2.0.87",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "foreign-types-shared"
version = "0.3.1"
@ -2872,6 +2888,7 @@ dependencies = [
"backtrace",
"bdk_electrum",
"dirs 5.0.1",
"electrum-client",
"fern",
"jsonrpc 0.17.0",
"liana",
@ -3123,7 +3140,7 @@ dependencies = [
"bitflags 2.6.0",
"block",
"core-graphics-types 0.1.3",
"foreign-types",
"foreign-types 0.5.0",
"log",
"objc",
"paste",
@ -3535,6 +3552,44 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "openssl"
version = "0.10.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5"
dependencies = [
"bitflags 2.6.0",
"cfg-if",
"foreign-types 0.3.2",
"libc",
"once_cell",
"openssl-macros",
"openssl-sys",
]
[[package]]
name = "openssl-macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.87",
]
[[package]]
name = "openssl-sys"
version = "0.9.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "option-ext"
version = "0.2.0"
@ -4789,7 +4844,7 @@ dependencies = [
"core-graphics 0.24.0",
"drm",
"fastrand",
"foreign-types",
"foreign-types 0.5.0",
"js-sys",
"log",
"memmap2 0.9.5",

View File

@ -28,6 +28,7 @@ miniscript = { version = "11.0", features = ["serde", "compiler", "base64"] }
# For Electrum backend. This is the latest version with the same bitcoin version as
# the miniscript dependency.
bdk_electrum = { version = "0.14" }
electrum-client = { version = "0.19", features = ["use-openssl"] }
# Don't reinvent the wheel
dirs = "5.0"

View File

@ -7,10 +7,11 @@ use bdk_electrum::{
spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult},
BlockId, ChainPosition, ConfirmationHeightAnchor, TxGraph,
},
electrum_client::{self, Config, ElectrumApi},
ElectrumExt,
};
use electrum_client::{self, Config, ElectrumApi};
use super::utils::{
block_id_from_tip, height_i32_from_usize, height_usize_from_i32, outpoints_from_tx,
};
@ -56,9 +57,13 @@ impl Client {
/// Create a new client and perform sanity checks.
pub fn new(electrum_config: &config::ElectrumConfig) -> Result<Self, Error> {
// First use a dummy config to check connectivity (no retries, short timeout).
let dummy_config = Config::builder().retry(0).timeout(Some(3)).build();
let dummy_config = Config::builder()
.retry(0)
.validate_domain(electrum_config.validate_domain)
.timeout(Some(3))
.build();
// Try to ping the server.
bdk_electrum::electrum_client::Client::from_config(&electrum_config.addr, dummy_config)
electrum_client::Client::from_config(&electrum_config.addr, dummy_config)
.and_then(|dummy_client| dummy_client.ping())
.map_err(Error::Server)?;
@ -66,10 +71,10 @@ impl Client {
let config = Config::builder()
.retry(RETRY_LIMIT)
.timeout(Some(RPC_SOCKET_TIMEOUT))
.validate_domain(electrum_config.validate_domain)
.build();
let client =
bdk_electrum::electrum_client::Client::from_config(&electrum_config.addr, config)
.map_err(Error::Server)?;
let client = electrum_client::Client::from_config(&electrum_config.addr, config)
.map_err(Error::Server)?;
Ok(Self(client))
}

View File

@ -128,6 +128,19 @@ pub struct ElectrumConfig {
/// Include "ssl://" for SSL. otherwise TCP will be assumed.
/// Can optionally prefix with "tcp://".
pub addr: String,
/// If validate_domain == false, domain of ssl certificate will not be validated
/// (useful to allow usage of self signed certificates on local network)
#[serde(default)]
pub validate_domain: bool,
}
impl Default for ElectrumConfig {
fn default() -> Self {
Self {
addr: Default::default(),
validate_domain: true,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]