diff --git a/ext/node/ops/crypto/mod.rs b/ext/node/ops/crypto/mod.rs index cf44f48f7e..3b33be3fc2 100644 --- a/ext/node/ops/crypto/mod.rs +++ b/ext/node/ops/crypto/mod.rs @@ -1607,6 +1607,7 @@ pub fn op_node_create_public_key( named_curve: named_curve.to_string(), }) } + DH_KEY_AGREEMENT_OID => Ok(AsymmetricKeyDetails::Dh), _ => Err(type_error("Unsupported algorithm")), } } diff --git a/tests/unit_node/crypto/crypto_key_test.ts b/tests/unit_node/crypto/crypto_key_test.ts index 5fa36bd115..de941da88d 100644 --- a/tests/unit_node/crypto/crypto_key_test.ts +++ b/tests/unit_node/crypto/crypto_key_test.ts @@ -248,6 +248,24 @@ Deno.test("createPrivateKey dh", function () { assertEquals(key.asymmetricKeyType, "dh"); }); +Deno.test("createPublicKey dh", function () { + // 1.2.840.113549.1.3.1 + const pem = "-----BEGIN PUBLIC KEY-----\n" + + "MIIBnzCB1QYJKoZIhvcNAQMBMIHHAoHBAP//////////yQ/aoiFowjTExmKLgNwc\n" + + "0SkCTgiKZ8x0Agu+pjsTmyJRSgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHC\n" + + "ReSFtXZiXn7G9ExC6aY37WsL/1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR7ORb\n" + + "PcIAfLihY78FmNpINhxV05ppFj+o/STPX4NlXSPco62WHGLzViCFUrue1SkHcJaW\n" + + "bWcMNU5KvJgE8XRsCMojcyf//////////wIBAgOBxAACgcBR7+iL5qx7aOb9K+aZ\n" + + "y2oLt7ST33sDKT+nxpag6cWDDWzPBKFDCJ8fr0v7yW453px8N4qi4R7SYYxFBaYN\n" + + "Y3JvgDg1ct2JC9sxSuUOLqSFn3hpmAjW7cS0kExIVGfdLlYtIqbhhuo45cTEbVIM\n" + + "rDEz8mjIlnvbWpKB9+uYmbjfVoc3leFvUBqfG2In2m23Md1swsPxr3n7g68H66JX\n" + + "iBJKZLQMqNdbY14G9rdKmhhTJrQjC+i7Q/wI8JPhOFzHIGA=\n" + + "-----END PUBLIC KEY-----"; + const key = createPublicKey(pem); + assertEquals(key.type, "public"); + assertEquals(key.asymmetricKeyType, "dh"); +}); + // openssl ecparam -name secp256r1 -genkey -noout -out a.pem // openssl pkcs8 -topk8 -nocrypt -in a.pem -out b.pem const ecPrivateKey = Deno.readTextFileSync(