refactor: rename trustAllCerts → usePinnedTrustStore

The field no longer means 'trust all certificates' — since the Samsung
One UI 7 fix, it means 'use the pinned trust store (hardcoded +
TOFU-pinned certs + system CAs) instead of system-only trust.'

The old name was actively misleading and could cause a future
contributor to interpret the flag literally, potentially reintroducing
the trust-all pattern that Samsung Knox and GrapheneOS reject.

Renamed across all 4 files:
- ElectrumxServer.kt: field definition + updated KDoc
- ElectrumXClient.kt: createSocket() usage + comments
- NamecoinSettings.kt: parseServerString() usage + comments
- NamecoinSettingsTest.kt: test assertions
This commit is contained in:
M
2026-03-26 06:33:43 +11:00
parent 7f451ee7c7
commit 2e02edc333
4 changed files with 27 additions and 27 deletions
@@ -44,8 +44,14 @@ data class ElectrumxServer(
val host: String,
val port: Int,
val useSsl: Boolean = true,
/** If true, accept any certificate (self-signed, expired, etc.) */
val trustAllCerts: Boolean = false,
/**
* If true, use the pinned trust store (hardcoded + TOFU-pinned certs
* plus system CAs) instead of the default system-only trust store.
*
* Required for ElectrumX servers that use self-signed certificates,
* which is the norm for the Namecoin ElectrumX ecosystem.
*/
val usePinnedTrustStore: Boolean = false,
)
/**
@@ -90,9 +96,9 @@ data class ServerTestResult(
/** Well-known public Namecoin ElectrumX servers (clearnet). */
val DEFAULT_ELECTRUMX_SERVERS =
listOf(
ElectrumxServer("electrumx.testls.space", 50002, useSsl = true, trustAllCerts = true),
ElectrumxServer("nmc2.bitcoins.sk", 57002, useSsl = true, trustAllCerts = true),
ElectrumxServer("46.229.238.187", 57002, useSsl = true, trustAllCerts = true),
ElectrumxServer("electrumx.testls.space", 50002, useSsl = true, usePinnedTrustStore = true),
ElectrumxServer("nmc2.bitcoins.sk", 57002, useSsl = true, usePinnedTrustStore = true),
ElectrumxServer("46.229.238.187", 57002, useSsl = true, usePinnedTrustStore = true),
)
/** Tor-preferred server list: onion primary, clearnet fallback. */
@@ -102,8 +108,8 @@ val TOR_ELECTRUMX_SERVERS =
"i665jpwsq46zlsdbnj4axgzd3s56uzey5uhotsnxzsknzbn36jaddsid.onion",
50002,
useSsl = true,
trustAllCerts = true,
usePinnedTrustStore = true,
),
ElectrumxServer("electrumx.testls.space", 50002, useSsl = true, trustAllCerts = true),
ElectrumxServer("nmc2.bitcoins.sk", 57002, useSsl = true, trustAllCerts = true),
ElectrumxServer("electrumx.testls.space", 50002, useSsl = true, usePinnedTrustStore = true),
ElectrumxServer("nmc2.bitcoins.sk", 57002, useSsl = true, usePinnedTrustStore = true),
)
@@ -601,14 +601,10 @@ class ElectrumXClient(
if (!server.useSsl) return baseSocket
// Upgrade to TLS over the already-connected (possibly proxied) socket.
// When the server uses a self-signed certificate (trustAllCerts flag),
// we use a pinned trust store that contains the known ElectrumX server
// certs. This is required because Samsung One UI 7 (Android 16) silently
// rejects connections that use a no-op "trust-all" X509TrustManager.
//
// Exception: .onion addresses bypass cert pinning entirely — the Tor
// hidden service protocol already provides end-to-end authentication
// via the onion address, making TLS cert verification redundant.
// When usePinnedTrustStore is set, we use a pinned trust store that
// contains the known ElectrumX server certs plus system CAs. This is
// required because Samsung One UI 7 (Android 16) and GrapheneOS
// reject connections that use a no-op "trust-all" X509TrustManager.
val sslFactory =
if (server.host.endsWith(".onion")) {
// .onion addresses: prefer the pinned factory (the .onion server's
@@ -618,7 +614,7 @@ class ElectrumXClient(
// blanket trust-all that hardened TLS stacks (GrapheneOS, Samsung
// Knox) may reject at the Conscrypt/BoringSSL layer.
cachedPinnedSslFactory()
} else if (server.trustAllCerts) {
} else if (server.usePinnedTrustStore) {
cachedPinnedSslFactory()
} else {
SSLSocketFactory.getDefault() as SSLSocketFactory