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

Side by Side Diff: net/base/multi_threaded_cert_verifier.h

Issue 10556022: Consider the verification time as well as the expiration time when caching certificate verification… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fixes Created 8 years, 6 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 | Annotate | Revision Log
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_BASE_MULTI_THREADED_CERT_VERIFIER_H_ 5 #ifndef NET_BASE_MULTI_THREADED_CERT_VERIFIER_H_
6 #define NET_BASE_MULTI_THREADED_CERT_VERIFIER_H_ 6 #define NET_BASE_MULTI_THREADED_CERT_VERIFIER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 // CachedResult contains the result of a certificate verification. 102 // CachedResult contains the result of a certificate verification.
103 struct CachedResult { 103 struct CachedResult {
104 CachedResult(); 104 CachedResult();
105 ~CachedResult(); 105 ~CachedResult();
106 106
107 int error; // The return value of CertVerifier::Verify. 107 int error; // The return value of CertVerifier::Verify.
108 CertVerifyResult result; // The output of CertVerifier::Verify. 108 CertVerifyResult result; // The output of CertVerifier::Verify.
109 }; 109 };
110 110
111 // Rather than having a single validity point along a monotonically increasing
112 // timeline, certificate verification is based on falling within a range of
113 // the certificate's NotBefore and NotAfter and based on what the current
114 // system clock says (which may advance forwards or backwards as users correct
115 // clock skew). ValidityRange and CompareValidityFn are helpers to ensure that
116 // expiration is measured both by the 'general' case (now + cache TTL) and by
117 // whether or not significant enough clock skew was introduced since the last
118 // verification.
119 struct ValidityRange {
wtc 2012/06/18 22:10:38 Nit: this seems to be more commonly called the val
Ryan Sleevi 2012/06/19 00:59:28 To some degree, I think I wanted to avoid that ter
120 explicit ValidityRange(const base::Time& now);
121 ValidityRange(const base::Time& now, const base::Time& expiration);
122
123 base::Time verification_time;
124 base::Time expiration_time;
125 };
126
127 typedef bool (*CompareValidityFn)(const ValidityRange&, const ValidityRange&);
128 typedef ExpiringCache<RequestParams, CachedResult, ValidityRange,
129 CompareValidityFn> CertVerifierCache;
130
131 // Returns true if |now| is within the validity range of |expiration|.
132 static bool CompareValidityRange(const ValidityRange& now,
133 const ValidityRange& expiration);
134
111 void HandleResult(X509Certificate* cert, 135 void HandleResult(X509Certificate* cert,
112 const std::string& hostname, 136 const std::string& hostname,
113 int flags, 137 int flags,
114 int error, 138 int error,
115 const CertVerifyResult& verify_result); 139 const CertVerifyResult& verify_result);
116 140
117 // CertDatabase::Observer methods: 141 // CertDatabase::Observer methods:
118 virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE; 142 virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE;
119 143
120 // For unit testing. 144 // For unit testing.
121 void ClearCache() { cache_.Clear(); } 145 void ClearCache() { cache_.Clear(); }
122 size_t GetCacheSize() const { return cache_.size(); } 146 size_t GetCacheSize() const { return cache_.size(); }
123 uint64 cache_hits() const { return cache_hits_; } 147 uint64 cache_hits() const { return cache_hits_; }
124 uint64 requests() const { return requests_; } 148 uint64 requests() const { return requests_; }
125 uint64 inflight_joins() const { return inflight_joins_; } 149 uint64 inflight_joins() const { return inflight_joins_; }
126 void SetCertVerifyProc(CertVerifyProc* verify_proc); 150 void SetCertVerifyProc(CertVerifyProc* verify_proc);
127 151
128 // cache_ maps from a request to a cached result. 152 // cache_ maps from a request to a cached result.
129 typedef ExpiringCache<RequestParams, CachedResult> CertVerifierCache;
130 CertVerifierCache cache_; 153 CertVerifierCache cache_;
131 154
132 // inflight_ maps from a request to an active verification which is taking 155 // inflight_ maps from a request to an active verification which is taking
133 // place. 156 // place.
134 std::map<RequestParams, CertVerifierJob*> inflight_; 157 std::map<RequestParams, CertVerifierJob*> inflight_;
135 158
136 uint64 requests_; 159 uint64 requests_;
137 uint64 cache_hits_; 160 uint64 cache_hits_;
138 uint64 inflight_joins_; 161 uint64 inflight_joins_;
139 162
140 scoped_refptr<CertVerifyProc> verify_proc_; 163 scoped_refptr<CertVerifyProc> verify_proc_;
141 164
142 DISALLOW_COPY_AND_ASSIGN(MultiThreadedCertVerifier); 165 DISALLOW_COPY_AND_ASSIGN(MultiThreadedCertVerifier);
143 }; 166 };
144 167
145 } // namespace net 168 } // namespace net
146 169
147 #endif // NET_BASE_MULTI_THREADED_CERT_VERIFIER_H_ 170 #endif // NET_BASE_MULTI_THREADED_CERT_VERIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698