Commit b01b9a7f authored by khorimoto's avatar khorimoto Committed by Commit Bot

[CrOS Tether] ProximityAuth WebUI improvement: show the local device's ID.

Previously, there was a device ID section which was never actually updated, leading to confusion by dogfooders. With this change, it is actually shown in the WebUI page.

BUG=672263

Review-Url: https://codereview.chromium.org/2953863002
Cr-Commit-Position: refs/heads/master@{#481788}
parent a2c68af4
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "components/cryptauth/cryptauth_client_impl.h" #include "components/cryptauth/cryptauth_client_impl.h"
#include "components/cryptauth/cryptauth_device_manager.h" #include "components/cryptauth/cryptauth_device_manager.h"
#include "components/cryptauth/cryptauth_enrollment_manager.h" #include "components/cryptauth/cryptauth_enrollment_manager.h"
#include "components/cryptauth/local_device_data_provider.h"
#include "components/cryptauth/secure_message_delegate.h" #include "components/cryptauth/secure_message_delegate.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/proximity_auth/logging/logging.h" #include "components/proximity_auth/logging/logging.h"
...@@ -134,3 +135,10 @@ cryptauth::CryptAuthService* ChromeProximityAuthClient::GetCryptAuthService() { ...@@ -134,3 +135,10 @@ cryptauth::CryptAuthService* ChromeProximityAuthClient::GetCryptAuthService() {
return ChromeCryptAuthServiceFactory::GetInstance()->GetForBrowserContext( return ChromeCryptAuthServiceFactory::GetInstance()->GetForBrowserContext(
profile_); profile_);
} }
std::string ChromeProximityAuthClient::GetLocalDevicePublicKey() {
cryptauth::LocalDeviceDataProvider provider(GetCryptAuthService());
std::string local_public_key;
provider.GetLocalDeviceData(&local_public_key, nullptr);
return local_public_key;
}
...@@ -42,6 +42,7 @@ class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient { ...@@ -42,6 +42,7 @@ class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient {
const std::string& remote_public_key, const std::string& remote_public_key,
const std::string& nonce, const std::string& nonce,
base::Callback<void(const std::string& challenge)> callback) override; base::Callback<void(const std::string& challenge)> callback) override;
std::string GetLocalDevicePublicKey() override;
private: private:
cryptauth::CryptAuthService* GetCryptAuthService(); cryptauth::CryptAuthService* GetCryptAuthService();
......
...@@ -47,6 +47,7 @@ class MockProximityAuthClient : public ProximityAuthClient { ...@@ -47,6 +47,7 @@ class MockProximityAuthClient : public ProximityAuthClient {
CreateSecureMessageDelegate() override; CreateSecureMessageDelegate() override;
std::unique_ptr<cryptauth::CryptAuthClientFactory> std::unique_ptr<cryptauth::CryptAuthClientFactory>
CreateCryptAuthClientFactory() override; CreateCryptAuthClientFactory() override;
MOCK_METHOD0(GetLocalDevicePublicKey, std::string(void));
// Proxy mock methods because implementation requires returning scoped_ptr. // Proxy mock methods because implementation requires returning scoped_ptr.
MOCK_METHOD0(CreateSecureMessageDelegatePtr, MOCK_METHOD0(CreateSecureMessageDelegatePtr,
......
...@@ -79,6 +79,8 @@ class ProximityAuthClient { ...@@ -79,6 +79,8 @@ class ProximityAuthClient {
GetCryptAuthEnrollmentManager() = 0; GetCryptAuthEnrollmentManager() = 0;
virtual cryptauth::CryptAuthDeviceManager* GetCryptAuthDeviceManager() = 0; virtual cryptauth::CryptAuthDeviceManager* GetCryptAuthDeviceManager() = 0;
virtual std::string GetLocalDevicePublicKey() = 0;
}; };
} // namespace proximity_auth } // namespace proximity_auth
......
...@@ -415,6 +415,8 @@ void ProximityAuthWebUIHandler::OnReachablePhonesFound( ...@@ -415,6 +415,8 @@ void ProximityAuthWebUIHandler::OnReachablePhonesFound(
} }
void ProximityAuthWebUIHandler::GetLocalState(const base::ListValue* args) { void ProximityAuthWebUIHandler::GetLocalState(const base::ListValue* args) {
std::unique_ptr<base::Value> truncated_local_device_id =
GetTruncatedLocalDeviceId();
std::unique_ptr<base::DictionaryValue> enrollment_state = std::unique_ptr<base::DictionaryValue> enrollment_state =
GetEnrollmentStateDictionary(); GetEnrollmentStateDictionary();
std::unique_ptr<base::DictionaryValue> device_sync_state = std::unique_ptr<base::DictionaryValue> device_sync_state =
...@@ -422,13 +424,28 @@ void ProximityAuthWebUIHandler::GetLocalState(const base::ListValue* args) { ...@@ -422,13 +424,28 @@ void ProximityAuthWebUIHandler::GetLocalState(const base::ListValue* args) {
std::unique_ptr<base::ListValue> synced_devices = GetRemoteDevicesList(); std::unique_ptr<base::ListValue> synced_devices = GetRemoteDevicesList();
PA_LOG(INFO) << "==== Got Local State ====\n" PA_LOG(INFO) << "==== Got Local State ====\n"
<< "Enrollment State: \n" << "Device ID (truncated): " << *truncated_local_device_id
<< "\nEnrollment State: \n"
<< *enrollment_state << "Device Sync State: \n" << *enrollment_state << "Device Sync State: \n"
<< *device_sync_state << "Unlock Keys: \n" << *device_sync_state << "Unlock Keys: \n"
<< *synced_devices; << *synced_devices;
web_ui()->CallJavascriptFunctionUnsafe("LocalStateInterface.onGotLocalState", web_ui()->CallJavascriptFunctionUnsafe(
*enrollment_state, *device_sync_state, "LocalStateInterface.onGotLocalState", *truncated_local_device_id,
*synced_devices); *enrollment_state, *device_sync_state, *synced_devices);
}
std::unique_ptr<base::Value>
ProximityAuthWebUIHandler::GetTruncatedLocalDeviceId() {
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 base::MakeUnique<base::Value>(
cryptauth::RemoteDevice::TruncateDeviceIdForLogs(device_id));
} }
std::unique_ptr<base::DictionaryValue> std::unique_ptr<base::DictionaryValue>
......
...@@ -120,6 +120,9 @@ class ProximityAuthWebUIHandler ...@@ -120,6 +120,9 @@ class ProximityAuthWebUIHandler
// MessengerObserver: // MessengerObserver:
void OnRemoteStatusUpdate(const RemoteStatusUpdate& status_update) override; void OnRemoteStatusUpdate(const RemoteStatusUpdate& status_update) override;
// Returns the truncated device ID of the local device.
std::unique_ptr<base::Value> GetTruncatedLocalDeviceId();
// Returns the current enrollment state that can be used as a JSON object. // Returns the current enrollment state that can be used as a JSON object.
std::unique_ptr<base::DictionaryValue> GetEnrollmentStateDictionary(); std::unique_ptr<base::DictionaryValue> GetEnrollmentStateDictionary();
......
...@@ -31,6 +31,10 @@ tr.subrow td:first-of-type { ...@@ -31,6 +31,10 @@ tr.subrow td:first-of-type {
flex: 1; flex: 1;
} }
#local-device-id {
font-family: monospace;
}
.remote-device { .remote-device {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
......
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
<div class='control-title'>CRYPTAUTH</div> <div class='control-title'>CRYPTAUTH</div>
<table> <table>
<tr> <tr>
<td>PUBLIC KEY (functionality coming soon)</td> <td>DEVICE ID (truncated)</td>
<td colspan="2" id='public-key'>----</td> <td colspan="2" id='local-device-id'>----</td>
</tr> </tr>
<tr><td id='enrollment-title' state='synced'>ENROLLMENT</td></tr> <tr><td id='enrollment-title' state='synced'>ENROLLMENT</td></tr>
<tr class='subrow'> <tr class='subrow'>
......
...@@ -26,7 +26,7 @@ ProximityAuth = { ...@@ -26,7 +26,7 @@ ProximityAuth = {
class CryptAuthController { class CryptAuthController {
constructor() { constructor() {
this.elements_ = { this.elements_ = {
publicKey: document.getElementById('public-key'), localDeviceId: document.getElementById('local-device-id'),
gcmRegistration: document.getElementById('gcm-registration'), gcmRegistration: document.getElementById('gcm-registration'),
currentEid: document.getElementById('current-eid'), currentEid: document.getElementById('current-eid'),
enrollmentTitle: document.getElementById('enrollment-title'), enrollmentTitle: document.getElementById('enrollment-title'),
...@@ -43,6 +43,14 @@ class CryptAuthController { ...@@ -43,6 +43,14 @@ class CryptAuthController {
this.elements_.deviceSyncButton.onclick = this.forceDeviceSync_.bind(this); this.elements_.deviceSyncButton.onclick = this.forceDeviceSync_.bind(this);
} }
/**
* Sets the local device's ID. Note that this value is truncated since the
* full value is very long and does not cleanly fit on the screen.
*/
setLocalDeviceId(deviceIdTruncated) {
this.elements_.localDeviceId.textContent = deviceIdTruncated;
}
/** /**
* Update the enrollment state in the UI. * Update the enrollment state in the UI.
*/ */
...@@ -253,12 +261,18 @@ class EligibleDevicesController { ...@@ -253,12 +261,18 @@ class EligibleDevicesController {
* Interface for the native WebUI to call into our JS. * Interface for the native WebUI to call into our JS.
*/ */
LocalStateInterface = { LocalStateInterface = {
onGotLocalState: function(enrollmentState, deviceSyncState, remoteDevices) { onGotLocalState: function(
localDeviceId, enrollmentState, deviceSyncState, remoteDevices) {
LocalStateInterface.setLocalDeviceId(localDeviceId);
LocalStateInterface.onEnrollmentStateChanged(enrollmentState); LocalStateInterface.onEnrollmentStateChanged(enrollmentState);
LocalStateInterface.onDeviceSyncStateChanged(deviceSyncState); LocalStateInterface.onDeviceSyncStateChanged(deviceSyncState);
LocalStateInterface.onRemoteDevicesChanged(remoteDevices); LocalStateInterface.onRemoteDevicesChanged(remoteDevices);
}, },
setLocalDeviceId: function(localDeviceId) {
ProximityAuth.cryptauthController_.setLocalDeviceId(localDeviceId);
},
onEnrollmentStateChanged: function(enrollmentState) { onEnrollmentStateChanged: function(enrollmentState) {
ProximityAuth.cryptauthController_.updateEnrollmentState(enrollmentState); ProximityAuth.cryptauthController_.updateEnrollmentState(enrollmentState);
}, },
......
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