| OLD | NEW |
| 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.h" | 5 #include "chrome/browser/signin/easy_unlock_service.h" |
| 6 | 6 |
| 7 #include "apps/app_lifetime_monitor.h" | 7 #include "apps/app_lifetime_monitor.h" |
| 8 #include "apps/app_lifetime_monitor_factory.h" | 8 #include "apps/app_lifetime_monitor_factory.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/signin/chrome_proximity_auth_client.h" | 24 #include "chrome/browser/signin/chrome_proximity_auth_client.h" |
| 25 #include "chrome/browser/signin/easy_unlock_app_manager.h" | 25 #include "chrome/browser/signin/easy_unlock_app_manager.h" |
| 26 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 26 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
| 27 #include "chrome/browser/signin/easy_unlock_service_observer.h" | 27 #include "chrome/browser/signin/easy_unlock_service_observer.h" |
| 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 29 #include "chrome/browser/signin/signin_manager_factory.h" | 29 #include "chrome/browser/signin/signin_manager_factory.h" |
| 30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
| 32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 33 #include "components/pref_registry/pref_registry_syncable.h" | 33 #include "components/pref_registry/pref_registry_syncable.h" |
| 34 #include "components/proximity_auth/ble/proximity_auth_ble_system.h" | |
| 35 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" | 34 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" |
| 36 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h" | 35 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h" |
| 37 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" | 36 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" |
| 38 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" | 37 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" |
| 38 #include "components/proximity_auth/logging/logging.h" |
| 39 #include "components/proximity_auth/proximity_auth_system.h" |
| 39 #include "components/proximity_auth/screenlock_bridge.h" | 40 #include "components/proximity_auth/screenlock_bridge.h" |
| 40 #include "components/proximity_auth/switches.h" | 41 #include "components/proximity_auth/switches.h" |
| 41 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 42 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 42 #include "components/signin/core/browser/signin_manager.h" | 43 #include "components/signin/core/browser/signin_manager.h" |
| 43 #include "components/user_manager/user.h" | 44 #include "components/user_manager/user.h" |
| 44 #include "components/version_info/version_info.h" | 45 #include "components/version_info/version_info.h" |
| 45 #include "device/bluetooth/bluetooth_adapter.h" | 46 #include "device/bluetooth/bluetooth_adapter.h" |
| 46 #include "device/bluetooth/bluetooth_adapter_factory.h" | 47 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 47 | 48 |
| 48 #if defined(OS_CHROMEOS) | 49 #if defined(OS_CHROMEOS) |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 registry->RegisterDictionaryPref(prefs::kEasyUnlockPairing, | 277 registry->RegisterDictionaryPref(prefs::kEasyUnlockPairing, |
| 277 new base::DictionaryValue()); | 278 new base::DictionaryValue()); |
| 278 registry->RegisterBooleanPref( | 279 registry->RegisterBooleanPref( |
| 279 prefs::kEasyUnlockProximityRequired, | 280 prefs::kEasyUnlockProximityRequired, |
| 280 false, | 281 false, |
| 281 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 282 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 282 | 283 |
| 283 proximity_auth::CryptAuthGCMManager::RegisterPrefs(registry); | 284 proximity_auth::CryptAuthGCMManager::RegisterPrefs(registry); |
| 284 proximity_auth::CryptAuthDeviceManager::RegisterPrefs(registry); | 285 proximity_auth::CryptAuthDeviceManager::RegisterPrefs(registry); |
| 285 proximity_auth::CryptAuthEnrollmentManager::RegisterPrefs(registry); | 286 proximity_auth::CryptAuthEnrollmentManager::RegisterPrefs(registry); |
| 286 | |
| 287 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 288 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) | |
| 289 proximity_auth::ProximityAuthBleSystem::RegisterPrefs(registry); | |
| 290 } | 287 } |
| 291 | 288 |
| 292 // static | 289 // static |
| 293 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { | 290 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 294 registry->RegisterStringPref(prefs::kEasyUnlockDeviceId, std::string()); | 291 registry->RegisterStringPref(prefs::kEasyUnlockDeviceId, std::string()); |
| 295 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); | 292 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); |
| 296 registry->RegisterDictionaryPref(prefs::kEasyUnlockLocalStateUserPrefs); | 293 registry->RegisterDictionaryPref(prefs::kEasyUnlockLocalStateUserPrefs); |
| 297 #if defined(OS_CHROMEOS) | 294 #if defined(OS_CHROMEOS) |
| 298 EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry); | 295 EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry); |
| 299 #endif | 296 #endif |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 return; | 515 return; |
| 519 } | 516 } |
| 520 | 517 |
| 521 CHECK_EQ(GetUserEmail(), user_id); | 518 CHECK_EQ(GetUserEmail(), user_id); |
| 522 | 519 |
| 523 auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), user_id, | 520 auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), user_id, |
| 524 auth_attempt_type, callback)); | 521 auth_attempt_type, callback)); |
| 525 if (!auth_attempt_->Start()) | 522 if (!auth_attempt_->Start()) |
| 526 auth_attempt_.reset(); | 523 auth_attempt_.reset(); |
| 527 | 524 |
| 528 // TODO(tengs): We notify ProximityAuthBleSystem whenever unlock attempts are | 525 // TODO(tengs): We notify ProximityAuthSystem whenever unlock attempts are |
| 529 // attempted. However, we ideally should refactor the auth attempt logic to | 526 // attempted. However, we ideally should refactor the auth attempt logic to |
| 530 // the proximity_auth component. | 527 // the proximity_auth component. |
| 531 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 528 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 532 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) && | 529 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) && |
| 533 auth_attempt_type == EasyUnlockAuthAttempt::TYPE_UNLOCK && | 530 auth_attempt_type == EasyUnlockAuthAttempt::TYPE_UNLOCK && |
| 534 proximity_auth_ble_system_) { | 531 proximity_auth_system_) { |
| 535 proximity_auth_ble_system_->OnAuthAttempted(user_id); | 532 proximity_auth_system_->OnAuthAttempted(user_id); |
| 536 } | 533 } |
| 537 } | 534 } |
| 538 | 535 |
| 539 void EasyUnlockService::FinalizeUnlock(bool success) { | 536 void EasyUnlockService::FinalizeUnlock(bool success) { |
| 540 if (!auth_attempt_.get()) | 537 if (!auth_attempt_.get()) |
| 541 return; | 538 return; |
| 542 | 539 |
| 543 this->OnWillFinalizeUnlock(success); | 540 this->OnWillFinalizeUnlock(success); |
| 544 auth_attempt_->FinalizeUnlock(GetUserEmail(), success); | 541 auth_attempt_->FinalizeUnlock(GetUserEmail(), success); |
| 545 auth_attempt_.reset(); | 542 auth_attempt_.reset(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 639 |
| 643 void EasyUnlockService::Shutdown() { | 640 void EasyUnlockService::Shutdown() { |
| 644 if (shut_down_) | 641 if (shut_down_) |
| 645 return; | 642 return; |
| 646 shut_down_ = true; | 643 shut_down_ = true; |
| 647 | 644 |
| 648 ShutdownInternal(); | 645 ShutdownInternal(); |
| 649 | 646 |
| 650 ResetScreenlockState(); | 647 ResetScreenlockState(); |
| 651 bluetooth_detector_.reset(); | 648 bluetooth_detector_.reset(); |
| 649 proximity_auth_system_.reset(); |
| 652 #if defined(OS_CHROMEOS) | 650 #if defined(OS_CHROMEOS) |
| 653 power_monitor_.reset(); | 651 power_monitor_.reset(); |
| 654 #endif | 652 #endif |
| 655 | 653 |
| 656 weak_ptr_factory_.InvalidateWeakPtrs(); | 654 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 657 } | 655 } |
| 658 | 656 |
| 659 void EasyUnlockService::ReloadAppAndLockScreen() { | 657 void EasyUnlockService::ReloadAppAndLockScreen() { |
| 660 // Make sure lock screen state set by the extension gets reset. | 658 // Make sure lock screen state set by the extension gets reset. |
| 661 ResetScreenlockState(); | 659 ResetScreenlockState(); |
| 662 app_manager_->ReloadApp(); | 660 app_manager_->ReloadApp(); |
| 663 NotifyUserUpdated(); | 661 NotifyUserUpdated(); |
| 664 } | 662 } |
| 665 | 663 |
| 666 void EasyUnlockService::UpdateAppState() { | 664 void EasyUnlockService::UpdateAppState() { |
| 667 if (IsAllowed()) { | 665 if (IsAllowed()) { |
| 668 EnsureTpmKeyPresentIfNeeded(); | 666 EnsureTpmKeyPresentIfNeeded(); |
| 669 app_manager_->LoadApp(); | 667 app_manager_->LoadApp(); |
| 670 NotifyUserUpdated(); | 668 NotifyUserUpdated(); |
| 671 | 669 |
| 672 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 673 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) && | |
| 674 GetType() == EasyUnlockService::TYPE_REGULAR && | |
| 675 !proximity_auth_ble_system_) { | |
| 676 proximity_auth_ble_system_.reset( | |
| 677 new proximity_auth::ProximityAuthBleSystem( | |
| 678 proximity_auth::ScreenlockBridge::Get(), &proximity_auth_client_, | |
| 679 profile_->GetPrefs())); | |
| 680 } | |
| 681 | |
| 682 #if defined(OS_CHROMEOS) | 670 #if defined(OS_CHROMEOS) |
| 683 if (!power_monitor_) | 671 if (!power_monitor_) |
| 684 power_monitor_.reset(new PowerMonitor(this)); | 672 power_monitor_.reset(new PowerMonitor(this)); |
| 685 #endif | 673 #endif |
| 686 } else { | 674 } else { |
| 687 bool bluetooth_waking_up = false; | 675 bool bluetooth_waking_up = false; |
| 688 #if defined(OS_CHROMEOS) | 676 #if defined(OS_CHROMEOS) |
| 689 // If the service is not allowed due to bluetooth not being detected just | 677 // If the service is not allowed due to bluetooth not being detected just |
| 690 // after system suspend is done, give bluetooth more time to be detected | 678 // after system suspend is done, give bluetooth more time to be detected |
| 691 // before disabling the app (and resetting screenlock state). | 679 // before disabling the app (and resetting screenlock state). |
| 692 bluetooth_waking_up = | 680 bluetooth_waking_up = |
| 693 power_monitor_.get() && power_monitor_->waking_up() && | 681 power_monitor_.get() && power_monitor_->waking_up() && |
| 694 !bluetooth_detector_->IsPresent(); | 682 !bluetooth_detector_->IsPresent(); |
| 695 #endif | 683 #endif |
| 696 | 684 |
| 697 if (!bluetooth_waking_up) { | 685 if (!bluetooth_waking_up) { |
| 698 app_manager_->DisableAppIfLoaded(); | 686 app_manager_->DisableAppIfLoaded(); |
| 699 ResetScreenlockState(); | 687 ResetScreenlockState(); |
| 700 proximity_auth_ble_system_.reset(); | 688 proximity_auth_system_.reset(); |
| 701 #if defined(OS_CHROMEOS) | 689 #if defined(OS_CHROMEOS) |
| 702 power_monitor_.reset(); | 690 power_monitor_.reset(); |
| 703 #endif | 691 #endif |
| 704 } | 692 } |
| 705 } | 693 } |
| 706 } | 694 } |
| 707 | 695 |
| 708 void EasyUnlockService::DisableAppWithoutResettingScreenlockState() { | 696 void EasyUnlockService::DisableAppWithoutResettingScreenlockState() { |
| 709 app_manager_->DisableAppIfLoaded(); | 697 app_manager_->DisableAppIfLoaded(); |
| 710 } | 698 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 return PASSWORD_ENTRY_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH; | 820 return PASSWORD_ENTRY_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH; |
| 833 case ScreenlockState::AUTHENTICATED: | 821 case ScreenlockState::AUTHENTICATED: |
| 834 return PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE; | 822 return PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE; |
| 835 } | 823 } |
| 836 } | 824 } |
| 837 | 825 |
| 838 NOTREACHED(); | 826 NOTREACHED(); |
| 839 return EASY_UNLOCK_AUTH_EVENT_COUNT; | 827 return EASY_UNLOCK_AUTH_EVENT_COUNT; |
| 840 } | 828 } |
| 841 | 829 |
| 830 void EasyUnlockService::OnRemoteDeviceChanged( |
| 831 const proximity_auth::RemoteDevice* remote_device) { |
| 832 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 833 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) |
| 834 return; |
| 835 |
| 836 if (remote_device) { |
| 837 PA_LOG(INFO) << "Remote device changed, recreating ProximityAuthSystem."; |
| 838 proximity_auth_system_.reset(new proximity_auth::ProximityAuthSystem( |
| 839 *remote_device, proximity_auth_client())); |
| 840 proximity_auth_system_->Start(); |
| 841 } else { |
| 842 PA_LOG(INFO) << "Remote device removed, destroying ProximityAuthSystem."; |
| 843 proximity_auth_system_.reset(); |
| 844 } |
| 845 } |
| 846 |
| 842 #if defined(OS_CHROMEOS) | 847 #if defined(OS_CHROMEOS) |
| 843 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( | 848 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( |
| 844 const std::string& user_id, | 849 const std::string& user_id, |
| 845 const std::set<std::string> paired_devices, | 850 const std::set<std::string> paired_devices, |
| 846 bool success, | 851 bool success, |
| 847 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) { | 852 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) { |
| 848 DCHECK(!user_id.empty() && !paired_devices.empty()); | 853 DCHECK(!user_id.empty() && !paired_devices.empty()); |
| 849 | 854 |
| 850 if (!success) { | 855 if (!success) { |
| 851 SetHardlockStateForUser(user_id, | 856 SetHardlockStateForUser(user_id, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 865 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED | 870 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED |
| 866 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); | 871 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
| 867 } | 872 } |
| 868 } | 873 } |
| 869 #endif | 874 #endif |
| 870 | 875 |
| 871 void EasyUnlockService::PrepareForSuspend() { | 876 void EasyUnlockService::PrepareForSuspend() { |
| 872 app_manager_->DisableAppIfLoaded(); | 877 app_manager_->DisableAppIfLoaded(); |
| 873 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) | 878 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) |
| 874 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING); | 879 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING); |
| 880 if (proximity_auth_system_) |
| 881 proximity_auth_system_->OnSuspend(); |
| 882 } |
| 883 |
| 884 void EasyUnlockService::OnSuspendDone() { |
| 885 if (proximity_auth_system_) |
| 886 proximity_auth_system_->OnSuspendDone(); |
| 875 } | 887 } |
| 876 | 888 |
| 877 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { | 889 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { |
| 878 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetUserEmail().empty() || | 890 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetUserEmail().empty() || |
| 879 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { | 891 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { |
| 880 return; | 892 return; |
| 881 } | 893 } |
| 882 | 894 |
| 883 #if defined(OS_CHROMEOS) | 895 #if defined(OS_CHROMEOS) |
| 884 // If this is called before the session is started, the chances are Chrome | 896 // If this is called before the session is started, the chances are Chrome |
| 885 // is restarting in order to apply user flags. Don't check TPM keys in this | 897 // is restarting in order to apply user flags. Don't check TPM keys in this |
| 886 // case. | 898 // case. |
| 887 if (!user_manager::UserManager::Get() || | 899 if (!user_manager::UserManager::Get() || |
| 888 !user_manager::UserManager::Get()->IsSessionStarted()) | 900 !user_manager::UserManager::Get()->IsSessionStarted()) |
| 889 return; | 901 return; |
| 890 | 902 |
| 891 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | 903 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt |
| 892 // failed. | 904 // failed. |
| 893 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | 905 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) |
| 894 ->PrepareTpmKey(true /* check_private_key */, | 906 ->PrepareTpmKey(true /* check_private_key */, |
| 895 base::Closure()); | 907 base::Closure()); |
| 896 #endif // defined(OS_CHROMEOS) | 908 #endif // defined(OS_CHROMEOS) |
| 897 | 909 |
| 898 tpm_key_checked_ = true; | 910 tpm_key_checked_ = true; |
| 899 } | 911 } |
| OLD | NEW |