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(false /* check_private_key */, |
| 67 do_refresh_keys)) { |
| 68 do_refresh_keys.Run(); |
| 69 } else { |
| 70 // In case Chrome is supposed to restart to apply user session flags, the |
| 71 // Chrome restart will be postponed until Easy Sign-in keys are refreshed. |
| 72 // This is to ensure that creating TPM key does not hang if TPM system |
| 73 // loading takes too much time. Note that in normal circumstances the |
| 74 // chances that TPM slot cannot be loaded should be extremely low. |
| 75 // TODO(tbarzic): Add some metrics to measure if the timeout even gets hit. |
| 76 tpm_key_manager->StartGetSystemSlotTimeoutMs(2000); |
| 77 } |
| 78 } |
| 79 |
| 80 void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent( |
| 81 const UserContext& user_context, |
| 82 base::ListValue* remote_devices, |
| 83 const RefreshKeysCallback& callback) { |
| 84 EasyUnlockTpmKeyManager* tpm_key_manager = |
| 85 EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser( |
| 86 user_context.GetUserID()); |
| 87 std::string tpm_public_key = |
| 88 tpm_key_manager->GetPublicTpmKey(user_context.GetUserID()); |
| 89 |
48 EasyUnlockDeviceKeyDataList devices; | 90 EasyUnlockDeviceKeyDataList devices; |
49 if (!RemoteDeviceListToDeviceDataList(remote_devices, &devices)) | 91 if (!RemoteDeviceListToDeviceDataList(*remote_devices, &devices)) |
50 devices.clear(); | 92 devices.clear(); |
51 | 93 |
52 // Only one pending request. | 94 // Only one pending request. |
53 DCHECK(!HasPendingOperations()); | 95 DCHECK(!HasPendingOperations()); |
54 create_keys_op_.reset(new EasyUnlockCreateKeysOperation( | 96 create_keys_op_.reset(new EasyUnlockCreateKeysOperation( |
55 user_context, | 97 user_context, |
| 98 tpm_public_key, |
56 devices, | 99 devices, |
57 base::Bind(&EasyUnlockKeyManager::OnKeysCreated, | 100 base::Bind(&EasyUnlockKeyManager::OnKeysCreated, |
58 weak_ptr_factory_.GetWeakPtr(), | 101 weak_ptr_factory_.GetWeakPtr(), |
59 devices.size(), | 102 devices.size(), |
60 callback))); | 103 callback))); |
61 create_keys_op_->Start(); | 104 create_keys_op_->Start(); |
62 } | 105 } |
63 | 106 |
64 void EasyUnlockKeyManager::RemoveKeys(const UserContext& user_context, | 107 void EasyUnlockKeyManager::RemoveKeys(const UserContext& user_context, |
65 size_t start_index, | 108 size_t start_index, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 278 } |
236 | 279 |
237 if (!callback.is_null()) | 280 if (!callback.is_null()) |
238 callback.Run(fetch_success, fetched_data); | 281 callback.Run(fetch_success, fetched_data); |
239 | 282 |
240 if (!HasPendingOperations()) | 283 if (!HasPendingOperations()) |
241 RunNextPendingOp(); | 284 RunNextPendingOp(); |
242 } | 285 } |
243 | 286 |
244 } // namespace chromeos | 287 } // namespace chromeos |
OLD | NEW |