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

Side by Side Diff: net/cert/cert_verifier.h

Issue 1994353002: Update CertVerifier::Verify to use RequestParams instead (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@request_params
Patch Set: Rebased Created 4 years, 6 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
« no previous file with comments | « ios/web/net/cert_verifier_block_adapter.cc ('k') | net/cert/cert_verifier.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
13 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
14 #include "net/base/hash_value.h" 15 #include "net/base/hash_value.h"
15 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
16 #include "net/cert/x509_certificate.h" 17 #include "net/cert/x509_certificate.h"
17 18
18 namespace net { 19 namespace net {
19 20
20 class BoundNetLog; 21 class BoundNetLog;
21 class CertVerifyResult; 22 class CertVerifyResult;
22 class CRLSet; 23 class CRLSet;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // for certificates issued by non-public trust anchors. Failure to check 70 // for certificates issued by non-public trust anchors. Failure to check
70 // revocation is treated as a hard failure. 71 // revocation is treated as a hard failure.
71 // Note: If VERIFY_CERT_IO_ENABLE is not also supplied, certificates 72 // Note: If VERIFY_CERT_IO_ENABLE is not also supplied, certificates
72 // that chain to local trust anchors will likely fail - for example, due to 73 // that chain to local trust anchors will likely fail - for example, due to
73 // lacking fresh cached revocation issue (Windows) or because OCSP stapling 74 // lacking fresh cached revocation issue (Windows) or because OCSP stapling
74 // can only provide information for the leaf, and not for any 75 // can only provide information for the leaf, and not for any
75 // intermediates. 76 // intermediates.
76 VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS = 1 << 4, 77 VERIFY_REV_CHECKING_REQUIRED_LOCAL_ANCHORS = 1 << 4,
77 }; 78 };
78 79
79 // The parameters for doing a Verify(). |certificate|, |hostname|, and 80 // Parameters to verify |certificate| against the supplied
80 // |flags| are required. The rest are optional. 81 // |hostname| as an SSL server.
82 //
83 // |hostname| should be a canonicalized hostname (in A-Label form) or IP
84 // address in string form, following the rules of a URL host portion. In
85 // the case of |hostname| being a domain name, it may contain a trailing
86 // dot (e.g. "example.com."), as used to signal to DNS not to perform
87 // suffix search, and it will safely be ignored. If |hostname| is an IPv6
88 // address, it MUST be in URL form - that is, surrounded in square
89 // brackets, such as "[::1]".
90 //
91 // |flags| is a bitwise OR of VerifyFlags.
92 //
93 // |ocsp_response| is optional, but if non-empty, should contain an OCSP
94 // response obtained via OCSP stapling. It may be ignored by the
95 // CertVerifier.
96 //
97 // |additional_trust_anchors| is optional, but if non-empty, should contain
98 // additional certificates to be treated as trust anchors. It may be ignored
99 // by the CertVerifier.
81 class NET_EXPORT RequestParams { 100 class NET_EXPORT RequestParams {
82 public: 101 public:
83 RequestParams(X509Certificate* certificate, 102 RequestParams(scoped_refptr<X509Certificate> certificate,
84 const std::string& hostname, 103 const std::string& hostname,
85 int flags, 104 int flags,
86 const std::string& ocsp_response, 105 const std::string& ocsp_response,
87 const CertificateList& additional_trust_anchors); 106 CertificateList additional_trust_anchors);
88 RequestParams(const RequestParams& other); 107 RequestParams(const RequestParams& other);
89 ~RequestParams(); 108 ~RequestParams();
90 109
110 const scoped_refptr<X509Certificate>& certificate() const {
111 return certificate_;
112 }
91 const std::string& hostname() const { return hostname_; } 113 const std::string& hostname() const { return hostname_; }
92 int flags() const { return flags_; } 114 int flags() const { return flags_; }
93 const std::vector<SHA1HashValue> request_data() const { 115 const std::string& ocsp_response() const { return ocsp_response_; }
94 return request_data_; 116 const CertificateList& additional_trust_anchors() const {
117 return additional_trust_anchors_;
95 } 118 }
96 119
97 bool operator<(const RequestParams& other) const; 120 bool operator<(const RequestParams& other) const;
98 121
99 private: 122 private:
123 scoped_refptr<X509Certificate> certificate_;
100 std::string hostname_; 124 std::string hostname_;
101 int flags_; 125 int flags_;
102 std::vector<SHA1HashValue> request_data_; 126 std::string ocsp_response_;
127 CertificateList additional_trust_anchors_;
128
129 // Used to optimize sorting/indexing comparisons.
130 std::string key_;
103 }; 131 };
104 132
105 // When the verifier is destroyed, all certificate verification requests are 133 // When the verifier is destroyed, all certificate verification requests are
106 // canceled, and their completion callbacks will not be called. 134 // canceled, and their completion callbacks will not be called.
107 virtual ~CertVerifier() {} 135 virtual ~CertVerifier() {}
108 136
109 // Verifies the given certificate against the given hostname as an SSL server. 137 // Verifies the given certificate against the given hostname as an SSL server.
110 // Returns OK if successful or an error code upon failure. 138 // Returns OK if successful or an error code upon failure.
111 // 139 //
112 // The |*verify_result| structure, including the |verify_result->cert_status| 140 // The |*verify_result| structure, including the |verify_result->cert_status|
113 // bitmask, is always filled out regardless of the return value. If the 141 // bitmask, is always filled out regardless of the return value. If the
114 // certificate has multiple errors, the corresponding status flags are set in 142 // certificate has multiple errors, the corresponding status flags are set in
115 // |verify_result->cert_status|, and the error code for the most serious 143 // |verify_result->cert_status|, and the error code for the most serious
116 // error is returned. 144 // error is returned.
117 // 145 //
118 // |ocsp_response|, if non-empty, is a stapled OCSP response to use.
119 //
120 // |flags| is bitwise OR'd of VerifyFlags.
121 // If VERIFY_REV_CHECKING_ENABLED is set in |flags|, certificate revocation
122 // checking is performed.
123 //
124 // If VERIFY_EV_CERT is set in |flags| too, EV certificate verification is
125 // performed. If |flags| is VERIFY_EV_CERT (that is,
126 // VERIFY_REV_CHECKING_ENABLED is not set), EV certificate verification will
127 // not be performed.
128 //
129 // |crl_set| points to an optional CRLSet structure which can be used to 146 // |crl_set| points to an optional CRLSet structure which can be used to
130 // avoid revocation checks over the network. 147 // avoid revocation checks over the network.
131 // 148 //
132 // |callback| must not be null. ERR_IO_PENDING is returned if the operation 149 // |callback| must not be null. ERR_IO_PENDING is returned if the operation
133 // could not be completed synchronously, in which case the result code will 150 // could not be completed synchronously, in which case the result code will
134 // be passed to the callback when available. 151 // be passed to the callback when available.
135 // 152 //
136 // On asynchronous completion (when Verify returns ERR_IO_PENDING) |out_req| 153 // On asynchronous completion (when Verify returns ERR_IO_PENDING) |out_req|
137 // will be reset with a pointer to the request. Freeing this pointer before 154 // will be reset with a pointer to the request. Freeing this pointer before
138 // the request has completed will cancel it. 155 // the request has completed will cancel it.
139 // 156 //
140 // If Verify() completes synchronously then |out_req| *may* be reset to 157 // If Verify() completes synchronously then |out_req| *may* be reset to
141 // nullptr. However it is not guaranteed that all implementations will reset 158 // nullptr. However it is not guaranteed that all implementations will reset
142 // it in this case. 159 // it in this case.
143 // 160 virtual int Verify(const RequestParams& params,
144 // TODO(rsleevi): Update this to use RequestParams as part of the signature.
145 virtual int Verify(X509Certificate* cert,
146 const std::string& hostname,
147 const std::string& ocsp_response,
148 int flags,
149 CRLSet* crl_set, 161 CRLSet* crl_set,
150 CertVerifyResult* verify_result, 162 CertVerifyResult* verify_result,
151 const CompletionCallback& callback, 163 const CompletionCallback& callback,
152 std::unique_ptr<Request>* out_req, 164 std::unique_ptr<Request>* out_req,
153 const BoundNetLog& net_log) = 0; 165 const BoundNetLog& net_log) = 0;
154 166
155 // Returns true if this CertVerifier supports stapled OCSP responses. 167 // Returns true if this CertVerifier supports stapled OCSP responses.
156 virtual bool SupportsOCSPStapling(); 168 virtual bool SupportsOCSPStapling();
157 169
158 // Creates a CertVerifier implementation that verifies certificates using 170 // Creates a CertVerifier implementation that verifies certificates using
159 // the preferred underlying cryptographic libraries. 171 // the preferred underlying cryptographic libraries.
160 static std::unique_ptr<CertVerifier> CreateDefault(); 172 static std::unique_ptr<CertVerifier> CreateDefault();
161 }; 173 };
162 174
163 } // namespace net 175 } // namespace net
164 176
165 #endif // NET_CERT_CERT_VERIFIER_H_ 177 #endif // NET_CERT_CERT_VERIFIER_H_
OLDNEW
« no previous file with comments | « ios/web/net/cert_verifier_block_adapter.cc ('k') | net/cert/cert_verifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698