diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-12-03 09:58:13 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-03 09:58:13 +0530 |
commit | 32438d25c337f9160c1c90d48680963654385e22 (patch) | |
tree | 14efb86398438a9d05d00be96791b3a6e98eca66 /cli/tests/unit_node/crypto/crypto_sign_test.ts | |
parent | 39c7d8dafe00fd619afac7de0151790e7d53cd43 (diff) |
fix(ext/node): sign with PEM private keys (#21287)
Add support for signing with a RSA PEM private key: `pkcs8` and `pkcs1`.
Fixes https://github.com/denoland/deno/issues/18972
Ref #21124
Verified fix with `npm:sshpk`. Unverfied but fixes
`npm:google-auth-library`, `npm:web-push` & `oracle/oci-typescript-sdk`
---------
Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'cli/tests/unit_node/crypto/crypto_sign_test.ts')
-rw-r--r-- | cli/tests/unit_node/crypto/crypto_sign_test.ts | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/cli/tests/unit_node/crypto/crypto_sign_test.ts b/cli/tests/unit_node/crypto/crypto_sign_test.ts index 58107b563..b04cae407 100644 --- a/cli/tests/unit_node/crypto/crypto_sign_test.ts +++ b/cli/tests/unit_node/crypto/crypto_sign_test.ts @@ -1,6 +1,9 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../../../../test_util/std/assert/mod.ts"; +import { + assert, + assertEquals, +} from "../../../../test_util/std/testing/asserts.ts"; import { createSign, createVerify, sign, verify } from "node:crypto"; import { Buffer } from "node:buffer"; @@ -9,6 +12,11 @@ const rsaPrivatePem = Buffer.from( new URL("../testdata/rsa_private.pem", import.meta.url), ), ); +const rsaPrivatePkcs1Pem = Buffer.from( + await Deno.readFile( + new URL("../testdata/rsa_private_pkcs1.pem", import.meta.url), + ), +); const rsaPublicPem = Buffer.from( await Deno.readFile( new URL("../testdata/rsa_public.pem", import.meta.url), @@ -86,3 +94,39 @@ Deno.test({ } }, }); + +Deno.test({ + name: "crypto.createPrivateKey|sign - RSA PEM", + fn() { + for (const testCase of table) { + for (const algorithm of testCase.algorithms) { + assertEquals( + createSign(algorithm).update(data).sign(rsaPrivatePem, "hex"), + testCase.signature, + ); + assertEquals( + sign(algorithm, data, rsaPrivatePem), + Buffer.from(testCase.signature, "hex"), + ); + } + } + }, +}); + +Deno.test({ + name: "crypto.createPrivateKey|sign - RSA PKCS1 PEM", + fn() { + for (const testCase of table) { + for (const algorithm of testCase.algorithms) { + assertEquals( + createSign(algorithm).update(data).sign(rsaPrivatePkcs1Pem, "hex"), + testCase.signature, + ); + assertEquals( + sign(algorithm, data, rsaPrivatePkcs1Pem), + Buffer.from(testCase.signature, "hex"), + ); + } + } + }, +}); |