mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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>
This commit is contained in:
1 parent
7f02e22998
commit
9f1de2c005
2 files changed
+16
-8
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user