crypto: ensure exported webcrypto EC keys use uncompressed point format · nodejs/node@777c551 · GitHub
Skip to content

Commit 777c551

Browse files
bnoordhuisRafaelGSS
authored andcommitted
crypto: ensure exported webcrypto EC keys use uncompressed point format
The WebCrypto spec apparently mandates that EC keys must be exported in uncompressed point format. This commit makes it so. Fixes: #45859 PR-URL: #46021 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 25d0a94 commit 777c551

3 files changed

Lines changed: 56 additions & 15 deletions

File tree

src/crypto/crypto_ec.cc

Lines changed: 43 additions & 2 deletions

test/parallel/test-webcrypto-export-import-ec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,19 @@ async function testImportRaw({ name, publicUsages }, namedCurve) {
327327
await Promise.all(tests);
328328
})().then(common.mustCall());
329329

330+
331+
// https://github.com/nodejs/node/issues/45859
332+
(async function() {
333+
const compressed = Buffer.from([48, 57, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 34, 0, 2, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209]); // eslint-disable-line max-len
334+
const uncompressed = Buffer.from([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209, 206, 3, 117, 82, 212, 129, 69, 12, 227, 155, 77, 16, 149, 112, 27, 23, 91, 250, 179, 75, 142, 108, 9, 158, 24, 241, 193, 152, 53, 131, 97, 232]); // eslint-disable-line max-len
335+
for (const name of ['ECDH', 'ECDSA']) {
336+
const options = { name, namedCurve: 'P-256' };
337+
const key = await subtle.importKey('spki', compressed, options, true, []);
338+
const spki = await subtle.exportKey('spki', key);
339+
assert.deepStrictEqual(uncompressed, Buffer.from(spki));
340+
}
341+
})().then(common.mustCall());
342+
330343
{
331344
const rsaPublic = crypto.createPublicKey(
332345
fixtures.readKey('rsa_public_2048.pem'));

test/wpt/status/WebCryptoAPI.json

Lines changed: 0 additions & 13 deletions

0 commit comments

Comments
 (0)