-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
WebCrypto reports unsupported JWK key type when exporting a key #39805
Comments
@SakerGT can you provide the value of the certificate? |
The problem with rsa-pss key export to JWK is that we don't know if the key has any constraining parameters or not and that JWK format has no way of preserving them. This is similar to why we don't allow rsa-pss private keys to be exported to pkcs1. |
cc @nodejs/crypto |
@panva Absolutely, sorry I should have included earlier. Here is the contents of the PEM file (github won't allow me to attach):
|
Ah yes, I see what you mean. In my example, I have not set any constraints on the key. As a last resort, could the full certificate be exported in |
The certificate does contain PSS parameters, for those JWK does not have a representation for. But even if the key had no PSS parameters we have no way of knowing - @tniessen am i right here? Is that why pkcs1 private rsa-pss key export is out right blocked as well? Because pkcs1 cannot represent those parameters?
No, |
@tniessen would likely know better than I, but that's my understanding also. |
Hmm, perhaps I have misunderstood what you mean by parameter restrictions. It is obviously necessary to have information that the certificate is PSS, but I didn't (at least intentionally) set any key restrictions per OpenSSL. My apologies if I've caused any confusion. For RSA keys in JWK, aren't only
I wasn't suggesting only I accept the standard simply does not have any other means to accommodate PSS parameters this today. |
It's part of the reason. The main reason is that RSA-PSS has the OID |
Just to be clear, I don't want to export the private rsa-pss key to JWK. Only the public rsa-pss key contained in a certificate. |
A number of points I have
🐛 Because of 4) we rely on OpenSSL to throw if the PSS Parameters in the key don't match the SubtleCrypto Algorithm, but we don't do so when importing the key, it is done so for us during sign/verify. 🐛 🐛 We should allow RSA-PSS key export as JWK in WebCrypto but because of the lack of information that PSS Parameters are present and lack of Algorithm support on KeyObject instances we shouldn't do the same in keyObject.export({ format: 'jwk' }) 🐛 I am not entirely sure how to proceed on these. NB: Chromium chose to not support |
As noted above I've checked the specification and WebCryptoAPI is fine to export your key as JWK because the
You're free to assign the x5c parameter after the export. But our KeyObject abstraction has no knowledge of the value of the certificate, the same applies to WebCrypto API where X.509 is not even supported. |
Cool, that's sort of what I'd thought from reading the specs.
Understood and all good. I appreciate you taking the time to follow up on this. |
It's been a while since I worked on Node.js crypto internals, but that should not happen. |
X.509 > createPublicKey > keyObject.export({ format: 'pem', type: 'spki' }) |
@panva That looks correct to me. |
The lack of sha-512 and pkcs1-MGF in the SPKI doesn't to me, but i'll leave this be as it's not my forte. I guess what it looks like to me is that certificate has constraints that the SPKI does not? |
Oh, sorry, I see the source of confusion. The certificate you posted only contains PSS parameters in the TBSCertificate ::= SEQUENCE {
version [0] Version DEFAULT v1,
serialNumber CertificateSerialNumber,
signature AlgorithmIdentifier{SIGNATURE-ALGORITHM,
{SignatureAlgorithms}},
issuer Name,
validity Validity,
subject Name,
subjectPublicKeyInfo SubjectPublicKeyInfo,
... ,
[[2: -- If present, version MUST be v2
issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL
]],
[[3: -- If present, version MUST be v3 --
extensions [3] Extensions{{CertExtensions}} OPTIONAL
]], ... } You could have a certificate that is signed with EC but contains an RSA public key. |
🙇 thank you for enlightening me |
This was fixed with #39828 |
Version
v16.7.0
Platform
Linux cloud 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
WebCrypto
What steps will reproduce the bug?
This is a bit long winded, but here is what causes the issue for me.
Results in:
Works in v16.5.0 and earlier
How often does it reproduce? Is there a required condition?
Always reproducible
What is the expected behavior?
Should export a JWK with
kty: 'RSA'
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: