| 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" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // callback, the remaining requests in the completing job will NOT be cancelled. | 74 // callback, the remaining requests in the completing job will NOT be cancelled. |
| 75 | 75 |
| 76 namespace { | 76 namespace { |
| 77 | 77 |
| 78 // The maximum number of cache entries to use for the ExpiringCache. | 78 // The maximum number of cache entries to use for the ExpiringCache. |
| 79 const unsigned kMaxCacheEntries = 256; | 79 const unsigned kMaxCacheEntries = 256; |
| 80 | 80 |
| 81 // The number of seconds to cache entries. | 81 // The number of seconds to cache entries. |
| 82 const unsigned kTTLSecs = 1800; // 30 minutes. | 82 const unsigned kTTLSecs = 1800; // 30 minutes. |
| 83 | 83 |
| 84 base::Value* CertVerifyResultCallback(const CertVerifyResult& verify_result, | 84 scoped_ptr<base::Value> CertVerifyResultCallback( |
| 85 NetLogCaptureMode capture_mode) { | 85 const CertVerifyResult& verify_result, |
| 86 base::DictionaryValue* results = new base::DictionaryValue(); | 86 NetLogCaptureMode capture_mode) { |
| 87 scoped_ptr<base::DictionaryValue> results(new base::DictionaryValue()); |
| 87 results->SetBoolean("has_md5", verify_result.has_md5); | 88 results->SetBoolean("has_md5", verify_result.has_md5); |
| 88 results->SetBoolean("has_md2", verify_result.has_md2); | 89 results->SetBoolean("has_md2", verify_result.has_md2); |
| 89 results->SetBoolean("has_md4", verify_result.has_md4); | 90 results->SetBoolean("has_md4", verify_result.has_md4); |
| 90 results->SetBoolean("is_issued_by_known_root", | 91 results->SetBoolean("is_issued_by_known_root", |
| 91 verify_result.is_issued_by_known_root); | 92 verify_result.is_issued_by_known_root); |
| 92 results->SetBoolean("is_issued_by_additional_trust_anchor", | 93 results->SetBoolean("is_issued_by_additional_trust_anchor", |
| 93 verify_result.is_issued_by_additional_trust_anchor); | 94 verify_result.is_issued_by_additional_trust_anchor); |
| 94 results->SetBoolean("common_name_fallback_used", | 95 results->SetBoolean("common_name_fallback_used", |
| 95 verify_result.common_name_fallback_used); | 96 verify_result.common_name_fallback_used); |
| 96 results->SetInteger("cert_status", verify_result.cert_status); | 97 results->SetInteger("cert_status", verify_result.cert_status); |
| 97 results->Set("verified_cert", | 98 results->Set("verified_cert", |
| 98 NetLogX509CertificateCallback(verify_result.verified_cert.get(), | 99 NetLogX509CertificateCallback(verify_result.verified_cert.get(), |
| 99 capture_mode)); | 100 capture_mode)); |
| 100 | 101 |
| 101 base::ListValue* hashes = new base::ListValue(); | 102 scoped_ptr<base::ListValue> hashes(new base::ListValue()); |
| 102 for (std::vector<HashValue>::const_iterator it = | 103 for (std::vector<HashValue>::const_iterator it = |
| 103 verify_result.public_key_hashes.begin(); | 104 verify_result.public_key_hashes.begin(); |
| 104 it != verify_result.public_key_hashes.end(); | 105 it != verify_result.public_key_hashes.end(); |
| 105 ++it) { | 106 ++it) { |
| 106 hashes->AppendString(it->ToString()); | 107 hashes->AppendString(it->ToString()); |
| 107 } | 108 } |
| 108 results->Set("public_key_hashes", hashes); | 109 results->Set("public_key_hashes", hashes.Pass()); |
| 109 | 110 |
| 110 return results; | 111 return results.Pass(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace | 114 } // namespace |
| 114 | 115 |
| 115 MultiThreadedCertVerifier::CachedResult::CachedResult() : error(ERR_FAILED) {} | 116 MultiThreadedCertVerifier::CachedResult::CachedResult() : error(ERR_FAILED) {} |
| 116 | 117 |
| 117 MultiThreadedCertVerifier::CachedResult::~CachedResult() {} | 118 MultiThreadedCertVerifier::CachedResult::~CachedResult() {} |
| 118 | 119 |
| 119 MultiThreadedCertVerifier::CacheValidityPeriod::CacheValidityPeriod( | 120 MultiThreadedCertVerifier::CacheValidityPeriod::CacheValidityPeriod( |
| 120 const base::Time& now) | 121 const base::Time& now) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 X509Certificate* cert, | 256 X509Certificate* cert, |
| 256 MultiThreadedCertVerifier* cert_verifier) | 257 MultiThreadedCertVerifier* cert_verifier) |
| 257 : key_(key), | 258 : key_(key), |
| 258 start_time_(base::TimeTicks::Now()), | 259 start_time_(base::TimeTicks::Now()), |
| 259 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_CERT_VERIFIER_JOB)), | 260 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_CERT_VERIFIER_JOB)), |
| 260 cert_verifier_(cert_verifier), | 261 cert_verifier_(cert_verifier), |
| 261 is_first_job_(false), | 262 is_first_job_(false), |
| 262 weak_ptr_factory_(this) { | 263 weak_ptr_factory_(this) { |
| 263 net_log_.BeginEvent( | 264 net_log_.BeginEvent( |
| 264 NetLog::TYPE_CERT_VERIFIER_JOB, | 265 NetLog::TYPE_CERT_VERIFIER_JOB, |
| 265 base::Bind(&NetLogX509CertificateCallback, base::Unretained(cert))); | 266 base::Bind(NetLogX509CertificateCallback, base::Unretained(cert))); |
| 266 } | 267 } |
| 267 | 268 |
| 268 // Indicates whether this was the first job started by the CertVerifier. This | 269 // Indicates whether this was the first job started by the CertVerifier. This |
| 269 // is only used for logging certain UMA stats. | 270 // is only used for logging certain UMA stats. |
| 270 void set_is_first_job(bool is_first_job) { is_first_job_ = is_first_job; } | 271 void set_is_first_job(bool is_first_job) { is_first_job_ = is_first_job; } |
| 271 | 272 |
| 272 const MultiThreadedCertVerifier::RequestParams& key() const { return key_; } | 273 const MultiThreadedCertVerifier::RequestParams& key() const { return key_; } |
| 273 | 274 |
| 274 // Posts a task to the worker pool to do the verification. Once the | 275 // Posts a task to the worker pool to do the verification. Once the |
| 275 // verification has completed on the worker thread, it will call | 276 // verification has completed on the worker thread, it will call |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 333 } |
| 333 | 334 |
| 334 private: | 335 private: |
| 335 using RequestList = base::LinkedList<CertVerifierRequest>; | 336 using RequestList = base::LinkedList<CertVerifierRequest>; |
| 336 | 337 |
| 337 // Called on completion of the Job to log UMA metrics and NetLog events. | 338 // Called on completion of the Job to log UMA metrics and NetLog events. |
| 338 void LogMetrics( | 339 void LogMetrics( |
| 339 const MultiThreadedCertVerifier::CachedResult& verify_result) { | 340 const MultiThreadedCertVerifier::CachedResult& verify_result) { |
| 340 net_log_.EndEvent( | 341 net_log_.EndEvent( |
| 341 NetLog::TYPE_CERT_VERIFIER_JOB, | 342 NetLog::TYPE_CERT_VERIFIER_JOB, |
| 342 base::Bind(&CertVerifyResultCallback, verify_result.result)); | 343 base::Bind(CertVerifyResultCallback, verify_result.result)); |
| 343 base::TimeDelta latency = base::TimeTicks::Now() - start_time_; | 344 base::TimeDelta latency = base::TimeTicks::Now() - start_time_; |
| 344 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_Job_Latency", | 345 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_Job_Latency", |
| 345 latency, | 346 latency, |
| 346 base::TimeDelta::FromMilliseconds(1), | 347 base::TimeDelta::FromMilliseconds(1), |
| 347 base::TimeDelta::FromMinutes(10), | 348 base::TimeDelta::FromMinutes(10), |
| 348 100); | 349 100); |
| 349 if (is_first_job_) { | 350 if (is_first_job_) { |
| 350 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_First_Job_Latency", | 351 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_First_Job_Latency", |
| 351 latency, | 352 latency, |
| 352 base::TimeDelta::FromMilliseconds(1), | 353 base::TimeDelta::FromMilliseconds(1), |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 // search. | 557 // search. |
| 557 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, | 558 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, |
| 558 JobToRequestParamsComparator()); | 559 JobToRequestParamsComparator()); |
| 559 if (it != inflight_.end() && !(key < (*it)->key())) | 560 if (it != inflight_.end() && !(key < (*it)->key())) |
| 560 return *it; | 561 return *it; |
| 561 return nullptr; | 562 return nullptr; |
| 562 } | 563 } |
| 563 | 564 |
| 564 } // namespace net | 565 } // namespace net |
| 565 | 566 |
| OLD | NEW |