OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CERT_VERIFIER_H_ | 5 #ifndef NET_CERT_CERT_VERIFIER_H_ |
6 #define NET_CERT_CERT_VERIFIER_H_ | 6 #define NET_CERT_CERT_VERIFIER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
14 #include "net/base/hash_value.h" | |
13 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
16 #include "net/cert/x509_certificate.h" | |
14 | 17 |
15 namespace net { | 18 namespace net { |
16 | 19 |
17 class BoundNetLog; | 20 class BoundNetLog; |
18 class CertVerifyResult; | 21 class CertVerifyResult; |
19 class CRLSet; | 22 class CRLSet; |
20 class X509Certificate; | |
21 | 23 |
22 // CertVerifier represents a service for verifying certificates. | 24 // CertVerifier represents a service for verifying certificates. |
23 // | 25 // |
24 // CertVerifiers can handle multiple requests at a time. | 26 // CertVerifiers can handle multiple requests at a time. |
25 class NET_EXPORT CertVerifier { | 27 class NET_EXPORT CertVerifier { |
26 public: | 28 public: |
27 class Request { | 29 class Request { |
28 public: | 30 public: |
29 Request() {} | 31 Request() {} |
30 | 32 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 // for certificates issued by non-public trust anchors. Failure to check | 69 // for certificates issued by non-public trust anchors. Failure to check |
68 // revocation is treated as a hard failure. | 70 // revocation is treated as a hard failure. |
69 // Note: If VERIFY_CERT_IO_ENABLE is not also supplied, certificates | 71 // Note: If VERIFY_CERT_IO_ENABLE is not also supplied, certificates |
70 // that chain to local trust anchors will likely fail - for example, due to | 72 // that chain to local trust anchors will likely fail - for example, due to |
71 // lacking fresh cached revocation issue (Windows) or because OCSP stapling | 73 // lacking fresh cached revocation issue (Windows) or because OCSP stapling |
72 // can only provide information for the leaf, and not for any | 74 // can only provide information for the leaf, and not for any |
73 // intermediates. | 75 // intermediates. |
74 VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS = 1 << 4, | 76 VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS = 1 << 4, |
75 }; | 77 }; |
76 | 78 |
79 // The parameters for doing a Verify(). |certificate|, |hostname|, and | |
80 // |flags| are required. The rest are optional. | |
eroman
2016/05/18 01:43:18
Are you going to move documentation for the variou
Ryan Sleevi
2016/05/18 02:02:02
Yes, when updating Verify() to use this.
| |
81 class RequestParams { | |
82 public: | |
83 RequestParams(X509Certificate* certificate, | |
84 const std::string& hostname, | |
85 int flags, | |
86 const std::string& ocsp_response, | |
87 const CertificateList& additional_trust_anchors); | |
88 RequestParams(const RequestParams& other); | |
89 ~RequestParams(); | |
90 | |
91 const std::string& hostname() const { return hostname_; } | |
92 int flags() const { return flags_; } | |
93 const std::vector<SHA1HashValue> request_data() const { | |
94 return request_data_; | |
95 } | |
96 | |
97 bool operator<(const RequestParams& other) const; | |
98 | |
99 private: | |
100 std::string hostname_; | |
101 int flags_; | |
102 std::vector<SHA1HashValue> request_data_; | |
eroman
2016/05/18 01:43:18
Can you speak to the design choice of using a vect
Ryan Sleevi
2016/05/18 02:02:02
While I appreciate all of this feedback, I don't t
eroman
2016/05/18 02:06:43
OK, we can discuss that separately.
| |
103 }; | |
104 | |
77 // When the verifier is destroyed, all certificate verification requests are | 105 // When the verifier is destroyed, all certificate verification requests are |
78 // canceled, and their completion callbacks will not be called. | 106 // canceled, and their completion callbacks will not be called. |
79 virtual ~CertVerifier() {} | 107 virtual ~CertVerifier() {} |
80 | 108 |
81 // Verifies the given certificate against the given hostname as an SSL server. | 109 // Verifies the given certificate against the given hostname as an SSL server. |
82 // Returns OK if successful or an error code upon failure. | 110 // Returns OK if successful or an error code upon failure. |
83 // | 111 // |
84 // The |*verify_result| structure, including the |verify_result->cert_status| | 112 // The |*verify_result| structure, including the |verify_result->cert_status| |
85 // bitmask, is always filled out regardless of the return value. If the | 113 // bitmask, is always filled out regardless of the return value. If the |
86 // certificate has multiple errors, the corresponding status flags are set in | 114 // certificate has multiple errors, the corresponding status flags are set in |
(...skipping 19 matching lines...) Expand all Loading... | |
106 // be passed to the callback when available. | 134 // be passed to the callback when available. |
107 // | 135 // |
108 // On asynchronous completion (when Verify returns ERR_IO_PENDING) |out_req| | 136 // On asynchronous completion (when Verify returns ERR_IO_PENDING) |out_req| |
109 // will be reset with a pointer to the request. Freeing this pointer before | 137 // will be reset with a pointer to the request. Freeing this pointer before |
110 // the request has completed will cancel it. | 138 // the request has completed will cancel it. |
111 // | 139 // |
112 // If Verify() completes synchronously then |out_req| *may* be reset to | 140 // If Verify() completes synchronously then |out_req| *may* be reset to |
113 // nullptr. However it is not guaranteed that all implementations will reset | 141 // nullptr. However it is not guaranteed that all implementations will reset |
114 // it in this case. | 142 // it in this case. |
115 // | 143 // |
116 // TODO(rsleevi): Move CRLSet* out of the CertVerifier signature. | 144 // TODO(rsleevi): Update this to use RequestParams as part of the signature. |
117 virtual int Verify(X509Certificate* cert, | 145 virtual int Verify(X509Certificate* cert, |
118 const std::string& hostname, | 146 const std::string& hostname, |
119 const std::string& ocsp_response, | 147 const std::string& ocsp_response, |
120 int flags, | 148 int flags, |
121 CRLSet* crl_set, | 149 CRLSet* crl_set, |
122 CertVerifyResult* verify_result, | 150 CertVerifyResult* verify_result, |
123 const CompletionCallback& callback, | 151 const CompletionCallback& callback, |
124 std::unique_ptr<Request>* out_req, | 152 std::unique_ptr<Request>* out_req, |
125 const BoundNetLog& net_log) = 0; | 153 const BoundNetLog& net_log) = 0; |
126 | 154 |
127 // Returns true if this CertVerifier supports stapled OCSP responses. | 155 // Returns true if this CertVerifier supports stapled OCSP responses. |
128 virtual bool SupportsOCSPStapling(); | 156 virtual bool SupportsOCSPStapling(); |
129 | 157 |
130 // Creates a CertVerifier implementation that verifies certificates using | 158 // Creates a CertVerifier implementation that verifies certificates using |
131 // the preferred underlying cryptographic libraries. | 159 // the preferred underlying cryptographic libraries. |
132 static std::unique_ptr<CertVerifier> CreateDefault(); | 160 static std::unique_ptr<CertVerifier> CreateDefault(); |
133 }; | 161 }; |
134 | 162 |
135 } // namespace net | 163 } // namespace net |
136 | 164 |
137 #endif // NET_CERT_CERT_VERIFIER_H_ | 165 #endif // NET_CERT_CERT_VERIFIER_H_ |
OLD | NEW |