Commit d7bfd5bb authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

Proximity Auth: Remove kMultiDeviceApi flagging from ProxAuthWebuiHandler.

R=hansberry@chromium.org

Bug: 899324
Test: none
Change-Id: Iac6aacb1b40608d261d6c13b12fd37bfd6b0df8f
Reviewed-on: https://chromium-review.googlesource.com/c/1325393Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606865}
parent f513b7c0
......@@ -263,23 +263,12 @@ WebUIController* NewWebUI<proximity_auth::ProximityAuthUI>(WebUI* web_ui,
const GURL& url) {
content::BrowserContext* browser_context =
web_ui->GetWebContents()->GetBrowserContext();
// TODO(crbug.com/848956): Only pass DeviceSyncClient once Smart Lock has
// fully migrated to the DeviceSync API.
return new proximity_auth::ProximityAuthUI(
web_ui,
base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
? nullptr
: chromeos::EasyUnlockServiceFactory::GetForBrowserContext(
browser_context)
->proximity_auth_client(),
base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
? chromeos::device_sync::DeviceSyncClientFactory::GetForProfile(
Profile::FromBrowserContext(browser_context))
: nullptr,
base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
? chromeos::secure_channel::SecureChannelClientProvider::GetInstance()
->GetClient()
: nullptr);
chromeos::device_sync::DeviceSyncClientFactory::GetForProfile(
Profile::FromBrowserContext(browser_context)),
chromeos::secure_channel::SecureChannelClientProvider::GetInstance()
->GetClient());
}
#endif
......
......@@ -23,7 +23,6 @@ namespace proximity_auth {
ProximityAuthUI::ProximityAuthUI(
content::WebUI* web_ui,
ProximityAuthClient* proximity_auth_client,
chromeos::device_sync::DeviceSyncClient* device_sync_client,
chromeos::secure_channel::SecureChannelClient* secure_channel_client)
: ui::MojoWebUIController(web_ui, true /* enable_chrome_send */) {
......@@ -47,7 +46,7 @@ ProximityAuthUI::ProximityAuthUI(
web_ui->GetWebContents()->GetBrowserContext();
content::WebUIDataSource::Add(browser_context, source);
web_ui->AddMessageHandler(std::make_unique<ProximityAuthWebUIHandler>(
proximity_auth_client, device_sync_client, secure_channel_client));
device_sync_client, secure_channel_client));
AddHandlerToRegistry(base::BindRepeating(
&ProximityAuthUI::BindMultiDeviceSetup, base::Unretained(this)));
}
......
......@@ -23,16 +23,13 @@ class SecureChannelClient;
namespace proximity_auth {
class ProximityAuthClient;
// The WebUI controller for chrome://proximity-auth.
class ProximityAuthUI : public ui::MojoWebUIController {
public:
// Note: |web_ui| and |proximity_auth_client| are not owned by this instance
// and must outlive this instance.
// Note: |web_ui| is not owned by this instance and must outlive this
// instance.
ProximityAuthUI(
content::WebUI* web_ui,
ProximityAuthClient* proximity_auth_client,
chromeos::device_sync::DeviceSyncClient* device_sync_client,
chromeos::secure_channel::SecureChannelClient* secure_channel_client);
~ProximityAuthUI() override;
......
......@@ -21,13 +21,6 @@
#include "chromeos/components/proximity_auth/messenger.h"
#include "chromeos/components/proximity_auth/remote_device_life_cycle_impl.h"
#include "chromeos/components/proximity_auth/remote_status_update.h"
#include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h"
#include "components/cryptauth/proto/enum_util.h"
#include "components/cryptauth/remote_device_loader.h"
#include "components/cryptauth/remote_device_ref.h"
#include "components/cryptauth/secure_context.h"
#include "components/cryptauth/secure_message_delegate_impl.h"
#include "components/cryptauth/software_feature_state.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
......@@ -83,11 +76,8 @@ std::unique_ptr<base::DictionaryValue> LogMessageToDictionary(
const char kExternalDevicePublicKey[] = "publicKey";
const char kExternalDevicePublicKeyTruncated[] = "publicKeyTruncated";
const char kExternalDeviceFriendlyName[] = "friendlyDeviceName";
const char kExternalDeviceBluetoothAddress[] = "bluetoothAddress";
const char kExternalDeviceUnlockKey[] = "unlockKey";
const char kExternalDeviceMobileHotspot[] = "hasMobileHotspot";
const char kExternalDeviceIsArcPlusPlusEnrollment[] = "isArcPlusPlusEnrollment";
const char kExternalDeviceIsPixelPhone[] = "isPixelPhone";
const char kExternalDeviceConnectionStatus[] = "connectionStatus";
const char kExternalDeviceFeatureStates[] = "featureStates";
const char kExternalDeviceRemoteState[] = "remoteState";
......@@ -97,9 +87,6 @@ const char kExternalDeviceConnected[] = "connected";
const char kExternalDeviceDisconnected[] = "disconnected";
const char kExternalDeviceConnecting[] = "connecting";
// Keys in the JSON representation of an IneligibleDevice proto.
const char kIneligibleDeviceReasons[] = "ineligibilityReasons";
// Creates a SyncState JSON object that can be passed to the WebUI.
std::unique_ptr<base::DictionaryValue> CreateSyncStateDictionary(
double last_success_time,
......@@ -144,31 +131,17 @@ std::string GenerateFeaturesString(const cryptauth::RemoteDeviceRef& device) {
} // namespace
ProximityAuthWebUIHandler::ProximityAuthWebUIHandler(
ProximityAuthClient* proximity_auth_client,
chromeos::device_sync::DeviceSyncClient* device_sync_client,
chromeos::secure_channel::SecureChannelClient* secure_channel_client)
: proximity_auth_client_(proximity_auth_client),
device_sync_client_(device_sync_client),
: device_sync_client_(device_sync_client),
secure_channel_client_(secure_channel_client),
web_contents_initialized_(false),
weak_ptr_factory_(this) {
if (!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
cryptauth_client_factory_ =
proximity_auth_client_->CreateCryptAuthClientFactory();
}
}
weak_ptr_factory_(this) {}
ProximityAuthWebUIHandler::~ProximityAuthWebUIHandler() {
LogBuffer::GetInstance()->RemoveObserver(this);
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
device_sync_client_->RemoveObserver(this);
} else {
cryptauth::CryptAuthDeviceManager* device_manager =
proximity_auth_client_->GetCryptAuthDeviceManager();
if (device_manager)
device_manager->RemoveObserver(this);
}
device_sync_client_->RemoveObserver(this);
}
void ProximityAuthWebUIHandler::RegisterMessages() {
......@@ -231,41 +204,7 @@ void ProximityAuthWebUIHandler::OnLogBufferCleared() {
"LogBufferInterface.onLogBufferCleared");
}
void ProximityAuthWebUIHandler::OnEnrollmentStarted() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
web_ui()->CallJavascriptFunctionUnsafe(
"LocalStateInterface.onEnrollmentStateChanged",
*GetEnrollmentStateDictionary());
}
void ProximityAuthWebUIHandler::OnEnrollmentFinished(bool success) {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
NotifyOnEnrollmentFinished(success, GetEnrollmentStateDictionary());
}
void ProximityAuthWebUIHandler::OnSyncStarted() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
web_ui()->CallJavascriptFunctionUnsafe(
"LocalStateInterface.onDeviceSyncStateChanged",
*GetDeviceSyncStateDictionary());
}
void ProximityAuthWebUIHandler::OnSyncFinished(
cryptauth::CryptAuthDeviceManager::SyncResult sync_result,
cryptauth::CryptAuthDeviceManager::DeviceChangeResult
device_change_result) {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
NotifyOnSyncFinished(
sync_result == cryptauth::CryptAuthDeviceManager::SyncResult::
SUCCESS /* was_sync_successful */,
device_change_result == cryptauth::CryptAuthDeviceManager::
DeviceChangeResult::CHANGED /* changed */,
GetDeviceSyncStateDictionary());
}
void ProximityAuthWebUIHandler::OnEnrollmentFinished() {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
// OnGetDebugInfo() will call NotifyOnEnrollmentFinished() with the enrollment
// state info.
enrollment_update_waiting_for_debug_info_ = true;
......@@ -275,8 +214,6 @@ void ProximityAuthWebUIHandler::OnEnrollmentFinished() {
}
void ProximityAuthWebUIHandler::OnNewDevicesSynced() {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
// OnGetDebugInfo() will call NotifyOnSyncFinished() with the device sync
// state info.
sync_update_waiting_for_debug_info_ = true;
......@@ -288,22 +225,8 @@ void ProximityAuthWebUIHandler::OnNewDevicesSynced() {
void ProximityAuthWebUIHandler::OnWebContentsInitialized(
const base::ListValue* args) {
if (!web_contents_initialized_) {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
device_sync_client_->AddObserver(this);
} else {
cryptauth::CryptAuthEnrollmentManager* enrollment_manager =
proximity_auth_client_->GetCryptAuthEnrollmentManager();
if (enrollment_manager)
enrollment_manager->AddObserver(this);
cryptauth::CryptAuthDeviceManager* device_manager =
proximity_auth_client_->GetCryptAuthDeviceManager();
if (device_manager)
device_manager->AddObserver(this);
}
device_sync_client_->AddObserver(this);
LogBuffer::GetInstance()->AddObserver(this);
web_contents_initialized_ = true;
}
}
......@@ -335,80 +258,31 @@ void ProximityAuthWebUIHandler::ToggleUnlockKey(const base::ListValue* args) {
return;
}
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
device_sync_client_->SetSoftwareFeatureState(
public_key, cryptauth::SoftwareFeature::EASY_UNLOCK_HOST,
true /* enabled */, true /* is_exclusive */,
base::BindOnce(&ProximityAuthWebUIHandler::OnSetSoftwareFeatureState,
weak_ptr_factory_.GetWeakPtr(), public_key));
} else {
cryptauth::ToggleEasyUnlockRequest request;
request.set_enable(make_unlock_key);
request.set_public_key(public_key);
*(request.mutable_device_classifier()) =
proximity_auth_client_->GetDeviceClassifier();
PA_LOG(VERBOSE) << "Toggling unlock key:\n"
<< " public_key: " << public_key_b64 << "\n"
<< " make_unlock_key: " << make_unlock_key;
cryptauth_client_ = cryptauth_client_factory_->CreateInstance();
cryptauth_client_->ToggleEasyUnlock(
request,
base::Bind(&ProximityAuthWebUIHandler::OnEasyUnlockToggled,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&ProximityAuthWebUIHandler::OnCryptAuthClientError,
weak_ptr_factory_.GetWeakPtr()));
}
device_sync_client_->SetSoftwareFeatureState(
public_key, cryptauth::SoftwareFeature::EASY_UNLOCK_HOST,
true /* enabled */, true /* is_exclusive */,
base::BindOnce(&ProximityAuthWebUIHandler::OnSetSoftwareFeatureState,
weak_ptr_factory_.GetWeakPtr(), public_key));
}
void ProximityAuthWebUIHandler::FindEligibleUnlockDevices(
const base::ListValue* args) {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
device_sync_client_->FindEligibleDevices(
cryptauth::SoftwareFeature::EASY_UNLOCK_HOST,
base::BindOnce(&ProximityAuthWebUIHandler::OnFindEligibleDevices,
weak_ptr_factory_.GetWeakPtr()));
} else {
cryptauth_client_ = cryptauth_client_factory_->CreateInstance();
cryptauth::FindEligibleUnlockDevicesRequest request;
*(request.mutable_device_classifier()) =
proximity_auth_client_->GetDeviceClassifier();
cryptauth_client_->FindEligibleUnlockDevices(
request,
base::Bind(&ProximityAuthWebUIHandler::OnFoundEligibleUnlockDevices,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&ProximityAuthWebUIHandler::OnCryptAuthClientError,
weak_ptr_factory_.GetWeakPtr()));
}
device_sync_client_->FindEligibleDevices(
cryptauth::SoftwareFeature::EASY_UNLOCK_HOST,
base::BindOnce(&ProximityAuthWebUIHandler::OnFindEligibleDevices,
weak_ptr_factory_.GetWeakPtr()));
}
void ProximityAuthWebUIHandler::ForceEnrollment(const base::ListValue* args) {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
device_sync_client_->ForceEnrollmentNow(
base::BindOnce(&ProximityAuthWebUIHandler::OnForceEnrollmentNow,
weak_ptr_factory_.GetWeakPtr()));
} else {
cryptauth::CryptAuthEnrollmentManager* enrollment_manager =
proximity_auth_client_->GetCryptAuthEnrollmentManager();
if (enrollment_manager) {
enrollment_manager->ForceEnrollmentNow(
cryptauth::INVOCATION_REASON_MANUAL);
}
}
device_sync_client_->ForceEnrollmentNow(
base::BindOnce(&ProximityAuthWebUIHandler::OnForceEnrollmentNow,
weak_ptr_factory_.GetWeakPtr()));
}
void ProximityAuthWebUIHandler::ForceDeviceSync(const base::ListValue* args) {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
device_sync_client_->ForceSyncNow(
base::BindOnce(&ProximityAuthWebUIHandler::OnForceSyncNow,
weak_ptr_factory_.GetWeakPtr()));
} else {
cryptauth::CryptAuthDeviceManager* device_manager =
proximity_auth_client_->GetCryptAuthDeviceManager();
if (device_manager)
device_manager->ForceSyncNow(cryptauth::INVOCATION_REASON_MANUAL);
}
device_sync_client_->ForceSyncNow(
base::BindOnce(&ProximityAuthWebUIHandler::OnForceSyncNow,
weak_ptr_factory_.GetWeakPtr()));
}
void ProximityAuthWebUIHandler::ToggleConnection(const base::ListValue* args) {
......@@ -426,196 +300,49 @@ void ProximityAuthWebUIHandler::ToggleConnection(const base::ListValue* args) {
if (selected_remote_device_)
selected_device_public_key = selected_remote_device_->public_key();
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
for (const auto& remote_device : device_sync_client_->GetSyncedDevices()) {
if (remote_device.public_key() != public_key)
continue;
if (life_cycle_ && selected_device_public_key == public_key) {
CleanUpRemoteDeviceLifeCycle();
return;
}
for (const auto& remote_device : device_sync_client_->GetSyncedDevices()) {
if (remote_device.public_key() != public_key)
continue;
StartRemoteDeviceLifeCycle(remote_device);
}
} else {
cryptauth::CryptAuthEnrollmentManager* enrollment_manager =
proximity_auth_client_->GetCryptAuthEnrollmentManager();
cryptauth::CryptAuthDeviceManager* device_manager =
proximity_auth_client_->GetCryptAuthDeviceManager();
if (!enrollment_manager || !device_manager)
return;
for (const auto& unlock_key : device_manager->GetUnlockKeys()) {
if (unlock_key.public_key() != public_key)
continue;
if (life_cycle_ && selected_device_public_key == public_key) {
CleanUpRemoteDeviceLifeCycle();
return;
}
remote_device_loader_.reset(new cryptauth::RemoteDeviceLoader(
std::vector<cryptauth::ExternalDeviceInfo>(1, unlock_key),
proximity_auth_client_->GetAccountId(),
enrollment_manager->GetUserPrivateKey(),
cryptauth::SecureMessageDelegateImpl::Factory::NewInstance()));
remote_device_loader_->Load(
base::Bind(&ProximityAuthWebUIHandler::OnRemoteDevicesLoaded,
weak_ptr_factory_.GetWeakPtr()));
if (life_cycle_ && selected_device_public_key == public_key) {
CleanUpRemoteDeviceLifeCycle();
return;
}
}
}
void ProximityAuthWebUIHandler::OnCryptAuthClientError(
cryptauth::NetworkRequestError error) {
PA_LOG(WARNING) << "CryptAuth request failed: " << error;
std::stringstream ss;
ss << error;
base::Value error_string(ss.str());
web_ui()->CallJavascriptFunctionUnsafe("CryptAuthInterface.onError",
error_string);
}
void ProximityAuthWebUIHandler::OnEasyUnlockToggled(
const cryptauth::ToggleEasyUnlockResponse& response) {
web_ui()->CallJavascriptFunctionUnsafe(
"CryptAuthInterface.onUnlockKeyToggled");
// TODO(tengs): Update the local state to reflect the toggle.
}
void ProximityAuthWebUIHandler::OnFoundEligibleUnlockDevices(
const cryptauth::FindEligibleUnlockDevicesResponse& response) {
base::ListValue eligible_devices;
for (const auto& external_device : response.eligible_devices()) {
eligible_devices.Append(ExternalDeviceInfoToDictionary(external_device));
}
base::ListValue ineligible_devices;
for (const auto& ineligible_device : response.ineligible_devices()) {
ineligible_devices.Append(IneligibleDeviceToDictionary(ineligible_device));
StartRemoteDeviceLifeCycle(remote_device);
}
PA_LOG(VERBOSE) << "Found " << eligible_devices.GetSize()
<< " eligible devices and " << ineligible_devices.GetSize()
<< " ineligible devices.";
web_ui()->CallJavascriptFunctionUnsafe(
"CryptAuthInterface.onGotEligibleDevices", eligible_devices,
ineligible_devices);
}
void ProximityAuthWebUIHandler::GetLocalState(const base::ListValue* args) {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
// OnGetDebugInfo() will call NotifyGotLocalState() with the enrollment and
// device sync state info.
get_local_state_update_waiting_for_debug_info_ = true;
device_sync_client_->GetDebugInfo(
base::BindOnce(&ProximityAuthWebUIHandler::OnGetDebugInfo,
weak_ptr_factory_.GetWeakPtr()));
return;
}
NotifyGotLocalState(GetTruncatedLocalDeviceId(),
GetEnrollmentStateDictionary(),
GetDeviceSyncStateDictionary(), GetRemoteDevicesList());
// OnGetDebugInfo() will call NotifyGotLocalState() with the enrollment and
// device sync state info.
get_local_state_update_waiting_for_debug_info_ = true;
device_sync_client_->GetDebugInfo(
base::BindOnce(&ProximityAuthWebUIHandler::OnGetDebugInfo,
weak_ptr_factory_.GetWeakPtr()));
}
std::unique_ptr<base::Value>
ProximityAuthWebUIHandler::GetTruncatedLocalDeviceId() {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
return std::make_unique<base::Value>(
device_sync_client_->GetLocalDeviceMetadata()
->GetTruncatedDeviceIdForLogs());
}
std::string local_public_key =
proximity_auth_client_->GetLocalDevicePublicKey();
std::string device_id;
base::Base64UrlEncode(local_public_key,
base::Base64UrlEncodePolicy::INCLUDE_PADDING,
&device_id);
return std::make_unique<base::Value>(
cryptauth::RemoteDeviceRef::TruncateDeviceIdForLogs(device_id));
}
std::unique_ptr<base::DictionaryValue>
ProximityAuthWebUIHandler::GetEnrollmentStateDictionary() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
cryptauth::CryptAuthEnrollmentManager* enrollment_manager =
proximity_auth_client_->GetCryptAuthEnrollmentManager();
if (!enrollment_manager)
return std::make_unique<base::DictionaryValue>();
return CreateSyncStateDictionary(
enrollment_manager->GetLastEnrollmentTime().ToJsTime(),
enrollment_manager->GetTimeToNextAttempt().InMillisecondsF(),
enrollment_manager->IsRecoveringFromFailure(),
enrollment_manager->IsEnrollmentInProgress());
}
std::unique_ptr<base::DictionaryValue>
ProximityAuthWebUIHandler::GetDeviceSyncStateDictionary() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
cryptauth::CryptAuthDeviceManager* device_manager =
proximity_auth_client_->GetCryptAuthDeviceManager();
if (!device_manager)
return std::make_unique<base::DictionaryValue>();
return CreateSyncStateDictionary(
device_manager->GetLastSyncTime().ToJsTime(),
device_manager->GetTimeToNextAttempt().InMillisecondsF(),
device_manager->IsRecoveringFromFailure(),
device_manager->IsSyncInProgress());
device_sync_client_->GetLocalDeviceMetadata()
->GetTruncatedDeviceIdForLogs());
}
std::unique_ptr<base::ListValue>
ProximityAuthWebUIHandler::GetRemoteDevicesList() {
std::unique_ptr<base::ListValue> devices_list_value(new base::ListValue());
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
for (const auto& remote_device : device_sync_client_->GetSyncedDevices())
devices_list_value->Append(RemoteDeviceToDictionary(remote_device));
} else {
cryptauth::CryptAuthDeviceManager* device_manager =
proximity_auth_client_->GetCryptAuthDeviceManager();
if (!device_manager)
return devices_list_value;
for (const auto& unlock_key : device_manager->GetSyncedDevices())
devices_list_value->Append(ExternalDeviceInfoToDictionary(unlock_key));
}
for (const auto& remote_device : device_sync_client_->GetSyncedDevices())
devices_list_value->Append(RemoteDeviceToDictionary(remote_device));
return devices_list_value;
}
void ProximityAuthWebUIHandler::OnRemoteDevicesLoaded(
const cryptauth::RemoteDeviceList& remote_devices) {
if (remote_devices.empty()) {
PA_LOG(WARNING) << "Remote device list is empty.";
return;
}
if (remote_devices[0].persistent_symmetric_key.empty()) {
PA_LOG(ERROR) << "Failed to derive PSK.";
return;
}
StartRemoteDeviceLifeCycle(cryptauth::RemoteDeviceRef(
std::make_shared<cryptauth::RemoteDevice>(remote_devices[0])));
}
void ProximityAuthWebUIHandler::StartRemoteDeviceLifeCycle(
cryptauth::RemoteDeviceRef remote_device) {
base::Optional<cryptauth::RemoteDeviceRef> local_device;
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
local_device = device_sync_client_->GetLocalDeviceMetadata();
}
local_device = device_sync_client_->GetLocalDeviceMetadata();
selected_remote_device_ = remote_device;
life_cycle_.reset(new RemoteDeviceLifeCycleImpl(
......@@ -636,102 +363,9 @@ void ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle() {
"LocalStateInterface.onRemoteDevicesChanged", *GetRemoteDevicesList());
}
std::unique_ptr<base::DictionaryValue>
ProximityAuthWebUIHandler::ExternalDeviceInfoToDictionary(
const cryptauth::ExternalDeviceInfo& device_info) {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
std::string base64_public_key;
base::Base64UrlEncode(device_info.public_key(),
base::Base64UrlEncodePolicy::INCLUDE_PADDING,
&base64_public_key);
// Set the fields in the ExternalDeviceInfo proto.
std::unique_ptr<base::DictionaryValue> dictionary(
new base::DictionaryValue());
dictionary->SetString(kExternalDevicePublicKey, base64_public_key);
dictionary->SetString(
kExternalDevicePublicKeyTruncated,
cryptauth::RemoteDeviceRef::TruncateDeviceIdForLogs(base64_public_key));
dictionary->SetString(kExternalDeviceFriendlyName,
device_info.friendly_device_name());
dictionary->SetString(kExternalDeviceBluetoothAddress,
device_info.bluetooth_address());
dictionary->SetBoolean(
kExternalDeviceUnlockKey,
base::ContainsValue(device_info.enabled_software_features(),
cryptauth::SoftwareFeatureEnumToString(
cryptauth::SoftwareFeature::EASY_UNLOCK_HOST)));
dictionary->SetBoolean(
kExternalDeviceMobileHotspot,
base::ContainsValue(device_info.supported_software_features(),
cryptauth::SoftwareFeatureEnumToString(
cryptauth::SoftwareFeature::MAGIC_TETHER_HOST)));
dictionary->SetBoolean(kExternalDeviceIsArcPlusPlusEnrollment,
device_info.arc_plus_plus());
dictionary->SetBoolean(kExternalDeviceIsPixelPhone,
device_info.pixel_phone());
dictionary->SetString(kExternalDeviceConnectionStatus,
kExternalDeviceDisconnected);
cryptauth::CryptAuthDeviceManager* device_manager =
proximity_auth_client_->GetCryptAuthDeviceManager();
if (!device_manager)
return dictionary;
// If |device_info| is a known unlock key, then combine the proto data with
// the corresponding local device data (e.g. connection status and remote
// status updates).
std::string public_key = device_info.public_key();
std::vector<cryptauth::ExternalDeviceInfo> unlock_keys =
device_manager->GetUnlockKeys();
auto iterator = std::find_if(
unlock_keys.begin(), unlock_keys.end(),
[&public_key](const cryptauth::ExternalDeviceInfo& unlock_key) {
return unlock_key.public_key() == public_key;
});
std::string selected_device_public_key;
if (selected_remote_device_)
selected_device_public_key = selected_remote_device_->public_key();
if (iterator == unlock_keys.end() ||
selected_device_public_key != device_info.public_key())
return dictionary;
// Fill in the current Bluetooth connection status.
std::string connection_status = kExternalDeviceDisconnected;
if (life_cycle_ &&
life_cycle_->GetState() ==
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) {
connection_status = kExternalDeviceConnected;
} else if (life_cycle_) {
connection_status = kExternalDeviceConnecting;
}
dictionary->SetString(kExternalDeviceConnectionStatus, connection_status);
// Fill the remote status dictionary.
if (last_remote_status_update_) {
std::unique_ptr<base::DictionaryValue> status_dictionary(
new base::DictionaryValue());
status_dictionary->SetInteger("userPresent",
last_remote_status_update_->user_presence);
status_dictionary->SetInteger(
"secureScreenLock",
last_remote_status_update_->secure_screen_lock_state);
status_dictionary->SetInteger(
"trustAgent", last_remote_status_update_->trust_agent_state);
dictionary->Set(kExternalDeviceRemoteState, std::move(status_dictionary));
}
return dictionary;
}
std::unique_ptr<base::DictionaryValue>
ProximityAuthWebUIHandler::RemoteDeviceToDictionary(
const cryptauth::RemoteDeviceRef& remote_device) {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
// Set the fields in the ExternalDeviceInfo proto.
std::unique_ptr<base::DictionaryValue> dictionary(
new base::DictionaryValue());
......@@ -794,21 +428,6 @@ ProximityAuthWebUIHandler::RemoteDeviceToDictionary(
return dictionary;
}
std::unique_ptr<base::DictionaryValue>
ProximityAuthWebUIHandler::IneligibleDeviceToDictionary(
const cryptauth::IneligibleDevice& ineligible_device) {
std::unique_ptr<base::ListValue> ineligibility_reasons(new base::ListValue());
for (const auto& reason : ineligible_device.reasons()) {
ineligibility_reasons->AppendInteger(reason);
}
std::unique_ptr<base::DictionaryValue> device_dictionary =
ExternalDeviceInfoToDictionary(ineligible_device.device());
device_dictionary->Set(kIneligibleDeviceReasons,
std::move(ineligibility_reasons));
return device_dictionary;
}
void ProximityAuthWebUIHandler::OnLifeCycleStateChanged(
RemoteDeviceLifeCycle::State old_state,
RemoteDeviceLifeCycle::State new_state) {
......
......@@ -15,11 +15,6 @@
#include "chromeos/components/proximity_auth/remote_device_life_cycle.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "chromeos/services/secure_channel/public/cpp/client/secure_channel_client.h"
#include "components/cryptauth/connection_observer.h"
#include "components/cryptauth/cryptauth_client.h"
#include "components/cryptauth/cryptauth_device_manager.h"
#include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/cryptauth_gcm_manager.h"
#include "components/cryptauth/network_request_error.h"
#include "components/cryptauth/remote_device_ref.h"
#include "content/public/browser/web_ui_message_handler.h"
......@@ -28,11 +23,6 @@ namespace base {
class ListValue;
}
namespace cryptauth {
class ExternalDeviceInfo;
class RemoteDeviceLoader;
} // namespace cryptauth
namespace proximity_auth {
class RemoteDeviceLifeCycle;
......@@ -42,14 +32,11 @@ struct RemoteStatusUpdate;
class ProximityAuthWebUIHandler
: public content::WebUIMessageHandler,
public LogBuffer::Observer,
public cryptauth::CryptAuthEnrollmentManager::Observer,
public cryptauth::CryptAuthDeviceManager::Observer,
public chromeos::device_sync::DeviceSyncClient::Observer,
public RemoteDeviceLifeCycle::Observer,
public MessengerObserver {
public:
ProximityAuthWebUIHandler(
ProximityAuthClient* proximity_auth_client,
chromeos::device_sync::DeviceSyncClient* device_sync_client,
chromeos::secure_channel::SecureChannelClient* secure_channel_client);
~ProximityAuthWebUIHandler() override;
......@@ -62,16 +49,6 @@ class ProximityAuthWebUIHandler
void OnLogMessageAdded(const LogBuffer::LogMessage& log_message) override;
void OnLogBufferCleared() override;
// CryptAuthEnrollmentManager::Observer:
void OnEnrollmentStarted() override;
void OnEnrollmentFinished(bool success) override;
// CryptAuthDeviceManager::Observer:
void OnSyncStarted() override;
void OnSyncFinished(cryptauth::CryptAuthDeviceManager::SyncResult sync_result,
cryptauth::CryptAuthDeviceManager::DeviceChangeResult
device_change_result) override;
// chromeos::device_sync::DeviceSyncClient::Observer:
void OnEnrollmentFinished() override;
void OnNewDevicesSynced() override;
......@@ -87,29 +64,11 @@ class ProximityAuthWebUIHandler
void ForceDeviceSync(const base::ListValue* args);
void ToggleConnection(const base::ListValue* args);
// Initializes CryptAuth managers, used for development purposes.
void InitGCMManager();
void InitEnrollmentManager();
void InitDeviceManager();
void OnCryptAuthClientError(cryptauth::NetworkRequestError error);
void OnEasyUnlockToggled(const cryptauth::ToggleEasyUnlockResponse& response);
void OnFoundEligibleUnlockDevices(
const cryptauth::FindEligibleUnlockDevicesResponse& response);
// Called when the RemoteDevice is loaded so we can create a connection.
void OnRemoteDevicesLoaded(const cryptauth::RemoteDeviceList& remote_devices);
void StartRemoteDeviceLifeCycle(cryptauth::RemoteDeviceRef remote_device);
void CleanUpRemoteDeviceLifeCycle();
std::unique_ptr<base::DictionaryValue> ExternalDeviceInfoToDictionary(
const cryptauth::ExternalDeviceInfo& device_info);
std::unique_ptr<base::DictionaryValue> RemoteDeviceToDictionary(
const cryptauth::RemoteDeviceRef& remote_device);
std::unique_ptr<base::DictionaryValue> IneligibleDeviceToDictionary(
const cryptauth::IneligibleDevice& ineligible_device);
// RemoteDeviceLifeCycle::Observer:
void OnLifeCycleStateChanged(RemoteDeviceLifeCycle::State old_state,
......@@ -144,22 +103,11 @@ class ProximityAuthWebUIHandler
std::unique_ptr<base::ListValue> synced_devices);
std::unique_ptr<base::Value> GetTruncatedLocalDeviceId();
// These two methods cannot be used if the chromeos::features::kMultiDeviceApi
// flag is enabled.
std::unique_ptr<base::DictionaryValue> GetEnrollmentStateDictionary();
std::unique_ptr<base::DictionaryValue> GetDeviceSyncStateDictionary();
std::unique_ptr<base::ListValue> GetRemoteDevicesList();
// The delegate used to fetch dependencies. Must outlive this instance.
ProximityAuthClient* proximity_auth_client_;
chromeos::device_sync::DeviceSyncClient* device_sync_client_;
chromeos::secure_channel::SecureChannelClient* secure_channel_client_;
std::unique_ptr<cryptauth::CryptAuthClientFactory> cryptauth_client_factory_;
// We only support one concurrent API call.
std::unique_ptr<cryptauth::CryptAuthClient> cryptauth_client_;
// True if we get a message from the loaded WebContents to know that it is
// initialized, and we can inject JavaScript.
......@@ -167,7 +115,6 @@ class ProximityAuthWebUIHandler
// Member variables for connecting to and authenticating the remote device.
// TODO(tengs): Support multiple simultaenous connections.
std::unique_ptr<cryptauth::RemoteDeviceLoader> remote_device_loader_;
base::Optional<cryptauth::RemoteDeviceRef> selected_remote_device_;
std::unique_ptr<RemoteDeviceLifeCycle> life_cycle_;
std::unique_ptr<RemoteStatusUpdate> last_remote_status_update_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment