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

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

Issue 1302313004: Replace ProximityAuthUIDelegate with ProximityAuthClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proximity_auth_client
Patch Set: fixes Created 5 years, 3 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
« no previous file with comments | « components/proximity_auth/webui/proximity_auth_webui_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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/bluetooth_low_energy_connection_finder.h " 16 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h "
17 #include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h" 17 #include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h"
18 #include "components/proximity_auth/ble/pref_names.h" 18 #include "components/proximity_auth/ble/pref_names.h"
19 #include "components/proximity_auth/bluetooth_connection_finder.h" 19 #include "components/proximity_auth/bluetooth_connection_finder.h"
20 #include "components/proximity_auth/bluetooth_throttler_impl.h" 20 #include "components/proximity_auth/bluetooth_throttler_impl.h"
21 #include "components/proximity_auth/bluetooth_util.h" 21 #include "components/proximity_auth/bluetooth_util.h"
22 #include "components/proximity_auth/client_impl.h" 22 #include "components/proximity_auth/client_impl.h"
23 #include "components/proximity_auth/cryptauth/base64url.h" 23 #include "components/proximity_auth/cryptauth/base64url.h"
24 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" 24 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h"
25 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.h"
26 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" 25 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h"
27 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" 26 #include "components/proximity_auth/cryptauth/secure_message_delegate.h"
28 #include "components/proximity_auth/device_to_device_authenticator.h" 27 #include "components/proximity_auth/device_to_device_authenticator.h"
29 #include "components/proximity_auth/logging/logging.h" 28 #include "components/proximity_auth/logging/logging.h"
30 #include "components/proximity_auth/remote_status_update.h" 29 #include "components/proximity_auth/remote_status_update.h"
31 #include "components/proximity_auth/secure_context.h" 30 #include "components/proximity_auth/secure_context.h"
32 #include "components/proximity_auth/webui/cryptauth_enroller_factory_impl.h"
33 #include "components/proximity_auth/webui/proximity_auth_ui_delegate.h"
34 #include "components/proximity_auth/webui/reachable_phone_flow.h" 31 #include "components/proximity_auth/webui/reachable_phone_flow.h"
35 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/web_ui.h" 33 #include "content/public/browser/web_ui.h"
37 #include "device/bluetooth/bluetooth_uuid.h" 34 #include "device/bluetooth/bluetooth_uuid.h"
38 35
39 namespace proximity_auth { 36 namespace proximity_auth {
40 37
41 namespace { 38 namespace {
42 39
43 // The UUID of the Smart Lock classic Bluetooth service. 40 // The UUID of the Smart Lock classic Bluetooth service.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 sync_state->SetBoolean(kSyncStateRecoveringFromFailure, 109 sync_state->SetBoolean(kSyncStateRecoveringFromFailure,
113 is_recovering_from_failure); 110 is_recovering_from_failure);
114 sync_state->SetBoolean(kSyncStateOperationInProgress, 111 sync_state->SetBoolean(kSyncStateOperationInProgress,
115 is_enrollment_in_progress); 112 is_enrollment_in_progress);
116 return sync_state; 113 return sync_state;
117 } 114 }
118 115
119 } // namespace 116 } // namespace
120 117
121 ProximityAuthWebUIHandler::ProximityAuthWebUIHandler( 118 ProximityAuthWebUIHandler::ProximityAuthWebUIHandler(
122 ProximityAuthUIDelegate* delegate) 119 ProximityAuthClient* proximity_auth_client)
123 : delegate_(delegate), 120 : proximity_auth_client_(proximity_auth_client),
121 web_contents_initialized_(false),
124 weak_ptr_factory_(this) { 122 weak_ptr_factory_(this) {
125 cryptauth_client_factory_ = delegate_->CreateCryptAuthClientFactory(); 123 cryptauth_client_factory_ =
124 proximity_auth_client_->CreateCryptAuthClientFactory();
126 } 125 }
127 126
128 ProximityAuthWebUIHandler::~ProximityAuthWebUIHandler() { 127 ProximityAuthWebUIHandler::~ProximityAuthWebUIHandler() {
129 LogBuffer::GetInstance()->RemoveObserver(this); 128 LogBuffer::GetInstance()->RemoveObserver(this);
130 } 129 }
131 130
132 void ProximityAuthWebUIHandler::RegisterMessages() { 131 void ProximityAuthWebUIHandler::RegisterMessages() {
133 web_ui()->RegisterMessageCallback( 132 web_ui()->RegisterMessageCallback(
134 "onWebContentsInitialized", 133 "onWebContentsInitialized",
135 base::Bind(&ProximityAuthWebUIHandler::OnWebContentsInitialized, 134 base::Bind(&ProximityAuthWebUIHandler::OnWebContentsInitialized,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 scoped_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); 222 scoped_ptr<base::ListValue> unlock_keys = GetUnlockKeysList();
224 PA_LOG(INFO) << "New unlock keys obtained after device sync:\n" 223 PA_LOG(INFO) << "New unlock keys obtained after device sync:\n"
225 << *unlock_keys; 224 << *unlock_keys;
226 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", 225 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged",
227 *unlock_keys); 226 *unlock_keys);
228 } 227 }
229 } 228 }
230 229
231 void ProximityAuthWebUIHandler::OnWebContentsInitialized( 230 void ProximityAuthWebUIHandler::OnWebContentsInitialized(
232 const base::ListValue* args) { 231 const base::ListValue* args) {
233 if (!gcm_manager_ || !enrollment_manager_ || !device_manager_) { 232 if (!web_contents_initialized_) {
234 InitGCMManager(); 233 CryptAuthEnrollmentManager* enrollment_manager =
235 InitEnrollmentManager(); 234 proximity_auth_client_->GetCryptAuthEnrollmentManager();
236 InitDeviceManager(); 235 if (enrollment_manager)
236 enrollment_manager->AddObserver(this);
237
238 CryptAuthDeviceManager* device_manager =
239 proximity_auth_client_->GetCryptAuthDeviceManager();
240 if (device_manager)
241 device_manager->AddObserver(this);
242
237 LogBuffer::GetInstance()->AddObserver(this); 243 LogBuffer::GetInstance()->AddObserver(this);
244
245 web_contents_initialized_ = true;
238 } 246 }
239 } 247 }
240 248
241 void ProximityAuthWebUIHandler::GetLogMessages(const base::ListValue* args) { 249 void ProximityAuthWebUIHandler::GetLogMessages(const base::ListValue* args) {
242 base::ListValue json_logs; 250 base::ListValue json_logs;
243 for (const auto& log : *LogBuffer::GetInstance()->logs()) { 251 for (const auto& log : *LogBuffer::GetInstance()->logs()) {
244 json_logs.Append(LogMessageToDictionary(log).release()); 252 json_logs.Append(LogMessageToDictionary(log).release());
245 } 253 }
246 web_ui()->CallJavascriptFunction("LogBufferInterface.onGotLogMessages", 254 web_ui()->CallJavascriptFunction("LogBufferInterface.onGotLogMessages",
247 json_logs); 255 json_logs);
(...skipping 11 matching lines...) Expand all
259 if (args->GetSize() != 2 || !args->GetString(0, &public_key_b64) || 267 if (args->GetSize() != 2 || !args->GetString(0, &public_key_b64) ||
260 !args->GetBoolean(1, &make_unlock_key) || 268 !args->GetBoolean(1, &make_unlock_key) ||
261 !Base64UrlDecode(public_key_b64, &public_key)) { 269 !Base64UrlDecode(public_key_b64, &public_key)) {
262 PA_LOG(ERROR) << "Invalid arguments to toggleUnlockKey"; 270 PA_LOG(ERROR) << "Invalid arguments to toggleUnlockKey";
263 return; 271 return;
264 } 272 }
265 273
266 cryptauth::ToggleEasyUnlockRequest request; 274 cryptauth::ToggleEasyUnlockRequest request;
267 request.set_enable(make_unlock_key); 275 request.set_enable(make_unlock_key);
268 request.set_public_key(public_key); 276 request.set_public_key(public_key);
269 *(request.mutable_device_classifier()) = delegate_->GetDeviceClassifier(); 277 *(request.mutable_device_classifier()) =
278 proximity_auth_client_->GetDeviceClassifier();
270 279
271 PA_LOG(INFO) << "Toggling unlock key:\n" 280 PA_LOG(INFO) << "Toggling unlock key:\n"
272 << " public_key: " << public_key_b64 << "\n" 281 << " public_key: " << public_key_b64 << "\n"
273 << " make_unlock_key: " << make_unlock_key; 282 << " make_unlock_key: " << make_unlock_key;
274 cryptauth_client_ = cryptauth_client_factory_->CreateInstance(); 283 cryptauth_client_ = cryptauth_client_factory_->CreateInstance();
275 cryptauth_client_->ToggleEasyUnlock( 284 cryptauth_client_->ToggleEasyUnlock(
276 request, base::Bind(&ProximityAuthWebUIHandler::OnEasyUnlockToggled, 285 request, base::Bind(&ProximityAuthWebUIHandler::OnEasyUnlockToggled,
277 weak_ptr_factory_.GetWeakPtr()), 286 weak_ptr_factory_.GetWeakPtr()),
278 base::Bind(&ProximityAuthWebUIHandler::OnCryptAuthClientError, 287 base::Bind(&ProximityAuthWebUIHandler::OnCryptAuthClientError,
279 weak_ptr_factory_.GetWeakPtr())); 288 weak_ptr_factory_.GetWeakPtr()));
280 } 289 }
281 290
282 void ProximityAuthWebUIHandler::FindEligibleUnlockDevices( 291 void ProximityAuthWebUIHandler::FindEligibleUnlockDevices(
283 const base::ListValue* args) { 292 const base::ListValue* args) {
284 cryptauth_client_ = cryptauth_client_factory_->CreateInstance(); 293 cryptauth_client_ = cryptauth_client_factory_->CreateInstance();
285 294
286 cryptauth::FindEligibleUnlockDevicesRequest request; 295 cryptauth::FindEligibleUnlockDevicesRequest request;
287 *(request.mutable_device_classifier()) = delegate_->GetDeviceClassifier(); 296 *(request.mutable_device_classifier()) =
297 proximity_auth_client_->GetDeviceClassifier();
288 cryptauth_client_->FindEligibleUnlockDevices( 298 cryptauth_client_->FindEligibleUnlockDevices(
289 request, 299 request,
290 base::Bind(&ProximityAuthWebUIHandler::OnFoundEligibleUnlockDevices, 300 base::Bind(&ProximityAuthWebUIHandler::OnFoundEligibleUnlockDevices,
291 weak_ptr_factory_.GetWeakPtr()), 301 weak_ptr_factory_.GetWeakPtr()),
292 base::Bind(&ProximityAuthWebUIHandler::OnCryptAuthClientError, 302 base::Bind(&ProximityAuthWebUIHandler::OnCryptAuthClientError,
293 weak_ptr_factory_.GetWeakPtr())); 303 weak_ptr_factory_.GetWeakPtr()));
294 } 304 }
295 305
296 void ProximityAuthWebUIHandler::FindReachableDevices( 306 void ProximityAuthWebUIHandler::FindReachableDevices(
297 const base::ListValue* args) { 307 const base::ListValue* args) {
298 if (reachable_phone_flow_) { 308 if (reachable_phone_flow_) {
299 PA_LOG(INFO) << "Waiting for existing ReachablePhoneFlow to finish."; 309 PA_LOG(INFO) << "Waiting for existing ReachablePhoneFlow to finish.";
300 return; 310 return;
301 } 311 }
302 312
303 reachable_phone_flow_.reset( 313 reachable_phone_flow_.reset(
304 new ReachablePhoneFlow(cryptauth_client_factory_.get())); 314 new ReachablePhoneFlow(cryptauth_client_factory_.get()));
305 reachable_phone_flow_->Run( 315 reachable_phone_flow_->Run(
306 base::Bind(&ProximityAuthWebUIHandler::OnReachablePhonesFound, 316 base::Bind(&ProximityAuthWebUIHandler::OnReachablePhonesFound,
307 weak_ptr_factory_.GetWeakPtr())); 317 weak_ptr_factory_.GetWeakPtr()));
308 } 318 }
309 319
310 void ProximityAuthWebUIHandler::ForceEnrollment(const base::ListValue* args) { 320 void ProximityAuthWebUIHandler::ForceEnrollment(const base::ListValue* args) {
311 if (enrollment_manager_) { 321 CryptAuthEnrollmentManager* enrollment_manager =
312 enrollment_manager_->ForceEnrollmentNow( 322 proximity_auth_client_->GetCryptAuthEnrollmentManager();
313 cryptauth::INVOCATION_REASON_MANUAL); 323 if (enrollment_manager) {
324 enrollment_manager->ForceEnrollmentNow(cryptauth::INVOCATION_REASON_MANUAL);
314 } 325 }
315 } 326 }
316 327
317 void ProximityAuthWebUIHandler::ForceDeviceSync(const base::ListValue* args) { 328 void ProximityAuthWebUIHandler::ForceDeviceSync(const base::ListValue* args) {
318 if (device_manager_) 329 CryptAuthDeviceManager* device_manager =
319 device_manager_->ForceSyncNow(cryptauth::INVOCATION_REASON_MANUAL); 330 proximity_auth_client_->GetCryptAuthDeviceManager();
331 if (device_manager)
332 device_manager->ForceSyncNow(cryptauth::INVOCATION_REASON_MANUAL);
320 } 333 }
321 334
322 void ProximityAuthWebUIHandler::ToggleConnection(const base::ListValue* args) { 335 void ProximityAuthWebUIHandler::ToggleConnection(const base::ListValue* args) {
336 CryptAuthEnrollmentManager* enrollment_manager =
337 proximity_auth_client_->GetCryptAuthEnrollmentManager();
338 CryptAuthDeviceManager* device_manager =
339 proximity_auth_client_->GetCryptAuthDeviceManager();
340 if (!enrollment_manager || !device_manager)
341 return;
342
323 std::string b64_public_key; 343 std::string b64_public_key;
324 std::string public_key; 344 std::string public_key;
325 if (!enrollment_manager_ || !device_manager_ || !args->GetSize() || 345 if (!enrollment_manager || !device_manager || !args->GetSize() ||
326 !args->GetString(0, &b64_public_key) || 346 !args->GetString(0, &b64_public_key) ||
327 !Base64UrlDecode(b64_public_key, &public_key)) { 347 !Base64UrlDecode(b64_public_key, &public_key)) {
328 return; 348 return;
329 } 349 }
330 350
331 Connection* connection = GetConnection(); 351 Connection* connection = GetConnection();
332 for (const auto& unlock_key : device_manager_->unlock_keys()) { 352 for (const auto& unlock_key : device_manager->unlock_keys()) {
333 if (unlock_key.public_key() == public_key) { 353 if (unlock_key.public_key() == public_key) {
334 // Check if there is an existing connection to disconnect from first. 354 // Check if there is an existing connection to disconnect from first.
335 if (connection && connection->IsConnected() && 355 if (connection && connection->IsConnected() &&
336 selected_remote_device_.public_key == public_key) { 356 selected_remote_device_.public_key == public_key) {
337 PA_LOG(INFO) << "Disconnecting from " 357 PA_LOG(INFO) << "Disconnecting from "
338 << unlock_key.friendly_device_name() << "[" 358 << unlock_key.friendly_device_name() << "["
339 << unlock_key.bluetooth_address() << "]"; 359 << unlock_key.bluetooth_address() << "]";
340 connection->Disconnect(); 360 connection->Disconnect();
341 return; 361 return;
342 } 362 }
343 363
344 // Derive the PSK before connecting to the device. 364 // Derive the PSK before connecting to the device.
345 PA_LOG(INFO) << "Deriving PSK before connecting to " 365 PA_LOG(INFO) << "Deriving PSK before connecting to "
346 << unlock_key.friendly_device_name(); 366 << unlock_key.friendly_device_name();
347 secure_message_delegate_ = delegate_->CreateSecureMessageDelegate(); 367 secure_message_delegate_ =
368 proximity_auth_client_->CreateSecureMessageDelegate();
348 secure_message_delegate_->DeriveKey( 369 secure_message_delegate_->DeriveKey(
349 enrollment_manager_->GetUserPrivateKey(), unlock_key.public_key(), 370 enrollment_manager->GetUserPrivateKey(), unlock_key.public_key(),
350 base::Bind(&ProximityAuthWebUIHandler::OnPSKDerived, 371 base::Bind(&ProximityAuthWebUIHandler::OnPSKDerived,
351 weak_ptr_factory_.GetWeakPtr(), unlock_key)); 372 weak_ptr_factory_.GetWeakPtr(), unlock_key));
352 373
353 return; 374 return;
354 } 375 }
355 } 376 }
356 377
357 PA_LOG(ERROR) << "Unlock key (" << b64_public_key << ") not found"; 378 PA_LOG(ERROR) << "Unlock key (" << b64_public_key << ") not found";
358 } 379 }
359 380
360 void ProximityAuthWebUIHandler::InitGCMManager() {
361 gcm_manager_.reset(new CryptAuthGCMManagerImpl(delegate_->GetGCMDriver(),
362 delegate_->GetPrefService()));
363 gcm_manager_->StartListening();
364 }
365
366 void ProximityAuthWebUIHandler::InitEnrollmentManager() {
367 #if defined(OS_CHROMEOS)
368 // TODO(tengs): We initialize a CryptAuthEnrollmentManager here for
369 // development and testing purposes until it is ready to be moved into Chrome.
370 // The public/private key pair has been generated and serialized in a previous
371 // session.
372 // This serialized DeviceInfo proto was previously captured from a real
373 // CryptAuth enrollment, and is replayed here for testing purposes.
374 std::string serialized_device_info;
375 Base64UrlDecode(
376 "IkoIARJGCiEAX_ZjLSq73EVcrarX-7l7No7nSP86GEC322ocSZKqUKwSIQDbEDu9KN7AgLM"
377 "v_lzZZNui9zSOgXCeDpLhS2tgrYVXijoEbGlua0IFZW4tVVNKSggBEkYKIQBf9mMtKrvcRV"
378 "ytqtf7uXs2judI_zoYQLfbahxJkqpQrBIhANsQO70o3sCAsy_-XNlk26L3NI6BcJ4OkuFLa"
379 "2CthVeKam9Nb3ppbGxhLzUuMCAoWDExOyBDck9TIHg4Nl82NCA3MTM0LjAuMCkgQXBwbGVX"
380 "ZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzQ1LjAuMjQyMi4wIFN"
381 "hZmFyaS81MzcuMzZwLYoBAzEuMJABAZoBIG1rYWVtaWdob2xlYmNnY2hsa2JhbmttaWhrbm"
382 "9qZWFrsAHDPuoBHEJLZEluZWxFZk05VG1adGV3eTRGb19RV1Vicz2AAgKyBqIBQVBBOTFiS"
383 "FZDdlJJNGJFSXppMmFXOTBlZ044eHFBYkhWYnJwSVFuMTk3bWltd3RWWTZYN0JEcEI4Szg3"
384 "RjRubkJnejdLX1BQV2xkcUtDRVhiZkFiMGwyN1VaQXgtVjBWbEE4WlFwdkhETmpHVlh4RlV"
385 "WRDFNY1AzNTgtYTZ3eHRpVG5LQnpMTEVIT1F6Ujdpb0lUMzRtWWY1VmNhbmhPZDh3ugYgs9"
386 "7-c7qNUzzLeEqVCDXb_EaJ8wC3iie_Lpid44iuAh3CPo0CCugBCiMIARACGgi5wHHa82avM"
387 "ioQ7y8xhiUBs7Um73ZC1vQlzzIBABLAAeCqGnWF7RwtnmdfIQJoEqXoXrH1qLw4yqUAA1TW"
388 "M1qxTepJOdDHrh54eiejobW0SKpHqTlZIyiK3ObHAPdfzFum1l640RFdFGZTTTksZFqfD9O"
389 "dftoi0pMrApob4gXj8Pv2g22ArX55BiH56TkTIcDcEE3KKnA_2G0INT1y_clZvZfDw1n0WP"
390 "0Xdg1PLLCOb46WfDWUhHvUk3GzUce8xyxsjOkiZUNh8yvhFXaP2wJgVKVWInf0inuofo9Za"
391 "7p44hIgHgKJIr_4fuVs9Ojf0KcMzxoJTbFUGg58jglUAKFfJBLKPpMBeWEyOS5pQUdTNFZ1"
392 "bF9JVWY4YTJDSmJNbXFqaWpYUFYzaVV5dmJXSVRrR3d1bFRaVUs3RGVZczJtT0h5ZkQ1NWR"
393 "HRXEtdnJTdVc4VEZ2Z1haa2xhVEZTN0dqM2xCVUktSHd5Z0h6bHZHX2NGLWtzQmw0dXdveG"
394 "VPWE1hRlJ3WGJHVUU1Tm9sLS1mdkRIcGVZVnJR",
395 &serialized_device_info);
396 cryptauth::GcmDeviceInfo device_info;
397 device_info.ParseFromString(serialized_device_info);
398
399 enrollment_manager_.reset(new CryptAuthEnrollmentManager(
400 make_scoped_ptr(new base::DefaultClock()),
401 make_scoped_ptr(new CryptAuthEnrollerFactoryImpl(delegate_)),
402 delegate_->CreateSecureMessageDelegate(), device_info, gcm_manager_.get(),
403 delegate_->GetPrefService()));
404 enrollment_manager_->AddObserver(this);
405 enrollment_manager_->Start();
406 #endif
407 }
408
409 void ProximityAuthWebUIHandler::InitDeviceManager() {
410 // TODO(tengs): We initialize a CryptAuthDeviceManager here for
411 // development and testing purposes until it is ready to be moved into Chrome.
412 device_manager_.reset(new CryptAuthDeviceManager(
413 make_scoped_ptr(new base::DefaultClock()),
414 delegate_->CreateCryptAuthClientFactory(), gcm_manager_.get(),
415 delegate_->GetPrefService()));
416 device_manager_->AddObserver(this);
417 device_manager_->Start();
418 }
419
420 void ProximityAuthWebUIHandler::OnCryptAuthClientError( 381 void ProximityAuthWebUIHandler::OnCryptAuthClientError(
421 const std::string& error_message) { 382 const std::string& error_message) {
422 PA_LOG(WARNING) << "CryptAuth request failed: " << error_message; 383 PA_LOG(WARNING) << "CryptAuth request failed: " << error_message;
423 base::StringValue error_string(error_message); 384 base::StringValue error_string(error_message);
424 web_ui()->CallJavascriptFunction("CryptAuthInterface.onError", error_string); 385 web_ui()->CallJavascriptFunction("CryptAuthInterface.onError", error_string);
425 } 386 }
426 387
427 void ProximityAuthWebUIHandler::OnEasyUnlockToggled( 388 void ProximityAuthWebUIHandler::OnEasyUnlockToggled(
428 const cryptauth::ToggleEasyUnlockResponse& response) { 389 const cryptauth::ToggleEasyUnlockResponse& response) {
429 web_ui()->CallJavascriptFunction("CryptAuthInterface.onUnlockKeyToggled"); 390 web_ui()->CallJavascriptFunction("CryptAuthInterface.onUnlockKeyToggled");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 << "Enrollment State: \n" << *enrollment_state 432 << "Enrollment State: \n" << *enrollment_state
472 << "Device Sync State: \n" << *device_sync_state 433 << "Device Sync State: \n" << *device_sync_state
473 << "Unlock Keys: \n" << *unlock_keys; 434 << "Unlock Keys: \n" << *unlock_keys;
474 web_ui()->CallJavascriptFunction("LocalStateInterface.onGotLocalState", 435 web_ui()->CallJavascriptFunction("LocalStateInterface.onGotLocalState",
475 *enrollment_state, *device_sync_state, 436 *enrollment_state, *device_sync_state,
476 *unlock_keys); 437 *unlock_keys);
477 } 438 }
478 439
479 scoped_ptr<base::DictionaryValue> 440 scoped_ptr<base::DictionaryValue>
480 ProximityAuthWebUIHandler::GetEnrollmentStateDictionary() { 441 ProximityAuthWebUIHandler::GetEnrollmentStateDictionary() {
481 if (!enrollment_manager_) 442 CryptAuthEnrollmentManager* enrollment_manager =
443 proximity_auth_client_->GetCryptAuthEnrollmentManager();
444 if (!enrollment_manager)
482 return make_scoped_ptr(new base::DictionaryValue()); 445 return make_scoped_ptr(new base::DictionaryValue());
483 446
484 return CreateSyncStateDictionary( 447 return CreateSyncStateDictionary(
485 enrollment_manager_->GetLastEnrollmentTime().ToJsTime(), 448 enrollment_manager->GetLastEnrollmentTime().ToJsTime(),
486 enrollment_manager_->GetTimeToNextAttempt().InMillisecondsF(), 449 enrollment_manager->GetTimeToNextAttempt().InMillisecondsF(),
487 enrollment_manager_->IsRecoveringFromFailure(), 450 enrollment_manager->IsRecoveringFromFailure(),
488 enrollment_manager_->IsEnrollmentInProgress()); 451 enrollment_manager->IsEnrollmentInProgress());
489 } 452 }
490 453
491 scoped_ptr<base::DictionaryValue> 454 scoped_ptr<base::DictionaryValue>
492 ProximityAuthWebUIHandler::GetDeviceSyncStateDictionary() { 455 ProximityAuthWebUIHandler::GetDeviceSyncStateDictionary() {
493 if (!device_manager_) 456 CryptAuthDeviceManager* device_manager =
457 proximity_auth_client_->GetCryptAuthDeviceManager();
458 if (!device_manager)
494 return make_scoped_ptr(new base::DictionaryValue()); 459 return make_scoped_ptr(new base::DictionaryValue());
495 460
496 return CreateSyncStateDictionary( 461 return CreateSyncStateDictionary(
497 device_manager_->GetLastSyncTime().ToJsTime(), 462 device_manager->GetLastSyncTime().ToJsTime(),
498 device_manager_->GetTimeToNextAttempt().InMillisecondsF(), 463 device_manager->GetTimeToNextAttempt().InMillisecondsF(),
499 device_manager_->IsRecoveringFromFailure(), 464 device_manager->IsRecoveringFromFailure(),
500 device_manager_->IsSyncInProgress()); 465 device_manager->IsSyncInProgress());
501 } 466 }
502 467
503 scoped_ptr<base::ListValue> ProximityAuthWebUIHandler::GetUnlockKeysList() { 468 scoped_ptr<base::ListValue> ProximityAuthWebUIHandler::GetUnlockKeysList() {
504 scoped_ptr<base::ListValue> unlock_keys(new base::ListValue()); 469 scoped_ptr<base::ListValue> unlock_keys(new base::ListValue());
505 if (!device_manager_) 470 CryptAuthDeviceManager* device_manager =
471 proximity_auth_client_->GetCryptAuthDeviceManager();
472 if (!device_manager)
506 return unlock_keys; 473 return unlock_keys;
507 474
508 for (const auto& unlock_key : device_manager_->unlock_keys()) { 475 for (const auto& unlock_key : device_manager->unlock_keys()) {
509 unlock_keys->Append(ExternalDeviceInfoToDictionary(unlock_key)); 476 unlock_keys->Append(ExternalDeviceInfoToDictionary(unlock_key));
510 } 477 }
511 478
512 return unlock_keys; 479 return unlock_keys;
513 } 480 }
514 481
515 Connection* ProximityAuthWebUIHandler::GetConnection() { 482 Connection* ProximityAuthWebUIHandler::GetConnection() {
516 Connection* connection = connection_.get(); 483 Connection* connection = connection_.get();
517 if (client_) { 484 if (client_) {
518 DCHECK(!connection); 485 DCHECK(!connection);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 connection_finder_->Find( 521 connection_finder_->Find(
555 base::Bind(&ProximityAuthWebUIHandler::OnConnectionFound, 522 base::Bind(&ProximityAuthWebUIHandler::OnConnectionFound,
556 weak_ptr_factory_.GetWeakPtr())); 523 weak_ptr_factory_.GetWeakPtr()));
557 524
558 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", 525 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged",
559 *GetUnlockKeysList()); 526 *GetUnlockKeysList());
560 } 527 }
561 528
562 void ProximityAuthWebUIHandler::FindBluetoothLowEnergyConnection( 529 void ProximityAuthWebUIHandler::FindBluetoothLowEnergyConnection(
563 const RemoteDevice& remote_device) { 530 const RemoteDevice& remote_device) {
564 PrefService* pref_service = delegate_->GetPrefService(); 531 PrefService* pref_service = proximity_auth_client_->GetPrefService();
565 if (!pref_service->FindPreference( 532 if (!pref_service->FindPreference(
566 prefs::kBluetoothLowEnergyDeviceWhitelist)) { 533 prefs::kBluetoothLowEnergyDeviceWhitelist)) {
567 PA_LOG(ERROR) << "Please enable the BLE experiment in chrome://flags."; 534 PA_LOG(ERROR) << "Please enable the BLE experiment in chrome://flags.";
568 return; 535 return;
569 } 536 }
570 537
571 PA_LOG(INFO) << "Finding Bluetooth Low Energy device " << remote_device.name; 538 PA_LOG(INFO) << "Finding Bluetooth Low Energy device " << remote_device.name;
572 if (!bluetooth_throttler_) { 539 if (!bluetooth_throttler_) {
573 bluetooth_throttler_.reset(new BluetoothThrottlerImpl( 540 bluetooth_throttler_.reset(new BluetoothThrottlerImpl(
574 make_scoped_ptr(new base::DefaultTickClock()))); 541 make_scoped_ptr(new base::DefaultTickClock())));
575 } 542 }
576 543
577 ble_device_whitelist_.reset( 544 ble_device_whitelist_.reset(new BluetoothLowEnergyDeviceWhitelist(
578 new BluetoothLowEnergyDeviceWhitelist(delegate_->GetPrefService())); 545 proximity_auth_client_->GetPrefService()));
579 546
580 // TODO(tengs): Set a timeout to stop the connection finder eventually. 547 // TODO(tengs): Set a timeout to stop the connection finder eventually.
581 connection_finder_.reset(new BluetoothLowEnergyConnectionFinder( 548 connection_finder_.reset(new BluetoothLowEnergyConnectionFinder(
582 kBLESmartLockServiceUUID, kBLEToPeripheralCharUUID, 549 kBLESmartLockServiceUUID, kBLEToPeripheralCharUUID,
583 kBLEFromPeripheralCharUUID, ble_device_whitelist_.get(), 550 kBLEFromPeripheralCharUUID, ble_device_whitelist_.get(),
584 bluetooth_throttler_.get(), 3)); 551 bluetooth_throttler_.get(), 3));
585 connection_finder_->Find( 552 connection_finder_->Find(
586 base::Bind(&ProximityAuthWebUIHandler::OnConnectionFound, 553 base::Bind(&ProximityAuthWebUIHandler::OnConnectionFound,
587 weak_ptr_factory_.GetWeakPtr())); 554 weak_ptr_factory_.GetWeakPtr()));
588 555
(...skipping 22 matching lines...) Expand all
611 connection_->AddObserver(this); 578 connection_->AddObserver(this);
612 579
613 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", 580 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged",
614 *GetUnlockKeysList()); 581 *GetUnlockKeysList());
615 582
616 // TODO(tengs): Create an authenticator for BLE connections. 583 // TODO(tengs): Create an authenticator for BLE connections.
617 if (selected_remote_device_.bluetooth_address.empty()) 584 if (selected_remote_device_.bluetooth_address.empty())
618 return; 585 return;
619 586
620 authenticator_.reset(new DeviceToDeviceAuthenticator( 587 authenticator_.reset(new DeviceToDeviceAuthenticator(
621 connection_.get(), delegate_->GetAccountId(), 588 connection_.get(), proximity_auth_client_->GetAccountId(),
622 delegate_->CreateSecureMessageDelegate())); 589 proximity_auth_client_->CreateSecureMessageDelegate()));
623 authenticator_->Authenticate( 590 authenticator_->Authenticate(
624 base::Bind(&ProximityAuthWebUIHandler::OnAuthenticationResult, 591 base::Bind(&ProximityAuthWebUIHandler::OnAuthenticationResult,
625 weak_ptr_factory_.GetWeakPtr())); 592 weak_ptr_factory_.GetWeakPtr()));
626 } 593 }
627 594
628 void ProximityAuthWebUIHandler::CreateStatusUpdateClient() { 595 void ProximityAuthWebUIHandler::CreateStatusUpdateClient() {
629 client_.reset(new ClientImpl(connection_.Pass(), secure_context_.Pass())); 596 client_.reset(new ClientImpl(connection_.Pass(), secure_context_.Pass()));
630 client_->AddObserver(this); 597 client_->AddObserver(this);
631 } 598 }
632 599
633 scoped_ptr<base::DictionaryValue> 600 scoped_ptr<base::DictionaryValue>
634 ProximityAuthWebUIHandler::ExternalDeviceInfoToDictionary( 601 ProximityAuthWebUIHandler::ExternalDeviceInfoToDictionary(
635 const cryptauth::ExternalDeviceInfo& device_info) { 602 const cryptauth::ExternalDeviceInfo& device_info) {
636 std::string base64_public_key; 603 std::string base64_public_key;
637 Base64UrlEncode(device_info.public_key(), &base64_public_key); 604 Base64UrlEncode(device_info.public_key(), &base64_public_key);
638 605
639 // Set the fields in the ExternalDeviceInfo proto. 606 // Set the fields in the ExternalDeviceInfo proto.
640 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); 607 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue());
641 dictionary->SetString(kExternalDevicePublicKey, base64_public_key); 608 dictionary->SetString(kExternalDevicePublicKey, base64_public_key);
642 dictionary->SetString(kExternalDeviceFriendlyName, 609 dictionary->SetString(kExternalDeviceFriendlyName,
643 device_info.friendly_device_name()); 610 device_info.friendly_device_name());
644 dictionary->SetString(kExternalDeviceBluetoothAddress, 611 dictionary->SetString(kExternalDeviceBluetoothAddress,
645 device_info.bluetooth_address()); 612 device_info.bluetooth_address());
646 dictionary->SetBoolean(kExternalDeviceUnlockKey, device_info.unlock_key()); 613 dictionary->SetBoolean(kExternalDeviceUnlockKey, device_info.unlock_key());
647 dictionary->SetString(kExternalDeviceConnectionStatus, 614 dictionary->SetString(kExternalDeviceConnectionStatus,
648 kExternalDeviceDisconnected); 615 kExternalDeviceDisconnected);
649 616
650 if (!device_manager_) 617 CryptAuthDeviceManager* device_manager =
618 proximity_auth_client_->GetCryptAuthDeviceManager();
619 if (!device_manager)
651 return dictionary; 620 return dictionary;
652 621
653 // If |device_info| is a known unlock key, then combine the proto data with 622 // If |device_info| is a known unlock key, then combine the proto data with
654 // the corresponding local device data (e.g. connection status and remote 623 // the corresponding local device data (e.g. connection status and remote
655 // status updates). 624 // status updates).
656 std::string public_key = device_info.public_key(); 625 std::string public_key = device_info.public_key();
657 auto iterator = std::find_if( 626 auto iterator = std::find_if(
658 device_manager_->unlock_keys().begin(), 627 device_manager->unlock_keys().begin(),
659 device_manager_->unlock_keys().end(), 628 device_manager->unlock_keys().end(),
660 [&public_key](const cryptauth::ExternalDeviceInfo& unlock_key) { 629 [&public_key](const cryptauth::ExternalDeviceInfo& unlock_key) {
661 return unlock_key.public_key() == public_key; 630 return unlock_key.public_key() == public_key;
662 }); 631 });
663 632
664 if (iterator == device_manager_->unlock_keys().end() || 633 if (iterator == device_manager->unlock_keys().end() ||
665 selected_remote_device_.public_key != device_info.public_key()) 634 selected_remote_device_.public_key != device_info.public_key())
666 return dictionary; 635 return dictionary;
667 636
668 // Fill in the current Bluetooth connection status. 637 // Fill in the current Bluetooth connection status.
669 std::string connection_status = kExternalDeviceDisconnected; 638 std::string connection_status = kExternalDeviceDisconnected;
670 Connection* connection = GetConnection(); 639 Connection* connection = GetConnection();
671 if (connection && connection->IsConnected()) { 640 if (connection && connection->IsConnected()) {
672 connection_status = kExternalDeviceConnected; 641 connection_status = kExternalDeviceConnected;
673 } else if (connection_finder_) { 642 } else if (connection_finder_) {
674 connection_status = kExternalDeviceConnecting; 643 connection_status = kExternalDeviceConnecting;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 << "\n trust_agent_state: " 710 << "\n trust_agent_state: "
742 << static_cast<int>(status_update.trust_agent_state); 711 << static_cast<int>(status_update.trust_agent_state);
743 712
744 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update)); 713 last_remote_status_update_.reset(new RemoteStatusUpdate(status_update));
745 scoped_ptr<base::ListValue> unlock_keys = GetUnlockKeysList(); 714 scoped_ptr<base::ListValue> unlock_keys = GetUnlockKeysList();
746 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged", 715 web_ui()->CallJavascriptFunction("LocalStateInterface.onUnlockKeysChanged",
747 *unlock_keys); 716 *unlock_keys);
748 } 717 }
749 718
750 } // namespace proximity_auth 719 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/webui/proximity_auth_webui_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698