securemail: send ?l= on WKD lookups so Proton keys are found
- Commit
6da6a7ee65041353541dec101311e052aed2f676- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-02 04:14 UTC (1 month ago)
- Parents
1e62496
Mail to Proton went out unencrypted ("Sent unencrypted - no key for a
recipient") even though Proton publishes keys over WKD. The lookup URLs
carried only the hashed local part; Proton's openpgpkey.proton.me
rejects that with 400 Bad Request and only answers when the original
local part is also sent as ?l=<local> (WKD draft section 3.1, which
GnuPG and other clients always send). Checked live for
[email protected]: 200 with a 779-byte key with ?l=, 400 without.
wkdUrls() now appends ?l= with the original-case local part,
URL-encoded (URLEncoder's "UTF-8" overload, since the Charset overload
needs API 33 and minSdk is 31). The hash still uses the lowercased
local part as RFC 7929 requires. HTTPS already used system trust, so no
TLS change was needed.
Verified: MailPolicyTest gains the RFC 7929 vector as an exact URL
(Joe.Doe -> iy9q119eutrkn8s1mk4r39qejnbu3n5q?l=Joe.Doe) and a
URL-encoding case; securemail unit tests, lint clean, detekt
unchanged at 40.Diff
securemail/src/main/java/com/vayunmathur/securemail/domain/mail/KeyLookupPolicy.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/domain/mail/KeyLookupPolicy.kt b/securemail/src/main/java/com/vayunmathur/securemail/domain/mail/KeyLookupPolicy.ktindex af9718f7cc..f928434f1b 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/domain/mail/KeyLookupPolicy.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/domain/mail/KeyLookupPolicy.kt@@ -63,19 +63,22 @@ object KeyLookupPolicy { /** * WKD lookup URLs for [address] (RFC 7929): the advanced method * (`openpgpkey.<domain>`) first, then the direct method (`<domain>`).- * The local part is lowercased, SHA-1 hashed, and z-base-32 encoded.- * Proton serves WKD on `proton.me` for `@proton.me` / `@protonmail.com`.+ * The local part is lowercased, SHA-1 hashed, and z-base-32 encoded; the+ * original local part also rides as `?l=` (WKD draft §3.1), which Proton+ * requires - without it openpgpkey.proton.me answers 400. */ fun wkdUrls(address: String): List<String> { val at = address.lastIndexOf('@') if (at <= 0) return emptyList()- val local = address.substring(0, at).lowercase()+ val rawLocal = address.substring(0, at)+ val local = rawLocal.lowercase() val domain = address.substring(at + 1).lowercase() if (local.isEmpty() || domain.isEmpty()) return emptyList() val hash = wkdHash(local)+ val l = java.net.URLEncoder.encode(rawLocal, "UTF-8") return listOf(- "https://openpgpkey.$domain/.well-known/openpgpkey/$domain/hu/$hash",- "https://$domain/.well-known/openpgpkey/hu/$hash",+ "https://openpgpkey.$domain/.well-known/openpgpkey/$domain/hu/$hash?l=$l",+ "https://$domain/.well-known/openpgpkey/hu/$hash?l=$l", ) }
securemail/src/test/java/com/vayunmathur/securemail/domain/mail/MailPolicyTest.kt
diff --git a/securemail/src/test/java/com/vayunmathur/securemail/domain/mail/MailPolicyTest.kt b/securemail/src/test/java/com/vayunmathur/securemail/domain/mail/MailPolicyTest.ktindex 7a8c82b17e..1354db7f55 100644--- a/securemail/src/test/java/com/vayunmathur/securemail/domain/mail/MailPolicyTest.kt+++ b/securemail/src/test/java/com/vayunmathur/securemail/domain/mail/MailPolicyTest.kt@@ -89,5 +89,13 @@ class KeyLookupPolicyTest { // Both methods share the same hash suffix. assertEquals(urls[0].substringAfter("/hu/"), urls[1].substringAfter("/hu/")) assertTrue(KeyLookupPolicy.wkdUrls("not-an-address").isEmpty())+ // RFC 7929 vector: hash from the lowercased local part, ?l= keeps the+ // original (Proton rejects lookups without it).+ assertEquals(+ "https://openpgpkey.example.org/.well-known/openpgpkey/example.org/hu/" ++ "iy9q119eutrkn8s1mk4r39qejnbu3n5q?l=Joe.Doe",+ KeyLookupPolicy.wkdUrls("[email protected]")[0],+ )+ assertTrue(KeyLookupPolicy.wkdUrls("[email protected]")[1].endsWith("?l=a%2Bb")) } }