| OLD | NEW |
| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/time/default_clock.h" | 13 #include "base/time/default_clock.h" |
| 14 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "components/proximity_auth/ble/pref_names.h" | 16 #include "components/proximity_auth/ble/pref_names.h" |
| 17 #include "components/proximity_auth/bluetooth_connection_finder.h" | 17 #include "components/proximity_auth/bluetooth_connection_finder.h" |
| 18 #include "components/proximity_auth/cryptauth/base64url.h" | 18 #include "components/proximity_auth/cryptauth/base64url.h" |
| 19 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" | 19 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" |
| 20 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" | 20 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" |
| 21 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" | 21 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" |
| 22 #include "components/proximity_auth/logging/logging.h" | 22 #include "components/proximity_auth/logging/logging.h" |
| 23 #include "components/proximity_auth/messenger.h" | 23 #include "components/proximity_auth/messenger.h" |
| 24 #include "components/proximity_auth/remote_device_life_cycle_impl.h" | 24 #include "components/proximity_auth/remote_device_life_cycle_impl.h" |
| 25 #include "components/proximity_auth/remote_device_loader.h" |
| 25 #include "components/proximity_auth/remote_status_update.h" | 26 #include "components/proximity_auth/remote_status_update.h" |
| 26 #include "components/proximity_auth/secure_context.h" | 27 #include "components/proximity_auth/secure_context.h" |
| 27 #include "components/proximity_auth/webui/reachable_phone_flow.h" | 28 #include "components/proximity_auth/webui/reachable_phone_flow.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 30 #include "device/bluetooth/bluetooth_uuid.h" | 31 #include "device/bluetooth/bluetooth_uuid.h" |
| 31 | 32 |
| 32 namespace proximity_auth { | 33 namespace proximity_auth { |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 return; | 338 return; |
| 338 } | 339 } |
| 339 | 340 |
| 340 for (const auto& unlock_key : device_manager->unlock_keys()) { | 341 for (const auto& unlock_key : device_manager->unlock_keys()) { |
| 341 if (unlock_key.public_key() == public_key) { | 342 if (unlock_key.public_key() == public_key) { |
| 342 if (life_cycle_ && selected_remote_device_.public_key == public_key) { | 343 if (life_cycle_ && selected_remote_device_.public_key == public_key) { |
| 343 CleanUpRemoteDeviceLifeCycle(); | 344 CleanUpRemoteDeviceLifeCycle(); |
| 344 return; | 345 return; |
| 345 } | 346 } |
| 346 | 347 |
| 347 // Derive the PSK before connecting to the device. | 348 remote_device_loader_.reset(new RemoteDeviceLoader( |
| 348 PA_LOG(INFO) << "Deriving PSK before connecting to " | 349 std::vector<cryptauth::ExternalDeviceInfo>(1, unlock_key), |
| 349 << unlock_key.friendly_device_name(); | 350 proximity_auth_client_->GetAccountId(), |
| 350 secure_message_delegate_ = | 351 enrollment_manager->GetUserPrivateKey(), |
| 351 proximity_auth_client_->CreateSecureMessageDelegate(); | 352 proximity_auth_client_->CreateSecureMessageDelegate())); |
| 352 secure_message_delegate_->DeriveKey( | 353 remote_device_loader_->Load( |
| 353 enrollment_manager->GetUserPrivateKey(), unlock_key.public_key(), | 354 base::Bind(&ProximityAuthWebUIHandler::OnRemoteDevicesLoaded, |
| 354 base::Bind(&ProximityAuthWebUIHandler::OnPSKDerived, | 355 weak_ptr_factory_.GetWeakPtr())); |
| 355 weak_ptr_factory_.GetWeakPtr(), unlock_key)); | |
| 356 | |
| 357 return; | 356 return; |
| 358 } | 357 } |
| 359 } | 358 } |
| 360 | 359 |
| 361 PA_LOG(ERROR) << "Unlock key (" << b64_public_key << ") not found"; | 360 PA_LOG(ERROR) << "Unlock key (" << b64_public_key << ") not found"; |
| 362 } | 361 } |
| 363 | 362 |
| 364 void ProximityAuthWebUIHandler::OnCryptAuthClientError( | 363 void ProximityAuthWebUIHandler::OnCryptAuthClientError( |
| 365 const std::string& error_message) { | 364 const std::string& error_message) { |
| 366 PA_LOG(WARNING) << "CryptAuth request failed: " << error_message; | 365 PA_LOG(WARNING) << "CryptAuth request failed: " << error_message; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 if (!device_manager) | 454 if (!device_manager) |
| 456 return unlock_keys; | 455 return unlock_keys; |
| 457 | 456 |
| 458 for (const auto& unlock_key : device_manager->unlock_keys()) { | 457 for (const auto& unlock_key : device_manager->unlock_keys()) { |
| 459 unlock_keys->Append(ExternalDeviceInfoToDictionary(unlock_key)); | 458 unlock_keys->Append(ExternalDeviceInfoToDictionary(unlock_key)); |
| 460 } | 459 } |
| 461 | 460 |
| 462 return unlock_keys; | 461 return unlock_keys; |
| 463 } | 462 } |
| 464 | 463 |
| 465 void ProximityAuthWebUIHandler::OnPSKDerived( | 464 void ProximityAuthWebUIHandler::OnRemoteDevicesLoaded( |
| 466 const cryptauth::ExternalDeviceInfo& unlock_key, | 465 const std::vector<RemoteDevice>& remote_devices) { |
| 467 const std::string& persistent_symmetric_key) { | 466 if (remote_devices[0].persistent_symmetric_key.empty()) { |
| 468 if (persistent_symmetric_key.empty()) { | |
| 469 PA_LOG(ERROR) << "Failed to derive PSK."; | 467 PA_LOG(ERROR) << "Failed to derive PSK."; |
| 470 return; | 468 return; |
| 471 } | 469 } |
| 472 | 470 |
| 473 selected_remote_device_ = | 471 selected_remote_device_ = remote_devices[0]; |
| 474 RemoteDevice(unlock_key.friendly_device_name(), unlock_key.public_key(), | |
| 475 unlock_key.bluetooth_address(), persistent_symmetric_key); | |
| 476 | |
| 477 life_cycle_.reset(new RemoteDeviceLifeCycleImpl(selected_remote_device_, | 472 life_cycle_.reset(new RemoteDeviceLifeCycleImpl(selected_remote_device_, |
| 478 proximity_auth_client_)); | 473 proximity_auth_client_)); |
| 479 life_cycle_->AddObserver(this); | 474 life_cycle_->AddObserver(this); |
| 480 life_cycle_->Start(); | 475 life_cycle_->Start(); |
| 481 } | 476 } |
| 482 | 477 |
| 483 scoped_ptr<base::DictionaryValue> | 478 scoped_ptr<base::DictionaryValue> |
| 484 ProximityAuthWebUIHandler::ExternalDeviceInfoToDictionary( | 479 ProximityAuthWebUIHandler::ExternalDeviceInfoToDictionary( |
| 485 const cryptauth::ExternalDeviceInfo& device_info) { | 480 const cryptauth::ExternalDeviceInfo& device_info) { |
| 486 std::string base64_public_key; | 481 std::string base64_public_key; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 << "\n trust_agent_state: " | 598 << "\n trust_agent_state: " |
| 604 << static_cast<int>(status_update.trust_agent_state); | 599 << static_cast<int>(status_update.trust_agent_state); |
| 605 | 600 |
| 606 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update)); | 601 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update)); |
| 607 scoped_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); | 602 scoped_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); |
| 608 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", | 603 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", |
| 609 *unlock_keys); | 604 *unlock_keys); |
| 610 } | 605 } |
| 611 | 606 |
| 612 } // namespace proximity_auth | 607 } // namespace proximity_auth |
| OLD | NEW |