Skip to content

Commit

Permalink
fixup! crypto: check ed/x webcrypto key import algorithm names
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Feb 24, 2021
1 parent 5b257fa commit 8596512
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions lib/internal/crypto/ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-webcrypto-x25519-x448.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down

0 comments on commit 8596512

Please sign in to comment.