490a1a7592ef
agree one canonical revocation record across Browser and Android, issuer bound to known-key history (Android v2.17.24)
- time
- 2026-09-10 17:40 UTC · 2 months ago
- machine
- koh2
- agent
- deepseek/deepseek-v4-flash
- session
- cross-client remediation
- parent
- e0404bda3dae
↓ peach-android-490a1a75.tar.gzatlas at this save
files changed5 files
VERSION+1 −1app/src/main/java/com/peachpasswords/sync/DeviceManifestSupport.kt+25 −31app/src/main/java/com/peachpasswords/sync/SyncMessage.kt+19 −4app/src/test/java/com/peachpasswords/CrossPlatformKATTest.kt+11 −10app/src/test/java/com/peachpasswords/sync/DeviceManifestSupportTest.kt+1 −1app/src/main/java/com/peachpasswords/sync/DeviceManifestSupport.kt+25 −31
@@ -95,7 +95,6 @@9595 revoked: List<DeviceRevocation> = emptyList(),9696 ): SignedDeviceManifest {9797 require(issuerDeviceId.isNotBlank()) { "issuerDeviceId is required" }98- val issuerKeyHex = pubkeyToHex(signingPrivateKey.generatePublicKey().encoded)9998 val body = DeviceManifestBody(10099 manifestVersion = DEVICE_MANIFEST_VERSION,101100 issuerDeviceId = issuerDeviceId,@@ -103,16 +102,9 @@103102 devices = devices.map { normaliseManifestEntry(it) ?: it },104103 revoked = revoked.map { record ->105104 // A forwarded revocation is an immutable issuer statement. Preserve106- // its original issuer, key, and signature; only sign locally-created105+ // its original issuer and signature; only sign locally-created107106 // records that have not been signed yet.108- if (record.signatureHex.isNotBlank()) {109- record110- } else {111- signDeviceRevocation(112- record.copy(issuerDeviceId = issuerDeviceId, issuerSigningKeyHex = issuerKeyHex),113- signingPrivateKey,114- )115- }107+ if (record.signatureHex.isNotBlank()) record else signDeviceRevocation(record, signingPrivateKey)116108 },117109 )118110 val signature = signEd25519(signingPrivateKey, canonicalDeviceManifestBody(body).toByteArray(Charsets.UTF_8))@@ -124,11 +116,7 @@124116 record: DeviceRevocation,125117 signingPrivateKey: Ed25519PrivateKeyParameters,126118 ): DeviceRevocation {127- val keyHex = pubkeyToHex(signingPrivateKey.generatePublicKey().encoded)128- val unsigned = record.copy(129- issuerSigningKeyHex = keyHex,130- signatureHex = "",131- )119+ val unsigned = record.copy(signatureHex = "")132120 val signature = signEd25519(133121 signingPrivateKey,134122 canonicalDeviceRevocation(unsigned).toByteArray(Charsets.UTF_8),@@ -136,13 +124,13 @@136124 return unsigned.copy(signatureHex = pubkeyToHex(signature))137125 }138126 127+/** The exact bytes an issuer signs; identical in Browser and Android. */139128 fun canonicalDeviceRevocation(record: DeviceRevocation): String =140129 canonicalise(141130 mapOf(142131 "deviceId" to record.deviceId,143- "issuerDeviceId" to record.issuerDeviceId,144- "issuerSigningKeyHex" to record.issuerSigningKeyHex.lowercase(),145132 "longTermPublicKeyHex" to record.longTermPublicKeyHex.lowercase(),133+ "recordVersion" to record.recordVersion,146134 "revokedAt" to record.revokedAt,147135 "revokedByDeviceId" to record.revokedByDeviceId,148136 ),@@ -159,20 +147,28 @@159147 }160148 161149 /**162- * A relayed revocation counts only when the key it names is one the receiver163- * already trusts for `revokedByDeviceId` — that device's current signing key or164- * an entry in its immutable known-key history. An unresolvable issuer fails165- * closed: the manifest is rejected rather than the record being skipped, so a166- * dropped history entry can never silently un-revoke a device.150+ * A relayed revocation counts only when its signature verifies under a key the151+ * receiver already trusts for `revokedByDeviceId` — that device's current152+ * signing key or an entry in its immutable known-key history. The record names153+ * no key of its own, so a relaying peer cannot authorise anything by supplying154+ * one.155+ *156+ * An unresolvable issuer fails closed: the manifest is rejected rather than the157+ * record being skipped, so a dropped history entry can never silently158+ * un-revoke a device.167159 */168160 private fun isAuthorisedRevocation(169161 record: DeviceRevocation,170162 resolveIssuerSigningKeys: (String) -> Set<String>,171163 ): Boolean {172- val statedKey = record.issuerSigningKeyHex.lowercase()173- val trusted = resolveIssuerSigningKeys(record.revokedByDeviceId).map { it.lowercase() }174- if (statedKey !in trusted) return false175- return verifyDeviceRevocation(record, hexToPubkey(statedKey))164+ val signature = runCatching { hexToBytes(record.signatureHex) }.getOrNull() ?: return false165+ val payload = canonicalDeviceRevocation(record.copy(signatureHex = "")).toByteArray(Charsets.UTF_8)166+ val trusted = resolveIssuerSigningKeys(record.revokedByDeviceId)167+ if (trusted.isEmpty()) return false168+ return trusted.any { key ->169+ val hex = key.lowercase()170+ isHex(hex, 64) && verifyEd25519(hexToPubkey(hex), payload, signature)171+ }176172 }177173 178174 fun verifyDeviceManifest(@@ -269,20 +265,18 @@269265 r.copy(longTermPublicKeyHex = r.longTermPublicKeyHex.lowercase())270266 271267 private fun isValidRevocation(r: DeviceRevocation): Boolean =272- r.deviceId.isNotBlank() && r.deviceId.length <= MAX_MANIFEST_STRING &&268+ r.recordVersion == DEVICE_REVOCATION_RECORD_VERSION &&269+ r.deviceId.isNotBlank() && r.deviceId.length <= MAX_MANIFEST_STRING &&273270 isHex(r.longTermPublicKeyHex.lowercase(), 64) &&274271 r.revokedByDeviceId.isNotBlank() && r.revokedByDeviceId.length <= MAX_MANIFEST_STRING &&275- r.issuerDeviceId.isNotBlank() && r.issuerDeviceId.length <= MAX_MANIFEST_STRING &&276- isHex(r.issuerSigningKeyHex.lowercase(), 64) &&277272 isHex(r.signatureHex, 128) &&278273 r.revokedAt >= 0L279274 280275 281276 private fun revocationMap(r: DeviceRevocation): Map<String, Any> = linkedMapOf(282277 "deviceId" to r.deviceId,283- "issuerDeviceId" to r.issuerDeviceId,284- "issuerSigningKeyHex" to r.issuerSigningKeyHex.lowercase(),285278 "longTermPublicKeyHex" to r.longTermPublicKeyHex.lowercase(),279+ "recordVersion" to r.recordVersion,286280 "revokedAt" to r.revokedAt,287281 "revokedByDeviceId" to r.revokedByDeviceId,288282 "signatureHex" to r.signatureHex.lowercase(),app/src/main/java/com/peachpasswords/sync/SyncMessage.kt+19 −4
@@ -114,13 +114,28 @@114114 val longTermPublicKeyHex: String,115115 val revokedAt: Long,116116 val revokedByDeviceId: String,117- /** Immutable issuer identity carried by the record itself. */118- val issuerDeviceId: String = revokedByDeviceId,119- /** Signing key version/binding used for this record; never rewrite history. */120- val issuerSigningKeyHex: String = "",117+ /**118+ * Frozen record version. Defaulted rather than required so a persisted119+ * pre-migration record still decodes; such a record is rejected by120+ * signature verification, which covers its different canonical bytes.121+ */122+ val recordVersion: Int = DEVICE_REVOCATION_RECORD_VERSION,121123 /** Ed25519 signature over [canonicalDeviceRevocation]. */122124 val signatureHex: String = "",123125 )126+127+/**128+ * Frozen revocation record version (campaign §5.5, Amendment A-2). Every field129+ * except [DeviceRevocation.signatureHex] is covered by the canonical bytes the130+ * issuer signs — and `recordVersion` is part of those bytes, so a peer cannot131+ * reinterpret the record under a different version.132+ *133+ * The record deliberately carries no issuer key: a receiver resolves134+ * `revokedByDeviceId` through its own immutable known-key history, so a peer135+ * that merely relays a manifest cannot authorise a revocation by supplying a136+ * key of its own.137+ */138+const val DEVICE_REVOCATION_RECORD_VERSION = 2124139 125140 @Serializable126141 data class SignedDeviceManifest(app/src/test/java/com/peachpasswords/CrossPlatformKATTest.kt+11 −10
@@ -1,5 +1,6 @@11 package com.peachpasswords22 3+import com.peachpasswords.sync.DEVICE_MANIFEST_VERSION34 import com.peachpasswords.sync.DeviceManifestBody45 import com.peachpasswords.sync.DeviceRevocation56 import com.peachpasswords.sync.ManifestDeviceEntry@@ -62,13 +63,13 @@6263 assertEquals("ae0ec54041c9ba3e20c0c2d33bdeb2552f3b9a3fb4be3286ec0ef0a61be2fc9c", computeVaultId(masterKey))6364 }6465 65- @Test fun device_manifest_v4_canonical_form_vector() {66+ @Test fun device_manifest_v5_canonical_form_vector() {6667 // Pinned byte-for-byte against peach-browser's canonicalise() in6768 // device-manifest.test.ts. If either side reorders a key, renames a6869 // field, or changes number formatting, this string moves and the two6970 // stop verifying each other's signatures.7071 val body = DeviceManifestBody(71- manifestVersion = 4,72+ manifestVersion = DEVICE_MANIFEST_VERSION,7273 issuerDeviceId = "issuer-1",7374 issuedAt = 1_700_000_000_000L,7475 devices = listOf(@@ -97,9 +98,9 @@9798 "\"pairedAt\":1700000000001,\"relayUrl\":\"wss://relay.peachpasswords.com\"," +9899 "\"signingPublicKeyHex\":\"" + "bb".repeat(32) + "\"," +99100 "\"vouchDepth\":0,\"wsPort\":49142}],\"issuedAt\":1700000000000,\"issuerDeviceId\":\"issuer-1\"," +100- "\"manifestVersion\":4,\"revoked\":[{\"deviceId\":\"gone-1\"," +101- "\"longTermPublicKeyHex\":\"" + "cc".repeat(32) + "\",\"revokedAt\":1700000000002," +102- "\"revokedByDeviceId\":\"issuer-1\"}]}"101+ "\"manifestVersion\":5,\"revoked\":[{\"deviceId\":\"gone-1\"," +102+ "\"longTermPublicKeyHex\":\"" + "cc".repeat(32) + "\",\"recordVersion\":2," +103+ "\"revokedAt\":1700000000002,\"revokedByDeviceId\":\"issuer-1\",\"signatureHex\":\"\"}]}"103104 assertEquals(expected, canonicalDeviceManifestBody(body))104105 }105106 @@ -130,7 +131,7 @@130131 assertEquals("57af120b0de7acbe7907ec149c5ae870a2dbb74232b65777ba4123f1f7f888f5", hex(nk2))131132 }132133 133- @Test fun device_manifest_v4_canonical_form_omits_null_ws_port_and_relay_url() {134+ @Test fun device_manifest_v5_canonical_form_omits_null_ws_port_and_relay_url() {134135 // Pinned against peach-browser canonicalise() in device-manifest.test.ts.135136 // Android's manifestEntryMap (DeviceManifestSupport.kt:194) omits wsPort136137 // and relayUrl when null; the browser's canonicalise skips null values@@ -138,7 +139,7 @@138139 // bytes — a future regression that re-introduces the null key on either139140 // side will fail this KAT and the browser's mirror test.140141 val body = DeviceManifestBody(141- manifestVersion = 4,142+ manifestVersion = DEVICE_MANIFEST_VERSION,142143 issuerDeviceId = "issuer-1",143144 issuedAt = 1_700_000_000_000L,144145 devices = listOf(@@ -172,10 +173,10 @@172173 "\"pairedAt\":1700000000001," +173174 "\"signingPublicKeyHex\":\"" + "bb".repeat(32) + "\",\"vouchDepth\":0}]," +174175 "\"issuedAt\":1700000000000,\"issuerDeviceId\":\"issuer-1\"," +175- "\"manifestVersion\":4," +176+ "\"manifestVersion\":5," +176177 "\"revoked\":[{\"deviceId\":\"gone-1\"," +177- "\"longTermPublicKeyHex\":\"" + "cc".repeat(32) + "\",\"revokedAt\":1700000000002," +178- "\"revokedByDeviceId\":\"issuer-1\"}]}"178+ "\"longTermPublicKeyHex\":\"" + "cc".repeat(32) + "\",\"recordVersion\":2," +179+ "\"revokedAt\":1700000000002,\"revokedByDeviceId\":\"issuer-1\",\"signatureHex\":\"\"}]}"179180 assertEquals(expected, canonical)180181 }181182 }app/src/test/java/com/peachpasswords/sync/DeviceManifestSupportTest.kt+1 −1
@@ -151,7 +151,7 @@151151 signing.privateKey,152152 )153153 assertEquals(154- """{"deviceId":"peer","issuerDeviceId":"issuer","issuerSigningKeyHex":"${pubkeyToHex(signing.publicKeyRaw)}","longTermPublicKeyHex":"${"aa".repeat(32)}","revokedAt":42,"revokedByDeviceId":"issuer"}""",154+ """{"deviceId":"peer","longTermPublicKeyHex":"${"aa".repeat(32)}","recordVersion":2,"revokedAt":42,"revokedByDeviceId":"issuer"}""",155155 canonicalDeviceRevocation(record),156156 )157157 assertEquals(true, verifyDeviceRevocation(record, signing.publicKeyRaw))