Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
cov/c3 ▾

Modern-Apps.git / library / everysync-core / LIVE_RELAY_CONFORMANCE.md

LIVE_RELAY_CONFORMANCE.md6.4 KiBRenderedCodeRaw
1# Live-relay conformance — staging `https://api.maproj.org/personal`
2
3Scripted manual checklist for a human (or a scripted device pair) to verify a
4real relay deployment speaks the shared-core protocol. **No automation runs
5this file** — each step lists the exact endpoint, channel, and envelope shape
6to exercise, and the assertion to record. Automated coverage of the same
7contract lives in `src/commonTest/.../network/RelayConformanceTest.kt` (fake
8transport) and `SharedTransportTest.kt`.
9
10Prerequisites: two clean installs (device A = owner, device B = joiner),
11`SharedRelayTransport.init()` succeeding on both (PQC identity in
12`SecureStore` under `personalKemPub/Priv`, `personalDsaPub/Priv`; stable id
13under `personalDeviceId`). Record both device ids.
14
15## 1. `POST /register` + `POST /getkey`
16
171. A: `register()` → HTTP 200.
182. B: `register()` → HTTP 200.
193. A: `getKey(B)` → non-empty bundle; B: `getKey(A)` → non-empty bundle.
204. A: `getKey("nonexistent-device")` → null (unknown id, no crash).
21
22## 2. Record channels — `POST /append` + `POST /pull`
23
24Channel names (`RelayContract.kt`): records `passwords:<vault>` /
25`notes:<vault>` / `todos:<vault>` / `contacts:<vault>` / `calendar:<vault>`,
26`members:<vault>`, `keys:<vault>`, `owner:<vault>`, `title:<vault>`,
27`inbox:<device>`, blobs `notes-blobs:<vault>`.
28
291. A creates vault V (`newVaultId()`), key K (`newVaultKey()`, 32 bytes).
302. A: `appendRecords(recordChannel("notes", V), K, [noteJsonA, noteJsonB])` → seq S1 > 0.
313. B (same K, out of band = sealed invite, step 5): `pullRecords(channel, K, 0)`
32 → `items == [noteJsonA, noteJsonB]`, `rawCount == 2`, `undecryptable == 0`,
33 `fullyUndecryptable == false`, `seq == S1`.
344. B: `pullRecords(channel, WRONG_KEY, 0)` → `items.isEmpty()`,
35 `undecryptable == 2`, `fullyUndecryptable == true` → caller MUST abort, not merge.
36
37## 3. B64 AES record shape
38
391. `pullRaw(channel, 0)` → each envelope is valid Base64
40 (`Base64.decode` succeeds) and `AesGcm.decrypt(K, bytes)` yields the
41 plaintext JSON; IV-prepended layout (`[12B iv][ct||tag]`), same as Android
42 `E2ee` and both `AesGcm` actuals.
43
44## 4. Double-wrapped roster + epoch (`VaultPolicy.kt`)
45
461. A: `VaultRoster.recordMembers(V, [Member(B, role=editor)])` → true.
472. B: `fetchRoster(V, ownerKey)` → contains B as editor; tamper with one
48 envelope on a scratch channel (append garbage) → skipped, roster still resolves.
493. A: `VaultKeys.rotateKey(V, epoch=0, {A: bundleA, B: bundleB})` → new key K2.
504. B: `fetchCurrentKey(V, inviteKey=K, ownerKey)` → `(1, K2)`; `K2 != K`.
515. Records appended under K2 do not decrypt under K (epoch isolation).
52
53## 5. Sealed invite + join request (`RelayEnvelopes.kt`)
54
551. B: `sendJoinRequest(ownerId=A, V, "notes", B, name)` → true; lands on
56 `inbox:A` with `kind:"req"` discriminator.
572. A: `pullInbox(0)` → `requests` contains B's request, `invites` empty.
583. A: `sendInvite(B, V, "notes", K_current, title, editor, ownerKeyB64, A)` → true.
594. B: `pullInvites(0)` → one invite, `vaultId == V`, `key` Base64-decodes to
60 `K_current`. Relay log shows only ciphertext (spot-check: no plaintext
61 title/key in raw `pullRaw(inbox:B, 0)` output).
62
63## 6. `everysync://join` link parse (`RelayLinks`)
64
651. `shareLinkFor(V, A, "notes")` → `https://maproj.org/es/share#id=V&owner=A&type=notes`;
66 contains no `key` (case-insensitive).
672. `parseJoinLink("everysync", "join", V, A, "notes")` → `Triple(V, A, "notes")`;
68 wrong scheme / blank vault / blank owner → null.
69
70## 7. The three invariants (abort conditions — verify each against staging)
71
721. **Failed pull returns null, never empty**: kill network mid-`pullRaw` (or
73 point at a bad host) → null → `SyncDriver.drive` returns false and merges
74 nothing. Provably-empty channel → empty list (merge proceeds).
752. **Only explicit tombstones delete**: delete a note locally, sync, pull on B
76 → B's row is tombstoned (`deleted=true` envelope in the folded log), never
77 silently dropped; an id absent from the log with no tombstone is resurrected,
78 not deleted (`RelayMerge.reconcileLocalOnly` / `reconcileRemoteOnly`).
793. **Vault keys never user-visible**: share links carry ids only (step 6);
80 keys move exclusively via PQC-sealed inbox invites (step 5); no key material
81 in logcat, share sheets, or error messages.
82
83## Sign-off
84
85| Step | Date | Relay build | Pass? | Notes |
86| ---- | ---- | ----------- | ----- | ----- |
87| 1 register/getkey | 2026-10-18 | staging `https://api.maproj.org/personal` → HTTP 404 `Not Found` on all `/personal/*` routes (host serves static 200 at `/`) | BLOCKED | `POST /register` → 404 body=`Not Found` (also via pwsh `Invoke-WebRequest`, GET `/personal` → 404, trailing-slash + plain-HTTP variants → 404). `JvmRelayTransport.init()` false on both A+B. Runner: `LiveRelayConformanceTest` step 1 BLOCKED. |
88| 2 append/pull | 2026-10-18 | same 404 staging | BLOCKED | No channel reachable; step never executed. Runner step 2 BLOCKED with the same 404 evidence. |
89| 3 B64 AES shape | 2026-10-18 | same 404 staging (relay half) | partial — local half PASS | Local half genuinely executed+asserted with JVM `AesGcm`: IV-prepended `[12B iv][ct\|\|tag]` (pt+28B), random IV (two encryptions differ, both decrypt), B64 envelope round-trip (runner step 3-local PASS). Relay half BLOCKED (no `pullRaw` possible). |
90| 4 roster/epoch | 2026-10-18 | same 404 staging | BLOCKED | Never executed against staging; runner step 4 BLOCKED. Scripted: roster editor + garbage-skip, `rotateKey` → epoch 1 K2, epoch isolation (runner `phaseRosterEpoch`). |
91| 5 invite/join | 2026-10-18 | same 404 staging | BLOCKED | Never executed against staging; runner step 5 BLOCKED. Scripted: join-req `kind:req` → invite resolves vault+key → raw inbox ciphertext scan (runner `phaseInviteJoin`). |
92| 6 join parse | 2026-10-18 | n/a (pure local) | PASS | Genuinely executed+asserted: share link ids-only, parse round-trips, bad scheme/host/blank ids → null (runner step 6 PASS). |
93| 7 invariants | 2026-10-18 | same 404 staging (relay halves) | partial — local halves PASS | 7.1 PASS asserted: kill-network `pullRaw` → null → `SyncDriver.drive` false, zero writes. 7.2 merge half PASS asserted: absent-without-tombstone resurrects, `deleted=true` envelope tombstones. 7.3 local half PASS asserted: link ids-only + PQC-sealed envelope has no title/key substrings and opens for the recipient. Relay halves (live tombstone propagation) BLOCKED on the 404. |