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 DCHECK(slot); |
| 97 scoped_ptr<CertificateList> certs(new CertificateList()); |
| 98 |
| 99 // base::Passed will NULL out |certs|, so cache the underlying pointer here. |
| 100 CertificateList* raw_certs = certs.get(); |
| 101 scoped_refptr<base::TaskRunner> task_runner = GetSlowTaskRunner(); |
| 102 // PostTaskAndReply doesn't work if called from a TaskRunner without message |
| 103 // loop, e.g. from a worker thread. |
| 104 if (task_runner->RunsTasksOnCurrentThread()) { |
| 105 ListCertsInSlotImpl(crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot)), |
| 106 certs.get()); |
| 107 task_runner->PostTask(FROM_HERE, |
| 108 base::Bind(callback, base::Passed(&certs))); |
| 109 } else { |
| 110 task_runner->PostTaskAndReply( |
| 111 FROM_HERE, |
| 112 base::Bind( |
| 113 &NSSCertDatabase::ListCertsInSlotImpl, |
| 114 base::Passed(crypto::ScopedPK11Slot(PK11_ReferenceSlot(slot))), |
| 115 base::Unretained(raw_certs)), |
| 116 base::Bind(callback, base::Passed(&certs))); |
| 117 } |
| 118 } |
| 119 |
94 crypto::ScopedPK11Slot NSSCertDatabase::GetPublicSlot() const { | 120 crypto::ScopedPK11Slot NSSCertDatabase::GetPublicSlot() const { |
95 return crypto::ScopedPK11Slot(crypto::GetPublicNSSKeySlot()); | 121 return crypto::ScopedPK11Slot(crypto::GetPublicNSSKeySlot()); |
96 } | 122 } |
97 | 123 |
98 crypto::ScopedPK11Slot NSSCertDatabase::GetPrivateSlot() const { | 124 crypto::ScopedPK11Slot NSSCertDatabase::GetPrivateSlot() const { |
99 return crypto::ScopedPK11Slot(crypto::GetPrivateNSSKeySlot()); | 125 return crypto::ScopedPK11Slot(crypto::GetPrivateNSSKeySlot()); |
100 } | 126 } |
101 | 127 |
102 CryptoModule* NSSCertDatabase::GetPublicModule() const { | 128 CryptoModule* NSSCertDatabase::GetPublicModule() const { |
103 crypto::ScopedPK11Slot slot(GetPublicSlot()); | 129 crypto::ScopedPK11Slot slot(GetPublicSlot()); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 void NSSCertDatabase::RemoveObserver(Observer* observer) { | 381 void NSSCertDatabase::RemoveObserver(Observer* observer) { |
356 observer_list_->RemoveObserver(observer); | 382 observer_list_->RemoveObserver(observer); |
357 } | 383 } |
358 | 384 |
359 void NSSCertDatabase::SetSlowTaskRunnerForTest( | 385 void NSSCertDatabase::SetSlowTaskRunnerForTest( |
360 const scoped_refptr<base::TaskRunner>& task_runner) { | 386 const scoped_refptr<base::TaskRunner>& task_runner) { |
361 slow_task_runner_for_test_ = task_runner; | 387 slow_task_runner_for_test_ = task_runner; |
362 } | 388 } |
363 | 389 |
364 // static | 390 // static |
| 391 void NSSCertDatabase::ListCertsInSlotImpl(crypto::ScopedPK11Slot slot, |
| 392 CertificateList* certs) { |
| 393 DCHECK(slot); |
| 394 CERTCertList* cert_list = PK11_ListCertsInSlot(slot.get()); |
| 395 CERTCertListNode* node; |
| 396 for (node = CERT_LIST_HEAD(cert_list); !CERT_LIST_END(node, cert_list); |
| 397 node = CERT_LIST_NEXT(node)) { |
| 398 certs->push_back(X509Certificate::CreateFromHandle( |
| 399 node->cert, X509Certificate::OSCertHandles())); |
| 400 } |
| 401 CERT_DestroyCertList(cert_list); |
| 402 } |
| 403 |
| 404 // static |
365 void NSSCertDatabase::ListCertsImpl(CertificateList* certs) { | 405 void NSSCertDatabase::ListCertsImpl(CertificateList* certs) { |
366 certs->clear(); | 406 certs->clear(); |
367 | 407 |
368 CERTCertList* cert_list = PK11_ListCerts(PK11CertListUnique, NULL); | 408 CERTCertList* cert_list = PK11_ListCerts(PK11CertListUnique, NULL); |
369 CERTCertListNode* node; | 409 CERTCertListNode* node; |
370 for (node = CERT_LIST_HEAD(cert_list); | 410 for (node = CERT_LIST_HEAD(cert_list); |
371 !CERT_LIST_END(node, cert_list); | 411 !CERT_LIST_END(node, cert_list); |
372 node = CERT_LIST_NEXT(node)) { | 412 node = CERT_LIST_NEXT(node)) { |
373 certs->push_back(X509Certificate::CreateFromHandle( | 413 certs->push_back(X509Certificate::CreateFromHandle( |
374 node->cert, X509Certificate::OSCertHandles())); | 414 node->cert, X509Certificate::OSCertHandles())); |
(...skipping 16 matching lines...) Expand all Loading... |
391 observer_list_->Notify(&Observer::OnCertRemoved, make_scoped_refptr(cert)); | 431 observer_list_->Notify(&Observer::OnCertRemoved, make_scoped_refptr(cert)); |
392 } | 432 } |
393 | 433 |
394 void NSSCertDatabase::NotifyObserversOfCACertChanged( | 434 void NSSCertDatabase::NotifyObserversOfCACertChanged( |
395 const X509Certificate* cert) { | 435 const X509Certificate* cert) { |
396 observer_list_->Notify( | 436 observer_list_->Notify( |
397 &Observer::OnCACertChanged, make_scoped_refptr(cert)); | 437 &Observer::OnCACertChanged, make_scoped_refptr(cert)); |
398 } | 438 } |
399 | 439 |
400 } // namespace net | 440 } // namespace net |
OLD | NEW |