Get rid of intermediates and rehydrate from issuerCert

This commit is contained in:
joshaber 2017-04-03 16:27:53 -04:00
parent 74c0cbddae
commit 370cf815d9

View file

@ -59,8 +59,7 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
net::HashValue( net::HashValue(
val->CalculateFingerprint256(val->os_cert_handle())).ToString()); val->CalculateFingerprint256(val->os_cert_handle())).ToString());
auto intermediates = val->GetIntermediateCertificates(); if (!val->GetIntermediateCertificates().empty()) {
if (!intermediates.empty()) {
net::X509Certificate::OSCertHandles issuer_intermediates( net::X509Certificate::OSCertHandles issuer_intermediates(
val->GetIntermediateCertificates().begin() + 1, val->GetIntermediateCertificates().begin() + 1,
val->GetIntermediateCertificates().end()); val->GetIntermediateCertificates().end());
@ -69,15 +68,6 @@ v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
val->GetIntermediateCertificates().front(), val->GetIntermediateCertificates().front(),
issuer_intermediates); issuer_intermediates);
dict.Set("issuerCert", issuer_cert); dict.Set("issuerCert", issuer_cert);
std::vector<std::string> intermediates_encoded;
for (auto& native_cert : intermediates) {
std::string encoded;
net::X509Certificate::GetPEMEncoded(native_cert, &encoded);
intermediates_encoded.push_back(encoded);
}
dict.Set("intermediates", intermediates_encoded);
} }
return dict.GetHandle(); return dict.GetHandle();
@ -113,24 +103,21 @@ bool Converter<scoped_refptr<net::X509Certificate>>::FromV8(
if (!CertFromData(data, &leaf_cert)) if (!CertFromData(data, &leaf_cert))
return false; return false;
std::vector<std::string> intermediates_encoded; scoped_refptr<net::X509Certificate> parent;
dict.Get("intermediates", &intermediates_encoded); if (dict.Get("issuerCert", &parent)) {
std::vector<net::X509Certificate::OSCertHandle> intermediates; auto parents = std::vector<net::X509Certificate::OSCertHandle>(
for (size_t i = 0; i < intermediates_encoded.size(); i++) { parent->GetIntermediateCertificates());
auto intermediate_data = intermediates_encoded[i]; parents.insert(parents.begin(), parent->os_cert_handle());
scoped_refptr<net::X509Certificate> cert;
if (!CertFromData(intermediate_data, &cert))
return false;
intermediates.push_back(cert->os_cert_handle());
}
auto cert = net::X509Certificate::CreateFromHandle( auto cert = net::X509Certificate::CreateFromHandle(
leaf_cert->os_cert_handle(), intermediates); leaf_cert->os_cert_handle(), parents);
if (!cert) if (!cert)
return false; return false;
*out = cert; *out = cert;
} else {
*out = leaf_cert;
}
return true; return true;
} }