Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: net/cert/nss_cert_database.h

Issue 18121007: *WIP* Store NSS slots per profile. Move keygen to chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more refactoring Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/cert/cert_database_nss.cc ('k') | net/cert/nss_cert_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "crypto/scoped_nss_types.h"
14 #include "net/base/net_export.h" 15 #include "net/base/net_export.h"
16 #include "net/cert/cert_database.h"
15 #include "net/cert/cert_type.h" 17 #include "net/cert/cert_type.h"
16 #include "net/cert/x509_certificate.h" 18 #include "net/cert/x509_certificate.h"
17 19
18 template <typename T> struct DefaultSingletonTraits; 20 namespace base {
21 template <typename T> struct DefaultLazyInstanceTraits;
22 }
19 template <class ObserverType> class ObserverListThreadSafe; 23 template <class ObserverType> class ObserverListThreadSafe;
20 24
21 namespace net { 25 namespace net {
22 26
23 class CryptoModule; 27 class CryptoModule;
24 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; 28 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList;
25 29
26 // Provides functions to manipulate the NSS certificate stores. 30 // Provides functions to manipulate the NSS certificate stores.
27 class NET_EXPORT NSSCertDatabase { 31 class NET_EXPORT NSSCertDatabase : public CertDatabaseSource {
28 public: 32 public:
29
30 class NET_EXPORT Observer {
31 public:
32 virtual ~Observer() {}
33
34 // Will be called when a new certificate is added.
35 // Called with |cert| == NULL after importing a list of certificates
36 // in ImportFromPKCS12().
37 virtual void OnCertAdded(const X509Certificate* cert) {}
38
39 // Will be called when a certificate is removed.
40 virtual void OnCertRemoved(const X509Certificate* cert) {}
41
42 // Will be called when a CA certificate is changed.
43 // Called with |cert| == NULL after importing a list of certificates
44 // in ImportCACerts().
45 virtual void OnCACertChanged(const X509Certificate* cert) {}
46
47 protected:
48 Observer() {}
49
50 private:
51 DISALLOW_COPY_AND_ASSIGN(Observer);
52 };
53
54 // Stores per-certificate error codes for import failures. 33 // Stores per-certificate error codes for import failures.
55 struct NET_EXPORT ImportCertFailure { 34 struct NET_EXPORT ImportCertFailure {
56 public: 35 public:
57 ImportCertFailure(const scoped_refptr<X509Certificate>& cert, int err); 36 ImportCertFailure(const scoped_refptr<X509Certificate>& cert, int err);
58 ~ImportCertFailure(); 37 ~ImportCertFailure();
59 38
60 scoped_refptr<X509Certificate> certificate; 39 scoped_refptr<X509Certificate> certificate;
61 int net_error; 40 int net_error;
62 }; 41 };
63 typedef std::vector<ImportCertFailure> ImportCertFailureList; 42 typedef std::vector<ImportCertFailure> ImportCertFailureList;
(...skipping 21 matching lines...) Expand all
85 TRUSTED_OBJ_SIGN = 1 << 2, 64 TRUSTED_OBJ_SIGN = 1 << 2,
86 DISTRUSTED_SSL = 1 << 3, 65 DISTRUSTED_SSL = 1 << 3,
87 DISTRUSTED_EMAIL = 1 << 4, 66 DISTRUSTED_EMAIL = 1 << 4,
88 DISTRUSTED_OBJ_SIGN = 1 << 5, 67 DISTRUSTED_OBJ_SIGN = 1 << 5,
89 }; 68 };
90 69
91 static NSSCertDatabase* GetInstance(); 70 static NSSCertDatabase* GetInstance();
92 71
93 // Get a list of unique certificates in the certificate database (one 72 // Get a list of unique certificates in the certificate database (one
94 // instance of all certificates). 73 // instance of all certificates).
95 void ListCerts(CertificateList* certs); 74 virtual void ListCerts(CertificateList* certs);
75
76 // Get the default slot for public key data.
77 virtual crypto::ScopedPK11Slot GetPublicSlot() const;
78
79 // Get the default slot for private key or mixed private/public key data.
80 virtual crypto::ScopedPK11Slot GetPrivateSlot() const;
96 81
97 // Get the default module for public key data. 82 // Get the default module for public key data.
98 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. 83 // The returned pointer must be stored in a scoped_refptr<CryptoModule>.
84 // DEPRECATED: use GetPublicSlot instead.
99 CryptoModule* GetPublicModule() const; 85 CryptoModule* GetPublicModule() const;
100 86
101 // Get the default module for private key or mixed private/public key data. 87 // Get the default module for private key or mixed private/public key data.
102 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. 88 // The returned pointer must be stored in a scoped_refptr<CryptoModule>.
89 // DEPRECATED: use GetPrivateSlot instead.
103 CryptoModule* GetPrivateModule() const; 90 CryptoModule* GetPrivateModule() const;
104 91
105 // Get all modules. 92 // Get all modules.
106 // If |need_rw| is true, only writable modules will be returned. 93 // If |need_rw| is true, only writable modules will be returned.
107 void ListModules(CryptoModuleList* modules, bool need_rw) const; 94 virtual void ListModules(CryptoModuleList* modules, bool need_rw) const;
108 95
109 // Import certificates and private keys from PKCS #12 blob into the module. 96 // Import certificates and private keys from PKCS #12 blob into the module.
110 // If |is_extractable| is false, mark the private key as being unextractable 97 // If |is_extractable| is false, mark the private key as being unextractable
111 // from the module. 98 // from the module.
112 // Returns OK or a network error code such as ERR_PKCS12_IMPORT_BAD_PASSWORD 99 // Returns OK or a network error code such as ERR_PKCS12_IMPORT_BAD_PASSWORD
113 // or ERR_PKCS12_IMPORT_ERROR. |imported_certs|, if non-NULL, returns a list 100 // or ERR_PKCS12_IMPORT_ERROR. |imported_certs|, if non-NULL, returns a list
114 // of certs that were imported. 101 // of certs that were imported.
115 int ImportFromPKCS12(CryptoModule* module, 102 int ImportFromPKCS12(CryptoModule* module,
116 const std::string& data, 103 const std::string& data,
117 const base::string16& password, 104 const base::string16& password,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // |trust_bits| can be set to explicitly trust or distrust the certificate, or 137 // |trust_bits| can be set to explicitly trust or distrust the certificate, or
151 // use TRUST_DEFAULT to inherit trust as normal. 138 // use TRUST_DEFAULT to inherit trust as normal.
152 // Returns false if there is an internal error, otherwise true is returned and 139 // Returns false if there is an internal error, otherwise true is returned and
153 // |not_imported| should be checked for any certificates that were not 140 // |not_imported| should be checked for any certificates that were not
154 // imported. 141 // imported.
155 bool ImportServerCert(const CertificateList& certificates, 142 bool ImportServerCert(const CertificateList& certificates,
156 TrustBits trust_bits, 143 TrustBits trust_bits,
157 ImportCertFailureList* not_imported); 144 ImportCertFailureList* not_imported);
158 145
159 // Get trust bits for certificate. 146 // Get trust bits for certificate.
160 TrustBits GetCertTrust(const X509Certificate* cert, CertType type) const; 147 virtual TrustBits GetCertTrust(const X509Certificate* cert,
148 CertType type) const;
161 149
162 // IsUntrusted returns true if |cert| is specifically untrusted. These 150 // IsUntrusted returns true if |cert| is specifically untrusted. These
163 // certificates are stored in the database for the specific purpose of 151 // certificates are stored in the database for the specific purpose of
164 // rejecting them. 152 // rejecting them.
165 bool IsUntrusted(const X509Certificate* cert) const; 153 virtual bool IsUntrusted(const X509Certificate* cert) const;
166 154
167 // Set trust values for certificate. 155 // Set trust values for certificate.
168 // Returns true on success or false on failure. 156 // Returns true on success or false on failure.
169 bool SetCertTrust(const X509Certificate* cert, 157 virtual bool SetCertTrust(const X509Certificate* cert,
170 CertType type, 158 CertType type,
171 TrustBits trust_bits); 159 TrustBits trust_bits);
172 160
173 // Delete certificate and associated private key (if one exists). 161 // Delete certificate and associated private key (if one exists).
174 // |cert| is still valid when this function returns. Returns true on 162 // |cert| is still valid when this function returns. Returns true on
175 // success. 163 // success.
176 bool DeleteCertAndKey(const X509Certificate* cert); 164 bool DeleteCertAndKey(const X509Certificate* cert);
177 165
178 // Check whether cert is stored in a readonly slot. 166 // Check whether cert is stored in a readonly slot.
179 bool IsReadOnly(const X509Certificate* cert) const; 167 bool IsReadOnly(const X509Certificate* cert) const;
180 168
181 // Check whether cert is stored in a hardware slot. 169 // Check whether cert is stored in a hardware slot.
182 bool IsHardwareBacked(const X509Certificate* cert) const; 170 bool IsHardwareBacked(const X509Certificate* cert) const;
183 171
184 // Registers |observer| to receive notifications of certificate changes. The 172 // Registers |observer| to receive notifications of certificate changes. The
185 // thread on which this is called is the thread on which |observer| will be 173 // thread on which this is called is the thread on which |observer| will be
186 // called back with notifications. 174 // called back with notifications.
187 void AddObserver(Observer* observer); 175 virtual void AddObserver(Observer* observer) OVERRIDE;
188 176
189 // Unregisters |observer| from receiving notifications. This must be called 177 // Unregisters |observer| from receiving notifications. This must be called
190 // on the same thread on which AddObserver() was called. 178 // on the same thread on which AddObserver() was called.
191 void RemoveObserver(Observer* observer); 179 virtual void RemoveObserver(Observer* observer) OVERRIDE;
180
181 // Observe events and forward them to observers of this NSSCertDatabase. It is
182 // assumed that the NSSCertDatabase will outlive the source, so we don't need
183 // to bother with unregistering. //XXX
184 void AddSource(CertDatabaseSource* source);
185
186 protected:
187 NSSCertDatabase();
188 virtual ~NSSCertDatabase();
189
190 // XXX document, name this better
191 static NSSCertDatabase* GetInstanceNoWarn();
192 192
193 private: 193 private:
194 friend struct DefaultSingletonTraits<NSSCertDatabase>; 194 friend struct base::DefaultLazyInstanceTraits<NSSCertDatabase>;
195
196 NSSCertDatabase();
197 ~NSSCertDatabase();
198 195
199 // Broadcasts notifications to all registered observers. 196 // Broadcasts notifications to all registered observers.
200 void NotifyObserversOfCertAdded(const X509Certificate* cert); 197 void NotifyObserversOfCertAdded(const X509Certificate* cert);
201 void NotifyObserversOfCertRemoved(const X509Certificate* cert); 198 void NotifyObserversOfCertRemoved(const X509Certificate* cert);
202 void NotifyObserversOfCACertChanged(const X509Certificate* cert); 199 void NotifyObserversOfCACertChanged(const X509Certificate* cert);
203 200
204 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; 201 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
205 202
203 class Notifier;
204 friend class Notifier;
205 scoped_ptr<Notifier> notifier_;
206
206 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); 207 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase);
207 }; 208 };
208 209
209 } // namespace net 210 } // namespace net
210 211
211 #endif // NET_CERT_NSS_CERT_DATABASE_H_ 212 #endif // NET_CERT_NSS_CERT_DATABASE_H_
OLDNEW
« no previous file with comments | « net/cert/cert_database_nss.cc ('k') | net/cert/nss_cert_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698