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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 42 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
43 #include "chromeos/dbus/dbus_thread_manager.h" | 43 #include "chromeos/dbus/dbus_thread_manager.h" |
44 #include "chromeos/dbus/power_manager_client.h" | 44 #include "chromeos/dbus/power_manager_client.h" |
45 #include "components/user_manager/user_manager.h" | 45 #include "components/user_manager/user_manager.h" |
46 #endif | 46 #endif |
47 | 47 |
48 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
49 #include "base/win/windows_version.h" | 49 #include "base/win/windows_version.h" |
50 #endif | 50 #endif |
51 | 51 |
| 52 using proximity_auth::ScreenlockState; |
| 53 |
52 namespace { | 54 namespace { |
53 | 55 |
54 enum BluetoothType { | 56 enum BluetoothType { |
55 BT_NO_ADAPTER, | 57 BT_NO_ADAPTER, |
56 BT_NORMAL, | 58 BT_NORMAL, |
57 BT_LOW_ENERGY_CAPABLE, | 59 BT_LOW_ENERGY_CAPABLE, |
58 BT_MAX_TYPE | 60 BT_MAX_TYPE |
59 }; | 61 }; |
60 | 62 |
61 PrefService* GetLocalState() { | 63 PrefService* GetLocalState() { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 if (!GetScreenlockStateHandler()) | 429 if (!GetScreenlockStateHandler()) |
428 return; | 430 return; |
429 | 431 |
430 EasyUnlockScreenlockStateHandler::HardlockState state; | 432 EasyUnlockScreenlockStateHandler::HardlockState state; |
431 bool has_persisted_state = GetPersistedHardlockState(&state); | 433 bool has_persisted_state = GetPersistedHardlockState(&state); |
432 if (!has_persisted_state) | 434 if (!has_persisted_state) |
433 return; | 435 return; |
434 | 436 |
435 if (state == EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { | 437 if (state == EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { |
436 // Show connecting icon early when there is a persisted non hardlock state. | 438 // Show connecting icon early when there is a persisted non hardlock state. |
437 UpdateScreenlockState( | 439 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING); |
438 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | |
439 } else { | 440 } else { |
440 screenlock_state_handler_->MaybeShowHardlockUI(); | 441 screenlock_state_handler_->MaybeShowHardlockUI(); |
441 } | 442 } |
442 } | 443 } |
443 | 444 |
444 EasyUnlockScreenlockStateHandler* | 445 EasyUnlockScreenlockStateHandler* |
445 EasyUnlockService::GetScreenlockStateHandler() { | 446 EasyUnlockService::GetScreenlockStateHandler() { |
446 if (!IsAllowed()) | 447 if (!IsAllowed()) |
447 return NULL; | 448 return NULL; |
448 if (!screenlock_state_handler_) { | 449 if (!screenlock_state_handler_) { |
449 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( | 450 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
450 GetUserEmail(), GetHardlockState(), GetScreenlockBridgeInstance())); | 451 GetUserEmail(), GetHardlockState(), GetScreenlockBridgeInstance())); |
451 } | 452 } |
452 return screenlock_state_handler_.get(); | 453 return screenlock_state_handler_.get(); |
453 } | 454 } |
454 | 455 |
455 bool EasyUnlockService::UpdateScreenlockState( | 456 bool EasyUnlockService::UpdateScreenlockState(ScreenlockState state) { |
456 EasyUnlockScreenlockStateHandler::State state) { | |
457 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); | 457 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); |
458 if (!handler) | 458 if (!handler) |
459 return false; | 459 return false; |
460 | 460 |
461 handler->ChangeState(state); | 461 handler->ChangeState(state); |
462 | 462 |
463 if (state == EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED) { | 463 if (state == ScreenlockState::AUTHENTICATED) { |
464 #if defined(OS_CHROMEOS) | 464 #if defined(OS_CHROMEOS) |
465 if (power_monitor_) | 465 if (power_monitor_) |
466 power_monitor_->RecordStartUpTime(); | 466 power_monitor_->RecordStartUpTime(); |
467 #endif | 467 #endif |
468 } else if (auth_attempt_.get()) { | 468 } else if (auth_attempt_.get()) { |
469 // Clean up existing auth attempt if we can no longer authenticate the | 469 // Clean up existing auth attempt if we can no longer authenticate the |
470 // remote device. | 470 // remote device. |
471 auth_attempt_.reset(); | 471 auth_attempt_.reset(); |
472 | 472 |
473 if (!handler->InStateValidOnRemoteAuthFailure()) | 473 if (!handler->InStateValidOnRemoteAuthFailure()) |
474 HandleAuthFailure(GetUserEmail()); | 474 HandleAuthFailure(GetUserEmail()); |
475 } | 475 } |
476 | 476 |
477 FOR_EACH_OBSERVER( | 477 FOR_EACH_OBSERVER( |
478 EasyUnlockServiceObserver, observers_, OnScreenlockStateChanged(state)); | 478 EasyUnlockServiceObserver, observers_, OnScreenlockStateChanged(state)); |
479 return true; | 479 return true; |
480 } | 480 } |
481 | 481 |
482 EasyUnlockScreenlockStateHandler::State | 482 ScreenlockState EasyUnlockService::GetScreenlockState() { |
483 EasyUnlockService::GetScreenlockState() { | |
484 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); | 483 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); |
485 if (!handler) | 484 if (!handler) |
486 return EasyUnlockScreenlockStateHandler::STATE_INACTIVE; | 485 return ScreenlockState::INACTIVE; |
487 | 486 |
488 return handler->state(); | 487 return handler->state(); |
489 } | 488 } |
490 | 489 |
491 void EasyUnlockService::AttemptAuth(const std::string& user_id) { | 490 void EasyUnlockService::AttemptAuth(const std::string& user_id) { |
492 AttemptAuth(user_id, AttemptAuthCallback()); | 491 AttemptAuth(user_id, AttemptAuthCallback()); |
493 } | 492 } |
494 | 493 |
495 void EasyUnlockService::AttemptAuth(const std::string& user_id, | 494 void EasyUnlockService::AttemptAuth(const std::string& user_id, |
496 const AttemptAuthCallback& callback) { | 495 const AttemptAuthCallback& callback) { |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 return PASSWORD_ENTRY_PAIRING_CHANGED; | 768 return PASSWORD_ENTRY_PAIRING_CHANGED; |
770 case EasyUnlockScreenlockStateHandler::LOGIN_FAILED: | 769 case EasyUnlockScreenlockStateHandler::LOGIN_FAILED: |
771 return PASSWORD_ENTRY_LOGIN_FAILED; | 770 return PASSWORD_ENTRY_LOGIN_FAILED; |
772 case EasyUnlockScreenlockStateHandler::PAIRING_ADDED: | 771 case EasyUnlockScreenlockStateHandler::PAIRING_ADDED: |
773 return PASSWORD_ENTRY_PAIRING_ADDED; | 772 return PASSWORD_ENTRY_PAIRING_ADDED; |
774 } | 773 } |
775 } else if (!screenlock_state_handler()) { | 774 } else if (!screenlock_state_handler()) { |
776 return PASSWORD_ENTRY_NO_SCREENLOCK_STATE_HANDLER; | 775 return PASSWORD_ENTRY_NO_SCREENLOCK_STATE_HANDLER; |
777 } else { | 776 } else { |
778 switch (screenlock_state_handler()->state()) { | 777 switch (screenlock_state_handler()->state()) { |
779 case EasyUnlockScreenlockStateHandler::STATE_INACTIVE: | 778 case ScreenlockState::INACTIVE: |
780 return PASSWORD_ENTRY_SERVICE_NOT_ACTIVE; | 779 return PASSWORD_ENTRY_SERVICE_NOT_ACTIVE; |
781 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: | 780 case ScreenlockState::NO_BLUETOOTH: |
782 return PASSWORD_ENTRY_NO_BLUETOOTH; | 781 return PASSWORD_ENTRY_NO_BLUETOOTH; |
783 case EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING: | 782 case ScreenlockState::BLUETOOTH_CONNECTING: |
784 return PASSWORD_ENTRY_BLUETOOTH_CONNECTING; | 783 return PASSWORD_ENTRY_BLUETOOTH_CONNECTING; |
785 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: | 784 case ScreenlockState::NO_PHONE: |
786 return PASSWORD_ENTRY_NO_PHONE; | 785 return PASSWORD_ENTRY_NO_PHONE; |
787 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: | 786 case ScreenlockState::PHONE_NOT_AUTHENTICATED: |
788 return PASSWORD_ENTRY_PHONE_NOT_AUTHENTICATED; | 787 return PASSWORD_ENTRY_PHONE_NOT_AUTHENTICATED; |
789 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: | 788 case ScreenlockState::PHONE_LOCKED: |
790 return PASSWORD_ENTRY_PHONE_LOCKED; | 789 return PASSWORD_ENTRY_PHONE_LOCKED; |
791 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: | 790 case ScreenlockState::PHONE_NOT_LOCKABLE: |
792 return PASSWORD_ENTRY_PHONE_NOT_LOCKABLE; | 791 return PASSWORD_ENTRY_PHONE_NOT_LOCKABLE; |
793 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED: | 792 case ScreenlockState::PHONE_UNSUPPORTED: |
794 return PASSWORD_ENTRY_PHONE_UNSUPPORTED; | 793 return PASSWORD_ENTRY_PHONE_UNSUPPORTED; |
795 case EasyUnlockScreenlockStateHandler::STATE_RSSI_TOO_LOW: | 794 case ScreenlockState::RSSI_TOO_LOW: |
796 return PASSWORD_ENTRY_RSSI_TOO_LOW; | 795 return PASSWORD_ENTRY_RSSI_TOO_LOW; |
797 case EasyUnlockScreenlockStateHandler::STATE_TX_POWER_TOO_HIGH: | 796 case ScreenlockState::TX_POWER_TOO_HIGH: |
798 return PASSWORD_ENTRY_TX_POWER_TOO_HIGH; | 797 return PASSWORD_ENTRY_TX_POWER_TOO_HIGH; |
799 case EasyUnlockScreenlockStateHandler:: | 798 case ScreenlockState::PHONE_LOCKED_AND_TX_POWER_TOO_HIGH: |
800 STATE_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH: | |
801 return PASSWORD_ENTRY_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH; | 799 return PASSWORD_ENTRY_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH; |
802 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: | 800 case ScreenlockState::AUTHENTICATED: |
803 return PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE; | 801 return PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE; |
804 } | 802 } |
805 } | 803 } |
806 | 804 |
807 NOTREACHED(); | 805 NOTREACHED(); |
808 return EASY_UNLOCK_AUTH_EVENT_COUNT; | 806 return EASY_UNLOCK_AUTH_EVENT_COUNT; |
809 } | 807 } |
810 | 808 |
811 #if defined(OS_CHROMEOS) | 809 #if defined(OS_CHROMEOS) |
812 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( | 810 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( |
(...skipping 19 matching lines...) Expand all Loading... |
832 user_id, | 830 user_id, |
833 devices_in_cryptohome.empty() | 831 devices_in_cryptohome.empty() |
834 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED | 832 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED |
835 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); | 833 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
836 } | 834 } |
837 } | 835 } |
838 #endif | 836 #endif |
839 | 837 |
840 void EasyUnlockService::PrepareForSuspend() { | 838 void EasyUnlockService::PrepareForSuspend() { |
841 app_manager_->DisableAppIfLoaded(); | 839 app_manager_->DisableAppIfLoaded(); |
842 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) { | 840 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) |
843 UpdateScreenlockState( | 841 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING); |
844 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | |
845 } | |
846 } | 842 } |
847 | 843 |
848 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { | 844 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { |
849 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetUserEmail().empty() || | 845 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetUserEmail().empty() || |
850 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { | 846 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { |
851 return; | 847 return; |
852 } | 848 } |
853 | 849 |
854 #if defined(OS_CHROMEOS) | 850 #if defined(OS_CHROMEOS) |
855 // If this is called before the session is started, the chances are Chrome | 851 // If this is called before the session is started, the chances are Chrome |
856 // is restarting in order to apply user flags. Don't check TPM keys in this | 852 // is restarting in order to apply user flags. Don't check TPM keys in this |
857 // case. | 853 // case. |
858 if (!user_manager::UserManager::Get() || | 854 if (!user_manager::UserManager::Get() || |
859 !user_manager::UserManager::Get()->IsSessionStarted()) | 855 !user_manager::UserManager::Get()->IsSessionStarted()) |
860 return; | 856 return; |
861 | 857 |
862 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | 858 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt |
863 // failed. | 859 // failed. |
864 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | 860 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) |
865 ->PrepareTpmKey(true /* check_private_key */, | 861 ->PrepareTpmKey(true /* check_private_key */, |
866 base::Closure()); | 862 base::Closure()); |
867 #endif // defined(OS_CHROMEOS) | 863 #endif // defined(OS_CHROMEOS) |
868 | 864 |
869 tpm_key_checked_ = true; | 865 tpm_key_checked_ = true; |
870 } | 866 } |
OLD | NEW |