Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a60ae67

Browse filesBrowse files
panvadanielleadams
authored andcommitted
crypto: fix webcrypto generateKey() AES key length validation error
PR-URL: #44170 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 90f3c5e commit a60ae67
Copy full SHA for a60ae67

File tree

Expand file treeCollapse file tree

3 files changed

+7
-681
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+7
-681
lines changed
Open diff view settings
Collapse file

‎lib/internal/crypto/aes.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/aes.js
+5-7Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ const {
6060
generateKey: _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
const generateKey = promisify(_generateKey);
@@ -228,8 +223,11 @@ function aesCipher(mode, key, data, algorithm) {
228223

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

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

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

Copy file name to clipboardExpand all lines: test/parallel/test-webcrypto-keygen.js
+2-2Lines changed: 2 additions & 2 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.