5b77d27b8c69

refuse every device-manifest operation in a locked session and record the PB-26-111/112/115 owner decisions (v2.17.29)

time
2026-09-10 22:01 UTC · 2 months ago
machine
koh2
agent
deepseek/deepseek-v4-flash
session
cross-client remediation
parent
812f9ac7993c
3 files VERSION+1 −1app/src/main/java/com/peachpasswords/sync/LockedSyncSpoolStore.kt+44 −5app/src/test/java/com/peachpasswords/sync/LockedSyncSpoolModelTest.kt+49 −0
VERSION+1 −1
@@ -1 +1 @@1-2.17.281+2.17.29

view file

app/src/main/java/com/peachpasswords/sync/LockedSyncSpoolStore.kt+44 −5
@@ -98,7 +98,14 @@9898         return lockedSyncIdentity(state, RelaySettingsStore.readRelayUrl(context))9999     }100100 101-    internal fun adapter(): SyncVaultAdapter? = read()?.let { LockedSyncVaultAdapter(this, it.vaultId) }101+    internal fun adapter(): SyncVaultAdapter? = read()?.let { state ->102+        LockedSyncVaultAdapter(103+            vaultId = state.vaultId,104+            readSnapshot = { snapshot(state.vaultId) },105+            stageEntriesInto = { entries, manifest -> stageEntries(state.vaultId, entries, manifest) },106+            stageTombstonesInto = { tombstones -> stageTombstones(state.vaultId, tombstones) },107+        )108+    }102109 103110     internal suspend fun drainInto(repo: VaultRepository) {104111         val staged = read() ?: return@@ -213,11 +220,30 @@213220     }214221 }215222 223+/**224+ * The sync adapter a fully locked session may use.225+ *226+ * It can do exactly two things: report the cached snapshot, and STAGE incoming227+ * ciphertext for the next unlock to drain into the vault. It deliberately228+ * cannot author or accept a device manifest.229+ *230+ * That boundary is load-bearing for PB-26-112. The Keystore-wrapped key this231+ * session runs on is the X25519 TRANSPORT key only — the Ed25519 signing key is232+ * never written to the spool — so a locked device holds no key that can233+ * authorise a manifest or a revocation. Admission, vouching, revocation, and234+ * identity rotation all require an unlocked vault.235+ *236+ * The refusals below are explicit instead of inherited from the interface's237+ * silent defaults, so a future wiring change cannot quietly turn a locked238+ * session into a trust-mutating one.239+ */216240 internal class LockedSyncVaultAdapter(217-    private val store: LockedSyncSpoolStore,218241     private val vaultId: String,242+    private val readSnapshot: () -> LockedSyncSpool?,243+    private val stageEntriesInto: (Map<String, String>, Map<String, Long>) -> Unit,244+    private val stageTombstonesInto: (Map<String, Long>) -> Unit,219245 ) : SyncVaultAdapter {220-    private fun state() = store.snapshot(vaultId) ?: throw VaultLockedException()246+    private fun state() = readSnapshot() ?: throw VaultLockedException()221247     override suspend fun computeVaultId() = vaultId222248     override suspend fun getOurDeviceId() = state().deviceId223249     override suspend fun getLocalVersion() = state().localVersion@@ -227,10 +253,23 @@227253         val entries = state().entries228254         return entryIds.mapNotNull { id -> entries[id]?.ciphertext?.let { id to it } }.toMap()229255     }256+257+    // Staging only — the vault is not touched until the next unlock drains it.230258     override suspend fun applyEntries(entries: Map<String, String>, remoteManifest: Map<String, Long>) =231-        store.stageEntries(vaultId, entries, remoteManifest)259+        stageEntriesInto(entries, remoteManifest)260+232261     override suspend fun applyTombstones(tombstones: Map<String, Long>) =233-        store.stageTombstones(vaultId, tombstones)262+        stageTombstonesInto(tombstones)263+264+    override val supportsDeviceManifest: Boolean = false265+266+    override suspend fun buildOutgoingDeviceManifest(): SignedDeviceManifest =267+        throw VaultLockedException()268+269+    override suspend fun applyIncomingDeviceManifest(270+        manifest: SignedDeviceManifest,271+        authenticatedRemoteStaticPublicKey: ByteArray,272+    ): Unit = throw VaultLockedException()234273 }235274 236275 internal object LockedSyncSpoolHooks {

view file

app/src/test/java/com/peachpasswords/sync/LockedSyncSpoolModelTest.kt+49 −0
@@ -1,8 +1,10 @@11 package com.peachpasswords.sync22 3+import kotlinx.coroutines.runBlocking34 import org.bouncycastle.crypto.params.X25519PrivateKeyParameters45 import org.junit.Assert.assertArrayEquals56 import org.junit.Assert.assertEquals7+import org.junit.Assert.assertFalse68 import org.junit.Assert.assertNull79 import org.junit.Assert.assertThrows810 import org.junit.Test@@ -45,6 +47,53 @@4547             ),4648         )4749     }50+51+    @Test fun locked_adapter_refuses_every_device_manifest_operation() {52+        val adapter = lockedAdapter()53+54+        // A locked session must not be able to mutate trust in either direction.55+        assertFalse(adapter.supportsDeviceManifest)56+        assertThrows(VaultLockedException::class.java) {57+            runBlocking { adapter.buildOutgoingDeviceManifest() }58+        }59+        assertThrows(VaultLockedException::class.java) {60+            runBlocking { adapter.applyIncomingDeviceManifest(manifest(), ByteArray(32)) }61+        }62+    }63+64+    @Test fun locked_adapter_still_stages_ciphertext_for_the_next_unlock() = runBlocking {65+        val entries = mutableMapOf<String, String>()66+        val tombstones = mutableMapOf<String, Long>()67+        val adapter = LockedSyncVaultAdapter(68+            vaultId = "a".repeat(64),69+            readSnapshot = { null },70+            stageEntriesInto = { staged, _ -> entries.putAll(staged) },71+            stageTombstonesInto = { tombstones.putAll(it) },72+        )73+74+        adapter.applyEntries(mapOf("entry-1" to "AA=="), mapOf("entry-1" to 5L))75+        adapter.applyTombstones(mapOf("entry-2" to 7L))76+77+        assertEquals(mapOf("entry-1" to "AA=="), entries)78+        assertEquals(mapOf("entry-2" to 7L), tombstones)79+    }80+81+    private fun lockedAdapter() = LockedSyncVaultAdapter(82+        vaultId = "a".repeat(64),83+        readSnapshot = { null },84+        stageEntriesInto = { _, _ -> },85+        stageTombstonesInto = { _ -> },86+    )87+88+    private fun manifest() = SignedDeviceManifest(89+        body = DeviceManifestBody(90+            manifestVersion = DEVICE_MANIFEST_VERSION,91+            issuerDeviceId = "issuer",92+            issuedAt = 1L,93+            devices = emptyList(),94+        ),95+        signatureHex = "00".repeat(64),96+    )4897 4998     private fun state(5099         inboxEntries: Map<String, LockedSyncCachedEntry> = emptyMap(),

view file