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

Side by Side Diff: components/proximity_auth/webui/proximity_auth_webui_handler.cc

Issue 2561683002: Update CryptAuthDeviceManager to store all synced devices instead of only unlock keys. (Closed)
Patch Set: tengs@ comments. Created 4 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/proximity_auth/webui/proximity_auth_webui_handler.h" 5 #include "components/proximity_auth/webui/proximity_auth_webui_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64url.h" 10 #include "base/base64url.h"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 std::string b64_public_key; 334 std::string b64_public_key;
335 std::string public_key; 335 std::string public_key;
336 if (!enrollment_manager || !device_manager || !args->GetSize() || 336 if (!enrollment_manager || !device_manager || !args->GetSize() ||
337 !args->GetString(0, &b64_public_key) || 337 !args->GetString(0, &b64_public_key) ||
338 !base::Base64UrlDecode(b64_public_key, 338 !base::Base64UrlDecode(b64_public_key,
339 base::Base64UrlDecodePolicy::REQUIRE_PADDING, 339 base::Base64UrlDecodePolicy::REQUIRE_PADDING,
340 &public_key)) { 340 &public_key)) {
341 return; 341 return;
342 } 342 }
343 343
344 for (const auto& unlock_key : device_manager->unlock_keys()) { 344 for (const auto& unlock_key : device_manager->UnlockKeys()) {
345 if (unlock_key.public_key() == public_key) { 345 if (unlock_key.public_key() == public_key) {
346 if (life_cycle_ && selected_remote_device_.public_key == public_key) { 346 if (life_cycle_ && selected_remote_device_.public_key == public_key) {
347 CleanUpRemoteDeviceLifeCycle(); 347 CleanUpRemoteDeviceLifeCycle();
348 return; 348 return;
349 } 349 }
350 350
351 // TODO(sacomoto): Pass an instance of ProximityAuthPrefManager. This is 351 // TODO(sacomoto): Pass an instance of ProximityAuthPrefManager. This is
352 // used to get the address of BLE devices. 352 // used to get the address of BLE devices.
353 remote_device_loader_.reset(new RemoteDeviceLoader( 353 remote_device_loader_.reset(new RemoteDeviceLoader(
354 std::vector<cryptauth::ExternalDeviceInfo>(1, unlock_key), 354 std::vector<cryptauth::ExternalDeviceInfo>(1, unlock_key),
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 456 }
457 457
458 std::unique_ptr<base::ListValue> 458 std::unique_ptr<base::ListValue>
459 ProximityAuthWebUIHandler::GetUnlockKeysList() { 459 ProximityAuthWebUIHandler::GetUnlockKeysList() {
460 std::unique_ptr<base::ListValue> unlock_keys(new base::ListValue()); 460 std::unique_ptr<base::ListValue> unlock_keys(new base::ListValue());
461 cryptauth::CryptAuthDeviceManager* device_manager = 461 cryptauth::CryptAuthDeviceManager* device_manager =
462 proximity_auth_client_->GetCryptAuthDeviceManager(); 462 proximity_auth_client_->GetCryptAuthDeviceManager();
463 if (!device_manager) 463 if (!device_manager)
464 return unlock_keys; 464 return unlock_keys;
465 465
466 for (const auto& unlock_key : device_manager->unlock_keys()) { 466 for (const auto& unlock_key : device_manager->UnlockKeys()) {
467 unlock_keys->Append(ExternalDeviceInfoToDictionary(unlock_key)); 467 unlock_keys->Append(ExternalDeviceInfoToDictionary(unlock_key));
468 } 468 }
469 469
470 return unlock_keys; 470 return unlock_keys;
471 } 471 }
472 472
473 void ProximityAuthWebUIHandler::OnRemoteDevicesLoaded( 473 void ProximityAuthWebUIHandler::OnRemoteDevicesLoaded(
474 const std::vector<cryptauth::RemoteDevice>& remote_devices) { 474 const std::vector<cryptauth::RemoteDevice>& remote_devices) {
475 if (remote_devices[0].persistent_symmetric_key.empty()) { 475 if (remote_devices[0].persistent_symmetric_key.empty()) {
476 PA_LOG(ERROR) << "Failed to derive PSK."; 476 PA_LOG(ERROR) << "Failed to derive PSK.";
(...skipping 30 matching lines...) Expand all
507 cryptauth::CryptAuthDeviceManager* device_manager = 507 cryptauth::CryptAuthDeviceManager* device_manager =
508 proximity_auth_client_->GetCryptAuthDeviceManager(); 508 proximity_auth_client_->GetCryptAuthDeviceManager();
509 if (!device_manager) 509 if (!device_manager)
510 return dictionary; 510 return dictionary;
511 511
512 // If |device_info| is a known unlock key, then combine the proto data with 512 // If |device_info| is a known unlock key, then combine the proto data with
513 // the corresponding local device data (e.g. connection status and remote 513 // the corresponding local device data (e.g. connection status and remote
514 // status updates). 514 // status updates).
515 std::string public_key = device_info.public_key(); 515 std::string public_key = device_info.public_key();
516 auto iterator = std::find_if( 516 auto iterator = std::find_if(
517 device_manager->unlock_keys().begin(), 517 device_manager->UnlockKeys().begin(), device_manager->UnlockKeys().end(),
518 device_manager->unlock_keys().end(),
519 [&public_key](const cryptauth::ExternalDeviceInfo& unlock_key) { 518 [&public_key](const cryptauth::ExternalDeviceInfo& unlock_key) {
520 return unlock_key.public_key() == public_key; 519 return unlock_key.public_key() == public_key;
521 }); 520 });
522 521
523 if (iterator == device_manager->unlock_keys().end() || 522 if (iterator == device_manager->UnlockKeys().end() ||
524 selected_remote_device_.public_key != device_info.public_key()) 523 selected_remote_device_.public_key != device_info.public_key())
525 return dictionary; 524 return dictionary;
526 525
527 // Fill in the current Bluetooth connection status. 526 // Fill in the current Bluetooth connection status.
528 std::string connection_status = kExternalDeviceDisconnected; 527 std::string connection_status = kExternalDeviceDisconnected;
529 if (life_cycle_ && 528 if (life_cycle_ &&
530 life_cycle_->GetState() == 529 life_cycle_->GetState() ==
531 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) { 530 RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) {
532 connection_status = kExternalDeviceConnected; 531 connection_status = kExternalDeviceConnected;
533 } else if (life_cycle_) { 532 } else if (life_cycle_) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 << "\n trust_agent_state: " 609 << "\n trust_agent_state: "
611 << static_cast<int>(status_update.trust_agent_state); 610 << static_cast<int>(status_update.trust_agent_state);
612 611
613 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update)); 612 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update));
614 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); 613 std::unique_ptr<base::ListValue> unlock_keys = GetUnlockKeysList();
615 web_ui()->CallJavascriptFunctionUnsafe( 614 web_ui()->CallJavascriptFunctionUnsafe(
616 "LocalStateInterface.onUnlockKeysChanged", *unlock_keys); 615 "LocalStateInterface.onUnlockKeysChanged", *unlock_keys);
617 } 616 }
618 617
619 } // namespace proximity_auth 618 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698