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

Side by Side Diff: net/cert/multi_threaded_cert_verifier.cc

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 #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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // destructors run. 251 // destructors run.
252 PR_DetachThread(); 252 PR_DetachThread();
253 #endif 253 #endif
254 } 254 }
255 255
256 // CertVerifierJob lives only on the verifier's origin message loop. 256 // CertVerifierJob lives only on the verifier's origin message loop.
257 class CertVerifierJob { 257 class CertVerifierJob {
258 public: 258 public:
259 CertVerifierJob(const CertVerifier::RequestParams& key, 259 CertVerifierJob(const CertVerifier::RequestParams& key,
260 NetLog* net_log, 260 NetLog* net_log,
261 X509Certificate* cert,
262 MultiThreadedCertVerifier* cert_verifier) 261 MultiThreadedCertVerifier* cert_verifier)
263 : key_(key), 262 : key_(key),
264 start_time_(base::TimeTicks::Now()), 263 start_time_(base::TimeTicks::Now()),
265 wall_start_time_(base::Time::Now()), 264 wall_start_time_(base::Time::Now()),
266 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_CERT_VERIFIER_JOB)), 265 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_CERT_VERIFIER_JOB)),
267 cert_verifier_(cert_verifier), 266 cert_verifier_(cert_verifier),
268 is_first_job_(false), 267 is_first_job_(false),
269 weak_ptr_factory_(this) { 268 weak_ptr_factory_(this) {
270 net_log_.BeginEvent( 269 net_log_.BeginEvent(NetLog::TYPE_CERT_VERIFIER_JOB,
271 NetLog::TYPE_CERT_VERIFIER_JOB, 270 base::Bind(&NetLogX509CertificateCallback,
272 base::Bind(&NetLogX509CertificateCallback, base::Unretained(cert))); 271 base::Unretained(key.certificate().get())));
273 } 272 }
274 273
275 // Indicates whether this was the first job started by the CertVerifier. This 274 // Indicates whether this was the first job started by the CertVerifier. This
276 // is only used for logging certain UMA stats. 275 // is only used for logging certain UMA stats.
277 void set_is_first_job(bool is_first_job) { is_first_job_ = is_first_job; } 276 void set_is_first_job(bool is_first_job) { is_first_job_ = is_first_job; }
278 277
279 const CertVerifier::RequestParams& key() const { return key_; } 278 const CertVerifier::RequestParams& key() const { return key_; }
280 279
281 // Posts a task to the worker pool to do the verification. Once the 280 // Posts a task to the worker pool to do the verification. Once the
282 // verification has completed on the worker thread, it will call 281 // verification has completed on the worker thread, it will call
283 // OnJobCompleted() on the origin thread. 282 // OnJobCompleted() on the origin thread.
284 bool Start(const scoped_refptr<CertVerifyProc>& verify_proc, 283 bool Start(const scoped_refptr<CertVerifyProc>& verify_proc,
285 const scoped_refptr<X509Certificate>& cert, 284 const scoped_refptr<CRLSet>& crl_set) {
286 const std::string& hostname,
287 const std::string& ocsp_response,
288 int flags,
289 const scoped_refptr<CRLSet>& crl_set,
290 const CertificateList& additional_trust_anchors) {
291 // Owned by the bound reply callback. 285 // Owned by the bound reply callback.
292 std::unique_ptr<MultiThreadedCertVerifier::CachedResult> owned_result( 286 std::unique_ptr<MultiThreadedCertVerifier::CachedResult> owned_result(
293 new MultiThreadedCertVerifier::CachedResult()); 287 new MultiThreadedCertVerifier::CachedResult());
294 288
295 // Parameter evaluation order is undefined in C++. Ensure the pointer value 289 // Parameter evaluation order is undefined in C++. Ensure the pointer value
296 // is gotten before calling base::Passed(). 290 // is gotten before calling base::Passed().
297 auto result = owned_result.get(); 291 auto result = owned_result.get();
298 292
299 return base::WorkerPool::PostTaskAndReply( 293 return base::WorkerPool::PostTaskAndReply(
300 FROM_HERE, 294 FROM_HERE,
301 base::Bind(&DoVerifyOnWorkerThread, verify_proc, cert, hostname, 295 base::Bind(&DoVerifyOnWorkerThread, verify_proc, key_.certificate(),
302 ocsp_response, flags, crl_set, additional_trust_anchors, 296 key_.hostname(), key_.ocsp_response(), key_.flags(), crl_set,
303 &result->error, &result->result), 297 key_.additional_trust_anchors(), &result->error,
298 &result->result),
304 base::Bind(&CertVerifierJob::OnJobCompleted, 299 base::Bind(&CertVerifierJob::OnJobCompleted,
305 weak_ptr_factory_.GetWeakPtr(), base::Passed(&owned_result)), 300 weak_ptr_factory_.GetWeakPtr(), base::Passed(&owned_result)),
306 true /* task is slow */); 301 true /* task is slow */);
307 } 302 }
308 303
309 ~CertVerifierJob() { 304 ~CertVerifierJob() {
310 // If the job is in progress, cancel it. 305 // If the job is in progress, cancel it.
311 if (cert_verifier_) { 306 if (cert_verifier_) {
312 cert_verifier_ = nullptr; 307 cert_verifier_ = nullptr;
313 308
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 STLDeleteElements(&inflight_); 411 STLDeleteElements(&inflight_);
417 CertDatabase::GetInstance()->RemoveObserver(this); 412 CertDatabase::GetInstance()->RemoveObserver(this);
418 } 413 }
419 414
420 void MultiThreadedCertVerifier::SetCertTrustAnchorProvider( 415 void MultiThreadedCertVerifier::SetCertTrustAnchorProvider(
421 CertTrustAnchorProvider* trust_anchor_provider) { 416 CertTrustAnchorProvider* trust_anchor_provider) {
422 DCHECK(CalledOnValidThread()); 417 DCHECK(CalledOnValidThread());
423 trust_anchor_provider_ = trust_anchor_provider; 418 trust_anchor_provider_ = trust_anchor_provider;
424 } 419 }
425 420
426 int MultiThreadedCertVerifier::Verify(X509Certificate* cert, 421 int MultiThreadedCertVerifier::Verify(const CertVerifier::RequestParams& params,
427 const std::string& hostname,
428 const std::string& ocsp_response,
429 int flags,
430 CRLSet* crl_set, 422 CRLSet* crl_set,
431 CertVerifyResult* verify_result, 423 CertVerifyResult* verify_result,
432 const CompletionCallback& callback, 424 const CompletionCallback& callback,
433 std::unique_ptr<Request>* out_req, 425 std::unique_ptr<Request>* out_req,
434 const BoundNetLog& net_log) { 426 const BoundNetLog& net_log) {
435 out_req->reset(); 427 out_req->reset();
436 428
437 DCHECK(CalledOnValidThread()); 429 DCHECK(CalledOnValidThread());
438 430
439 if (callback.is_null() || !verify_result || hostname.empty()) 431 if (callback.is_null() || !verify_result || params.hostname().empty())
440 return ERR_INVALID_ARGUMENT; 432 return ERR_INVALID_ARGUMENT;
441 433
442 requests_++; 434 requests_++;
443 435
444 const CertificateList empty_cert_list; 436 CertificateList new_trust_anchors(params.additional_trust_anchors());
445 const CertificateList& additional_trust_anchors = 437 if (trust_anchor_provider_) {
446 trust_anchor_provider_ ? 438 new_trust_anchors.insert(
447 trust_anchor_provider_->GetAdditionalTrustAnchors() : empty_cert_list; 439 new_trust_anchors.end(),
440 trust_anchor_provider_->GetAdditionalTrustAnchors().begin(),
eroman 2016/05/20 00:41:18 My expectation is for GetAdditionalTrustAnchors()
Ryan Sleevi 2016/05/20 02:39:43 Why? It's the same as GetIntermediateCertificates(
441 trust_anchor_provider_->GetAdditionalTrustAnchors().end());
442 }
448 443
449 const CertVerifier::RequestParams key(cert, hostname, flags, ocsp_response, 444 const CertVerifier::RequestParams key(params.certificate(), params.hostname(),
450 additional_trust_anchors); 445 params.flags(), params.ocsp_response(),
446 new_trust_anchors);
451 const CertVerifierCache::value_type* cached_entry = 447 const CertVerifierCache::value_type* cached_entry =
452 cache_.Get(key, CacheValidityPeriod(base::Time::Now())); 448 cache_.Get(key, CacheValidityPeriod(base::Time::Now()));
453 if (cached_entry) { 449 if (cached_entry) {
454 ++cache_hits_; 450 ++cache_hits_;
455 *verify_result = cached_entry->result; 451 *verify_result = cached_entry->result;
456 return cached_entry->error; 452 return cached_entry->error;
457 } 453 }
458 454
459 // No cache hit. See if an identical request is currently in flight. 455 // No cache hit. See if an identical request is currently in flight.
460 CertVerifierJob* job = FindJob(key); 456 CertVerifierJob* job = FindJob(key);
461 if (job) { 457 if (job) {
462 // An identical request is in flight already. We'll just attach our 458 // An identical request is in flight already. We'll just attach our
463 // callback. 459 // callback.
464 inflight_joins_++; 460 inflight_joins_++;
465 } else { 461 } else {
466 // Need to make a new job. 462 // Need to make a new job.
467 std::unique_ptr<CertVerifierJob> new_job( 463 std::unique_ptr<CertVerifierJob> new_job(
468 new CertVerifierJob(key, net_log.net_log(), cert, this)); 464 new CertVerifierJob(key, net_log.net_log(), this));
469 465
470 if (!new_job->Start(verify_proc_, cert, hostname, ocsp_response, flags, 466 if (!new_job->Start(verify_proc_, crl_set)) {
471 crl_set, additional_trust_anchors)) {
472 // TODO(wtc): log to the NetLog. 467 // TODO(wtc): log to the NetLog.
473 LOG(ERROR) << "CertVerifierJob couldn't be started."; 468 LOG(ERROR) << "CertVerifierJob couldn't be started.";
474 return ERR_INSUFFICIENT_RESOURCES; // Just a guess. 469 return ERR_INSUFFICIENT_RESOURCES; // Just a guess.
475 } 470 }
476 471
477 job = new_job.release(); 472 job = new_job.release();
478 inflight_.insert(job); 473 inflight_.insert(job);
479 474
480 if (requests_ == 1) 475 if (requests_ == 1)
481 job->set_is_first_job(true); 476 job->set_is_first_job(true);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 // The JobSet is kept in sorted order so items can be found using binary 556 // The JobSet is kept in sorted order so items can be found using binary
562 // search. 557 // search.
563 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, 558 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key,
564 JobToRequestParamsComparator()); 559 JobToRequestParamsComparator());
565 if (it != inflight_.end() && !(key < (*it)->key())) 560 if (it != inflight_.end() && !(key < (*it)->key()))
566 return *it; 561 return *it;
567 return nullptr; 562 return nullptr;
568 } 563 }
569 564
570 } // namespace net 565 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698