From a6f6614344f47abdc11cfeb55a16df3a4cbf75e6 Mon Sep 17 00:00:00 2001 From: pythcoiner Date: Mon, 16 Dec 2024 09:43:23 +0100 Subject: [PATCH] gui: allow user to not validate the ssl domain for an electrum server --- liana-gui/src/app/state/settings/bitcoind.rs | 8 +++++++ liana-gui/src/app/view/message.rs | 1 + liana-gui/src/app/view/settings.rs | 14 ++++++++++++- liana-gui/src/installer/message.rs | 1 + liana-gui/src/installer/step/node/electrum.rs | 21 ++++++++++++++++--- liana-gui/src/installer/view/mod.rs | 21 +++++++++++++++++-- liana-gui/src/node/electrum.rs | 3 +-- 7 files changed, 61 insertions(+), 8 deletions(-) diff --git a/liana-gui/src/app/state/settings/bitcoind.rs b/liana-gui/src/app/state/settings/bitcoind.rs index 9be01bb50..9a4610932 100644 --- a/liana-gui/src/app/state/settings/bitcoind.rs +++ b/liana-gui/src/app/state/settings/bitcoind.rs @@ -323,6 +323,7 @@ impl BitcoindSettings { } } } + view::SettingsEditMessage::ValidateDomainEdited(_) => {} view::SettingsEditMessage::BitcoindRpcAuthTypeSelected(auth_type) => { if !self.processing { self.selected_auth_type = auth_type; @@ -461,6 +462,7 @@ impl ElectrumSettings { daemon_config.bitcoin_backend = Some(lianad::config::BitcoinBackend::Electrum(ElectrumConfig { addr: self.addr.value.clone(), + validate_domain: self.electrum_config.validate_domain, })); self.processing = true; return Command::perform(async move { daemon_config }, |cfg| { @@ -468,6 +470,11 @@ impl ElectrumSettings { }); } } + view::SettingsEditMessage::ValidateDomainEdited(b) => { + if !self.processing { + self.electrum_config.validate_domain = b; + } + } _ => {} }; Command::none() @@ -482,6 +489,7 @@ impl ElectrumSettings { cache.blockheight, &self.addr, self.processing, + self.electrum_config.validate_domain, ) } else { view::settings::electrum( diff --git a/liana-gui/src/app/view/message.rs b/liana-gui/src/app/view/message.rs index c726b5fc5..9fc12bbab 100644 --- a/liana-gui/src/app/view/message.rs +++ b/liana-gui/src/app/view/message.rs @@ -88,6 +88,7 @@ pub enum RemoteBackendSettingsMessage { pub enum SettingsEditMessage { Select, FieldEdited(&'static str, String), + ValidateDomainEdited(bool), BitcoindRpcAuthTypeSelected(RpcAuthType), Cancel, Confirm, diff --git a/liana-gui/src/app/view/settings.rs b/liana-gui/src/app/view/settings.rs index 72d986e05..5da93d323 100644 --- a/liana-gui/src/app/view/settings.rs +++ b/liana-gui/src/app/view/settings.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use iced::{ alignment, - widget::{radio, scrollable, tooltip as iced_tooltip, Space}, + widget::{checkbox, radio, scrollable, tooltip as iced_tooltip, Space}, Alignment, Length, }; @@ -551,6 +551,7 @@ pub fn electrum_edit<'a>( blockheight: i32, addr: &form::Value, processing: bool, + validate_domain: bool, ) -> Element<'a, SettingsEditMessage> { let mut col = Column::new().spacing(20); if is_configured_node_type && blockheight != 0 { @@ -583,6 +584,16 @@ pub fn electrum_edit<'a>( .push(separation().width(Length::Fill)); } + let checkbox = checkbox( + "Do not validate SSL Domain(check this only if you want to use a self-signed certificate)", + !validate_domain, + ) + .on_toggle(|b| SettingsEditMessage::ValidateDomainEdited(!b)); + let checkbox = if addr.valid && addr.value.contains("ssl://") { + Some(checkbox) + } else { + None + }; col = col.push( Column::new() .push(text("Address:").bold().small()) @@ -594,6 +605,7 @@ pub fn electrum_edit<'a>( .size(P1_SIZE) .padding(5), ) + .push_maybe(checkbox) .push(text(electrum::ADDRESS_NOTES).size(P2_SIZE)) .spacing(5), ); diff --git a/liana-gui/src/installer/message.rs b/liana-gui/src/installer/message.rs index 96f5acd15..3d093f933 100644 --- a/liana-gui/src/installer/message.rs +++ b/liana-gui/src/installer/message.rs @@ -81,6 +81,7 @@ pub enum DefineBitcoind { #[derive(Debug, Clone)] pub enum DefineElectrum { ConfigFieldEdited(electrum::ConfigField, String), + ValidDomainChanged(bool), } #[derive(Debug, Clone)] diff --git a/liana-gui/src/installer/step/node/electrum.rs b/liana-gui/src/installer/step/node/electrum.rs index f594e6a22..5aeb8bf9d 100644 --- a/liana-gui/src/installer/step/node/electrum.rs +++ b/liana-gui/src/installer/step/node/electrum.rs @@ -14,9 +14,19 @@ use crate::{ node::electrum::ConfigField, }; -#[derive(Clone, Default)] +#[derive(Clone)] pub struct DefineElectrum { address: form::Value, + validate_domain: bool, +} + +impl Default for DefineElectrum { + fn default() -> Self { + Self { + address: Default::default(), + validate_domain: true, + } + } } impl DefineElectrum { @@ -38,6 +48,7 @@ impl DefineElectrum { crate::node::electrum::is_electrum_address_valid(&value); } }, + message::DefineElectrum::ValidDomainChanged(v) => self.validate_domain = v, }; }; Command::none() @@ -47,6 +58,7 @@ impl DefineElectrum { if self.can_try_ping() { ctx.bitcoin_backend = Some(lianad::config::BitcoinBackend::Electrum(ElectrumConfig { addr: self.address.value.clone(), + validate_domain: self.validate_domain, })); return true; } @@ -54,12 +66,15 @@ impl DefineElectrum { } pub fn view(&self) -> Element { - view::define_electrum(&self.address) + view::define_electrum(&self.address, self.validate_domain) } pub fn ping(&self) -> Result<(), Error> { let builder = electrum_client::Config::builder(); - let config = builder.timeout(Some(3)).build(); + let config = builder + .timeout(Some(3)) + .validate_domain(self.validate_domain) + .build(); let client = electrum_client::Client::from_config(&self.address.value, config) .map_err(|e| Error::Electrum(e.to_string()))?; client diff --git a/liana-gui/src/installer/view/mod.rs b/liana-gui/src/installer/view/mod.rs index acd3b7d79..b7e1d4662 100644 --- a/liana-gui/src/installer/view/mod.rs +++ b/liana-gui/src/installer/view/mod.rs @@ -1134,7 +1134,19 @@ pub fn define_bitcoind<'a>( .into() } -pub fn define_electrum<'a>(address: &form::Value) -> Element<'a, Message> { +pub fn define_electrum<'a>( + address: &form::Value, + validate_domain: bool, +) -> Element<'a, Message> { + let checkbox = checkbox( + "Do not validate SSL Domain(check this only if you want to use a self-signed certificate)", + !validate_domain, + ) + .on_toggle(|b| { + Message::DefineNode(DefineNode::DefineElectrum( + message::DefineElectrum::ValidDomainChanged(!b), + )) + }); let col_address = Column::new() .push(text("Address:").bold()) .push( @@ -1150,7 +1162,12 @@ pub fn define_electrum<'a>(address: &form::Value) -> Element<'a, Message .size(text::P1_SIZE) .padding(10), ) - .push(text(electrum::ADDRESS_NOTES).size(text::P2_SIZE)) + .push_maybe(if address.valid && (address.value.contains("ssl://")) { + Some(checkbox) + } else { + None + }) + .push(text(electrum::ADDRESS_NOTES)) .spacing(10); Column::new().push(col_address).spacing(50).into() diff --git a/liana-gui/src/node/electrum.rs b/liana-gui/src/node/electrum.rs index 89886f9ab..8c6acfe19 100644 --- a/liana-gui/src/node/electrum.rs +++ b/liana-gui/src/node/electrum.rs @@ -6,8 +6,7 @@ pub enum ConfigField { } pub const ADDRESS_NOTES: &str = "Note: include \"ssl://\" as a prefix \ - for SSL connections. Be aware that self-signed \ - SSL certificates are currently not supported."; + for SSL connections."; impl fmt::Display for ConfigField { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {