Chromium Code Reviews| 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 #ifndef NET_CERT_MULTI_THREADED_CERT_VERIFIER_H_ | 5 #ifndef NET_CERT_MULTI_THREADED_CERT_VERIFIER_H_ |
| 6 #define NET_CERT_MULTI_THREADED_CERT_VERIFIER_H_ | 6 #define NET_CERT_MULTI_THREADED_CERT_VERIFIER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 const std::string& ocsp_response, | 63 const std::string& ocsp_response, |
| 64 int flags, | 64 int flags, |
| 65 CRLSet* crl_set, | 65 CRLSet* crl_set, |
| 66 CertVerifyResult* verify_result, | 66 CertVerifyResult* verify_result, |
| 67 const CompletionCallback& callback, | 67 const CompletionCallback& callback, |
| 68 std::unique_ptr<Request>* out_req, | 68 std::unique_ptr<Request>* out_req, |
| 69 const BoundNetLog& net_log) override; | 69 const BoundNetLog& net_log) override; |
| 70 | 70 |
| 71 bool SupportsOCSPStapling() override; | 71 bool SupportsOCSPStapling() override; |
| 72 | 72 |
| 73 // Adds explicitly-specified data to CertVerifierCache. Returns true if | |
| 74 // |cache_| is updated. | |
|
Ryan Sleevi
2016/04/29 23:33:21
This is not a helpful comment, because it provides
ramant (doing other things)
2016/04/30 22:58:11
Many many thanks for the above comments.
Done.
| |
| 75 bool AddCertResult(std::string& hostname, | |
| 76 int flags, | |
| 77 std::vector<SHA1HashValue>& hash_values, | |
| 78 base::Time start_time, | |
| 79 int error, | |
| 80 const CertVerifyResult& result, | |
| 81 base::Time verification_time, | |
| 82 base::Time expiration_time); | |
| 83 | |
| 73 private: | 84 private: |
| 74 struct JobToRequestParamsComparator; | 85 struct JobToRequestParamsComparator; |
| 86 friend class CertVerifierCacheIterator; | |
| 87 friend class CertVerifierCachePersisterTest; | |
| 75 friend class CertVerifierRequest; | 88 friend class CertVerifierRequest; |
| 76 friend class CertVerifierJob; | 89 friend class CertVerifierJob; |
| 77 friend class MultiThreadedCertVerifierTest; | 90 friend class MultiThreadedCertVerifierTest; |
| 78 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, CacheHit); | 91 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, CacheHit); |
| 79 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, DifferentCACerts); | 92 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, DifferentCACerts); |
| 80 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, InflightJoin); | 93 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, InflightJoin); |
| 81 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, MultipleInflightJoin); | 94 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, MultipleInflightJoin); |
| 82 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, CancelRequest); | 95 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, CancelRequest); |
| 83 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, | 96 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, |
| 84 RequestParamsComparators); | 97 RequestParamsComparators); |
| 85 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, | 98 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCertVerifierTest, |
| 86 CertTrustAnchorProvider); | 99 CertTrustAnchorProvider); |
| 100 FRIEND_TEST_ALL_PREFIXES(CertVerifierCachePersisterTest, PersistCache); | |
| 101 FRIEND_TEST_ALL_PREFIXES(CertVerifierCachePersisterTest, | |
| 102 PersistCacheExpiredEntry); | |
|
Ryan Sleevi
2016/04/29 23:33:21
This (and line 87) improperly creates the circular
ramant (doing other things)
2016/04/30 22:58:11
Done.
| |
| 87 | 103 |
| 88 // Input parameters of a certificate verification request. | 104 // Input parameters of a certificate verification request. |
| 89 struct NET_EXPORT_PRIVATE RequestParams { | 105 struct NET_EXPORT_PRIVATE RequestParams { |
| 90 RequestParams(const SHA1HashValue& cert_fingerprint_arg, | 106 RequestParams(const SHA1HashValue& cert_fingerprint_arg, |
| 91 const SHA1HashValue& ca_fingerprint_arg, | 107 const SHA1HashValue& ca_fingerprint_arg, |
| 92 const std::string& hostname_arg, | 108 const std::string& hostname_arg, |
| 93 const std::string& ocsp_response_arg, | 109 const std::string& ocsp_response_arg, |
| 94 int flags_arg, | 110 int flags_arg, |
| 95 const CertificateList& additional_trust_anchors); | 111 const CertificateList& additional_trust_anchors); |
| 96 RequestParams(const RequestParams& other); | 112 RequestParams(const RequestParams& other); |
| 113 RequestParams(std::string& hostname_arg, | |
| 114 int flags_arg, | |
| 115 std::vector<SHA1HashValue>& hash_values_arg, | |
|
Ryan Sleevi
2016/04/29 23:33:21
Don't pass by non-const reference. I realize you d
ramant (doing other things)
2016/04/30 22:58:11
Done.
| |
| 116 base::Time start_time_arg); | |
| 97 ~RequestParams(); | 117 ~RequestParams(); |
| 98 | 118 |
| 99 bool operator<(const RequestParams& other) const; | 119 bool operator<(const RequestParams& other) const; |
| 100 | 120 |
| 101 std::string hostname; | 121 std::string hostname; |
| 102 int flags; | 122 int flags; |
| 103 std::vector<SHA1HashValue> hash_values; | 123 std::vector<SHA1HashValue> hash_values; |
| 104 // The time when verification started. | 124 // The time when verification started. |
| 105 // Note: This uses base::Time, rather than base::TimeTicks, to | 125 // Note: This uses base::Time, rather than base::TimeTicks, to |
| 106 // account for system clock changes. | 126 // account for system clock changes. |
| 107 base::Time start_time; | 127 base::Time start_time; |
| 108 }; | 128 }; |
| 109 | 129 |
| 110 // CachedResult contains the result of a certificate verification. | 130 // CachedResult contains the result of a certificate verification. |
| 111 struct NET_EXPORT_PRIVATE CachedResult { | 131 struct NET_EXPORT_PRIVATE CachedResult { |
| 112 CachedResult(); | 132 CachedResult(); |
| 133 CachedResult(int error_arg, CertVerifyResult result_arg); | |
| 113 ~CachedResult(); | 134 ~CachedResult(); |
| 114 | 135 |
| 115 int error; // The return value of CertVerifier::Verify. | 136 int error; // The return value of CertVerifier::Verify. |
| 116 CertVerifyResult result; // The output of CertVerifier::Verify. | 137 CertVerifyResult result; // The output of CertVerifier::Verify. |
| 117 }; | 138 }; |
| 118 | 139 |
| 119 // Rather than having a single validity point along a monotonically increasing | 140 // Rather than having a single validity point along a monotonically increasing |
| 120 // timeline, certificate verification is based on falling within a range of | 141 // timeline, certificate verification is based on falling within a range of |
| 121 // the certificate's NotBefore and NotAfter and based on what the current | 142 // the certificate's NotBefore and NotAfter and based on what the current |
| 122 // system clock says (which may advance forwards or backwards as users correct | 143 // system clock says (which may advance forwards or backwards as users correct |
| 123 // clock skew). CacheValidityPeriod and CacheExpirationFunctor are helpers to | 144 // clock skew). CacheValidityPeriod and CacheExpirationFunctor are helpers to |
| 124 // ensure that expiration is measured both by the 'general' case (now + cache | 145 // ensure that expiration is measured both by the 'general' case (now + cache |
| 125 // TTL) and by whether or not significant enough clock skew was introduced | 146 // TTL) and by whether or not significant enough clock skew was introduced |
| 126 // since the last verification. | 147 // since the last verification. |
| 127 struct CacheValidityPeriod { | 148 struct NET_EXPORT_PRIVATE CacheValidityPeriod { |
|
Ryan Sleevi
2016/04/29 23:33:21
Why?
ramant (doing other things)
2016/04/30 22:58:11
Deleted them. Changed the tests to test the interf
| |
| 128 explicit CacheValidityPeriod(const base::Time& now); | 149 explicit CacheValidityPeriod(const base::Time& now); |
| 129 CacheValidityPeriod(const base::Time& now, const base::Time& expiration); | 150 CacheValidityPeriod(const base::Time& now, const base::Time& expiration); |
| 130 | 151 |
| 131 base::Time verification_time; | 152 base::Time verification_time; |
| 132 base::Time expiration_time; | 153 base::Time expiration_time; |
| 133 }; | 154 }; |
| 134 | 155 |
| 135 struct CacheExpirationFunctor { | 156 struct NET_EXPORT_PRIVATE CacheExpirationFunctor { |
|
Ryan Sleevi
2016/04/29 23:33:21
Why?
ramant (doing other things)
2016/04/30 22:58:11
Deleted them. Changed the tests to test the interf
| |
| 136 // Returns true iff |now| is within the validity period of |expiration|. | 157 // Returns true iff |now| is within the validity period of |expiration|. |
| 137 bool operator()(const CacheValidityPeriod& now, | 158 bool operator()(const CacheValidityPeriod& now, |
| 138 const CacheValidityPeriod& expiration) const; | 159 const CacheValidityPeriod& expiration) const; |
| 139 }; | 160 }; |
| 140 | 161 |
| 141 struct JobComparator { | 162 struct JobComparator { |
| 142 bool operator()(const CertVerifierJob* job1, | 163 bool operator()(const CertVerifierJob* job1, |
| 143 const CertVerifierJob* job2) const; | 164 const CertVerifierJob* job2) const; |
| 144 }; | 165 }; |
| 145 | 166 |
| 146 using JobSet = std::set<CertVerifierJob*, JobComparator>; | 167 using JobSet = std::set<CertVerifierJob*, JobComparator>; |
| 147 | 168 |
| 148 typedef ExpiringCache<RequestParams, CachedResult, CacheValidityPeriod, | 169 typedef ExpiringCache<RequestParams, |
| 149 CacheExpirationFunctor> CertVerifierCache; | 170 CachedResult, |
| 171 CacheValidityPeriod, | |
| 172 CacheExpirationFunctor> | |
| 173 CertVerifierCache; | |
| 150 | 174 |
| 151 // Saves |result| into the cache, keyed by |key|. | 175 // Saves |result| into the cache, keyed by |key|. |
| 152 void SaveResultToCache(const RequestParams& key, const CachedResult& result); | 176 void SaveResultToCache(const RequestParams& key, const CachedResult& result); |
| 153 | 177 |
| 154 // CertDatabase::Observer methods: | 178 // CertDatabase::Observer methods: |
| 155 void OnCACertChanged(const X509Certificate* cert) override; | 179 void OnCACertChanged(const X509Certificate* cert) override; |
| 156 | 180 |
| 157 // Returns an inflight job for |key|. If there is no such job then returns | 181 // Returns an inflight job for |key|. If there is no such job then returns |
| 158 // null. | 182 // null. |
| 159 CertVerifierJob* FindJob(const RequestParams& key); | 183 CertVerifierJob* FindJob(const RequestParams& key); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 179 uint64_t cache_hits_; | 203 uint64_t cache_hits_; |
| 180 uint64_t inflight_joins_; | 204 uint64_t inflight_joins_; |
| 181 | 205 |
| 182 scoped_refptr<CertVerifyProc> verify_proc_; | 206 scoped_refptr<CertVerifyProc> verify_proc_; |
| 183 | 207 |
| 184 CertTrustAnchorProvider* trust_anchor_provider_; | 208 CertTrustAnchorProvider* trust_anchor_provider_; |
| 185 | 209 |
| 186 DISALLOW_COPY_AND_ASSIGN(MultiThreadedCertVerifier); | 210 DISALLOW_COPY_AND_ASSIGN(MultiThreadedCertVerifier); |
| 187 }; | 211 }; |
| 188 | 212 |
| 213 class NET_EXPORT_PRIVATE CertVerifierCacheIterator { | |
|
Ryan Sleevi
2016/04/29 23:33:21
I suggested several times that this be a member.
ramant (doing other things)
2016/04/30 22:58:11
Sincere apologies. Undid this change.
Was trying
| |
| 214 public: | |
| 215 explicit CertVerifierCacheIterator(const MultiThreadedCertVerifier& verifier); | |
| 216 ~CertVerifierCacheIterator(); | |
| 217 | |
| 218 bool HasNext() const { return iterator_.HasNext(); } | |
| 219 void Advance() { iterator_.Advance(); } | |
| 220 | |
| 221 const std::string& hostname() const { return iterator_.key().hostname; } | |
| 222 int flags() const { return iterator_.key().flags; } | |
| 223 const std::vector<SHA1HashValue>& hash_values() const { | |
| 224 return iterator_.key().hash_values; | |
| 225 } | |
| 226 const base::Time& start_time() const { return iterator_.key().start_time; } | |
| 227 int error() const { return iterator_.value().error; } | |
| 228 const CertVerifyResult& result() const { return iterator_.value().result; } | |
| 229 const base::Time& verification_time() const { | |
| 230 return iterator_.expiration().verification_time; | |
| 231 } | |
| 232 const base::Time& expiration_time() const { | |
| 233 return iterator_.expiration().expiration_time; | |
| 234 } | |
| 235 | |
| 236 private: | |
| 237 MultiThreadedCertVerifier::CertVerifierCache::Iterator iterator_; | |
| 238 | |
| 239 DISALLOW_COPY_AND_ASSIGN(CertVerifierCacheIterator); | |
| 240 }; | |
| 241 | |
| 189 } // namespace net | 242 } // namespace net |
| 190 | 243 |
| 191 #endif // NET_CERT_MULTI_THREADED_CERT_VERIFIER_H_ | 244 #endif // NET_CERT_MULTI_THREADED_CERT_VERIFIER_H_ |
| OLD | NEW |