Expose extra certificate information: full breakdown of issuer and subject principals, as well as full structure of intermediate issuer certificates.

This commit is contained in:
Greg Nolle 2016-11-09 17:19:35 +00:00 committed by Kevin Sawicki
parent 446399c3c1
commit 5d028f9163
4 changed files with 47 additions and 4 deletions

View file

@ -45,12 +45,11 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
std::string encoded_data;
net::X509Certificate::GetPEMEncoded(
val->os_cert_handle(), &encoded_data);
std::vector<std::string> encoded_chain;
val->GetPEMEncodedChain(&encoded_chain);
dict.Set("data", encoded_data);
dict.Set("chain", encoded_chain);
dict.Set("issuer", mate::ConvertToV8(isolate, val->issuer()));
dict.Set("issuerName", val->issuer().GetDisplayName());
dict.Set("subject", mate::ConvertToV8(isolate, val->subject()));
dict.Set("subjectName", val->subject().GetDisplayName());
dict.Set("serialNumber", base::HexEncode(val->serial_number().data(),
val->serial_number().size()));
@ -60,6 +59,33 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
net::HashValue(
val->CalculateFingerprint256(val->os_cert_handle())).ToString());
if (!val->GetIntermediateCertificates().empty()) {
net::X509Certificate::OSCertHandles issuer_intermediates(
val->GetIntermediateCertificates().begin() + 1,
val->GetIntermediateCertificates().end());
const scoped_refptr<net::X509Certificate>& issuer_cert =
net::X509Certificate::CreateFromHandle(
val->GetIntermediateCertificates().front(),
issuer_intermediates);
dict.Set("issuerCert", mate::ConvertToV8(isolate, issuer_cert));
}
return dict.GetHandle();
}
// static
v8::Local<v8::Value> Converter<net::CertPrincipal>::ToV8(
v8::Isolate* isolate, const net::CertPrincipal& val) {
mate::Dictionary dict(isolate, v8::Object::New(isolate));
dict.Set("commonName", val.common_name);
dict.Set("organizations", mate::ConvertToV8(isolate, val.organization_names));
dict.Set("organizationUnits",
mate::ConvertToV8(isolate, val.organization_unit_names));
dict.Set("locality", val.locality_name);
dict.Set("state", val.state_or_province_name);
dict.Set("country", val.country_name);
return dict.GetHandle();
}

View file

@ -18,6 +18,7 @@ class AuthChallengeInfo;
class URLRequest;
class X509Certificate;
class HttpResponseHeaders;
struct CertPrincipal;
}
namespace mate {
@ -34,6 +35,12 @@ struct Converter<scoped_refptr<net::X509Certificate>> {
const scoped_refptr<net::X509Certificate>& val);
};
template<>
struct Converter<net::CertPrincipal> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const net::CertPrincipal& val);
};
template <>
struct Converter<net::HttpResponseHeaders*> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,

View file

@ -0,0 +1,8 @@
# CertificatePrincipal Object
* `commonName` String - Common Name
* `organizations` String[] - Organization names
* `organizationUnits` String[] - Organization Unit names
* `locality` String - Locality
* `state` String - State or province
* `country` String - Country or region

View file

@ -1,8 +1,10 @@
# Certificate Object
* `data` String - PEM encoded data
* `chain` String[] - PEM encoded chain
* `issuer` [CertificatePrincipal](structures/certificate-principal.md) - Issuer principal
* `issuerName` String - Issuer's Common Name
* `issuerCert` Certificate - Issuer certificate (if not self-signed)
* `subject` [CertificatePrincipal](structures/certificate-principal.md) - Subject principal
* `subjectName` String - Subject's Common Name
* `serialNumber` String - Hex value represented string
* `validStart` Number - Start date of the certificate being valid in seconds