8000 feat(sync): authenticate ledger revocation records with a MAC (ACF-26) by ahmet-cetinkaya · Pull Request #332 · ahmet-cetinkaya/whph · GitHub
[go: up one dir, main page]

Skip to content

feat(sync): authenticate ledger revocation records with a MAC (ACF-26) - #332

Merged
ahmet-cetinkaya merged 1 commit into
feat/reliable-secure-lan-syncfrom
feat/sync-p3-14-ledger-mac
Oct 29, 2026
Merged

ahmet-cetinkaya merged 1 commit into
feat/reliable-secure-lan-syncfrom
feat/sync-p3-14-ledger-mac

Conversation

@ahmet-cetinkaya
Copy link
Copy Markdown
Owner

What

ACF-26 / D13a (option L1): revocation records in sync_ledger.json now carry a MAC, so a forged (record, revoker-entry) pair written to the ledger file can no longer reach Membership.

  • whph_sync_core/lib/src/store/ledger_mac.dart: deriveLedgerMacKey (HKDF of the key-file Ed25519 seed) and ledgerRevocationMac (HMAC-BLAKE2b over record, revoker entry and carrier origin/seq, length-prefixed). Constant-time compare.
  • FileSyncKeyStore: writes the MAC on every save, verifies on load. A record with a bad MAC, or a MAC while the key file is unreadable, is skipped; the origin list still loads.
  • Ledger format 1 -> 2. A v1 record (no MAC) is kept apart and never returned; SyncMembershipService.loadKeyFile then keeps those signed by a current group member (and MACs them) and drops the rest. Dropped records: count logged (no bytes) and written as one JSON line to sync_ledger.json.dropped-v1 next to the ledger, so a bad migration is reversible by hand.

Deviation from the plan (one)

Key salt: the plan said salt = groupId. I used no group salt: pairing persists records before the key file holds the new group id, and leaving a group already clears the records. The seed changes on key loss, which invalidates old MACs anyway.

Compatibility: ledger v2 needs this app version or newer

An older build reading a v2 file rejects the version, treats the ledger as unreadable (isReadable == false) and the D14 startup check then runs the restore flow (new origin). No data is lost, but a downgrade costs one origin switch and the device must re-sync. Newer builds read v1 files.

Tests

  • core: ledger_mac_test.dart (determinism, every field, other seed, no byte-moving collision, short MAC).
  • app: file_sync_key_store_test.dart (round trip, forged MAC, altered field, other identity, no key file, v1 not returned, adoption keeps genuine / drops rest + backup) and sync_ledger_mac_migration_test.dart (real 3-device group: forged attacker-signed pair dropped, genuine kept).
  • Mutation-checked: accepting any MAC fails 4 store tests; accepting any legacy record fails the migration test.
  • dart analyze clean (lib, tests, core). whph_sync_core non-soak: 514 pass. App sync, persistence/sync, integration/sync_acceptance (excluding perf-sync): 351 pass.
  • Not run: a soak range (engine untouched; the in-memory ledger has no MAC) and sync_performance_loopback_test (known >30 min).

Accepted risk unchanged: key file + ledger + DB written together.

…; forged record+entry pairs no longer enter (ACF-26, D13a)

Each stored record gets HMAC-BLAKE2b over record, revoker entry and carrier
position, keyed by an HKDF of the key-file identity seed. A record with a bad
MAC, or any MAC while the key file is unreadable, is skipped without making
the ledger unreadable. Version 1 records (no MAC) are kept apart until the
startup path accepts those signed by a current group member; the rest are
dropped, logged by count, and backed up to sync_ledger.json.dropped-v1.

Ledger format 1 -> 2.
@ahmet-cetinkaya
ahmet-cetinkaya merged commit a5192ca into feat/reliable-secure-lan-sync Oct 29, 2026
ahmet-cetinkaya added a commit that referenced this pull request Oct 29, 2026
…ac-followups

fix(sync): ledger MAC follow-ups from the #332 review (M-1, M-2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0