| 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_key_manager.h" | 5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" | 12 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" |
| 13 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_
factory.h" | 13 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_
factory.h" |
| 14 #include "components/signin/core/account_id/account_id.h" | |
| 15 | 14 |
| 16 namespace chromeos { | 15 namespace chromeos { |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 | 18 |
| 20 const char kKeyBluetoothAddress[] = "bluetoothAddress"; | 19 const char kKeyBluetoothAddress[] = "bluetoothAddress"; |
| 21 const char kKeyPermitRecord[] = "permitRecord"; | 20 const char kKeyPermitRecord[] = "permitRecord"; |
| 22 const char kKeyPermitId[] = "permitRecord.id"; | 21 const char kKeyPermitId[] = "permitRecord.id"; |
| 23 const char kKeyPermitPermitId[] = "permitRecord.permitId"; | 22 const char kKeyPermitPermitId[] = "permitRecord.permitId"; |
| 24 const char kKeyPermitData[] = "permitRecord.data"; | 23 const char kKeyPermitData[] = "permitRecord.data"; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 46 const RefreshKeysCallback& callback) { | 45 const RefreshKeysCallback& callback) { |
| 47 base::Closure do_refresh_keys = base::Bind( | 46 base::Closure do_refresh_keys = base::Bind( |
| 48 &EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent, | 47 &EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent, |
| 49 weak_ptr_factory_.GetWeakPtr(), | 48 weak_ptr_factory_.GetWeakPtr(), |
| 50 user_context, | 49 user_context, |
| 51 base::Owned(remote_devices.DeepCopy()), | 50 base::Owned(remote_devices.DeepCopy()), |
| 52 callback); | 51 callback); |
| 53 | 52 |
| 54 EasyUnlockTpmKeyManager* tpm_key_manager = | 53 EasyUnlockTpmKeyManager* tpm_key_manager = |
| 55 EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( | 54 EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( |
| 56 user_context.GetAccountId().GetUserEmail()); | 55 user_context.GetUserID()); |
| 57 if (!tpm_key_manager) { | 56 if (!tpm_key_manager) { |
| 58 LOG(ERROR) << "No TPM key manager."; | 57 LOG(ERROR) << "No TPM key manager."; |
| 59 callback.Run(false); | 58 callback.Run(false); |
| 60 return; | 59 return; |
| 61 } | 60 } |
| 62 | 61 |
| 63 // Private TPM key is needed only when adding new keys. | 62 // Private TPM key is needed only when adding new keys. |
| 64 if (remote_devices.empty() || | 63 if (remote_devices.empty() || |
| 65 tpm_key_manager->PrepareTpmKey(false /* check_private_key */, | 64 tpm_key_manager->PrepareTpmKey(false /* check_private_key */, |
| 66 do_refresh_keys)) { | 65 do_refresh_keys)) { |
| 67 do_refresh_keys.Run(); | 66 do_refresh_keys.Run(); |
| 68 } else { | 67 } else { |
| 69 // In case Chrome is supposed to restart to apply user session flags, the | 68 // In case Chrome is supposed to restart to apply user session flags, the |
| 70 // Chrome restart will be postponed until Easy Sign-in keys are refreshed. | 69 // Chrome restart will be postponed until Easy Sign-in keys are refreshed. |
| 71 // This is to ensure that creating TPM key does not hang if TPM system | 70 // This is to ensure that creating TPM key does not hang if TPM system |
| 72 // loading takes too much time. Note that in normal circumstances the | 71 // loading takes too much time. Note that in normal circumstances the |
| 73 // chances that TPM slot cannot be loaded should be extremely low. | 72 // chances that TPM slot cannot be loaded should be extremely low. |
| 74 // TODO(tbarzic): Add some metrics to measure if the timeout even gets hit. | 73 // TODO(tbarzic): Add some metrics to measure if the timeout even gets hit. |
| 75 tpm_key_manager->StartGetSystemSlotTimeoutMs(2000); | 74 tpm_key_manager->StartGetSystemSlotTimeoutMs(2000); |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 | 77 |
| 79 void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent( | 78 void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent( |
| 80 const UserContext& user_context, | 79 const UserContext& user_context, |
| 81 base::ListValue* remote_devices, | 80 base::ListValue* remote_devices, |
| 82 const RefreshKeysCallback& callback) { | 81 const RefreshKeysCallback& callback) { |
| 83 EasyUnlockTpmKeyManager* tpm_key_manager = | 82 EasyUnlockTpmKeyManager* tpm_key_manager = |
| 84 EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( | 83 EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( |
| 85 user_context.GetAccountId().GetUserEmail()); | 84 user_context.GetUserID()); |
| 86 const std::string tpm_public_key = tpm_key_manager->GetPublicTpmKey( | 85 std::string tpm_public_key = |
| 87 user_context.GetAccountId().GetUserEmail()); | 86 tpm_key_manager->GetPublicTpmKey(user_context.GetUserID()); |
| 88 | 87 |
| 89 EasyUnlockDeviceKeyDataList devices; | 88 EasyUnlockDeviceKeyDataList devices; |
| 90 if (!RemoteDeviceListToDeviceDataList(*remote_devices, &devices)) | 89 if (!RemoteDeviceListToDeviceDataList(*remote_devices, &devices)) |
| 91 devices.clear(); | 90 devices.clear(); |
| 92 | 91 |
| 93 write_operation_queue_.push_back(new EasyUnlockRefreshKeysOperation( | 92 write_operation_queue_.push_back(new EasyUnlockRefreshKeysOperation( |
| 94 user_context, tpm_public_key, devices, | 93 user_context, tpm_public_key, devices, |
| 95 base::Bind(&EasyUnlockKeyManager::OnKeysRefreshed, | 94 base::Bind(&EasyUnlockKeyManager::OnKeysRefreshed, |
| 96 weak_ptr_factory_.GetWeakPtr(), callback))); | 95 weak_ptr_factory_.GetWeakPtr(), callback))); |
| 97 RunNextOperation(); | 96 RunNextOperation(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 const EasyUnlockDeviceKeyDataList& fetched_data) { | 215 const EasyUnlockDeviceKeyDataList& fetched_data) { |
| 217 if (!callback.is_null()) | 216 if (!callback.is_null()) |
| 218 callback.Run(fetch_success, fetched_data); | 217 callback.Run(fetch_success, fetched_data); |
| 219 | 218 |
| 220 DCHECK(pending_read_operation_); | 219 DCHECK(pending_read_operation_); |
| 221 pending_read_operation_.reset(); | 220 pending_read_operation_.reset(); |
| 222 RunNextOperation(); | 221 RunNextOperation(); |
| 223 } | 222 } |
| 224 | 223 |
| 225 } // namespace chromeos | 224 } // namespace chromeos |
| OLD | NEW |