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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "base/values.h" | |
19 #include "net/base/hash_value.h" | |
18 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
19 #include "net/base/net_log.h" | 21 #include "net/base/net_log.h" |
20 #include "net/cert/cert_trust_anchor_provider.h" | 22 #include "net/cert/cert_trust_anchor_provider.h" |
21 #include "net/cert/cert_verify_proc.h" | 23 #include "net/cert/cert_verify_proc.h" |
22 #include "net/cert/crl_set.h" | 24 #include "net/cert/crl_set.h" |
23 #include "net/cert/x509_certificate.h" | 25 #include "net/cert/x509_certificate.h" |
24 #include "net/cert/x509_certificate_net_log_param.h" | 26 #include "net/cert/x509_certificate_net_log_param.h" |
25 | 27 |
26 #if defined(USE_NSS) || defined(OS_IOS) | 28 #if defined(USE_NSS) || defined(OS_IOS) |
27 #include <private/pprthred.h> // PR_DetachThread | 29 #include <private/pprthred.h> // PR_DetachThread |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 // without posting a task to a worker thread. | 73 // without posting a task to a worker thread. |
72 | 74 |
73 namespace { | 75 namespace { |
74 | 76 |
75 // The default value of max_cache_entries_. | 77 // The default value of max_cache_entries_. |
76 const unsigned kMaxCacheEntries = 256; | 78 const unsigned kMaxCacheEntries = 256; |
77 | 79 |
78 // The number of seconds for which we'll cache a cache entry. | 80 // The number of seconds for which we'll cache a cache entry. |
79 const unsigned kTTLSecs = 1800; // 30 minutes. | 81 const unsigned kTTLSecs = 1800; // 30 minutes. |
80 | 82 |
83 base::Value* CertVerifyResultCallback(const CertVerifyResult& verify_result, | |
84 NetLog::LogLevel log_level) { | |
85 base::DictionaryValue* results = new base::DictionaryValue(); | |
86 results->SetBoolean("has_md5", verify_result.has_md5); | |
87 results->SetBoolean("has_md2", verify_result.has_md2); | |
88 results->SetBoolean("has_md4", verify_result.has_md4); | |
89 results->SetBoolean("is_issued_by_known_root", | |
90 verify_result.is_issued_by_known_root); | |
91 results->SetBoolean("is_issued_by_additional_trust_anchor", | |
92 verify_result.is_issued_by_additional_trust_anchor); | |
93 results->SetBoolean("common_name_fallback_used", | |
94 verify_result.common_name_fallback_used); | |
95 results->SetInteger("cert_status", verify_result.cert_status); | |
96 results->Set( | |
97 "verified_cert", | |
98 NetLogX509CertificateCallback(verify_result.verified_cert, log_level)); | |
99 base::ListValue* hashes = new base::ListValue(); | |
100 for (std::vector<HashValue>::const_iterator it = | |
101 verify_result.public_key_hashes.begin(); | |
102 it != verify_result.public_key_hashes.end(); | |
103 ++it) { | |
104 hashes->AppendString(it->ToString()); | |
105 } | |
106 | |
107 results->Set("public_key_hashes", hashes); | |
wtc
2014/06/02 22:29:47
Please use blank lines to suggest that lines 99-10
| |
108 | |
109 return results; | |
110 } | |
111 | |
81 } // namespace | 112 } // namespace |
82 | 113 |
83 MultiThreadedCertVerifier::CachedResult::CachedResult() : error(ERR_FAILED) {} | 114 MultiThreadedCertVerifier::CachedResult::CachedResult() : error(ERR_FAILED) {} |
84 | 115 |
85 MultiThreadedCertVerifier::CachedResult::~CachedResult() {} | 116 MultiThreadedCertVerifier::CachedResult::~CachedResult() {} |
86 | 117 |
87 MultiThreadedCertVerifier::CacheValidityPeriod::CacheValidityPeriod( | 118 MultiThreadedCertVerifier::CacheValidityPeriod::CacheValidityPeriod( |
88 const base::Time& now) | 119 const base::Time& now) |
89 : verification_time(now), | 120 : verification_time(now), |
90 expiration_time(now) { | 121 expiration_time(now) { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 NetLog::TYPE_CERT_VERIFIER_REQUEST_BOUND_TO_JOB, | 375 NetLog::TYPE_CERT_VERIFIER_REQUEST_BOUND_TO_JOB, |
345 net_log_.source().ToEventParametersCallback()); | 376 net_log_.source().ToEventParametersCallback()); |
346 | 377 |
347 requests_.push_back(request); | 378 requests_.push_back(request); |
348 } | 379 } |
349 | 380 |
350 void HandleResult( | 381 void HandleResult( |
351 const MultiThreadedCertVerifier::CachedResult& verify_result, | 382 const MultiThreadedCertVerifier::CachedResult& verify_result, |
352 bool is_first_job) { | 383 bool is_first_job) { |
353 worker_ = NULL; | 384 worker_ = NULL; |
354 net_log_.EndEvent(NetLog::TYPE_CERT_VERIFIER_JOB); | 385 net_log_.EndEvent( |
386 NetLog::TYPE_CERT_VERIFIER_JOB, | |
387 base::Bind(&CertVerifyResultCallback, verify_result.result)); | |
355 base::TimeDelta latency = base::TimeTicks::Now() - start_time_; | 388 base::TimeDelta latency = base::TimeTicks::Now() - start_time_; |
356 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_Job_Latency", | 389 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_Job_Latency", |
357 latency, | 390 latency, |
358 base::TimeDelta::FromMilliseconds(1), | 391 base::TimeDelta::FromMilliseconds(1), |
359 base::TimeDelta::FromMinutes(10), | 392 base::TimeDelta::FromMinutes(10), |
360 100); | 393 100); |
361 if (is_first_job) { | 394 if (is_first_job) { |
362 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_First_Job_Latency", | 395 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_First_Job_Latency", |
363 latency, | 396 latency, |
364 base::TimeDelta::FromMilliseconds(1), | 397 base::TimeDelta::FromMilliseconds(1), |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 } | 609 } |
577 | 610 |
578 void MultiThreadedCertVerifier::OnCACertChanged( | 611 void MultiThreadedCertVerifier::OnCACertChanged( |
579 const X509Certificate* cert) { | 612 const X509Certificate* cert) { |
580 DCHECK(CalledOnValidThread()); | 613 DCHECK(CalledOnValidThread()); |
581 | 614 |
582 ClearCache(); | 615 ClearCache(); |
583 } | 616 } |
584 | 617 |
585 } // namespace net | 618 } // namespace net |
619 | |
wtc
2014/06/02 22:29:47
Nit: if this line was not added by git cl format,
| |
OLD | NEW |