Fix key-reuse and race conditions in keychain encrypt/decrypt; add cr… - #2
Open
DavidValin wants to merge 2 commits into
Open
Fix key-reuse and race conditions in keychain encrypt/decrypt; add cr…#2DavidValin wants to merge 2 commits into
DavidValin wants to merge 2 commits into
Conversation
…ash safety and Windows support Fixes five related vulnerabilities/gaps in the keychain (-c <contact>) encrypt/decrypt path where OTP key material could be reused or lost: - Multi-chunk key leak: a message spanning several 4MB chunks that exceeded the remaining key could leak already-encrypted chunks to output before the oversize was detected, leaving that key range falsely marked unused and reusable. - Crash-time key reuse: a kill/crash between emitting ciphertext and committing key consumption could leave a key range looking unspent after it was already used. Fixed with a stage → verify (read-back) → atomic-publish commit protocol and deterministic 3-window crash recovery, applied to both encrypt and decrypt. - Concurrent same-contact reuse: two processes racing on one contact could each read and consume the same key offset. Fixed with per-contact flock()-based locking plus a metadata reload after acquiring the lock. - Concurrent cross-contact corruption: all contacts shared one keychain.txt, so concurrent writes to different contacts could silently overwrite each other's metadata. Fixed by splitting metadata into one file per contact, with transparent migration from the old format. - Windows gap: the above fixes relied on POSIX-only dirent.h/flock(), leaving Windows builds without recovery scanning or locking. Added platform.h, a shim providing the same APIs via Win32 FindFirstFile/LockFileEx, so both platforms run identical code.
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.
Fixes five related vulnerabilities/gaps in the keychain (-c ) encrypt/decrypt path where OTP key material could be reused or lost: