Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/signin/easy_unlock_service_signin_chromeos.cc

Issue 2863533003: [EasyUnlock] Serialize and store BeaconSeeds along as cryptohome key metadata. (Closed)
Patch Set: [EasyUnlock] Serialize and store BeaconSeeds along as cryptohome key metadata. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_signin_chromeos.h" 5 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/base64url.h" 9 #include "base/base64url.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/json/json_string_value_serializer.h"
12 #include "base/location.h" 13 #include "base/location.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/sys_info.h" 16 #include "base/sys_info.h"
16 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_challenge_wrappe r.h" 19 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_challenge_wrappe r.h"
19 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" 20 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h"
20 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager. h" 21 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager. h"
21 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_ factory.h" 22 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_ factory.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback) { 87 const chromeos::EasyUnlockKeyManager::GetDeviceDataListCallback& callback) {
87 chromeos::EasyUnlockKeyManager* key_manager = 88 chromeos::EasyUnlockKeyManager* key_manager =
88 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); 89 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
89 DCHECK(key_manager); 90 DCHECK(key_manager);
90 91
91 key_manager->GetDeviceDataList( 92 key_manager->GetDeviceDataList(
92 chromeos::UserContext(account_id), 93 chromeos::UserContext(account_id),
93 base::Bind(&RetryDataLoadOnError, account_id, backoff_ms, callback)); 94 base::Bind(&RetryDataLoadOnError, account_id, backoff_ms, callback));
94 } 95 }
95 96
97 // Deserializes a vector of BeaconSeeds. If an error occurs, an empty vector
98 // will be returned. Note: The logic to serialize BeaconSeeds lives in
99 // EasyUnlockServiceRegular.
100 std::vector<cryptauth::BeaconSeed> DeserializeBeaconSeeds(
Ryan Hansberry 2017/05/09 02:44:08 Why should serialization and deserialization logic
Tim Song 2017/05/10 18:23:26 This would require some refactoring. Essentially,
Ryan Hansberry 2017/05/15 15:36:41 Got it. Can you please add a comment explaining th
Tim Song 2017/05/17 19:18:07 Done.
101 const std::string& serialized_beacon_seeds) {
102 std::vector<cryptauth::BeaconSeed> beacon_seeds;
103
104 JSONStringValueDeserializer deserializer(serialized_beacon_seeds);
105 std::string error;
106 std::unique_ptr<base::Value> deserialized_value =
107 deserializer.Deserialize(nullptr, &error);
108 if (!deserialized_value) {
109 PA_LOG(ERROR) << "Unable to deserialize BeaconSeeds: " << error;
110 return beacon_seeds;
111 }
112
113 base::ListValue* beacon_seed_list;
114 if (!deserialized_value->GetAsList(&beacon_seed_list)) {
115 PA_LOG(ERROR) << "Deserialized BeaconSeeds value is not list.";
116 return beacon_seeds;
117 }
118
119 for (size_t i = 0; i < beacon_seed_list->GetSize(); ++i) {
120 std::string b64_beacon_seed;
121 if (!beacon_seed_list->GetString(i, &b64_beacon_seed)) {
122 PA_LOG(ERROR) << "Expected Base64 BeaconSeed.";
123 continue;
124 }
125
126 std::string proto_serialized_beacon_seed;
127 if (!base::Base64UrlDecode(b64_beacon_seed,
128 base::Base64UrlDecodePolicy::REQUIRE_PADDING,
129 &proto_serialized_beacon_seed)) {
130 PA_LOG(ERROR) << "Unable to Base64 decode BeaconSeed.";
131 continue;
132 }
133
134 cryptauth::BeaconSeed beacon_seed;
135 if (!beacon_seed.ParseFromString(proto_serialized_beacon_seed)) {
136 PA_LOG(ERROR) << "Unable to parse BeaconSeed proto.";
137 continue;
138 }
139
140 beacon_seeds.push_back(beacon_seed);
141 }
142
143 PA_LOG(INFO) << "Deserialized " << beacon_seeds.size() << " BeaconSeeds.";
144 return beacon_seeds;
145 }
146
96 } // namespace 147 } // namespace
97 148
98 EasyUnlockServiceSignin::UserData::UserData() 149 EasyUnlockServiceSignin::UserData::UserData()
99 : state(EasyUnlockServiceSignin::USER_DATA_STATE_INITIAL) { 150 : state(EasyUnlockServiceSignin::USER_DATA_STATE_INITIAL) {
100 } 151 }
101 152
102 EasyUnlockServiceSignin::UserData::~UserData() {} 153 EasyUnlockServiceSignin::UserData::~UserData() {}
103 154
104 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile) 155 EasyUnlockServiceSignin::EasyUnlockServiceSignin(Profile* profile)
105 : EasyUnlockService(profile), 156 : EasyUnlockService(profile),
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 return; 480 return;
430 481
431 cryptauth::RemoteDeviceList remote_devices; 482 cryptauth::RemoteDeviceList remote_devices;
432 for (const auto& device : devices) { 483 for (const auto& device : devices) {
433 std::string decoded_public_key, decoded_psk, decoded_challenge; 484 std::string decoded_public_key, decoded_psk, decoded_challenge;
434 if (!base::Base64UrlDecode(device.public_key, 485 if (!base::Base64UrlDecode(device.public_key,
435 base::Base64UrlDecodePolicy::REQUIRE_PADDING, 486 base::Base64UrlDecodePolicy::REQUIRE_PADDING,
436 &decoded_public_key) || 487 &decoded_public_key) ||
437 !base::Base64UrlDecode(device.psk, 488 !base::Base64UrlDecode(device.psk,
438 base::Base64UrlDecodePolicy::REQUIRE_PADDING, 489 base::Base64UrlDecodePolicy::REQUIRE_PADDING,
439 &decoded_psk) || 490 &decoded_psk)) {
440 !base::Base64UrlDecode(device.challenge, 491 PA_LOG(ERROR) << "Unable base64url decode stored remote device:\n"
441 base::Base64UrlDecodePolicy::REQUIRE_PADDING, 492 << " public_key: " << device.public_key << "\n"
442 &decoded_challenge)) { 493 << " psk: " << device.psk;
443 PA_LOG(ERROR) << "Unable base64url decode stored remote device: "
444 << device.public_key;
445 continue; 494 continue;
446 } 495 }
447 cryptauth::RemoteDevice remote_device( 496 cryptauth::RemoteDevice remote_device(
448 account_id.GetUserEmail(), std::string(), decoded_public_key, 497 account_id.GetUserEmail(), std::string(), decoded_public_key,
449 device.bluetooth_address, decoded_psk, decoded_challenge); 498 device.bluetooth_address, decoded_psk, decoded_challenge);
499
500 if (!device.serialized_beacon_seeds.empty()) {
501 PA_LOG(INFO) << "Deserializing BeaconSeeds: "
502 << device.serialized_beacon_seeds;
503 // TODO(tengs): Assign deserialized BeaconSeeds to the RemoteDevice.
504 DeserializeBeaconSeeds(device.serialized_beacon_seeds);
505 } else {
506 PA_LOG(WARNING) << "No BeaconSeeds were loaded.";
507 }
508
450 remote_devices.push_back(remote_device); 509 remote_devices.push_back(remote_device);
451 PA_LOG(INFO) << "Loaded Remote Device:\n" 510 PA_LOG(INFO) << "Loaded Remote Device:\n"
452 << " user id: " << remote_device.user_id << "\n" 511 << " user id: " << remote_device.user_id << "\n"
453 << " name: " << remote_device.name << "\n" 512 << " name: " << remote_device.name << "\n"
454 << " public key" << device.public_key << "\n" 513 << " public key" << device.public_key << "\n"
455 << " bt_addr:" << remote_device.bluetooth_address; 514 << " bt_addr:" << remote_device.bluetooth_address;
456 } 515 }
457 516
458 SetProximityAuthDevices(account_id, remote_devices); 517 SetProximityAuthDevices(account_id, remote_devices);
459 } 518 }
460 519
461 const EasyUnlockServiceSignin::UserData* 520 const EasyUnlockServiceSignin::UserData*
462 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { 521 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const {
463 if (!account_id_.is_valid()) 522 if (!account_id_.is_valid())
464 return nullptr; 523 return nullptr;
465 524
466 const auto it = user_data_.find(account_id_); 525 const auto it = user_data_.find(account_id_);
467 if (it == user_data_.end()) 526 if (it == user_data_.end())
468 return nullptr; 527 return nullptr;
469 if (it->second->state != USER_DATA_STATE_LOADED) 528 if (it->second->state != USER_DATA_STATE_LOADED)
470 return nullptr; 529 return nullptr;
471 return it->second.get(); 530 return it->second.get();
472 } 531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698