Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_CACHING_CERT_VERIFIER_H_ | 5 #ifndef NET_CERT_CACHING_CERT_VERIFIER_H_ |
| 6 #define NET_CERT_CACHING_CERT_VERIFIER_H_ | 6 #define NET_CERT_CACHING_CERT_VERIFIER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "net/base/expiring_cache.h" | 10 #include "net/base/expiring_cache.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 // - The trust settings (a user may change trust settings at any time) | 29 // - The trust settings (a user may change trust settings at any time) |
| 30 // | 30 // |
| 31 // This class tries to optimize by allowing certificate verification results | 31 // This class tries to optimize by allowing certificate verification results |
| 32 // to be cached for a limited amount of time (presently, 30 minutes), which | 32 // to be cached for a limited amount of time (presently, 30 minutes), which |
| 33 // tries to balance the implementation complexity of needing to monitor the | 33 // tries to balance the implementation complexity of needing to monitor the |
| 34 // above for meaningful changes and the practical utility of being able to | 34 // above for meaningful changes and the practical utility of being able to |
| 35 // cache results when they're not expected to change. | 35 // cache results when they're not expected to change. |
| 36 class NET_EXPORT CachingCertVerifier : public CertVerifier, | 36 class NET_EXPORT CachingCertVerifier : public CertVerifier, |
| 37 public CertDatabase::Observer { | 37 public CertDatabase::Observer { |
| 38 public: | 38 public: |
| 39 // Visitor class to allow read-only inspection of the verification cache. | |
|
eroman
2016/06/16 00:25:04
optional: Either here or in VisitEntries() mention
| |
| 40 class NET_EXPORT CacheVisitor { | |
| 41 public: | |
| 42 virtual ~CacheVisitor() {} | |
|
eroman
2016/06/16 00:25:04
optional: Move to an out-of-line dtor in .cc file,
| |
| 43 | |
| 44 // Called once for each entry in the cache, providing details about the | |
| 45 // cached entry. | |
| 46 // Returns true to continue iteration, or false to abort. | |
| 47 virtual bool VisitEntry(const RequestParams& params, | |
|
eroman
2016/06/16 00:25:04
optional: Name this VisitCertificateCacheEntry().
Ryan Sleevi
2016/06/16 00:44:34
I'm pretty anti-smashing of pure interfaces :)
| |
| 48 int error, | |
| 49 const CertVerifyResult& verify_result, | |
| 50 base::Time verification_time, | |
| 51 base::Time expiration_time) = 0; | |
| 52 }; | |
| 53 | |
| 39 // Creates a CachingCertVerifier that will use |verifier| to perform the | 54 // Creates a CachingCertVerifier that will use |verifier| to perform the |
| 40 // actual verifications if they're not already cached or if the cached | 55 // actual verifications if they're not already cached or if the cached |
| 41 // item has expired. | 56 // item has expired. |
| 42 explicit CachingCertVerifier(std::unique_ptr<CertVerifier> verifier); | 57 explicit CachingCertVerifier(std::unique_ptr<CertVerifier> verifier); |
| 43 | 58 |
| 44 ~CachingCertVerifier() override; | 59 ~CachingCertVerifier() override; |
| 45 | 60 |
| 46 // Configures a source of additional certificates that should be treated as | 61 // Configures a source of additional certificates that should be treated as |
| 47 // trust anchors during verification, provided that the underlying | 62 // trust anchors during verification, provided that the underlying |
| 48 // CertVerifyProc supports additional trust beyond the default implementation. | 63 // CertVerifyProc supports additional trust beyond the default implementation. |
| 49 // It must outlive the CachingCertVerifier. | 64 // It must outlive the CachingCertVerifier. |
| 50 void SetCertTrustAnchorProvider( | 65 void SetCertTrustAnchorProvider( |
| 51 CertTrustAnchorProvider* trust_anchor_provider); | 66 CertTrustAnchorProvider* trust_anchor_provider); |
| 52 | 67 |
| 53 // CertVerifier implementation: | 68 // CertVerifier implementation: |
| 54 int Verify(const RequestParams& params, | 69 int Verify(const RequestParams& params, |
| 55 CRLSet* crl_set, | 70 CRLSet* crl_set, |
| 56 CertVerifyResult* verify_result, | 71 CertVerifyResult* verify_result, |
| 57 const CompletionCallback& callback, | 72 const CompletionCallback& callback, |
| 58 std::unique_ptr<Request>* out_req, | 73 std::unique_ptr<Request>* out_req, |
| 59 const BoundNetLog& net_log) override; | 74 const BoundNetLog& net_log) override; |
| 60 bool SupportsOCSPStapling() override; | 75 bool SupportsOCSPStapling() override; |
| 61 | 76 |
| 77 // Opportunistically attempts to add |error| and |verify_result| as the | |
| 78 // result for |params|, which was obtained at |verification_time| and | |
| 79 // expires at |expiration_time|. | |
| 80 // This is opportunistic because it is not guaranteed that the entry | |
| 81 // will be added (such as if the cache is full or an entry already | |
| 82 // exists). | |
| 83 bool AddEntry(const RequestParams& params, | |
| 84 int error, | |
| 85 const CertVerifyResult& verify_result, | |
| 86 base::Time verification_time); | |
| 87 | |
| 88 // Iterates through all of the non-expired entries in the cache, calling | |
| 89 // VisitEntry on |visitor| for each, until either all entries are | |
| 90 // iterated through or the |visitor| aborts. | |
| 91 void VisitEntries(CacheVisitor* visitor); | |
|
eroman
2016/06/16 00:25:04
Can this method be "const" ?
Ryan Sleevi
2016/06/16 00:44:34
I saw no reason to impose that contract on impleme
eroman
2016/06/16 00:54:51
I think you misunderstood. What I am asking for is
| |
| 92 | |
| 62 private: | 93 private: |
| 94 friend class CacheVisitor; | |
|
eroman
2016/06/16 00:25:04
Is this needed?
Ryan Sleevi
2016/06/16 00:44:34
Nope
| |
| 63 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, CacheHit); | 95 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, CacheHit); |
| 96 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, Visitor); | |
| 97 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, AddsEntries); | |
| 64 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, DifferentCACerts); | 98 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, DifferentCACerts); |
| 65 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, CertTrustAnchorProvider); | 99 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, CertTrustAnchorProvider); |
| 66 | 100 |
| 67 // CachedResult contains the result of a certificate verification. | 101 // CachedResult contains the result of a certificate verification. |
| 68 struct NET_EXPORT_PRIVATE CachedResult { | 102 struct NET_EXPORT_PRIVATE CachedResult { |
| 69 CachedResult(); | 103 CachedResult(); |
| 70 ~CachedResult(); | 104 ~CachedResult(); |
| 71 | 105 |
| 72 int error; // The return value of CertVerifier::Verify. | 106 int error; // The return value of CertVerifier::Verify. |
| 73 CertVerifyResult result; // The output of CertVerifier::Verify. | 107 CertVerifyResult result; // The output of CertVerifier::Verify. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 | 168 |
| 135 uint64_t requests_; | 169 uint64_t requests_; |
| 136 uint64_t cache_hits_; | 170 uint64_t cache_hits_; |
| 137 | 171 |
| 138 DISALLOW_COPY_AND_ASSIGN(CachingCertVerifier); | 172 DISALLOW_COPY_AND_ASSIGN(CachingCertVerifier); |
| 139 }; | 173 }; |
| 140 | 174 |
| 141 } // namespace net | 175 } // namespace net |
| 142 | 176 |
| 143 #endif // NET_CERT_CACHING_CERT_VERIFIER_H_ | 177 #endif // NET_CERT_CACHING_CERT_VERIFIER_H_ |
| OLD | NEW |