| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_chromeos.h" | 5 #include "net/cert/nss_cert_database_chromeos.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 16 #include "net/base/crypto_module.h" | 16 #include "net/base/crypto_module.h" |
| 17 #include "net/cert/x509_certificate.h" | 17 #include "net/cert/x509_certificate.h" |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 NSSCertDatabaseChromeOS::NSSCertDatabaseChromeOS( | 21 NSSCertDatabaseChromeOS::NSSCertDatabaseChromeOS( |
| 22 crypto::ScopedPK11Slot public_slot, | 22 crypto::ScopedPK11Slot public_slot, |
| 23 crypto::ScopedPK11Slot private_slot) | 23 crypto::ScopedPK11Slot private_slot) |
| 24 : public_slot_(public_slot.Pass()), | 24 : NSSCertDatabase(public_slot.Pass(), private_slot.Pass()) { |
| 25 private_slot_(private_slot.Pass()) { | |
| 26 profile_filter_.Init(GetPublicSlot(), GetPrivateSlot()); | 25 profile_filter_.Init(GetPublicSlot(), GetPrivateSlot()); |
| 27 } | 26 } |
| 28 | 27 |
| 29 NSSCertDatabaseChromeOS::~NSSCertDatabaseChromeOS() {} | 28 NSSCertDatabaseChromeOS::~NSSCertDatabaseChromeOS() {} |
| 30 | 29 |
| 31 void NSSCertDatabaseChromeOS::ListCertsSync(CertificateList* certs) { | 30 void NSSCertDatabaseChromeOS::ListCertsSync(CertificateList* certs) { |
| 32 ListCertsImpl(profile_filter_, certs); | 31 ListCertsImpl(profile_filter_, certs); |
| 33 } | 32 } |
| 34 | 33 |
| 35 void NSSCertDatabaseChromeOS::ListCerts( | 34 void NSSCertDatabaseChromeOS::ListCerts( |
| 36 const base::Callback<void(scoped_ptr<CertificateList> certs)>& callback) { | 35 const base::Callback<void(scoped_ptr<CertificateList> certs)>& callback) { |
| 37 scoped_ptr<CertificateList> certs(new CertificateList()); | 36 scoped_ptr<CertificateList> certs(new CertificateList()); |
| 38 | 37 |
| 39 // base::Pased will NULL out |certs|, so cache the underlying pointer here. | 38 // base::Pased will NULL out |certs|, so cache the underlying pointer here. |
| 40 CertificateList* raw_certs = certs.get(); | 39 CertificateList* raw_certs = certs.get(); |
| 41 GetSlowTaskRunner()->PostTaskAndReply( | 40 GetSlowTaskRunner()->PostTaskAndReply( |
| 42 FROM_HERE, | 41 FROM_HERE, |
| 43 base::Bind(&NSSCertDatabaseChromeOS::ListCertsImpl, | 42 base::Bind(&NSSCertDatabaseChromeOS::ListCertsImpl, |
| 44 profile_filter_, | 43 profile_filter_, |
| 45 base::Unretained(raw_certs)), | 44 base::Unretained(raw_certs)), |
| 46 base::Bind(callback, base::Passed(&certs))); | 45 base::Bind(callback, base::Passed(&certs))); |
| 47 } | 46 } |
| 48 | 47 |
| 49 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPublicSlot() const { | |
| 50 return crypto::ScopedPK11Slot( | |
| 51 public_slot_ ? PK11_ReferenceSlot(public_slot_.get()) : NULL); | |
| 52 } | |
| 53 | |
| 54 crypto::ScopedPK11Slot NSSCertDatabaseChromeOS::GetPrivateSlot() const { | |
| 55 return crypto::ScopedPK11Slot( | |
| 56 private_slot_ ? PK11_ReferenceSlot(private_slot_.get()) : NULL); | |
| 57 } | |
| 58 | |
| 59 void NSSCertDatabaseChromeOS::ListModules(CryptoModuleList* modules, | 48 void NSSCertDatabaseChromeOS::ListModules(CryptoModuleList* modules, |
| 60 bool need_rw) const { | 49 bool need_rw) const { |
| 61 NSSCertDatabase::ListModules(modules, need_rw); | 50 NSSCertDatabase::ListModules(modules, need_rw); |
| 62 | 51 |
| 63 size_t pre_size = modules->size(); | 52 size_t pre_size = modules->size(); |
| 64 modules->erase( | 53 modules->erase( |
| 65 std::remove_if( | 54 std::remove_if( |
| 66 modules->begin(), | 55 modules->begin(), |
| 67 modules->end(), | 56 modules->end(), |
| 68 NSSProfileFilterChromeOS::ModuleNotAllowedForProfilePredicate( | 57 NSSProfileFilterChromeOS::ModuleNotAllowedForProfilePredicate( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 82 certs->begin(), | 71 certs->begin(), |
| 83 certs->end(), | 72 certs->end(), |
| 84 NSSProfileFilterChromeOS::CertNotAllowedForProfilePredicate( | 73 NSSProfileFilterChromeOS::CertNotAllowedForProfilePredicate( |
| 85 profile_filter)), | 74 profile_filter)), |
| 86 certs->end()); | 75 certs->end()); |
| 87 DVLOG(1) << "filtered " << pre_size - certs->size() << " of " << pre_size | 76 DVLOG(1) << "filtered " << pre_size - certs->size() << " of " << pre_size |
| 88 << " certs"; | 77 << " certs"; |
| 89 } | 78 } |
| 90 | 79 |
| 91 } // namespace net | 80 } // namespace net |
| OLD | NEW |