feat: add authenticationFreshness option to force a fresh auth prompt on read - #798
Open
idanlevi1 wants to merge 1 commit into
Open
feat: add authenticationFreshness option to force a fresh auth prompt on read#798idanlevi1 wants to merge 1 commit into
idanlevi1 wants to merge 1 commit into
Conversation
… on read By default a protected keychain read can be satisfied without prompting when the user authenticated (or unlocked the device) very recently: - iOS: an item protected only by the device passcode is returned silently by SecItemCopyMatching while the device is unlocked, and biometric reads honor touchIDAuthenticationAllowableReuseDuration. - Android: the underlying key stays usable for a short validity window (~5s, validityDuration in getKeyGenSpecBuilder) after the last authentication, so a read within that window decrypts without a new BiometricPrompt. For high-assurance actions (signing, step-up auth) callers need a guaranteed fresh prompt on every read. This adds an opt-in, typed GetOptions field `authenticationFreshness: AUTHENTICATION_FRESHNESS`: - ALLOW_REUSE (default) — unchanged behavior, a recent auth may satisfy the read. - REQUIRE_FRESH — force a fresh OS authentication prompt on every read. iOS: evaluate the device-owner policy (respecting authenticationType) on a dedicated LAContext with a zero reuse duration, then pass it via kSecUseAuthenticationContext so the granted authorization satisfies the lookup without a second prompt. Android: for auth-gated keys, drive the interactive BiometricPrompt up front instead of the optimistic decrypt that would succeed inside the validity window. Threaded to the cipher via a ResultHandler.requireFreshAuth flag; non auth-gated keys and encrypt paths are unaffected. Default behavior is unchanged; the option is fully backward compatible.
This was referenced Aug 28, 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.
Motivation
By default a protected keychain read can be satisfied without prompting when the user authenticated (or unlocked the device) very recently:
SecItemCopyMatchingwhile the device is unlocked (no prompt), and biometric reads honortouchIDAuthenticationAllowableReuseDuration.validityDurationingetKeyGenSpecBuilder), so a read inside that window decrypts without a newBiometricPrompt.This is the behavior noted in the
AUTH_INVALIDATEDdocs: "Due to the way this library currently handles user authentication validity duration…".For high-assurance actions (transaction signing, step-up auth) an app needs a guaranteed fresh prompt on every read. Today there's no way to request that.
What this adds
A new opt-in, typed
GetOptionsfield:Implementation
RNKeychainManager.mm) — whenREQUIRE_FRESH, evaluate the device-owner policy (via the existingauthPolicy(options), soauthenticationTypeis respected) on a dedicatedLAContextwithtouchIDAuthenticationAllowableReuseDuration = 0, then pass that context viakSecUseAuthenticationContextso the just-granted authorization satisfies the lookup without a second prompt.KeychainModule→ResultHandler.requireFreshAuth→CipherStorageKeystoreAesGcm/CipherStorageKeystoreRsaEcb) — for auth-gated keys, drive the interactiveBiometricPromptup front instead of taking the optimistic decrypt that would succeed inside the validity window. Non auth-gated keys and all encrypt paths are unchanged.Compatibility
ALLOW_REUSE; existing callers are unaffected.optionsis already a genericObject).GetOptionsfield (feeds the generated API docs).Testing
tscpasses on the changed TS.KeychainExampleand any Android instrumentation you'd like included.cc @oblador @DorianMazur — happy to adjust the naming/shape (e.g. fold into an existing option) to match your preferences.