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/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 14 #include "crypto/scoped_nss_types.h" | 15 #include "crypto/scoped_nss_types.h" |
| 15 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 16 #include "net/cert/cert_type.h" | 17 #include "net/cert/cert_type.h" |
| 18 #include "net/cert/nss_database_filter.h" | |
| 17 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
| 18 | 20 |
| 19 namespace base { | 21 namespace base { |
| 20 template <typename T> struct DefaultLazyInstanceTraits; | 22 template <typename T> struct DefaultLazyInstanceTraits; |
| 23 class TaskRunner; | |
| 21 } | 24 } |
| 22 template <class ObserverType> class ObserverListThreadSafe; | 25 template <class ObserverType> class ObserverListThreadSafe; |
| 23 | 26 |
| 24 namespace net { | 27 namespace net { |
| 25 | 28 |
| 26 class CryptoModule; | 29 class CryptoModule; |
| 27 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; | 30 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; |
| 28 | 31 |
| 29 // Provides functions to manipulate the NSS certificate stores. | 32 // Provides functions to manipulate the NSS certificate stores. |
| 30 class NET_EXPORT NSSCertDatabase { | 33 class NET_EXPORT NSSCertDatabase { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 DISTRUSTED_SSL = 1 << 3, | 92 DISTRUSTED_SSL = 1 << 3, |
| 90 DISTRUSTED_EMAIL = 1 << 4, | 93 DISTRUSTED_EMAIL = 1 << 4, |
| 91 DISTRUSTED_OBJ_SIGN = 1 << 5, | 94 DISTRUSTED_OBJ_SIGN = 1 << 5, |
| 92 }; | 95 }; |
| 93 | 96 |
| 94 // DEPRECATED: See http://crbug.com/329735. | 97 // DEPRECATED: See http://crbug.com/329735. |
| 95 static NSSCertDatabase* GetInstance(); | 98 static NSSCertDatabase* GetInstance(); |
| 96 | 99 |
| 97 // Get a list of unique certificates in the certificate database (one | 100 // Get a list of unique certificates in the certificate database (one |
| 98 // instance of all certificates). | 101 // instance of all certificates). |
| 99 virtual void ListCerts(CertificateList* certs); | 102 // DEPRECATED: Use ListCerts instead. |
| 103 void ListCertsSync(CertificateList* certs); | |
| 104 | |
| 105 // Asynchronously get a list of unique certificates in the certificate | |
| 106 // database (one instance of all certificates). | |
| 107 typedef base::Callback<void(scoped_ptr<CertificateList> certs)> | |
| 108 ListCertsCallback; | |
| 109 void ListCerts(const ListCertsCallback& callback); | |
| 100 | 110 |
| 101 // Get the default slot for public key data. | 111 // Get the default slot for public key data. |
| 102 virtual crypto::ScopedPK11Slot GetPublicSlot() const; | 112 virtual crypto::ScopedPK11Slot GetPublicSlot() const; |
| 103 | 113 |
| 104 // Get the default slot for private key or mixed private/public key data. | 114 // Get the default slot for private key or mixed private/public key data. |
| 105 virtual crypto::ScopedPK11Slot GetPrivateSlot() const; | 115 virtual crypto::ScopedPK11Slot GetPrivateSlot() const; |
| 106 | 116 |
| 107 // Get the default module for public key data. | 117 // Get the default module for public key data. |
| 108 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. | 118 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. |
| 109 // DEPRECATED: use GetPublicSlot instead. | 119 // DEPRECATED: use GetPublicSlot instead. |
| 110 // TODO(mattm): remove usage of this method and remove it. | 120 // TODO(mattm): remove usage of this method and remove it. |
| 111 CryptoModule* GetPublicModule() const; | 121 CryptoModule* GetPublicModule() const; |
| 112 | 122 |
| 113 // Get the default module for private key or mixed private/public key data. | 123 // Get the default module for private key or mixed private/public key data. |
| 114 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. | 124 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. |
| 115 // DEPRECATED: use GetPrivateSlot instead. | 125 // DEPRECATED: use GetPrivateSlot instead. |
| 116 // TODO(mattm): remove usage of this method and remove it. | 126 // TODO(mattm): remove usage of this method and remove it. |
| 117 CryptoModule* GetPrivateModule() const; | 127 CryptoModule* GetPrivateModule() const; |
| 118 | 128 |
| 119 // Get all modules. | 129 // Get all modules. |
| 120 // If |need_rw| is true, only writable modules will be returned. | 130 // If |need_rw| is true, only writable modules will be returned. |
| 121 // TODO(mattm): come up with better alternative to CryptoModuleList. | 131 // TODO(mattm): come up with better alternative to CryptoModuleList. |
| 122 virtual void ListModules(CryptoModuleList* modules, bool need_rw) const; | 132 virtual void ListModulesSync(CryptoModuleList* modules, bool need_rw) const; |
| 123 | 133 |
| 124 // Import certificates and private keys from PKCS #12 blob into the module. | 134 // Import certificates and private keys from PKCS #12 blob into the module. |
| 125 // If |is_extractable| is false, mark the private key as being unextractable | 135 // If |is_extractable| is false, mark the private key as being unextractable |
| 126 // from the module. | 136 // from the module. |
| 127 // Returns OK or a network error code such as ERR_PKCS12_IMPORT_BAD_PASSWORD | 137 // Returns OK or a network error code such as ERR_PKCS12_IMPORT_BAD_PASSWORD |
| 128 // or ERR_PKCS12_IMPORT_ERROR. |imported_certs|, if non-NULL, returns a list | 138 // or ERR_PKCS12_IMPORT_ERROR. |imported_certs|, if non-NULL, returns a list |
| 129 // of certs that were imported. | 139 // of certs that were imported. |
| 130 int ImportFromPKCS12(CryptoModule* module, | 140 int ImportFromPKCS12(CryptoModule* module, |
| 131 const std::string& data, | 141 const std::string& data, |
| 132 const base::string16& password, | 142 const base::string16& password, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 // NOTE: CertDatabase::AddObserver should be preferred. Observers registered | 212 // NOTE: CertDatabase::AddObserver should be preferred. Observers registered |
| 203 // here will only recieve notifications generated directly through the | 213 // here will only recieve notifications generated directly through the |
| 204 // NSSCertDatabase, but not those from the CertDatabase. The CertDatabase | 214 // NSSCertDatabase, but not those from the CertDatabase. The CertDatabase |
| 205 // observers will recieve both. | 215 // observers will recieve both. |
| 206 void AddObserver(Observer* observer); | 216 void AddObserver(Observer* observer); |
| 207 | 217 |
| 208 // Unregisters |observer| from receiving notifications. This must be called | 218 // Unregisters |observer| from receiving notifications. This must be called |
| 209 // on the same thread on which AddObserver() was called. | 219 // on the same thread on which AddObserver() was called. |
| 210 void RemoveObserver(Observer* observer); | 220 void RemoveObserver(Observer* observer); |
| 211 | 221 |
| 222 // Overrides task runner that's used for running slow tasks. | |
| 223 void SetSlowTaskRunnerForTest( | |
| 224 const scoped_refptr<base::TaskRunner>& task_runner); | |
|
Ryan Sleevi
2014/01/28 02:11:22
Why is this not private w/ friend?
| |
| 225 | |
| 212 protected: | 226 protected: |
| 213 NSSCertDatabase(); | 227 NSSCertDatabase(); |
| 214 virtual ~NSSCertDatabase(); | 228 virtual ~NSSCertDatabase(); |
| 215 | 229 |
| 230 // Returns the NSSDatabaseFilter that should be used to filter out | |
| 231 // certificated and modules during their listing. Default value is NULL, | |
| 232 // but subclasses may override it. | |
| 233 virtual scoped_refptr<NSSDatabaseFilter> GetDatabaseFilter() const; | |
| 234 | |
| 216 private: | 235 private: |
| 217 friend struct base::DefaultLazyInstanceTraits<NSSCertDatabase>; | 236 friend struct base::DefaultLazyInstanceTraits<NSSCertDatabase>; |
| 218 | 237 |
| 238 // Static method that lists all the certificates and filters out the ones | |
| 239 // that satisfy |predicate|. If |predicate| is not set, no filtering is done. | |
| 240 // The result is returned using |certs|. | |
| 241 static void ListAndFilterCerts( | |
| 242 scoped_ptr<NSSDatabaseFilter::CertNotAllowedPredicate> predicate, | |
| 243 CertificateList* certs); | |
| 244 | |
| 219 // Broadcasts notifications to all registered observers. | 245 // Broadcasts notifications to all registered observers. |
| 220 void NotifyObserversOfCertAdded(const X509Certificate* cert); | 246 void NotifyObserversOfCertAdded(const X509Certificate* cert); |
| 221 void NotifyObserversOfCertRemoved(const X509Certificate* cert); | 247 void NotifyObserversOfCertRemoved(const X509Certificate* cert); |
| 222 void NotifyObserversOfCACertChanged(const X509Certificate* cert); | 248 void NotifyObserversOfCACertChanged(const X509Certificate* cert); |
| 223 | 249 |
| 250 // Gets task runner that should be use for slow tasks like certificate | |
| 251 // listing. Defaults to a base::WorkerPool runner, but may be overriden | |
| 252 // in tests (see SetSlowTaskRunnerForTest). | |
| 253 scoped_refptr<base::TaskRunner> GetSlowTaskRunner() const; | |
| 254 | |
| 255 // Task runner that should be used in tests if set. | |
| 256 scoped_refptr<base::TaskRunner> slow_task_runner_for_test_; | |
| 257 | |
| 224 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; | 258 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; |
| 225 | 259 |
| 226 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); | 260 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); |
| 227 }; | 261 }; |
| 228 | 262 |
| 229 } // namespace net | 263 } // namespace net |
| 230 | 264 |
| 231 #endif // NET_CERT_NSS_CERT_DATABASE_H_ | 265 #endif // NET_CERT_NSS_CERT_DATABASE_H_ |
| OLD | NEW |