From 2e02edc3333c40e70fa82ed801264835d817ce4e Mon Sep 17 00:00:00 2001 From: M Date: Thu, 26 Mar 2026 06:33:43 +1100 Subject: [PATCH] =?UTF-8?q?refactor:=20rename=20trustAllCerts=20=E2=86=92?= =?UTF-8?q?=20usePinnedTrustStore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../service/namecoin/NamecoinSettings.kt | 14 +++++------- .../service/namecoin/NamecoinSettingsTest.kt | 4 ++-- .../namecoin/ElectrumXServer.kt | 22 ++++++++++++------- .../namecoin/ElectrumXClient.kt | 14 +++++------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/namecoin/NamecoinSettings.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/namecoin/NamecoinSettings.kt index 0f372e577..1a859848c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/namecoin/NamecoinSettings.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/namecoin/NamecoinSettings.kt @@ -66,7 +66,7 @@ data class NamecoinSettings( * TLS is the default protocol. Append `:tcp` for plaintext * (useful for `.onion` addresses and local servers). * - * `.onion` addresses automatically get `trustAllCerts = true` + * `.onion` addresses automatically get `usePinnedTrustStore = true` * since certificate verification is meaningless over Tor. */ fun parseServerString(s: String): ElectrumxServer? { @@ -77,17 +77,15 @@ data class NamecoinSettings( if (host.isEmpty() || port <= 0 || port > 65535) return null val useSsl = parts.getOrNull(2)?.trim()?.lowercase() != "tcp" val isOnion = host.endsWith(".onion") - // All custom servers set trustAllCerts=true, which (despite the - // legacy name) means "use the pinned trust store" rather than - // "trust all certificates". ElectrumX servers almost universally - // use self-signed certs, so we route them through our pinned - // SSLSocketFactory (hardcoded defaults + TOFU-pinned certs). - // TODO: rename trustAllCerts → usePinnedTrustStore for clarity. + // All custom servers use the pinned trust store. ElectrumX + // servers almost universally use self-signed certs, so we + // route them through our pinned SSLSocketFactory (hardcoded + // defaults + TOFU-pinned certs + system CAs). return ElectrumxServer( host = host, port = port, useSsl = useSsl, - trustAllCerts = true, + usePinnedTrustStore = true, ) } diff --git a/amethyst/src/test/java/com/vitorpamplona/amethyst/service/namecoin/NamecoinSettingsTest.kt b/amethyst/src/test/java/com/vitorpamplona/amethyst/service/namecoin/NamecoinSettingsTest.kt index 4eb495af6..661caca6e 100644 --- a/amethyst/src/test/java/com/vitorpamplona/amethyst/service/namecoin/NamecoinSettingsTest.kt +++ b/amethyst/src/test/java/com/vitorpamplona/amethyst/service/namecoin/NamecoinSettingsTest.kt @@ -56,7 +56,7 @@ class NamecoinSettingsTest { assertEquals("abc123def.onion", s!!.host) assertEquals(50001, s.port) assertFalse(s.useSsl) - assertTrue(s.trustAllCerts) + assertTrue(s.usePinnedTrustStore) } @Test @@ -131,7 +131,7 @@ class NamecoinSettingsTest { assertTrue(servers[0].useSsl) assertEquals("server2.onion", servers[1].host) assertFalse(servers[1].useSsl) - assertTrue(servers[1].trustAllCerts) + assertTrue(servers[1].usePinnedTrustStore) } @Test diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/namecoin/ElectrumXServer.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/namecoin/ElectrumXServer.kt index f683894f8..4c6c96937 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/namecoin/ElectrumXServer.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/namecoin/ElectrumXServer.kt @@ -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), ) diff --git a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/namecoin/ElectrumXClient.kt b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/namecoin/ElectrumXClient.kt index 5119a6eb7..f8e0e3152 100644 --- a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/namecoin/ElectrumXClient.kt +++ b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/namecoin/ElectrumXClient.kt @@ -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