summaryrefslogtreecommitdiff
path: root/cli/tests/unit/webcrypto_test.ts
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2021-07-07 20:03:58 +0530
committerGitHub <noreply@github.com>2021-07-07 16:33:58 +0200
commite3a4e9cf11438948ddd86a7ebdac344190acafa8 (patch)
tree7e049c5ef60d4cfd8713376279ab1d59b283ec0f /cli/tests/unit/webcrypto_test.ts
parentb091b8fefb5946c9ddaae026cbc6ad5159409c51 (diff)
fix(crypto): hash input for RSASSA-PKCS1-v1_5 before signing (#11314)
Diffstat (limited to 'cli/tests/unit/webcrypto_test.ts')
-rw-r--r--cli/tests/unit/webcrypto_test.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts
index 4361d3a10..b507a0c58 100644
--- a/cli/tests/unit/webcrypto_test.ts
+++ b/cli/tests/unit/webcrypto_test.ts
@@ -56,3 +56,36 @@ unitTest(async function testSignECDSA() {
assert(signature);
});
+
+// https://github.com/denoland/deno/issues/11313
+unitTest(async function testSignRSASSAKey() {
+ const subtle = window.crypto.subtle;
+ assert(subtle);
+
+ const keyPair = await subtle.generateKey(
+ {
+ name: "RSASSA-PKCS1-v1_5",
+ modulusLength: 2048,
+ publicExponent: new Uint8Array([1, 0, 1]),
+ hash: "SHA-256",
+ },
+ true,
+ ["sign", "verify"],
+ );
+
+ assert(keyPair.privateKey);
+ assert(keyPair.publicKey);
+ assertEquals(keyPair.privateKey.extractable, true);
+ assert(keyPair.privateKey.usages.includes("sign"));
+
+ const encoder = new TextEncoder();
+ const encoded = encoder.encode("Hello, World!");
+
+ const signature = await window.crypto.subtle.sign(
+ { name: "RSASSA-PKCS1-v1_5" },
+ keyPair.privateKey,
+ encoded,
+ );
+
+ assert(signature);
+});