Skip to content

Commit 695591e

Browse files
panvatargos
authored andcommitted
crypto: fix webcrypto RSA generateKey() use of publicExponent
PR-URL: #43431 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent f7f940d commit 695591e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/internal/crypto/rsa.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async function rsaKeyGenerate(
176176
return new Promise((resolve, reject) => {
177177
generateKeyPair('rsa', {
178178
modulusLength,
179-
publicExponentConverted,
179+
publicExponent: publicExponentConverted,
180180
}, (err, pubKey, privKey) => {
181181
if (err) {
182182
return reject(lazyDOMException(

test/parallel/test-webcrypto-keygen.js

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --expose-internals
12
'use strict';
23

34
const common = require('../common');
@@ -10,8 +11,11 @@ const { types: { isCryptoKey } } = require('util');
1011
const {
1112
webcrypto: { subtle, CryptoKey },
1213
createSecretKey,
14+
KeyObject,
1315
} = require('crypto');
1416

17+
const { bigIntArrayToUnsignedBigInt } = require('internal/crypto/util');
18+
1519
const allUsages = [
1620
'encrypt',
1721
'decrypt',
@@ -264,10 +268,16 @@ const vectors = {
264268
assert.strictEqual(publicKey.algorithm.name, name);
265269
assert.strictEqual(publicKey.algorithm.modulusLength, modulusLength);
266270
assert.deepStrictEqual(publicKey.algorithm.publicExponent, publicExponent);
271+
assert.strictEqual(
272+
KeyObject.from(publicKey).asymmetricKeyDetails.publicExponent,
273+
bigIntArrayToUnsignedBigInt(publicExponent));
267274
assert.strictEqual(publicKey.algorithm.hash.name, hash);
268275
assert.strictEqual(privateKey.algorithm.name, name);
269276
assert.strictEqual(privateKey.algorithm.modulusLength, modulusLength);
270277
assert.deepStrictEqual(privateKey.algorithm.publicExponent, publicExponent);
278+
assert.strictEqual(
279+
KeyObject.from(privateKey).asymmetricKeyDetails.publicExponent,
280+
bigIntArrayToUnsignedBigInt(publicExponent));
271281
assert.strictEqual(privateKey.algorithm.hash.name, hash);
272282

273283
// Missing parameters
@@ -344,6 +354,17 @@ const vectors = {
344354
code: 'ERR_INVALID_ARG_TYPE'
345355
});
346356
}));
357+
358+
await Promise.all([[1], [1, 0, 0]].map((publicExponent) => {
359+
return assert.rejects(subtle.generateKey({
360+
name,
361+
modulusLength,
362+
publicExponent: new Uint8Array(publicExponent),
363+
hash
364+
}, true, usages), {
365+
name: 'OperationError',
366+
});
367+
}));
347368
}
348369

349370
const kTests = [

0 commit comments

Comments
 (0)