Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: net/cert/nss_cert_database.cc

Issue 405973003: Remove the deprecated NSSCertDatabase::GetInstance() . (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.
34 #if !defined(CERTDB_TERMINAL_RECORD) 31 #if !defined(CERTDB_TERMINAL_RECORD)
35 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER 32 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER
36 #endif 33 #endif
37 34
38 // PSM = Mozilla's Personal Security Manager. 35 // PSM = Mozilla's Personal Security Manager.
39 namespace psm = mozilla_security_manager; 36 namespace psm = mozilla_security_manager;
40 37
41 namespace net { 38 namespace net {
42 39
43 namespace { 40 namespace {
44 41
42 // TODO(pneubeck): Move this class to chrome/browser/net/nss_context .
Ryan Sleevi 2014/07/22 08:31:58 TODO with a bug #? Feels gross mentioning //chrom
pneubeck (no reviews) 2014/07/22 09:51:50 Done.
45 // Helper that observes events from the NSSCertDatabase and forwards them to 43 // Helper that observes events from the NSSCertDatabase and forwards them to
46 // the given CertDatabase. 44 // the given CertDatabase.
47 class CertNotificationForwarder : public NSSCertDatabase::Observer { 45 class CertNotificationForwarder : public NSSCertDatabase::Observer {
48 public: 46 public:
49 explicit CertNotificationForwarder(CertDatabase* cert_db) 47 explicit CertNotificationForwarder(CertDatabase* cert_db)
50 : cert_db_(cert_db) {} 48 : cert_db_(cert_db) {}
51 49
52 virtual ~CertNotificationForwarder() {} 50 virtual ~CertNotificationForwarder() {}
53 51
54 // NSSCertDatabase::Observer implementation: 52 // NSSCertDatabase::Observer implementation:
55 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE { 53 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE {
56 cert_db_->NotifyObserversOfCertAdded(cert); 54 cert_db_->NotifyObserversOfCertAdded(cert);
57 } 55 }
58 56
59 virtual void OnCertRemoved(const X509Certificate* cert) OVERRIDE { 57 virtual void OnCertRemoved(const X509Certificate* cert) OVERRIDE {
60 cert_db_->NotifyObserversOfCertRemoved(cert); 58 cert_db_->NotifyObserversOfCertRemoved(cert);
61 } 59 }
62 60
63 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE { 61 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE {
64 cert_db_->NotifyObserversOfCACertChanged(cert); 62 cert_db_->NotifyObserversOfCACertChanged(cert);
65 } 63 }
66 64
67 private: 65 private:
68 CertDatabase* cert_db_; 66 CertDatabase* cert_db_;
69 67
70 DISALLOW_COPY_AND_ASSIGN(CertNotificationForwarder); 68 DISALLOW_COPY_AND_ASSIGN(CertNotificationForwarder);
71 }; 69 };
72 70
73 base::LazyInstance<NSSCertDatabase>::Leaky
74 g_nss_cert_database = LAZY_INSTANCE_INITIALIZER;
75
76 } // namespace 71 } // namespace
77 72
78 NSSCertDatabase::ImportCertFailure::ImportCertFailure( 73 NSSCertDatabase::ImportCertFailure::ImportCertFailure(
79 const scoped_refptr<X509Certificate>& cert, 74 const scoped_refptr<X509Certificate>& cert,
80 int err) 75 int err)
81 : certificate(cert), net_error(err) {} 76 : certificate(cert), net_error(err) {}
82 77
83 NSSCertDatabase::ImportCertFailure::~ImportCertFailure() {} 78 NSSCertDatabase::ImportCertFailure::~ImportCertFailure() {}
84 79
85 // static 80 NSSCertDatabase::NSSCertDatabase(crypto::ScopedPK11Slot persistent_slot)
86 NSSCertDatabase* NSSCertDatabase::GetInstance() { 81 : persistent_slot_(persistent_slot.Pass()),
87 // TODO(mattm): Remove this ifdef guard once the linux impl of 82 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) { 83 weak_factory_(this) {
99 // This also makes sure that NSS has been initialized. 84 // This also makes sure that NSS has been initialized.
100 CertDatabase* cert_db = CertDatabase::GetInstance(); 85 CertDatabase* cert_db = CertDatabase::GetInstance();
101 cert_notification_forwarder_.reset(new CertNotificationForwarder(cert_db)); 86 cert_notification_forwarder_.reset(new CertNotificationForwarder(cert_db));
102 AddObserver(cert_notification_forwarder_.get()); 87 AddObserver(cert_notification_forwarder_.get());
103 88
104 psm::EnsurePKCS12Init(); 89 psm::EnsurePKCS12Init();
105 } 90 }
106 91
107 NSSCertDatabase::~NSSCertDatabase() {} 92 NSSCertDatabase::~NSSCertDatabase() {}
(...skipping 25 matching lines...) Expand all
133 CertificateList* raw_certs = certs.get(); 118 CertificateList* raw_certs = certs.get();
134 GetSlowTaskRunner()->PostTaskAndReply( 119 GetSlowTaskRunner()->PostTaskAndReply(
135 FROM_HERE, 120 FROM_HERE,
136 base::Bind(&NSSCertDatabase::ListCertsImpl, 121 base::Bind(&NSSCertDatabase::ListCertsImpl,
137 base::Passed(crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot))), 122 base::Passed(crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot))),
138 base::Unretained(raw_certs)), 123 base::Unretained(raw_certs)),
139 base::Bind(callback, base::Passed(&certs))); 124 base::Bind(callback, base::Passed(&certs)));
140 } 125 }
141 126
142 crypto::ScopedPK11Slot NSSCertDatabase::GetPublicSlot() const { 127 crypto::ScopedPK11Slot NSSCertDatabase::GetPublicSlot() const {
143 return crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot()); 128 DCHECK(persistent_slot_);
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 DCHECK(persistent_slot_);
134 return crypto::ScopedPK11Slot(PK11_ReferenceSlot(persistent_slot_.get()));
148 } 135 }
149 136
150 CryptoModule* NSSCertDatabase::GetPublicModule() const { 137 CryptoModule* NSSCertDatabase::GetPublicModule() const {
151 crypto::ScopedPK11Slot slot(GetPublicSlot()); 138 crypto::ScopedPK11Slot slot(GetPublicSlot());
152 return CryptoModule::CreateFromHandle(slot.get()); 139 return CryptoModule::CreateFromHandle(slot.get());
153 } 140 }
154 141
155 CryptoModule* NSSCertDatabase::GetPrivateModule() const { 142 CryptoModule* NSSCertDatabase::GetPrivateModule() const {
156 crypto::ScopedPK11Slot slot(GetPrivateSlot()); 143 crypto::ScopedPK11Slot slot(GetPrivateSlot());
157 return CryptoModule::CreateFromHandle(slot.get()); 144 return CryptoModule::CreateFromHandle(slot.get());
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 } else { 459 } else {
473 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { 460 if (SEC_DeletePermCertificate(cert->os_cert_handle())) {
474 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); 461 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError();
475 return false; 462 return false;
476 } 463 }
477 } 464 }
478 return true; 465 return true;
479 } 466 }
480 467
481 } // namespace net 468 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698