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/signin/easy_unlock_service_regular.h" | 5 #include "chrome/browser/signin/easy_unlock_service_regular.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/base64url.h" | 11 #include "base/base64url.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/json/json_string_value_serializer.h" | |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
16 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
17 #include "base/time/default_clock.h" | 18 #include "base/time/default_clock.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h" | 22 #include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h" |
22 #include "chrome/browser/gcm/gcm_profile_service_factory.h" | 23 #include "chrome/browser/gcm/gcm_profile_service_factory.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 &b64_psk); | 129 &b64_psk); |
129 | 130 |
130 dict->SetString("name", device.name); | 131 dict->SetString("name", device.name); |
131 dict->SetString("psk", b64_psk); | 132 dict->SetString("psk", b64_psk); |
132 dict->SetString("bluetoothAddress", device.bluetooth_address); | 133 dict->SetString("bluetoothAddress", device.bluetooth_address); |
133 dict->SetString("permitId", "permit://google.com/easyunlock/v1/" + | 134 dict->SetString("permitId", "permit://google.com/easyunlock/v1/" + |
134 proximity_auth_client()->GetAccountId()); | 135 proximity_auth_client()->GetAccountId()); |
135 dict->SetString("permitRecord.id", b64_public_key); | 136 dict->SetString("permitRecord.id", b64_public_key); |
136 dict->SetString("permitRecord.type", "license"); | 137 dict->SetString("permitRecord.type", "license"); |
137 dict->SetString("permitRecord.data", b64_public_key); | 138 dict->SetString("permitRecord.data", b64_public_key); |
139 | |
140 // TODO(tengs): Retrieve the actual BeaconSeeds from the RemoteDevice. | |
141 std::vector<cryptauth::BeaconSeed> beacon_seeds; | |
142 std::unique_ptr<base::ListValue> beacon_seed_list(new base::ListValue()); | |
143 for (const auto& beacon_seed : beacon_seeds) { | |
144 std::string b64_beacon_seed; | |
145 base::Base64UrlEncode(beacon_seed.SerializeAsString(), | |
146 base::Base64UrlEncodePolicy::INCLUDE_PADDING, | |
147 &b64_beacon_seed); | |
148 PA_LOG(INFO) << " beacon_seed: " << b64_beacon_seed; | |
Ryan Hansberry
2017/05/09 02:44:08
nit: Make the output of this prettier. At least ma
Tim Song
2017/05/10 18:23:26
Done. I just deleted this log; it's a bit unnecess
| |
149 beacon_seed_list->AppendString(b64_beacon_seed); | |
150 } | |
151 | |
152 PA_LOG(INFO) << "Serializing " << beacon_seed_list->GetSize() << " seeds."; | |
153 std::string serialized_beacon_seeds; | |
154 JSONStringValueSerializer serializer(&serialized_beacon_seeds); | |
155 serializer.Serialize(*beacon_seed_list); | |
156 dict->SetString("serializedBeaconSeeds", serialized_beacon_seeds); | |
157 | |
138 device_list->Append(std::move(dict)); | 158 device_list->Append(std::move(dict)); |
139 } | 159 } |
140 | 160 |
141 // TODO(tengs): Rename this function after the easy_unlock app is replaced. | 161 // TODO(tengs): Rename this function after the easy_unlock app is replaced. |
142 SetRemoteDevices(*device_list); | 162 SetRemoteDevices(*device_list); |
143 #endif | 163 #endif |
144 } | 164 } |
145 | 165 |
146 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { | 166 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { |
147 return EasyUnlockService::TYPE_REGULAR; | 167 return EasyUnlockService::TYPE_REGULAR; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 const base::DictionaryValue* pairing_dict = | 268 const base::DictionaryValue* pairing_dict = |
249 profile()->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing); | 269 profile()->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing); |
250 const base::ListValue* devices = NULL; | 270 const base::ListValue* devices = NULL; |
251 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices)) | 271 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices)) |
252 return devices; | 272 return devices; |
253 return NULL; | 273 return NULL; |
254 } | 274 } |
255 | 275 |
256 void EasyUnlockServiceRegular::SetRemoteDevices( | 276 void EasyUnlockServiceRegular::SetRemoteDevices( |
257 const base::ListValue& devices) { | 277 const base::ListValue& devices) { |
278 std::string remote_devices_json; | |
279 JSONStringValueSerializer serializer(&remote_devices_json); | |
280 serializer.Serialize(devices); | |
281 PA_LOG(INFO) << "Setting RemoteDevices:\n " << remote_devices_json; | |
Ryan Hansberry
2017/05/09 02:44:08
nit: remove the line break.
Tim Song
2017/05/10 18:23:26
The line break makes the JSON more readable, as it
| |
282 | |
258 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), | 283 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), |
259 prefs::kEasyUnlockPairing); | 284 prefs::kEasyUnlockPairing); |
260 if (devices.empty()) | 285 if (devices.empty()) |
261 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); | 286 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); |
262 else | 287 else |
263 pairing_update->SetWithoutPathExpansion( | 288 pairing_update->SetWithoutPathExpansion( |
264 kKeyDevices, base::MakeUnique<base::Value>(devices)); | 289 kKeyDevices, base::MakeUnique<base::Value>(devices)); |
265 | 290 |
266 #if defined(OS_CHROMEOS) | 291 #if defined(OS_CHROMEOS) |
267 // TODO(tengs): Investigate if we can determine if the remote devices were set | 292 // TODO(tengs): Investigate if we can determine if the remote devices were set |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 | 618 |
594 cryptauth::CryptAuthDeviceManager* | 619 cryptauth::CryptAuthDeviceManager* |
595 EasyUnlockServiceRegular::GetCryptAuthDeviceManager() { | 620 EasyUnlockServiceRegular::GetCryptAuthDeviceManager() { |
596 cryptauth::CryptAuthDeviceManager* manager = | 621 cryptauth::CryptAuthDeviceManager* manager = |
597 ChromeCryptAuthServiceFactory::GetInstance() | 622 ChromeCryptAuthServiceFactory::GetInstance() |
598 ->GetForBrowserContext(profile()) | 623 ->GetForBrowserContext(profile()) |
599 ->GetCryptAuthDeviceManager(); | 624 ->GetCryptAuthDeviceManager(); |
600 DCHECK(manager); | 625 DCHECK(manager); |
601 return manager; | 626 return manager; |
602 } | 627 } |
OLD | NEW |