OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 CHROMEOS_CERT_LOADER_H_ | 5 #ifndef CHROMEOS_CERT_LOADER_H_ |
6 #define CHROMEOS_CERT_LOADER_H_ | 6 #define CHROMEOS_CERT_LOADER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "chromeos/chromeos_export.h" | 17 #include "chromeos/chromeos_export.h" |
18 #include "net/cert/cert_database.h" | 18 #include "net/cert/cert_database.h" |
19 | 19 |
20 namespace base { | |
21 class TaskRunner; | |
emaxx
2017/04/24 21:23:13
nit: Include this header directly, as I believe sc
pmarko
2017/04/25 12:10:02
Removed becuse TaskRunner is not necessary in the
| |
22 } | |
23 | |
20 namespace net { | 24 namespace net { |
21 class NSSCertDatabase; | 25 class NSSCertDatabase; |
22 class X509Certificate; | 26 class X509Certificate; |
23 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; | 27 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; |
24 } | 28 } |
25 | 29 |
26 namespace chromeos { | 30 namespace chromeos { |
27 | 31 |
28 // This class is responsible for loading certificates once the TPM is | 32 // This class is responsible for loading certificates once the TPM is |
29 // initialized. It is expected to be constructed on the UI thread and public | 33 // initialized. It is expected to be constructed on the UI thread and public |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 | 80 |
77 // Returns true if |cert| is hardware backed. See also | 81 // Returns true if |cert| is hardware backed. See also |
78 // ForceHardwareBackedForTesting(). | 82 // ForceHardwareBackedForTesting(). |
79 static bool IsCertificateHardwareBacked(const net::X509Certificate* cert); | 83 static bool IsCertificateHardwareBacked(const net::X509Certificate* cert); |
80 | 84 |
81 // Returns true when the certificate list has been requested but not loaded. | 85 // Returns true when the certificate list has been requested but not loaded. |
82 bool CertificatesLoading() const; | 86 bool CertificatesLoading() const; |
83 | 87 |
84 bool certificates_loaded() const { return certificates_loaded_; } | 88 bool certificates_loaded() const { return certificates_loaded_; } |
85 | 89 |
86 // This will be empty until certificates_loaded() is true. | 90 // Returns all certificates. This will be empty until certificates_loaded() is |
91 // true. | |
87 const net::CertificateList& cert_list() const { return *cert_list_; } | 92 const net::CertificateList& cert_list() const { return *cert_list_; } |
stevenjb
2017/04/24 15:53:59
nit: I'm not sure how much churn this would cause,
pmarko
2017/04/25 12:10:02
Good idea, changed to all_certs+system_certs. Not
| |
88 | 93 |
94 // Returns certificates from the system token. This will be empty until | |
95 // certificates_loaded() is true. | |
96 const net::CertificateList& system_cert_list() const { | |
97 return *system_cert_list_; | |
98 } | |
99 | |
100 // Overrides task runner that's used for running slow tasks. | |
101 void SetSlowTaskRunnerForTest( | |
emaxx
2017/04/24 21:23:13
nit: s/ForTest/ForTesting/ - as that form is used
pmarko
2017/04/25 12:10:02
Done. / Removed because the switch to TaskSchedule
| |
102 const scoped_refptr<base::TaskRunner>& task_runner); | |
103 | |
89 // Called in tests if |IsCertificateHardwareBacked()| should always return | 104 // Called in tests if |IsCertificateHardwareBacked()| should always return |
90 // true. | 105 // true. |
91 static void ForceHardwareBackedForTesting(); | 106 static void ForceHardwareBackedForTesting(); |
92 | 107 |
93 private: | 108 private: |
94 CertLoader(); | 109 CertLoader(); |
95 ~CertLoader() override; | 110 ~CertLoader() override; |
96 | 111 |
97 // Trigger a certificate load. If a certificate loading task is already in | 112 // Trigger a certificate load. If a certificate loading task is already in |
98 // progress, will start a reload once the current task is finished. | 113 // progress, will start a reload once the current task is finished. |
99 void LoadCertificates(); | 114 void LoadCertificates(); |
100 | 115 |
116 // Called when the underlying NSS database finished loading certificates. | |
117 void CertificatesLoaded(std::unique_ptr<net::CertificateList> cert_list); | |
118 | |
101 // Called if a certificate load task is finished. | 119 // Called if a certificate load task is finished. |
102 void UpdateCertificates(std::unique_ptr<net::CertificateList> cert_list); | 120 void UpdateCertificates( |
121 std::unique_ptr<net::CertificateList> cert_list, | |
122 std::unique_ptr<net::CertificateList> system_cert_list); | |
103 | 123 |
104 void NotifyCertificatesLoaded(bool initial_load); | 124 void NotifyCertificatesLoaded(bool initial_load); |
105 | 125 |
106 // net::CertDatabase::Observer | 126 // net::CertDatabase::Observer |
107 void OnCertDBChanged() override; | 127 void OnCertDBChanged() override; |
108 | 128 |
129 // Gets task runner that should be used for potentially slow tasks like | |
130 // certificate filtering. Defaults to a base::WorkerPool runner, but may be | |
131 // overriden in tests (see SetSlowTaskRunnerForTest). | |
132 scoped_refptr<base::TaskRunner> GetSlowTaskRunner() const; | |
133 | |
109 base::ObserverList<Observer> observers_; | 134 base::ObserverList<Observer> observers_; |
110 | 135 |
111 // Flags describing current CertLoader state. | 136 // Flags describing current CertLoader state. |
112 bool certificates_loaded_; | 137 bool certificates_loaded_; |
113 bool certificates_update_required_; | 138 bool certificates_update_required_; |
114 bool certificates_update_running_; | 139 bool certificates_update_running_; |
115 | 140 |
116 // The user-specific NSS certificate database from which the certificates | 141 // The user-specific NSS certificate database from which the certificates |
117 // should be loaded. | 142 // should be loaded. |
118 net::NSSCertDatabase* database_; | 143 net::NSSCertDatabase* database_; |
119 | 144 |
120 // Cached Certificates loaded from the database. | 145 // Cached certificates loaded from the database. |
121 std::unique_ptr<net::CertificateList> cert_list_; | 146 std::unique_ptr<net::CertificateList> cert_list_; |
122 | 147 |
148 // Cached Certifictes from system token. Currently this is a sublist of | |
emaxx
2017/04/24 21:23:13
nit: s/Certifictes/certificates/
pmarko
2017/04/25 12:10:02
Done.
| |
149 // |cert_list_|. | |
150 std::unique_ptr<net::CertificateList> system_cert_list_; | |
151 | |
152 // Task runner that should be used for slow tasks in tests if set. | |
153 scoped_refptr<base::TaskRunner> slow_task_runner_for_test_; | |
154 | |
123 base::ThreadChecker thread_checker_; | 155 base::ThreadChecker thread_checker_; |
124 | 156 |
125 base::WeakPtrFactory<CertLoader> weak_factory_; | 157 base::WeakPtrFactory<CertLoader> weak_factory_; |
126 | 158 |
127 DISALLOW_COPY_AND_ASSIGN(CertLoader); | 159 DISALLOW_COPY_AND_ASSIGN(CertLoader); |
128 }; | 160 }; |
129 | 161 |
130 } // namespace chromeos | 162 } // namespace chromeos |
131 | 163 |
132 #endif // CHROMEOS_CERT_LOADER_H_ | 164 #endif // CHROMEOS_CERT_LOADER_H_ |
OLD | NEW |