Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilip Skokan <panva.ip@gmail.com>2022-06-15 16:33:55 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2022-06-16 04:28:47 +0300
commit9f1de2c005d55205bb7c6b6bbbf8963fc951bc6f (patch)
treed588022c4f11b105d7ba4ac9789500c3499ee264
parent7f02e22998881b747d0d96e130eb64348cbe59f2 (diff)
crypto: fix webcrypto import of cfrg raw public keys
PR-URL: https://github.com/nodejs/node/pull/43404 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
-rw-r--r--lib/internal/crypto/cfrg.js9
-rw-r--r--test/parallel/test-webcrypto-export-import-cfrg.js15
2 files changed, 16 insertions, 8 deletions
diff --git a/lib/internal/crypto/cfrg.js b/lib/internal/crypto/cfrg.js
index 5dd4e44bdd0..6910aa84134 100644
--- a/lib/internal/crypto/cfrg.js
+++ b/lib/internal/crypto/cfrg.js
@@ -72,13 +72,6 @@ function verifyAcceptableCfrgKeyUse(name, type, usages) {
}
}
-function createECPublicKeyRaw(name, keyData) {
- const handle = new KeyObjectHandle();
- keyData = getArrayBufferOrView(keyData, 'keyData');
- if (handle.initECRaw(name.toLowerCase(), keyData))
- return new PublicKeyObject(handle);
-}
-
function createCFRGRawKey(name, keyData, isPublic) {
const handle = new KeyObjectHandle();
keyData = getArrayBufferOrView(keyData, 'keyData');
@@ -297,7 +290,7 @@ async function cfrgImportKey(
}
case 'raw': {
verifyAcceptableCfrgKeyUse(name, 'public', usagesSet);
- keyObject = createECPublicKeyRaw(name, keyData);
+ keyObject = createCFRGRawKey(name, keyData, true);
if (keyObject === undefined)
throw lazyDOMException('Unable to import CFRG key', 'OperationError');
break;
diff --git a/test/parallel/test-webcrypto-export-import-cfrg.js b/test/parallel/test-webcrypto-export-import-cfrg.js
index 531cb51c1b8..6d162ac61c2 100644
--- a/test/parallel/test-webcrypto-export-import-cfrg.js
+++ b/test/parallel/test-webcrypto-export-import-cfrg.js
@@ -281,6 +281,20 @@ async function testImportJwk({ name, publicUsages, privateUsages }, extractable)
}
}
+async function testImportRaw({ name, publicUsages }) {
+ const jwk = keyData[name].jwk;
+
+ const publicKey = await subtle.importKey(
+ 'raw',
+ Buffer.from(jwk.x, 'base64url'),
+ { name },
+ true, publicUsages);
+
+ assert.strictEqual(publicKey.type, 'public');
+ assert.deepStrictEqual(publicKey.usages, publicUsages);
+ assert.strictEqual(publicKey.algorithm.name, name);
+}
+
(async function() {
const tests = [];
testVectors.forEach((vector) => {
@@ -289,6 +303,7 @@ async function testImportJwk({ name, publicUsages, privateUsages }, extractable)
tests.push(testImportPkcs8(vector, extractable));
tests.push(testImportJwk(vector, extractable));
});
+ tests.push(testImportRaw(vector));
});
await Promise.all(tests);