Repository navigation
feat(sync): authenticate ledger revocation records with a MAC (ACF-26) - #332
Merged
ahmet-cetinkaya merged 1 commit intoOct 29, 2026
Merged
Conversation
…; 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
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ACF-26 / D13a (option L1): revocation records in
sync_ledger.jsonnow carry a MAC, so a forged (record, revoker-entry) pair written to the ledger file can no longer reachMembership.whph_sync_core/lib/src/store/ledger_mac.dart:deriveLedgerMacKey(HKDF of the key-file Ed25519 seed) andledgerRevocationMac(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.SyncMembershipService.loadKeyFilethen 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 tosync_ledger.json.dropped-v1next 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
ledger_mac_test.dart(determinism, every field, other seed, no byte-moving collision, short MAC).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) andsync_ledger_mac_migration_test.dart(real 3-device group: forged attacker-signed pair dropped, genuine kept).dart analyzeclean (lib, tests, core).whph_sync_corenon-soak: 514 pass. Appsync,persistence/sync,integration/sync_acceptance(excluding perf-sync): 351 pass.sync_performance_loopback_test(known >30 min).Accepted risk unchanged: key file + ledger + DB written together.