Skip to content

Commit 36bb8da

Browse files
panvatargos
authored andcommitted
crypto: forbid NODE-ED25519 and NODE-ED448 "raw" key export
closes #38655 PR-URL: #38668 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent a028805 commit 36bb8da

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/internal/crypto/webcrypto.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ async function exportKeyRaw(key) {
288288
case 'NODE-ED25519':
289289
// Fall through
290290
case 'NODE-ED448':
291-
return lazyRequire('internal/crypto/ec')
292-
.ecExportKey(key, kWebCryptoKeyFormatRaw);
291+
if (key.type === 'public') {
292+
return lazyRequire('internal/crypto/ec')
293+
.ecExportKey(key, kWebCryptoKeyFormatRaw);
294+
}
295+
break;
293296
case 'ECDSA':
294297
// Fall through
295298
case 'ECDH':

test/parallel/test-webcrypto-ed25519-ed448.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,12 @@ async function test2(namedCurve) {
268268
true, ['verify']),
269269
]);
270270

271-
const [
272-
rawKey1,
273-
rawKey2,
274-
] = await Promise.all([
275-
subtle.exportKey('raw', privateKey),
276-
subtle.exportKey('raw', publicKey),
277-
]);
278-
assert.deepStrictEqual(Buffer.from(rawKey1), vector.privateKey);
279-
assert.deepStrictEqual(Buffer.from(rawKey2), vector.publicKey);
271+
const rawPublicKey = await subtle.exportKey('raw', publicKey);
272+
assert.deepStrictEqual(Buffer.from(rawPublicKey), vector.publicKey);
273+
274+
assert.rejects(subtle.exportKey('raw', privateKey), {
275+
message: new RegExp(`Unable to export a raw ${namedCurve} private key`)
276+
}).then(common.mustCall());
280277

281278
const sig = await subtle.sign(
282279
{ name: namedCurve },

0 commit comments

Comments
 (0)