| 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 "chrome/browser/chromeos/cros/cert_library.h" | 5 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/chromeos/chromeos_version.h" | 9 #include "base/chromeos/chromeos_version.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/common/net/x509_certificate_model.h" | 21 #include "chrome/common/net/x509_certificate_model.h" |
| 22 #include "chromeos/dbus/cryptohome_client.h" | 22 #include "chromeos/dbus/cryptohome_client.h" |
| 23 #include "chromeos/dbus/dbus_thread_manager.h" | 23 #include "chromeos/dbus/dbus_thread_manager.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "crypto/encryptor.h" | 25 #include "crypto/encryptor.h" |
| 26 #include "crypto/nss_util.h" | 26 #include "crypto/nss_util.h" |
| 27 #include "crypto/sha2.h" | 27 #include "crypto/sha2.h" |
| 28 #include "crypto/symmetric_key.h" | 28 #include "crypto/symmetric_key.h" |
| 29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 30 #include "net/base/cert_database.h" | 30 #include "net/base/cert_database.h" |
| 31 #include "net/base/nss_cert_database.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/l10n/l10n_util_collator.h" | 33 #include "ui/base/l10n/l10n_util_collator.h" |
| 33 #include "unicode/coll.h" // icu::Collator | 34 #include "unicode/coll.h" // icu::Collator |
| 34 | 35 |
| 35 using content::BrowserThread; | 36 using content::BrowserThread; |
| 36 | 37 |
| 37 namespace chromeos { | 38 namespace chromeos { |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 user_logged_in_(false), | 122 user_logged_in_(false), |
| 122 certificates_requested_(false), | 123 certificates_requested_(false), |
| 123 certificates_loaded_(false), | 124 certificates_loaded_(false), |
| 124 key_store_loaded_(false), | 125 key_store_loaded_(false), |
| 125 ALLOW_THIS_IN_INITIALIZER_LIST(certs_(this)), | 126 ALLOW_THIS_IN_INITIALIZER_LIST(certs_(this)), |
| 126 ALLOW_THIS_IN_INITIALIZER_LIST(user_certs_(this)), | 127 ALLOW_THIS_IN_INITIALIZER_LIST(user_certs_(this)), |
| 127 ALLOW_THIS_IN_INITIALIZER_LIST(server_certs_(this)), | 128 ALLOW_THIS_IN_INITIALIZER_LIST(server_certs_(this)), |
| 128 ALLOW_THIS_IN_INITIALIZER_LIST(server_ca_certs_(this)), | 129 ALLOW_THIS_IN_INITIALIZER_LIST(server_ca_certs_(this)), |
| 129 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 130 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 130 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 131 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 131 net::CertDatabase::AddObserver(this); | 132 net::CertDatabase::GetInstance()->AddObserver(this); |
| 132 } | 133 } |
| 133 | 134 |
| 134 ~CertLibraryImpl() { | 135 ~CertLibraryImpl() { |
| 135 DCHECK(request_task_.is_null()); | 136 DCHECK(request_task_.is_null()); |
| 136 net::CertDatabase::RemoveObserver(this); | 137 net::CertDatabase::GetInstance()->RemoveObserver(this); |
| 137 } | 138 } |
| 138 | 139 |
| 139 // CertLibrary implementation. | 140 // CertLibrary implementation. |
| 140 virtual void AddObserver(CertLibrary::Observer* observer) OVERRIDE { | 141 virtual void AddObserver(CertLibrary::Observer* observer) OVERRIDE { |
| 141 observer_list_->AddObserver(observer); | 142 observer_list_->AddObserver(observer); |
| 142 } | 143 } |
| 143 | 144 |
| 144 virtual void RemoveObserver(CertLibrary::Observer* observer) OVERRIDE { | 145 virtual void RemoveObserver(CertLibrary::Observer* observer) OVERRIDE { |
| 145 observer_list_->RemoveObserver(observer); | 146 observer_list_->RemoveObserver(observer); |
| 146 } | 147 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 return DecryptTokenWithKey(supplemental_user_key_.get(), | 236 return DecryptTokenWithKey(supplemental_user_key_.get(), |
| 236 CrosLibrary::Get()->GetCryptohomeLibrary()->GetSystemSalt(), | 237 CrosLibrary::Get()->GetCryptohomeLibrary()->GetSystemSalt(), |
| 237 encrypted_token_hex); | 238 encrypted_token_hex); |
| 238 } | 239 } |
| 239 | 240 |
| 240 // net::CertDatabase::Observer implementation. Observer added on UI thread. | 241 // net::CertDatabase::Observer implementation. Observer added on UI thread. |
| 241 virtual void OnCertTrustChanged(const net::X509Certificate* cert) OVERRIDE { | 242 virtual void OnCertTrustChanged(const net::X509Certificate* cert) OVERRIDE { |
| 242 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 243 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 243 } | 244 } |
| 244 | 245 |
| 245 virtual void OnUserCertAdded(const net::X509Certificate* cert) OVERRIDE { | 246 virtual void OnCertAdded(const net::X509Certificate* cert) OVERRIDE { |
| 246 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 247 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 247 // Only load certificates if we have completed an initial request. | 248 // Only load certificates if we have completed an initial request. |
| 248 if (certificates_loaded_) { | 249 if (certificates_loaded_) { |
| 249 BrowserThread::PostTask( | 250 BrowserThread::PostTask( |
| 250 BrowserThread::DB, FROM_HERE, | 251 BrowserThread::DB, FROM_HERE, |
| 251 base::Bind(&CertLibraryImpl::LoadCertificates, | 252 base::Bind(&CertLibraryImpl::LoadCertificates, |
| 252 base::Unretained(this))); | 253 base::Unretained(this))); |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 | 256 |
| 256 virtual void OnUserCertRemoved(const net::X509Certificate* cert) OVERRIDE { | 257 virtual void OnCertRemoved(const net::X509Certificate* cert) OVERRIDE { |
| 257 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 258 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 258 // Only load certificates if we have completed an initial request. | 259 // Only load certificates if we have completed an initial request. |
| 259 if (certificates_loaded_) { | 260 if (certificates_loaded_) { |
| 260 BrowserThread::PostTask( | 261 BrowserThread::PostTask( |
| 261 BrowserThread::DB, FROM_HERE, | 262 BrowserThread::DB, FROM_HERE, |
| 262 base::Bind(&CertLibraryImpl::LoadCertificates, | 263 base::Bind(&CertLibraryImpl::LoadCertificates, |
| 263 base::Unretained(this))); | 264 base::Unretained(this))); |
| 264 } | 265 } |
| 265 } | 266 } |
| 266 | 267 |
| 267 virtual const std::string& GetTpmTokenName() const OVERRIDE { | 268 virtual const std::string& GetTpmTokenName() const OVERRIDE { |
| 268 return tpm_token_name_; | 269 return tpm_token_name_; |
| 269 } | 270 } |
| 270 | 271 |
| 271 private: | 272 private: |
| 272 void LoadCertificates() { | 273 void LoadCertificates() { |
| 273 VLOG(1) << " Loading Certificates."; | 274 VLOG(1) << " Loading Certificates."; |
| 274 // Certificate fetch occurs on the DB thread. | 275 // Certificate fetch occurs on the DB thread. |
| 275 CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 276 CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 276 net::CertDatabase cert_db; | |
| 277 net::CertificateList* cert_list = new net::CertificateList(); | 277 net::CertificateList* cert_list = new net::CertificateList(); |
| 278 cert_db.ListCerts(cert_list); | 278 net::NSSCertDatabase::GetInstance()->ListCerts(cert_list); |
| 279 // Pass the list to the UI thread to safely update the local lists. | 279 // Pass the list to the UI thread to safely update the local lists. |
| 280 BrowserThread::PostTask( | 280 BrowserThread::PostTask( |
| 281 BrowserThread::UI, FROM_HERE, | 281 BrowserThread::UI, FROM_HERE, |
| 282 base::Bind(&CertLibraryImpl::UpdateCertificates, | 282 base::Bind(&CertLibraryImpl::UpdateCertificates, |
| 283 base::Unretained(this), cert_list)); | 283 base::Unretained(this), cert_list)); |
| 284 } | 284 } |
| 285 | 285 |
| 286 // Comparison functor for locale-sensitive sorting of certificates by name. | 286 // Comparison functor for locale-sensitive sorting of certificates by name. |
| 287 class CertNameComparator { | 287 class CertNameComparator { |
| 288 public: | 288 public: |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 net::X509Certificate* cert = GetCertificateAt(index); | 604 net::X509Certificate* cert = GetCertificateAt(index); |
| 605 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); | 605 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); |
| 606 std::string id = x509_certificate_model::GetPkcs11Id(cert_handle); | 606 std::string id = x509_certificate_model::GetPkcs11Id(cert_handle); |
| 607 if (id == pkcs11_id) | 607 if (id == pkcs11_id) |
| 608 return index; | 608 return index; |
| 609 } | 609 } |
| 610 return -1; // Not found. | 610 return -1; // Not found. |
| 611 } | 611 } |
| 612 | 612 |
| 613 } // chromeos | 613 } // chromeos |
| OLD | NEW |