Skip to content

wollet: configure Electrum domain validation - #3

Closed
ethicnology-agent wants to merge 3 commits into
SatoshiPortal:masterfrom
ethicnology-agent:fix/electrum-keep-validate-domain
Closed

ethicnology-agent wants to merge 3 commits into
SatoshiPortal:masterfrom
ethicnology-agent:fix/electrum-keep-validate-domain

Conversation

@ethicnology-agent

@ethicnology-agent ethicnology-agent commented Nov 5, 2026 •

Copy link
Copy Markdown

Motivation

Users who run their own Electrum node often serve TLS with a self-signed certificate, or reach the node by IP address on a LAN or VPN. ElectrumClientBuilder, the Electrum interface since 0.19.0, has no way to connect to such a server: the certificate is always verified, and an ssl:// url with an IP host is rejected with SslWithoutDomain.

The older path is broken too. Since 0.19.0, ElectrumClient::new() and ElectrumClient::with_options() rebuild the client from the string form of the ElectrumUrl, which cannot carry the domain validation flag. An ElectrumUrl built with ElectrumUrl::new(host, true, false), the documented way to use TLS without validating the domain, is validated anyway, and the same url on an IP host fails with SslWithoutDomain. The UniFFI ElectrumClient(url, tls, validate_domain) constructor drops validate_domain = false the same way, since bindings 0.19.0.

The validate_domain part of Blockstream#60 asked for the same on the previous ElectrumOptions; this does it on the builder instead.

API

  • lwk_wollet: ElectrumClientBuilder::validate_domain(bool), true by default. The flag is applied while the url is parsed, so ssl://<ip>:<port> is accepted only when it is false, and it is passed to electrum-client for TLS. tcp:// urls ignore it. ElectrumUrl::from_str stays strict, ElectrumUrl::new() and ElectrumOptions are unchanged, and there is no new public conversion from ElectrumUrl.
  • lwk_wollet: ElectrumClient::new() and with_options() pass the ElectrumUrl::Tls flag to the builder again. ElectrumUrl::build_client() already did.
  • lwk_bindings: ElectrumClientBuilder gets a last field validate_domain: bool, default true, so existing callers are unaffected. The ElectrumClient(url, tls, validate_domain) constructor passes its flag, which also applies to the builder kept for clone_client. ElectrumClient.from_url() keeps validating. Its tls=false, validate_domain=true error is unchanged. Nothing changes for wasm, which has no Electrum client.

No breaking change: the Rust additions are a new builder method and private fields, and the bindings field is appended with a default.

Security note

With the rustls backend used by lwk_wollet, validate_domain(false) does not only skip matching the certificate against the host name: electrum-client installs NoCertificateVerification, so the server certificate is not verified at all. The connection stays encrypted but the server is not authenticated, so anyone able to intercept the connection can impersonate the server and see or alter the requests and their answers. A token from token_provider is sent to whoever answers and can then be captured. validate_domain(false) does not relax the refusal to send a token over tcp://, which still needs allow_plaintext_with_token(true). The docs of the method and of the bindings field say this.

Tests

  • lwk_wollet unit test electrum_tls_domain_validation_flag, no network: ssl://127.0.0.1:1 is rejected with SslWithoutDomain by default; with validate_domain(false) the builder, ElectrumClient::new() and with_options() accept the url and fail on the connection (nothing listens on port 1), not on the url. On the previous code the two constructors return SslWithoutDomain.

Verified on 2026-11-05 on Linux: cargo test -p lwk_wollet --lib electrum_tls_domain_validation_flag, cargo clippy --all-targets -- -D warnings on lwk_wollet and lwk_bindings, cargo fmt --check. The source commits were also checked with rustdoc (-D warnings --cfg docsrs) and the CI wasm check of lwk_wollet before the test was reduced.

Review guide

Base: SatoshiPortal/lwk master 70b3aa03 (2026-11-05), which is Blockstream/lwk master 32201840 plus the signer commits of Blockstream#196; these four commits touch only lwk_wollet and lwk_bindings and apply unchanged on 32201840. Cargo.lock is unchanged.

Commit Kind Lines
8bc6cecd wollet: configure Electrum domain validation source: builder method, url parsing, constructors, docs, changelog +64/−24
886a593c wollet: test Electrum domain validation flag test: one unit test, no fixture, no new dependency +32
bd4ffc2e bindings: expose Electrum domain validation source: record field, constructor, changelog +10/−2

Read the two source commits closely; the test commit can be skimmed.

@ethicnology-agent

Copy link
Copy Markdown
Author

@ethicnology ready for your review.

- ElectrumClientBuilder had no way to skip the TLS certificate
  validation, so a server with a self-signed certificate or reached by
  IP address (e.g. a personal node on a LAN) could not be used over
  TLS. Add ElectrumClientBuilder::validate_domain(), true by default.
- The flag is applied while parsing the url: an ssl:// url with an IP
  host is only rejected when the domain is validated.
  ElectrumUrl::from_str stays strict.
- Since 0.19.0, ElectrumClient::new() and with_options() rebuild the
  client from the url's string form, which drops the flag of an
  ElectrumUrl built with ElectrumUrl::new(host, true, false): the
  domain is validated anyway, and an IP host fails with
  SslWithoutDomain. They now pass the flag to the builder.
- With rustls, false disables the server certificate verification
  entirely, so the server is not authenticated; the docs say so and
  that a token can then be intercepted. It does not relax the refusal
  to send a token over plaintext.
@ethicnology-agent
ethicnology-agent force-pushed the fix/electrum-keep-validate-domain branch from 75e2864 to 0075397 Compare November 5, 2026 19:32
@ethicnology-agent ethicnology-agent changed the title wollet: keep the electrum domain validation flag wollet: configure Electrum domain validation Nov 5, 2026
@ethicnology-agent
ethicnology-agent force-pushed the fix/electrum-keep-validate-domain branch from 0075397 to 5d1b262 Compare November 5, 2026 19:33
- A TLS url on an IP host is refused by default.
- With validate_domain(false) it passes url parsing and the client
  tries to connect, through the builder and the deprecated
  constructors, which lost the flag since 0.19.0.
- No server is needed: nothing listens on 127.0.0.1:1, so a
  connection error instead of a url error proves the flag is kept.
- Foreign languages could not use an Electrum server with a
  self-signed certificate or reached by IP address over TLS. Add a
  validate_domain field to the ElectrumClientBuilder record, true by
  default so existing callers keep validating, and pass it to the
  builder.
- Since 0.19.0, the ElectrumClient(url, tls, validate_domain)
  constructor dropped validate_domain=false: it built its builder from
  the url's string form. It now passes the flag, which also applies to
  the builder kept to recreate the client in clone_client.
- from_url keeps validating the domain.
@ethicnology-agent
ethicnology-agent force-pushed the fix/electrum-keep-validate-domain branch from 5d1b262 to bd4ffc2 Compare November 5, 2026 19:37
@ethicnology

Copy link
Copy Markdown
Member

Nobody (to my knowledge) self-host liquid electrum server

@ethicnology ethicnology closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants