From 5f1609903951bf9785f5010b560a62a9cd3fc088 Mon Sep 17 00:00:00 2001 From: "Matthew B. White" Date: Wed, 19 Dec 2018 17:32:35 +0000 Subject: [PATCH] incorrect fix for the extenion handling Signed-off-by: Matthew B. White --- src/x509.cc | 11 ++++------- test/test.js | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/x509.cc b/src/x509.cc index 00e02ae..86bcb6c 100644 --- a/src/x509.cc +++ b/src/x509.cc @@ -1,6 +1,7 @@ +#include #include #include -#include + using namespace v8; @@ -386,11 +387,7 @@ Local 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(buf), len); - } + M_ASN1_OCTET_STRING_print(ext_bio, ext->value); } BUF_MEM *bptr; @@ -468,7 +465,7 @@ Local parse_name(X509_NAME *subject) { Local cert = Nan::New(); 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++) { diff --git a/test/test.js b/test/test.js index c98818d..439fb38 100644 --- a/test/test.js +++ b/test/test.js @@ -53,4 +53,22 @@ x509.verify( function(err, result) { assert.throws(assert.ifError.bind(null, err), /Failed to load cert/) } -); \ No newline at end of file +); + +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) \ No newline at end of file