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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 MayBlock(). | 340 // This task interacts with the TPM, hence MayBlock(). |
341 base::PostTaskWithTraits( | 341 base::PostTaskWithTraits( |
342 FROM_HERE, base::TaskTraits().MayBlock().WithShutdownBehavior( | 342 FROM_HERE, |
343 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), | 343 {base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, |
344 base::Bind(&CreateTpmKeyPairOnWorkerThread, base::Passed(&system_slot), | 344 base::Bind(&CreateTpmKeyPairOnWorkerThread, base::Passed(&system_slot), |
345 public_key, base::ThreadTaskRunnerHandle::Get(), | 345 public_key, base::ThreadTaskRunnerHandle::Get(), |
346 base::Bind(&EasyUnlockTpmKeyManager::OnTpmKeyCreated, | 346 base::Bind(&EasyUnlockTpmKeyManager::OnTpmKeyCreated, |
347 weak_ptr_factory_.GetWeakPtr()))); | 347 weak_ptr_factory_.GetWeakPtr()))); |
348 } | 348 } |
349 | 349 |
350 void EasyUnlockTpmKeyManager::SignDataWithSystemSlot( | 350 void EasyUnlockTpmKeyManager::SignDataWithSystemSlot( |
351 const std::string& public_key, | 351 const std::string& public_key, |
352 const std::string& data, | 352 const std::string& data, |
353 const base::Callback<void(const std::string& data)> callback, | 353 const base::Callback<void(const std::string& data)> callback, |
354 crypto::ScopedPK11Slot system_slot) { | 354 crypto::ScopedPK11Slot system_slot) { |
355 CHECK(system_slot); | 355 CHECK(system_slot); |
356 | 356 |
357 // This task interacts with the TPM, hence MayBlock(). | 357 // This task interacts with the TPM, hence MayBlock(). |
358 base::PostTaskWithTraits( | 358 base::PostTaskWithTraits( |
359 FROM_HERE, base::TaskTraits().MayBlock().WithShutdownBehavior( | 359 FROM_HERE, |
360 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), | 360 {base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, |
361 base::Bind(&SignDataOnWorkerThread, base::Passed(&system_slot), | 361 base::Bind(&SignDataOnWorkerThread, base::Passed(&system_slot), |
362 public_key, data, base::ThreadTaskRunnerHandle::Get(), | 362 public_key, data, base::ThreadTaskRunnerHandle::Get(), |
363 base::Bind(&EasyUnlockTpmKeyManager::OnDataSigned, | 363 base::Bind(&EasyUnlockTpmKeyManager::OnDataSigned, |
364 weak_ptr_factory_.GetWeakPtr(), callback))); | 364 weak_ptr_factory_.GetWeakPtr(), callback))); |
365 } | 365 } |
366 | 366 |
367 void EasyUnlockTpmKeyManager::OnTpmKeyCreated(const std::string& public_key) { | 367 void EasyUnlockTpmKeyManager::OnTpmKeyCreated(const std::string& public_key) { |
368 // |OnTpmKeyCreated| is called by a timeout task posted by | 368 // |OnTpmKeyCreated| is called by a timeout task posted by |
369 // |StartGetSystemSlotTimeoutMs|. Invalidating the factory will have | 369 // |StartGetSystemSlotTimeoutMs|. Invalidating the factory will have |
370 // an effect of canceling any pending |GetSystemSlotOnIOThread| callbacks, | 370 // an effect of canceling any pending |GetSystemSlotOnIOThread| callbacks, |
(...skipping 16 matching lines...) Expand all Loading... |
387 // If key creation failed, reset the state machine. | 387 // If key creation failed, reset the state machine. |
388 create_tpm_key_state_ = | 388 create_tpm_key_state_ = |
389 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; |
390 } | 390 } |
391 | 391 |
392 void EasyUnlockTpmKeyManager::OnDataSigned( | 392 void EasyUnlockTpmKeyManager::OnDataSigned( |
393 const base::Callback<void(const std::string&)>& callback, | 393 const base::Callback<void(const std::string&)>& callback, |
394 const std::string& signature) { | 394 const std::string& signature) { |
395 callback.Run(signature); | 395 callback.Run(signature); |
396 } | 396 } |
OLD | NEW |