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/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
11 #include "base/observer_list_threadsafe.h" | 12 #include "base/observer_list_threadsafe.h" |
12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" // g_browser_process | 16 #include "chrome/browser/browser_process.h" // g_browser_process |
16 #include "chrome/browser/chromeos/cros/cros_library.h" | 17 #include "chrome/browser/chromeos/cros/cros_library.h" |
17 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 18 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
18 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 crypto::OpenPersistentNSSDB(); | 148 crypto::OpenPersistentNSSDB(); |
148 | 149 |
149 // Only load the Opencryptoki library into NSS if we have this switch. | 150 // Only load the Opencryptoki library into NSS if we have this switch. |
150 // TODO(gspencer): Remove this switch once cryptohomed work is finished: | 151 // TODO(gspencer): Remove this switch once cryptohomed work is finished: |
151 // http://crosbug.com/12295 and 12304 | 152 // http://crosbug.com/12295 and 12304 |
152 // Note: ChromeOS login with or without loginmanager will crash when | 153 // Note: ChromeOS login with or without loginmanager will crash when |
153 // the CertLibrary is not there (http://crosbug.com/121456). Before removing | 154 // the CertLibrary is not there (http://crosbug.com/121456). Before removing |
154 // make sure that that case still works. | 155 // make sure that that case still works. |
155 if (CommandLine::ForCurrentProcess()->HasSwitch( | 156 if (CommandLine::ForCurrentProcess()->HasSwitch( |
156 switches::kLoadOpencryptoki) || | 157 switches::kLoadOpencryptoki) || |
157 CommandLine::ForCurrentProcess()->HasSwitch(switches::kStubCros)) { | 158 !base::chromeos::IsRunningOnChromeOS()) { |
158 crypto::EnableTPMTokenForNSS(); | 159 crypto::EnableTPMTokenForNSS(); |
159 // Note: this calls crypto::EnsureTPMTokenReady() | 160 // Note: this calls crypto::EnsureTPMTokenReady() |
160 RequestCertificates(); | 161 RequestCertificates(); |
161 } | 162 } |
162 key_store_loaded_ = true; | 163 key_store_loaded_ = true; |
163 } | 164 } |
164 | 165 |
165 virtual bool CertificatesLoading() const OVERRIDE { | 166 virtual bool CertificatesLoading() const OVERRIDE { |
166 return certificates_requested_ && !certificates_loaded_; | 167 return certificates_requested_ && !certificates_loaded_; |
167 } | 168 } |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 DISALLOW_COPY_AND_ASSIGN(CertLibraryImpl); | 521 DISALLOW_COPY_AND_ASSIGN(CertLibraryImpl); |
521 }; | 522 }; |
522 | 523 |
523 ////////////////////////////////////////////////////////////////////////////// | 524 ////////////////////////////////////////////////////////////////////////////// |
524 | 525 |
525 CertLibrary::~CertLibrary() { | 526 CertLibrary::~CertLibrary() { |
526 } | 527 } |
527 | 528 |
528 // static | 529 // static |
529 CertLibrary* CertLibrary::GetImpl(bool stub) { | 530 CertLibrary* CertLibrary::GetImpl(bool stub) { |
530 // No libcros dependencies, so always return CertLibraryImpl() (no stub). | 531 // |stub| is ignored since we have no stub of CertLibrary. |
| 532 // TODO(stevenjb): Disassociate CertLibrary from CrosLibrary entirely. |
| 533 // crbug.com/133752 |
531 return new CertLibraryImpl(); | 534 return new CertLibraryImpl(); |
532 } | 535 } |
533 | 536 |
534 ////////////////////////////////////////////////////////////////////////////// | 537 ////////////////////////////////////////////////////////////////////////////// |
535 | 538 |
536 net::X509Certificate* CertLibrary::CertList::GetCertificateAt(int index) const { | 539 net::X509Certificate* CertLibrary::CertList::GetCertificateAt(int index) const { |
537 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 540 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
538 DCHECK_GE(index, 0); | 541 DCHECK_GE(index, 0); |
539 DCHECK_LT(index, static_cast<int>(list_.size())); | 542 DCHECK_LT(index, static_cast<int>(list_.size())); |
540 return list_[index].get(); | 543 return list_[index].get(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 net::X509Certificate* cert = GetCertificateAt(index); | 585 net::X509Certificate* cert = GetCertificateAt(index); |
583 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); | 586 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); |
584 std::string id = x509_certificate_model::GetPkcs11Id(cert_handle); | 587 std::string id = x509_certificate_model::GetPkcs11Id(cert_handle); |
585 if (id == pkcs11_id) | 588 if (id == pkcs11_id) |
586 return index; | 589 return index; |
587 } | 590 } |
588 return -1; // Not found. | 591 return -1; // Not found. |
589 } | 592 } |
590 | 593 |
591 } // chromeos | 594 } // chromeos |
OLD | NEW |