-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Android] Normalize RSA no-padding output to modulus size to fix VerifyHash #118880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Normalize RSA no-padding output to modulus size to fix VerifyHash #118880
Conversation
|
/azp run runtime-extra-platforms |
|
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a compatibility issue with Android crypto libraries where RSA verification operations return minimal-length results instead of modulus-sized outputs. The fix ensures that RSA verification results are properly normalized to the expected modulus size by left-padding with zeros when necessary.
Key changes:
- Added validation to ensure decrypted bytes don't exceed expected length
- Implemented left-padding with zeros to normalize output to modulus size
- Updated return value calculation to reflect the normalized length
|
/backport to release/10.0-rc1 |
|
Started backporting to release/10.0-rc1: https://github.com/dotnet/runtime/actions/runs/17096489581 |
|
@simonrozsival does this impact Android on net9.0 on newer Android versions? If so it might be worth taking the backport back to 9 and 8. |
|
@vcsjones yes, we should backport this to .NET 9 as well. I don't know if we should backport to .NET 8 as well, since .NET MAUI 8 is already out of support. |
|
/backport to release/9.0-staging |
|
Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/17099292564 |
Given #118366 happened in CI I'd say we should at least backport disabling the test if we don't backport the fix. Or disable running Android jobs in 8.0 😄 |
|
/backport to release/10.0 |
|
Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17120602273 |
It appears some versions of the Android crypto libraries the
"RSA/ECB/NoPadding"returns results as minimal-length big-endian integers (leading 0x00 trimmed), causingRsaVerificationPrimitiveto return fewer bytes than the modulus (e.g., 47 vs 48). This breaksRSAAndroid.VerifyHashand tests likePublicKeyTests.TestKey_RSA384_ValidatesSignaturefail.In the failing test, the
decryptedBytescontained the following 47 bytes when running on a Samsung device with Android API 35:The leading 0x00 byte in the signature padding is missing in this case (the expected RSA signature padding is
0x00 0x01 0xFF ... 0xFF 0x00).Fixes #118366
/cc @bartonjs @vcsjones @vitek-karas @BrzVlad