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