Modern Apps git

← Modern-Apps.git

findfamily: pair-ID connect generation, direct-boot mirror, tests

Commit
754e52f4c91f30ad3a8fc3c2374c9559e62350d5
Author
vayun-mathur <[email protected]>
When
2026-10-13 21:59 UTC (1 month ago)
Parents
06664dc

Diff

findfamily/src/main/java/com/vayunmathur/findfamily/data/DirectBootStore.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/data/DirectBootStore.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/data/DirectBootStore.ktindex 71b99cf690..a8d133124c 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/data/DirectBootStore.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/data/DirectBootStore.kt@@ -48,9 +48,19 @@ object DirectBootStore {         "ff_pqcKemPub", "ff_pqcKemPriv", "ff_pqcDsaPub", "ff_pqcDsaPriv",     ) -    /** A peer we may publish to, reduced to the two fields the publish path actually reads. */+    /** A peer we may publish to, reduced to the fields the publish path actually reads. */     @Serializable-    data class Target(val id: Long, val bundle: String)+    data class Target(+        val id: Long,+        val bundle: String,+        /**+         * Our outbound pair-ID secret for this peer (GHSA-x94x-v6f7-wwpp), mirrored so+         * pre-unlock publishes carry the same hidden value as unlocked ones. Defaults to+         * null for mirrors seeded before sender auth existed — those publishes go out+         * unauthenticated until the next unlocked seed.+         */+        val pairId: String? = null,+    )      private val json = Json { ignoreUnknownKeys = true } 
findfamily/src/main/java/com/vayunmathur/findfamily/platform/FinalLocationReporter.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/platform/FinalLocationReporter.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/platform/FinalLocationReporter.ktindex 83ffd0d175..d328fbe2b7 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/platform/FinalLocationReporter.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/platform/FinalLocationReporter.kt@@ -243,7 +243,9 @@ object FinalLocationReporter {         )         Log.status(TAG, "$source: reporting a fix ${now - value.timestamp} old to ${targets.size} peer(s)")         targets.forEach {-            runCatching { Networking.publishLocation(value, it.id, it.bundle) }+            // Parting reports ride the same seal path, pair ID included — a shutdown report+            // without one would be dropped as unauthenticated once the peer has pinned us.+            runCatching { Networking.publishLocation(value, it.id, it.bundle, it.pairId) }                 .onFailure { e -> Log.status(TAG, "$source publish to ${it.id.toULong()} failed", e) }         }     }
findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.ktindex 6ec2fda1c1..6520e68d0e 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.kt@@ -175,9 +175,16 @@ class FindFamilyViewModel(                 else -> {                     // Store the fingerprint-checked key with the row itself, so the key that was                     // verified is the one used from here on rather than a fresh relay lookup.-                    repository.upsertUser(-                        check.verifiedBundleB64?.let { user.copy(pqcEncryptionKey = it) } ?: user-                    )+                    val withKey = check.verifiedBundleB64?.let { user.copy(pqcEncryptionKey = it) } ?: user+                    // Hidden sender-auth secret (GHSA-x94x-v6f7-wwpp): the outbound pair ID this+                    // device puts in every packet to this peer. Minted once at explicit connect+                    // time — never rotated (the peer pins the first value it sees), never+                    // overwritten here (a re-add must not invalidate the peer's pin).+                    val withPair = withKey.outboundPairId?.let { withKey }+                        ?: withKey.copy(+                            outboundPairId = com.vayunmathur.findfamily.domain.PairAuth.generatePairId()+                        )+                    repository.upsertUser(withPair)                     LocationServiceController.syncServiceState(ctx)                     withContext(Dispatchers.Main) { onDone() }                 }
findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingDirectBoot.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingDirectBoot.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingDirectBoot.ktindex 64dd231f0d..592bfd6674 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingDirectBoot.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingDirectBoot.kt@@ -99,7 +99,7 @@ internal suspend fun LocationTrackingService.publishDirectBoot(targets: List<Dir     )     targets.forEach {         try {-            Networking.publishLocation(lv, it.id, it.bundle)+            Networking.publishLocation(lv, it.id, it.bundle, it.pairId)         } catch (e: CancellationException) {             throw e         } catch (e: Exception) {
findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeat.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeat.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeat.ktindex c1fb5c86c6..96229ea2c1 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeat.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeat.kt@@ -247,8 +247,8 @@ internal suspend fun LocationTrackingService.seedDirectBootMirror() {     val trackingEnabled = LocationServiceController.isTrackingEnabled(this)     val targets = repository.getAllUsers()         .filter { it.id != Networking.userid && it.sendingEnabled }-        .mapNotNull { u -> u.pqcEncryptionKey?.let { DirectBootStore.Target(u.id, it) } }-    val signature = "$sharingOut|$trackingEnabled|" + targets.joinToString(",") { "${it.id}:${it.bundle.length}" }+        .mapNotNull { u -> u.pqcEncryptionKey?.let { DirectBootStore.Target(u.id, it, u.outboundPairId) } }+    val signature = "$sharingOut|$trackingEnabled|" + targets.joinToString(",") { "${it.id}:${it.bundle.length}:${it.pairId?.take(4)}" }     publishRoster = if (sharingOut) targets else emptyList()     if (signature == lastSeededMirror) return     DirectBootStore.seed(
findfamily/src/test/java/com/vayunmathur/findfamily/domain/PairAuthTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/domain/PairAuthTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/domain/PairAuthTest.ktnew file mode 100644index 0000000000..046a3eeaa6--- /dev/null+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/domain/PairAuthTest.kt@@ -0,0 +1,116 @@+package com.vayunmathur.findfamily.domain++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertNotEquals+import kotlin.test.assertTrue+import kotlin.time.Duration.Companion.minutes+import kotlin.time.Duration.Companion.seconds+import kotlin.time.Instant++/**+ * Pure-JVM tests for [PairAuth] (GHSA-x94x-v6f7-wwpp). No Android, no database —+ * every case feeds strings and instants straight into the policy.+ */+class PairAuthTest {++    private val now = Instant.fromEpochSeconds(1_786_570_000L)++    // --- generatePairId ---++    @Test+    fun generatedIdsAreUniqueAndUrlSafe() {+        val a = PairAuth.generatePairId()+        val b = PairAuth.generatePairId()+        assertNotEquals(a, b)+        for (id in listOf(a, b)) {+            assertTrue(id.length in 20..24, "unexpected length: $id")+            assertTrue(id.all { it.isLetterOrDigit() || it == '-' || it == '_' }, "not url-safe: $id")+        }+    }++    // --- checkInbound ---++    @Test+    fun unpinnedAcceptsFirstIdForPinning() {+        assertEquals(+            PairAuth.InboundVerdict.ACCEPT_PIN,+            PairAuth.checkInbound(null, "some-id"),+        )+    }++    @Test+    fun unpinnedWithoutIdIsLegacyAccept() {+        assertEquals(+            PairAuth.InboundVerdict.ACCEPT_LEGACY,+            PairAuth.checkInbound(null, null),+        )+    }++    @Test+    fun pinnedMatchingAccepts() {+        assertEquals(+            PairAuth.InboundVerdict.ACCEPT_MATCH,+            PairAuth.checkInbound("abc", "abc"),+        )+    }++    @Test+    fun pinnedMismatchDrops() {+        assertEquals(+            PairAuth.InboundVerdict.DROP_MISMATCH,+            PairAuth.checkInbound("abc", "attacker-guess"),+        )+    }++    @Test+    fun pinnedMissingDrops() {+        assertEquals(+            PairAuth.InboundVerdict.DROP_MISSING,+            PairAuth.checkInbound("abc", null),+        )+    }++    // --- isFromTheFuture ---++    @Test+    fun timelyFixIsNotFuture() {+        assertFalse(PairAuth.isFromTheFuture(now, now, now))+        assertFalse(PairAuth.isFromTheFuture(now - 1.seconds, now, now))+        assertFalse(PairAuth.isFromTheFuture(now, now - 1.seconds, now))+    }++    @Test+    fun smallSkewIsTolerated() {+        assertFalse(PairAuth.isFromTheFuture(now + 5.minutes, now, now))+        assertFalse(PairAuth.isFromTheFuture(now, now + 5.minutes, now))+    }++    @Test+    fun farFutureReportedAtIsRejected() {+        assertTrue(PairAuth.isFromTheFuture(now + 5.minutes + 1.seconds, now, now))+    }++    @Test+    fun farFutureTimestampIsRejected() {+        assertTrue(PairAuth.isFromTheFuture(now, now + 5.minutes + 1.seconds, now))+    }++    @Test+    fun farPastIsNotFuture() {+        // Stale is a different problem (handled by getLatest ranking); the clamp only kills pins.+        assertFalse(PairAuth.isFromTheFuture(now - 30 * 24 * 3600.seconds, now, now))+    }++    // --- logPreview ---++    @Test+    fun logPreviewNeverLeaksFullValue() {+        val id = PairAuth.generatePairId()+        val preview = PairAuth.logPreview(id)+        assertFalse(preview.contains(id))+        assertTrue(preview.length < id.length)+        assertEquals("absent", PairAuth.logPreview(null))+    }+}