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_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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.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/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "crypto/scoped_nss_types.h" | 16 #include "crypto/scoped_nss_types.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
| 19 #include "net/cert/cert_type.h" | 19 #include "net/cert/cert_type.h" |
| 20 #include "net/cert/x509_certificate.h" | 20 #include "net/cert/x509_certificate.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 template <typename T> struct DefaultLazyInstanceTraits; | |
| 24 class TaskRunner; | 23 class TaskRunner; |
| 25 } | 24 } |
| 26 template <class ObserverType> class ObserverListThreadSafe; | 25 template <class ObserverType> class ObserverListThreadSafe; |
| 27 | 26 |
| 28 namespace net { | 27 namespace net { |
| 29 | 28 |
| 30 class CryptoModule; | 29 class CryptoModule; |
| 31 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; | 30 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; |
| 32 | 31 |
| 33 // Provides functions to manipulate the NSS certificate stores. | 32 // Provides functions to manipulate the NSS certificate stores. |
| 34 // Forwards notifications about certificate changes to the global CertDatabase | 33 // Forwards notifications about certificate changes to the global CertDatabase |
| 35 // singleton. | 34 // singleton. |
| 36 class NET_EXPORT NSSCertDatabase { | 35 class NET_EXPORT NSSCertDatabase { |
| 37 public: | 36 public: |
| 38 | |
| 39 class NET_EXPORT Observer { | 37 class NET_EXPORT Observer { |
| 40 public: | 38 public: |
| 41 virtual ~Observer() {} | 39 virtual ~Observer() {} |
| 42 | 40 |
| 43 // Will be called when a new certificate is added. | 41 // Will be called when a new certificate is added. |
| 44 // Called with |cert| == NULL after importing a list of certificates | 42 // Called with |cert| == NULL after importing a list of certificates |
| 45 // in ImportFromPKCS12(). | 43 // in ImportFromPKCS12(). |
| 46 virtual void OnCertAdded(const X509Certificate* cert) {} | 44 virtual void OnCertAdded(const X509Certificate* cert) {} |
| 47 | 45 |
| 48 // Will be called when a certificate is removed. | 46 // Will be called when a certificate is removed. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 DISTRUSTED_SSL = 1 << 3, | 93 DISTRUSTED_SSL = 1 << 3, |
| 96 DISTRUSTED_EMAIL = 1 << 4, | 94 DISTRUSTED_EMAIL = 1 << 4, |
| 97 DISTRUSTED_OBJ_SIGN = 1 << 5, | 95 DISTRUSTED_OBJ_SIGN = 1 << 5, |
| 98 }; | 96 }; |
| 99 | 97 |
| 100 typedef base::Callback<void(scoped_ptr<CertificateList> certs)> | 98 typedef base::Callback<void(scoped_ptr<CertificateList> certs)> |
| 101 ListCertsCallback; | 99 ListCertsCallback; |
| 102 | 100 |
| 103 typedef base::Callback<void(bool)> DeleteCertCallback; | 101 typedef base::Callback<void(bool)> DeleteCertCallback; |
| 104 | 102 |
| 105 // DEPRECATED: See http://crbug.com/329735. | 103 // Only exposed publicly for use in tests. Otherwise use the getter from |
| 106 static NSSCertDatabase* GetInstance(); | 104 // nss_context.h. |
|
Ryan Sleevi
2014/07/22 01:18:32
Any chance of hiding this for future tests, and fr
pneubeck (no reviews)
2014/07/22 08:23:56
I'd punt such a change into a separate CL and it s
| |
| 105 explicit NSSCertDatabase(crypto::ScopedPK11Slot persistent_slot); | |
| 106 virtual ~NSSCertDatabase(); | |
| 107 | 107 |
| 108 // Get a list of unique certificates in the certificate database (one | 108 // Get a list of unique certificates in the certificate database (one |
| 109 // instance of all certificates). | 109 // instance of all certificates). |
| 110 // DEPRECATED by |ListCerts|. See http://crbug.com/340460. | 110 // DEPRECATED by |ListCerts|. See http://crbug.com/340460. |
| 111 virtual void ListCertsSync(CertificateList* certs); | 111 virtual void ListCertsSync(CertificateList* certs); |
| 112 | 112 |
| 113 // Asynchronously get a list of unique certificates in the certificate | 113 // Asynchronously get a list of unique certificates in the certificate |
| 114 // database (one instance of all certificates). Note that the callback may be | 114 // database (one instance of all certificates). Note that the callback may be |
| 115 // run even after the database is deleted. | 115 // run even after the database is deleted. |
| 116 virtual void ListCerts(const ListCertsCallback& callback); | 116 virtual void ListCerts(const ListCertsCallback& callback); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 bool IsReadOnly(const X509Certificate* cert) const; | 225 bool IsReadOnly(const X509Certificate* cert) const; |
| 226 | 226 |
| 227 // Check whether cert is stored in a hardware slot. | 227 // Check whether cert is stored in a hardware slot. |
| 228 bool IsHardwareBacked(const X509Certificate* cert) const; | 228 bool IsHardwareBacked(const X509Certificate* cert) const; |
| 229 | 229 |
| 230 // Overrides task runner that's used for running slow tasks. | 230 // Overrides task runner that's used for running slow tasks. |
| 231 void SetSlowTaskRunnerForTest( | 231 void SetSlowTaskRunnerForTest( |
| 232 const scoped_refptr<base::TaskRunner>& task_runner); | 232 const scoped_refptr<base::TaskRunner>& task_runner); |
| 233 | 233 |
| 234 protected: | 234 protected: |
| 235 NSSCertDatabase(); | |
| 236 virtual ~NSSCertDatabase(); | |
| 237 | |
| 238 // Certificate listing implementation used by |ListCerts*| and | 235 // Certificate listing implementation used by |ListCerts*| and |
| 239 // |ListCertsSync|. Static so it may safely be used on the worker thread. | 236 // |ListCertsSync|. Static so it may safely be used on the worker thread. |
| 240 // If |slot| is NULL, obtains the certs of all slots, otherwise only of | 237 // If |slot| is NULL, obtains the certs of all slots, otherwise only of |
| 241 // |slot|. | 238 // |slot|. |
| 242 static void ListCertsImpl(crypto::ScopedPK11Slot slot, | 239 static void ListCertsImpl(crypto::ScopedPK11Slot slot, |
| 243 CertificateList* certs); | 240 CertificateList* certs); |
| 244 | 241 |
| 245 // Gets task runner that should be used for slow tasks like certificate | 242 // Gets task runner that should be used for slow tasks like certificate |
| 246 // listing. Defaults to a base::WorkerPool runner, but may be overriden | 243 // listing. Defaults to a base::WorkerPool runner, but may be overriden |
| 247 // in tests (see SetSlowTaskRunnerForTest). | 244 // in tests (see SetSlowTaskRunnerForTest). |
| 248 scoped_refptr<base::TaskRunner> GetSlowTaskRunner() const; | 245 scoped_refptr<base::TaskRunner> GetSlowTaskRunner() const; |
| 249 | 246 |
| 250 private: | 247 private: |
| 251 friend struct base::DefaultLazyInstanceTraits<NSSCertDatabase>; | |
| 252 | |
| 253 // Registers |observer| to receive notifications of certificate changes. The | 248 // Registers |observer| to receive notifications of certificate changes. The |
| 254 // thread on which this is called is the thread on which |observer| will be | 249 // thread on which this is called is the thread on which |observer| will be |
| 255 // called back with notifications. | 250 // called back with notifications. |
| 256 // NOTE: Observers registered here will only receive notifications generated | 251 // NOTE: Observers registered here will only receive notifications generated |
| 257 // directly through the NSSCertDatabase, but not those from the CertDatabase. | 252 // directly through the NSSCertDatabase, but not those from the CertDatabase. |
| 258 // CertDatabase observers will receive all certificate notifications. | 253 // CertDatabase observers will receive all certificate notifications. |
| 259 void AddObserver(Observer* observer); | 254 void AddObserver(Observer* observer); |
| 260 | 255 |
| 261 // Unregisters |observer| from receiving notifications. This must be called | 256 // Unregisters |observer| from receiving notifications. This must be called |
| 262 // on the same thread on which AddObserver() was called. | 257 // on the same thread on which AddObserver() was called. |
| 263 void RemoveObserver(Observer* observer); | 258 void RemoveObserver(Observer* observer); |
| 264 | 259 |
| 265 // Notifies observers of the removal of |cert| and calls |callback| with | 260 // Notifies observers of the removal of |cert| and calls |callback| with |
| 266 // |success| as argument. | 261 // |success| as argument. |
| 267 void NotifyCertRemovalAndCallBack(scoped_refptr<X509Certificate> cert, | 262 void NotifyCertRemovalAndCallBack(scoped_refptr<X509Certificate> cert, |
| 268 const DeleteCertCallback& callback, | 263 const DeleteCertCallback& callback, |
| 269 bool success); | 264 bool success); |
| 270 | 265 |
| 271 // Broadcasts notifications to all registered observers. | 266 // Broadcasts notifications to all registered observers. |
| 272 void NotifyObserversOfCertAdded(const X509Certificate* cert); | 267 void NotifyObserversOfCertAdded(const X509Certificate* cert); |
| 273 void NotifyObserversOfCertRemoved(const X509Certificate* cert); | 268 void NotifyObserversOfCertRemoved(const X509Certificate* cert); |
| 274 void NotifyObserversOfCACertChanged(const X509Certificate* cert); | 269 void NotifyObserversOfCACertChanged(const X509Certificate* cert); |
| 275 | 270 |
| 276 // Certificate removal implementation used by |DeleteCertAndKey*|. Static so | 271 // Certificate removal implementation used by |DeleteCertAndKey*|. Static so |
| 277 // it may safely be used on the worker thread. | 272 // it may safely be used on the worker thread. |
| 278 static bool DeleteCertAndKeyImpl(scoped_refptr<X509Certificate> cert); | 273 static bool DeleteCertAndKeyImpl(scoped_refptr<X509Certificate> cert); |
| 279 | 274 |
| 275 crypto::ScopedPK11Slot persistent_slot_; | |
| 276 | |
| 280 // A helper observer that forwards events from this database to CertDatabase. | 277 // A helper observer that forwards events from this database to CertDatabase. |
| 281 scoped_ptr<Observer> cert_notification_forwarder_; | 278 scoped_ptr<Observer> cert_notification_forwarder_; |
| 282 | 279 |
| 283 // Task runner that should be used in tests if set. | 280 // Task runner that should be used in tests if set. |
| 284 scoped_refptr<base::TaskRunner> slow_task_runner_for_test_; | 281 scoped_refptr<base::TaskRunner> slow_task_runner_for_test_; |
| 285 | 282 |
| 286 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; | 283 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; |
| 287 | 284 |
| 288 base::WeakPtrFactory<NSSCertDatabase> weak_factory_; | 285 base::WeakPtrFactory<NSSCertDatabase> weak_factory_; |
| 289 | 286 |
| 290 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); | 287 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); |
| 291 }; | 288 }; |
| 292 | 289 |
| 293 } // namespace net | 290 } // namespace net |
| 294 | 291 |
| 295 #endif // NET_CERT_NSS_CERT_DATABASE_H_ | 292 #endif // NET_CERT_NSS_CERT_DATABASE_H_ |
| OLD | NEW |