Skip to content

Commit 8596512

Browse files
committed
fixup! crypto: check ed/x webcrypto key import algorithm names
1 parent 5b257fa commit 8596512

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/internal/crypto/ec.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,20 @@ async function ecImportKey(
308308
case 'OKP': {
309309
checkNamedCurve = false;
310310
const isPublic = keyData.d === undefined;
311-
const type = namedCurve === 'NODE-ED25519' || 'NODE-ED448' ?
312-
`NODE-${keyData.crv.toUpperCase()}` : 'ECDH';
311+
312+
let type;
313+
switch (namedCurve) {
314+
case 'NODE-ED25519':
315+
// Fall through
316+
case 'NODE-ED448':
317+
type = `NODE-${keyData.crv.toUpperCase()}`;
318+
break;
319+
case 'NODE-X25519':
320+
// Fall through
321+
case 'NODE-X448':
322+
type = 'ECDH';
323+
break;
324+
}
313325

314326
if (algorithm.name !== type)
315327
throw lazyDOMException('Invalid algorithm name.', 'DataError');

test/parallel/test-webcrypto-x25519-x448.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ assert.rejects(
264264
namedCurve: 'NODE-X25519'
265265
},
266266
true,
267-
['deriveBits']).then(common.mustCall());
267+
['deriveBits']).then(common.mustCall(), common.mustNotCall());
268268

269269
// Public JWK import
270270
subtle.importKey(
@@ -279,7 +279,7 @@ assert.rejects(
279279
namedCurve: 'NODE-X25519'
280280
},
281281
true,
282-
[]).then(common.mustCall());
282+
[]).then(common.mustCall(), common.mustNotCall());
283283

284284
for (const asymmetricKeyType of ['x25519', 'x448']) {
285285
const { publicKey, privateKey } = generateKeyPairSync(asymmetricKeyType);

0 commit comments

Comments
 (0)