| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chromeos/cert_loader.h" | 5 #include "chromeos/cert_loader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 CertLoader::CertLoader() | 88 CertLoader::CertLoader() |
| 89 : initialize_tpm_for_test_(false), | 89 : initialize_tpm_for_test_(false), |
| 90 certificates_requested_(false), | 90 certificates_requested_(false), |
| 91 certificates_loaded_(false), | 91 certificates_loaded_(false), |
| 92 certificates_update_required_(false), | 92 certificates_update_required_(false), |
| 93 certificates_update_running_(false), | 93 certificates_update_running_(false), |
| 94 tpm_token_state_(TPM_STATE_UNKNOWN), | 94 tpm_token_state_(TPM_STATE_UNKNOWN), |
| 95 tpm_request_delay_( | 95 tpm_request_delay_( |
| 96 base::TimeDelta::FromMilliseconds(kInitialRequestDelayMs)), | 96 base::TimeDelta::FromMilliseconds(kInitialRequestDelayMs)), |
| 97 tpm_token_slot_(-1), |
| 97 initialize_token_factory_(this), | 98 initialize_token_factory_(this), |
| 98 update_certificates_factory_(this) { | 99 update_certificates_factory_(this) { |
| 99 if (LoginState::IsInitialized()) | 100 if (LoginState::IsInitialized()) |
| 100 LoginState::Get()->AddObserver(this); | 101 LoginState::Get()->AddObserver(this); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void CertLoader::InitializeTPMForTest() { | 104 void CertLoader::InitializeTPMForTest() { |
| 104 initialize_tpm_for_test_ = true; | 105 initialize_tpm_for_test_ = true; |
| 105 } | 106 } |
| 106 | 107 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // and CryptohomeClient calls are not thread safe. | 205 // and CryptohomeClient calls are not thread safe. |
| 205 DBusThreadManager::Get()->GetCryptohomeClient()->Pkcs11GetTpmTokenInfo( | 206 DBusThreadManager::Get()->GetCryptohomeClient()->Pkcs11GetTpmTokenInfo( |
| 206 base::Bind(&CertLoader::OnPkcs11GetTpmTokenInfo, | 207 base::Bind(&CertLoader::OnPkcs11GetTpmTokenInfo, |
| 207 initialize_token_factory_.GetWeakPtr())); | 208 initialize_token_factory_.GetWeakPtr())); |
| 208 return; | 209 return; |
| 209 } | 210 } |
| 210 case TPM_TOKEN_INFO_RECEIVED: { | 211 case TPM_TOKEN_INFO_RECEIVED: { |
| 211 base::PostTaskAndReplyWithResult( | 212 base::PostTaskAndReplyWithResult( |
| 212 crypto_task_runner_.get(), | 213 crypto_task_runner_.get(), |
| 213 FROM_HERE, | 214 FROM_HERE, |
| 214 base::Bind( | 215 base::Bind(&crypto::InitializeTPMToken, |
| 215 &crypto::InitializeTPMToken, tpm_token_name_, tpm_user_pin_), | 216 tpm_token_name_, |
| 217 tpm_user_pin_, |
| 218 tpm_token_slot_), |
| 216 base::Bind(&CertLoader::OnTPMTokenInitialized, | 219 base::Bind(&CertLoader::OnTPMTokenInitialized, |
| 217 initialize_token_factory_.GetWeakPtr())); | 220 initialize_token_factory_.GetWeakPtr())); |
| 218 return; | 221 return; |
| 219 } | 222 } |
| 220 case TPM_TOKEN_INITIALIZED: { | 223 case TPM_TOKEN_INITIALIZED: { |
| 221 StartLoadCertificates(); | 224 StartLoadCertificates(); |
| 222 return; | 225 return; |
| 223 } | 226 } |
| 224 } | 227 } |
| 225 } | 228 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 const std::string& user_pin, | 303 const std::string& user_pin, |
| 301 int token_slot) { | 304 int token_slot) { |
| 302 VLOG(1) << "OnPkcs11GetTpmTokenInfo: " << token_name; | 305 VLOG(1) << "OnPkcs11GetTpmTokenInfo: " << token_name; |
| 303 | 306 |
| 304 if (call_status == DBUS_METHOD_CALL_FAILURE) { | 307 if (call_status == DBUS_METHOD_CALL_FAILURE) { |
| 305 RetryTokenInitializationLater(); | 308 RetryTokenInitializationLater(); |
| 306 return; | 309 return; |
| 307 } | 310 } |
| 308 | 311 |
| 309 tpm_token_name_ = token_name; | 312 tpm_token_name_ = token_name; |
| 310 tpm_token_slot_ = base::IntToString(token_slot); | 313 tpm_token_slot_ = token_slot; |
| 311 tpm_user_pin_ = user_pin; | 314 tpm_user_pin_ = user_pin; |
| 312 tpm_token_state_ = TPM_TOKEN_INFO_RECEIVED; | 315 tpm_token_state_ = TPM_TOKEN_INFO_RECEIVED; |
| 313 | 316 |
| 314 InitializeTokenAndLoadCertificates(); | 317 InitializeTokenAndLoadCertificates(); |
| 315 } | 318 } |
| 316 | 319 |
| 317 void CertLoader::OnTPMTokenInitialized(bool success) { | 320 void CertLoader::OnTPMTokenInitialized(bool success) { |
| 318 VLOG(1) << "OnTPMTokenInitialized: " << success; | 321 VLOG(1) << "OnTPMTokenInitialized: " << success; |
| 319 if (!success) { | 322 if (!success) { |
| 320 RetryTokenInitializationLater(); | 323 RetryTokenInitializationLater(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 VLOG(1) << "OnCertRemoved"; | 391 VLOG(1) << "OnCertRemoved"; |
| 389 LoadCertificates(); | 392 LoadCertificates(); |
| 390 } | 393 } |
| 391 | 394 |
| 392 void CertLoader::LoggedInStateChanged() { | 395 void CertLoader::LoggedInStateChanged() { |
| 393 VLOG(1) << "LoggedInStateChanged"; | 396 VLOG(1) << "LoggedInStateChanged"; |
| 394 MaybeRequestCertificates(); | 397 MaybeRequestCertificates(); |
| 395 } | 398 } |
| 396 | 399 |
| 397 } // namespace chromeos | 400 } // namespace chromeos |
| OLD | NEW |