OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CERT_DATABASE_H_ |
6 #define NET_BASE_CERT_DATABASE_H_ | 6 #define NET_BASE_CERT_DATABASE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // Check whether this is a valid user cert that we have the private key for. | 92 // Check whether this is a valid user cert that we have the private key for. |
93 // Returns OK or a network error code such as ERR_CERT_CONTAINS_ERRORS. | 93 // Returns OK or a network error code such as ERR_CERT_CONTAINS_ERRORS. |
94 int CheckUserCert(X509Certificate* cert); | 94 int CheckUserCert(X509Certificate* cert); |
95 | 95 |
96 // Store user (client) certificate. Assumes CheckUserCert has already passed. | 96 // Store user (client) certificate. Assumes CheckUserCert has already passed. |
97 // Returns OK, or ERR_ADD_USER_CERT_FAILED if there was a problem saving to | 97 // Returns OK, or ERR_ADD_USER_CERT_FAILED if there was a problem saving to |
98 // the platform cert database, or possibly other network error codes. | 98 // the platform cert database, or possibly other network error codes. |
99 int AddUserCert(X509Certificate* cert); | 99 int AddUserCert(X509Certificate* cert); |
100 | 100 |
101 #if defined(USE_NSS) || defined(USE_OPENSSL) | 101 #if defined(USE_NSS) || defined(USE_OPENSSL) |
102 // Get a list of unique certificates in the certificate database. (One | 102 // Get a list of unique certificates in the certificate database (one |
103 // instance of all certificates.) | 103 // instance of all certificates). |
104 void ListCerts(CertificateList* certs); | 104 void ListCerts(CertificateList* certs); |
105 | 105 |
106 // Get the default module for public key data. | 106 // Get the default module for public key data. |
107 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. | 107 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. |
108 CryptoModule* GetPublicModule() const; | 108 CryptoModule* GetPublicModule() const; |
109 | 109 |
110 // Get the default module for private key or mixed private/public key data. | 110 // Get the default module for private key or mixed private/public key data. |
111 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. | 111 // The returned pointer must be stored in a scoped_refptr<CryptoModule>. |
112 CryptoModule* GetPrivateModule() const; | 112 CryptoModule* GetPrivateModule() const; |
113 | 113 |
114 // Get all modules. | 114 // Get all modules. |
115 // If |need_rw| is true, only writable modules will be returned. | 115 // If |need_rw| is true, only writable modules will be returned. |
116 void ListModules(CryptoModuleList* modules, bool need_rw) const; | 116 void ListModules(CryptoModuleList* modules, bool need_rw) const; |
117 | 117 |
118 // Import certificates and private keys from PKCS #12 blob into the module. | 118 // Import certificates and private keys from PKCS #12 blob into the module. |
119 // If |is_extractable| is false, mark the private key as being unextractable | 119 // If |is_extractable| is false, mark the private key as being unextractable |
120 // from the module. | 120 // from the module. |
121 // Returns OK or a network error code such as ERR_PKCS12_IMPORT_BAD_PASSWORD | 121 // Returns OK or a network error code such as ERR_PKCS12_IMPORT_BAD_PASSWORD |
122 // or ERR_PKCS12_IMPORT_ERROR. | 122 // or ERR_PKCS12_IMPORT_ERROR. |
123 int ImportFromPKCS12(CryptoModule* module, | 123 int ImportFromPKCS12(CryptoModule* module, |
124 const std::string& data, | 124 const std::string& data, |
125 const string16& password, | 125 const string16& password, |
126 bool is_extractable); | 126 bool is_extractable, |
127 CertificateList* imported_certs); | |
wtc
2011/11/29 23:13:57
Please document the new imported_certs output para
Greg Spencer (Chromium)
2011/12/02 18:50:07
Done.
| |
127 | 128 |
128 // Export the given certificates and private keys into a PKCS #12 blob, | 129 // Export the given certificates and private keys into a PKCS #12 blob, |
129 // storing into |output|. | 130 // storing into |output|. |
130 // Returns the number of certificates successfully exported. | 131 // Returns the number of certificates successfully exported. |
131 int ExportToPKCS12(const CertificateList& certs, const string16& password, | 132 int ExportToPKCS12(const CertificateList& certs, const string16& password, |
132 std::string* output) const; | 133 std::string* output) const; |
133 | 134 |
134 // Uses similar logic to nsNSSCertificateDB::handleCACertDownload to find the | 135 // Uses similar logic to nsNSSCertificateDB::handleCACertDownload to find the |
135 // root. Assumes the list is an ordered hierarchy with the root being either | 136 // root. Assumes the list is an ordered hierarchy with the root being either |
136 // the first or last element. | 137 // the first or last element. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 // Returns true on success or false on failure. | 172 // Returns true on success or false on failure. |
172 bool SetCertTrust(const X509Certificate* cert, | 173 bool SetCertTrust(const X509Certificate* cert, |
173 CertType type, | 174 CertType type, |
174 TrustBits trust_bits); | 175 TrustBits trust_bits); |
175 | 176 |
176 // Delete certificate and associated private key (if one exists). | 177 // Delete certificate and associated private key (if one exists). |
177 // |cert| is still valid when this function returns. Returns true on | 178 // |cert| is still valid when this function returns. Returns true on |
178 // success. | 179 // success. |
179 bool DeleteCertAndKey(const X509Certificate* cert); | 180 bool DeleteCertAndKey(const X509Certificate* cert); |
180 | 181 |
181 // Delete the certificate and associated public and private key (if | |
182 // one exists) with the given label from the database. Returns true | |
183 // on success. ("label" here refers to the NSS Attribute CKA_LABEL, | |
184 // also referred to as a nickname or friendly name). | |
185 bool DeleteCertAndKeyByLabel(const std::string& label); | |
186 | |
187 // Check whether cert is stored in a readonly slot. | 182 // Check whether cert is stored in a readonly slot. |
188 bool IsReadOnly(const X509Certificate* cert) const; | 183 bool IsReadOnly(const X509Certificate* cert) const; |
189 #endif | 184 #endif |
190 | 185 |
186 #if defined(USE_NSS) | |
187 // Delete the certificate and associated public and private key (if | |
188 // one exists) with the given label from the database. Returns true | |
189 // on success. ("label" here refers to the NSS attribute CKA_LABEL, | |
wtc
2011/11/29 23:13:57
Nit: NSS attribute => PKCS #11 attribute
Greg Spencer (Chromium)
2011/12/02 18:50:07
Done. I've also moved these functions into the on
| |
190 // also referred to as a nickname or friendly name). | |
191 bool DeleteCertAndKeyByLabel(const std::string& label); | |
192 | |
193 // Get a list of certificates in the certificate database that | |
194 // contain the given string in their label (one instance of all | |
195 // certificates that match). This is a substring match, so if the | |
wtc
2011/11/29 23:13:57
Doing an exact match in DeleteCertAndKeyByLabel bu
Greg Spencer (Chromium)
2011/12/02 18:50:07
I've moved these into OncNetworkParser, since it k
| |
196 // requested label is "a", then all certs with an "a" in their label | |
197 // will be returned. | |
198 void ListCertsWithLabel(const std::string& label, CertificateList* certs); | |
199 #endif | |
200 | |
191 // Registers |observer| to receive notifications of certificate changes. The | 201 // Registers |observer| to receive notifications of certificate changes. The |
192 // thread on which this is called is the thread on which |observer| will be | 202 // thread on which this is called is the thread on which |observer| will be |
193 // called back with notifications. | 203 // called back with notifications. |
194 static void AddObserver(Observer* observer); | 204 static void AddObserver(Observer* observer); |
195 | 205 |
196 // Unregisters |observer| from receiving notifications. This must be called | 206 // Unregisters |observer| from receiving notifications. This must be called |
197 // on the same thread on which AddObserver() was called. | 207 // on the same thread on which AddObserver() was called. |
198 static void RemoveObserver(Observer* observer); | 208 static void RemoveObserver(Observer* observer); |
199 | 209 |
200 private: | 210 private: |
201 // Broadcasts notifications to all registered observers. | 211 // Broadcasts notifications to all registered observers. |
202 static void NotifyObserversOfUserCertAdded(const X509Certificate* cert); | 212 static void NotifyObserversOfUserCertAdded(const X509Certificate* cert); |
203 static void NotifyObserversOfCertTrustChanged(const X509Certificate* cert); | 213 static void NotifyObserversOfCertTrustChanged(const X509Certificate* cert); |
204 | 214 |
205 DISALLOW_COPY_AND_ASSIGN(CertDatabase); | 215 DISALLOW_COPY_AND_ASSIGN(CertDatabase); |
206 }; | 216 }; |
207 | 217 |
208 } // namespace net | 218 } // namespace net |
209 | 219 |
210 #endif // NET_BASE_CERT_DATABASE_H_ | 220 #endif // NET_BASE_CERT_DATABASE_H_ |
OLD | NEW |