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" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/observer_list_threadsafe.h" | 18 #include "base/observer_list_threadsafe.h" |
| 19 #include "base/task_runner.h" | 19 #include "base/task_runner.h" |
| 20 #include "base/task_runner_util.h" | 20 #include "base/task_runner_util.h" |
| 21 #include "base/threading/worker_pool.h" | 21 #include "base/threading/worker_pool.h" |
| 22 #include "crypto/nss_util.h" | 22 #include "crypto/nss_util.h" |
| 23 #include "crypto/nss_util_internal.h" | 23 #include "crypto/nss_util_internal.h" |
| 24 #include "crypto/scoped_nss_types.h" | 24 #include "crypto/scoped_nss_types.h" |
| 25 #include "net/base/crypto_module.h" | 25 #include "net/base/crypto_module.h" |
| 26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 27 #include "net/cert/cert_database.h" | |
| 28 #include "net/cert/x509_certificate.h" | 27 #include "net/cert/x509_certificate.h" |
| 29 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" | 28 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" |
| 30 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" | 29 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" |
| 31 | 30 |
| 32 // In NSS 3.13, CERTDB_VALID_PEER was renamed CERTDB_TERMINAL_RECORD. So we use | 31 // In NSS 3.13, CERTDB_VALID_PEER was renamed CERTDB_TERMINAL_RECORD. So we use |
| 33 // the new name of the macro. | 32 // the new name of the macro. |
| 34 #if !defined(CERTDB_TERMINAL_RECORD) | 33 #if !defined(CERTDB_TERMINAL_RECORD) |
| 35 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER | 34 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER |
| 36 #endif | 35 #endif |
| 37 | 36 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 61 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
| 62 LOG(ERROR) << "NSSCertDatabase::GetInstance() is deprecated." | 61 LOG(ERROR) << "NSSCertDatabase::GetInstance() is deprecated." |
| 63 << "See http://crbug.com/329735."; | 62 << "See http://crbug.com/329735."; |
| 64 #endif | 63 #endif |
| 65 return &g_nss_cert_database.Get(); | 64 return &g_nss_cert_database.Get(); |
| 66 } | 65 } |
| 67 | 66 |
| 68 NSSCertDatabase::NSSCertDatabase() | 67 NSSCertDatabase::NSSCertDatabase() |
| 69 : observer_list_(new ObserverListThreadSafe<Observer>), | 68 : observer_list_(new ObserverListThreadSafe<Observer>), |
| 70 weak_factory_(this) { | 69 weak_factory_(this) { |
| 71 // This also makes sure that NSS has been initialized. | 70 AddObserver(CertDatabase::GetInstance()->GetObserver()); |
| 72 CertDatabase::GetInstance()->ObserveNSSCertDatabase(this); | |
| 73 | 71 |
| 72 // This makes sure that NSS has been initialized. | |
|
mattm
2014/07/08 21:13:06
previous comment was correct (CertDatabase constru
| |
| 74 psm::EnsurePKCS12Init(); | 73 psm::EnsurePKCS12Init(); |
| 75 } | 74 } |
| 76 | 75 |
| 77 NSSCertDatabase::~NSSCertDatabase() {} | 76 NSSCertDatabase::~NSSCertDatabase() {} |
| 78 | 77 |
| 79 void NSSCertDatabase::ListCertsSync(CertificateList* certs) { | 78 void NSSCertDatabase::ListCertsSync(CertificateList* certs) { |
| 80 ListCertsImpl(crypto::ScopedPK11Slot(), certs); | 79 ListCertsImpl(crypto::ScopedPK11Slot(), certs); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void NSSCertDatabase::ListCerts( | 82 void NSSCertDatabase::ListCerts( |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 bool NSSCertDatabase::IsReadOnly(const X509Certificate* cert) const { | 353 bool NSSCertDatabase::IsReadOnly(const X509Certificate* cert) const { |
| 355 PK11SlotInfo* slot = cert->os_cert_handle()->slot; | 354 PK11SlotInfo* slot = cert->os_cert_handle()->slot; |
| 356 return slot && PK11_IsReadOnly(slot); | 355 return slot && PK11_IsReadOnly(slot); |
| 357 } | 356 } |
| 358 | 357 |
| 359 bool NSSCertDatabase::IsHardwareBacked(const X509Certificate* cert) const { | 358 bool NSSCertDatabase::IsHardwareBacked(const X509Certificate* cert) const { |
| 360 PK11SlotInfo* slot = cert->os_cert_handle()->slot; | 359 PK11SlotInfo* slot = cert->os_cert_handle()->slot; |
| 361 return slot && PK11_IsHW(slot); | 360 return slot && PK11_IsHW(slot); |
| 362 } | 361 } |
| 363 | 362 |
| 364 void NSSCertDatabase::AddObserver(Observer* observer) { | 363 void NSSCertDatabase::AddObserver(CertDatabase::Observer* observer) { |
| 365 observer_list_->AddObserver(observer); | 364 observer_list_->AddObserver(observer); |
| 366 } | 365 } |
| 367 | 366 |
| 368 void NSSCertDatabase::RemoveObserver(Observer* observer) { | 367 void NSSCertDatabase::RemoveObserver(CertDatabase::Observer* observer) { |
| 369 observer_list_->RemoveObserver(observer); | 368 observer_list_->RemoveObserver(observer); |
| 370 } | 369 } |
| 371 | 370 |
| 372 void NSSCertDatabase::SetSlowTaskRunnerForTest( | 371 void NSSCertDatabase::SetSlowTaskRunnerForTest( |
| 373 const scoped_refptr<base::TaskRunner>& task_runner) { | 372 const scoped_refptr<base::TaskRunner>& task_runner) { |
| 374 slow_task_runner_for_test_ = task_runner; | 373 slow_task_runner_for_test_ = task_runner; |
| 375 } | 374 } |
| 376 | 375 |
| 377 // static | 376 // static |
| 378 void NSSCertDatabase::ListCertsImpl(crypto::ScopedPK11Slot slot, | 377 void NSSCertDatabase::ListCertsImpl(crypto::ScopedPK11Slot slot, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 } else { | 441 } else { |
| 443 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { | 442 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { |
| 444 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); | 443 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); |
| 445 return false; | 444 return false; |
| 446 } | 445 } |
| 447 } | 446 } |
| 448 return true; | 447 return true; |
| 449 } | 448 } |
| 450 | 449 |
| 451 } // namespace net | 450 } // namespace net |
| OLD | NEW |