fix: don't evict LAContext on user-cancelled Touch ID prompts#155
Merged
Conversation
Prevents LAContext cache thrashing when users cancel Touch ID prompts, which was causing repeated Touch ID prompts and eventual password fallback after 3+ cancellations. Changes: - Add SE_ERR_USER_CANCEL (code 16) to Swift bridge for explicit user cancellation (LAError.userCancel, errSecUserCanceled) - Add Error::UserCancelled variant to Rust error enum - Update should_evict_lacontext to NOT evict on UserCancelled - Add error logging to Swift bridge catch blocks to show actual NSError/LAError details in agent logs Root cause: Generic error codes (SE_ERR_SIGN=3, SE_ERR_KEYCHAIN_LOAD=10) were collapsing all failures into a single code, causing Rust to evict the LAContext on user cancellation. The LAContext is still valid when the user cancels — evicting it forces a fresh Touch ID prompt on the next operation with no gain. With this fix, cancelling a Touch ID prompt preserves the LAContext cache, so subsequent operations within the cache TTL window succeed silently without re-prompting.
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.
Problem
Users experiencing repeated Touch ID prompts and eventual password fallback after cancelling Touch ID 3+ times. The
git pullerror showed:Agent logs showed:
SE_ERR_SIGN(code 3): signing failedSE_ERR_KEYCHAIN_LOAD(code 10): keychain load failedBoth errors triggered LAContext eviction, forcing fresh Touch ID prompts on every retry even though the LAContext was still valid.
Root Cause
Generic Swift error codes (3, 10) collapsed all failures into a single code, losing the actual OS error details (
LAError.userCancel,errSecUserCanceled). Rust couldn't distinguish "user cancelled" from "real error" and evicted the LAContext on both.Failure cycle:
Solution
SE_ERR_USER_CANCEL(code 16) for explicit user cancellationLAError.userCancelanderrSecUserCanceledto the new codeError::UserCancelledvariant to Rustshould_evict_lacontextto NOT evict onUserCancelledResult
When a user cancels Touch ID:
"enclaveapp: se_sign: user cancelled (LAError -2)"Testing
Error::UserCancelleddisplay message