fix: Handle ProviderException in PKCS1→OAEP key migration to prevent saveCredentials() crash#924
Conversation
… prevent saveCredentials() crash
|
Our crashes originated from Android 16 devices, will this fix work for them too? |
|
@alexRocket891 This is still a WIP as we want to ensure to cover all areas where the crash can occur and should work on all devices irrespective of the version. But we are not able to replicate the crash on our devices which makes the testing a bit difficult |
…S1-OAEP-key-migration-to-prevent-saveCredentials-crash
auth0/src/main/java/com/auth0/android/authentication/storage/CryptoUtil.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Fixes a crash during RSA PKCS1 → OAEP key migration on Android 12+ (Keystore2) by handling ProviderException cases and improving key cleanup/migration behavior in CryptoUtil, with accompanying unit tests.
Changes:
- Catch
ProviderExceptionin RSA encrypt/decrypt paths to avoid uncaught crashes on Keystore2. - Ensure legacy PKCS1 AES key migration deletes stale RSA keys before re-encrypting with OAEP.
- Add unit tests covering the new exception handling and migration/cleanup flows.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
auth0/src/main/java/com/auth0/android/authentication/storage/CryptoUtil.java |
Adds ProviderException handling and adjusts key migration/cleanup ordering to avoid Keystore2 padding-mismatch crashes. |
auth0/src/test/java/com/auth0/android/authentication/storage/CryptoUtilTest.java |
Adds new unit tests for ProviderException handling, RSA deletion ordering, and cleanup behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Changes
CryptoUtil.java — bug fix, no public API changes:
CryptoUtilTest.java — 5 new unit tests covering all four fix paths.
No public API surface changes. SecureCredentialsManager.saveCredentials() behaviour is unchanged from the caller's perspective — the migration is fully transparent.
References
#923
Testing
This change adds unit test coverage — 5 tests in CryptoUtilTest covering ProviderException in encrypt/decrypt, deleteRSAKeys() ordering, IncompatibleDeviceException cleanup, and the end-to-end migration flow. All pass via ./gradlew :auth0:test.
Tested on latest platform — verified end-to-end on Pixel 7a (Android 16) by installing a pre-OAEP build (commit 854fbc9) to seed the Keystore with a PKCS1 key, then upgrading to the fixed build. saveCredentials() self-healed in a single call with no user action required. Fixes SecureCredentialsManager.saveCredentials() started crashing in new version. #923.
Checklist
I have read the Auth0 general contribution guidelines
I have read the Auth0 Code of Conduct
All existing and new tests complete without errors