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

Side by Side Diff: net/cert/internal/verify_certificate_chain.h

Issue 1923433002: Certificate path builder for new certificate verification library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ 5 #ifndef NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_
6 #define NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ 6 #define NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "net/base/net_export.h" 15 #include "net/base/net_export.h"
16 #include "net/cert/internal/parse_certificate.h" 16 #include "net/cert/internal/parse_certificate.h"
17 #include "net/der/input.h" 17 #include "net/der/input.h"
18 18
19 namespace net { 19 namespace net {
20 20
21 namespace der { 21 namespace der {
22 struct GeneralizedTime; 22 struct GeneralizedTime;
23 } 23 }
24 24
25 class SignaturePolicy; 25 class SignaturePolicy;
26 26
27 // Represents a trust anchor (i.e. a trusted root certificate). 27 // XXX Rename, better comment
28 class NET_EXPORT TrustAnchor { 28 // Represents a certificate, including top-level parsing and normalized name
29 // values. The certificate is not completely parsed and validated, only the
30 // validation performed by ParseCertificate, ParseTbsCertificate and
31 // NormalizeName is done.
32 class NET_EXPORT CertThing {
29 public: 33 public:
30 // The certificate data for this trust anchor may either be owned internally 34 // The certificate data for this trust anchor may either be owned internally
31 // (INTERNAL_COPY) or owned externally (EXTERNAL_REFERENCE). When it is 35 // (INTERNAL_COPY) or owned externally (EXTERNAL_REFERENCE). When it is
32 // owned internally the data is held by |cert_data_| 36 // owned internally the data is held by |cert_data_|
33 enum class DataSource { 37 enum class DataSource {
34 INTERNAL_COPY, 38 INTERNAL_COPY,
35 EXTERNAL_REFERENCE, 39 EXTERNAL_REFERENCE,
36 }; 40 };
37 41
38 TrustAnchor(); 42 ~CertThing();
39 ~TrustAnchor();
40 43
41 // Creates a TrustAnchor given a DER-encoded certificate. Returns nullptr on 44 // Creates a CertThing given a DER-encoded certificate. Returns nullptr on
42 // failure. Failure will occur if the certificate data cannot be parsed to 45 // failure. Failure will occur if the certificate data cannot be parsed to
43 // find a subject. 46 // find a subject.
44 // 47 //
45 // The provided certificate data is either copied, or aliased, depending on 48 // The provided certificate data is either copied, or aliased, depending on
46 // the value of |source|. See the comments for DataSource for details. 49 // the value of |source|. See the comments for DataSource for details.
47 static std::unique_ptr<TrustAnchor> CreateFromCertificateData( 50 static std::unique_ptr<CertThing> CreateFromCertificateData(
48 const uint8_t* data, 51 const uint8_t* data,
49 size_t length, 52 size_t length,
50 DataSource source); 53 DataSource source);
54 static std::unique_ptr<CertThing> CreateFromCertificateCopy(
55 const base::StringPiece& data);
56
57 // XXX docs
58 std::unique_ptr<CertThing> Clone() const;
51 59
52 // Returns true if the trust anchor matches |name|. In other words, returns 60 // Returns true if the trust anchor matches |name|. In other words, returns
53 // true if the certificate's subject matches |name|. 61 // true if the certificate's subject matches |name|.
54 bool MatchesName(const der::Input& name) const; 62 bool MatchesName(const der::Input& name) const;
55 63
56 // Returns the DER-encoded certificate data for this trust anchor. 64 // Returns the DER-encoded certificate data for this cert.
57 const der::Input& cert() const { return cert_; } 65 const der::Input& der_cert() const { return cert_; }
66
67 const ParsedCertificate& parsed_cert() const { return parsed_cert_; }
68 const ParsedTbsCertificate& parsed_tbs() const { return parsed_tbs_; }
69
70 // Returns the DER-encoded normalized subject value (not including outer
71 // Sequence tag).
72 const std::string& normalized_subject() const { return normalized_subject_; }
73 // Returns the DER-encoded normalized issuer value (not including outer
74 // Sequence tag).
75 const std::string& normalized_issuer() const { return normalized_issuer_; }
58 76
59 private: 77 private:
78 CertThing();
79
60 // The backing store for the certificate data. This is only applicable when 80 // The backing store for the certificate data. This is only applicable when
61 // the trust anchor was initialized using DataSource::INTERNAL_COPY. 81 // the trust anchor was initialized using DataSource::INTERNAL_COPY.
62 std::vector<uint8_t> cert_data_; 82 std::vector<uint8_t> cert_data_;
63 83
64 // Note that the backing data for |cert_| and |name_| may come either form 84 // Note that the backing data for |cert_| and |name_| may come either form
65 // |cert_data_| or some external buffer (depending on how the anchor was 85 // |cert_data_| or some external buffer (depending on how the anchor was
66 // created). 86 // created).
67 87
68 // Points to the raw certificate DER. 88 // Points to the raw certificate DER.
69 der::Input cert_; 89 der::Input cert_;
70 90
71 // Points to the subject TLV for the certificate. 91 ParsedCertificate parsed_cert_;
72 der::Input name_; 92 ParsedTbsCertificate parsed_tbs_;
73 93
74 DISALLOW_COPY_AND_ASSIGN(TrustAnchor); 94 // Normalized DER-encoded Subject (not including outer Sequence tag).
95 std::string normalized_subject_;
96 // Normalized DER-encoded Issuer (not including outer Sequence tag).
97 std::string normalized_issuer_;
98
99 DISALLOW_COPY_AND_ASSIGN(CertThing);
75 }; 100 };
76 101
77 // A very simple implementation of a TrustStore, which contains a set of 102 // A very simple implementation of a TrustStore, which contains a set of
78 // trusted certificates. 103 // trusted certificates.
79 class NET_EXPORT TrustStore { 104 class NET_EXPORT TrustStore {
80 public: 105 public:
81 TrustStore(); 106 TrustStore();
82 ~TrustStore(); 107 ~TrustStore();
83 108
84 // Empties the trust store, resetting it to original state. 109 // Empties the trust store, resetting it to original state.
85 void Clear(); 110 void Clear();
86 111
87 // Adds a trusted certificate to the store. The trust store makes a copy of 112 // Adds a trusted certificate to the store. The trust store makes a copy of
88 // the provided certificate data. 113 // the provided certificate data.
89 bool AddTrustedCertificate(const uint8_t* data, 114 bool AddTrustedCertificate(const uint8_t* data,
90 size_t length) WARN_UNUSED_RESULT; 115 size_t length) WARN_UNUSED_RESULT;
91 bool AddTrustedCertificate(const base::StringPiece& data) WARN_UNUSED_RESULT; 116 bool AddTrustedCertificate(const base::StringPiece& data) WARN_UNUSED_RESULT;
92 117
93 // This function is the same as AddTrustedCertificate() except the underlying 118 // This function is the same as AddTrustedCertificate() except the underlying
94 // data is not copied. The caller is responsible for ensuring that the data 119 // data is not copied. The caller is responsible for ensuring that the data
95 // pointer remains alive and is not mutated for the lifetime of the 120 // pointer remains alive and is not mutated for the lifetime of the
96 // TrustStore. 121 // TrustStore.
97 bool AddTrustedCertificateWithoutCopying(const uint8_t* data, 122 bool AddTrustedCertificateWithoutCopying(const uint8_t* data,
98 size_t length) WARN_UNUSED_RESULT; 123 size_t length) WARN_UNUSED_RESULT;
99 124
100 // Returns the trust anchor that matches |name|, or nullptr if there is none. 125 // Returns the trust anchor that matches |name|, or nullptr if there is none.
101 // TODO(eroman): There may be multiple matches. 126 // TODO(eroman): There may be multiple matches.
102 const TrustAnchor* FindTrustAnchorByName(const der::Input& name) const 127 const CertThing* FindTrustAnchorByName(const der::Input& name) const
103 WARN_UNUSED_RESULT; 128 WARN_UNUSED_RESULT;
129 // XXX Add docs. Remove above version? Should take der::Input?
130 std::vector<const CertThing*> FindTrustAnchorsByNormalizedName(
131 const std::string& normalized_name) const WARN_UNUSED_RESULT;
104 132
105 // Returns true if |cert_der| matches a certificate in the TrustStore. 133 // Returns true if |cert_der| matches a certificate in the TrustStore.
106 bool IsTrustedCertificate(const der::Input& cert_der) const 134 bool IsTrustedCertificate(const der::Input& cert_der) const
107 WARN_UNUSED_RESULT; 135 WARN_UNUSED_RESULT;
108 136
109 private: 137 private:
110 bool AddTrustedCertificate(const uint8_t* data, 138 bool AddTrustedCertificate(const uint8_t* data,
111 size_t length, 139 size_t length,
112 TrustAnchor::DataSource source) WARN_UNUSED_RESULT; 140 CertThing::DataSource source) WARN_UNUSED_RESULT;
113 141
114 std::vector<std::unique_ptr<TrustAnchor>> anchors_; 142 std::vector<std::unique_ptr<CertThing>> anchors_;
115 143
116 DISALLOW_COPY_AND_ASSIGN(TrustStore); 144 DISALLOW_COPY_AND_ASSIGN(TrustStore);
117 }; 145 };
118 146
119 // VerifyCertificateChain() verifies a certificate path (chain) based on the 147 // VerifyCertificateChain() verifies a certificate path (chain) based on the
120 // rules in RFC 5280. 148 // rules in RFC 5280.
121 // 149 //
122 // WARNING: This implementation is in progress, and is currently 150 // WARNING: This implementation is in progress, and is currently
123 // incomplete. DO NOT USE IT unless its limitations are acceptable for your use. 151 // incomplete. DO NOT USE IT unless its limitations are acceptable for your use.
124 // 152 //
(...skipping 23 matching lines...) Expand all
148 // Outputs 176 // Outputs
149 // --------- 177 // ---------
150 // 178 //
151 // Returns true if the target certificate can be verified. 179 // Returns true if the target certificate can be verified.
152 NET_EXPORT bool VerifyCertificateChain(const std::vector<der::Input>& certs_der, 180 NET_EXPORT bool VerifyCertificateChain(const std::vector<der::Input>& certs_der,
153 const TrustStore& trust_store, 181 const TrustStore& trust_store,
154 const SignaturePolicy* signature_policy, 182 const SignaturePolicy* signature_policy,
155 const der::GeneralizedTime& time) 183 const der::GeneralizedTime& time)
156 WARN_UNUSED_RESULT; 184 WARN_UNUSED_RESULT;
157 185
186 NET_EXPORT bool VerifyCertificateChainAssumingTrustedRoot(
187 const std::vector<std::unique_ptr<CertThing>>& certs,
188 // The trust store is only used for assertions.
189 const TrustStore& trust_store,
190 const SignaturePolicy* signature_policy,
191 const der::GeneralizedTime& time) WARN_UNUSED_RESULT;
192
158 } // namespace net 193 } // namespace net
159 194
160 #endif // NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_ 195 #endif // NET_CERT_INTERNAL_VERIFY_CERTIFICATE_CHAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698