-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Exception when unwrapping PKCS7 CMS envelope that encrypted with RSAES-OAEP (1.2.840.113549.1.1.7) asymmetric algorithm #1277
Comments
Here is a related PR that was proposed by @jensthomassen. |
For those who have similar concern, here is a workaround by specifying the mapping in your application code.
|
Thanks for the report, this makes it a bit clearer what is going on. So, part of the issue is going to be the use of the SunJCE which doesn't recognize the OAEP OID, but instead uses "OAEP" for the algorithm parameters and "RSA/ECB/OAEPPadding" for the default cipher name. BC actually supports both, so I've added support for it. I'm not sure this will fix the other issue though - the PR is "wrong", as is the mapping above, it will work for the specific case but not for OAEP in general. From what you are describing here it may just be that the original submitter didn't realize there were algorithm parameters involved. Try the bcpkix jar at https://www.bouncycastle.org/betas (173b09 or later) - it has the SunJCE fix in it. This may fix the problem. Let me know how you go. |
…or SunJCE (relates to github bcgit#1277)
@dghgit thanks for getting back to me. I want to clarify so we have mutual understanding of the gap and request. From what I understand, JCE expects a name string in Also, could you be more specific on the issues that may be caused by #953? Updated: |
#953 fails to take into account that RSA OAEP has algorithm parameters and is used with SHA-1, SHA-2, SHA-3 and even the XOFs SHAKE-128 and SHAKE-256. Try the beta - it's the bcpkix jar you want. |
@dghgit thanks for explaining it. To reflect on what I heard, JCE I will figure out how I can consume the beta build in my app before it's available in Maven. In the meantime, do you have an estimation on when the beta build will become GA in maven? |
@dghgit I'd like to have you opinion on another exception in my application after I switched from SpongyCastle to BouncyCastle 1.70. The exception complains that provider for PBKDFS2 (1.2.840.113549.1.5.12) can't be found when attempts to decrypt PKCS12 keystore file. Do you think if this is also addressed by the latest beta build https://www.bouncycastle.org/betas? Backtrace:
PBKDF2 OID References: |
We've supported PBKDFS2 for quite a while now. The issue you have here is that the stack trace isn't from Bouncy Castle, it's from the Android fork of it. Spongy Castle is Bouncy Castle, the BC built into Android... well, not quite. |
@adams-y-chen would you confirm if the beta fixed the problem? Thanks. |
@dghgit sorry for getting back to you late. I was pulled away from this. I will get back to it and let you know how it goes. |
@dghgit, I run the test code today with both BouncyCastle beta build and 1.70 release build. However, I'm not able to reproduce the issue today with both builds. This would prevent me from getting a conclusion whether this issue is addressed in the beta build. To give some context, I encountered compiling issue after come back to my Android repo. After I made some attempts to address the issue which including clean up the reop, I can no longer reproduce the issue by running my Android Unit Test on my desktop with BouncyCastle 1.70. You mentioned that the issue was tied to SunJCE. I'd like to troubleshoot and check if SunJCE is called by my UTs. Could you share some guidance on the items below?
I can share my test code, test certificate and PCKS CMS envelope if you need to reproduce on your end. |
Symptom:
My java application throws exception when unwrapping PKCS7 CMS envelope that encrypted with RSAES-OAEP. The PKCS7 CMS envelope is created using Microsoft .NET.
RFC Spec and RSAES-OAEP Definition: 1.2.840.113549.1.1.7
IETF RFC 3447 and RFC 8017.
Backtrace:
Root cause:
The mapping from
PKCSObjectIdentifiers.id_RSAES_OAEP
(i.e. OID 1.2.840.113549.1.1.7) to RSAES-OAEP algorithm name is missing inasymmetricWrapperAlgNames
.See: OperatorHelper.java
This would result in passing the OID string to
javax.crypto.Cipher.createCipher
instead of a valid Cipher algorithm name. This eventually caused the exception as the OID string is not a valid Cipher algorithm name in JCE/JCA.To fix the issue, the mapping from
PKCSObjectIdentifiers.id_RSAES_OAEP
(i.e. OID 1.2.840.113549.1.1.7) to RSAES-OAEP algorithm name is needed inasymmetricWrapperAlgNames
inOperatorHelper.java
.Proposal:
Add the mapping from
PKCSObjectIdentifiers.id_RSAES_OAEP
(i.e. OID 1.2.840.113549.1.1.7) to RSAES-OAEP algorithm name inasymmetricWrapperAlgNames
inOperatorHelper.java
.The text was updated successfully, but these errors were encountered: