From 859651283804515b199a9731e00010a2762e5b9c Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Wed, 24 Feb 2021 09:29:00 +0100 Subject: [PATCH] fixup! crypto: check ed/x webcrypto key import algorithm names --- lib/internal/crypto/ec.js | 16 ++++++++++++++-- test/parallel/test-webcrypto-x25519-x448.js | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/internal/crypto/ec.js b/lib/internal/crypto/ec.js index f3438bd422f493..50641d00a6be04 100644 --- a/lib/internal/crypto/ec.js +++ b/lib/internal/crypto/ec.js @@ -308,8 +308,20 @@ async function ecImportKey( case 'OKP': { checkNamedCurve = false; const isPublic = keyData.d === undefined; - const type = namedCurve === 'NODE-ED25519' || 'NODE-ED448' ? - `NODE-${keyData.crv.toUpperCase()}` : 'ECDH'; + + let type; + switch (namedCurve) { + case 'NODE-ED25519': + // Fall through + case 'NODE-ED448': + type = `NODE-${keyData.crv.toUpperCase()}`; + break; + case 'NODE-X25519': + // Fall through + case 'NODE-X448': + type = 'ECDH'; + break; + } if (algorithm.name !== type) throw lazyDOMException('Invalid algorithm name.', 'DataError'); diff --git a/test/parallel/test-webcrypto-x25519-x448.js b/test/parallel/test-webcrypto-x25519-x448.js index df4798112dc77b..84f8b88f254261 100644 --- a/test/parallel/test-webcrypto-x25519-x448.js +++ b/test/parallel/test-webcrypto-x25519-x448.js @@ -264,7 +264,7 @@ assert.rejects( namedCurve: 'NODE-X25519' }, true, - ['deriveBits']).then(common.mustCall()); + ['deriveBits']).then(common.mustCall(), common.mustNotCall()); // Public JWK import subtle.importKey( @@ -279,7 +279,7 @@ assert.rejects( namedCurve: 'NODE-X25519' }, true, - []).then(common.mustCall()); + []).then(common.mustCall(), common.mustNotCall()); for (const asymmetricKeyType of ['x25519', 'x448']) { const { publicKey, privateKey } = generateKeyPairSync(asymmetricKeyType);