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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 NSSCertDatabase::~NSSCertDatabase() {} | 75 NSSCertDatabase::~NSSCertDatabase() {} |
76 | 76 |
77 void NSSCertDatabase::ListCertsSync(CertificateList* certs) { | 77 void NSSCertDatabase::ListCertsSync(CertificateList* certs) { |
78 ListCertsImpl(certs); | 78 ListCertsImpl(certs); |
79 } | 79 } |
80 | 80 |
81 void NSSCertDatabase::ListCerts( | 81 void NSSCertDatabase::ListCerts( |
82 const base::Callback<void(scoped_ptr<CertificateList> certs)>& callback) { | 82 const base::Callback<void(scoped_ptr<CertificateList> certs)>& callback) { |
83 scoped_ptr<CertificateList> certs(new CertificateList()); | 83 scoped_ptr<CertificateList> certs(new CertificateList()); |
84 | 84 |
85 // base::Pased will NULL out |certs|, so cache the underlying pointer here. | 85 // base::Passed will NULL out |certs|, so cache the underlying pointer here. |
86 CertificateList* raw_certs = certs.get(); | 86 CertificateList* raw_certs = certs.get(); |
87 GetSlowTaskRunner()->PostTaskAndReply( | 87 GetSlowTaskRunner()->PostTaskAndReply( |
88 FROM_HERE, | 88 FROM_HERE, |
89 base::Bind(&NSSCertDatabase::ListCertsImpl, | 89 base::Bind(&NSSCertDatabase::ListCertsImpl, |
90 base::Unretained(raw_certs)), | 90 base::Unretained(raw_certs)), |
91 base::Bind(callback, base::Passed(&certs))); | 91 base::Bind(callback, base::Passed(&certs))); |
92 } | 92 } |
93 | 93 |
| 94 void NSSCertDatabase::ListCertsInSlot(const ListCertsCallback& callback, |
| 95 PK11SlotInfo* slot) { |
| 96 scoped_ptr<CertificateList> certs(new CertificateList()); |
| 97 |
| 98 // base::Passed will NULL out |certs|, so cache the underlying pointer here. |
| 99 CertificateList* raw_certs = certs.get(); |
| 100 GetSlowTaskRunner()->PostTaskAndReply( |
| 101 FROM_HERE, |
| 102 base::Bind(&NSSCertDatabase::ListCertsInSlotImpl, |
| 103 base::Passed(crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot))), |
| 104 base::Unretained(raw_certs)), |
| 105 base::Bind(callback, base::Passed(&certs))); |
| 106 } |
| 107 |
94 crypto::ScopedPK11Slot NSSCertDatabase::GetPublicSlot() const { | 108 crypto::ScopedPK11Slot NSSCertDatabase::GetPublicSlot() const { |
95 return crypto::ScopedPK11Slot(crypto::GetPublicNSSKeySlot()); | 109 return crypto::ScopedPK11Slot(crypto::GetPublicNSSKeySlot()); |
96 } | 110 } |
97 | 111 |
98 crypto::ScopedPK11Slot NSSCertDatabase::GetPrivateSlot() const { | 112 crypto::ScopedPK11Slot NSSCertDatabase::GetPrivateSlot() const { |
99 return crypto::ScopedPK11Slot(crypto::GetPrivateNSSKeySlot()); | 113 return crypto::ScopedPK11Slot(crypto::GetPrivateNSSKeySlot()); |
100 } | 114 } |
101 | 115 |
102 CryptoModule* NSSCertDatabase::GetPublicModule() const { | 116 CryptoModule* NSSCertDatabase::GetPublicModule() const { |
103 crypto::ScopedPK11Slot slot(GetPublicSlot()); | 117 crypto::ScopedPK11Slot slot(GetPublicSlot()); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 void NSSCertDatabase::RemoveObserver(Observer* observer) { | 369 void NSSCertDatabase::RemoveObserver(Observer* observer) { |
356 observer_list_->RemoveObserver(observer); | 370 observer_list_->RemoveObserver(observer); |
357 } | 371 } |
358 | 372 |
359 void NSSCertDatabase::SetSlowTaskRunnerForTest( | 373 void NSSCertDatabase::SetSlowTaskRunnerForTest( |
360 const scoped_refptr<base::TaskRunner>& task_runner) { | 374 const scoped_refptr<base::TaskRunner>& task_runner) { |
361 slow_task_runner_for_test_ = task_runner; | 375 slow_task_runner_for_test_ = task_runner; |
362 } | 376 } |
363 | 377 |
364 // static | 378 // static |
| 379 void NSSCertDatabase::ListCertsInSlotImpl(crypto::ScopedPK11Slot slot, |
| 380 CertificateList* certs) { |
| 381 CERTCertList* cert_list = PK11_ListCertsInSlot(slot.get()); |
| 382 CERTCertListNode* node; |
| 383 for (node = CERT_LIST_HEAD(cert_list); |
| 384 !CERT_LIST_END(node, cert_list); |
| 385 node = CERT_LIST_NEXT(node)) { |
| 386 certs->push_back(X509Certificate::CreateFromHandle( |
| 387 node->cert, X509Certificate::OSCertHandles())); |
| 388 } |
| 389 CERT_DestroyCertList(cert_list); |
| 390 } |
| 391 |
| 392 // static |
365 void NSSCertDatabase::ListCertsImpl(CertificateList* certs) { | 393 void NSSCertDatabase::ListCertsImpl(CertificateList* certs) { |
366 certs->clear(); | 394 certs->clear(); |
367 | 395 |
368 CERTCertList* cert_list = PK11_ListCerts(PK11CertListUnique, NULL); | 396 CERTCertList* cert_list = PK11_ListCerts(PK11CertListUnique, NULL); |
369 CERTCertListNode* node; | 397 CERTCertListNode* node; |
370 for (node = CERT_LIST_HEAD(cert_list); | 398 for (node = CERT_LIST_HEAD(cert_list); |
371 !CERT_LIST_END(node, cert_list); | 399 !CERT_LIST_END(node, cert_list); |
372 node = CERT_LIST_NEXT(node)) { | 400 node = CERT_LIST_NEXT(node)) { |
373 certs->push_back(X509Certificate::CreateFromHandle( | 401 certs->push_back(X509Certificate::CreateFromHandle( |
374 node->cert, X509Certificate::OSCertHandles())); | 402 node->cert, X509Certificate::OSCertHandles())); |
(...skipping 16 matching lines...) Expand all Loading... |
391 observer_list_->Notify(&Observer::OnCertRemoved, make_scoped_refptr(cert)); | 419 observer_list_->Notify(&Observer::OnCertRemoved, make_scoped_refptr(cert)); |
392 } | 420 } |
393 | 421 |
394 void NSSCertDatabase::NotifyObserversOfCACertChanged( | 422 void NSSCertDatabase::NotifyObserversOfCACertChanged( |
395 const X509Certificate* cert) { | 423 const X509Certificate* cert) { |
396 observer_list_->Notify( | 424 observer_list_->Notify( |
397 &Observer::OnCACertChanged, make_scoped_refptr(cert)); | 425 &Observer::OnCACertChanged, make_scoped_refptr(cert)); |
398 } | 426 } |
399 | 427 |
400 } // namespace net | 428 } // namespace net |
OLD | NEW |