fix: macOS Keychain stale key accumulation on reinit - #15
Merged
Conversation
SecItemDelete only removes one Keychain item per call. Multiple amesh init --force runs accumulated stale keys under the same tag, causing sign() to use an old private key while identity.json stored the new public key. selfSig verification failed on the remote peer. Fix: loop SecItemDelete until all matching items are gone before generating a new key. Applied to both generate and delete actions. Added regression tests for both encrypted-file and macOS Keychain drivers verifying that generateAndStore twice with the same ID produces signatures that verify against the second (new) public key.
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.
Summary
amesh init --forceaccumulated stale keys in macOS Keychain —SecItemDeleteonly removes one item per call, leaving old keys behindsign()used the old private key whileidentity.jsonstored the new public key, causingselfSig verification failedon remote peers during pairing and shell handshakesSecItemDeleteuntil all matching items are cleared before generating a new keyChanges
packages/keystore/swift/main.swift— Loop delete in bothgenerateanddeleteactionspackages/keystore/src/__tests__/encrypted-file.test.ts— Key overwrite regression testspackages/keystore/src/__tests__/macos-keychain.test.ts— New: macOS Keychain driver tests including stale key regression testTest plan
bun test packages/keystore/src/__tests__/encrypted-file.test.ts— 15 tests passbun test packages/keystore/src/__tests__/macos-keychain.test.ts— 5 tests pass (macOS only, skipped on Linux CI)amesh init --forcetwice, then verifyselfSiground-trip succeeds🤖 Generated with Claude Code