Skip to content

Commit

Permalink
incorrect fix for the extenion handling
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew B. White <[email protected]>
  • Loading branch information
mbwhite committed Dec 19, 2018
1 parent e32709f commit 5f16099
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/x509.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <x509.h>
#include <cstring>
#include <sstream>
#include <x509.h>


using namespace v8;

Expand Down Expand Up @@ -386,11 +387,7 @@ Local<Value> try_parse(const std::string& dataString) {
BIO *ext_bio = BIO_new(BIO_s_mem());
// IFNULL_FAIL(ext_bio, "unable to allocate memory for extension value BIO");
if (!X509V3_EXT_print(ext_bio, ext, 0, 0)) {
unsigned char *buf = NULL;
int len = i2d_ASN1_OCTET_STRING(X509_EXTENSION_get_data(ext), &buf);
if (len >= 0) {
BIO_write(ext_bio, static_cast<const void *>(buf), len);
}
M_ASN1_OCTET_STRING_print(ext_bio, ext->value);
}

BUF_MEM *bptr;
Expand Down Expand Up @@ -468,7 +465,7 @@ Local<Object> parse_name(X509_NAME *subject) {
Local<Object> cert = Nan::New<Object>();
int i, length;
ASN1_OBJECT *entry;
const unsigned char *value;
unsigned char *value;
char buf[255];
length = X509_NAME_entry_count(subject);
for (i = 0; i < length; i++) {
Expand Down
20 changes: 19 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,22 @@ x509.verify(
function(err, result) {
assert.throws(assert.ifError.bind(null, err), /Failed to load cert/)
}
);
);

const certWithAttrs = `-----BEGIN CERTIFICATE-----
MIIB6TCCAY+gAwIBAgIUHkmY6fRP0ANTvzaBwKCkMZZPUnUwCgYIKoZIzj0EAwIw
GzEZMBcGA1UEAxMQZmFicmljLWNhLXNlcnZlcjAeFw0xNzA5MDgwMzQyMDBaFw0x
ODA5MDgwMzQyMDBaMB4xHDAaBgNVBAMTE015VGVzdFVzZXJXaXRoQXR0cnMwWTAT
BgcqhkjOPQIBBggqhkjOPQMBBwNCAATmB1r3CdWvOOP3opB3DjJnW3CnN8q1ydiR
dzmuA6A2rXKzPIltHvYbbSqISZJubsy8gVL6GYgYXNdu69RzzFF5o4GtMIGqMA4G
A1UdDwEB/wQEAwICBDAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBTYKLTAvJJK08OM
VGwIhjMQpo2DrjAfBgNVHSMEGDAWgBTEs/52DeLePPx1+65VhgTwu3/2ATAiBgNV
HREEGzAZghdBbmlscy1NYWNCb29rLVByby5sb2NhbDAmBggqAwQFBgcIAQQaeyJh
dHRycyI6eyJhdHRyMSI6InZhbDEifX0wCgYIKoZIzj0EAwIDSAAwRQIhAPuEqWUp
svTTvBqLR5JeQSctJuz3zaqGRqSs2iW+QB3FAiAIP0mGWKcgSGRMMBvaqaLytBYo
9v3hRt1r8j8vN0pMcg==
-----END CERTIFICATE-----`;


let cert = x509.parseCert((certWithAttrs));
console.log(cert)

0 comments on commit 5f16099

Please sign in to comment.