Skip to content
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

Add id_RSAES_OAEP to asymmetricWrapperAlgNames #953

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jensthomassen
Copy link

This makes it easier to decode SCEP requests from some Windows computers with OAEP Padding using the JSCEP library.
Without the patch, I see this Exception:

Caused by: org.bouncycastle.cms.CMSException: exception unwrapping key: cannot create cipher: Cannot find any provider supporting 1.2.840.113549.1.1.7
at org.bouncycastle.cms.jcajce.JceKeyTransRecipient.extractSecretKey(Unknown Source)
at org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient.getRecipientOperator(Unknown Source)
at org.jscep.message.PkcsPkiEnvelopeDecoder$InternalKeyTransEnvelopedRecipient.getRecipientOperator(PkcsPkiEnvelopeDecoder.java:150)
at org.bouncycastle.cms.KeyTransRecipientInformation.getRecipientOperator(Unknown Source)
at org.bouncycastle.cms.RecipientInformation.getContentStream(Unknown Source)
at org.bouncycastle.cms.RecipientInformation.getContent(Unknown Source)
at org.jscep.message.PkcsPkiEnvelopeDecoder.decode(PkcsPkiEnvelopeDecoder.java:92)
... 67 more
Caused by: org.bouncycastle.operator.OperatorCreationException: cannot create cipher: Cannot find any provider supporting 1.2.840.113549.1.1.7
at org.bouncycastle.operator.jcajce.OperatorHelper.createAsymmetricWrapper(Unknown Source)
at org.bouncycastle.operator.jcajce.JceAsymmetricKeyUnwrapper.generateUnwrappedKey(Unknown Source)
... 74 more
Caused by: java.security.NoSuchAlgorithmException: Cannot find any provider supporting 1.2.840.113549.1.1.7
at javax.crypto.Cipher.getInstance(Unknown Source)
at org.bouncycastle.jcajce.util.DefaultJcaJceHelper.createCipher(Unknown Source)
... 76 more

@cubicrace
Copy link

We need this for the Microsoft Intune SCEP flow

@dghgit
Copy link
Contributor

dghgit commented May 18, 2021

Unfortunately this patch would almost completely break the use of OAEP in the CMS library (evidently it would work for the case specified). I think there's a way out of this though. If I understand correctly the system only recognizes the full name. Can you tell me what other OAEP algorithms the system can handle, or is it just one.

@jensthomassen
Copy link
Author

jensthomassen commented May 18, 2021 via email

@dghgit
Copy link
Contributor

dghgit commented May 18, 2021

OAEP also has an algorithm parameters block in the AlgorithmIdentifier - RSA/ECB/OAEPWithSHA-1AndMGF1Padding is what you would call the default setting. The question was more about what does the provider being used had available in it? Or are you saying you are using the BC provider?

@cubicrace
Copy link

https://docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html

The above link lists all the possible ciphers that every java platform must implement.
We are interested in these 3:
RSA/ECB/PKCS1Padding (1024, 2048)
RSA/ECB/OAEPWithSHA-1AndMGF1Padding (1024, 2048) - OID mapping missing in BC based on the current PR
RSA/ECB/OAEPWithSHA-256AndMGF1Padding (1024, 2048) - OID mapping missing in BC based on the current PR

@jensthomassen
Copy link
Author

jensthomassen commented May 18, 2021 via email

@dghgit
Copy link
Contributor

dghgit commented May 18, 2021

I'll look into it - it'll need to map to the algorithm name based on the parameters though the OID is for OAEP, not for OAEP with SHA1 or SHA256, so what's required is to recognise the oid explicitly and then generate an algorithm name from the combination of the OID and the parameters block.

@adams-y-chen
Copy link

adams-y-chen commented Nov 15, 2022

@dghgit @cubicrace @jensthomassen

I also need this for my project. My Java application throws similar exception when unwrapping PKCS7 CMS envelope created by ASP.NET.

I don't have the answer for the algorithm naming yet. But I find this OID to name mapping in AllTests.java.

        assertEquals(nameFinder.getAlgorithmName(PKCSObjectIdentifiers.id_RSAES_OAEP), "RSAOAEP");

So we might need this mapping in PR

        asymmetricWrapperAlgNames.put(PKCSObjectIdentifiers.id_RSAES_OAEP, "RSAOAEP");

instead of

        asymmetricWrapperAlgNames.put(PKCSObjectIdentifiers.id_RSAES_OAEP, "RSA/ECB/OAEPWithSHA-1AndMGF1Padding");

Any thought on that?

ASP.NET PKCS7 CMS code link for reference:
https://referencesource.microsoft.com/#System.Security/system/security/cryptography/pkcs/envelopedpkcs7.cs

@adams-y-chen
Copy link

adams-y-chen commented Nov 19, 2022

I have tested and can confirm "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" is the right name. I'm able to unwrap PKCS7 CMS envelope created using ASP .NET.

@dghgit
Copy link
Contributor

dghgit commented Nov 19, 2022

Can you send me an example which we can try and work with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants