| 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/stl_util.h" | 9 #include "base/stl_util.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" |
| 13 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_
factory.h" |
| 12 | 14 |
| 13 namespace chromeos { | 15 namespace chromeos { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 const char kKeyBluetoothAddress[] = "bluetoothAddress"; | 19 const char kKeyBluetoothAddress[] = "bluetoothAddress"; |
| 18 const char kKeyPermitRecord[] = "permitRecord"; | 20 const char kKeyPermitRecord[] = "permitRecord"; |
| 19 const char kKeyPermitId[] = "permitRecord.id"; | 21 const char kKeyPermitId[] = "permitRecord.id"; |
| 20 const char kKeyPermitPermitId[] = "permitRecord.permitId"; | 22 const char kKeyPermitPermitId[] = "permitRecord.permitId"; |
| 21 const char kKeyPermitData[] = "permitRecord.data"; | 23 const char kKeyPermitData[] = "permitRecord.data"; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 38 STLDeleteContainerPairSecondPointers(get_keys_ops_.begin(), | 40 STLDeleteContainerPairSecondPointers(get_keys_ops_.begin(), |
| 39 get_keys_ops_.end()); | 41 get_keys_ops_.end()); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void EasyUnlockKeyManager::RefreshKeys(const UserContext& user_context, | 44 void EasyUnlockKeyManager::RefreshKeys(const UserContext& user_context, |
| 43 const base::ListValue& remote_devices, | 45 const base::ListValue& remote_devices, |
| 44 const RefreshKeysCallback& callback) { | 46 const RefreshKeysCallback& callback) { |
| 45 // Must have the secret. | 47 // Must have the secret. |
| 46 DCHECK(!user_context.GetKey()->GetSecret().empty()); | 48 DCHECK(!user_context.GetKey()->GetSecret().empty()); |
| 47 | 49 |
| 50 base::Closure do_refresh_keys = base::Bind( |
| 51 &EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent, |
| 52 weak_ptr_factory_.GetWeakPtr(), |
| 53 user_context, |
| 54 base::Owned(remote_devices.DeepCopy()), |
| 55 callback); |
| 56 |
| 57 EasyUnlockTpmKeyManager* tpm_key_manager = |
| 58 EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( |
| 59 user_context.GetUserID()); |
| 60 if (!tpm_key_manager) { |
| 61 LOG(ERROR) << "No TPM key manager."; |
| 62 callback.Run(false); |
| 63 return; |
| 64 } |
| 65 |
| 66 if (tpm_key_manager->PrepareTpmKey(user_context.GetUserID(), |
| 67 false /* check_private_key */, |
| 68 do_refresh_keys)) { |
| 69 do_refresh_keys.Run(); |
| 70 } else { |
| 71 // In case Chrome is supposed to restart to apply user session flags, the |
| 72 // Chrome restart will be postponed until Easy Sign-in keys are refreshed. |
| 73 // This is to ensure that creating TPM key does not hang if TPM system |
| 74 // loading takes too much time. Note that in normal circumstances the |
| 75 // chances that TPM slot cannot be loaded should be extremely low. |
| 76 // TODO(tbarzic): Add some metrics to measure if the timeout even gets hit. |
| 77 tpm_key_manager->SetGetSystemSlotTimeoutMs(2000); |
| 78 } |
| 79 } |
| 80 |
| 81 void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent( |
| 82 const UserContext& user_context, |
| 83 base::ListValue* remote_devices, |
| 84 const RefreshKeysCallback& callback) { |
| 85 EasyUnlockTpmKeyManager* tpm_key_manager = |
| 86 EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( |
| 87 user_context.GetUserID()); |
| 88 std::string tpm_public_key = |
| 89 tpm_key_manager->GetPublicTpmKey(user_context.GetUserID()); |
| 90 |
| 48 EasyUnlockDeviceKeyDataList devices; | 91 EasyUnlockDeviceKeyDataList devices; |
| 49 if (!RemoteDeviceListToDeviceDataList(remote_devices, &devices)) | 92 if (!RemoteDeviceListToDeviceDataList(*remote_devices, &devices)) |
| 50 devices.clear(); | 93 devices.clear(); |
| 51 | 94 |
| 52 // Only one pending request. | 95 // Only one pending request. |
| 53 DCHECK(!HasPendingOperations()); | 96 DCHECK(!HasPendingOperations()); |
| 54 create_keys_op_.reset(new EasyUnlockCreateKeysOperation( | 97 create_keys_op_.reset(new EasyUnlockCreateKeysOperation( |
| 55 user_context, | 98 user_context, |
| 99 tpm_public_key, |
| 56 devices, | 100 devices, |
| 57 base::Bind(&EasyUnlockKeyManager::OnKeysCreated, | 101 base::Bind(&EasyUnlockKeyManager::OnKeysCreated, |
| 58 weak_ptr_factory_.GetWeakPtr(), | 102 weak_ptr_factory_.GetWeakPtr(), |
| 59 devices.size(), | 103 devices.size(), |
| 60 callback))); | 104 callback))); |
| 61 create_keys_op_->Start(); | 105 create_keys_op_->Start(); |
| 62 } | 106 } |
| 63 | 107 |
| 64 void EasyUnlockKeyManager::RemoveKeys(const UserContext& user_context, | 108 void EasyUnlockKeyManager::RemoveKeys(const UserContext& user_context, |
| 65 size_t start_index, | 109 size_t start_index, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 279 } |
| 236 | 280 |
| 237 if (!callback.is_null()) | 281 if (!callback.is_null()) |
| 238 callback.Run(fetch_success, fetched_data); | 282 callback.Run(fetch_success, fetched_data); |
| 239 | 283 |
| 240 if (!HasPendingOperations()) | 284 if (!HasPendingOperations()) |
| 241 RunNextPendingOp(); | 285 RunNextPendingOp(); |
| 242 } | 286 } |
| 243 | 287 |
| 244 } // namespace chromeos | 288 } // namespace chromeos |
| OLD | NEW |