Skip to content

Commit 97a7d92

Browse files
committed
crypto: validate key generation options
Reject null options with ERR_INVALID_ARG_TYPE. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent 2e62e1d commit 97a7d92

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/internal/crypto/keygen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ const nidOnlyKeyPairs = {
209209
function createJob(mode, type, options) {
210210
validateString(type, 'type');
211211

212-
const encoding = new SafeArrayIterator(parseKeyEncoding(type, options));
213-
214212
if (options !== undefined)
215213
validateObject(options, 'options');
216214

215+
const encoding = new SafeArrayIterator(parseKeyEncoding(type, options));
216+
217217
switch (type) {
218218
case 'rsa':
219219
case 'rsa-pss':

test/parallel/test-crypto-keygen.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ const isBoringSSL = process.features.openssl_is_boringssl;
8989
message: 'The "options" argument must be of type object. ' +
9090
'Received type number (0)'
9191
});
92+
93+
for (const type of ['rsa', 'ed25519']) {
94+
assert.throws(() => generateKeyPairSync(type, null), {
95+
name: 'TypeError',
96+
code: 'ERR_INVALID_ARG_TYPE',
97+
message: 'The "options" argument must be of type object. ' +
98+
'Received null'
99+
});
100+
assert.throws(() => generateKeyPair(type, null, common.mustNotCall()), {
101+
name: 'TypeError',
102+
code: 'ERR_INVALID_ARG_TYPE',
103+
message: 'The "options" argument must be of type object. ' +
104+
'Received null'
105+
});
106+
}
92107
}
93108

94109
{

0 commit comments

Comments
 (0)