findfamily: hidden pair-ID sender auth policy, storage, wire field
- Commit
d940fe5360538738461384f817f2758d97f111c1- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-13 21:34 UTC (1 month ago)
- Parents
438ba49
Diff
findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.ktindex 27bca6288e..fc06e7bc6a 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/data/LocationValue.kt@@ -104,7 +104,7 @@ data class LocationValue( val source: LocationSource = LocationSource.LIVE, @PrimaryKey(autoGenerate = true) override val id: Long = 0 ): DatabaseItem {- fun toCompatible(senderPlatform: String? = null): LocationValueCompatible {+ fun toCompatible(senderPlatform: String? = null, pairId: String? = null): LocationValueCompatible { return LocationValueCompatible( userid = userid.toULong(), coord = coord,@@ -115,6 +115,7 @@ data class LocationValue( sleep = false, id = id.toULong(), senderPlatform = senderPlatform,+ pairId = pairId, reportedAt = reportedAt.toEpochMilliseconds(), source = source.name, )@@ -133,6 +134,12 @@ data class LocationValueCompatible( val sleep: Boolean? = null, /** Sender's platform tag (`"android"` or `"ios"`). Optional for backward compatibility. */ val senderPlatform: String? = null,+ /**+ * Hidden sender-auth secret (GHSA-x94x-v6f7-wwpp): this sender's outbound pair ID+ * for the recipient. Base64url unpadded, ~22 chars. Optional for backward+ * compatibility — absent means a peer that predates sender authentication.+ */+ val pairId: String? = null, /** [LocationValue.reportedAt] in epoch milliseconds. Absent from peers that predate it, in * which case it falls back to [timestamp] — an older peer only ever sent live reports. */ val reportedAt: Long? = null,
findfamily/src/main/java/com/vayunmathur/findfamily/data/User.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/data/User.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/data/User.ktindex e9d794e2aa..62c46bf14f 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/data/User.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/data/User.kt@@ -50,6 +50,22 @@ data class User( val sharingAutoToggleWaypointId: Long? = null, /** Peer post-quantum public bundle (base64: [4B kemLen][kemPubDer][dsaPubDer]), nullable for backward compat. */ val pqcEncryptionKey: String? = null,+ /**+ * Hidden per-peer sender-auth secrets (GHSA-x94x-v6f7-wwpp).+ *+ * Encryption to the peer's bundle proves who a packet is *for*, not who it is *from*,+ * and the userid inside the plaintext is self-declared. Each direction holds its own+ * 128-bit secret (base64url, unpadded, ~22 chars) that never leaves the ciphertext:+ * - [outboundPairId]: what this device puts in every packet it sends to this peer.+ * Created once at explicit connect time; generated lazily on first send for+ * pre-existing rows.+ * - [inboundPairId]: what this device expects from this peer; pinned+ * trust-on-first-use on the first packet carrying an ID. Null = unpinned/legacy.+ *+ * Never user-visible, never logged in full, never sent outside the encrypted payload.+ */+ val inboundPairId: String? = null,+ val outboundPairId: String? = null, /** Whether this row is a person contact or a custom UWB tracker. Defaults to * [UserKind.PERSON]; only the DEV_BUILD tracker feature ever writes [UserKind.TRACKER]. */ val kind: UserKind = UserKind.PERSON
findfamily/src/main/java/com/vayunmathur/findfamily/domain/PairAuth.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/domain/PairAuth.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/domain/PairAuth.ktnew file mode 100644index 0000000000..655db4dfe7--- /dev/null+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/domain/PairAuth.kt@@ -0,0 +1,77 @@+package com.vayunmathur.findfamily.domain++import java.security.SecureRandom+import kotlin.io.encoding.Base64+import kotlin.time.Instant++/**+ * Hidden per-peer sender authentication for location packets (GHSA-x94x-v6f7-wwpp).+ *+ * ML-KEM + AES-GCM encrypts *to* the recipient, proving nothing about who sent the+ * plaintext — and the `userid` inside is self-declared. Instead of a 3,309-byte+ * ML-DSA signature per message, each direction of each peer relationship holds a+ * 128-bit secret ("pair ID") that is never user-visible and never leaves the+ * ciphertext:+ * - `outboundPairId`: what this device puts in every packet it sends to a peer.+ * - `inboundPairId`: what this device expects from a peer; pinned trust-on-first-use.+ *+ * Both IDs are opaque strings (base64url, unpadded, 16 random bytes ≈ 22 chars).+ * Directional so neither side transmits its expectation.+ */+object PairAuth {+ /** Random bytes per pair ID (128-bit). */+ const val PAIR_ID_BYTES = 16++ /**+ * How far ahead of the receiver's clock a fix may claim before it is dropped.+ * Kills the one-message future-pin amplifier (`getLatest()` ranks on `reportedAt`).+ */+ const val MAX_FUTURE_SKEW_SECONDS = 5 * 60L++ /** Result of checking one inbound packet's pair ID against the pinned expectation. */+ enum class InboundVerdict {+ /** No pin yet and packet carries an ID — caller should pin it, then accept. */+ ACCEPT_PIN,++ /** Pinned and matches — accept. */+ ACCEPT_MATCH,++ /** No pin and no ID (legacy peer) — accept without pinning. */+ ACCEPT_LEGACY,++ /** Pinned but packet carries a different ID — drop. */+ DROP_MISMATCH,++ /** Pinned but packet carries none — drop. */+ DROP_MISSING,+ }++ /** Generates a fresh pair ID (16 bytes, base64url unpadded). */+ fun generatePairId(): String {+ val bytes = ByteArray(PAIR_ID_BYTES)+ SecureRandom().nextBytes(bytes)+ return Base64.UrlSafe.encode(bytes).trimEnd('=')+ }++ /** Pure check of an inbound `pairId` against the pinned [expected] (null = unpinned). */+ fun checkInbound(expected: String?, incoming: String?): InboundVerdict {+ if (expected == null) {+ return if (incoming == null) InboundVerdict.ACCEPT_LEGACY else InboundVerdict.ACCEPT_PIN+ }+ if (incoming == null) return InboundVerdict.DROP_MISSING+ return if (incoming == expected) InboundVerdict.ACCEPT_MATCH else InboundVerdict.DROP_MISMATCH+ }++ /**+ * True when a fix claims a time more than [MAX_FUTURE_SKEW_SECONDS] ahead of [now].+ * Both `reportedAt` (send time) and `timestamp` (measure time) are sender-controlled.+ */+ fun isFromTheFuture(reportedAt: Instant, timestamp: Instant, now: Instant): Boolean {+ val skew = MAX_FUTURE_SKEW_SECONDS+ return reportedAt.epochSeconds - now.epochSeconds > skew ||+ timestamp.epochSeconds - now.epochSeconds > skew+ }++ /** Truncated pair ID for logs — the full value must never be logged. */+ fun logPreview(pairId: String?): String = pairId?.take(4)?.let { "$it…" } ?: "absent"+}