| 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> |
| 11 | 11 |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/task_scheduler/post_task.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/threading/worker_pool.h" | |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "components/prefs/pref_registry_simple.h" | 24 #include "components/prefs/pref_registry_simple.h" |
| 25 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 26 #include "components/prefs/scoped_user_pref_update.h" | 26 #include "components/prefs/scoped_user_pref_update.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "crypto/nss_key_util.h" | 28 #include "crypto/nss_key_util.h" |
| 29 #include "crypto/nss_util_internal.h" | 29 #include "crypto/nss_util_internal.h" |
| (...skipping 300 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 base::WorkerPool::PostTask( | 340 // This task interacts with the TPM, hence WithFileIO() and WithWait(). |
| 341 base::PostTaskWithTraits( |
| 341 FROM_HERE, | 342 FROM_HERE, |
| 342 base::Bind(&CreateTpmKeyPairOnWorkerThread, | 343 base::TaskTraits().WithFileIO().WithWait().WithShutdownBehavior( |
| 343 base::Passed(&system_slot), | 344 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
| 344 public_key, | 345 base::Bind(&CreateTpmKeyPairOnWorkerThread, base::Passed(&system_slot), |
| 345 base::ThreadTaskRunnerHandle::Get(), | 346 public_key, base::ThreadTaskRunnerHandle::Get(), |
| 346 base::Bind(&EasyUnlockTpmKeyManager::OnTpmKeyCreated, | 347 base::Bind(&EasyUnlockTpmKeyManager::OnTpmKeyCreated, |
| 347 weak_ptr_factory_.GetWeakPtr())), | 348 weak_ptr_factory_.GetWeakPtr()))); |
| 348 true /* long task */); | |
| 349 } | 349 } |
| 350 | 350 |
| 351 void EasyUnlockTpmKeyManager::SignDataWithSystemSlot( | 351 void EasyUnlockTpmKeyManager::SignDataWithSystemSlot( |
| 352 const std::string& public_key, | 352 const std::string& public_key, |
| 353 const std::string& data, | 353 const std::string& data, |
| 354 const base::Callback<void(const std::string& data)> callback, | 354 const base::Callback<void(const std::string& data)> callback, |
| 355 crypto::ScopedPK11Slot system_slot) { | 355 crypto::ScopedPK11Slot system_slot) { |
| 356 CHECK(system_slot); | 356 CHECK(system_slot); |
| 357 | 357 |
| 358 base::WorkerPool::PostTask( | 358 // This task interacts with the TPM, hence WithFileIO() and WithWait(). |
| 359 base::PostTaskWithTraits( |
| 359 FROM_HERE, | 360 FROM_HERE, |
| 360 base::Bind(&SignDataOnWorkerThread, | 361 base::TaskTraits().WithFileIO().WithWait().WithShutdownBehavior( |
| 361 base::Passed(&system_slot), | 362 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
| 362 public_key, | 363 base::Bind(&SignDataOnWorkerThread, base::Passed(&system_slot), |
| 363 data, | 364 public_key, data, base::ThreadTaskRunnerHandle::Get(), |
| 364 base::ThreadTaskRunnerHandle::Get(), | |
| 365 base::Bind(&EasyUnlockTpmKeyManager::OnDataSigned, | 365 base::Bind(&EasyUnlockTpmKeyManager::OnDataSigned, |
| 366 weak_ptr_factory_.GetWeakPtr(), | 366 weak_ptr_factory_.GetWeakPtr(), callback))); |
| 367 callback)), | |
| 368 true /* long task */); | |
| 369 } | 367 } |
| 370 | 368 |
| 371 void EasyUnlockTpmKeyManager::OnTpmKeyCreated(const std::string& public_key) { | 369 void EasyUnlockTpmKeyManager::OnTpmKeyCreated(const std::string& public_key) { |
| 372 // |OnTpmKeyCreated| is called by a timeout task posted by | 370 // |OnTpmKeyCreated| is called by a timeout task posted by |
| 373 // |StartGetSystemSlotTimeoutMs|. Invalidating the factory will have | 371 // |StartGetSystemSlotTimeoutMs|. Invalidating the factory will have |
| 374 // an effect of canceling any pending |GetSystemSlotOnIOThread| callbacks, | 372 // an effect of canceling any pending |GetSystemSlotOnIOThread| callbacks, |
| 375 // as well as other pending timeouts. | 373 // as well as other pending timeouts. |
| 376 // Note that in the case |OnTpmKeyCreated| was called as a result of | 374 // Note that in the case |OnTpmKeyCreated| was called as a result of |
| 377 // |CreateKeyInSystemSlot|, this should have no effect as no weak ptrs from | 375 // |CreateKeyInSystemSlot|, this should have no effect as no weak ptrs from |
| 378 // this factory should be in use in this case. | 376 // this factory should be in use in this case. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 391 // If key creation failed, reset the state machine. | 389 // If key creation failed, reset the state machine. |
| 392 create_tpm_key_state_ = | 390 create_tpm_key_state_ = |
| 393 public_key.empty() ? CREATE_TPM_KEY_NOT_STARTED : CREATE_TPM_KEY_DONE; | 391 public_key.empty() ? CREATE_TPM_KEY_NOT_STARTED : CREATE_TPM_KEY_DONE; |
| 394 } | 392 } |
| 395 | 393 |
| 396 void EasyUnlockTpmKeyManager::OnDataSigned( | 394 void EasyUnlockTpmKeyManager::OnDataSigned( |
| 397 const base::Callback<void(const std::string&)>& callback, | 395 const base::Callback<void(const std::string&)>& callback, |
| 398 const std::string& signature) { | 396 const std::string& signature) { |
| 399 callback.Run(signature); | 397 callback.Run(signature); |
| 400 } | 398 } |
| OLD | NEW |