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

Side by Side Diff: net/cert/caching_cert_verifier.h

Issue 2070223002: Remove CertTrustAnchorProvider from net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
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"
11 #include "net/base/net_export.h" 11 #include "net/base/net_export.h"
12 #include "net/cert/cert_database.h" 12 #include "net/cert/cert_database.h"
13 #include "net/cert/cert_verifier.h" 13 #include "net/cert/cert_verifier.h"
14 #include "net/cert/cert_verify_result.h" 14 #include "net/cert/cert_verify_result.h"
15 15
16 namespace net { 16 namespace net {
17 17
18 class CertTrustAnchorProvider;
19
20 // CertVerifier that caches the results of certificate verifications. 18 // CertVerifier that caches the results of certificate verifications.
21 // 19 //
22 // In general, certificate verification results will vary on only three 20 // In general, certificate verification results will vary on only three
23 // parameters: 21 // parameters:
24 // - The time of validation (as certificates are only valid for a period of 22 // - The time of validation (as certificates are only valid for a period of
25 // time) 23 // time)
26 // - The revocation status (a certificate may be revoked at any time, but 24 // - The revocation status (a certificate may be revoked at any time, but
27 // revocation statuses themselves have validity period, so a 'good' result 25 // revocation statuses themselves have validity period, so a 'good' result
28 // may be reused for a period of time) 26 // may be reused for a period of time)
29 // - The trust settings (a user may change trust settings at any time) 27 // - The trust settings (a user may change trust settings at any time)
30 // 28 //
31 // This class tries to optimize by allowing certificate verification results 29 // This class tries to optimize by allowing certificate verification results
32 // to be cached for a limited amount of time (presently, 30 minutes), which 30 // 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 31 // tries to balance the implementation complexity of needing to monitor the
34 // above for meaningful changes and the practical utility of being able to 32 // above for meaningful changes and the practical utility of being able to
35 // cache results when they're not expected to change. 33 // cache results when they're not expected to change.
36 class NET_EXPORT CachingCertVerifier : public CertVerifier, 34 class NET_EXPORT CachingCertVerifier : public CertVerifier,
37 public CertDatabase::Observer { 35 public CertDatabase::Observer {
38 public: 36 public:
39 // Creates a CachingCertVerifier that will use |verifier| to perform the 37 // Creates a CachingCertVerifier that will use |verifier| to perform the
40 // actual verifications if they're not already cached or if the cached 38 // actual verifications if they're not already cached or if the cached
41 // item has expired. 39 // item has expired.
42 explicit CachingCertVerifier(std::unique_ptr<CertVerifier> verifier); 40 explicit CachingCertVerifier(std::unique_ptr<CertVerifier> verifier);
43 41
44 ~CachingCertVerifier() override; 42 ~CachingCertVerifier() override;
45 43
46 // Configures a source of additional certificates that should be treated as
47 // trust anchors during verification, provided that the underlying
48 // CertVerifyProc supports additional trust beyond the default implementation.
49 // It must outlive the CachingCertVerifier.
50 void SetCertTrustAnchorProvider(
51 CertTrustAnchorProvider* trust_anchor_provider);
52
53 // CertVerifier implementation: 44 // CertVerifier implementation:
54 int Verify(const RequestParams& params, 45 int Verify(const RequestParams& params,
55 CRLSet* crl_set, 46 CRLSet* crl_set,
56 CertVerifyResult* verify_result, 47 CertVerifyResult* verify_result,
57 const CompletionCallback& callback, 48 const CompletionCallback& callback,
58 std::unique_ptr<Request>* out_req, 49 std::unique_ptr<Request>* out_req,
59 const BoundNetLog& net_log) override; 50 const BoundNetLog& net_log) override;
60 bool SupportsOCSPStapling() override; 51 bool SupportsOCSPStapling() override;
61 52
62 private: 53 private:
63 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, CacheHit); 54 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, CacheHit);
64 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, DifferentCACerts); 55 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, DifferentCACerts);
65 FRIEND_TEST_ALL_PREFIXES(CachingCertVerifierTest, CertTrustAnchorProvider);
66 56
67 // CachedResult contains the result of a certificate verification. 57 // CachedResult contains the result of a certificate verification.
68 struct NET_EXPORT_PRIVATE CachedResult { 58 struct NET_EXPORT_PRIVATE CachedResult {
69 CachedResult(); 59 CachedResult();
70 ~CachedResult(); 60 ~CachedResult();
71 61
72 int error; // The return value of CertVerifier::Verify. 62 int error; // The return value of CertVerifier::Verify.
73 CertVerifyResult result; // The output of CertVerifier::Verify. 63 CertVerifyResult result; // The output of CertVerifier::Verify.
74 }; 64 };
75 65
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 void OnCACertChanged(const X509Certificate* cert) override; 111 void OnCACertChanged(const X509Certificate* cert) override;
122 112
123 // For unit testing. 113 // For unit testing.
124 void ClearCache(); 114 void ClearCache();
125 size_t GetCacheSize() const; 115 size_t GetCacheSize() const;
126 uint64_t cache_hits() const { return cache_hits_; } 116 uint64_t cache_hits() const { return cache_hits_; }
127 uint64_t requests() const { return requests_; } 117 uint64_t requests() const { return requests_; }
128 118
129 std::unique_ptr<CertVerifier> verifier_; 119 std::unique_ptr<CertVerifier> verifier_;
130 120
131 CertTrustAnchorProvider* trust_anchor_provider_;
132
133 CertVerificationCache cache_; 121 CertVerificationCache cache_;
134 122
135 uint64_t requests_; 123 uint64_t requests_;
136 uint64_t cache_hits_; 124 uint64_t cache_hits_;
137 125
138 DISALLOW_COPY_AND_ASSIGN(CachingCertVerifier); 126 DISALLOW_COPY_AND_ASSIGN(CachingCertVerifier);
139 }; 127 };
140 128
141 } // namespace net 129 } // namespace net
142 130
143 #endif // NET_CERT_CACHING_CERT_VERIFIER_H_ 131 #endif // NET_CERT_CACHING_CERT_VERIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698