| 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> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER | 35 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 // PSM = Mozilla's Personal Security Manager. | 38 // PSM = Mozilla's Personal Security Manager. |
| 39 namespace psm = mozilla_security_manager; | 39 namespace psm = mozilla_security_manager; |
| 40 | 40 |
| 41 namespace net { | 41 namespace net { |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 // Helper that observes events from the NSSCertDatabase and forwards them to |
| 46 // the given CertDatabase. |
| 47 class CertNotificationForwarder : public NSSCertDatabase::Observer { |
| 48 public: |
| 49 explicit CertNotificationForwarder(CertDatabase* cert_db) |
| 50 : cert_db_(cert_db) {} |
| 51 |
| 52 virtual ~CertNotificationForwarder() {} |
| 53 |
| 54 // NSSCertDatabase::Observer implementation: |
| 55 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE { |
| 56 cert_db_->NotifyObserversOfCertAdded(cert); |
| 57 } |
| 58 |
| 59 virtual void OnCertRemoved(const X509Certificate* cert) OVERRIDE { |
| 60 cert_db_->NotifyObserversOfCertRemoved(cert); |
| 61 } |
| 62 |
| 63 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE { |
| 64 cert_db_->NotifyObserversOfCACertChanged(cert); |
| 65 } |
| 66 |
| 67 private: |
| 68 CertDatabase* cert_db_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(CertNotificationForwarder); |
| 71 }; |
| 72 |
| 45 base::LazyInstance<NSSCertDatabase>::Leaky | 73 base::LazyInstance<NSSCertDatabase>::Leaky |
| 46 g_nss_cert_database = LAZY_INSTANCE_INITIALIZER; | 74 g_nss_cert_database = LAZY_INSTANCE_INITIALIZER; |
| 47 | 75 |
| 48 } // namespace | 76 } // namespace |
| 49 | 77 |
| 50 NSSCertDatabase::ImportCertFailure::ImportCertFailure( | 78 NSSCertDatabase::ImportCertFailure::ImportCertFailure( |
| 51 const scoped_refptr<X509Certificate>& cert, | 79 const scoped_refptr<X509Certificate>& cert, |
| 52 int err) | 80 int err) |
| 53 : certificate(cert), net_error(err) {} | 81 : certificate(cert), net_error(err) {} |
| 54 | 82 |
| 55 NSSCertDatabase::ImportCertFailure::~ImportCertFailure() {} | 83 NSSCertDatabase::ImportCertFailure::~ImportCertFailure() {} |
| 56 | 84 |
| 57 // static | 85 // static |
| 58 NSSCertDatabase* NSSCertDatabase::GetInstance() { | 86 NSSCertDatabase* NSSCertDatabase::GetInstance() { |
| 59 // TODO(mattm): Remove this ifdef guard once the linux impl of | 87 // TODO(mattm): Remove this ifdef guard once the linux impl of |
| 60 // GetNSSCertDatabaseForResourceContext does not call GetInstance. | 88 // GetNSSCertDatabaseForResourceContext does not call GetInstance. |
| 61 #if defined(OS_CHROMEOS) | 89 #if defined(OS_CHROMEOS) |
| 62 LOG(ERROR) << "NSSCertDatabase::GetInstance() is deprecated." | 90 LOG(ERROR) << "NSSCertDatabase::GetInstance() is deprecated." |
| 63 << "See http://crbug.com/329735."; | 91 << "See http://crbug.com/329735."; |
| 64 #endif | 92 #endif |
| 65 return &g_nss_cert_database.Get(); | 93 return &g_nss_cert_database.Get(); |
| 66 } | 94 } |
| 67 | 95 |
| 68 NSSCertDatabase::NSSCertDatabase() | 96 NSSCertDatabase::NSSCertDatabase() |
| 69 : observer_list_(new ObserverListThreadSafe<Observer>), | 97 : observer_list_(new ObserverListThreadSafe<Observer>), |
| 70 weak_factory_(this) { | 98 weak_factory_(this) { |
| 71 // This also makes sure that NSS has been initialized. | 99 // This also makes sure that NSS has been initialized. |
| 72 CertDatabase::GetInstance()->ObserveNSSCertDatabase(this); | 100 CertDatabase* cert_db = CertDatabase::GetInstance(); |
| 101 cert_notification_forwarder_.reset(new CertNotificationForwarder(cert_db)); |
| 102 AddObserver(cert_notification_forwarder_.get()); |
| 73 | 103 |
| 74 psm::EnsurePKCS12Init(); | 104 psm::EnsurePKCS12Init(); |
| 75 } | 105 } |
| 76 | 106 |
| 77 NSSCertDatabase::~NSSCertDatabase() {} | 107 NSSCertDatabase::~NSSCertDatabase() {} |
| 78 | 108 |
| 79 void NSSCertDatabase::ListCertsSync(CertificateList* certs) { | 109 void NSSCertDatabase::ListCertsSync(CertificateList* certs) { |
| 80 ListCertsImpl(crypto::ScopedPK11Slot(), certs); | 110 ListCertsImpl(crypto::ScopedPK11Slot(), certs); |
| 81 } | 111 } |
| 82 | 112 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } else { | 472 } else { |
| 443 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { | 473 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { |
| 444 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); | 474 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); |
| 445 return false; | 475 return false; |
| 446 } | 476 } |
| 447 } | 477 } |
| 448 return true; | 478 return true; |
| 449 } | 479 } |
| 450 | 480 |
| 451 } // namespace net | 481 } // namespace net |
| OLD | NEW |