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

Side by Side Diff: chrome/browser/signin/easy_unlock_service_regular.cc

Issue 1372283002: Hook up ProximityAuthSystem in EasyUnlockService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_connection
Patch Set: fix compile Created 5 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/signin/easy_unlock_service_regular.h" 5 #include "chrome/browser/signin/easy_unlock_service_regular.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/sys_info.h" 12 #include "base/sys_info.h"
13 #include "base/time/default_clock.h" 13 #include "base/time/default_clock.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/services/gcm/gcm_profile_service.h" 17 #include "chrome/browser/services/gcm/gcm_profile_service.h"
18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
19 #include "chrome/browser/signin/chrome_proximity_auth_client.h" 19 #include "chrome/browser/signin/chrome_proximity_auth_client.h"
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 21 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/common/extensions/api/easy_unlock_private.h" 22 #include "chrome/common/extensions/api/easy_unlock_private.h"
23 #include "chrome/common/extensions/extension_constants.h" 23 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
25 #include "chromeos/login/user_names.h" 25 #include "chromeos/login/user_names.h"
26 #include "components/pref_registry/pref_registry_syncable.h" 26 #include "components/pref_registry/pref_registry_syncable.h"
27 #include "components/proximity_auth/cryptauth/base64url.h"
27 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h" 28 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h"
28 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" 29 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h"
29 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h"
30 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" 30 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h"
31 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_utils.h" 31 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_utils.h"
32 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.h" 32 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.h"
33 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" 33 #include "components/proximity_auth/cryptauth/secure_message_delegate.h"
34 #include "components/proximity_auth/cryptauth_enroller_factory_impl.h" 34 #include "components/proximity_auth/cryptauth_enroller_factory_impl.h"
35 #include "components/proximity_auth/logging/logging.h" 35 #include "components/proximity_auth/logging/logging.h"
36 #include "components/proximity_auth/proximity_auth_system.h"
37 #include "components/proximity_auth/remote_device_loader.h"
36 #include "components/proximity_auth/screenlock_bridge.h" 38 #include "components/proximity_auth/screenlock_bridge.h"
37 #include "components/proximity_auth/switches.h" 39 #include "components/proximity_auth/switches.h"
38 #include "components/signin/core/browser/profile_oauth2_token_service.h" 40 #include "components/signin/core/browser/profile_oauth2_token_service.h"
39 #include "components/signin/core/browser/signin_manager.h" 41 #include "components/signin/core/browser/signin_manager.h"
40 #include "components/translate/core/browser/translate_download_manager.h" 42 #include "components/translate/core/browser/translate_download_manager.h"
41 #include "components/version_info/version_info.h" 43 #include "components/version_info/version_info.h"
42 #include "content/public/browser/browser_thread.h" 44 #include "content/public/browser/browser_thread.h"
43 #include "extensions/browser/event_router.h" 45 #include "extensions/browser/event_router.h"
44 #include "extensions/common/constants.h" 46 #include "extensions/common/constants.h"
45 #include "google_apis/gaia/gaia_auth_util.h" 47 #include "google_apis/gaia/gaia_auth_util.h"
(...skipping 20 matching lines...) Expand all
66 // Key name of the remote device list in kEasyUnlockPairing. 68 // Key name of the remote device list in kEasyUnlockPairing.
67 const char kKeyDevices[] = "devices"; 69 const char kKeyDevices[] = "devices";
68 70
69 } // namespace 71 } // namespace
70 72
71 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile) 73 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile)
72 : EasyUnlockService(profile), 74 : EasyUnlockService(profile),
73 turn_off_flow_status_(EasyUnlockService::IDLE), 75 turn_off_flow_status_(EasyUnlockService::IDLE),
74 will_unlock_using_easy_unlock_(false), 76 will_unlock_using_easy_unlock_(false),
75 lock_screen_last_shown_timestamp_(base::TimeTicks::Now()), 77 lock_screen_last_shown_timestamp_(base::TimeTicks::Now()),
76 weak_ptr_factory_(this) { 78 deferring_device_load_(false),
77 } 79 weak_ptr_factory_(this) {}
78 80
79 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { 81 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() {
80 } 82 }
81 83
82 proximity_auth::CryptAuthEnrollmentManager* 84 proximity_auth::CryptAuthEnrollmentManager*
83 EasyUnlockServiceRegular::GetCryptAuthEnrollmentManager() { 85 EasyUnlockServiceRegular::GetCryptAuthEnrollmentManager() {
84 return enrollment_manager_.get(); 86 return enrollment_manager_.get();
85 } 87 }
86 88
87 proximity_auth::CryptAuthDeviceManager* 89 proximity_auth::CryptAuthDeviceManager*
88 EasyUnlockServiceRegular::GetCryptAuthDeviceManager() { 90 EasyUnlockServiceRegular::GetCryptAuthDeviceManager() {
89 return device_manager_.get(); 91 return device_manager_.get();
90 } 92 }
91 93
94 void EasyUnlockServiceRegular::LoadRemoteDevices() {
sacomoto 2015/09/30 16:46:40 After the setup is completed we need to sync the d
Tim Song 2015/09/30 19:13:39 That sounds good.
95 if (device_manager_->unlock_keys().empty()) {
96 OnRemoteDeviceChanged(nullptr);
97 return;
98 }
99
100 remote_device_loader_.reset(new proximity_auth::RemoteDeviceLoader(
101 device_manager_->unlock_keys(), proximity_auth_client()->GetAccountId(),
102 enrollment_manager_->GetUserPrivateKey(),
103 proximity_auth_client()->CreateSecureMessageDelegate()));
104 remote_device_loader_->Load(
105 base::Bind(&EasyUnlockServiceRegular::OnRemoteDevicesLoaded,
106 weak_ptr_factory_.GetWeakPtr()));
107 }
108
109 void EasyUnlockServiceRegular::OnRemoteDevicesLoaded(
110 const std::vector<proximity_auth::RemoteDevice>& remote_devices) {
111 // TODO(tengs): We only support unlocking with one remote device at the
112 // moment. We need to revisit once multiple devices are supported.
113 OnRemoteDeviceChanged(&remote_devices[0]);
114
115 #if defined(OS_CHROMEOS)
116 // We need to store a copy of |remote devices_| in the TPM, so it can be
117 // retrieved on the sign-in screen when a user session has not been started
118 // yet.
119 scoped_ptr<base::ListValue> device_list(new base::ListValue());
120 for (const auto& device : remote_devices) {
121 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
122 std::string b64_public_key, b64_psk;
123 proximity_auth::Base64UrlEncode(device.public_key, &b64_public_key);
124 proximity_auth::Base64UrlEncode(device.persistent_symmetric_key, &b64_psk);
125
126 dict->SetString("name", device.name);
127 dict->SetString("psk", b64_psk);
128 dict->SetString("bluetoothAddress", device.bluetooth_address);
129 dict->SetString("permitId", "permit://google.com/easyunlock/v1/" +
130 proximity_auth_client()->GetAccountId());
131 dict->SetString("permitRecord.id", b64_public_key);
132 dict->SetString("permitRecord.type", "license");
133 dict->SetString("permitRecord.data", b64_public_key);
134 device_list->Append(dict.Pass());
135 }
136
137 // TODO(tengs): Rename this function after the easy_unlock app is replaced.
138 SetRemoteDevices(*device_list);
139 #endif
140 }
141
92 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { 142 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const {
93 return EasyUnlockService::TYPE_REGULAR; 143 return EasyUnlockService::TYPE_REGULAR;
94 } 144 }
95 145
96 std::string EasyUnlockServiceRegular::GetUserEmail() const { 146 std::string EasyUnlockServiceRegular::GetUserEmail() const {
97 const SigninManagerBase* signin_manager = 147 const SigninManagerBase* signin_manager =
98 SigninManagerFactory::GetForProfileIfExists(profile()); 148 SigninManagerFactory::GetForProfileIfExists(profile());
99 // |profile| has to be a signed-in profile with SigninManager already 149 // |profile| has to be a signed-in profile with SigninManager already
100 // created. Otherwise, just crash to collect stack. 150 // created. Otherwise, just crash to collect stack.
101 DCHECK(signin_manager); 151 DCHECK(signin_manager);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 proximity_auth::ScreenlockBridge::Get()->AddObserver(this); 357 proximity_auth::ScreenlockBridge::Get()->AddObserver(this);
308 registrar_.Init(profile()->GetPrefs()); 358 registrar_.Init(profile()->GetPrefs());
309 registrar_.Add( 359 registrar_.Add(
310 prefs::kEasyUnlockAllowed, 360 prefs::kEasyUnlockAllowed,
311 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, 361 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
312 base::Unretained(this))); 362 base::Unretained(this)));
313 registrar_.Add(prefs::kEasyUnlockProximityRequired, 363 registrar_.Add(prefs::kEasyUnlockProximityRequired,
314 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, 364 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
315 base::Unretained(this))); 365 base::Unretained(this)));
316 366
367 OnPrefsChanged();
368
317 #if defined(OS_CHROMEOS) 369 #if defined(OS_CHROMEOS)
318 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 370 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
319 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) 371 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) {
320 InitializeCryptAuth(); 372 InitializeCryptAuth();
373 LoadRemoteDevices();
374 }
321 #endif 375 #endif
322
323 OnPrefsChanged();
324 } 376 }
325 377
326 void EasyUnlockServiceRegular::ShutdownInternal() { 378 void EasyUnlockServiceRegular::ShutdownInternal() {
327 #if defined(OS_CHROMEOS) 379 #if defined(OS_CHROMEOS)
328 short_lived_user_context_.reset(); 380 short_lived_user_context_.reset();
329 #endif 381 #endif
330 382
331 turn_off_flow_status_ = EasyUnlockService::IDLE; 383 turn_off_flow_status_ = EasyUnlockService::IDLE;
332 registrar_.RemoveAll(); 384 registrar_.RemoveAll();
333 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); 385 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this);
(...skipping 21 matching lines...) Expand all
355 #else 407 #else
356 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. 408 // TODO(xiyuan): Revisit when non-chromeos platforms are supported.
357 return false; 409 return false;
358 #endif 410 #endif
359 } 411 }
360 412
361 void EasyUnlockServiceRegular::OnWillFinalizeUnlock(bool success) { 413 void EasyUnlockServiceRegular::OnWillFinalizeUnlock(bool success) {
362 will_unlock_using_easy_unlock_ = success; 414 will_unlock_using_easy_unlock_ = success;
363 } 415 }
364 416
365 void EasyUnlockServiceRegular::OnSuspendDone() { 417 void EasyUnlockServiceRegular::OnSuspendDoneInternal() {
366 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); 418 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now();
367 } 419 }
368 420
369 void EasyUnlockServiceRegular::OnRefreshTokenAvailable( 421 void EasyUnlockServiceRegular::OnRefreshTokenAvailable(
370 const std::string& account_id) { 422 const std::string& account_id) {
371 if (account_id == proximity_auth_client()->GetAccountId()) { 423 if (account_id == proximity_auth_client()->GetAccountId()) {
372 OAuth2TokenService* token_service = 424 OAuth2TokenService* token_service =
373 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); 425 ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
374 token_service->RemoveObserver(this); 426 token_service->RemoveObserver(this);
375 #if defined(OS_CHROMEOS) 427 #if defined(OS_CHROMEOS)
376 InitializeCryptAuth(); 428 enrollment_manager_->Start();
429 device_manager_->Start();
377 #endif 430 #endif
378 } 431 }
379 } 432 }
380 433
434 void EasyUnlockServiceRegular::OnSyncFinished(
435 proximity_auth::CryptAuthDeviceManager::SyncResult sync_result,
436 proximity_auth::CryptAuthDeviceManager::DeviceChangeResult
437 device_change_result) {
438 if (device_change_result !=
439 proximity_auth::CryptAuthDeviceManager::DeviceChangeResult::CHANGED)
440 return;
441
442 if (proximity_auth::ScreenlockBridge::Get()->IsLocked()) {
443 PA_LOG(INFO) << "Deferring device load until screen is unlocked.";
444 deferring_device_load_ = true;
445 } else {
446 LoadRemoteDevices();
447 }
448 }
449
381 void EasyUnlockServiceRegular::OnScreenDidLock( 450 void EasyUnlockServiceRegular::OnScreenDidLock(
382 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { 451 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
383 will_unlock_using_easy_unlock_ = false; 452 will_unlock_using_easy_unlock_ = false;
384 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); 453 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now();
385 } 454 }
386 455
387 void EasyUnlockServiceRegular::OnScreenDidUnlock( 456 void EasyUnlockServiceRegular::OnScreenDidUnlock(
388 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { 457 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
389 // Notifications of signin screen unlock events can also reach this code path; 458 // Notifications of signin screen unlock events can also reach this code path;
390 // disregard them. 459 // disregard them.
391 if (screen_type != proximity_auth::ScreenlockBridge::LockHandler::LOCK_SCREEN) 460 if (screen_type != proximity_auth::ScreenlockBridge::LockHandler::LOCK_SCREEN)
392 return; 461 return;
393 462
394 // Only record metrics for users who have enabled the feature. 463 // Only record metrics for users who have enabled the feature.
395 if (IsEnabled()) { 464 if (IsEnabled()) {
396 EasyUnlockAuthEvent event = 465 EasyUnlockAuthEvent event =
397 will_unlock_using_easy_unlock_ 466 will_unlock_using_easy_unlock_
398 ? EASY_UNLOCK_SUCCESS 467 ? EASY_UNLOCK_SUCCESS
399 : GetPasswordAuthEvent(); 468 : GetPasswordAuthEvent();
400 RecordEasyUnlockScreenUnlockEvent(event); 469 RecordEasyUnlockScreenUnlockEvent(event);
401 470
402 if (will_unlock_using_easy_unlock_) { 471 if (will_unlock_using_easy_unlock_) {
403 RecordEasyUnlockScreenUnlockDuration( 472 RecordEasyUnlockScreenUnlockDuration(
404 base::TimeTicks::Now() - lock_screen_last_shown_timestamp_); 473 base::TimeTicks::Now() - lock_screen_last_shown_timestamp_);
405 } 474 }
406 } 475 }
407 476
408 will_unlock_using_easy_unlock_ = false; 477 will_unlock_using_easy_unlock_ = false;
478
479 // If we synced remote devices while the screen was locked, we can now load
480 // the new remote devices.
481 if (deferring_device_load_) {
482 PA_LOG(INFO) << "Loading deferred devices after screen unlock.";
483 deferring_device_load_ = false;
484 LoadRemoteDevices();
485 }
409 } 486 }
410 487
411 void EasyUnlockServiceRegular::OnFocusedUserChanged( 488 void EasyUnlockServiceRegular::OnFocusedUserChanged(
412 const std::string& user_id) { 489 const std::string& user_id) {
413 // Nothing to do. 490 // Nothing to do.
414 } 491 }
415 492
416 void EasyUnlockServiceRegular::OnPrefsChanged() { 493 void EasyUnlockServiceRegular::OnPrefsChanged() {
417 SyncProfilePrefsToLocalState(); 494 SyncProfilePrefsToLocalState();
418 UpdateAppState(); 495 UpdateAppState();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 // Note: The unit of this measument is in milli-inches. 576 // Note: The unit of this measument is in milli-inches.
500 device_info.set_device_display_diagonal_mils(diagonal_in_inches * 1000.0); 577 device_info.set_device_display_diagonal_mils(diagonal_in_inches * 1000.0);
501 #else 578 #else
502 // TODO(tengs): Fill in device information for other platforms. 579 // TODO(tengs): Fill in device information for other platforms.
503 #endif 580 #endif
504 return device_info; 581 return device_info;
505 } 582 }
506 583
507 #if defined(OS_CHROMEOS) 584 #if defined(OS_CHROMEOS)
508 void EasyUnlockServiceRegular::InitializeCryptAuth() { 585 void EasyUnlockServiceRegular::InitializeCryptAuth() {
509 OAuth2TokenService* token_service =
510 ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
511 if (!token_service->RefreshTokenIsAvailable(
512 proximity_auth_client()->GetAccountId())) {
513 PA_LOG(INFO) << "Refresh token not yet available.";
514 token_service->AddObserver(this);
515 return;
516 }
517
518 PA_LOG(INFO) << "Initializing CryptAuth managers."; 586 PA_LOG(INFO) << "Initializing CryptAuth managers.";
519 // Initialize GCM manager. 587 // Initialize GCM manager.
520 gcm_manager_.reset(new proximity_auth::CryptAuthGCMManagerImpl( 588 gcm_manager_.reset(new proximity_auth::CryptAuthGCMManagerImpl(
521 gcm::GCMProfileServiceFactory::GetForProfile(profile())->driver(), 589 gcm::GCMProfileServiceFactory::GetForProfile(profile())->driver(),
522 proximity_auth_client()->GetPrefService())); 590 proximity_auth_client()->GetPrefService()));
523 gcm_manager_->StartListening(); 591 gcm_manager_->StartListening();
524 592
525 // Initialize enrollment manager. 593 // Initialize enrollment manager.
526 cryptauth::GcmDeviceInfo device_info; 594 cryptauth::GcmDeviceInfo device_info;
527 enrollment_manager_.reset(new proximity_auth::CryptAuthEnrollmentManager( 595 enrollment_manager_.reset(new proximity_auth::CryptAuthEnrollmentManager(
528 make_scoped_ptr(new base::DefaultClock()), 596 make_scoped_ptr(new base::DefaultClock()),
529 make_scoped_ptr(new proximity_auth::CryptAuthEnrollerFactoryImpl( 597 make_scoped_ptr(new proximity_auth::CryptAuthEnrollerFactoryImpl(
530 proximity_auth_client())), 598 proximity_auth_client())),
531 proximity_auth_client()->CreateSecureMessageDelegate(), 599 proximity_auth_client()->CreateSecureMessageDelegate(),
532 GetGcmDeviceInfo(), gcm_manager_.get(), 600 GetGcmDeviceInfo(), gcm_manager_.get(),
533 proximity_auth_client()->GetPrefService())); 601 proximity_auth_client()->GetPrefService()));
534 enrollment_manager_->Start();
535 602
536 // Initialize device manager. 603 // Initialize device manager.
537 device_manager_.reset(new proximity_auth::CryptAuthDeviceManager( 604 device_manager_.reset(new proximity_auth::CryptAuthDeviceManager(
538 make_scoped_ptr(new base::DefaultClock()), 605 make_scoped_ptr(new base::DefaultClock()),
539 proximity_auth_client()->CreateCryptAuthClientFactory(), 606 proximity_auth_client()->CreateCryptAuthClientFactory(),
540 gcm_manager_.get(), proximity_auth_client()->GetPrefService())); 607 gcm_manager_.get(), proximity_auth_client()->GetPrefService()));
608
609 OAuth2TokenService* token_service =
610 ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
611 if (!token_service->RefreshTokenIsAvailable(
612 proximity_auth_client()->GetAccountId())) {
613 PA_LOG(INFO) << "Refresh token not yet available, "
614 << "waiting before starting CryptAuth managers";
615 token_service->AddObserver(this);
616 }
617
618 device_manager_->AddObserver(this);
619 enrollment_manager_->Start();
541 device_manager_->Start(); 620 device_manager_->Start();
542 } 621 }
543 #endif 622 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698