Skip to content

Commit 4276516

Browse files
panvatargos
authored andcommitted
crypto: normalize RsaHashedKeyParams publicExponent
Fixes: #59535 PR-URL: #59538Fixes: #59534 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 0821b44 commit 4276516

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

‎lib/internal/crypto/util.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,9 @@ const kSupportedAlgorithms = createSupportedAlgorithms(kAlgorithmDefinitions);
397397

398398
constsimpleAlgorithmDictionaries={
399399
AeadParams: {iv: 'BufferSource',additionalData: 'BufferSource'},
400-
RsaHashedKeyGenParams: {hash: 'HashAlgorithmIdentifier'},
400+
// publicExponent is not strictly a BufferSource but it is a Uint8Array that we normalize
401+
// this way
402+
RsaHashedKeyGenParams: {hash: 'HashAlgorithmIdentifier',publicExponent: 'BufferSource'},
401403
EcKeyGenParams: {},
402404
HmacKeyGenParams: {hash: 'HashAlgorithmIdentifier'},
403405
RsaPssParams: {},

‎test/parallel/test-webcrypto-keygen.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,20 @@ if (hasOpenSSL(3, 5)){
311311
assert.deepStrictEqual(privateKey.usages,privateUsages);
312312
assert.strictEqual(publicKey.algorithm.name,name);
313313
assert.strictEqual(publicKey.algorithm.modulusLength,modulusLength);
314-
assert.deepStrictEqual(publicKey.algorithm.publicExponent,publicExponent);
314+
assert(publicKey.algorithm.publicExponentinstanceofUint8Array);
315+
assert.notStrictEqual(publicKey.algorithm.publicExponent,publicExponent);
316+
assert(!Buffer.isBuffer(publicKey.algorithm.publicExponent));
317+
assert.deepStrictEqual(publicKey.algorithm.publicExponent,newUint8Array(publicExponent));
315318
assert.strictEqual(
316319
KeyObject.from(publicKey).asymmetricKeyDetails.publicExponent,
317320
bigIntArrayToUnsignedBigInt(publicExponent));
318321
assert.strictEqual(publicKey.algorithm.hash.name,hash);
319322
assert.strictEqual(privateKey.algorithm.name,name);
320323
assert.strictEqual(privateKey.algorithm.modulusLength,modulusLength);
321-
assert.deepStrictEqual(privateKey.algorithm.publicExponent,publicExponent);
324+
assert(privateKey.algorithm.publicExponentinstanceofUint8Array);
325+
assert.notStrictEqual(privateKey.algorithm.publicExponent,publicExponent);
326+
assert(!Buffer.isBuffer(privateKey.algorithm.publicExponent));
327+
assert.deepStrictEqual(privateKey.algorithm.publicExponent,newUint8Array(publicExponent));
322328
assert.strictEqual(
323329
KeyObject.from(privateKey).asymmetricKeyDetails.publicExponent,
324330
bigIntArrayToUnsignedBigInt(publicExponent));

0 commit comments

Comments
(0)