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 #include "net/cert/nss_cert_database.h" | 5 #include "net/cert/nss_cert_database.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <certdb.h> | 8 #include <certdb.h> |
| 9 #include <keyhi.h> | 9 #include <keyhi.h> |
| 10 #include <pk11pub.h> | 10 #include <pk11pub.h> |
| 11 #include <secmod.h> | 11 #include <secmod.h> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/lazy_instance.h" | |
| 16 #include "base/logging.h" | 15 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/observer_list_threadsafe.h" | 17 #include "base/observer_list_threadsafe.h" |
| 19 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
| 20 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
| 21 #include "base/threading/worker_pool.h" | 20 #include "base/threading/worker_pool.h" |
| 22 #include "crypto/nss_util.h" | |
| 23 #include "crypto/nss_util_internal.h" | |
| 24 #include "crypto/scoped_nss_types.h" | 21 #include "crypto/scoped_nss_types.h" |
| 25 #include "net/base/crypto_module.h" | 22 #include "net/base/crypto_module.h" |
| 26 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 27 #include "net/cert/cert_database.h" | 24 #include "net/cert/cert_database.h" |
| 28 #include "net/cert/x509_certificate.h" | 25 #include "net/cert/x509_certificate.h" |
| 29 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" | 26 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" |
| 30 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" | 27 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" |
| 31 | 28 |
| 32 // In NSS 3.13, CERTDB_VALID_PEER was renamed CERTDB_TERMINAL_RECORD. So we use | 29 // In NSS 3.13, CERTDB_VALID_PEER was renamed CERTDB_TERMINAL_RECORD. So we use |
| 33 // the new name of the macro. | 30 // the new name of the macro. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 63 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE { | 60 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE { |
| 64 cert_db_->NotifyObserversOfCACertChanged(cert); | 61 cert_db_->NotifyObserversOfCACertChanged(cert); |
| 65 } | 62 } |
| 66 | 63 |
| 67 private: | 64 private: |
| 68 CertDatabase* cert_db_; | 65 CertDatabase* cert_db_; |
| 69 | 66 |
| 70 DISALLOW_COPY_AND_ASSIGN(CertNotificationForwarder); | 67 DISALLOW_COPY_AND_ASSIGN(CertNotificationForwarder); |
| 71 }; | 68 }; |
| 72 | 69 |
| 73 base::LazyInstance<NSSCertDatabase>::Leaky | |
| 74 g_nss_cert_database = LAZY_INSTANCE_INITIALIZER; | |
| 75 | |
| 76 } // namespace | 70 } // namespace |
| 77 | 71 |
| 78 NSSCertDatabase::ImportCertFailure::ImportCertFailure( | 72 NSSCertDatabase::ImportCertFailure::ImportCertFailure( |
| 79 const scoped_refptr<X509Certificate>& cert, | 73 const scoped_refptr<X509Certificate>& cert, |
| 80 int err) | 74 int err) |
| 81 : certificate(cert), net_error(err) {} | 75 : certificate(cert), net_error(err) {} |
| 82 | 76 |
| 83 NSSCertDatabase::ImportCertFailure::~ImportCertFailure() {} | 77 NSSCertDatabase::ImportCertFailure::~ImportCertFailure() {} |
| 84 | 78 |
| 85 // static | 79 NSSCertDatabase::NSSCertDatabase(crypto::ScopedPK11Slot persistent_slot) |
| 86 NSSCertDatabase* NSSCertDatabase::GetInstance() { | 80 : persistent_slot_(persistent_slot.Pass()), |
| 87 // TODO(mattm): Remove this ifdef guard once the linux impl of | 81 observer_list_(new ObserverListThreadSafe<Observer>), |
| 88 // GetNSSCertDatabaseForResourceContext does not call GetInstance. | |
| 89 #if defined(OS_CHROMEOS) | |
| 90 LOG(ERROR) << "NSSCertDatabase::GetInstance() is deprecated." | |
| 91 << "See http://crbug.com/329735."; | |
| 92 #endif | |
| 93 return &g_nss_cert_database.Get(); | |
| 94 } | |
| 95 | |
| 96 NSSCertDatabase::NSSCertDatabase() | |
| 97 : observer_list_(new ObserverListThreadSafe<Observer>), | |
| 98 weak_factory_(this) { | 82 weak_factory_(this) { |
| 99 // This also makes sure that NSS has been initialized. | 83 // This also makes sure that NSS has been initialized. |
| 100 CertDatabase* cert_db = CertDatabase::GetInstance(); | 84 CertDatabase* cert_db = CertDatabase::GetInstance(); |
| 101 cert_notification_forwarder_.reset(new CertNotificationForwarder(cert_db)); | 85 cert_notification_forwarder_.reset(new CertNotificationForwarder(cert_db)); |
| 102 AddObserver(cert_notification_forwarder_.get()); | 86 AddObserver(cert_notification_forwarder_.get()); |
| 103 | 87 |
| 104 psm::EnsurePKCS12Init(); | 88 psm::EnsurePKCS12Init(); |
| 105 } | 89 } |
| 106 | 90 |
| 107 NSSCertDatabase::~NSSCertDatabase() {} | 91 NSSCertDatabase::~NSSCertDatabase() {} |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 133 CertificateList* raw_certs = certs.get(); | 117 CertificateList* raw_certs = certs.get(); |
| 134 GetSlowTaskRunner()->PostTaskAndReply( | 118 GetSlowTaskRunner()->PostTaskAndReply( |
| 135 FROM_HERE, | 119 FROM_HERE, |
| 136 base::Bind(&NSSCertDatabase::ListCertsImpl, | 120 base::Bind(&NSSCertDatabase::ListCertsImpl, |
| 137 base::Passed(crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot))), | 121 base::Passed(crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot))), |
| 138 base::Unretained(raw_certs)), | 122 base::Unretained(raw_certs)), |
| 139 base::Bind(callback, base::Passed(&certs))); | 123 base::Bind(callback, base::Passed(&certs))); |
| 140 } | 124 } |
| 141 | 125 |
| 142 crypto::ScopedPK11Slot NSSCertDatabase::GetPublicSlot() const { | 126 crypto::ScopedPK11Slot NSSCertDatabase::GetPublicSlot() const { |
| 143 return crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot()); | 127 if (!persistent_slot_) |
| 128 return crypto::ScopedPK11Slot(); | |
|
Ryan Sleevi
2014/07/22 01:18:32
Why is NULL valid? Requires updating the header fi
pneubeck (no reviews)
2014/07/22 08:23:56
Done.
Note that the DCHECK (PK11_REferenceSlot sh
| |
| 129 return crypto::ScopedPK11Slot(PK11_ReferenceSlot(persistent_slot_.get())); | |
| 144 } | 130 } |
| 145 | 131 |
| 146 crypto::ScopedPK11Slot NSSCertDatabase::GetPrivateSlot() const { | 132 crypto::ScopedPK11Slot NSSCertDatabase::GetPrivateSlot() const { |
| 147 return crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot()); | 133 if (!persistent_slot_) |
| 134 return crypto::ScopedPK11Slot(); | |
| 135 return crypto::ScopedPK11Slot(PK11_ReferenceSlot(persistent_slot_.get())); | |
| 148 } | 136 } |
| 149 | 137 |
| 150 CryptoModule* NSSCertDatabase::GetPublicModule() const { | 138 CryptoModule* NSSCertDatabase::GetPublicModule() const { |
| 151 crypto::ScopedPK11Slot slot(GetPublicSlot()); | 139 crypto::ScopedPK11Slot slot(GetPublicSlot()); |
| 152 return CryptoModule::CreateFromHandle(slot.get()); | 140 return CryptoModule::CreateFromHandle(slot.get()); |
| 153 } | 141 } |
| 154 | 142 |
| 155 CryptoModule* NSSCertDatabase::GetPrivateModule() const { | 143 CryptoModule* NSSCertDatabase::GetPrivateModule() const { |
| 156 crypto::ScopedPK11Slot slot(GetPrivateSlot()); | 144 crypto::ScopedPK11Slot slot(GetPrivateSlot()); |
| 157 return CryptoModule::CreateFromHandle(slot.get()); | 145 return CryptoModule::CreateFromHandle(slot.get()); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 } else { | 460 } else { |
| 473 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { | 461 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { |
| 474 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); | 462 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); |
| 475 return false; | 463 return false; |
| 476 } | 464 } |
| 477 } | 465 } |
| 478 return true; | 466 return true; |
| 479 } | 467 } |
| 480 | 468 |
| 481 } // namespace net | 469 } // namespace net |
| OLD | NEW |