From 0e50bb1d4abd80da3fc1be17978760ddfa8560fa Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 28 Aug 2024 20:56:11 +0530 Subject: fix(ext/node): import RSA JWK keys (#25267) Fixes https://github.com/denoland/deno/issues/24129 --- ext/node/polyfills/internal/crypto/keys.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'ext/node/polyfills/internal/crypto/keys.ts') diff --git a/ext/node/polyfills/internal/crypto/keys.ts b/ext/node/polyfills/internal/crypto/keys.ts index 49a618b65..c91c23cc3 100644 --- a/ext/node/polyfills/internal/crypto/keys.ts +++ b/ext/node/polyfills/internal/crypto/keys.ts @@ -16,6 +16,7 @@ import { op_node_create_ed_raw, op_node_create_private_key, op_node_create_public_key, + op_node_create_rsa_jwk, op_node_create_secret_key, op_node_derive_public_key_from_private_key, op_node_export_private_key_der, @@ -324,7 +325,32 @@ function getKeyObjectHandleFromJwk(key, ctx) { return op_node_create_ec_jwk(key, isPublic); } - throw new TypeError("rsa jwk imports not implemented"); + // RSA + validateString(key.n, "key.n"); + validateString(key.e, "key.e"); + + const jwk = { + kty: key.kty, + n: key.n, + e: key.e, + }; + + if (!isPublic) { + validateString(key.d, "key.d"); + validateString(key.p, "key.p"); + validateString(key.q, "key.q"); + validateString(key.dp, "key.dp"); + validateString(key.dq, "key.dq"); + validateString(key.qi, "key.qi"); + jwk.d = key.d; + jwk.p = key.p; + jwk.q = key.q; + jwk.dp = key.dp; + jwk.dq = key.dq; + jwk.qi = key.qi; + } + + return op_node_create_rsa_jwk(jwk, isPublic); } export function prepareAsymmetricKey( -- cgit v1.2.3