From e97f00f6f624d11ce7f37796bd65e52c473093b6 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 19 Sep 2024 19:12:23 +0530 Subject: fix(ext/node): support x509 certificates in `createPublicKey` (#25731) Fixes https://github.com/denoland/deno/issues/25681 --- ext/node/ops/crypto/keys.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ext/node') diff --git a/ext/node/ops/crypto/keys.rs b/ext/node/ops/crypto/keys.rs index cc011dfad..867b34e04 100644 --- a/ext/node/ops/crypto/keys.rs +++ b/ext/node/ops/crypto/keys.rs @@ -752,7 +752,15 @@ impl KeyObjectHandle { | KeyObjectHandle::Secret(_) => unreachable!(), } } - // TODO: handle x509 certificates as public keys + "CERTIFICATE" => { + let (_, pem) = x509_parser::pem::parse_x509_pem(pem.as_bytes()) + .map_err(|_| type_error("invalid x509 certificate"))?; + + let cert = pem.parse_x509()?; + let public_key = cert.tbs_certificate.subject_pki; + + return KeyObjectHandle::new_x509_public_key(&public_key); + } _ => { return Err(type_error(format!("unsupported PEM label: {}", label))) } -- cgit v1.2.3