| OLD | NEW |
| 1 /* ***** BEGIN LICENSE BLOCK ***** | 1 /* ***** BEGIN LICENSE BLOCK ***** |
| 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 3 * | 3 * |
| 4 * The contents of this file are subject to the Mozilla Public License Version | 4 * The contents of this file are subject to the Mozilla Public License Version |
| 5 * 1.1 (the "License"); you may not use this file except in compliance with | 5 * 1.1 (the "License"); you may not use this file except in compliance with |
| 6 * the License. You may obtain a copy of the License at | 6 * the License. You may obtain a copy of the License at |
| 7 * http://www.mozilla.org/MPL/ | 7 * http://www.mozilla.org/MPL/ |
| 8 * | 8 * |
| 9 * Software distributed under the License is distributed on an "AS IS" basis, | 9 * Software distributed under the License is distributed on an "AS IS" basis, |
| 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" | 39 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" |
| 40 | 40 |
| 41 #include <cert.h> | 41 #include <cert.h> |
| 42 #include <certdb.h> | 42 #include <certdb.h> |
| 43 #include <pk11pub.h> | 43 #include <pk11pub.h> |
| 44 #include <secerr.h> | 44 #include <secerr.h> |
| 45 | 45 |
| 46 #include "base/logging.h" | 46 #include "base/logging.h" |
| 47 #include "crypto/nss_util_internal.h" | 47 #include "crypto/nss_util_internal.h" |
| 48 #include "crypto/scoped_nss_types.h" | |
| 49 #include "net/base/net_errors.h" | 48 #include "net/base/net_errors.h" |
| 50 #include "net/cert/x509_certificate.h" | 49 #include "net/cert/x509_certificate.h" |
| 51 #include "net/cert/x509_util_nss.h" | 50 #include "net/cert/x509_util_nss.h" |
| 52 | 51 |
| 53 #if !defined(CERTDB_TERMINAL_RECORD) | 52 #if !defined(CERTDB_TERMINAL_RECORD) |
| 54 /* NSS 3.13 renames CERTDB_VALID_PEER to CERTDB_TERMINAL_RECORD | 53 /* NSS 3.13 renames CERTDB_VALID_PEER to CERTDB_TERMINAL_RECORD |
| 55 * and marks CERTDB_VALID_PEER as deprecated. | 54 * and marks CERTDB_VALID_PEER as deprecated. |
| 56 * If we're using an older version, rename it ourselves. | 55 * If we're using an older version, rename it ourselves. |
| 57 */ | 56 */ |
| 58 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER | 57 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER |
| 59 #endif | 58 #endif |
| 60 | 59 |
| 61 namespace mozilla_security_manager { | 60 namespace mozilla_security_manager { |
| 62 | 61 |
| 63 // Based on nsNSSCertificateDB::handleCACertDownload, minus the UI bits. | 62 // Based on nsNSSCertificateDB::handleCACertDownload, minus the UI bits. |
| 64 bool ImportCACerts(const net::CertificateList& certificates, | 63 bool ImportCACerts(crypto::ScopedPK11Slot slot, |
| 64 const net::CertificateList& certificates, |
| 65 net::X509Certificate* root, | 65 net::X509Certificate* root, |
| 66 net::NSSCertDatabase::TrustBits trustBits, | 66 net::NSSCertDatabase::TrustBits trustBits, |
| 67 net::NSSCertDatabase::ImportCertFailureList* not_imported) { | 67 net::NSSCertDatabase::ImportCertFailureList* not_imported) { |
| 68 if (certificates.empty() || !root) | 68 if (certificates.empty() || !root || !slot.get()) |
| 69 return false; | 69 return false; |
| 70 | 70 |
| 71 crypto::ScopedPK11Slot slot(crypto::GetPublicNSSKeySlot()); | |
| 72 if (!slot.get()) { | |
| 73 LOG(ERROR) << "Couldn't get internal key slot!"; | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 // Mozilla had some code here to check if a perm version of the cert exists | 71 // Mozilla had some code here to check if a perm version of the cert exists |
| 78 // already and use that, but CERT_NewTempCertificate actually does that | 72 // already and use that, but CERT_NewTempCertificate actually does that |
| 79 // itself, so we skip it here. | 73 // itself, so we skip it here. |
| 80 | 74 |
| 81 if (!CERT_IsCACert(root->os_cert_handle(), NULL)) { | 75 if (!CERT_IsCACert(root->os_cert_handle(), NULL)) { |
| 82 not_imported->push_back(net::NSSCertDatabase::ImportCertFailure( | 76 not_imported->push_back(net::NSSCertDatabase::ImportCertFailure( |
| 83 root, net::ERR_IMPORT_CA_CERT_NOT_CA)); | 77 root, net::ERR_IMPORT_CA_CERT_NOT_CA)); |
| 84 } else if (root->os_cert_handle()->isperm) { | 78 } else if (root->os_cert_handle()->isperm) { |
| 85 // Mozilla just returns here, but we continue in case there are other certs | 79 // Mozilla just returns here, but we continue in case there are other certs |
| 86 // in the list which aren't already imported. | 80 // in the list which aren't already imported. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 cert, net::ERR_IMPORT_CA_CERT_FAILED)); | 163 cert, net::ERR_IMPORT_CA_CERT_FAILED)); |
| 170 } | 164 } |
| 171 } | 165 } |
| 172 | 166 |
| 173 // Any errors importing individual certs will be in listed in |not_imported|. | 167 // Any errors importing individual certs will be in listed in |not_imported|. |
| 174 return true; | 168 return true; |
| 175 } | 169 } |
| 176 | 170 |
| 177 // Based on nsNSSCertificateDB::ImportServerCertificate. | 171 // Based on nsNSSCertificateDB::ImportServerCertificate. |
| 178 bool ImportServerCert( | 172 bool ImportServerCert( |
| 173 crypto::ScopedPK11Slot slot, |
| 179 const net::CertificateList& certificates, | 174 const net::CertificateList& certificates, |
| 180 net::NSSCertDatabase::TrustBits trustBits, | 175 net::NSSCertDatabase::TrustBits trustBits, |
| 181 net::NSSCertDatabase::ImportCertFailureList* not_imported) { | 176 net::NSSCertDatabase::ImportCertFailureList* not_imported) { |
| 182 if (certificates.empty()) | 177 if (certificates.empty() || !slot.get()) |
| 183 return false; | 178 return false; |
| 184 | 179 |
| 185 crypto::ScopedPK11Slot slot(crypto::GetPublicNSSKeySlot()); | |
| 186 if (!slot.get()) { | |
| 187 LOG(ERROR) << "Couldn't get internal key slot!"; | |
| 188 return false; | |
| 189 } | |
| 190 | |
| 191 for (size_t i = 0; i < certificates.size(); ++i) { | 180 for (size_t i = 0; i < certificates.size(); ++i) { |
| 192 const scoped_refptr<net::X509Certificate>& cert = certificates[i]; | 181 const scoped_refptr<net::X509Certificate>& cert = certificates[i]; |
| 193 | 182 |
| 194 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use | 183 // Mozilla uses CERT_ImportCerts, which doesn't take a slot arg. We use |
| 195 // PK11_ImportCert instead. | 184 // PK11_ImportCert instead. |
| 196 SECStatus srv = PK11_ImportCert( | 185 SECStatus srv = PK11_ImportCert( |
| 197 slot.get(), | 186 slot.get(), |
| 198 cert->os_cert_handle(), | 187 cert->os_cert_handle(), |
| 199 CK_INVALID_HANDLE, | 188 CK_INVALID_HANDLE, |
| 200 net::x509_util::GetUniqueNicknameForSlot( | 189 net::x509_util::GetUniqueNicknameForSlot( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 } else { | 267 } else { |
| 279 // ignore user and email/unknown certs | 268 // ignore user and email/unknown certs |
| 280 return true; | 269 return true; |
| 281 } | 270 } |
| 282 if (srv != SECSuccess) | 271 if (srv != SECSuccess) |
| 283 LOG(ERROR) << "SetCertTrust failed with error " << PORT_GetError(); | 272 LOG(ERROR) << "SetCertTrust failed with error " << PORT_GetError(); |
| 284 return srv == SECSuccess; | 273 return srv == SECSuccess; |
| 285 } | 274 } |
| 286 | 275 |
| 287 } // namespace mozilla_security_manager | 276 } // namespace mozilla_security_manager |
| OLD | NEW |