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 02bcf13

Browse filesBrowse files
panvadanielleadams
authored andcommitted
crypto: fix webcrypto EC key namedCurve validation errors
PR-URL: #44172 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent a60ae67 commit 02bcf13
Copy full SHA for 02bcf13

File tree

Expand file treeCollapse file tree

3 files changed

+15
-52
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+15
-52
lines changed
Open diff view settings
Collapse file

‎lib/internal/crypto/ec.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/ec.js
+14-15Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
ArrayPrototypeIncludes,
45
ObjectKeys,
56
SafeSet,
67
} = primordials;
@@ -16,11 +17,6 @@ const {
1617
kSigEncP1363,
1718
} = internalBinding('crypto');
1819

19-
const {
20-
validateOneOf,
21-
validateString,
22-
} = require('internal/validators');
23-
2420
const {
2521
codes: {
2622
ERR_MISSING_OPTION,
@@ -90,11 +86,12 @@ function createECPublicKeyRaw(namedCurve, keyData) {
9086

9187
async function ecGenerateKey(algorithm, extractable, keyUsages) {
9288
const { name, namedCurve } = algorithm;
93-
validateString(namedCurve, 'algorithm.namedCurve');
94-
validateOneOf(
95-
namedCurve,
96-
'algorithm.namedCurve',
97-
ObjectKeys(kNamedCurveAliases));
89+
90+
if (!ArrayPrototypeIncludes(ObjectKeys(kNamedCurveAliases), namedCurve)) {
91+
throw lazyDOMException(
92+
'Unrecognized namedCurve',
93+
'NotSupportedError');
94+
}
9895

9996
const usageSet = new SafeSet(keyUsages);
10097
switch (name) {
@@ -168,11 +165,13 @@ async function ecImportKey(
168165
keyUsages) {
169166

170167
const { name, namedCurve } = algorithm;
171-
validateString(namedCurve, 'algorithm.namedCurve');
172-
validateOneOf(
173-
namedCurve,
174-
'algorithm.namedCurve',
175-
ObjectKeys(kNamedCurveAliases));
168+
169+
if (!ArrayPrototypeIncludes(ObjectKeys(kNamedCurveAliases), namedCurve)) {
170+
throw lazyDOMException(
171+
'Unrecognized namedCurve',
172+
'NotSupportedError');
173+
}
174+
176175
let keyObject;
177176
const usagesSet = new SafeSet(keyUsages);
178177
switch (format) {
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-webcrypto-keygen.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ const vectors = {
452452
[1, true, {}, [], undefined, null].forEach(async (namedCurve) => {
453453
await assert.rejects(
454454
subtle.generateKey({ name, namedCurve }, true, privateUsages), {
455-
code: 'ERR_INVALID_ARG_TYPE'
455+
name: 'NotSupportedError'
456456
});
457457
});
458458
}
Collapse file

‎test/wpt/status/WebCryptoAPI.json‎

Copy file name to clipboardExpand all lines: test/wpt/status/WebCryptoAPI.json
-36Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,48 +2690,12 @@
26902690
"generateKey/failures_ECDH.https.any.js": {
26912691
"fail": {
26922692
"expected": [
2693-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, false, [deriveKey])",
2694-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, true, [deriveKey])",
2695-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, false, [deriveBits, deriveKey])",
2696-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, true, [deriveBits, deriveKey])",
2697-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, false, [deriveBits])",
2698-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, true, [deriveBits])",
2699-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, false, [])",
2700-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, true, [])",
2701-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, false, [deriveKey, deriveBits, deriveKey, deriveBits, deriveKey, deriveBits])",
2702-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: P-512}, true, [deriveKey, deriveBits, deriveKey, deriveBits, deriveKey, deriveBits])",
2703-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, false, [deriveKey])",
2704-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, true, [deriveKey])",
2705-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, false, [deriveBits, deriveKey])",
2706-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, true, [deriveBits, deriveKey])",
2707-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, false, [deriveBits])",
2708-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, true, [deriveBits])",
2709-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, false, [])",
2710-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, true, [])",
2711-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, false, [deriveKey, deriveBits, deriveKey, deriveBits, deriveKey, deriveBits])",
2712-
"Bad algorithm property: generateKey({name: ECDH, namedCurve: Curve25519}, true, [deriveKey, deriveBits, deriveKey, deriveBits, deriveKey, deriveBits])"
27132693
]
27142694
}
27152695
},
27162696
"generateKey/failures_ECDSA.https.any.js": {
27172697
"fail": {
27182698
"expected": [
2719-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: P-512}, false, [sign])",
2720-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: P-512}, true, [sign])",
2721-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: P-512}, false, [verify, sign])",
2722-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: P-512}, true, [verify, sign])",
2723-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: P-512}, false, [])",
2724-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: P-512}, true, [])",
2725-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: P-512}, false, [sign, verify, sign, sign, verify])",
2726-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: P-512}, true, [sign, verify, sign, sign, verify])",
2727-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: Curve25519}, false, [sign])",
2728-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: Curve25519}, true, [sign])",
2729-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: Curve25519}, false, [verify, sign])",
2730-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: Curve25519}, true, [verify, sign])",
2731-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: Curve25519}, false, [])",
2732-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: Curve25519}, true, [])",
2733-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: Curve25519}, false, [sign, verify, sign, sign, verify])",
2734-
"Bad algorithm property: generateKey({name: ECDSA, namedCurve: Curve25519}, true, [sign, verify, sign, sign, verify])"
27352699
]
27362700
}
27372701
},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.