3655f5a3af0a

drive thirteen matrix scenarios plus the manifest adversarial cases

time
2026-09-11 00:17 UTC · 2 months ago
machine
koh2
agent
deepseek/deepseek-v4-flash
session
cross-client matrix
parent
7da1f5ffe7c9
1 file app/src/test/java/com/peachpasswords/sync/CrossClientSyncProcessTest.kt+49 −3
app/src/test/java/com/peachpasswords/sync/CrossClientSyncProcessTest.kt+49 −3
@@ -1,6 +1,7 @@11 package com.peachpasswords.sync22 33 import java.io.BufferedReader4+import kotlinx.serialization.json.Json45 import java.io.BufferedWriter56 import java.io.File67 import java.io.InputStreamReader@@ -102,6 +103,27 @@102103         }103104     }104105 106+    private fun craftedManifest(config: HarnessConfig): SignedDeviceManifest? =107+        config.signedManifestJson?.let {108+            json.decodeFromString(SignedDeviceManifest.serializer(), it)109+        }110+111+    /**112+     * The production verdict on the peer's manifest. The trusted key stands in113+     * for this device's stored issuer key, and every known issuer resolves to114+     * it, so a revocation signed by another key fails closed.115+     */116+    private fun manifestVerdict(config: HarnessConfig, manifest: SignedDeviceManifest, nowMs: Long): String {117+        val trustedHex = config.trustedPubkeyHex ?: return "not-checked"118+        val accepted = verifyDeviceManifest(119+            manifest = manifest,120+            issuerSigningPublicKey = hexToPubkey(trustedHex),121+            resolveIssuerSigningKeys = { setOf(trustedHex.lowercase()) },122+            nowMs = nowMs,123+        )124+        return if (accepted != null) "accepted" else "rejected"125+    }126+105127     private fun renderTranscript(106128         status: String,107129         outcome: SyncOutcome?,@@ -114,6 +136,9 @@114136         append(",\"entriesReceived\":").append(outcome?.entriesReceived ?: 0)115137         append(",\"applied\":").append(vault.appliedCount)116138         append(",\"staged\":").append(vault.stagedCount)139+        append(",\"manifestAccepted\":").append(140+            vault.manifestVerdict?.let { it == "accepted" } ?: "null",141+        )117142         append(",\"events\":[")118143         transcript.forEachIndexed { index, event ->119144             if (index > 0) append(',')@@ -122,6 +147,8 @@122147         append("]}")123148     }124149 150+    private val json = Json { ignoreUnknownKeys = true }151+125152     private fun configured(name: String): String? =126153         System.getenv(name) ?: System.getProperty(name.lowercase().replace('_', '.'))127154 @@ -152,6 +179,13 @@152179         val mismatch: Boolean,153180         val locked: Boolean,154181         val stopAfter: String?,182+        /**183+         * A manifest the harness signed: the wire shape IS the scenario, and one184+         * signer keeps both clients verifying the same bytes rather than each185+         * signing its own.186+         */187+        val signedManifestJson: String?,188+        val trustedPubkeyHex: String?,155189     ) {156190         companion object {157191             fun read(id: String, configured: (String) -> String?) = HarnessConfig(@@ -171,11 +205,13 @@171205                 // and never merges entries into the live vault (PB-26-112 C).172206                 locked = configured("PEACH_SYNC_HARNESS_LOCKED") == "1",173207                 stopAfter = configured("PEACH_SYNC_HARNESS_STOP_AFTER")?.takeIf(String::isNotEmpty),208+                signedManifestJson = configured("PEACH_SYNC_HARNESS_SIGNED_MANIFEST")?.takeIf(String::isNotEmpty),209+                trustedPubkeyHex = configured("PEACH_SYNC_HARNESS_TRUSTED_PUBKEY")?.takeIf(String::isNotEmpty),174210             )175211         }176212     }177213 178-    private class ProcessVault(private val config: HarnessConfig) : SyncVaultAdapter {214+    private inner class ProcessVault(private val config: HarnessConfig) : SyncVaultAdapter {179215         private val id = config.id180216         // Entries are shared ids so a diff can actually flow. Parity decides181217         // which side is newer for a given index: the same parity on both sides@@ -199,6 +235,13 @@199235             "11".repeat(64),200236         )201237 238+        /** The production verdict on the peer's manifest, or null if none arrived. */239+        var manifestVerdict: String? = null240+            private set241+242+        private val nowMs = System.currentTimeMillis()243+        private val crafted: SignedDeviceManifest? = craftedManifest(config)244+202245         /** Entries this side merged into its live vault. */203246         var appliedCount = 0204247             private set@@ -232,11 +275,14 @@232275         override suspend fun applyTombstones(tombstones: Map<String, Long>) = Unit233276 234277         override suspend fun buildOutgoingDeviceManifest() =235-            if (config.manifestSupport && !config.locked) manifest else null278+            if (!config.manifestSupport || config.locked) null else crafted ?: manifest279+236280         override suspend fun applyIncomingDeviceManifest(237281             manifest: SignedDeviceManifest,238282             authenticatedRemoteStaticPublicKey: ByteArray,239-        ) = Unit283+        ) {284+            manifestVerdict = manifestVerdict(config, manifest, nowMs)285+        }240286 241287         override val supportsDeviceManifest = config.manifestSupport && !config.locked242288     }

view file