crypto: ensure expected JWK alg in SubtleCrypto.importKey RSA imports · nodejs/node@ada572b · GitHub
Skip to content

Commit ada572b

Browse files
panvaRafaelGSS
authored andcommitted
crypto: ensure expected JWK alg in SubtleCrypto.importKey RSA imports
PR-URL: #57450 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent c35e1f9 commit ada572b

3 files changed

Lines changed: 74 additions & 19 deletions

File tree

lib/internal/crypto/hashnames.js

Lines changed: 3 additions & 8 deletions

lib/internal/crypto/rsa.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,13 @@ function rsaImportKey(
275275
}
276276

277277
if (keyData.alg !== undefined) {
278-
const hash =
279-
normalizeHashName(keyData.alg, normalizeHashName.kContextWebCrypto);
280-
if (hash !== algorithm.hash.name)
278+
const expected =
279+
normalizeHashName(algorithm.hash.name,
280+
algorithm.name === 'RSASSA-PKCS1-v1_5' ? normalizeHashName.kContextJwkRsa :
281+
algorithm.name === 'RSA-PSS' ? normalizeHashName.kContextJwkRsaPss :
282+
normalizeHashName.kContextJwkRsaOaep);
283+
284+
if (keyData.alg !== expected)
281285
throw lazyDOMException(
282286
'JWK "alg" does not match the requested algorithm',
283287
'DataError');

test/parallel/test-webcrypto-export-import-rsa.js

Lines changed: 64 additions & 8 deletions

0 commit comments

Comments
 (0)