Feat: new error code indicating that ios private key is corrupted#87
Conversation
📝 WalkthroughWalkthroughImport of CryptoTokenKit enables detection of corrupted cryptographic key data during signature operations. The error-handling logic in key-integrity signature creation and key-signature verification now specifically maps Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ios/ReactNativeBiometrics.swift (1)
830-831: GuardcorruptedDatamapping by error domain, not code alone.Lines 830 and 1015 currently match only on numeric code. Add a TokenKit domain check using
CFErrorGetDomainto avoid accidental misclassification when different error domains share the same code value.Suggested patch
let errorCode = CFErrorGetCode(cfError) + let errorDomain = CFErrorGetDomain(cfError) as String if errorCode == errSecUserCanceled { biometricsError = .userCancel } else if errorCode == errSecAuthFailed { biometricsError = .authenticationFailed - } else if errorCode == TKError.Code.corruptedData.rawValue { + } else if errorDomain == TKError.errorDomain && + errorCode == TKError.Code.corruptedData.rawValue { biometricsError = .keyAccessFailed } else { biometricsError = .signatureCreationFailed }let errorCode = CFErrorGetCode(cfError) + let errorDomain = CFErrorGetDomain(cfError) as String if errorCode == errSecUserCanceled { biometricsError = ReactNativeBiometricsError.userCancel } else if errorCode == errSecAuthFailed { biometricsError = ReactNativeBiometricsError.authenticationFailed - } else if errorCode == TKError.Code.corruptedData.rawValue { + } else if errorDomain == TKError.errorDomain && + errorCode == TKError.Code.corruptedData.rawValue { biometricsError = ReactNativeBiometricsError.keyAccessFailed } else { biometricsError = ReactNativeBiometricsError.signatureCreationFailed }Also applies to: 1015-1016
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ios/ReactNativeBiometrics.swift` around lines 830 - 831, The mapping for TKError.Code.corruptedData currently checks only the numeric code and may misclassify errors from other domains; update the error-to-biometricsError mapping (the branches that inspect TKError.Code.corruptedData and set biometricsError = .keyAccessFailed) to first verify the CFError domain by calling CFErrorGetDomain(error as CFError) (or comparing (error as NSError).domain) equals TKErrorDomain before relying on the numeric code, and apply this same domain-guarded check in both places where corruptedData is handled so only TokenKit errors are mapped to .keyAccessFailed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ios/ReactNativeBiometrics.swift`:
- Around line 830-831: The mapping for TKError.Code.corruptedData currently
checks only the numeric code and may misclassify errors from other domains;
update the error-to-biometricsError mapping (the branches that inspect
TKError.Code.corruptedData and set biometricsError = .keyAccessFailed) to first
verify the CFError domain by calling CFErrorGetDomain(error as CFError) (or
comparing (error as NSError).domain) equals TKErrorDomain before relying on the
numeric code, and apply this same domain-guarded check in both places where
corruptedData is handled so only TokenKit errors are mapped to .keyAccessFailed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3ae4488d-b5aa-42d8-abcf-56a572bac395
📒 Files selected for processing (1)
ios/ReactNativeBiometrics.swift
This pull request adds a new error code that can be returned by signWithOptions or ValidateKeyIntegrity, which indicates private key corruption (due to e.g. invalidation by credentials re-enrollment).
Summary by CodeRabbit