Skip to content

fix: macOS Keychain stale key accumulation on reinit - #15

Merged
YairEtzion merged 1 commit into
mainfrom
fix/keychain-stale-key
Apr 4, 2026
Merged

fix: macOS Keychain stale key accumulation on reinit#15
YairEtzion merged 1 commit into
mainfrom
fix/keychain-stale-key

Conversation

@YairEtzion

Copy link
Copy Markdown
Contributor

Summary

  • Bug: amesh init --force accumulated stale keys in macOS Keychain — SecItemDelete only removes one item per call, leaving old keys behind
  • Impact: sign() used the old private key while identity.json stored the new public key, causing selfSig verification failed on remote peers during pairing and shell handshakes
  • Fix: Loop SecItemDelete until all matching items are cleared before generating a new key

Changes

  • packages/keystore/swift/main.swift — Loop delete in both generate and delete actions
  • packages/keystore/src/__tests__/encrypted-file.test.ts — Key overwrite regression tests
  • packages/keystore/src/__tests__/macos-keychain.test.ts — New: macOS Keychain driver tests including stale key regression test

Test plan

  • bun test packages/keystore/src/__tests__/encrypted-file.test.ts — 15 tests pass
  • bun test packages/keystore/src/__tests__/macos-keychain.test.ts — 5 tests pass (macOS only, skipped on Linux CI)
  • Manual: amesh init --force twice, then verify selfSig round-trip succeeds
  • Manual: pair Mac → Pi after reinit, confirm handshake completes

🤖 Generated with Claude Code

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.
@YairEtzion
YairEtzion merged commit d56147e into main Apr 4, 2026
1 check passed
@YairEtzion
YairEtzion deleted the fix/keychain-stale-key branch April 4, 2026 10:18
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