From 5a6beb774128a890830d3dc7b742929dc539418e Mon Sep 17 00:00:00 2001 From: Hannes Magnusson Date: Tue, 6 Feb 2018 21:34:08 -0800 Subject: [PATCH] crypto: add cert.pubkey containing the raw pubkey of certificate PR-URL: https://github.com/nodejs/node/pull/17690 Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis Reviewed-By: Ruben Bridgewater --- src/env.h | 1 + src/node_crypto.cc | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/env.h b/src/env.h index a4454d55c1c95b..4df4cb13b8209e 100644 --- a/src/env.h +++ b/src/env.h @@ -242,6 +242,7 @@ struct PackageConfig { V(priority_string, "priority") \ V(produce_cached_data_string, "produceCachedData") \ V(promise_string, "promise") \ + V(pubkey_string, "pubkey") \ V(raw_string, "raw") \ V(read_host_object_string, "_readHostObject") \ V(readable_string, "readable") \ diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 202de9cf675be1..a21e37408de68a 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1898,6 +1898,14 @@ static Local X509ToObject(Environment* env, X509* cert) { String::kNormalString, mem->length)).FromJust(); USE(BIO_reset(bio)); + + int size = i2d_RSA_PUBKEY(rsa, nullptr); + CHECK_GE(size, 0); + Local pubbuff = Buffer::New(env, size).ToLocalChecked(); + unsigned char* pubserialized = + reinterpret_cast(Buffer::Data(pubbuff)); + i2d_RSA_PUBKEY(rsa, &pubserialized); + info->Set(env->pubkey_string(), pubbuff); } if (pkey != nullptr) {