| 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() { | |
| 42 // Called from crypto_task_runner_. | |
| 43 VLOG(1) << "CallOpenPersistentNSSDB"; | |
| 44 | |
| 45 // Ensure we've opened the user's key/certificate database. | |
| 46 if (base::SysInfo::IsRunningOnChromeOS()) | |
| 47 crypto::OpenPersistentNSSDB(); | |
| 48 crypto::EnableTPMTokenForNSS(); | |
| 49 } | |
| 50 | |
| 51 void PostResultToTaskRunner(scoped_refptr<base::SequencedTaskRunner> runner, | 41 void PostResultToTaskRunner(scoped_refptr<base::SequencedTaskRunner> runner, |
| 52 const base::Callback<void(bool)>& callback, | 42 const base::Callback<void(bool)>& callback, |
| 53 bool success) { | 43 bool success) { |
| 54 runner->PostTask(FROM_HERE, base::Bind(callback, success)); | 44 runner->PostTask(FROM_HERE, base::Bind(callback, success)); |
| 55 } | 45 } |
| 56 | 46 |
| 57 } // namespace | 47 } // namespace |
| 58 | 48 |
| 59 static TPMTokenLoader* g_tpm_token_loader = NULL; | 49 static TPMTokenLoader* g_tpm_token_loader = NULL; |
| 60 | 50 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 150 } |
| 161 | 151 |
| 162 void TPMTokenLoader::ContinueTokenInitialization() { | 152 void TPMTokenLoader::ContinueTokenInitialization() { |
| 163 CHECK(thread_checker_.CalledOnValidThread()); | 153 CHECK(thread_checker_.CalledOnValidThread()); |
| 164 VLOG(1) << "ContinueTokenInitialization: " << tpm_token_state_; | 154 VLOG(1) << "ContinueTokenInitialization: " << tpm_token_state_; |
| 165 | 155 |
| 166 switch (tpm_token_state_) { | 156 switch (tpm_token_state_) { |
| 167 case TPM_STATE_UNKNOWN: { | 157 case TPM_STATE_UNKNOWN: { |
| 168 crypto_task_runner_->PostTaskAndReply( | 158 crypto_task_runner_->PostTaskAndReply( |
| 169 FROM_HERE, | 159 FROM_HERE, |
| 170 base::Bind(&CallOpenPersistentNSSDB), | 160 base::Bind(&crypto::EnableTPMTokenForNSS), |
| 171 base::Bind(&TPMTokenLoader::OnPersistentNSSDBOpened, | 161 base::Bind(&TPMTokenLoader::OnTPMTokenEnabledForNSS, |
| 172 weak_factory_.GetWeakPtr())); | 162 weak_factory_.GetWeakPtr())); |
| 173 tpm_token_state_ = TPM_INITIALIZATION_STARTED; | 163 tpm_token_state_ = TPM_INITIALIZATION_STARTED; |
| 174 return; | 164 return; |
| 175 } | 165 } |
| 176 case TPM_INITIALIZATION_STARTED: { | 166 case TPM_INITIALIZATION_STARTED: { |
| 177 NOTREACHED(); | 167 NOTREACHED(); |
| 178 return; | 168 return; |
| 179 } | 169 } |
| 180 case TPM_DB_OPENED: { | 170 case TPM_TOKEN_ENABLED_FOR_NSS: { |
| 181 DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsEnabled( | 171 DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsEnabled( |
| 182 base::Bind(&TPMTokenLoader::OnTpmIsEnabled, | 172 base::Bind(&TPMTokenLoader::OnTpmIsEnabled, |
| 183 weak_factory_.GetWeakPtr())); | 173 weak_factory_.GetWeakPtr())); |
| 184 return; | 174 return; |
| 185 } | 175 } |
| 186 case TPM_DISABLED: { | 176 case TPM_DISABLED: { |
| 187 // TPM is disabled, so proceed with empty tpm token name. | 177 // TPM is disabled, so proceed with empty tpm token name. |
| 188 NotifyTPMTokenReady(); | 178 NotifyTPMTokenReady(); |
| 189 return; | 179 return; |
| 190 } | 180 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 CHECK(thread_checker_.CalledOnValidThread()); | 215 CHECK(thread_checker_.CalledOnValidThread()); |
| 226 LOG(WARNING) << "Retry token initialization later."; | 216 LOG(WARNING) << "Retry token initialization later."; |
| 227 base::MessageLoopProxy::current()->PostDelayedTask( | 217 base::MessageLoopProxy::current()->PostDelayedTask( |
| 228 FROM_HERE, | 218 FROM_HERE, |
| 229 base::Bind(&TPMTokenLoader::ContinueTokenInitialization, | 219 base::Bind(&TPMTokenLoader::ContinueTokenInitialization, |
| 230 weak_factory_.GetWeakPtr()), | 220 weak_factory_.GetWeakPtr()), |
| 231 tpm_request_delay_); | 221 tpm_request_delay_); |
| 232 tpm_request_delay_ = GetNextRequestDelayMs(tpm_request_delay_); | 222 tpm_request_delay_ = GetNextRequestDelayMs(tpm_request_delay_); |
| 233 } | 223 } |
| 234 | 224 |
| 235 void TPMTokenLoader::OnPersistentNSSDBOpened() { | 225 void TPMTokenLoader::OnTPMTokenEnabledForNSS() { |
| 236 VLOG(1) << "PersistentNSSDBOpened"; | 226 VLOG(1) << "TPMTokenEnabledForNSS"; |
| 237 tpm_token_state_ = TPM_DB_OPENED; | 227 tpm_token_state_ = TPM_TOKEN_ENABLED_FOR_NSS; |
| 238 ContinueTokenInitialization(); | 228 ContinueTokenInitialization(); |
| 239 } | 229 } |
| 240 | 230 |
| 241 void TPMTokenLoader::OnTpmIsEnabled(DBusMethodCallStatus call_status, | 231 void TPMTokenLoader::OnTpmIsEnabled(DBusMethodCallStatus call_status, |
| 242 bool tpm_is_enabled) { | 232 bool tpm_is_enabled) { |
| 243 VLOG(1) << "OnTpmIsEnabled: " << tpm_is_enabled; | 233 VLOG(1) << "OnTpmIsEnabled: " << tpm_is_enabled; |
| 244 | 234 |
| 245 if (call_status == DBUS_METHOD_CALL_SUCCESS && tpm_is_enabled) | 235 if (call_status == DBUS_METHOD_CALL_SUCCESS && tpm_is_enabled) |
| 246 tpm_token_state_ = TPM_ENABLED; | 236 tpm_token_state_ = TPM_ENABLED; |
| 247 else | 237 else |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 void TPMTokenLoader::NotifyTPMTokenReady() { | 285 void TPMTokenLoader::NotifyTPMTokenReady() { |
| 296 FOR_EACH_OBSERVER(Observer, observers_, OnTPMTokenReady()); | 286 FOR_EACH_OBSERVER(Observer, observers_, OnTPMTokenReady()); |
| 297 } | 287 } |
| 298 | 288 |
| 299 void TPMTokenLoader::LoggedInStateChanged() { | 289 void TPMTokenLoader::LoggedInStateChanged() { |
| 300 VLOG(1) << "LoggedInStateChanged"; | 290 VLOG(1) << "LoggedInStateChanged"; |
| 301 MaybeStartTokenInitialization(); | 291 MaybeStartTokenInitialization(); |
| 302 } | 292 } |
| 303 | 293 |
| 304 } // namespace chromeos | 294 } // namespace chromeos |
| OLD | NEW |