Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

added additional properties to getPeerCertificate #1286

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ using namespace v8;
static Persistent<String> errno_symbol;
static Persistent<String> syscall_symbol;
static Persistent<String> subject_symbol;
static Persistent<String> subjectaltname_symbol;
static Persistent<String> modulus_symbol;
static Persistent<String> exponent_symbol;
static Persistent<String> issuer_symbol;
static Persistent<String> valid_from_symbol;
static Persistent<String> valid_to_symbol;
Expand Down Expand Up @@ -1003,7 +1006,44 @@ Handle<Value> Connection::GetPeerCertificate(const Arguments& args) {
OPENSSL_free(issuer);
}
char buf[256];
BIO* bio = BIO_new(BIO_s_mem());
BIO* bio = NULL;
ASN1_OBJECT *oid;
oid = OBJ_txt2obj("2.5.29.17", 1); // OID 2.5.29.17 is Subject AltName
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int count = 0, j;
count = X509_get_ext_count(peer_cert);
for (j = 0; j < count; j++) {
X509_EXTENSION *ext = X509_get_ext(peer_cert, j);
if (OBJ_cmp(ext->object, oid) == 0) {
bio = BIO_new(BIO_s_mem());
if (X509V3_EXT_print(bio, ext, 0, 0) == 1) {
memset(buf, 0, sizeof(buf));
BIO_read(bio, buf, sizeof(buf) - 1);
info->Set(subjectaltname_symbol, String::New(buf));
}
BIO_vfree(bio);
break;
}
}

EVP_PKEY *pkey = NULL;
RSA *rsa = NULL;
if( NULL != (pkey = X509_get_pubkey(peer_cert))
&& NULL != (rsa = EVP_PKEY_get1_RSA(pkey)) ) {
bio = BIO_new(BIO_s_mem());
BN_print(bio, rsa->n);
memset(buf, 0, sizeof(buf));
BIO_read(bio, buf, sizeof(buf) - 1);
info->Set(modulus_symbol, String::New(buf) );
BIO_free(bio);

bio = BIO_new(BIO_s_mem());
BN_print(bio, rsa->e);
memset(buf, 0, sizeof(buf));
BIO_read(bio, buf, sizeof(buf) - 1);
info->Set(exponent_symbol, String::New(buf) );
BIO_free(bio);
}
bio = BIO_new(BIO_s_mem());
ASN1_TIME_print(bio, X509_get_notBefore(peer_cert));
memset(buf, 0, sizeof(buf));
BIO_read(bio, buf, sizeof(buf) - 1);
Expand Down Expand Up @@ -3659,6 +3699,9 @@ void InitCrypto(Handle<Object> target) {
issuer_symbol = NODE_PSYMBOL("issuer");
valid_from_symbol = NODE_PSYMBOL("valid_from");
valid_to_symbol = NODE_PSYMBOL("valid_to");
subjectaltname_symbol = NODE_PSYMBOL("subjectaltname");
modulus_symbol = NODE_PSYMBOL("modulus");
exponent_symbol = NODE_PSYMBOL("exponent");
fingerprint_symbol = NODE_PSYMBOL("fingerprint");
name_symbol = NODE_PSYMBOL("name");
version_symbol = NODE_PSYMBOL("version");
Expand Down
1 change: 1 addition & 0 deletions src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/hmac.h>

#ifdef OPENSSL_NPN_NEGOTIATED
Expand Down