fix(apple): don't evict caches during protection-class migration#162
Merged
Merged
Conversation
…ction-class migration decrypt_with_cached_key re-stores the wrapping key on every cache miss to migrate items to AfterFirstUnlockThisDeviceOnly. It called keychain_store(), which evicts both the wrapping-key cache and the LAContext registry. This created a self-perpetuating cycle: every sign saw a cache miss, triggered the migration, evicted both caches, and forced a fresh Touch ID prompt on the next sign. Extract keychain_store_ffi (the raw FFI call without eviction) and use it in the migration path. The key bytes are unchanged — only the protection class is updated — so the cached entries remain valid. keychain_store retains the eviction for callers that change key bytes (generate_and_wrap, relabel_wrapping_key). Restores single-prompt-per-cache-window behavior: first sign triggers Touch ID, subsequent signs within the TTL reuse the cached LAContext.
This was referenced May 21, 2026
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
decrypt_with_cached_keycalledkeychain_store()on every cache miss, which evicts both the wrapping-key cache and the LAContext registrykeychain_store_ffi(raw FFI, no eviction) and use it in the migration path — the key bytes are unchanged, so cached entries remain validkeychain_storeretains eviction for callers that change key bytes (generate, relabel)Root cause
PR #158 added a lazy protection-class migration that re-stores the wrapping key on cache miss. The re-store called
keychain_store()→cache_evict()→ nuked both the wrapping-key cache and LAContext registry. Next sign saw another cache miss → migration fired again → infinite cycle. Every sign got a fresh LAContext and Touch ID prompt.Test plan
cargo test --workspace— all existing tests passcargo clippy --workspace --all-targets -- -D warnings— cleancargo fmt --all -- --check— clean