tengs | a72d976 | 2014-08-29 22:56:28 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
James Hawkins | 813085e | 2018-03-30 18:56:41 | [diff] [blame] | 5 | #ifndef CHROMEOS_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H_ |
| 6 | #define CHROMEOS_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H_ |
tengs | a72d976 | 2014-08-29 22:56:28 | [diff] [blame] | 7 | |
dcheng | 2f01269 | 2016-04-21 00:19:34 | [diff] [blame] | 8 | #include <memory> |
tengs | 2ae24cbb | 2015-07-22 17:43:19 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
tengs | a72d976 | 2014-08-29 22:56:28 | [diff] [blame] | 11 | #include "base/macros.h" |
Kyle Horimoto | ffeff6a7 | 2018-12-01 02:42:06 | [diff] [blame] | 12 | #include "chromeos/components/multidevice/remote_device_ref.h" |
James Hawkins | 813085e | 2018-03-30 18:56:41 | [diff] [blame] | 13 | #include "chromeos/components/proximity_auth/screenlock_bridge.h" |
Alexander Alekseev | 3f09a8f | 2018-05-03 02:52:10 | [diff] [blame] | 14 | #include "components/account_id/account_id.h" |
tengs | a72d976 | 2014-08-29 22:56:28 | [diff] [blame] | 15 | |
Ryan Hansberry | 56292a0 | 2018-06-22 23:39:19 | [diff] [blame] | 16 | namespace chromeos { |
| 17 | namespace secure_channel { |
| 18 | class SecureChannelClient; |
| 19 | } // namespace secure_channel |
| 20 | } // namespace chromeos |
| 21 | |
tengs | a72d976 | 2014-08-29 22:56:28 | [diff] [blame] | 22 | namespace proximity_auth { |
| 23 | |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 24 | class ProximityAuthClient; |
Ryan Hansberry | 2104fb8 | 2019-07-24 03:06:37 | [diff] [blame] | 25 | class RemoteDeviceLifeCycle; |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 26 | class UnlockManager; |
tengs | 163fa44 | 2015-10-01 02:22:17 | [diff] [blame] | 27 | |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 28 | // This is the main entry point to start Proximity Auth, the underlying system |
tengs | f65903f | 2015-12-08 08:57:54 | [diff] [blame] | 29 | // for the Smart Lock feature. Given a list of remote devices (i.e. a |
| 30 | // phone) for each registered user, the system will handle the connection, |
| 31 | // authentication, and messenging protocol when the screen is locked and the |
| 32 | // registered user is focused. |
Ryan Hansberry | 2104fb8 | 2019-07-24 03:06:37 | [diff] [blame] | 33 | class ProximityAuthSystem : public ScreenlockBridge::Observer { |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 34 | public: |
tengs | a85897c2 | 2015-10-29 01:12:00 | [diff] [blame] | 35 | enum ScreenlockType { SESSION_LOCK, SIGN_IN }; |
| 36 | |
Ryan Hansberry | 56292a0 | 2018-06-22 23:39:19 | [diff] [blame] | 37 | ProximityAuthSystem( |
| 38 | ScreenlockType screenlock_type, |
| 39 | ProximityAuthClient* proximity_auth_client, |
| 40 | chromeos::secure_channel::SecureChannelClient* secure_channel_client); |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 41 | ~ProximityAuthSystem() override; |
| 42 | |
tengs | f65903f | 2015-12-08 08:57:54 | [diff] [blame] | 43 | // Starts the system to connect and authenticate when a registered user is |
| 44 | // focused on the lock/sign-in screen. |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 45 | void Start(); |
| 46 | |
tengs | f65903f | 2015-12-08 08:57:54 | [diff] [blame] | 47 | // Stops the system. |
| 48 | void Stop(); |
| 49 | |
alemate | 546380c | 2015-12-09 23:54:46 | [diff] [blame] | 50 | // Registers a list of |remote_devices| for |account_id| that can be used for |
Ryan Hansberry | 56292a0 | 2018-06-22 23:39:19 | [diff] [blame] | 51 | // sign-in/unlock. |local_device| represents this device (i.e. this Chrome OS |
| 52 | // device) for this particular user profile context. If devices were |
| 53 | // previously registered for the user, then they will be replaced. |
khorimoto | de98b9e | 2016-12-07 22:28:55 | [diff] [blame] | 54 | void SetRemoteDevicesForUser( |
| 55 | const AccountId& account_id, |
Kyle Horimoto | ffeff6a7 | 2018-12-01 02:42:06 | [diff] [blame] | 56 | const chromeos::multidevice::RemoteDeviceRefList& remote_devices, |
Anton Bikineev | a55469fa | 2021-05-15 18:01:45 | [diff] [blame] | 57 | absl::optional<chromeos::multidevice::RemoteDeviceRef> local_device); |
tengs | f65903f | 2015-12-08 08:57:54 | [diff] [blame] | 58 | |
alemate | 546380c | 2015-12-09 23:54:46 | [diff] [blame] | 59 | // Returns the RemoteDevices registered for |account_id|. Returns an empty |
| 60 | // list |
| 61 | // if no devices are registered for |account_id|. |
Kyle Horimoto | ffeff6a7 | 2018-12-01 02:42:06 | [diff] [blame] | 62 | chromeos::multidevice::RemoteDeviceRefList GetRemoteDevicesForUser( |
khorimoto | de98b9e | 2016-12-07 22:28:55 | [diff] [blame] | 63 | const AccountId& account_id) const; |
tengs | f65903f | 2015-12-08 08:57:54 | [diff] [blame] | 64 | |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 65 | // Called when the user clicks the user pod and attempts to unlock/sign-in. |
James Hawkins | e492815 | 2019-11-25 18:21:26 | [diff] [blame] | 66 | void OnAuthAttempted(); |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 67 | |
| 68 | // Called when the system suspends. |
| 69 | void OnSuspend(); |
| 70 | |
| 71 | // Called when the system wakes up from a suspended state. |
| 72 | void OnSuspendDone(); |
tengs | a72d976 | 2014-08-29 22:56:28 | [diff] [blame] | 73 | |
Regan Hsu | 53001b7 | 2018-11-27 18:14:48 | [diff] [blame] | 74 | // Called in order to disable attempts to get RemoteStatus from host devices. |
| 75 | void CancelConnectionAttempt(); |
| 76 | |
Curt Clemens | 6b6173f | 2021-08-12 20:56:23 | [diff] [blame] | 77 | // The last value emitted to the SmartLock.GetRemoteStatus.Unlock(.Failure) |
| 78 | // metrics. Helps to understand whether/why not Smart Lock was an available |
| 79 | // choice for unlock. Returns the empty string if |unlock_manager_| is |
| 80 | // nullptr. |
| 81 | std::string GetLastRemoteStatusUnlockForLogging(); |
| 82 | |
tengs | 9fc34de2 | 2017-04-04 23:49:13 | [diff] [blame] | 83 | protected: |
| 84 | // Constructor which allows passing in a custom |unlock_manager_|. |
| 85 | // Exposed for testing. |
Ryan Hansberry | 56292a0 | 2018-06-22 23:39:19 | [diff] [blame] | 86 | ProximityAuthSystem( |
Ryan Hansberry | 56292a0 | 2018-06-22 23:39:19 | [diff] [blame] | 87 | chromeos::secure_channel::SecureChannelClient* secure_channel_client, |
James Hawkins | b5469b5be | 2018-11-10 02:15:01 | [diff] [blame] | 88 | std::unique_ptr<UnlockManager> unlock_manager); |
tengs | 9fc34de2 | 2017-04-04 23:49:13 | [diff] [blame] | 89 | |
Ryan Hansberry | 56292a0 | 2018-06-22 23:39:19 | [diff] [blame] | 90 | // Creates the RemoteDeviceLifeCycle for |remote_device| and |local_device|. |
| 91 | // |remote_device| is the host intended to be connected to, and |local_device| |
| 92 | // represents this device (i.e. this Chrome OS device) for this particular |
| 93 | // user profile context. |
tengs | 9fc34de2 | 2017-04-04 23:49:13 | [diff] [blame] | 94 | // Exposed for testing. |
| 95 | virtual std::unique_ptr<RemoteDeviceLifeCycle> CreateRemoteDeviceLifeCycle( |
Kyle Horimoto | ffeff6a7 | 2018-12-01 02:42:06 | [diff] [blame] | 96 | chromeos::multidevice::RemoteDeviceRef remote_device, |
Anton Bikineev | a55469fa | 2021-05-15 18:01:45 | [diff] [blame] | 97 | absl::optional<chromeos::multidevice::RemoteDeviceRef> local_device); |
tengs | 9fc34de2 | 2017-04-04 23:49:13 | [diff] [blame] | 98 | |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 99 | // ScreenlockBridge::Observer: |
| 100 | void OnScreenDidLock( |
| 101 | ScreenlockBridge::LockHandler::ScreenType screen_type) override; |
| 102 | void OnScreenDidUnlock( |
| 103 | ScreenlockBridge::LockHandler::ScreenType screen_type) override; |
alemate | 546380c | 2015-12-09 23:54:46 | [diff] [blame] | 104 | void OnFocusedUserChanged(const AccountId& account_id) override; |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 105 | |
tengs | 9fc34de2 | 2017-04-04 23:49:13 | [diff] [blame] | 106 | private: |
alemate | 546380c | 2015-12-09 23:54:46 | [diff] [blame] | 107 | // Lists of remote devices, keyed by user account id. |
Kyle Horimoto | ffeff6a7 | 2018-12-01 02:42:06 | [diff] [blame] | 108 | std::map<AccountId, chromeos::multidevice::RemoteDeviceRefList> |
| 109 | remote_devices_map_; |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 110 | |
Ryan Hansberry | 56292a0 | 2018-06-22 23:39:19 | [diff] [blame] | 111 | // A mapping from each profile's account ID to the profile-specific |
| 112 | // representation of this device (i.e. this Chrome OS device) for that |
| 113 | // particular user profile. |
Kyle Horimoto | ffeff6a7 | 2018-12-01 02:42:06 | [diff] [blame] | 114 | std::map<AccountId, chromeos::multidevice::RemoteDeviceRef> local_device_map_; |
Ryan Hansberry | 56292a0 | 2018-06-22 23:39:19 | [diff] [blame] | 115 | |
Ryan Hansberry | 56292a0 | 2018-06-22 23:39:19 | [diff] [blame] | 116 | // Entry point to the SecureChannel API. |
| 117 | chromeos::secure_channel::SecureChannelClient* secure_channel_client_; |
| 118 | |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 119 | // Responsible for the life cycle of connecting and authenticating to |
tengs | f65903f | 2015-12-08 08:57:54 | [diff] [blame] | 120 | // the RemoteDevice of the currently focused user. |
dcheng | 2f01269 | 2016-04-21 00:19:34 | [diff] [blame] | 121 | std::unique_ptr<RemoteDeviceLifeCycle> remote_device_life_cycle_; |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 122 | |
sacomoto | 474f53b | 2017-07-18 22:37:02 | [diff] [blame] | 123 | // Handles the interaction with the lock screen UI. |
| 124 | std::unique_ptr<UnlockManager> unlock_manager_; |
| 125 | |
tengs | ae50e97 | 2015-10-02 04:00:40 | [diff] [blame] | 126 | // True if the system is suspended. |
| 127 | bool suspended_; |
| 128 | |
tengs | f65903f | 2015-12-08 08:57:54 | [diff] [blame] | 129 | // True if the system is started_. |
| 130 | bool started_; |
| 131 | |
tengs | a72d976 | 2014-08-29 22:56:28 | [diff] [blame] | 132 | DISALLOW_COPY_AND_ASSIGN(ProximityAuthSystem); |
| 133 | }; |
| 134 | |
| 135 | } // namespace proximity_auth |
| 136 | |
James Hawkins | 813085e | 2018-03-30 18:56:41 | [diff] [blame] | 137 | #endif // CHROMEOS_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_SYSTEM_H_ |