summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorAurélien Bertron <aurelienbertron@gmail.com>2022-10-04 08:10:34 +0200
committerGitHub <noreply@github.com>2022-10-03 23:10:34 -0700
commit8d20784f7adc1eee6cd58f1b797263fc19d07327 (patch)
tree650550fd91884f584d11570550a1b0b2005bf5f5 /cli/tests
parent7742ad77fa94c402d59a890c67a11da55886c68b (diff)
fix(ext/crypto): deriveBits for ECDH not taking length into account (#16128)
Fixes #16047
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/webcrypto_test.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts
index 6695b157a..c5f5dc6c2 100644
--- a/cli/tests/unit/webcrypto_test.ts
+++ b/cli/tests/unit/webcrypto_test.ts
@@ -541,6 +541,71 @@ Deno.test(async function testHkdfDeriveBitsWithLargeKeySize() {
);
});
+Deno.test(async function testEcdhDeriveBitsWithShorterLength() {
+ const keypair = await crypto.subtle.generateKey(
+ {
+ name: "ECDH",
+ namedCurve: "P-384",
+ },
+ true,
+ ["deriveBits", "deriveKey"],
+ );
+ const result = await crypto.subtle.deriveBits(
+ {
+ name: "ECDH",
+ public: keypair.publicKey,
+ },
+ keypair.privateKey,
+ 256,
+ );
+ assertEquals(result.byteLength * 8, 256);
+});
+
+Deno.test(async function testEcdhDeriveBitsWithLongerLength() {
+ const keypair = await crypto.subtle.generateKey(
+ {
+ name: "ECDH",
+ namedCurve: "P-384",
+ },
+ true,
+ ["deriveBits", "deriveKey"],
+ );
+ await assertRejects(
+ () =>
+ crypto.subtle.deriveBits(
+ {
+ name: "ECDH",
+ public: keypair.publicKey,
+ },
+ keypair.privateKey,
+ 512,
+ ),
+ DOMException,
+ "Invalid length",
+ );
+});
+
+Deno.test(async function testEcdhDeriveBitsWithNullLength() {
+ const keypair = await crypto.subtle.generateKey(
+ {
+ name: "ECDH",
+ namedCurve: "P-384",
+ },
+ true,
+ ["deriveBits", "deriveKey"],
+ );
+ const result = await crypto.subtle.deriveBits(
+ {
+ name: "ECDH",
+ public: keypair.publicKey,
+ },
+ keypair.privateKey,
+ // @ts-ignore: necessary until .d.ts file allows passing null (see https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1416)
+ null,
+ );
+ assertEquals(result.byteLength * 8, 384);
+});
+
Deno.test(async function testDeriveKey() {
// Test deriveKey
const rawKey = await crypto.getRandomValues(new Uint8Array(16));