Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/tpm_token_loader.h" | 5 #include "chromeos/tpm_token_loader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 base::TimeDelta next_delay = last_delay * 2; | 31 base::TimeDelta next_delay = last_delay * 2; |
| 32 | 32 |
| 33 // Cap the delay to prevent an overflow. This threshold is arbitrarily chosen. | 33 // Cap the delay to prevent an overflow. This threshold is arbitrarily chosen. |
| 34 const base::TimeDelta max_delay = | 34 const base::TimeDelta max_delay = |
| 35 base::TimeDelta::FromMilliseconds(kMaxRequestDelayMs); | 35 base::TimeDelta::FromMilliseconds(kMaxRequestDelayMs); |
| 36 if (next_delay > max_delay) | 36 if (next_delay > max_delay) |
| 37 next_delay = max_delay; | 37 next_delay = max_delay; |
| 38 return next_delay; | 38 return next_delay; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void CallOpenPersistentNSSDB() { | 41 void CallEnableTPMTokenForNSS() { |
|
pneubeck (no reviews)
2014/06/12 15:14:54
optional nit: could be removed. I don't think that
tbarzic
2014/06/12 18:38:12
Done.
| |
| 42 // Called from crypto_task_runner_. | 42 // Called from crypto_task_runner_. |
| 43 VLOG(1) << "CallOpenPersistentNSSDB"; | 43 VLOG(1) << "EnableTPMTokenForNSS"; |
| 44 | 44 |
| 45 // Ensure we've opened the user's key/certificate database. | |
| 46 if (base::SysInfo::IsRunningOnChromeOS()) | |
| 47 crypto::OpenPersistentNSSDB(); | |
| 48 crypto::EnableTPMTokenForNSS(); | 45 crypto::EnableTPMTokenForNSS(); |
| 49 } | 46 } |
| 50 | 47 |
| 51 void PostResultToTaskRunner(scoped_refptr<base::SequencedTaskRunner> runner, | 48 void PostResultToTaskRunner(scoped_refptr<base::SequencedTaskRunner> runner, |
| 52 const base::Callback<void(bool)>& callback, | 49 const base::Callback<void(bool)>& callback, |
| 53 bool success) { | 50 bool success) { |
| 54 runner->PostTask(FROM_HERE, base::Bind(callback, success)); | 51 runner->PostTask(FROM_HERE, base::Bind(callback, success)); |
| 55 } | 52 } |
| 56 | 53 |
| 57 } // namespace | 54 } // namespace |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 } | 157 } |
| 161 | 158 |
| 162 void TPMTokenLoader::ContinueTokenInitialization() { | 159 void TPMTokenLoader::ContinueTokenInitialization() { |
| 163 CHECK(thread_checker_.CalledOnValidThread()); | 160 CHECK(thread_checker_.CalledOnValidThread()); |
| 164 VLOG(1) << "ContinueTokenInitialization: " << tpm_token_state_; | 161 VLOG(1) << "ContinueTokenInitialization: " << tpm_token_state_; |
| 165 | 162 |
| 166 switch (tpm_token_state_) { | 163 switch (tpm_token_state_) { |
| 167 case TPM_STATE_UNKNOWN: { | 164 case TPM_STATE_UNKNOWN: { |
| 168 crypto_task_runner_->PostTaskAndReply( | 165 crypto_task_runner_->PostTaskAndReply( |
| 169 FROM_HERE, | 166 FROM_HERE, |
| 170 base::Bind(&CallOpenPersistentNSSDB), | 167 base::Bind(&CallEnableTPMTokenForNSS), |
| 171 base::Bind(&TPMTokenLoader::OnPersistentNSSDBOpened, | 168 base::Bind(&TPMTokenLoader::OnTPMTokenEnabledForNSS, |
| 172 weak_factory_.GetWeakPtr())); | 169 weak_factory_.GetWeakPtr())); |
| 173 tpm_token_state_ = TPM_INITIALIZATION_STARTED; | 170 tpm_token_state_ = TPM_INITIALIZATION_STARTED; |
| 174 return; | 171 return; |
| 175 } | 172 } |
| 176 case TPM_INITIALIZATION_STARTED: { | 173 case TPM_INITIALIZATION_STARTED: { |
| 177 NOTREACHED(); | 174 NOTREACHED(); |
| 178 return; | 175 return; |
| 179 } | 176 } |
| 180 case TPM_DB_OPENED: { | 177 case TPM_TOKEN_ENABLED_FOR_NSS: { |
| 181 DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsEnabled( | 178 DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsEnabled( |
| 182 base::Bind(&TPMTokenLoader::OnTpmIsEnabled, | 179 base::Bind(&TPMTokenLoader::OnTpmIsEnabled, |
| 183 weak_factory_.GetWeakPtr())); | 180 weak_factory_.GetWeakPtr())); |
| 184 return; | 181 return; |
| 185 } | 182 } |
| 186 case TPM_DISABLED: { | 183 case TPM_DISABLED: { |
| 187 // TPM is disabled, so proceed with empty tpm token name. | 184 // TPM is disabled, so proceed with empty tpm token name. |
| 188 NotifyTPMTokenReady(); | 185 NotifyTPMTokenReady(); |
| 189 return; | 186 return; |
| 190 } | 187 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 CHECK(thread_checker_.CalledOnValidThread()); | 222 CHECK(thread_checker_.CalledOnValidThread()); |
| 226 LOG(WARNING) << "Retry token initialization later."; | 223 LOG(WARNING) << "Retry token initialization later."; |
| 227 base::MessageLoopProxy::current()->PostDelayedTask( | 224 base::MessageLoopProxy::current()->PostDelayedTask( |
| 228 FROM_HERE, | 225 FROM_HERE, |
| 229 base::Bind(&TPMTokenLoader::ContinueTokenInitialization, | 226 base::Bind(&TPMTokenLoader::ContinueTokenInitialization, |
| 230 weak_factory_.GetWeakPtr()), | 227 weak_factory_.GetWeakPtr()), |
| 231 tpm_request_delay_); | 228 tpm_request_delay_); |
| 232 tpm_request_delay_ = GetNextRequestDelayMs(tpm_request_delay_); | 229 tpm_request_delay_ = GetNextRequestDelayMs(tpm_request_delay_); |
| 233 } | 230 } |
| 234 | 231 |
| 235 void TPMTokenLoader::OnPersistentNSSDBOpened() { | 232 void TPMTokenLoader::OnTPMTokenEnabledForNSS() { |
| 236 VLOG(1) << "PersistentNSSDBOpened"; | 233 VLOG(1) << "TPMTokenEnabledForNSS"; |
| 237 tpm_token_state_ = TPM_DB_OPENED; | 234 tpm_token_state_ = TPM_TOKEN_ENABLED_FOR_NSS; |
| 238 ContinueTokenInitialization(); | 235 ContinueTokenInitialization(); |
| 239 } | 236 } |
| 240 | 237 |
| 241 void TPMTokenLoader::OnTpmIsEnabled(DBusMethodCallStatus call_status, | 238 void TPMTokenLoader::OnTpmIsEnabled(DBusMethodCallStatus call_status, |
| 242 bool tpm_is_enabled) { | 239 bool tpm_is_enabled) { |
| 243 VLOG(1) << "OnTpmIsEnabled: " << tpm_is_enabled; | 240 VLOG(1) << "OnTpmIsEnabled: " << tpm_is_enabled; |
| 244 | 241 |
| 245 if (call_status == DBUS_METHOD_CALL_SUCCESS && tpm_is_enabled) | 242 if (call_status == DBUS_METHOD_CALL_SUCCESS && tpm_is_enabled) |
| 246 tpm_token_state_ = TPM_ENABLED; | 243 tpm_token_state_ = TPM_ENABLED; |
| 247 else | 244 else |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 void TPMTokenLoader::NotifyTPMTokenReady() { | 292 void TPMTokenLoader::NotifyTPMTokenReady() { |
| 296 FOR_EACH_OBSERVER(Observer, observers_, OnTPMTokenReady()); | 293 FOR_EACH_OBSERVER(Observer, observers_, OnTPMTokenReady()); |
| 297 } | 294 } |
| 298 | 295 |
| 299 void TPMTokenLoader::LoggedInStateChanged() { | 296 void TPMTokenLoader::LoggedInStateChanged() { |
| 300 VLOG(1) << "LoggedInStateChanged"; | 297 VLOG(1) << "LoggedInStateChanged"; |
| 301 MaybeStartTokenInitialization(); | 298 MaybeStartTokenInitialization(); |
| 302 } | 299 } |
| 303 | 300 |
| 304 } // namespace chromeos | 301 } // namespace chromeos |
| OLD | NEW |