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

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: cert manager basics working Created 7 years, 2 months 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"
15 #include "net/cert/cert_type.h" 16 #include "net/cert/cert_type.h"
16 #include "net/cert/x509_certificate.h" 17 #include "net/cert/x509_certificate.h"
17 18
18 template <typename T> struct DefaultSingletonTraits; 19 template <typename T> struct DefaultSingletonTraits;
19 template <class ObserverType> class ObserverListThreadSafe; 20 template <class ObserverType> class ObserverListThreadSafe;
20 21
21 namespace net { 22 namespace net {
22 23
23 class CryptoModule; 24 class CryptoModule;
24 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList; 25 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList;
25 26
27 //XXX what to do with this?
28 //make callers do filtering themselves?
29 // - but this also does importing and stuff, with only the primary slot.
30 // - should there be a separate NSSCertDatabase per profile? How does that work
31 // since this lives in net/ ?
32 //
26 // Provides functions to manipulate the NSS certificate stores. 33 // Provides functions to manipulate the NSS certificate stores.
27 class NET_EXPORT NSSCertDatabase { 34 class NET_EXPORT NSSCertDatabase {
28 public: 35 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 certificate's trust is changed.
43 // Called with |cert| == NULL after importing a list of certificates
44 // in ImportCACerts().
45 virtual void OnCertTrustChanged(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. 36 // Stores per-certificate error codes for import failures.
55 struct NET_EXPORT ImportCertFailure { 37 struct NET_EXPORT ImportCertFailure {
56 public: 38 public:
57 ImportCertFailure(const scoped_refptr<X509Certificate>& cert, int err); 39 ImportCertFailure(const scoped_refptr<X509Certificate>& cert, int err);
58 ~ImportCertFailure(); 40 ~ImportCertFailure();
59 41
60 scoped_refptr<X509Certificate> certificate; 42 scoped_refptr<X509Certificate> certificate;
61 int net_error; 43 int net_error;
62 }; 44 };
63 typedef std::vector<ImportCertFailure> ImportCertFailureList; 45 typedef std::vector<ImportCertFailure> ImportCertFailureList;
(...skipping 21 matching lines...) Expand all
85 TRUSTED_OBJ_SIGN = 1 << 2, 67 TRUSTED_OBJ_SIGN = 1 << 2,
86 DISTRUSTED_SSL = 1 << 3, 68 DISTRUSTED_SSL = 1 << 3,
87 DISTRUSTED_EMAIL = 1 << 4, 69 DISTRUSTED_EMAIL = 1 << 4,
88 DISTRUSTED_OBJ_SIGN = 1 << 5, 70 DISTRUSTED_OBJ_SIGN = 1 << 5,
89 }; 71 };
90 72
91 static NSSCertDatabase* GetInstance(); 73 static NSSCertDatabase* GetInstance();
92 74
93 // Get a list of unique certificates in the certificate database (one 75 // Get a list of unique certificates in the certificate database (one
94 // instance of all certificates). 76 // instance of all certificates).
95 void ListCerts(CertificateList* certs); 77 virtual void ListCerts(CertificateList* certs);
96 78
97 // Get the default module for public key data. 79 // Get the default module for public key data.
98 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. 80 // The returned pointer must be stored in a scoped_refptr<CryptoModule>.
99 CryptoModule* GetPublicModule() const; 81 CryptoModule* GetPublicModule() const;
100 82
101 // Get the default module for private key or mixed private/public key data. 83 // 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>. 84 // The returned pointer must be stored in a scoped_refptr<CryptoModule>.
103 CryptoModule* GetPrivateModule() const; 85 CryptoModule* GetPrivateModule() const;
104 86
105 // Get all modules. 87 // Get all modules.
106 // If |need_rw| is true, only writable modules will be returned. 88 // If |need_rw| is true, only writable modules will be returned.
107 void ListModules(CryptoModuleList* modules, bool need_rw) const; 89 virtual void ListModules(CryptoModuleList* modules, bool need_rw) const;
108 90
109 // Import certificates and private keys from PKCS #12 blob into the module. 91 // 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 92 // If |is_extractable| is false, mark the private key as being unextractable
111 // from the module. 93 // from the module.
112 // Returns OK or a network error code such as ERR_PKCS12_IMPORT_BAD_PASSWORD 94 // 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 95 // or ERR_PKCS12_IMPORT_ERROR. |imported_certs|, if non-NULL, returns a list
114 // of certs that were imported. 96 // of certs that were imported.
115 int ImportFromPKCS12(CryptoModule* module, 97 int ImportFromPKCS12(CryptoModule* module,
116 const std::string& data, 98 const std::string& data,
117 const base::string16& password, 99 const base::string16& password,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 TrustBits trust_bits); 153 TrustBits trust_bits);
172 154
173 // Delete certificate and associated private key (if one exists). 155 // Delete certificate and associated private key (if one exists).
174 // |cert| is still valid when this function returns. Returns true on 156 // |cert| is still valid when this function returns. Returns true on
175 // success. 157 // success.
176 bool DeleteCertAndKey(const X509Certificate* cert); 158 bool DeleteCertAndKey(const X509Certificate* cert);
177 159
178 // Check whether cert is stored in a readonly slot. 160 // Check whether cert is stored in a readonly slot.
179 bool IsReadOnly(const X509Certificate* cert) const; 161 bool IsReadOnly(const X509Certificate* cert) const;
180 162
181 // Registers |observer| to receive notifications of certificate changes. The 163 protected:
182 // thread on which this is called is the thread on which |observer| will be 164 NSSCertDatabase();
183 // called back with notifications. 165 virtual ~NSSCertDatabase();
184 void AddObserver(Observer* observer);
185 166
186 // Unregisters |observer| from receiving notifications. This must be called 167 // Get private and public slots.
187 // on the same thread on which AddObserver() was called. 168 virtual crypto::ScopedPK11Slot GetPublicSlot() const;
188 void RemoveObserver(Observer* observer); 169 virtual crypto::ScopedPK11Slot GetPrivateSlot() const;
189 170
190 private: 171 private:
191 friend struct DefaultSingletonTraits<NSSCertDatabase>; 172 friend struct DefaultSingletonTraits<NSSCertDatabase>;
192 173
193 NSSCertDatabase();
194 ~NSSCertDatabase();
195
196 // Broadcasts notifications to all registered observers. 174 // Broadcasts notifications to all registered observers.
197 void NotifyObserversOfCertAdded(const X509Certificate* cert); 175 void NotifyObserversOfCertAdded(const X509Certificate* cert);
198 void NotifyObserversOfCertRemoved(const X509Certificate* cert); 176 void NotifyObserversOfCertRemoved(const X509Certificate* cert);
199 void NotifyObserversOfCertTrustChanged(const X509Certificate* cert); 177 void NotifyObserversOfCertTrustChanged(const X509Certificate* cert);
200 178
201 const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_;
202
203 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase); 179 DISALLOW_COPY_AND_ASSIGN(NSSCertDatabase);
204 }; 180 };
205 181
206 } // namespace net 182 } // namespace net
207 183
208 #endif // NET_CERT_NSS_CERT_DATABASE_H_ 184 #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