crypto: fix JWK RSA-PSS SubtleCrypto.exportKey#39828
crypto: fix JWK RSA-PSS SubtleCrypto.exportKey#39828panva wants to merge 3 commits intonodejs:masterfrom
Conversation
|
cc @nodejs/crypto |
|
Does this intentionally drop RSA-PSS parameters? That seems to be in violation of the Web Crypto API spec (RSA-PSS "Export Key" operation), and it also seems wrong to remove parameters from a key. If crypto does that (#39805 (comment)), then that's probably a bug in crypto. |
tniessen
left a comment
There was a problem hiding this comment.
Making my concerns explicit.
@tniessen You've got it backwards - this explicitly allows the JWK export only in Web Crypto API because the CryptoKey instance is already tied to a single Algorithm that represents the digest and use/value of RSA-PSS parameters. WebCryptoAPI exports the "alg" in addition to the key material here in accordance with the Web Cryptography API specification RSA-PSS > Export Key > JWK. The WebCrypto API does not drop anything. However, because KeyObject does not have that strong tie between its instance and digest and RSA-PSS parameters (and it therefore does not export any "alg" value) we continue to not allow rsa-pss key export as JWK from |
|
This is actually fixing a regression introduced in #39319 |
Ah, so the import function ensures that the |
| { name: 'RSA-PSS', hash: 'SHA-256' }, | ||
| true, | ||
| ['verify']); | ||
| await subtle.exportKey('jwk', key); |
There was a problem hiding this comment.
Could you add assertions about the returned JWK then? In particular, that it preserves the hash function?
Since we have no way of checking the PSS Params (as you know) it does not. You can end up with CryptoKey that does have a different algorithm than the underlying key material. Such key will however fail to be used with both sign and verify. I would say that is a different bug in the Web Crypto API implementation that we should think about how to fix - i.e. how to add RSA-PSS params to |
This comment has been minimized.
This comment has been minimized.
PR-URL: #39828 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
|
Landed in 4441c3e |
PR-URL: #39828 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
Allows JWK export from WebCryptoAPI whilst keeping the restriction on
KeyObject.prototype.export()Refs #39805