Skip to content

Add a SOCKS5 proxy option to the Electrum client - #199

Open
zebra-nerd wants to merge 3 commits into
Blockstream:masterfrom
zebra-nerd:electrum-socks5
Open

zebra-nerd wants to merge 3 commits into
Blockstream:masterfrom
zebra-nerd:electrum-socks5

Conversation

@zebra-nerd

Copy link
Copy Markdown

The Electrum client cannot be told to use a SOCKS5 proxy, so an application that sends its wallet traffic through Tor has to wrap the whole process (torsocks) or put a relay in front of the server. electrum-client already supports SOCKS5 and its proxy feature is already enabled in lwk_wollet; the builder just never passes a proxy on.

This adds ElectrumClientBuilder::socks5() in lwk_wollet and the matching optional socks5 field on the bindings' ElectrumClientBuilder record:

let client = ElectrumClientBuilder::new("tcp://example.onion:50001")
    .socks5("127.0.0.1:9050")
    .build()?;
builder = ElectrumClientBuilder(url="tcp://example.onion:50001", socks5="127.0.0.1:9050")
client = ElectrumClient.from_builder(builder)
  • The proxy is given as host:port, as electrum_client::Socks5Config::new takes it.
  • The server host is sent to the proxy as a domain name and resolved there, so .onion urls work and no DNS query for the server is made locally. A unit test in lwk_wollet and the Python example pin this against a local listener that reads the CONNECT request and refuses it; neither needs the network.
  • No new dependency and no new feature flag.

Not in this PR:

  • Esplora and Waterfalls. That needs reqwest's socks feature and a cfg for wasm, where a proxy cannot be set. I can send it separately if this direction is fine.
  • Proxy credentials (Socks5Config::with_credentials, which Tor uses for stream isolation). The builder derives Debug, so that would need a redacting impl first.
  • TokenProvider::Blockstream: the OAuth2 token is still fetched over a direct HTTPS connection. This is stated in the doc comment of socks5() and in the docs page.
  • lwk_cli and lwk_wasm (the Electrum client is not built for wasm).

This supersedes #60, which added the option to ElectrumOptions, deprecated since.

Checked locally: cargo fmt --check, cargo test -p lwk_wollet --lib (142 passed), and the new Python example against a release build of the bindings. cargo clippy --all-targets -- -D warnings was run with a newer toolchain than the pinned one (1.99.1), where it only reports lints in files this PR does not touch.

The Electrum client could not be told to use a SOCKS5 proxy, so an
application sending its wallet traffic through Tor had to wrap the
whole process or put a relay in front of the server. electrum-client
supports SOCKS5 and its `proxy` feature is already enabled here; the
builder never passed a proxy on.

- Add `ElectrumClientBuilder::socks5()`, taking the proxy as
  `host:port`.
- The server host goes to the proxy as a domain name and is resolved
  there, so `.onion` urls work and no local DNS query is made. A unit
  test pins this against a local listener.
Expose the SOCKS5 proxy option of the Electrum client builder, so the
foreign languages can connect through a proxy such as Tor.

- Add the optional `socks5` field to the `ElectrumClientBuilder`
  record.
- Add a Python example that runs offline against a local listener and
  checks the proxy is handed the server host name.
- Add a "SOCKS5 proxy" section to the Electrum client page.
- List the new Python example.

This branch has not been deployed

No deployments
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.

1 participant