Skip to content

Commit 6cd9328

Browse files
committed
crypto: fix webcrypto generateKey() AES key length validation error
1 parent c3ff198 commit 6cd9328

File tree

3 files changed

+7
-681
lines changed

3 files changed

+7
-681
lines changed

lib/internal/crypto/aes.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ const {
6060
generateKey,
6161
} = require('internal/crypto/keygen');
6262

63-
const {
64-
validateInteger,
65-
validateOneOf,
66-
} = require('internal/validators');
67-
6863
const kMaxCounterLength = 128;
6964
const kTagLengths = [32, 64, 96, 104, 112, 120, 128];
7065

@@ -227,8 +222,11 @@ function aesCipher(mode, key, data, algorithm) {
227222

228223
async function aesGenerateKey(algorithm, extractable, keyUsages) {
229224
const { name, length } = algorithm;
230-
validateInteger(length, 'algorithm.length');
231-
validateOneOf(length, 'algorithm.length', kAesKeyLengths);
225+
if (!ArrayPrototypeIncludes(kAesKeyLengths, length)) {
226+
throw lazyDOMException(
227+
'AES key length must be 128, 192, or 256 bits',
228+
'OperationError');
229+
}
232230

233231
const checkUsages = ['wrapKey', 'unwrapKey'];
234232
if (name !== 'AES-KW')

test/parallel/test-webcrypto-keygen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,14 @@ const vectors = {
512512
[1, 100, 257].forEach(async (length) => {
513513
await assert.rejects(
514514
subtle.generateKey({ name, length }, true, usages), {
515-
code: 'ERR_INVALID_ARG_VALUE'
515+
name: 'OperationError'
516516
});
517517
});
518518

519519
['', {}, [], false, null, undefined].forEach(async (length) => {
520520
await assert.rejects(
521521
subtle.generateKey({ name, length }, true, usages), {
522-
code: 'ERR_INVALID_ARG_TYPE'
522+
name: 'OperationError',
523523
});
524524
});
525525
}

0 commit comments

Comments
 (0)