| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/cert/internal/cert_issuer_source_nss.h" |
| 6 |
| 7 #include <cert.h> |
| 8 #include <certdb.h> |
| 9 |
| 10 #include "crypto/nss_util.h" |
| 11 #include "net/cert/internal/cert_errors.h" |
| 12 #include "net/cert/internal/parsed_certificate.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 CertIssuerSourceNSS::CertIssuerSourceNSS() = default; |
| 17 CertIssuerSourceNSS::~CertIssuerSourceNSS() = default; |
| 18 |
| 19 void CertIssuerSourceNSS::SyncGetIssuersOf(const ParsedCertificate* cert, |
| 20 ParsedCertificateList* issuers) { |
| 21 crypto::EnsureNSSInit(); |
| 22 |
| 23 SECItem name; |
| 24 // Use the original issuer value instead of the normalized version. NSS does a |
| 25 // less extensive normalization in its Name comparisons, so our normalized |
| 26 // version may not match the unnormalized version. |
| 27 name.len = cert->tbs().issuer_tlv.Length(); |
| 28 name.data = const_cast<uint8_t*>(cert->tbs().issuer_tlv.UnsafeData()); |
| 29 // |validOnly| in CERT_CreateSubjectCertList controls whether to return only |
| 30 // certs that are valid at |sorttime|. Including expired certs could lead to |
| 31 // more useful error messages in the case where a valid path can't be found, |
| 32 // so request all matches. |
| 33 CERTCertList* found_certs = CERT_CreateSubjectCertList( |
| 34 nullptr /* certList */, CERT_GetDefaultCertDB(), &name, |
| 35 PR_Now() /* sorttime */, PR_FALSE /* validOnly */); |
| 36 if (!found_certs) |
| 37 return; |
| 38 |
| 39 for (CERTCertListNode* node = CERT_LIST_HEAD(found_certs); |
| 40 !CERT_LIST_END(node, found_certs); node = CERT_LIST_NEXT(node)) { |
| 41 CertErrors errors; |
| 42 scoped_refptr<ParsedCertificate> issuer_cert = ParsedCertificate::Create( |
| 43 node->cert->derCert.data, node->cert->derCert.len, {}, &errors); |
| 44 if (!issuer_cert) { |
| 45 // TODO(crbug.com/634443): return errors better. |
| 46 LOG(ERROR) << "Error parsing issuer certificate:\n" |
| 47 << errors.ToDebugString(); |
| 48 continue; |
| 49 } |
| 50 |
| 51 issuers->push_back(std::move(issuer_cert)); |
| 52 } |
| 53 CERT_DestroyCertList(found_certs); |
| 54 } |
| 55 |
| 56 void CertIssuerSourceNSS::AsyncGetIssuersOf(const ParsedCertificate* cert, |
| 57 std::unique_ptr<Request>* out_req) { |
| 58 // CertIssuerSourceNSS never returns asynchronous results. |
| 59 out_req->reset(); |
| 60 } |
| 61 |
| 62 } // namespace net |
| OLD | NEW |