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 #include "net/cert/multi_threaded_cert_verifier.h" | 5 #include "net/cert/multi_threaded_cert_verifier.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 // Represents the output and result callback of a request. The | 121 // Represents the output and result callback of a request. The |
122 // CertVerifierRequest is owned by the caller that initiated the call to | 122 // CertVerifierRequest is owned by the caller that initiated the call to |
123 // CertVerifier::Verify(). | 123 // CertVerifier::Verify(). |
124 class CertVerifierRequest : public base::LinkNode<CertVerifierRequest>, | 124 class CertVerifierRequest : public base::LinkNode<CertVerifierRequest>, |
125 public CertVerifier::Request { | 125 public CertVerifier::Request { |
126 public: | 126 public: |
127 CertVerifierRequest(CertVerifierJob* job, | 127 CertVerifierRequest(CertVerifierJob* job, |
128 const CompletionCallback& callback, | 128 const CompletionCallback& callback, |
129 CertVerifyResult* verify_result, | 129 CertVerifyResult* verify_result, |
130 const BoundNetLog& net_log) | 130 const NetLogWithSource& net_log) |
131 : job_(job), | 131 : job_(job), |
132 callback_(callback), | 132 callback_(callback), |
133 verify_result_(verify_result), | 133 verify_result_(verify_result), |
134 net_log_(net_log) { | 134 net_log_(net_log) { |
135 net_log_.BeginEvent(NetLogEventType::CERT_VERIFIER_REQUEST); | 135 net_log_.BeginEvent(NetLogEventType::CERT_VERIFIER_REQUEST); |
136 } | 136 } |
137 | 137 |
138 // Cancels the request. | 138 // Cancels the request. |
139 ~CertVerifierRequest() override { | 139 ~CertVerifierRequest() override { |
140 if (job_) { | 140 if (job_) { |
(...skipping 18 matching lines...) Expand all Loading... |
159 *verify_result_ = verify_result.result; | 159 *verify_result_ = verify_result.result; |
160 | 160 |
161 base::ResetAndReturn(&callback_).Run(verify_result.error); | 161 base::ResetAndReturn(&callback_).Run(verify_result.error); |
162 } | 162 } |
163 | 163 |
164 void OnJobCancelled() { | 164 void OnJobCancelled() { |
165 job_ = nullptr; | 165 job_ = nullptr; |
166 callback_.Reset(); | 166 callback_.Reset(); |
167 } | 167 } |
168 | 168 |
169 const BoundNetLog& net_log() const { return net_log_; } | 169 const NetLogWithSource& net_log() const { return net_log_; } |
170 | 170 |
171 private: | 171 private: |
172 CertVerifierJob* job_; // Not owned. | 172 CertVerifierJob* job_; // Not owned. |
173 CompletionCallback callback_; | 173 CompletionCallback callback_; |
174 CertVerifyResult* verify_result_; | 174 CertVerifyResult* verify_result_; |
175 const BoundNetLog net_log_; | 175 const NetLogWithSource net_log_; |
176 }; | 176 }; |
177 | 177 |
178 // DoVerifyOnWorkerThread runs the verification synchronously on a worker | 178 // DoVerifyOnWorkerThread runs the verification synchronously on a worker |
179 // thread. The output parameters (error and result) must remain alive. | 179 // thread. The output parameters (error and result) must remain alive. |
180 void DoVerifyOnWorkerThread(const scoped_refptr<CertVerifyProc>& verify_proc, | 180 void DoVerifyOnWorkerThread(const scoped_refptr<CertVerifyProc>& verify_proc, |
181 const scoped_refptr<X509Certificate>& cert, | 181 const scoped_refptr<X509Certificate>& cert, |
182 const std::string& hostname, | 182 const std::string& hostname, |
183 const std::string& ocsp_response, | 183 const std::string& ocsp_response, |
184 int flags, | 184 int flags, |
185 const scoped_refptr<CRLSet>& crl_set, | 185 const scoped_refptr<CRLSet>& crl_set, |
(...skipping 17 matching lines...) Expand all Loading... |
203 } | 203 } |
204 | 204 |
205 // CertVerifierJob lives only on the verifier's origin message loop. | 205 // CertVerifierJob lives only on the verifier's origin message loop. |
206 class CertVerifierJob { | 206 class CertVerifierJob { |
207 public: | 207 public: |
208 CertVerifierJob(const CertVerifier::RequestParams& key, | 208 CertVerifierJob(const CertVerifier::RequestParams& key, |
209 NetLog* net_log, | 209 NetLog* net_log, |
210 MultiThreadedCertVerifier* cert_verifier) | 210 MultiThreadedCertVerifier* cert_verifier) |
211 : key_(key), | 211 : key_(key), |
212 start_time_(base::TimeTicks::Now()), | 212 start_time_(base::TimeTicks::Now()), |
213 net_log_( | 213 net_log_(NetLogWithSource::Make(net_log, |
214 BoundNetLog::Make(net_log, NetLogSourceType::CERT_VERIFIER_JOB)), | 214 NetLogSourceType::CERT_VERIFIER_JOB)), |
215 cert_verifier_(cert_verifier), | 215 cert_verifier_(cert_verifier), |
216 is_first_job_(false), | 216 is_first_job_(false), |
217 weak_ptr_factory_(this) { | 217 weak_ptr_factory_(this) { |
218 net_log_.BeginEvent(NetLogEventType::CERT_VERIFIER_JOB, | 218 net_log_.BeginEvent(NetLogEventType::CERT_VERIFIER_JOB, |
219 base::Bind(&NetLogX509CertificateCallback, | 219 base::Bind(&NetLogX509CertificateCallback, |
220 base::Unretained(key.certificate().get()))); | 220 base::Unretained(key.certificate().get()))); |
221 } | 221 } |
222 | 222 |
223 // Indicates whether this was the first job started by the CertVerifier. This | 223 // Indicates whether this was the first job started by the CertVerifier. This |
224 // is only used for logging certain UMA stats. | 224 // is only used for logging certain UMA stats. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 it != requests_.end(); it = it->next()) { | 262 it != requests_.end(); it = it->next()) { |
263 it->value()->OnJobCancelled(); | 263 it->value()->OnJobCancelled(); |
264 } | 264 } |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 // Creates and attaches a request to the Job. | 268 // Creates and attaches a request to the Job. |
269 std::unique_ptr<CertVerifierRequest> CreateRequest( | 269 std::unique_ptr<CertVerifierRequest> CreateRequest( |
270 const CompletionCallback& callback, | 270 const CompletionCallback& callback, |
271 CertVerifyResult* verify_result, | 271 CertVerifyResult* verify_result, |
272 const BoundNetLog& net_log) { | 272 const NetLogWithSource& net_log) { |
273 std::unique_ptr<CertVerifierRequest> request( | 273 std::unique_ptr<CertVerifierRequest> request( |
274 new CertVerifierRequest(this, callback, verify_result, net_log)); | 274 new CertVerifierRequest(this, callback, verify_result, net_log)); |
275 | 275 |
276 request->net_log().AddEvent( | 276 request->net_log().AddEvent( |
277 NetLogEventType::CERT_VERIFIER_REQUEST_BOUND_TO_JOB, | 277 NetLogEventType::CERT_VERIFIER_REQUEST_BOUND_TO_JOB, |
278 net_log_.source().ToEventParametersCallback()); | 278 net_log_.source().ToEventParametersCallback()); |
279 | 279 |
280 requests_.Append(request.get()); | 280 requests_.Append(request.get()); |
281 return request; | 281 return request; |
282 } | 282 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 const CertVerifier::RequestParams key_; | 325 const CertVerifier::RequestParams key_; |
326 // The tick count of when the job started. This is used to measure how long | 326 // The tick count of when the job started. This is used to measure how long |
327 // the job actually took to complete. | 327 // the job actually took to complete. |
328 const base::TimeTicks start_time_; | 328 const base::TimeTicks start_time_; |
329 | 329 |
330 RequestList requests_; // Non-owned. | 330 RequestList requests_; // Non-owned. |
331 | 331 |
332 const BoundNetLog net_log_; | 332 const NetLogWithSource net_log_; |
333 MultiThreadedCertVerifier* cert_verifier_; // Non-owned. | 333 MultiThreadedCertVerifier* cert_verifier_; // Non-owned. |
334 | 334 |
335 bool is_first_job_; | 335 bool is_first_job_; |
336 base::WeakPtrFactory<CertVerifierJob> weak_ptr_factory_; | 336 base::WeakPtrFactory<CertVerifierJob> weak_ptr_factory_; |
337 }; | 337 }; |
338 | 338 |
339 MultiThreadedCertVerifier::MultiThreadedCertVerifier( | 339 MultiThreadedCertVerifier::MultiThreadedCertVerifier( |
340 CertVerifyProc* verify_proc) | 340 CertVerifyProc* verify_proc) |
341 : requests_(0), inflight_joins_(0), verify_proc_(verify_proc) {} | 341 : requests_(0), inflight_joins_(0), verify_proc_(verify_proc) {} |
342 | 342 |
343 MultiThreadedCertVerifier::~MultiThreadedCertVerifier() { | 343 MultiThreadedCertVerifier::~MultiThreadedCertVerifier() { |
344 base::STLDeleteElements(&inflight_); | 344 base::STLDeleteElements(&inflight_); |
345 } | 345 } |
346 | 346 |
347 int MultiThreadedCertVerifier::Verify(const RequestParams& params, | 347 int MultiThreadedCertVerifier::Verify(const RequestParams& params, |
348 CRLSet* crl_set, | 348 CRLSet* crl_set, |
349 CertVerifyResult* verify_result, | 349 CertVerifyResult* verify_result, |
350 const CompletionCallback& callback, | 350 const CompletionCallback& callback, |
351 std::unique_ptr<Request>* out_req, | 351 std::unique_ptr<Request>* out_req, |
352 const BoundNetLog& net_log) { | 352 const NetLogWithSource& net_log) { |
353 out_req->reset(); | 353 out_req->reset(); |
354 | 354 |
355 DCHECK(CalledOnValidThread()); | 355 DCHECK(CalledOnValidThread()); |
356 | 356 |
357 if (callback.is_null() || !verify_result || params.hostname().empty()) | 357 if (callback.is_null() || !verify_result || params.hostname().empty()) |
358 return ERR_INVALID_ARGUMENT; | 358 return ERR_INVALID_ARGUMENT; |
359 | 359 |
360 requests_++; | 360 requests_++; |
361 | 361 |
362 // See if an identical request is currently in flight. | 362 // See if an identical request is currently in flight. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 // The JobSet is kept in sorted order so items can be found using binary | 420 // The JobSet is kept in sorted order so items can be found using binary |
421 // search. | 421 // search. |
422 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, | 422 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, |
423 JobToRequestParamsComparator()); | 423 JobToRequestParamsComparator()); |
424 if (it != inflight_.end() && !(key < (*it)->key())) | 424 if (it != inflight_.end() && !(key < (*it)->key())) |
425 return *it; | 425 return *it; |
426 return nullptr; | 426 return nullptr; |
427 } | 427 } |
428 | 428 |
429 } // namespace net | 429 } // namespace net |
OLD | NEW |