Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(855)

Side by Side Diff: net/cert/internal/trust_store_nss.cc

Issue 2832703002: Allow the TrustStore interface to return matching intermediates, and identify distrusted certs. (Closed)
Patch Set: mac fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/cert/internal/trust_store_nss.h" 5 #include "net/cert/internal/trust_store_nss.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <certdb.h> 8 #include <certdb.h>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "crypto/nss_util.h" 11 #include "crypto/nss_util.h"
12 #include "net/cert/internal/cert_errors.h" 12 #include "net/cert/internal/cert_errors.h"
13 #include "net/cert/internal/parsed_certificate.h" 13 #include "net/cert/internal/parsed_certificate.h"
14 #include "net/cert/x509_util.h" 14 #include "net/cert/x509_util.h"
15 15
16 // TODO(mattm): structure so that supporting ChromeOS multi-profile stuff is 16 // TODO(mattm): structure so that supporting ChromeOS multi-profile stuff is
17 // doable (Have a TrustStoreChromeOS which uses net::NSSProfileFilterChromeOS, 17 // doable (Have a TrustStoreChromeOS which uses net::NSSProfileFilterChromeOS,
18 // similar to CertVerifyProcChromeOS.) 18 // similar to CertVerifyProcChromeOS.)
19 19
20 namespace net { 20 namespace net {
21 21
22 TrustStoreNSS::TrustStoreNSS(SECTrustType trust_type) 22 TrustStoreNSS::TrustStoreNSS(SECTrustType trust_type)
23 : trust_type_(trust_type) {} 23 : trust_type_(trust_type) {}
24 24
25 TrustStoreNSS::~TrustStoreNSS() = default; 25 TrustStoreNSS::~TrustStoreNSS() = default;
26 26
27 void TrustStoreNSS::FindTrustAnchorsForCert( 27 void TrustStoreNSS::FindIssuers(const scoped_refptr<ParsedCertificate>& cert,
28 const scoped_refptr<ParsedCertificate>& cert, 28 TrustAnchors* trust_anchors,
29 TrustAnchors* out_anchors) const { 29 ParsedCertificateList* intermediates) const {
30 crypto::EnsureNSSInit(); 30 crypto::EnsureNSSInit();
31 31
32 SECItem name; 32 SECItem name;
33 // Use the original issuer value instead of the normalized version. NSS does a 33 // Use the original issuer value instead of the normalized version. NSS does a
34 // less extensive normalization in its Name comparisons, so our normalized 34 // less extensive normalization in its Name comparisons, so our normalized
35 // version may not match the unnormalized version. 35 // version may not match the unnormalized version.
36 name.len = cert->tbs().issuer_tlv.Length(); 36 name.len = cert->tbs().issuer_tlv.Length();
37 name.data = const_cast<uint8_t*>(cert->tbs().issuer_tlv.UnsafeData()); 37 name.data = const_cast<uint8_t*>(cert->tbs().issuer_tlv.UnsafeData());
38 // |validOnly| in CERT_CreateSubjectCertList controls whether to return only 38 // |validOnly| in CERT_CreateSubjectCertList controls whether to return only
39 // certs that are valid at |sorttime|. Expiration isn't meaningful for trust 39 // certs that are valid at |sorttime|. Expiration isn't meaningful for trust
40 // anchors, so request all the matches. 40 // anchors, so request all the matches.
41 CERTCertList* found_certs = CERT_CreateSubjectCertList( 41 CERTCertList* found_certs = CERT_CreateSubjectCertList(
42 nullptr /* certList */, CERT_GetDefaultCertDB(), &name, 42 nullptr /* certList */, CERT_GetDefaultCertDB(), &name,
43 PR_Now() /* sorttime */, PR_FALSE /* validOnly */); 43 PR_Now() /* sorttime */, PR_FALSE /* validOnly */);
44 if (!found_certs) 44 if (!found_certs)
45 return; 45 return;
46 46
47 for (CERTCertListNode* node = CERT_LIST_HEAD(found_certs); 47 for (CERTCertListNode* node = CERT_LIST_HEAD(found_certs);
48 !CERT_LIST_END(node, found_certs); node = CERT_LIST_NEXT(node)) { 48 !CERT_LIST_END(node, found_certs); node = CERT_LIST_NEXT(node)) {
49 CERTCertTrust trust; 49 CERTCertTrust trust;
50 if (CERT_GetCertTrust(node->cert, &trust) != SECSuccess) 50 if (CERT_GetCertTrust(node->cert, &trust) != SECSuccess)
51 continue; 51 continue;
52 52
53 // TODO(mattm): handle explicit distrust (blacklisting)?
54 const int ca_trust = CERTDB_TRUSTED_CA; 53 const int ca_trust = CERTDB_TRUSTED_CA;
55 if ((SEC_GET_TRUST_FLAGS(&trust, trust_type_) & ca_trust) != ca_trust) 54 bool is_trusted =
56 continue; 55 (SEC_GET_TRUST_FLAGS(&trust, trust_type_) & ca_trust) == ca_trust;
57 56
58 CertErrors errors; 57 CertErrors parse_errors;
59 scoped_refptr<ParsedCertificate> anchor_cert = ParsedCertificate::Create( 58 scoped_refptr<ParsedCertificate> cur_cert = ParsedCertificate::Create(
60 x509_util::CreateCryptoBuffer(node->cert->derCert.data, 59 x509_util::CreateCryptoBuffer(node->cert->derCert.data,
61 node->cert->derCert.len), 60 node->cert->derCert.len),
62 {}, &errors); 61 {}, &parse_errors);
63 if (!anchor_cert) { 62
63 if (!cur_cert) {
64 // TODO(crbug.com/634443): return errors better. 64 // TODO(crbug.com/634443): return errors better.
65 LOG(ERROR) << "Error parsing issuer certificate:\n" 65 LOG(ERROR) << "Error parsing issuer certificate:\n"
66 << errors.ToDebugString(); 66 << parse_errors.ToDebugString();
67 continue; 67 continue;
68 } 68 }
69 69
70 out_anchors->push_back(TrustAnchor::CreateFromCertificateNoConstraints( 70 if (is_trusted) {
71 std::move(anchor_cert))); 71 trust_anchors->push_back(
72 TrustAnchor::CreateFromCertificateNoConstraints(std::move(cur_cert)));
73 } else {
74 // Note that |cur_cert| may be distrusted. That is OK, since the path
75 // builder will be checking IsBlacklisted() for each certificate in the
76 // chain.
77 intermediates->push_back(std::move(cur_cert));
78 }
72 } 79 }
73 CERT_DestroyCertList(found_certs); 80 CERT_DestroyCertList(found_certs);
74 } 81 }
75 82
83 bool TrustStoreNSS::IsBlacklisted(
84 const scoped_refptr<ParsedCertificate>& cert) const {
85 // TODO(eroman): Implement
86 return false;
87 }
88
76 } // namespace net 89 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698