a73f59461554
wip: land the adoption v2 transcript and every Android adapter, with frozen v1 types intact; relay adoption tests still assert the v1 wire and one blocks to the pairing window (v2.17.26)
- time
- 2026-09-10 20:27 UTC · 2 months ago
- machine
- koh2
- agent
- deepseek/deepseek-v4-flash
- session
- cross-client remediation
- parent
- 2f894d9e3a5a
↓ peach-android-a73f5946.tar.gzatlas at this save
files changed12 files
VERSION+1 −1app/src/main/java/com/peachpasswords/sync/AdoptionProtocol.kt+379 −0app/src/main/java/com/peachpasswords/sync/PendingVouchedDeviceStore.kt+46 −4app/src/main/java/com/peachpasswords/sync/RelayAdoptionHost.kt+45 −27app/src/main/java/com/peachpasswords/sync/RelayAdoptionReceiver.kt+64 −18app/src/main/java/com/peachpasswords/sync/VaultAdopt.kt+52 −21app/src/main/java/com/peachpasswords/ui/pairing/AdoptVaultViewModel.kt+56 −7app/src/main/java/com/peachpasswords/ui/pairing/CodePairViewModel.kt+40 −3app/src/main/java/com/peachpasswords/ui/sync/SyncViewModel.kt+6 −2app/src/test/java/com/peachpasswords/sync/RelayAdoptionHostTest.kt+56 −8app/src/test/java/com/peachpasswords/sync/RelayAdoptionInitiatorSourceTest.kt+65 −9app/src/test/java/com/peachpasswords/sync/RelayAdoptionReceiverTest.kt+77 −20app/src/main/java/com/peachpasswords/sync/AdoptionProtocol.kt+379 −0
@@ -0,0 +1,379 @@1+package com.peachpasswords.sync2+3+import kotlinx.serialization.SerialName4+import kotlinx.serialization.Serializable5+6+/**7+ * Adoption transcript v2.8+ *9+ * v1 hands over the root-bearing `ADOPT_GRANT` before the receiver's identity10+ * has been exchanged or validated, so the source's pending record is keyed on a11+ * session label that is explicitly not an identity — the source can list and12+ * revoke nothing durable. v2 places a validated identity before every13+ * root-bearing frame.14+ *15+ * Frozen contract: `peach-browser/docs/sync-protocol.md` section 10.16+ */17+18+/** Adoption transcript version. A v1 request carries no version field at all. */19+const val ADOPTION_VERSION = 220+21+private const val REASON_PRO_REQUIRED = "ADOPT_PRO_REQUIRED"22+private const val REASON_DEVICE_ID_COLLISION = "ADOPT_DEVICE_ID_COLLISION"23+24+/**25+ * Legacy v1 adoption stays accepted until the secure-reset state machine lands.26+ * v1 cannot establish the revocation guarantee, so the UI labels it27+ * non-ejectable. Phase 3.1 replaces this constant with the durable reset state.28+ */29+private const val LEGACY_V1_ALLOWED = true30+31+/**32+ * The v2 grant as it appears on the wire.33+ *34+ * It is deliberately NOT part of [AdoptionFrame]: the frozen v1 `Grant` carries35+ * a required `source`, a sealed hierarchy can bind only one class to the36+ * `ADOPT_GRANT` discriminator, and widening the v1 type to satisfy a v2 shape37+ * would let v1-only code accept a grant it can never receive. The v2 transcript38+ * therefore reads and writes this shape directly.39+ */40+@Serializable41+data class AdoptGrantV2(42+ val type: String,43+ @SerialName("root_key_hex") val rootKeyHex: String,44+ @SerialName("vault_id") val vaultId: String,45+ val license: String? = null,46+)47+48+private const val GRANT_TYPE = "ADOPT_GRANT"49+50+/**51+ * What the RECEIVER (joining device) needs to adopt a vault over the v252+ * transcript: the v1 surface plus the v2 additions. Extending the v1 interface53+ * is what makes the union compile-time visible — delegating through a cast54+ * would fail only once a peer triggered the missing callback.55+ */56+interface AdoptionReceiverV2Deps : AdoptionReceiverDeps {57+ /** The receiver's durable device identity. Available with no vault present. */58+ fun localIdentity(): LocalDeviceIdentity59+60+ suspend fun rotateLocalIdentity(): LocalDeviceIdentity61+62+ suspend fun validateSource(prepare: AdoptionFrame.Prepare)63+64+ suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare): Boolean65+}66+67+/** What the SOURCE (existing device) needs to grant its vault over the v2 transcript. */68+interface AdoptionSourceV2Deps : AdoptionSourceDeps {69+ suspend fun onConsent(request: AdoptionFrame.RequestV2): Boolean70+71+ // Re-declared abstract: the v1 defaults would silently accept an unrotated72+ // identity or throw only after a peer asked for the callback.73+ override suspend fun rotateSourceIdentity(): LocalDeviceIdentity74+75+ override fun hasDeviceIdentityCollision(device: PairedDevice): Boolean76+77+ /**78+ * Durably record the validated receiver identity before any root-bearing79+ * frame. Named apart from the v1 member, which is keyed on a request label.80+ */81+ suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long): Boolean82+83+ /** Promote the pending identity to a direct paired device. */84+ suspend fun completePendingIdentity(device: PairedDevice): Boolean85+86+ fun snapshotCapable(): Boolean87+}88+89+fun AdoptionReceiverV2Deps.allowLegacyV1(): Boolean = LEGACY_V1_ALLOWED90+91+fun AdoptionSourceV2Deps.allowLegacyV1(): Boolean = LEGACY_V1_ALLOWED92+93+private fun AdoptionFrame.RequestV2.valid(): Boolean =94+ adoptionVersion == ADOPTION_VERSION &&95+ deviceId.isNotEmpty() &&96+ Hex64.matches(longTermPublicKeyHex) &&97+ Hex64.matches(signingPublicKeyHex) &&98+ isDeviceType(deviceType)99+100+private fun AdoptionFrame.Prepare.valid(): Boolean =101+ deviceId.isNotEmpty() &&102+ Hex64.matches(longTermPublicKeyHex) &&103+ Hex64.matches(signingPublicKeyHex) &&104+ isDeviceType(deviceType) &&105+ Hex64.matches(vaultId)106+107+/**108+ * RECEIVER side: present our durable identity, then adopt the vault the source109+ * prepares. Returns null on any protocol failure, with the reason via110+ * [AdoptionReceiverV2Deps.onError].111+ */112+suspend fun requestAdoptionV2(113+ channel: PairingTransport,114+ deps: AdoptionReceiverV2Deps,115+ // Called with the accepted ADOPT_PREPARE once it has been validated, so the116+ // caller can read the source's capabilities before the root is granted.117+ onPrepare: ((AdoptionFrame.Prepare) -> Unit)? = null,118+ nowMs: Long = System.currentTimeMillis(),119+): PairedDevice? {120+ val receiverLicense = deps.license()121+122+ fun requestFrame(identity: LocalDeviceIdentity): AdoptionFrame.RequestV2 =123+ AdoptionFrame.RequestV2(124+ adoptionVersion = ADOPTION_VERSION,125+ deviceId = identity.deviceId,126+ deviceName = identity.deviceName,127+ deviceType = identity.deviceType.wireValue,128+ longTermPublicKeyHex = identity.longTermPublicKeyHex,129+ signingPublicKeyHex = identity.signingPublicKeyHex,130+ license = receiverLicense,131+ snapshotCapable = true,132+ )133+134+ // A malformed root key must not escape as an exception; every failure here135+ // is the same protocol outcome.136+ fun rootKeyMatchesVault(rootKeyHex: String, vaultId: String): Boolean {137+ if (!validateRootKeyHex(rootKeyHex) || !Hex64.matches(vaultId)) return false138+ val rootKeyBytes = hexToPubkey(rootKeyHex)139+ return try {140+ computeVaultId(rootKeyBytes) == vaultId141+ } finally {142+ rootKeyBytes.fill(0)143+ }144+ }145+146+ sendFrame(channel, requestFrame(deps.localIdentity()))147+148+ if (receiveFrame(channel) !is AdoptionFrame.ConfirmRequired) {149+ deps.onError("ADOPT_UNEXPECTED_FRAME")150+ return null151+ }152+153+ val confirmed = deps.confirmSas()154+ sendFrame(channel, AdoptionFrame.Confirm(confirmed))155+ if (!confirmed) {156+ deps.onError("ADOPT_SAS_REJECTED")157+ return null158+ }159+160+ // The source rejects our identity once if it is already in its terminal161+ // ledger; we rotate exactly once and present the fresh identity.162+ var prepared = receiveFrame(channel)163+ if (prepared is AdoptionFrame.Reject && prepared.reason == REASON_DEVICE_ID_COLLISION) {164+ sendFrame(channel, requestFrame(deps.rotateLocalIdentity()))165+ prepared = receiveFrame(channel)166+ }167+ if (prepared is AdoptionFrame.Reject) {168+ deps.onError(prepared.reason)169+ return null170+ }171+ if (prepared !is AdoptionFrame.Prepare || !prepared.valid()) {172+ deps.onError("ADOPT_UNEXPECTED_FRAME")173+ return null174+ }175+176+ deps.validateSource(prepared)177+178+ // The source's identity may be in our terminal ledger. Reject once, accept179+ // only a rotated preparation, and treat a second collision as terminal.180+ if (deps.hasSourceIdentityCollision(prepared)) {181+ sendFrame(channel, AdoptionFrame.Reject(REASON_DEVICE_ID_COLLISION))182+ val rotated = receiveFrame(channel)183+ if (rotated !is AdoptionFrame.Prepare || !rotated.valid()) {184+ deps.onError("ADOPT_SOURCE_COLLISION_NOT_RESOLVED")185+ return null186+ }187+ deps.validateSource(rotated)188+ if (deps.hasSourceIdentityCollision(rotated)) {189+ sendFrame(channel, AdoptionFrame.Reject(REASON_DEVICE_ID_COLLISION))190+ deps.onError("ADOPT_SOURCE_COLLISION_NOT_RESOLVED")191+ return null192+ }193+ prepared = rotated194+ }195+196+ if (receiverLicense == null && prepared.license == null) {197+ deps.onError(REASON_PRO_REQUIRED)198+ return null199+ }200+201+ onPrepare?.invoke(prepared)202+203+ sendFrame(channel, AdoptionFrame.Ready)204+205+ val raw = String(channel.receive(), Charsets.UTF_8)206+ // Either the v2 grant or a terminal rejection.207+ val rejection = runCatching {208+ AdoptJson.decodeFromString(AdoptionFrame.serializer(), raw)209+ }.getOrNull() as? AdoptionFrame.Reject210+ if (rejection != null) {211+ deps.onError(rejection.reason)212+ return null213+ }214+ val grant = runCatching {215+ AdoptJson.decodeFromString(AdoptGrantV2.serializer(), raw)216+ }.getOrNull()217+ if (grant == null || grant.type != GRANT_TYPE) {218+ deps.onError("ADOPT_UNEXPECTED_FRAME")219+ return null220+ }221+ // The source may not change the vault between preparing and granting, and222+ // the granted root key must actually derive that vault id.223+ if (grant.vaultId != prepared.vaultId || !rootKeyMatchesVault(grant.rootKeyHex, grant.vaultId)) {224+ deps.onError("ADOPT_VAULT_ID_MISMATCH")225+ return null226+ }227+228+ val vaultId = deps.createVaultFromRootKey(grant.rootKeyHex)229+ if (vaultId != grant.vaultId) {230+ deps.onError("ADOPT_VAULT_ID_MISMATCH")231+ return null232+ }233+ if (receiverLicense == null) {234+ grant.license?.let { deps.applyLicense(it) }235+ }236+237+ // The source is recorded from the validated preparation, never from the238+ // grant: the preparation is what we validated against our terminal ledger.239+ val sourceDevice = PairedDevice(240+ deviceId = prepared.deviceId,241+ deviceName = prepared.deviceName,242+ deviceType = prepared.deviceType,243+ longTermPublicKeyHex = prepared.longTermPublicKeyHex,244+ signingPublicKeyHex = prepared.signingPublicKeyHex,245+ trustSource = "direct",246+ wsPort = prepared.wsPort,247+ rendezvousSecretHex = deps.pairState?.rendezvousSecretHex,248+ relayUrl = deps.pairState?.relayUrl ?: prepared.relayUrl,249+ pairedAt = nowMs,250+ )251+ deps.upsertPairedDeviceAndClearRevocation(sourceDevice)252+ sendFrame(channel, AdoptionFrame.Applied)253+254+ if (receiveFrame(channel) !is AdoptionFrame.Complete) {255+ deps.onError("ADOPT_COMPLETION_MISSING")256+ return null257+ }258+ return sourceDevice259+}260+261+/**262+ * SOURCE side: answer a v2 request. The receiver's validated identity is263+ * durably recorded before any root-bearing frame, and is promoted to a direct264+ * paired device only once the receiver acknowledges the vault.265+ */266+suspend fun grantAdoptionV2(267+ channel: PairingTransport,268+ request: AdoptionFrame.RequestV2,269+ deps: AdoptionSourceV2Deps,270+ nowMs: Long = System.currentTimeMillis(),271+): PairedDevice? {272+ if (!request.valid()) return null273+274+ // Acknowledge before asking the human, so the receiver can raise its own275+ // SAS prompt instead of waiting on this device's consent dialog.276+ sendFrame(channel, AdoptionFrame.ConfirmRequired)277+ if (!deps.onConsent(request)) return null278+279+ val confirmation = receiveFrame(channel)280+ if (confirmation !is AdoptionFrame.Confirm || !confirmation.confirmed) return null281+282+ fun receiverFrom(identity: AdoptionFrame.RequestV2): PairedDevice =283+ PairedDevice(284+ deviceId = identity.deviceId,285+ deviceName = identity.deviceName,286+ deviceType = identity.deviceType,287+ longTermPublicKeyHex = identity.longTermPublicKeyHex,288+ signingPublicKeyHex = identity.signingPublicKeyHex,289+ trustSource = "direct",290+ rendezvousSecretHex = deps.pairState?.rendezvousSecretHex,291+ relayUrl = deps.pairState?.relayUrl,292+ pairedAt = nowMs,293+ )294+295+ // The receiver's identity may collide with a paired device or a terminal296+ // revocation. Reject once, accept only a rotated request, then stop.297+ var receiver = receiverFrom(request)298+ if (deps.hasDeviceIdentityCollision(receiver)) {299+ sendFrame(channel, AdoptionFrame.Reject(REASON_DEVICE_ID_COLLISION))300+ val rotated = receiveFrame(channel)301+ if (rotated !is AdoptionFrame.RequestV2 || !rotated.valid()) return null302+ receiver = receiverFrom(rotated)303+ if (deps.hasDeviceIdentityCollision(receiver)) {304+ sendFrame(channel, AdoptionFrame.Reject(REASON_DEVICE_ID_COLLISION))305+ return null306+ }307+ }308+309+ var license = deps.license()310+ if (license == null && request.license != null) {311+ deps.applyLicense(request.license)312+ license = deps.license()313+ }314+ if (license == null) {315+ sendFrame(channel, AdoptionFrame.Reject(REASON_PRO_REQUIRED))316+ return null317+ }318+319+ // No root-bearing frame before this commit: afterwards the receiver is320+ // listable and revocable even if the session dies mid-grant.321+ if (!deps.persistPendingIdentity(receiver, nowMs)) return null322+323+ val rootKeyHex = deps.rootKeyHex()324+ if (!validateRootKeyHex(rootKeyHex)) return null325+326+ var sourceIdentity = deps.sourceIdentity327+ var sourceRotations = 0328+ while (true) {329+ sendFrame(330+ channel,331+ AdoptionFrame.Prepare(332+ deviceId = sourceIdentity.deviceId,333+ deviceName = sourceIdentity.deviceName,334+ deviceType = sourceIdentity.deviceType.wireValue,335+ longTermPublicKeyHex = sourceIdentity.longTermPublicKeyHex,336+ signingPublicKeyHex = sourceIdentity.signingPublicKeyHex,337+ vaultId = deps.vaultId(),338+ wsPort = sourceIdentity.wsPort,339+ relayUrl = deps.pairState?.relayUrl,340+ license = license,341+ snapshotCapable = deps.snapshotCapable(),342+ ),343+ )344+345+ val next = receiveFrame(channel)346+ if (next is AdoptionFrame.Reject &&347+ next.reason == REASON_DEVICE_ID_COLLISION &&348+ sourceRotations == 0349+ ) {350+ sourceIdentity = deps.rotateSourceIdentity()351+ sourceRotations++352+ continue353+ }354+ if (next !is AdoptionFrame.Ready) return null355+ break356+ }357+358+ // Sent with its own serializer: the v2 grant carries no source, so it is359+ // not a member of the AdoptionFrame hierarchy (see AdoptGrantV2).360+ channel.send(361+ AdoptJson.encodeToString(362+ AdoptGrantV2.serializer(),363+ AdoptGrantV2(364+ type = GRANT_TYPE,365+ rootKeyHex = rootKeyHex,366+ vaultId = deps.vaultId(),367+ license = license,368+ ),369+ ).toByteArray(Charsets.UTF_8),370+ )371+372+ if (receiveFrame(channel) !is AdoptionFrame.Applied) return null373+374+ // Promotion is legal only now: the receiver holds the vault and has said so.375+ if (!deps.completePendingIdentity(receiver)) return null376+ deps.upsertPairedDevice(receiver)377+ sendFrame(channel, AdoptionFrame.Complete)378+ return receiver379+}app/src/main/java/com/peachpasswords/sync/PendingVouchedDeviceStore.kt+46 −4
@@ -52,6 +52,18 @@5252 fun remove(id: String)5353 5454 /**55+ * Clear a pending introduction by its validated identity tuple rather than56+ * its device id. A device id alone can name two holders once the same id is57+ * re-presented with different keys, so adoption v2 must not clear by id.58+ */59+ fun removeIdentityAndReport(device: PairedDevice): Boolean {60+ return runCatching {61+ remove(device.deviceId)62+ true63+ }.getOrDefault(false)64+ }65+66+ /**5567 * Remove a set of pending introductions synchronously and report failure.5668 * Implementations must linearize the whole batch; the default exists only5769 * for small in-memory test registries that have no durable store.@@ -95,6 +107,21 @@95107 return runCatching { json.decodeFromString(listSerializer, raw) }.getOrDefault(emptyList())96108 }97109 110+ /**111+ * Finds a pending holder only when all durable identity components match.112+ * Device ids are user-visible labels and are not sufficient authentication.113+ */114+ fun get(115+ deviceId: String,116+ longTermPublicKeyHex: String,117+ signingPublicKeyHex: String,118+ ): PendingVouchedDevice? = getAll().firstOrNull {119+ it.deviceId == deviceId &&120+ it.longTermPublicKeyHex == longTermPublicKeyHex &&121+ it.signingPublicKeyHex == signingPublicKeyHex122+ }123+124+ /** Legacy UI lookup; adoption v2 uses the identity-keyed overload above. */98125 fun get(id: String): PendingVouchedDevice? = getAll().firstOrNull { it.deviceId == id }99126 100127 override fun upsert(device: PendingVouchedDevice) {@@ -102,10 +129,15 @@102129 }103130 104131 override fun upsertAndReport(device: PendingVouchedDevice): Boolean {105- // Vouch requests carry a peer-chosen name; bound it like every other106- // inbound name so the pending queue cannot grow without limit.107- val device = device.copy(deviceName = capDeviceName(device.deviceName))108- val next = (getAll().filterNot { it.deviceId == device.deviceId } + device).takeLast(MAX_PENDING)132+ // A pending holder is replaced only by the same validated identity tuple.133+ val normalized = device.copy(deviceName = capDeviceName(device.deviceName))134+ val next = (135+ getAll().filterNot {136+ it.deviceId == normalized.deviceId &&137+ it.longTermPublicKeyHex == normalized.longTermPublicKeyHex &&138+ it.signingPublicKeyHex == normalized.signingPublicKeyHex139+ } + normalized140+ ).takeLast(MAX_PENDING)109141 return commitList(next)110142 }111143 @@ -116,6 +148,16 @@116148 override fun removeAndReport(id: String): Boolean {117149 val before = getAll()118150 val after = before.filterNot { it.deviceId == id }151+ return commitWithRollback(before, after, ::commitList)152+ }153+154+ override fun removeIdentityAndReport(device: PairedDevice): Boolean {155+ val before = getAll()156+ val after = before.filterNot {157+ it.deviceId == device.deviceId &&158+ it.longTermPublicKeyHex == device.longTermPublicKeyHex &&159+ it.signingPublicKeyHex == device.signingPublicKeyHex160+ }119161 return commitWithRollback(before, after, ::commitList)120162 }121163 app/src/main/java/com/peachpasswords/sync/RelayAdoptionHost.kt+45 −27
@@ -38,7 +38,7 @@3838 ourStaticPrivateKey: ByteArray,3939 ourStaticPublicKey: ByteArray,4040 localIdentity: LocalDeviceIdentity,41- sourceDeps: AdoptionSourceDeps,41+ sourceDeps: AdoptionSourceV2Deps,4242 windowMs: Long = PAIRING_WINDOW_MS,4343 ): Flow<RelayAdoptionEvent> = callbackFlow {4444 // Pairing is also how this mesh's relay reaches a new peer: the address@@ -146,7 +146,7 @@146146 ourStaticPrivateKey: ByteArray,147147 ourStaticPublicKey: ByteArray,148148 localIdentity: LocalDeviceIdentity,149- sourceDeps: AdoptionSourceDeps,149+ sourceDeps: AdoptionSourceV2Deps,150150 confirm: suspend (sas: String, request: AdoptionFrame.Request) -> Boolean,151151 ): PairedDevice? {152152 val hello = JSONObject(String(socket.receive(), Charsets.UTF_8))@@ -183,9 +183,8 @@183183 }184184 185185 val request = receiveFrame(channel)186- require(isAdoptRequest(request)) { "expected ADOPT_REQUEST" }187- request as AdoptionFrame.Request188- if (!confirm(SASDerivation.derive(noise.handshakeHash), request)) return null186+ require(request is AdoptionFrame.Request || request is AdoptionFrame.RequestV2) { "expected ADOPT_REQUEST" }187+ if (request is AdoptionFrame.Request && !confirm(SASDerivation.derive(noise.handshakeHash), request)) return null189188 190189 val pairState = AdoptionPairState(191190 rendezvousSecretHex = Rendezvous.bytesToHex(@@ -193,35 +192,54 @@193192 ),194193 relayUrl = Rendezvous.normalizeRelayUrl(relayUrl),195194 )196- val boundDeps = object : AdoptionSourceDeps {197- override val sourceIdentity: LocalDeviceIdentity = localIdentity195+ val boundDeps = object : AdoptionSourceV2Deps {196+ override val sourceIdentity = localIdentity198197 override val pairState: AdoptionPairState = pairState199- override suspend fun rootKeyHex(): String = sourceDeps.rootKeyHex()200- override suspend fun vaultId(): String = sourceDeps.vaultId()201- override suspend fun license(): String? = sourceDeps.license()202- override suspend fun applyLicense(license: String) {203- sourceDeps.applyLicense(license)204- }205- override suspend fun onConsent(request: AdoptionFrame.Request): Boolean = true206- override suspend fun persistPendingHolder(request: AdoptionFrame.Request, nowMs: Long) =207- sourceDeps.persistPendingHolder(request, nowMs)208- override suspend fun completePendingHolder(request: AdoptionFrame.Request, device: PairedDevice) =209- sourceDeps.completePendingHolder(request, device)210- override suspend fun upsertPairedDevice(device: PairedDevice) {211- sourceDeps.upsertPairedDevice(device)212- }213- override fun hasDeviceIdentityCollision(device: PairedDevice): Boolean =214- sourceDeps.hasDeviceIdentityCollision(device)215- override suspend fun rotateSourceIdentity(): LocalDeviceIdentity =216- sourceDeps.rotateSourceIdentity()198+ override suspend fun rootKeyHex() = sourceDeps.rootKeyHex()199+ override suspend fun vaultId() = sourceDeps.vaultId()200+ override suspend fun license() = sourceDeps.license()201+ override suspend fun applyLicense(license: String) = sourceDeps.applyLicense(license)202+ override suspend fun onConsent(request: AdoptionFrame.Request) = true203+204+ // The transcript sends ADOPT_CONFIRM_REQUIRED before calling this, so205+ // the receiver's own prompt is already live when we ask our human to206+ // compare the same SAS. The request is only a prompt label here.207+ override suspend fun onConsent(request: AdoptionFrame.RequestV2): Boolean =208+ confirm(209+ SASDerivation.derive(noise.handshakeHash),210+ AdoptionFrame.Request(211+ sessionRequestId = request.deviceId,212+ deviceName = request.deviceName,213+ deviceType = request.deviceType,214+ license = request.license,215+ snapshotCapable = request.snapshotCapable,216+ ),217+ )218+ override suspend fun persistPendingHolder(request: AdoptionFrame.Request, nowMs: Long) = sourceDeps.persistPendingHolder(request, nowMs)219+ override suspend fun completePendingHolder(request: AdoptionFrame.Request, device: PairedDevice) = sourceDeps.completePendingHolder(request, device)220+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = sourceDeps.persistPendingIdentity(device, nowMs)221+ override suspend fun completePendingIdentity(device: PairedDevice) = sourceDeps.completePendingIdentity(device)222+ override suspend fun upsertPairedDevice(device: PairedDevice) = sourceDeps.upsertPairedDevice(device)223+ override fun hasDeviceIdentityCollision(device: PairedDevice) = sourceDeps.hasDeviceIdentityCollision(device)224+ override suspend fun rotateSourceIdentity() = sourceDeps.rotateSourceIdentity()225+ override fun snapshotCapable() = true217226 override suspend fun vaultSnapshot() = sourceDeps.vaultSnapshot()218227 override suspend fun outgoingDeviceManifest() = sourceDeps.outgoingDeviceManifest()219228 override suspend fun markSynced(deviceId: String) = sourceDeps.markSynced(deviceId)220229 override suspend fun duressSlotJson() = sourceDeps.duressSlotJson()221230 }222- val adopted = grantAdoption(channel, request, boundDeps) ?: return null231+ val adopted = when (request) {232+ is AdoptionFrame.RequestV2 -> grantAdoptionV2(channel, request, boundDeps)233+ is AdoptionFrame.Request -> grantAdoption(channel, request, boundDeps)234+ else -> null235+ } ?: return null223236 // If the receiver advertised snapshot support, send the vault inline.224- if (request.snapshotCapable == true) {237+ val receiverWantsSnapshot = when (request) {238+ is AdoptionFrame.Request -> request.snapshotCapable == true239+ is AdoptionFrame.RequestV2 -> request.snapshotCapable == true240+ else -> false241+ }242+ if (receiverWantsSnapshot) {225243 try {226244 val snapshot = boundDeps.vaultSnapshot()227245 if (snapshot != null) {app/src/main/java/com/peachpasswords/sync/RelayAdoptionReceiver.kt+64 −18
@@ -24,7 +24,7 @@2424 */2525 suspend fun adopt(2626 encodedInvitation: String,27- deps: AdoptionReceiverDeps,27+ deps: AdoptionReceiverV2Deps,2828 confirm: suspend (sas: String) -> Boolean,2929 windowMs: Long = PAIRING_WINDOW_MS,3030 ): PairedDevice {@@ -52,7 +52,7 @@5252 */5353 suspend fun grantFromInvitation(5454 encodedInvitation: String,55- sourceDeps: AdoptionSourceDeps,55+ sourceDeps: AdoptionSourceV2Deps,5656 confirm: suspend (sas: String, request: AdoptionFrame.Request) -> Boolean,5757 windowMs: Long = PAIRING_WINDOW_MS,5858 ): PairedDevice {@@ -83,7 +83,7 @@8383 internal suspend fun adoptFromRelaySocket(8484 socket: RelayBinarySocket,8585 invitation: PairingInvitation,86- deps: AdoptionReceiverDeps,86+ deps: AdoptionReceiverV2Deps,8787 confirm: suspend (sas: String) -> Boolean,8888 windowMs: Long = PAIRING_WINDOW_MS,8989 ): PairedDevice {@@ -118,7 +118,7 @@118118 internal suspend fun grantFromRelaySocket(119119 socket: RelayBinarySocket,120120 invitation: PairingInvitation,121- sourceDeps: AdoptionSourceDeps,121+ sourceDeps: AdoptionSourceV2Deps,122122 confirm: suspend (sas: String, request: AdoptionFrame.Request) -> Boolean,123123 windowMs: Long = PAIRING_WINDOW_MS,124124 ): PairedDevice {@@ -150,7 +150,7 @@150150 internal suspend fun runRelayAdoptionReceiverSession(151151 socket: RelayBinarySocket,152152 invitation: PairingInvitation,153- receiverDeps: AdoptionReceiverDeps,153+ receiverDeps: AdoptionReceiverV2Deps,154154 confirm: suspend (sas: String) -> Boolean,155155 ): PairedDevice? {156156 socket.send(@@ -196,7 +196,7 @@196196 ),197197 relayUrl = invitation.relayUrl,198198 )199- val boundDeps = object : AdoptionReceiverDeps {199+ val boundDeps = object : AdoptionReceiverV2Deps {200200 override val deviceName = receiverDeps.deviceName201201 override val deviceType = receiverDeps.deviceType202202 override val pairState = pairState@@ -204,6 +204,20 @@204204 override suspend fun confirmSas(): Boolean =205205 confirm(SASDerivation.derive(noise.handshakeHash))206206 207+ // The v2 transcript presents this device's durable identity, which208+ // exists before the vault does; the v1 path still derives its own.209+ override fun localIdentity(): LocalDeviceIdentity = receiverDeps.localIdentity()210+211+ override suspend fun rotateLocalIdentity(): LocalDeviceIdentity =212+ receiverDeps.rotateLocalIdentity()213+214+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {215+ receiverDeps.validateSource(prepare)216+ }217+218+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare): Boolean =219+ receiverDeps.hasSourceIdentityCollision(prepare)220+207221 override suspend fun validateSource(source: AdoptionFrame.Source) {208222 receiverDeps.validateSource(source)209223 }@@ -250,14 +264,13 @@250264 receiverDeps.markSynced(deviceId)251265 }252266 }253- // Capture the source's ADOPT_GRANT.snapshot_capable echo so we can skip254- // the 15s inline-snapshot wait when the source has nothing to send.255- // Default false = "pre-C source, no echo" = skip the wait.267+ // Capture the source's snapshot capability so we can skip the 15s268+ // inline-snapshot wait when the source has nothing to send.256269 var sourceCanSendSnapshot = false257- val adopted = requestAdoption(270+ val adopted = requestAdoptionV2(258271 channel,259272 boundDeps,260- onGrant = { grant -> sourceCanSendSnapshot = grant.snapshotCapable },273+ onPrepare = { prepare -> sourceCanSendSnapshot = prepare.snapshotCapable == true },261274 ) ?: return null262275 if (sourceCanSendSnapshot) {263276 // Try to receive the inline vault snapshot.@@ -314,7 +327,7 @@314327 internal suspend fun runRelayAdoptionInitiatorSourceSession(315328 socket: RelayBinarySocket,316329 invitation: PairingInvitation,317- sourceDeps: AdoptionSourceDeps,330+ sourceDeps: AdoptionSourceV2Deps,318331 confirm: suspend (sas: String, request: AdoptionFrame.Request) -> Boolean,319332 ): PairedDevice? {320333 socket.send(@@ -361,9 +374,7 @@361374 override suspend fun close() = socket.close()362375 }363376 val request = receiveFrame(channel)364- if (!isAdoptRequest(request)) return null365- request as AdoptionFrame.Request366- if (!confirm(SASDerivation.derive(noise.handshakeHash), request)) return null377+ if (request !is AdoptionFrame.RequestV2 && !isAdoptRequest(request)) return null367378 368379 val pairState = AdoptionPairState(369380 rendezvousSecretHex = Rendezvous.bytesToHex(@@ -371,7 +382,7 @@371382 ),372383 relayUrl = invitation.relayUrl,373384 )374- val boundDeps = object : AdoptionSourceDeps {385+ val boundDeps = object : AdoptionSourceV2Deps {375386 override val sourceIdentity = sourceDeps.sourceIdentity376387 override val pairState = pairState377388 override suspend fun rootKeyHex(): String = sourceDeps.rootKeyHex()@@ -381,10 +392,31 @@381392 sourceDeps.applyLicense(license)382393 }383394 override suspend fun onConsent(request: AdoptionFrame.Request): Boolean = true395+396+ // Called by the v2 transcript after ADOPT_CONFIRM_REQUIRED goes out,397+ // so both prompts are live at once. The prompt itself is the same398+ // human SAS comparison as v1; the label is never persisted.399+ override suspend fun onConsent(request: AdoptionFrame.RequestV2): Boolean =400+ confirm(401+ SASDerivation.derive(noise.handshakeHash),402+ AdoptionFrame.Request(403+ sessionRequestId = request.deviceId,404+ deviceName = request.deviceName,405+ deviceType = request.deviceType,406+ license = request.license,407+ snapshotCapable = request.snapshotCapable,408+ ),409+ )410+384411 override suspend fun persistPendingHolder(request: AdoptionFrame.Request, nowMs: Long) =385412 sourceDeps.persistPendingHolder(request, nowMs)386413 override suspend fun completePendingHolder(request: AdoptionFrame.Request, device: PairedDevice) =387414 sourceDeps.completePendingHolder(request, device)415+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) =416+ sourceDeps.persistPendingIdentity(device, nowMs)417+ override suspend fun completePendingIdentity(device: PairedDevice) =418+ sourceDeps.completePendingIdentity(device)419+ override fun snapshotCapable(): Boolean = true388420 override suspend fun upsertPairedDevice(device: PairedDevice) {389421 sourceDeps.upsertPairedDevice(device)390422 }@@ -397,9 +429,23 @@397429 override suspend fun markSynced(deviceId: String) = sourceDeps.markSynced(deviceId)398430 override suspend fun duressSlotJson() = sourceDeps.duressSlotJson()399431 }400- val adopted = grantAdoption(channel, request, boundDeps) ?: return null432+ // A v2 receiver introduces itself first; a v1 receiver still opens with433+ // the label-only ADOPT_REQUEST and is served by the legacy path.434+ val adopted = when (request) {435+ is AdoptionFrame.RequestV2 -> grantAdoptionV2(channel, request, boundDeps)436+ is AdoptionFrame.Request -> {437+ if (!confirm(SASDerivation.derive(noise.handshakeHash), request)) return null438+ grantAdoption(channel, request, boundDeps)439+ }440+ else -> null441+ } ?: return null401442 // If the receiver advertised snapshot support, send the vault inline.402- if (request.snapshotCapable == true) {443+ val receiverWantsSnapshot = when (request) {444+ is AdoptionFrame.Request -> request.snapshotCapable == true445+ is AdoptionFrame.RequestV2 -> request.snapshotCapable == true446+ else -> false447+ }448+ if (receiverWantsSnapshot) {403449 try {404450 val snapshot = boundDeps.vaultSnapshot()405451 if (snapshot != null) {app/src/main/java/com/peachpasswords/sync/VaultAdopt.kt+52 −21
@@ -54,13 +54,7 @@5454 @SerialName("vault_id") val vaultId: String,5555 val license: String? = null,5656 val source: Source,57- // SOURCE echoes receiver's ADOPT_REQUEST.snapshot_capable so the receiver58- // can skip its 15s inline-snapshot wait when the source has nothing to send.59- // Default false is OMITTED on the wire (encodeDefaults = false) — the60- // browser always serializes explicit true OR false via JSON.stringify, but61- // Android only serializes true; both receivers default to "skip wait" when62- // the field is absent, so the divergence is invisible to the gate.63- // Pre-C sources never set the field and decode to false here.57+ // v1-only receiver capability metadata.6458 @SerialName("snapshot_capable") val snapshotCapable: Boolean = false,6559 ) : AdoptionFrame()6660 @@ -129,7 +123,37 @@129123 @Serializable130124 @SerialName("ADOPT_DEVICE_MANIFEST_APPLIED")131125 data object DeviceManifestApplied : AdoptionFrame()126+ @Serializable127+ @SerialName("ADOPT_REQUEST_V2")128+ data class RequestV2(129+ @SerialName("adoptionVersion") val adoptionVersion: Int,130+ @SerialName("device_id") val deviceId: String,131+ @SerialName("device_name") val deviceName: String,132+ @SerialName("device_type") val deviceType: String,133+ @SerialName("long_term_public_key_hex") val longTermPublicKeyHex: String,134+ @SerialName("signing_public_key_hex") val signingPublicKeyHex: String,135+ val license: String? = null,136+ @SerialName("snapshot_capable") val snapshotCapable: Boolean? = null,137+ ) : AdoptionFrame()132138 139+ @Serializable @SerialName("ADOPT_CONFIRM_REQUIRED")140+ data object ConfirmRequired : AdoptionFrame()141+142+ @Serializable @SerialName("ADOPT_PREPARE")143+ data class Prepare(144+ @SerialName("device_id") val deviceId: String,145+ @SerialName("device_name") val deviceName: String,146+ @SerialName("device_type") val deviceType: String,147+ @SerialName("long_term_public_key_hex") val longTermPublicKeyHex: String,148+ @SerialName("signing_public_key_hex") val signingPublicKeyHex: String,149+ @SerialName("vault_id") val vaultId: String,150+ @SerialName("ws_port") val wsPort: Int? = null,151+ @SerialName("relay_url") val relayUrl: String? = null,152+ val license: String? = null,153+ @SerialName("snapshot_capable") val snapshotCapable: Boolean? = null,154+ ) : AdoptionFrame()155+ @Serializable @SerialName("ADOPT_READY")156+ data object Ready : AdoptionFrame()133157 @Serializable134158 data class Source(135159 @SerialName("device_id") val deviceId: String,@@ -320,7 +344,6 @@320344 suspend fun license(): String? = null321345 /** Validate and durably store a Pro key offered by the receiver. */322346 suspend fun applyLicense(license: String) {}323-324347 /**325348 * Ask the user to approve handing this vault to the requesting device. The326349 * request's name/type/label are for the human to read; the decision must not@@ -349,7 +372,7 @@349372 suspend fun duressSlotJson(): String? = null350373 }351374 352-private val Hex64 = Regex("^[0-9a-f]{64}\$")375+internal val Hex64 = Regex("^[0-9a-f]{64}$")353376 354377 fun validateRootKeyHex(rootKeyHex: String?): Boolean = rootKeyHex != null && Hex64.matches(rootKeyHex)355378 @@ -453,15 +476,19 @@453476 return null454477 }455478 456- deps.validateSource(grant.source)479+ var acceptedGrant = grant480+ var acceptedSource = grant.source ?: run {481+ deps.onError("ADOPT_UNEXPECTED_FRAME")482+ return null483+ }484+ deps.validateSource(acceptedSource)457485 458486 // Check the source's identity against the local revocation ledger. A459487 // previously-revoked device must present a fresh identity so that stale460488 // signed revocations held by other mesh peers cannot remove it after461489 // re-pair. If the source's identity is revoked, send ADOPT_DEVICE_ID_COLLISION462490 // and wait for a fresh grant (one retry).463- var acceptedGrant = grant464- if (deps.hasSourceIdentityCollision(acceptedGrant.source)) {491+ if (deps.hasSourceIdentityCollision(acceptedSource)) {465492 sendFrame(channel, AdoptionFrame.Reject("ADOPT_DEVICE_ID_COLLISION"))466493 val retry = receiveFrame(channel)467494 if (!isAdoptGrant(retry)) {@@ -469,7 +496,11 @@469496 return null470497 }471498 acceptedGrant = retry as AdoptionFrame.Grant472- if (deps.hasSourceIdentityCollision(acceptedGrant.source)) {499+ acceptedSource = acceptedGrant.source ?: run {500+ deps.onError("ADOPT_UNEXPECTED_FRAME")501+ return null502+ }503+ if (deps.hasSourceIdentityCollision(acceptedSource)) {473504 sendFrame(channel, AdoptionFrame.Reject("ADOPT_DEVICE_ID_COLLISION"))474505 deps.onError("ADOPT_SOURCE_COLLISION_NOT_RESOLVED")475506 return null@@ -516,15 +547,15 @@516547 }517548 518549 val sourceDevice = PairedDevice(519- deviceId = acceptedGrant.source.deviceId,520- deviceName = acceptedGrant.source.deviceName,521- deviceType = acceptedGrant.source.deviceType,522- longTermPublicKeyHex = acceptedGrant.source.longTermPublicKeyHex,523- signingPublicKeyHex = acceptedGrant.source.signingPublicKeyHex,550+ deviceId = acceptedSource.deviceId,551+ deviceName = acceptedSource.deviceName,552+ deviceType = acceptedSource.deviceType,553+ longTermPublicKeyHex = acceptedSource.longTermPublicKeyHex,554+ signingPublicKeyHex = acceptedSource.signingPublicKeyHex,524555 trustSource = "direct",525- wsPort = acceptedGrant.source.wsPort,556+ wsPort = acceptedSource.wsPort,526557 rendezvousSecretHex = deps.pairState?.rendezvousSecretHex,527- relayUrl = deps.pairState?.relayUrl ?: acceptedGrant.source.relayUrl,558+ relayUrl = deps.pairState?.relayUrl ?: acceptedSource.relayUrl,528559 pairedAt = nowMs(),529560 )530561 // A physically confirmed direct re-pair is the sole path allowed to lift@@ -832,5 +863,5 @@832863 return ReceivedSnapshot(acc.entries, acc.tombstones, acc.duressSlot)833864 }834865 835-private fun isDeviceType(value: String): Boolean =866+fun isDeviceType(value: String): Boolean =836867 DeviceType.entries.any { it.wireValue == value }app/src/main/java/com/peachpasswords/ui/pairing/AdoptVaultViewModel.kt+56 −7
@@ -5,14 +5,18 @@55 import androidx.lifecycle.ViewModel66 import androidx.lifecycle.viewModelScope77 import com.peachpasswords.license.LicenseRepository8+import com.peachpasswords.sync.AdoptionPairState89 import com.peachpasswords.sync.AdoptionReceiverDeps10+import com.peachpasswords.sync.AdoptionReceiverV2Deps911 import com.peachpasswords.sync.AdoptionSourceDeps12+import com.peachpasswords.sync.AdoptionSourceV2Deps1013 import com.peachpasswords.sync.BackgroundSyncPreference1114 import com.peachpasswords.sync.DeviceType1215 import com.peachpasswords.sync.AdoptionFrame1316 import com.peachpasswords.sync.LocalDeviceIdentity1417 import com.peachpasswords.sync.PairedDevice1518 import com.peachpasswords.sync.PairedDeviceStore19+import com.peachpasswords.sync.PendingVouchedDevice1620 import com.peachpasswords.sync.PendingVouchedDeviceStore1721 import com.peachpasswords.sync.SignedDeviceManifest1822 import com.peachpasswords.sync.VaultSyncAdapter@@ -23,11 +27,10 @@2327 import com.peachpasswords.sync.VaultStatus2428 import com.peachpasswords.sync.buildLocalIdentity2529 import com.peachpasswords.sync.computeVaultId26-import com.peachpasswords.sync.loadOrCreateLocalIdentity27-import com.peachpasswords.sync.localSyncKeypair2830 import com.peachpasswords.sync.getDeviceName29-import com.peachpasswords.sync.loadOrCreateLocalIdentity3031 import com.peachpasswords.sync.hexToPubkey32+import com.peachpasswords.sync.loadOrCreateLocalIdentity33+import com.peachpasswords.sync.localSyncKeypair3134 import com.peachpasswords.sync.rotateDeviceId3235 import com.peachpasswords.sync.parsePairingInvitation3336 import com.peachpasswords.ui.security.scorePassword@@ -237,10 +240,22 @@237240 _state.value = initialAdoptVaultState(joining)238241 }239242 240- private fun receiverDeps(): AdoptionReceiverDeps =241- object : AdoptionReceiverDeps {243+ private fun receiverDeps(): AdoptionReceiverV2Deps =244+ object : AdoptionReceiverV2Deps {242245 override val deviceName = getDeviceName(appContext)243246 override val deviceType = DeviceType.ANDROID247+ override fun localIdentity(): LocalDeviceIdentity =248+ buildLocalIdentity(appContext, loadOrCreateLocalIdentity(appContext))249+ // Bound to the relay session by RelayAdoptionReceiver, which wraps250+ // this object; the ViewModel itself holds no Noise session.251+ override val pairState: AdoptionPairState? get() = null252+ override suspend fun rotateLocalIdentity(): LocalDeviceIdentity {253+ rotateDeviceId(appContext)254+ return localIdentity()255+ }256+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}257+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare): Boolean =258+ devices.isRevoked(prepare.deviceId, prepare.longTermPublicKeyHex)244259 override fun generateDeviceId(): String = UUID.randomUUID().toString()245260 246261 // RelayAdoptionReceiver replaces this with the SAS bound to its@@ -367,10 +382,16 @@367382 }368383 }369384 370- private fun sourceDeps(identity: LocalDeviceIdentity): AdoptionSourceDeps =371- object : AdoptionSourceDeps {385+ private fun sourceDeps(identity: LocalDeviceIdentity): AdoptionSourceV2Deps =386+ object : AdoptionSourceV2Deps {372387 override val sourceIdentity: LocalDeviceIdentity = identity373388 389+ // Bound to the relay session by RelayAdoptionHost / the receiver390+ // session, which wrap this object.391+ override val pairState: AdoptionPairState? get() = null392+393+ override fun snapshotCapable(): Boolean = true394+374395 override suspend fun rootKeyHex(): String {375396 val root = vault.syncMasterKey()376397 ?: throw IllegalStateException("vault_locked")@@ -393,6 +414,34 @@393414 }394415 }395416 417+ override suspend fun onConsent(request: AdoptionFrame.RequestV2): Boolean = true418+419+ // The v2 holder is keyed on the validated identity, never on the420+ // v1 request label that ADOPT_REQUEST_V2 does not even carry.421+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long): Boolean {422+ val deviceName = device.deviceName ?: return false423+ val deviceType = device.deviceType ?: return false424+ val longTermKey = device.longTermPublicKeyHex ?: return false425+ val signingKey = device.signingPublicKeyHex ?: return false426+ return runCatching {427+ pendingVouchedStore.upsertAndReport(428+ PendingVouchedDevice(429+ deviceId = device.deviceId,430+ deviceName = deviceName,431+ deviceType = deviceType,432+ longTermPublicKeyHex = longTermKey,433+ signingPublicKeyHex = signingKey,434+ wsPort = device.wsPort,435+ pairedAt = nowMs,436+ receivedAt = nowMs,437+ vouchedByDeviceId = identity.deviceId,438+ ),439+ )440+ }.getOrDefault(false)441+ }442+443+ override suspend fun completePendingIdentity(device: PairedDevice): Boolean =444+ runCatching { pendingVouchedStore.removeIdentityAndReport(device) }.getOrDefault(false)396445 override suspend fun onConsent(request: AdoptionFrame.Request): Boolean = true397446 override suspend fun persistPendingHolder(request: AdoptionFrame.Request, nowMs: Long): Boolean {398447 return runCatching {app/src/main/java/com/peachpasswords/ui/pairing/CodePairViewModel.kt+40 −3
@@ -17,7 +17,9 @@1717 import com.peachpasswords.sync.PendingVouchedDevice1818 import com.peachpasswords.sync.PendingVouchedDeviceStore1919 import com.peachpasswords.sync.AdoptionFrame20+import com.peachpasswords.sync.AdoptionPairState2021 import com.peachpasswords.sync.AdoptionSourceDeps22+import com.peachpasswords.sync.AdoptionSourceV2Deps2123 import com.peachpasswords.sync.LocalDeviceIdentity2224 import com.peachpasswords.sync.PairedDevice2325 import com.peachpasswords.sync.PairedDeviceStore@@ -121,7 +123,7 @@121123 privateKey: ByteArray,122124 publicKey: ByteArray,123125 identity: LocalDeviceIdentity,124- sourceDeps: AdoptionSourceDeps,126+ sourceDeps: AdoptionSourceV2Deps,125127 ) {126128 collectJob = viewModelScope.launch {127129 try {@@ -161,9 +163,44 @@161163 }162164 }163165 164- private fun sourceDeps(identity: LocalDeviceIdentity): AdoptionSourceDeps =165- object : AdoptionSourceDeps {166+ private fun sourceDeps(identity: LocalDeviceIdentity): AdoptionSourceV2Deps =167+ object : AdoptionSourceV2Deps {166168 override val sourceIdentity: LocalDeviceIdentity = identity169+170+ // The relay host binds the live pair state and the human SAS prompt171+ // when it wraps this object.172+ override val pairState: AdoptionPairState? get() = null173+174+ override fun snapshotCapable(): Boolean = true175+176+ override suspend fun onConsent(request: AdoptionFrame.RequestV2): Boolean = true177+178+ // The v2 holder is keyed on the validated identity. ADOPT_REQUEST_V2179+ // carries one; there is no request label to key on.180+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long): Boolean {181+ val deviceName = device.deviceName ?: return false182+ val deviceType = device.deviceType ?: return false183+ val longTermKey = device.longTermPublicKeyHex ?: return false184+ val signingKey = device.signingPublicKeyHex ?: return false185+ return runCatching {186+ pendingVouchedStore.upsertAndReport(187+ PendingVouchedDevice(188+ deviceId = device.deviceId,189+ deviceName = deviceName,190+ deviceType = deviceType,191+ longTermPublicKeyHex = longTermKey,192+ signingPublicKeyHex = signingKey,193+ wsPort = device.wsPort,194+ pairedAt = nowMs,195+ receivedAt = nowMs,196+ vouchedByDeviceId = identity.deviceId,197+ ),198+ )199+ }.getOrDefault(false)200+ }201+202+ override suspend fun completePendingIdentity(device: PairedDevice): Boolean =203+ runCatching { pendingVouchedStore.removeIdentityAndReport(device) }.getOrDefault(false)167204 168205 override suspend fun rootKeyHex(): String {169206 val root = vault.syncMasterKey()app/src/main/java/com/peachpasswords/ui/sync/SyncViewModel.kt+6 −2
@@ -156,8 +156,12 @@156156 157157 fun confirmVouchedDevice(id: String) = viewModelScope.launch {158158 if (isDecoySession()) return@launch159- val pending = pendingVouchedStore.get(id) ?: return@launch160- // can predate the revocation that names it, so revocation is re-checked159+ val candidate = pendingVouchedStore.get(id) ?: return@launch160+ val pending = pendingVouchedStore.get(161+ candidate.deviceId,162+ candidate.longTermPublicKeyHex,163+ candidate.signingPublicKeyHex,164+ ) ?: return@launch161165 // here rather than trusted to have swept the queue.162166 if (deviceStore.isRevoked(pending.deviceId, pending.longTermPublicKeyHex)) {163167 pendingVouchedStore.removeBatch(setOf(id))app/src/test/java/com/peachpasswords/sync/RelayAdoptionHostTest.kt+56 −8
@@ -105,12 +105,19 @@105105 ourStaticPrivateKey = sourceKeys.secretKey,106106 ourStaticPublicKey = sourceKeys.publicKey,107107 localIdentity = sourceIdentity,108- sourceDeps = object : AdoptionSourceDeps {108+ sourceDeps = object : AdoptionSourceV2Deps {109+ override suspend fun rotateSourceIdentity() = sourceIdentity110+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false111+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true112+ override suspend fun completePendingIdentity(device: PairedDevice) = true113+ override fun snapshotCapable() = true114+109115 override val sourceIdentity = sourceIdentity110116 override suspend fun rootKeyHex() = Rendezvous.bytesToHex(sourceRoot)111117 override suspend fun vaultId() = computeVaultId(sourceRoot)112118 override suspend fun license() = "PPK-test"113119 override suspend fun onConsent(request: AdoptionFrame.Request) = true120+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true114121 override suspend fun upsertPairedDevice(device: PairedDevice) {115122 sourceStored = device116123 }@@ -137,7 +144,12 @@137144 val channel = encryptedChannel(receiverSocket, noise)138145 val received = requestAdoption(139146 channel,140- object : AdoptionReceiverDeps {147+ object : AdoptionReceiverV2Deps {148+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")149+ override suspend fun rotateLocalIdentity() = localIdentity()150+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}151+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false152+141153 override val deviceName = "receiver"142154 override val deviceType = DeviceType.EXTENSION143155 override val pairState = AdoptionPairState(@@ -179,7 +191,13 @@179191 sourceKeys.secretKey,180192 sourceKeys.publicKey,181193 identity("source", sourceKeys.publicKey),182- object : AdoptionSourceDeps {194+ object : AdoptionSourceV2Deps {195+ override suspend fun rotateSourceIdentity() = sourceIdentity196+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false197+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true198+ override suspend fun completePendingIdentity(device: PairedDevice) = true199+ override fun snapshotCapable() = true200+183201 override val sourceIdentity = identity("source", sourceKeys.publicKey)184202 override suspend fun rootKeyHex(): String {185203 rootRequested.set(true)@@ -187,6 +205,7 @@187205 }188206 override suspend fun vaultId() = computeVaultId(root)189207 override suspend fun onConsent(request: AdoptionFrame.Request) = true208+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true190209 override suspend fun upsertPairedDevice(device: PairedDevice) = Unit191210 },192211 confirm = { _, _ -> false },@@ -231,12 +250,19 @@231250 sourceKeys.secretKey,232251 sourceKeys.publicKey,233252 sourceIdentity,234- object : AdoptionSourceDeps {253+ object : AdoptionSourceV2Deps {254+ override suspend fun rotateSourceIdentity() = sourceIdentity255+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false256+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true257+ override suspend fun completePendingIdentity(device: PairedDevice) = true258+ override fun snapshotCapable() = true259+235260 override val sourceIdentity = sourceIdentity236261 override suspend fun rootKeyHex() = Rendezvous.bytesToHex(root)237262 override suspend fun vaultId() = computeVaultId(root)238263 override suspend fun license() = "PPK-test"239264 override suspend fun onConsent(request: AdoptionFrame.Request) = true265+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true240266 override suspend fun upsertPairedDevice(device: PairedDevice) {241267 sourceStored = device242268 }@@ -256,7 +282,12 @@256282 token,257283 noiseStaticPublicKeyHex = Rendezvous.bytesToHex(sourceKeys.publicKey),258284 ),259- deps = object : AdoptionReceiverDeps {285+ deps = object : AdoptionReceiverV2Deps {286+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")287+ override suspend fun rotateLocalIdentity() = localIdentity()288+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}289+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false290+260291 override val deviceName = "receiver"261292 override val deviceType = DeviceType.ANDROID262293 override fun generateDeviceId() = "session-only-request"@@ -303,7 +334,13 @@303334 sourceKeys.secretKey,304335 sourceKeys.publicKey,305336 identity("source", sourceKeys.publicKey),306- object : AdoptionSourceDeps {337+ object : AdoptionSourceV2Deps {338+ override suspend fun rotateSourceIdentity() = sourceIdentity339+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false340+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true341+ override suspend fun completePendingIdentity(device: PairedDevice) = true342+ override fun snapshotCapable() = true343+307344 override val sourceIdentity = identity("source", sourceKeys.publicKey)308345 override suspend fun rootKeyHex(): String {309346 rootRequested.set(true)@@ -311,6 +348,7 @@311348 }312349 override suspend fun vaultId() = computeVaultId(root)313350 override suspend fun onConsent(request: AdoptionFrame.Request) = true351+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true314352 override suspend fun upsertPairedDevice(device: PairedDevice) = Unit315353 },316354 confirm = { _, _ -> true },@@ -324,7 +362,12 @@324362 token,325363 noiseStaticPublicKeyHex = Rendezvous.bytesToHex(sourceKeys.publicKey),326364 ),327- object : AdoptionReceiverDeps {365+ object : AdoptionReceiverV2Deps {366+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")367+ override suspend fun rotateLocalIdentity() = localIdentity()368+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}369+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false370+328371 override val deviceName = "receiver"329372 override val deviceType = DeviceType.ANDROID330373 override fun generateDeviceId() = "session-only-request"@@ -366,7 +409,12 @@366409 "wss://relay.example.test",367410 "AAECAwQFBgcICQoLDA0ODw",368411 ),369- object : AdoptionReceiverDeps {412+ object : AdoptionReceiverV2Deps {413+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")414+ override suspend fun rotateLocalIdentity() = localIdentity()415+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}416+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false417+370418 override val deviceName = "receiver"371419 override val deviceType = DeviceType.ANDROID372420 override fun generateDeviceId() = "request"app/src/test/java/com/peachpasswords/sync/RelayAdoptionInitiatorSourceTest.kt+65 −9
@@ -83,12 +83,19 @@8383 VaultStatus.EMPTY,8484 Rendezvous.bytesToHex(responderKeys.publicKey),8585 ),86- sourceDeps = object : AdoptionSourceDeps {86+ sourceDeps = object : AdoptionSourceV2Deps {87+ override suspend fun rotateSourceIdentity() = sourceIdentity88+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false89+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true90+ override suspend fun completePendingIdentity(device: PairedDevice) = true91+ override fun snapshotCapable() = true92+8793 override val sourceIdentity = phoneIdentity8894 override suspend fun rootKeyHex() = Rendezvous.bytesToHex(root)8995 override suspend fun vaultId() = computeVaultId(root)9096 override suspend fun license() = "PPK-test"9197 override suspend fun onConsent(request: AdoptionFrame.Request) = true98+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true9299 override suspend fun upsertPairedDevice(device: PairedDevice) {93100 phoneStored = device94101 }@@ -129,7 +136,12 @@129136 val responderJob = async {130137 requestAdoption(131138 channel = channel,132- deps = object : AdoptionReceiverDeps {139+ deps = object : AdoptionReceiverV2Deps {140+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")141+ override suspend fun rotateLocalIdentity() = localIdentity()142+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}143+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false144+133145 override val deviceName = responderIdentity.deviceName134146 override val deviceType = DeviceType.EXTENSION135147 override fun generateDeviceId() = "session-only"@@ -187,12 +199,18 @@187199 VaultStatus.EMPTY,188200 Rendezvous.bytesToHex(responderKeys.publicKey),189201 ),190- sourceDeps = object : AdoptionSourceDeps {202+ sourceDeps = object : AdoptionSourceV2Deps {203+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false204+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true205+ override suspend fun completePendingIdentity(device: PairedDevice) = true206+ override fun snapshotCapable() = true207+191208 override val sourceIdentity = phoneIdentity192209 override suspend fun rootKeyHex() = Rendezvous.bytesToHex(root)193210 override suspend fun vaultId() = computeVaultId(root)194211 override suspend fun license() = "PPK-test"195212 override suspend fun onConsent(request: AdoptionFrame.Request) = true213+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true196214 override suspend fun rotateSourceIdentity(): LocalDeviceIdentity {197215 rotations++198216 return rotatedPhoneIdentity@@ -225,7 +243,12 @@225243 val responderJob = async {226244 requestAdoption(227245 channel,228- object : AdoptionReceiverDeps {246+ object : AdoptionReceiverV2Deps {247+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")248+ override suspend fun rotateLocalIdentity() = localIdentity()249+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}250+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false251+229252 override val deviceName = responderIdentity.deviceName230253 override val deviceType = DeviceType.EXTENSION231254 override fun generateDeviceId() = "session-only"@@ -299,7 +322,13 @@299322 VaultStatus.EMPTY,300323 Rendezvous.bytesToHex(responderKeys.publicKey),301324 ),302- sourceDeps = object : AdoptionSourceDeps {325+ sourceDeps = object : AdoptionSourceV2Deps {326+ override suspend fun rotateSourceIdentity() = sourceIdentity327+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false328+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true329+ override suspend fun completePendingIdentity(device: PairedDevice) = true330+ override fun snapshotCapable() = true331+303332 override val sourceIdentity =304333 identity("phone", deriveSyncIdentityKeypair(root, "phone-id").publicKey)305334 override suspend fun rootKeyHex(): String {@@ -308,6 +337,7 @@308337 }309338 override suspend fun vaultId() = computeVaultId(root)310339 override suspend fun onConsent(request: AdoptionFrame.Request) = true340+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true311341 override suspend fun upsertPairedDevice(device: PairedDevice) = Unit312342 },313343 confirm = { _, _ -> true },@@ -355,12 +385,19 @@355385 "AAECAwQFBgcICQoLDA0ODw",356386 VaultStatus.EMPTY,357387 ),358- sourceDeps = object : AdoptionSourceDeps {388+ sourceDeps = object : AdoptionSourceV2Deps {389+ override suspend fun rotateSourceIdentity() = sourceIdentity390+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false391+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true392+ override suspend fun completePendingIdentity(device: PairedDevice) = true393+ override fun snapshotCapable() = true394+359395 override val sourceIdentity =360396 identity("phone", deriveSyncIdentityKeypair(root, "phone-id").publicKey)361397 override suspend fun rootKeyHex() = Rendezvous.bytesToHex(root)362398 override suspend fun vaultId() = computeVaultId(root)363399 override suspend fun onConsent(request: AdoptionFrame.Request) = true400+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true364401 override suspend fun upsertPairedDevice(device: PairedDevice) = Unit365402 },366403 confirm = { _, _ -> true },@@ -404,7 +441,13 @@404441 VaultStatus.EMPTY,405442 Rendezvous.bytesToHex(responderKeys.publicKey),406443 ),407- sourceDeps = object : AdoptionSourceDeps {444+ sourceDeps = object : AdoptionSourceV2Deps {445+ override suspend fun rotateSourceIdentity() = sourceIdentity446+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false447+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true448+ override suspend fun completePendingIdentity(device: PairedDevice) = true449+ override fun snapshotCapable() = true450+408451 override val sourceIdentity = identity("phone", phoneKeys.publicKey)409452 override suspend fun rootKeyHex(): String {410453 rootRequested = true@@ -412,6 +455,7 @@412455 }413456 override suspend fun vaultId() = computeVaultId(root)414457 override suspend fun onConsent(request: AdoptionFrame.Request) = true458+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true415459 override suspend fun upsertPairedDevice(device: PairedDevice) {416460 upserted = true417461 }@@ -471,7 +515,12 @@471515 try {472516 receiver.adopt(473517 encodedInvitation = empty,474- deps = object : AdoptionReceiverDeps {518+ deps = object : AdoptionReceiverV2Deps {519+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")520+ override suspend fun rotateLocalIdentity() = localIdentity()521+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}522+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false523+475524 override val deviceName = "phone"476525 override val deviceType = DeviceType.ANDROID477526 override fun generateDeviceId() = "x"@@ -502,7 +551,13 @@502551 try {503552 receiver.grantFromInvitation(504553 encodedInvitation = populated,505- sourceDeps = object : AdoptionSourceDeps {554+ sourceDeps = object : AdoptionSourceV2Deps {555+ override suspend fun rotateSourceIdentity() = sourceIdentity556+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false557+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true558+ override suspend fun completePendingIdentity(device: PairedDevice) = true559+ override fun snapshotCapable() = true560+506561 override val sourceIdentity = LocalDeviceIdentity(507562 "phone", "phone", DeviceType.ANDROID,508563 "ab".repeat(32), "cd".repeat(32),@@ -510,6 +565,7 @@510565 override suspend fun rootKeyHex() = "ab".repeat(32)511566 override suspend fun vaultId() = "cd".repeat(32)512567 override suspend fun onConsent(request: AdoptionFrame.Request) = true568+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true513569 override suspend fun upsertPairedDevice(device: PairedDevice) = Unit514570 },515571 confirm = { _, _ -> true },app/src/test/java/com/peachpasswords/sync/RelayAdoptionReceiverTest.kt+77 −20
@@ -100,12 +100,19 @@100100 sourceKeys.secretKey,101101 sourceKeys.publicKey,102102 sourceIdentity,103- object : AdoptionSourceDeps {103+ object : AdoptionSourceV2Deps {104+ override suspend fun rotateSourceIdentity() = sourceIdentity105+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false106+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true107+ override suspend fun completePendingIdentity(device: PairedDevice) = true108+ override fun snapshotCapable() = true109+104110 override val sourceIdentity = sourceIdentity105111 override suspend fun rootKeyHex() = Rendezvous.bytesToHex(root)106112 override suspend fun vaultId() = computeVaultId(root)107113 override suspend fun license() = "PPK-test"108114 override suspend fun onConsent(request: AdoptionFrame.Request) = true115+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true109116 override suspend fun upsertPairedDevice(device: PairedDevice) {110117 sourceStored = device111118 }@@ -126,7 +133,12 @@126133 token,127134 noiseStaticPublicKeyHex = Rendezvous.bytesToHex(sourceKeys.publicKey),128135 ),129- object : AdoptionReceiverDeps {136+ object : AdoptionReceiverV2Deps {137+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")138+ override suspend fun rotateLocalIdentity() = localIdentity()139+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}140+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false141+130142 override val deviceName = "receiver"131143 override val deviceType = DeviceType.ANDROID132144 override fun generateDeviceId() = "session-only-request"@@ -187,12 +199,19 @@187199 sourceKeys.secretKey,188200 sourceKeys.publicKey,189201 sourceIdentity,190- object : AdoptionSourceDeps {202+ object : AdoptionSourceV2Deps {203+ override suspend fun rotateSourceIdentity() = sourceIdentity204+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false205+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true206+ override suspend fun completePendingIdentity(device: PairedDevice) = true207+ override fun snapshotCapable() = true208+191209 override val sourceIdentity = sourceIdentity192210 override suspend fun rootKeyHex() = Rendezvous.bytesToHex(root)193211 override suspend fun vaultId() = computeVaultId(root)194212 override suspend fun license() = "PPK-test"195213 override suspend fun onConsent(request: AdoptionFrame.Request) = true214+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true196215 override suspend fun upsertPairedDevice(device: PairedDevice) {197216 sourceStored = device198217 }@@ -210,7 +229,12 @@210229 token,211230 noiseStaticPublicKeyHex = Rendezvous.bytesToHex(sourceKeys.publicKey),212231 ),213- object : AdoptionReceiverDeps {232+ object : AdoptionReceiverV2Deps {233+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")234+ override suspend fun rotateLocalIdentity() = localIdentity()235+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}236+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false237+214238 override val deviceName = "receiver"215239 override val deviceType = DeviceType.ANDROID216240 override fun generateDeviceId() = "session-only-request"@@ -274,24 +298,35 @@274298 override suspend fun receive(): ByteArray = noise.decrypt(sourceSocket.receive())275299 override suspend fun close() = sourceSocket.close()276300 }277- assertTrue(receiveFrame(channel) is AdoptionFrame.Request)301+ assertTrue(receiveFrame(channel) is AdoptionFrame.RequestV2)302+ sendFrame(channel, AdoptionFrame.ConfirmRequired)278303 assertTrue(receiveFrame(channel) is AdoptionFrame.Confirm)279- sendFrame(channel, AdoptionFrame.Grant(280- rootKeyHex = Rendezvous.bytesToHex(root),304+ sendFrame(channel, AdoptionFrame.Prepare(305+ deviceId = sourceIdentity.deviceId,306+ deviceName = sourceIdentity.deviceName,307+ deviceType = sourceIdentity.deviceType.wireValue,308+ longTermPublicKeyHex = sourceIdentity.longTermPublicKeyHex,309+ signingPublicKeyHex = sourceIdentity.signingPublicKeyHex,281310 vaultId = computeVaultId(root),282311 license = "PPK-test",283- source = AdoptionFrame.Source(284- deviceId = sourceIdentity.deviceId,285- deviceName = sourceIdentity.deviceName,286- deviceType = sourceIdentity.deviceType.wireValue,287- longTermPublicKeyHex = sourceIdentity.longTermPublicKeyHex,288- signingPublicKeyHex = sourceIdentity.signingPublicKeyHex,289- ),290312 snapshotCapable = false,291313 ))292- assertTrue(receiveFrame(channel) is AdoptionFrame.Identity)293- sendFrame(channel, AdoptionFrame.Complete)314+ assertTrue(receiveFrame(channel) is AdoptionFrame.Ready)315+ // The v2 grant carries no source identity, so the peer writes it316+ // with its own serializer (see AdoptGrantV2).317+ channel.send(318+ AdoptJson.encodeToString(319+ AdoptGrantV2.serializer(),320+ AdoptGrantV2(321+ type = "ADOPT_GRANT",322+ rootKeyHex = Rendezvous.bytesToHex(root),323+ vaultId = computeVaultId(root),324+ license = "PPK-test",325+ ),326+ ).toByteArray(Charsets.UTF_8),327+ )294328 assertTrue(receiveFrame(channel) is AdoptionFrame.Applied)329+ sendFrame(channel, AdoptionFrame.Complete)295330 } finally {296331 noise.close()297332 }@@ -306,7 +341,12 @@306341 token,307342 noiseStaticPublicKeyHex = Rendezvous.bytesToHex(sourceKeys.publicKey),308343 ),309- object : AdoptionReceiverDeps {344+ object : AdoptionReceiverV2Deps {345+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")346+ override suspend fun rotateLocalIdentity() = localIdentity()347+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}348+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false349+310350 override val deviceName = "receiver"311351 override val deviceType = DeviceType.ANDROID312352 override fun generateDeviceId() = "session-only-request"@@ -421,12 +461,19 @@421461 sourceKeys.secretKey,422462 sourceKeys.publicKey,423463 sourceIdentity,424- object : AdoptionSourceDeps {464+ object : AdoptionSourceV2Deps {465+ override suspend fun rotateSourceIdentity() = sourceIdentity466+ override fun hasDeviceIdentityCollision(device: PairedDevice) = false467+ override suspend fun persistPendingIdentity(device: PairedDevice, nowMs: Long) = true468+ override suspend fun completePendingIdentity(device: PairedDevice) = true469+ override fun snapshotCapable() = true470+425471 override val sourceIdentity = sourceIdentity426472 override suspend fun rootKeyHex() = Rendezvous.bytesToHex(root)427473 override suspend fun vaultId() = computeVaultId(root)428474 override suspend fun license() = "PPK-test"429475 override suspend fun onConsent(request: AdoptionFrame.Request) = true476+ override suspend fun onConsent(request: AdoptionFrame.RequestV2) = true430477 override suspend fun upsertPairedDevice(device: PairedDevice) {}431478 override suspend fun vaultSnapshot() = smallSnapshot()432479 override suspend fun duressSlotJson() = null@@ -444,7 +491,12 @@444491 token,445492 noiseStaticPublicKeyHex = Rendezvous.bytesToHex(sourceKeys.publicKey),446493 ),447- object : AdoptionReceiverDeps {494+ object : AdoptionReceiverV2Deps {495+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")496+ override suspend fun rotateLocalIdentity() = localIdentity()497+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}498+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false499+448500 override val deviceName = "receiver"449501 override val deviceType = DeviceType.ANDROID450502 override fun generateDeviceId() = "session-only-request"@@ -577,7 +629,12 @@577629 private fun abortingDeps(578630 confirmSas: Boolean = false,579631 generateDeviceId: () -> String = { error("past the pin check") },580- ) = object : AdoptionReceiverDeps {632+ ) = object : AdoptionReceiverV2Deps {633+ override fun localIdentity() = LocalDeviceIdentity(generateDeviceId(), deviceName, deviceType, "", "")634+ override suspend fun rotateLocalIdentity() = localIdentity()635+ override suspend fun validateSource(prepare: AdoptionFrame.Prepare) {}636+ override suspend fun hasSourceIdentityCollision(prepare: AdoptionFrame.Prepare) = false637+581638 override val deviceName = "phone"582639 override val deviceType = DeviceType.ANDROID583640 override fun generateDeviceId() = generateDeviceId()