Skip to content

Commit

Permalink
gui: allow user to not validate the ssl domain for an electrum server
Browse files Browse the repository at this point in the history
  • Loading branch information
pythcoiner committed Dec 20, 2024
1 parent bcc07be commit a6f6614
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 8 deletions.
8 changes: 8 additions & 0 deletions liana-gui/src/app/state/settings/bitcoind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ impl BitcoindSettings {
}
}
}
view::SettingsEditMessage::ValidateDomainEdited(_) => {}
view::SettingsEditMessage::BitcoindRpcAuthTypeSelected(auth_type) => {
if !self.processing {
self.selected_auth_type = auth_type;
Expand Down Expand Up @@ -461,13 +462,19 @@ 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| {
Message::LoadDaemonConfig(Box::new(cfg))
});
}
}
view::SettingsEditMessage::ValidateDomainEdited(b) => {
if !self.processing {
self.electrum_config.validate_domain = b;
}
}
_ => {}
};
Command::none()
Expand All @@ -482,6 +489,7 @@ impl ElectrumSettings {
cache.blockheight,
&self.addr,
self.processing,
self.electrum_config.validate_domain,
)
} else {
view::settings::electrum(
Expand Down
1 change: 1 addition & 0 deletions liana-gui/src/app/view/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub enum RemoteBackendSettingsMessage {
pub enum SettingsEditMessage {
Select,
FieldEdited(&'static str, String),
ValidateDomainEdited(bool),
BitcoindRpcAuthTypeSelected(RpcAuthType),
Cancel,
Confirm,
Expand Down
14 changes: 13 additions & 1 deletion liana-gui/src/app/view/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -551,6 +551,7 @@ pub fn electrum_edit<'a>(
blockheight: i32,
addr: &form::Value<String>,
processing: bool,
validate_domain: bool,
) -> Element<'a, SettingsEditMessage> {
let mut col = Column::new().spacing(20);
if is_configured_node_type && blockheight != 0 {
Expand Down Expand Up @@ -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())
Expand All @@ -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),
);
Expand Down
1 change: 1 addition & 0 deletions liana-gui/src/installer/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub enum DefineBitcoind {
#[derive(Debug, Clone)]
pub enum DefineElectrum {
ConfigFieldEdited(electrum::ConfigField, String),
ValidDomainChanged(bool),
}

#[derive(Debug, Clone)]
Expand Down
21 changes: 18 additions & 3 deletions liana-gui/src/installer/step/node/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ use crate::{
node::electrum::ConfigField,
};

#[derive(Clone, Default)]
#[derive(Clone)]
pub struct DefineElectrum {
address: form::Value<String>,
validate_domain: bool,
}

impl Default for DefineElectrum {
fn default() -> Self {
Self {
address: Default::default(),
validate_domain: true,
}
}
}

impl DefineElectrum {
Expand All @@ -38,6 +48,7 @@ impl DefineElectrum {
crate::node::electrum::is_electrum_address_valid(&value);
}
},
message::DefineElectrum::ValidDomainChanged(v) => self.validate_domain = v,
};
};
Command::none()
Expand All @@ -47,19 +58,23 @@ 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;
}
false
}

pub fn view(&self) -> Element<Message> {
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
Expand Down
21 changes: 19 additions & 2 deletions liana-gui/src/installer/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,19 @@ pub fn define_bitcoind<'a>(
.into()
}

pub fn define_electrum<'a>(address: &form::Value<String>) -> Element<'a, Message> {
pub fn define_electrum<'a>(
address: &form::Value<String>,
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(
Expand All @@ -1150,7 +1162,12 @@ pub fn define_electrum<'a>(address: &form::Value<String>) -> 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()
Expand Down
3 changes: 1 addition & 2 deletions liana-gui/src/node/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a6f6614

Please sign in to comment.