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_BASE_CERT_DATABASE_H_ | 5 #ifndef NET_BASE_NSS_CERT_DATABASE_H_ |
| 6 #define NET_BASE_CERT_DATABASE_H_ | 6 #define NET_BASE_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/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "net/base/cert_type.h" | 14 #include "net/base/cert_type.h" |
| 15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
| 16 #include "net/base/x509_certificate.h" | 16 #include "net/base/x509_certificate.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 class CryptoModule; | 20 class CryptoModule; |
| 21 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; | 21 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; |
| 22 | 22 |
| 23 // This class provides functions to manipulate the local | 23 // Provides functions to manipulate the NSS certificate stores. |
| 24 // certificate store. | 24 class NET_EXPORT NSSCertDatabase { |
| 25 | |
| 26 // TODO(gauravsh): This class could be augmented with methods | |
| 27 // for all operations that manipulate the underlying system | |
| 28 // certificate store. | |
| 29 | |
| 30 class NET_EXPORT CertDatabase { | |
| 31 public: | 25 public: |
| 32 | 26 |
| 33 // A CertDatabase::Observer will be notified on certificate database changes. | |
| 34 // The change could be either a new user certificate is added or trust on | |
| 35 // a certificate is changed. Observers can register themselves | |
| 36 // via CertDatabase::AddObserver, and can un-register with | |
| 37 // CertDatabase::RemoveObserver. | |
| 38 class NET_EXPORT Observer { | 27 class NET_EXPORT Observer { |
| 39 public: | 28 public: |
| 40 virtual ~Observer() {} | 29 virtual ~Observer() {} |
| 41 | 30 |
| 42 // Will be called when a new user certificate is added. | 31 // Will be called when a new certificate is added. |
| 43 // Called with |cert| == NULL after importing a list of certificates | 32 // Called with |cert| == NULL after importing a list of certificates |
| 44 // in ImportFromPKCS12(). | 33 // in ImportFromPKCS12(). |
| 45 virtual void OnUserCertAdded(const X509Certificate* cert) {} | 34 virtual void OnCertAdded(const X509Certificate* cert) {} |
| 46 | 35 |
| 47 // Will be called when a user certificate is removed. | 36 // Will be called when a certificate is removed. |
| 48 virtual void OnUserCertRemoved(const X509Certificate* cert) {} | 37 virtual void OnCertRemoved(const X509Certificate* cert) {} |
| 49 | 38 |
| 50 // Will be called when a certificate's trust is changed. | 39 // Will be called when a certificate's trust is changed. |
| 51 // Called with |cert| == NULL after importing a list of certificates | 40 // Called with |cert| == NULL after importing a list of certificates |
| 52 // in ImportCACerts(). | 41 // in ImportCACerts(). |
| 53 virtual void OnCertTrustChanged(const X509Certificate* cert) {} | 42 virtual void OnCertTrustChanged(const X509Certificate* cert) {} |
| 54 | 43 |
| 55 protected: | 44 protected: |
| 56 Observer() {} | 45 Observer() {} |
| 57 | 46 |
| 58 private: | 47 private: |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 89 enum { | 78 enum { |
| 90 TRUST_DEFAULT = 0, | 79 TRUST_DEFAULT = 0, |
| 91 TRUSTED_SSL = 1 << 0, | 80 TRUSTED_SSL = 1 << 0, |
| 92 TRUSTED_EMAIL = 1 << 1, | 81 TRUSTED_EMAIL = 1 << 1, |
| 93 TRUSTED_OBJ_SIGN = 1 << 2, | 82 TRUSTED_OBJ_SIGN = 1 << 2, |
| 94 DISTRUSTED_SSL = 1 << 3, | 83 DISTRUSTED_SSL = 1 << 3, |
| 95 DISTRUSTED_EMAIL = 1 << 4, | 84 DISTRUSTED_EMAIL = 1 << 4, |
| 96 DISTRUSTED_OBJ_SIGN = 1 << 5, | 85 DISTRUSTED_OBJ_SIGN = 1 << 5, |
| 97 }; | 86 }; |
| 98 | 87 |
| 99 CertDatabase(); | 88 NSSCertDatabase(); |
| 100 | 89 |
| 101 // Check whether this is a valid user cert that we have the private key for. | 90 // Initializes NSS, if it isn't initialized yet. |
| 102 // Returns OK or a network error code such as ERR_CERT_CONTAINS_ERRORS. | 91 static void EnsureInit(); |
|
Ryan Sleevi
2012/09/05 21:44:17
nit: In case it wasn't clear, I think EnsureInit c
Joao da Silva
2012/09/06 15:11:41
This was the case before (the CertDatabase ctor fr
| |
| 103 int CheckUserCert(X509Certificate* cert); | |
| 104 | 92 |
| 105 // Store user (client) certificate. Assumes CheckUserCert has already passed. | |
| 106 // Returns OK, or ERR_ADD_USER_CERT_FAILED if there was a problem saving to | |
| 107 // the platform cert database, or possibly other network error codes. | |
| 108 int AddUserCert(X509Certificate* cert); | |
| 109 | |
| 110 #if defined(USE_NSS) | |
| 111 // Get a list of unique certificates in the certificate database (one | 93 // Get a list of unique certificates in the certificate database (one |
| 112 // instance of all certificates). | 94 // instance of all certificates). |
| 113 void ListCerts(CertificateList* certs); | 95 void ListCerts(CertificateList* certs); |
| 114 | 96 |
| 115 // Get the default module for public key data. | 97 // Get the default module for public key data. |
| 116 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. | 98 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. |
| 117 CryptoModule* GetPublicModule() const; | 99 CryptoModule* GetPublicModule() const; |
| 118 | 100 |
| 119 // Get the default module for private key or mixed private/public key data. | 101 // Get the default module for private key or mixed private/public key data. |
| 120 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. | 102 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 CertType type, | 169 CertType type, |
| 188 TrustBits trust_bits); | 170 TrustBits trust_bits); |
| 189 | 171 |
| 190 // Delete certificate and associated private key (if one exists). | 172 // Delete certificate and associated private key (if one exists). |
| 191 // |cert| is still valid when this function returns. Returns true on | 173 // |cert| is still valid when this function returns. Returns true on |
| 192 // success. | 174 // success. |
| 193 bool DeleteCertAndKey(const X509Certificate* cert); | 175 bool DeleteCertAndKey(const X509Certificate* cert); |
| 194 | 176 |
| 195 // Check whether cert is stored in a readonly slot. | 177 // Check whether cert is stored in a readonly slot. |
| 196 bool IsReadOnly(const X509Certificate* cert) const; | 178 bool IsReadOnly(const X509Certificate* cert) const; |
| 197 #endif | |
| 198 | 179 |
| 199 // Registers |observer| to receive notifications of certificate changes. The | 180 // Registers |observer| to receive notifications of certificate changes. The |
| 200 // thread on which this is called is the thread on which |observer| will be | 181 // thread on which this is called is the thread on which |observer| will be |
| 201 // called back with notifications. | 182 // called back with notifications. |
| 202 static void AddObserver(Observer* observer); | 183 void AddObserver(Observer* observer); |
| 203 | 184 |
| 204 // Unregisters |observer| from receiving notifications. This must be called | 185 // Unregisters |observer| from receiving notifications. This must be called |
| 205 // on the same thread on which AddObserver() was called. | 186 // on the same thread on which AddObserver() was called. |
| 206 static void RemoveObserver(Observer* observer); | 187 void RemoveObserver(Observer* observer); |
| 207 | 188 |
| 208 private: | 189 private: |
| 209 // Broadcasts notifications to all registered observers. | 190 // Broadcasts notifications to all registered observers. |
| 210 static void NotifyObserversOfUserCertAdded(const X509Certificate* cert); | 191 void NotifyObserversOfCertAdded(const X509Certificate* cert); |
| 211 static void NotifyObserversOfUserCertRemoved(const X509Certificate* cert); | 192 void NotifyObserversOfCertRemoved(const X509Certificate* cert); |
| 212 static void NotifyObserversOfCertTrustChanged(const X509Certificate* cert); | 193 void NotifyObserversOfCertTrustChanged(const X509Certificate* cert); |
| 213 | 194 |
| 214 DISALLOW_COPY_AND_ASSIGN(CertDatabase); | 195 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); |
| 215 }; | 196 }; |
| 216 | 197 |
| 217 } // namespace net | 198 } // namespace net |
| 218 | 199 |
| 219 #endif // NET_BASE_CERT_DATABASE_H_ | 200 #endif // NET_BASE_NSS_CERT_DATABASE_H_ |
| OLD | NEW |