| 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 "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" | 5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" |
| 6 | 6 |
| 7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
| 8 #include <keyhi.h> | 8 #include <keyhi.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 crypto::ScopedPK11Slot system_slot) { | 330 crypto::ScopedPK11Slot system_slot) { |
| 331 CHECK(system_slot); | 331 CHECK(system_slot); |
| 332 create_tpm_key_state_ = CREATE_TPM_KEY_GOT_SYSTEM_SLOT; | 332 create_tpm_key_state_ = CREATE_TPM_KEY_GOT_SYSTEM_SLOT; |
| 333 | 333 |
| 334 // If there are any delayed tasks posted using |StartGetSystemSlotTimeoutMs|, | 334 // If there are any delayed tasks posted using |StartGetSystemSlotTimeoutMs|, |
| 335 // this will cancel them. | 335 // this will cancel them. |
| 336 // Note that this would cancel other pending |CreateKeyInSystemSlot| tasks, | 336 // Note that this would cancel other pending |CreateKeyInSystemSlot| tasks, |
| 337 // but there should be at most one such task at a time. | 337 // but there should be at most one such task at a time. |
| 338 get_tpm_slot_weak_ptr_factory_.InvalidateWeakPtrs(); | 338 get_tpm_slot_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 339 | 339 |
| 340 // This task interacts with the TPM, hence WithFileIO() and WithWait(). | 340 // This task interacts with the TPM, hence MayBlock(). |
| 341 base::PostTaskWithTraits( | 341 base::PostTaskWithTraits( |
| 342 FROM_HERE, | 342 FROM_HERE, base::TaskTraits().MayBlock().WithShutdownBehavior( |
| 343 base::TaskTraits().WithFileIO().WithWait().WithShutdownBehavior( | 343 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
| 344 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), | |
| 345 base::Bind(&CreateTpmKeyPairOnWorkerThread, base::Passed(&system_slot), | 344 base::Bind(&CreateTpmKeyPairOnWorkerThread, base::Passed(&system_slot), |
| 346 public_key, base::ThreadTaskRunnerHandle::Get(), | 345 public_key, base::ThreadTaskRunnerHandle::Get(), |
| 347 base::Bind(&EasyUnlockTpmKeyManager::OnTpmKeyCreated, | 346 base::Bind(&EasyUnlockTpmKeyManager::OnTpmKeyCreated, |
| 348 weak_ptr_factory_.GetWeakPtr()))); | 347 weak_ptr_factory_.GetWeakPtr()))); |
| 349 } | 348 } |
| 350 | 349 |
| 351 void EasyUnlockTpmKeyManager::SignDataWithSystemSlot( | 350 void EasyUnlockTpmKeyManager::SignDataWithSystemSlot( |
| 352 const std::string& public_key, | 351 const std::string& public_key, |
| 353 const std::string& data, | 352 const std::string& data, |
| 354 const base::Callback<void(const std::string& data)> callback, | 353 const base::Callback<void(const std::string& data)> callback, |
| 355 crypto::ScopedPK11Slot system_slot) { | 354 crypto::ScopedPK11Slot system_slot) { |
| 356 CHECK(system_slot); | 355 CHECK(system_slot); |
| 357 | 356 |
| 358 // This task interacts with the TPM, hence WithFileIO() and WithWait(). | 357 // This task interacts with the TPM, hence MayBlock(). |
| 359 base::PostTaskWithTraits( | 358 base::PostTaskWithTraits( |
| 360 FROM_HERE, | 359 FROM_HERE, base::TaskTraits().MayBlock().WithShutdownBehavior( |
| 361 base::TaskTraits().WithFileIO().WithWait().WithShutdownBehavior( | 360 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
| 362 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), | |
| 363 base::Bind(&SignDataOnWorkerThread, base::Passed(&system_slot), | 361 base::Bind(&SignDataOnWorkerThread, base::Passed(&system_slot), |
| 364 public_key, data, base::ThreadTaskRunnerHandle::Get(), | 362 public_key, data, base::ThreadTaskRunnerHandle::Get(), |
| 365 base::Bind(&EasyUnlockTpmKeyManager::OnDataSigned, | 363 base::Bind(&EasyUnlockTpmKeyManager::OnDataSigned, |
| 366 weak_ptr_factory_.GetWeakPtr(), callback))); | 364 weak_ptr_factory_.GetWeakPtr(), callback))); |
| 367 } | 365 } |
| 368 | 366 |
| 369 void EasyUnlockTpmKeyManager::OnTpmKeyCreated(const std::string& public_key) { | 367 void EasyUnlockTpmKeyManager::OnTpmKeyCreated(const std::string& public_key) { |
| 370 // |OnTpmKeyCreated| is called by a timeout task posted by | 368 // |OnTpmKeyCreated| is called by a timeout task posted by |
| 371 // |StartGetSystemSlotTimeoutMs|. Invalidating the factory will have | 369 // |StartGetSystemSlotTimeoutMs|. Invalidating the factory will have |
| 372 // an effect of canceling any pending |GetSystemSlotOnIOThread| callbacks, | 370 // an effect of canceling any pending |GetSystemSlotOnIOThread| callbacks, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 389 // If key creation failed, reset the state machine. | 387 // If key creation failed, reset the state machine. |
| 390 create_tpm_key_state_ = | 388 create_tpm_key_state_ = |
| 391 public_key.empty() ? CREATE_TPM_KEY_NOT_STARTED : CREATE_TPM_KEY_DONE; | 389 public_key.empty() ? CREATE_TPM_KEY_NOT_STARTED : CREATE_TPM_KEY_DONE; |
| 392 } | 390 } |
| 393 | 391 |
| 394 void EasyUnlockTpmKeyManager::OnDataSigned( | 392 void EasyUnlockTpmKeyManager::OnDataSigned( |
| 395 const base::Callback<void(const std::string&)>& callback, | 393 const base::Callback<void(const std::string&)>& callback, |
| 396 const std::string& signature) { | 394 const std::string& signature) { |
| 397 callback.Run(signature); | 395 callback.Run(signature); |
| 398 } | 396 } |
| OLD | NEW |