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

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, 7 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 (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 // Verification parameters to verify |certificate| against the supplied
eroman 2016/05/20 00:41:18 nit: "Verification parameter to verify" --> Parame
80 // |flags| are required. The rest are optional. 81 // |hostname| as an SSL server.
eroman 2016/05/20 00:41:18 Should this comment document expectation around th
82 //
83 // |flags| is a bitwise OR of VerifyFlags.
84 //
85 // |ocsp_response| is optional, but if non-empty, should contain an OCSP
86 // response obtained via OCSP stapling. It may be ignored by the
87 // CertVerifier.
88 //
89 // |additional_trust_anchors| is optional, but if non-empty, should contain
90 // additional certificates to be treated as trust anchors. It may be ignored
91 // by the CertVerifier.
81 class NET_EXPORT RequestParams { 92 class NET_EXPORT RequestParams {
82 public: 93 public:
83 RequestParams(X509Certificate* certificate, 94 RequestParams(scoped_refptr<X509Certificate> certificate,
84 const std::string& hostname, 95 const std::string& hostname,
85 int flags, 96 int flags,
86 const std::string& ocsp_response, 97 const std::string& ocsp_response,
87 const CertificateList& additional_trust_anchors); 98 CertificateList additional_trust_anchors);
88 RequestParams(const RequestParams& other); 99 RequestParams(const RequestParams& other);
89 ~RequestParams(); 100 ~RequestParams();
90 101
102 const scoped_refptr<X509Certificate>& certificate() const {
103 return certificate_;
104 }
91 const std::string& hostname() const { return hostname_; } 105 const std::string& hostname() const { return hostname_; }
92 int flags() const { return flags_; } 106 int flags() const { return flags_; }
93 const std::vector<SHA1HashValue> request_data() const { 107 const std::string& ocsp_response() const { return ocsp_response_; }
94 return request_data_; 108 const CertificateList& additional_trust_anchors() const {
109 return additional_trust_anchors_;
95 } 110 }
96 111
97 bool operator<(const RequestParams& other) const; 112 bool operator<(const RequestParams& other) const;
98 113
99 private: 114 private:
115 scoped_refptr<X509Certificate> certificate_;
100 std::string hostname_; 116 std::string hostname_;
eroman 2016/05/20 00:41:18 I suggest marking these all as const.
101 int flags_; 117 int flags_;
102 std::vector<SHA1HashValue> request_data_; 118 std::string ocsp_response_;
119 CertificateList additional_trust_anchors_;
120
121 // Used to optimize sorting/indexing comparisons.
122 std::string key_;
103 }; 123 };
104 124
105 // When the verifier is destroyed, all certificate verification requests are 125 // When the verifier is destroyed, all certificate verification requests are
106 // canceled, and their completion callbacks will not be called. 126 // canceled, and their completion callbacks will not be called.
107 virtual ~CertVerifier() {} 127 virtual ~CertVerifier() {}
108 128
109 // Verifies the given certificate against the given hostname as an SSL server. 129 // Verifies the given certificate against the given hostname as an SSL server.
110 // Returns OK if successful or an error code upon failure. 130 // Returns OK if successful or an error code upon failure.
111 // 131 //
112 // The |*verify_result| structure, including the |verify_result->cert_status| 132 // The |*verify_result| structure, including the |verify_result->cert_status|
113 // bitmask, is always filled out regardless of the return value. If the 133 // bitmask, is always filled out regardless of the return value. If the
114 // certificate has multiple errors, the corresponding status flags are set in 134 // certificate has multiple errors, the corresponding status flags are set in
115 // |verify_result->cert_status|, and the error code for the most serious 135 // |verify_result->cert_status|, and the error code for the most serious
116 // error is returned. 136 // error is returned.
117 // 137 //
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 138 // |crl_set| points to an optional CRLSet structure which can be used to
130 // avoid revocation checks over the network. 139 // avoid revocation checks over the network.
131 // 140 //
132 // |callback| must not be null. ERR_IO_PENDING is returned if the operation 141 // |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 142 // could not be completed synchronously, in which case the result code will
134 // be passed to the callback when available. 143 // be passed to the callback when available.
135 // 144 //
136 // On asynchronous completion (when Verify returns ERR_IO_PENDING) |out_req| 145 // 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 146 // will be reset with a pointer to the request. Freeing this pointer before
138 // the request has completed will cancel it. 147 // the request has completed will cancel it.
139 // 148 //
140 // If Verify() completes synchronously then |out_req| *may* be reset to 149 // If Verify() completes synchronously then |out_req| *may* be reset to
141 // nullptr. However it is not guaranteed that all implementations will reset 150 // nullptr. However it is not guaranteed that all implementations will reset
142 // it in this case. 151 // it in this case.
143 // 152 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, 153 CRLSet* crl_set,
150 CertVerifyResult* verify_result, 154 CertVerifyResult* verify_result,
151 const CompletionCallback& callback, 155 const CompletionCallback& callback,
152 std::unique_ptr<Request>* out_req, 156 std::unique_ptr<Request>* out_req,
153 const BoundNetLog& net_log) = 0; 157 const BoundNetLog& net_log) = 0;
154 158
155 // Returns true if this CertVerifier supports stapled OCSP responses. 159 // Returns true if this CertVerifier supports stapled OCSP responses.
156 virtual bool SupportsOCSPStapling(); 160 virtual bool SupportsOCSPStapling();
157 161
158 // Creates a CertVerifier implementation that verifies certificates using 162 // Creates a CertVerifier implementation that verifies certificates using
159 // the preferred underlying cryptographic libraries. 163 // the preferred underlying cryptographic libraries.
160 static std::unique_ptr<CertVerifier> CreateDefault(); 164 static std::unique_ptr<CertVerifier> CreateDefault();
161 }; 165 };
162 166
163 } // namespace net 167 } // namespace net
164 168
165 #endif // NET_CERT_CERT_VERIFIER_H_ 169 #endif // NET_CERT_CERT_VERIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698