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_NSS_CERT_DATABASE_H_ | 5 #ifndef NET_CERT_NSS_CERT_DATABASE_H_ |
6 #define NET_CERT_NSS_CERT_DATABASE_H_ | 6 #define NET_CERT_NSS_CERT_DATABASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 class TaskRunner; | 24 class TaskRunner; |
25 } | 25 } |
26 template <class ObserverType> class ObserverListThreadSafe; | 26 template <class ObserverType> class ObserverListThreadSafe; |
27 | 27 |
28 namespace net { | 28 namespace net { |
29 | 29 |
30 class CryptoModule; | 30 class CryptoModule; |
31 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; | 31 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; |
32 | 32 |
33 // Provides functions to manipulate the NSS certificate stores. | 33 // Provides functions to manipulate the NSS certificate stores. |
| 34 // Forwards notifications about certificate changes to the global CertDatabase |
| 35 // singleton. |
34 class NET_EXPORT NSSCertDatabase { | 36 class NET_EXPORT NSSCertDatabase { |
35 public: | 37 public: |
36 | 38 |
37 class NET_EXPORT Observer { | 39 class NET_EXPORT Observer { |
38 public: | 40 public: |
39 virtual ~Observer() {} | 41 virtual ~Observer() {} |
40 | 42 |
41 // Will be called when a new certificate is added. | 43 // Will be called when a new certificate is added. |
42 // Called with |cert| == NULL after importing a list of certificates | 44 // Called with |cert| == NULL after importing a list of certificates |
43 // in ImportFromPKCS12(). | 45 // in ImportFromPKCS12(). |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // thread. Never calls |callback| synchronously. | 220 // thread. Never calls |callback| synchronously. |
219 void DeleteCertAndKeyAsync(const scoped_refptr<X509Certificate>& cert, | 221 void DeleteCertAndKeyAsync(const scoped_refptr<X509Certificate>& cert, |
220 const DeleteCertCallback& callback); | 222 const DeleteCertCallback& callback); |
221 | 223 |
222 // Check whether cert is stored in a readonly slot. | 224 // Check whether cert is stored in a readonly slot. |
223 bool IsReadOnly(const X509Certificate* cert) const; | 225 bool IsReadOnly(const X509Certificate* cert) const; |
224 | 226 |
225 // Check whether cert is stored in a hardware slot. | 227 // Check whether cert is stored in a hardware slot. |
226 bool IsHardwareBacked(const X509Certificate* cert) const; | 228 bool IsHardwareBacked(const X509Certificate* cert) const; |
227 | 229 |
228 // Registers |observer| to receive notifications of certificate changes. The | |
229 // thread on which this is called is the thread on which |observer| will be | |
230 // called back with notifications. | |
231 // NOTE: CertDatabase::AddObserver should be preferred. Observers registered | |
232 // here will only receive notifications generated directly through the | |
233 // NSSCertDatabase, but not those from the CertDatabase. The CertDatabase | |
234 // observers will receive both. | |
235 void AddObserver(Observer* observer); | |
236 | |
237 // Unregisters |observer| from receiving notifications. This must be called | |
238 // on the same thread on which AddObserver() was called. | |
239 void RemoveObserver(Observer* observer); | |
240 | |
241 // Overrides task runner that's used for running slow tasks. | 230 // Overrides task runner that's used for running slow tasks. |
242 void SetSlowTaskRunnerForTest( | 231 void SetSlowTaskRunnerForTest( |
243 const scoped_refptr<base::TaskRunner>& task_runner); | 232 const scoped_refptr<base::TaskRunner>& task_runner); |
244 | 233 |
245 protected: | 234 protected: |
246 NSSCertDatabase(); | 235 NSSCertDatabase(); |
247 virtual ~NSSCertDatabase(); | 236 virtual ~NSSCertDatabase(); |
248 | 237 |
249 // Certificate listing implementation used by |ListCerts*| and | 238 // Certificate listing implementation used by |ListCerts*| and |
250 // |ListCertsSync|. Static so it may safely be used on the worker thread. | 239 // |ListCertsSync|. Static so it may safely be used on the worker thread. |
251 // If |slot| is NULL, obtains the certs of all slots, otherwise only of | 240 // If |slot| is NULL, obtains the certs of all slots, otherwise only of |
252 // |slot|. | 241 // |slot|. |
253 static void ListCertsImpl(crypto::ScopedPK11Slot slot, | 242 static void ListCertsImpl(crypto::ScopedPK11Slot slot, |
254 CertificateList* certs); | 243 CertificateList* certs); |
255 | 244 |
256 // Gets task runner that should be used for slow tasks like certificate | 245 // Gets task runner that should be used for slow tasks like certificate |
257 // listing. Defaults to a base::WorkerPool runner, but may be overriden | 246 // listing. Defaults to a base::WorkerPool runner, but may be overriden |
258 // in tests (see SetSlowTaskRunnerForTest). | 247 // in tests (see SetSlowTaskRunnerForTest). |
259 scoped_refptr<base::TaskRunner> GetSlowTaskRunner() const; | 248 scoped_refptr<base::TaskRunner> GetSlowTaskRunner() const; |
260 | 249 |
261 private: | 250 private: |
262 friend struct base::DefaultLazyInstanceTraits<NSSCertDatabase>; | 251 friend struct base::DefaultLazyInstanceTraits<NSSCertDatabase>; |
263 | 252 |
| 253 // Registers |observer| to receive notifications of certificate changes. The |
| 254 // thread on which this is called is the thread on which |observer| will be |
| 255 // called back with notifications. |
| 256 // NOTE: Observers registered here will only receive notifications generated |
| 257 // directly through the NSSCertDatabase, but not those from the CertDatabase. |
| 258 // CertDatabase observers will receive all certificate notifications. |
| 259 void AddObserver(Observer* observer); |
| 260 |
| 261 // Unregisters |observer| from receiving notifications. This must be called |
| 262 // on the same thread on which AddObserver() was called. |
| 263 void RemoveObserver(Observer* observer); |
| 264 |
264 // Notifies observers of the removal of |cert| and calls |callback| with | 265 // Notifies observers of the removal of |cert| and calls |callback| with |
265 // |success| as argument. | 266 // |success| as argument. |
266 void NotifyCertRemovalAndCallBack(scoped_refptr<X509Certificate> cert, | 267 void NotifyCertRemovalAndCallBack(scoped_refptr<X509Certificate> cert, |
267 const DeleteCertCallback& callback, | 268 const DeleteCertCallback& callback, |
268 bool success); | 269 bool success); |
269 | 270 |
270 // Broadcasts notifications to all registered observers. | 271 // Broadcasts notifications to all registered observers. |
271 void NotifyObserversOfCertAdded(const X509Certificate* cert); | 272 void NotifyObserversOfCertAdded(const X509Certificate* cert); |
272 void NotifyObserversOfCertRemoved(const X509Certificate* cert); | 273 void NotifyObserversOfCertRemoved(const X509Certificate* cert); |
273 void NotifyObserversOfCACertChanged(const X509Certificate* cert); | 274 void NotifyObserversOfCACertChanged(const X509Certificate* cert); |
274 | 275 |
275 // Certificate removal implementation used by |DeleteCertAndKey*|. Static so | 276 // Certificate removal implementation used by |DeleteCertAndKey*|. Static so |
276 // it may safely be used on the worker thread. | 277 // it may safely be used on the worker thread. |
277 static bool DeleteCertAndKeyImpl(scoped_refptr<X509Certificate> cert); | 278 static bool DeleteCertAndKeyImpl(scoped_refptr<X509Certificate> cert); |
278 | 279 |
| 280 // A helper observer that forwards events from this database to CertDatabase. |
| 281 scoped_ptr<Observer> cert_notification_forwarder_; |
| 282 |
279 // Task runner that should be used in tests if set. | 283 // Task runner that should be used in tests if set. |
280 scoped_refptr<base::TaskRunner> slow_task_runner_for_test_; | 284 scoped_refptr<base::TaskRunner> slow_task_runner_for_test_; |
281 | 285 |
282 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; | 286 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; |
283 | 287 |
284 base::WeakPtrFactory<NSSCertDatabase> weak_factory_; | 288 base::WeakPtrFactory<NSSCertDatabase> weak_factory_; |
285 | 289 |
286 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); | 290 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); |
287 }; | 291 }; |
288 | 292 |
289 } // namespace net | 293 } // namespace net |
290 | 294 |
291 #endif // NET_CERT_NSS_CERT_DATABASE_H_ | 295 #endif // NET_CERT_NSS_CERT_DATABASE_H_ |
OLD | NEW |