summaryrefslogtreecommitdiff
path: root/cli/tests/unit/webcrypto_test.ts
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-01-30 18:42:29 +0530
committerGitHub <noreply@github.com>2022-01-30 18:42:29 +0530
commitefa02ffa2a1b5ff76c9b6ba440e69b68b01f8d7f (patch)
tree537f9206cb163a20ead5d8f938f77cdf678c680f /cli/tests/unit/webcrypto_test.ts
parenta2e4fa471ba3366f7e05bbad59b247e7825b832c (diff)
fix(ext/crypto): enforce 128bits tagLength for AES-GCM decryption (#13536)
Diffstat (limited to 'cli/tests/unit/webcrypto_test.ts')
-rw-r--r--cli/tests/unit/webcrypto_test.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts
index 84cf7d4ca..ba6aaa327 100644
--- a/cli/tests/unit/webcrypto_test.ts
+++ b/cli/tests/unit/webcrypto_test.ts
@@ -1639,3 +1639,32 @@ Deno.test(async function testAESWrapKey() {
assertEquals(new Uint8Array(hmacKeyBytes), new Uint8Array(unwrappedKeyBytes));
});
+
+// https://github.com/denoland/deno/issues/13534
+Deno.test(async function testAesGcmTagLength() {
+ const key = await crypto.subtle.importKey(
+ "raw",
+ new Uint8Array(32),
+ "AES-GCM",
+ false,
+ ["encrypt", "decrypt"],
+ );
+
+ const iv = crypto.getRandomValues(new Uint8Array(12));
+
+ // encrypt won't fail, it will simply truncate the tag
+ // as expected.
+ const encrypted = await crypto.subtle.encrypt(
+ { name: "AES-GCM", iv, tagLength: 96, additionalData: new Uint8Array() },
+ key,
+ new Uint8Array(32),
+ );
+
+ await assertRejects(async () => {
+ await crypto.subtle.decrypt(
+ { name: "AES-GCM", iv, tagLength: 96, additionalData: new Uint8Array() },
+ key,
+ encrypted,
+ );
+ });
+});