fix(storage): authorize MGF1 digest to prevent INCOMPATIBLE_DEVICE on…3.x - #1048
Merged
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
utkrishtsahu
force-pushed
the
fix/mgf1-incompatible-device-3.21.x
branch
from
August 12, 2026 13:35
554bc34 to
df1d9f5
Compare
utkrishtsahu
force-pushed
the
fix/mgf1-incompatible-device-3.21.x
branch
from
August 18, 2026 04:38
df1d9f5 to
fcb50ee
Compare
pmathew92
approved these changes
Aug 18, 2026
Merged
5 tasks
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.
Changes
What & why: On newer Android Keystore2 hardware,
SecureCredentialsManagercan fail immediately after a successful login withCredentialsManagerException.INCOMPATIBLE_DEVICE("This device is not compatible with the ... class"), blocking token persistence even though authentication succeeded. Reported viareact-native-auth0(which depends on this 3.x line) on Pixel 10 / Galaxy S26 (Android 16+).Root cause:
CryptoUtilencrypts stored credentials with an RSA-OAEP key whose cipher uses the MGF1/SHA-1 digest, but the key was generated without explicitly authorizing an MGF1 digest. Older KeyMint defaulted the MGF1 digest to SHA-1, so it matched. Newer Keystore2 firmware strictly enforces the authorized MGF1 set and its default is vendor-dependent (some default to SHA-256), so the private-key decrypt is rejected withINCOMPATIBLE_MGF_DIGEST("Incompatible padding mode") and surfaces asINCOMPATIBLE_DEVICE.Changes (both in
CryptoUtil.java, no public API change):getRSAKeyEntry()— when generating a new RSA key, explicitly authorize the MGF1 digests (SHA-1andSHA-256) viaKeyGenParameterSpec.Builder#setMgf1Digests, guarded toBuild.VERSION_CODES.VANILLA_ICE_CREAM(API 35+, where the API exists). The key no longer depends on the vendor's MGF1 default.RSADecrypt()—InvalidKeyException/InvalidAlgorithmParameterException(the MGF1-authorization rejection on an existing, pre-fix key) are now treated as recoverable: delete the stale RSA + AES keys and throwCryptoExceptionso the caller regenerates a correctly-authorized key, instead of the terminalIncompatibleDeviceException.NoSuchAlgorithmException/NoSuchPaddingExceptionremain terminal (genuine device incompatibility). This self-heals users already stuck (one re-login).No endpoints, classes, or public methods added/removed/deprecated.
CryptoUtilis internal; behavior change only.Testing
CryptoUtilcannot exercise the real Android Keystore under unit tests (Robolectric mocks it), so the hardware behavior was validated on physical devices and the exception-handling logic via unit tests.InvalidKeyExceptiontest to assert the new recovery behavior (throwsCryptoException, deletes RSA + AES keys) and added an equivalent test forInvalidAlgorithmParameterException.:auth0:testDebugUnitTestand:auth0:lintDebugpass (JDK 11).INCOMPATIBLE_MGF_DIGESTfailure, and that generating the key withsetMgf1Digests(SHA-1, SHA-256)+ the SDK's MGF1/SHA-1 cipher round-trips successfully.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