Browse Source

crypto: use X509_get_ext_by_NID(NID_subject_alt_name)

Ben Noordhuis 14 years ago
committed by koichik
parent
commit
5ded5e274f
  1. 34
      src/node_crypto.cc

34
src/node_crypto.cc

@ -1092,23 +1092,27 @@ Handle<Value> Connection::GetPeerCertificate(const Arguments& args) {
char buf[256]; char buf[256];
bio = NULL; bio = NULL;
ASN1_OBJECT *oid;
oid = OBJ_txt2obj("2.5.29.17", 1); // OID 2.5.29.17 is Subject AltName int index = X509_get_ext_by_NID(peer_cert, NID_subject_alt_name, -1);
int count = 0, j; if (index >= 0) {
count = X509_get_ext_count(peer_cert); X509_EXTENSION* ext;
for (j = 0; j < count; j++) { BUF_MEM* mem;
X509_EXTENSION *ext = X509_get_ext(peer_cert, j); int rv;
if (OBJ_cmp(ext->object, oid) == 0) {
bio = BIO_new(BIO_s_mem()); bio = BIO_new(BIO_s_mem());
if (X509V3_EXT_print(bio, ext, 0, 0) == 1) {
memset(buf, 0, sizeof(buf)); ext = X509_get_ext(peer_cert, index);
BIO_read(bio, buf, sizeof(buf) - 1); assert(ext != NULL);
info->Set(subjectaltname_symbol, String::New(buf));
} rv = X509V3_EXT_print(bio, ext, 0, 0);
BIO_vfree(bio); assert(rv == 1);
break;
} BIO_get_mem_ptr(bio, &mem);
info->Set(subjectaltname_symbol, String::New(mem->data, mem->length));
BIO_free(bio);
} }
(void) BIO_reset(bio);
EVP_PKEY *pkey = NULL; EVP_PKEY *pkey = NULL;
RSA *rsa = NULL; RSA *rsa = NULL;

Loading…
Cancel
Save