Commit 56292a0c authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

[CrOS Multidevice] Integrate SecureChannel API into ProximityAuthSystem.

Inject a SecureChannelClient and RemoteDeviceRef (representing the
local device) into ProximityAuthSystem, which are required by
RemoteDeviceLifeCycle in order to establish a secure connection to
a remote device.

R=jhawkins@chromium.org, khorimoto@chromium.org

Bug: 824568, 752273
Change-Id: Iab717e9b9a9d1e992da661406d4d8ddd233c2d6d
Reviewed-on: https://chromium-review.googlesource.com/1109505
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarJames Hawkins <jhawkins@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569841}
parent 25fee261
...@@ -670,7 +670,8 @@ EasyUnlockAuthEvent EasyUnlockService::GetPasswordAuthEvent() const { ...@@ -670,7 +670,8 @@ EasyUnlockAuthEvent EasyUnlockService::GetPasswordAuthEvent() const {
void EasyUnlockService::SetProximityAuthDevices( void EasyUnlockService::SetProximityAuthDevices(
const AccountId& account_id, const AccountId& account_id,
const cryptauth::RemoteDeviceRefList& remote_devices) { const cryptauth::RemoteDeviceRefList& remote_devices,
base::Optional<cryptauth::RemoteDeviceRef> local_device) {
UMA_HISTOGRAM_COUNTS_100("SmartLock.EnabledDevicesCount", UMA_HISTOGRAM_COUNTS_100("SmartLock.EnabledDevicesCount",
remote_devices.size()); remote_devices.size());
...@@ -681,14 +682,16 @@ void EasyUnlockService::SetProximityAuthDevices( ...@@ -681,14 +682,16 @@ void EasyUnlockService::SetProximityAuthDevices(
if (!proximity_auth_system_) { if (!proximity_auth_system_) {
PA_LOG(INFO) << "Creating ProximityAuthSystem."; PA_LOG(INFO) << "Creating ProximityAuthSystem.";
// TODO(crbug.com/752273): Inject a real secure_channel_client.
proximity_auth_system_.reset(new proximity_auth::ProximityAuthSystem( proximity_auth_system_.reset(new proximity_auth::ProximityAuthSystem(
GetType() == TYPE_SIGNIN GetType() == TYPE_SIGNIN
? proximity_auth::ProximityAuthSystem::SIGN_IN ? proximity_auth::ProximityAuthSystem::SIGN_IN
: proximity_auth::ProximityAuthSystem::SESSION_LOCK, : proximity_auth::ProximityAuthSystem::SESSION_LOCK,
proximity_auth_client())); proximity_auth_client(), nullptr /* secure_channel_client */));
} }
proximity_auth_system_->SetRemoteDevicesForUser(account_id, remote_devices); proximity_auth_system_->SetRemoteDevicesForUser(account_id, remote_devices,
local_device);
proximity_auth_system_->Start(); proximity_auth_system_->Start();
} }
......
...@@ -268,7 +268,8 @@ class EasyUnlockService : public KeyedService { ...@@ -268,7 +268,8 @@ class EasyUnlockService : public KeyedService {
// are loaded for |account_id|. // are loaded for |account_id|.
void SetProximityAuthDevices( void SetProximityAuthDevices(
const AccountId& account_id, const AccountId& account_id,
const cryptauth::RemoteDeviceRefList& remote_devices); const cryptauth::RemoteDeviceRefList& remote_devices,
base::Optional<cryptauth::RemoteDeviceRef> local_device);
private: private:
// A class to detect whether a bluetooth adapter is present. // A class to detect whether a bluetooth adapter is present.
......
...@@ -173,7 +173,8 @@ void EasyUnlockServiceRegular::LoadRemoteDevices() { ...@@ -173,7 +173,8 @@ void EasyUnlockServiceRegular::LoadRemoteDevices() {
pref_manager_->SetEasyUnlockEnabledStateSet(); pref_manager_->SetEasyUnlockEnabledStateSet();
LogSmartLockEnabledState(SmartLockEnabledState::ENABLED); LogSmartLockEnabledState(SmartLockEnabledState::ENABLED);
} else { } else {
SetProximityAuthDevices(GetAccountId(), cryptauth::RemoteDeviceRefList()); SetProximityAuthDevices(GetAccountId(), cryptauth::RemoteDeviceRefList(),
base::nullopt /* local_device */);
if (pref_manager_->IsEasyUnlockEnabledStateSet()) { if (pref_manager_->IsEasyUnlockEnabledStateSet()) {
LogSmartLockEnabledState(SmartLockEnabledState::DISABLED); LogSmartLockEnabledState(SmartLockEnabledState::DISABLED);
...@@ -224,7 +225,11 @@ void EasyUnlockServiceRegular::OnRemoteDevicesLoaded( ...@@ -224,7 +225,11 @@ void EasyUnlockServiceRegular::OnRemoteDevicesLoaded(
void EasyUnlockServiceRegular::UseLoadedRemoteDevices( void EasyUnlockServiceRegular::UseLoadedRemoteDevices(
const cryptauth::RemoteDeviceRefList& remote_devices) { const cryptauth::RemoteDeviceRefList& remote_devices) {
SetProximityAuthDevices(GetAccountId(), remote_devices); SetProximityAuthDevices(
GetAccountId(), remote_devices,
base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)
? device_sync_client_->GetLocalDeviceMetadata()
: base::nullopt);
// We need to store a copy of |remote devices_| in the TPM, so it can be // We need to store a copy of |remote devices_| in the TPM, so it can be
// retrieved on the sign-in screen when a user session has not been started // retrieved on the sign-in screen when a user session has not been started
...@@ -739,7 +744,8 @@ void EasyUnlockServiceRegular::OnTurnOffEasyUnlockSuccess() { ...@@ -739,7 +744,8 @@ void EasyUnlockServiceRegular::OnTurnOffEasyUnlockSuccess() {
EasyUnlockService::ResetLocalStateForUser(GetAccountId()); EasyUnlockService::ResetLocalStateForUser(GetAccountId());
SetRemoteDevices(base::ListValue()); SetRemoteDevices(base::ListValue());
SetProximityAuthDevices(GetAccountId(), cryptauth::RemoteDeviceRefList()); SetProximityAuthDevices(GetAccountId(), cryptauth::RemoteDeviceRefList(),
base::nullopt /* local_device */);
pref_manager_->SetIsEasyUnlockEnabled(false); pref_manager_->SetIsEasyUnlockEnabled(false);
SetTurnOffFlowStatus(IDLE); SetTurnOffFlowStatus(IDLE);
ResetScreenlockState(); ResetScreenlockState();
......
...@@ -404,7 +404,8 @@ void EasyUnlockServiceSignin::OnFocusedUserChanged( ...@@ -404,7 +404,8 @@ void EasyUnlockServiceSignin::OnFocusedUserChanged(
account_id_ = account_id; account_id_ = account_id;
pref_manager_->SetActiveUser(account_id); pref_manager_->SetActiveUser(account_id);
user_pod_last_focused_timestamp_ = base::TimeTicks::Now(); user_pod_last_focused_timestamp_ = base::TimeTicks::Now();
SetProximityAuthDevices(account_id_, cryptauth::RemoteDeviceRefList()); SetProximityAuthDevices(account_id_, cryptauth::RemoteDeviceRefList(),
base::nullopt /* local_device */);
ResetScreenlockState(); ResetScreenlockState();
pref_manager_->SetActiveUser(account_id); pref_manager_->SetActiveUser(account_id);
...@@ -538,7 +539,9 @@ void EasyUnlockServiceSignin::OnUserDataLoaded( ...@@ -538,7 +539,9 @@ void EasyUnlockServiceSignin::OnUserDataLoaded(
remote_device_cache_->SetRemoteDevices(remote_devices); remote_device_cache_->SetRemoteDevices(remote_devices);
SetProximityAuthDevices(account_id, remote_device_cache_->GetRemoteDevices()); // TODO(crbug.com/752273): Inject a real local device.
SetProximityAuthDevices(account_id, remote_device_cache_->GetRemoteDevices(),
base::nullopt /* local_device */);
} }
const EasyUnlockServiceSignin::UserData* const EasyUnlockServiceSignin::UserData*
......
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
namespace proximity_auth { namespace proximity_auth {
FakeRemoteDeviceLifeCycle::FakeRemoteDeviceLifeCycle( FakeRemoteDeviceLifeCycle::FakeRemoteDeviceLifeCycle(
cryptauth::RemoteDeviceRef remote_device) cryptauth::RemoteDeviceRef remote_device,
base::Optional<cryptauth::RemoteDeviceRef> local_device)
: remote_device_(remote_device), : remote_device_(remote_device),
local_device_(local_device),
started_(false), started_(false),
state_(RemoteDeviceLifeCycle::State::STOPPED) {} state_(RemoteDeviceLifeCycle::State::STOPPED) {}
......
...@@ -16,7 +16,9 @@ namespace proximity_auth { ...@@ -16,7 +16,9 @@ namespace proximity_auth {
class FakeRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle { class FakeRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle {
public: public:
explicit FakeRemoteDeviceLifeCycle(cryptauth::RemoteDeviceRef remote_device); explicit FakeRemoteDeviceLifeCycle(
cryptauth::RemoteDeviceRef remote_device,
base::Optional<cryptauth::RemoteDeviceRef> local_device);
~FakeRemoteDeviceLifeCycle() override; ~FakeRemoteDeviceLifeCycle() override;
// RemoteDeviceLifeCycle: // RemoteDeviceLifeCycle:
...@@ -44,10 +46,13 @@ class FakeRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle { ...@@ -44,10 +46,13 @@ class FakeRemoteDeviceLifeCycle : public RemoteDeviceLifeCycle {
bool started() { return started_; } bool started() { return started_; }
cryptauth::RemoteDeviceRef local_device() { return *local_device_; }
base::ObserverList<Observer>& observers() { return observers_; } base::ObserverList<Observer>& observers() { return observers_; }
private: private:
cryptauth::RemoteDeviceRef remote_device_; cryptauth::RemoteDeviceRef remote_device_;
base::Optional<cryptauth::RemoteDeviceRef> local_device_;
base::ObserverList<Observer> observers_; base::ObserverList<Observer> observers_;
bool started_; bool started_;
State state_; State state_;
......
...@@ -6,20 +6,24 @@ ...@@ -6,20 +6,24 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/components/proximity_auth/logging/logging.h" #include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/proximity_auth/proximity_auth_client.h" #include "chromeos/components/proximity_auth/proximity_auth_client.h"
#include "chromeos/components/proximity_auth/proximity_auth_profile_pref_manager.h" #include "chromeos/components/proximity_auth/proximity_auth_profile_pref_manager.h"
#include "chromeos/components/proximity_auth/remote_device_life_cycle_impl.h" #include "chromeos/components/proximity_auth/remote_device_life_cycle_impl.h"
#include "chromeos/components/proximity_auth/switches.h" #include "chromeos/components/proximity_auth/switches.h"
#include "chromeos/components/proximity_auth/unlock_manager_impl.h" #include "chromeos/components/proximity_auth/unlock_manager_impl.h"
#include "chromeos/services/secure_channel/public/cpp/client/secure_channel_client.h"
namespace proximity_auth { namespace proximity_auth {
ProximityAuthSystem::ProximityAuthSystem( ProximityAuthSystem::ProximityAuthSystem(
ScreenlockType screenlock_type, ScreenlockType screenlock_type,
ProximityAuthClient* proximity_auth_client) ProximityAuthClient* proximity_auth_client,
chromeos::secure_channel::SecureChannelClient* secure_channel_client)
: screenlock_type_(screenlock_type), : screenlock_type_(screenlock_type),
proximity_auth_client_(proximity_auth_client), proximity_auth_client_(proximity_auth_client),
secure_channel_client_(secure_channel_client),
pref_manager_(proximity_auth_client->GetPrefManager()), pref_manager_(proximity_auth_client->GetPrefManager()),
unlock_manager_(new UnlockManagerImpl(screenlock_type, unlock_manager_(new UnlockManagerImpl(screenlock_type,
proximity_auth_client_, proximity_auth_client_,
...@@ -31,10 +35,12 @@ ProximityAuthSystem::ProximityAuthSystem( ...@@ -31,10 +35,12 @@ ProximityAuthSystem::ProximityAuthSystem(
ProximityAuthSystem::ProximityAuthSystem( ProximityAuthSystem::ProximityAuthSystem(
ScreenlockType screenlock_type, ScreenlockType screenlock_type,
ProximityAuthClient* proximity_auth_client, ProximityAuthClient* proximity_auth_client,
chromeos::secure_channel::SecureChannelClient* secure_channel_client,
std::unique_ptr<UnlockManager> unlock_manager, std::unique_ptr<UnlockManager> unlock_manager,
ProximityAuthPrefManager* pref_manager) ProximityAuthPrefManager* pref_manager)
: screenlock_type_(screenlock_type), : screenlock_type_(screenlock_type),
proximity_auth_client_(proximity_auth_client), proximity_auth_client_(proximity_auth_client),
secure_channel_client_(secure_channel_client),
pref_manager_(pref_manager), pref_manager_(pref_manager),
unlock_manager_(std::move(unlock_manager)), unlock_manager_(std::move(unlock_manager)),
suspended_(false), suspended_(false),
...@@ -67,8 +73,12 @@ void ProximityAuthSystem::Stop() { ...@@ -67,8 +73,12 @@ void ProximityAuthSystem::Stop() {
void ProximityAuthSystem::SetRemoteDevicesForUser( void ProximityAuthSystem::SetRemoteDevicesForUser(
const AccountId& account_id, const AccountId& account_id,
const cryptauth::RemoteDeviceRefList& remote_devices) { const cryptauth::RemoteDeviceRefList& remote_devices,
base::Optional<cryptauth::RemoteDeviceRef> local_device) {
remote_devices_map_[account_id] = remote_devices; remote_devices_map_[account_id] = remote_devices;
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi))
local_device_map_.emplace(account_id, *local_device);
if (started_) { if (started_) {
const AccountId& focused_account_id = const AccountId& focused_account_id =
ScreenlockBridge::Get()->focused_account_id(); ScreenlockBridge::Get()->focused_account_id();
...@@ -113,11 +123,10 @@ void ProximityAuthSystem::OnSuspendDone() { ...@@ -113,11 +123,10 @@ void ProximityAuthSystem::OnSuspendDone() {
std::unique_ptr<RemoteDeviceLifeCycle> std::unique_ptr<RemoteDeviceLifeCycle>
ProximityAuthSystem::CreateRemoteDeviceLifeCycle( ProximityAuthSystem::CreateRemoteDeviceLifeCycle(
cryptauth::RemoteDeviceRef remote_device) { cryptauth::RemoteDeviceRef remote_device,
// TODO(crbug.com/752273): Inject a real local device and SecureChannelClient. base::Optional<cryptauth::RemoteDeviceRef> local_device) {
return std::make_unique<RemoteDeviceLifeCycleImpl>( return std::make_unique<RemoteDeviceLifeCycleImpl>(
remote_device, base::nullopt /* local_device */, remote_device, local_device, secure_channel_client_);
nullptr /* secure_channel_client */);
} }
void ProximityAuthSystem::OnLifeCycleStateChanged( void ProximityAuthSystem::OnLifeCycleStateChanged(
...@@ -158,17 +167,29 @@ void ProximityAuthSystem::OnFocusedUserChanged(const AccountId& account_id) { ...@@ -158,17 +167,29 @@ void ProximityAuthSystem::OnFocusedUserChanged(const AccountId& account_id) {
if (remote_devices_map_.find(account_id) == remote_devices_map_.end() || if (remote_devices_map_.find(account_id) == remote_devices_map_.end() ||
remote_devices_map_[account_id].size() == 0) { remote_devices_map_[account_id].size() == 0) {
PA_LOG(INFO) << "User " << account_id.Serialize() PA_LOG(INFO) << "User " << account_id.Serialize()
<< " does not have a RemoteDevice."; << " does not have a Smart Lock host device.";
return;
}
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi) &&
local_device_map_.find(account_id) == local_device_map_.end()) {
PA_LOG(INFO) << "User " << account_id.Serialize()
<< " does not have a local device.";
return; return;
} }
// TODO(tengs): We currently assume each user has only one RemoteDevice, so we // TODO(tengs): We currently assume each user has only one RemoteDevice, so we
// can simply take the first item in the list. // can simply take the first item in the list.
cryptauth::RemoteDeviceRef remote_device = remote_devices_map_[account_id][0]; cryptauth::RemoteDeviceRef remote_device = remote_devices_map_[account_id][0];
base::Optional<cryptauth::RemoteDeviceRef> local_device;
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi))
local_device = local_device_map_.at(account_id);
if (!suspended_) { if (!suspended_) {
PA_LOG(INFO) << "Creating RemoteDeviceLifeCycle for focused user: " PA_LOG(INFO) << "Creating RemoteDeviceLifeCycle for focused user: "
<< account_id.Serialize(); << account_id.Serialize();
remote_device_life_cycle_ = CreateRemoteDeviceLifeCycle(remote_device); remote_device_life_cycle_ =
CreateRemoteDeviceLifeCycle(remote_device, local_device);
unlock_manager_->SetRemoteDeviceLifeCycle(remote_device_life_cycle_.get()); unlock_manager_->SetRemoteDeviceLifeCycle(remote_device_life_cycle_.get());
remote_device_life_cycle_->AddObserver(this); remote_device_life_cycle_->AddObserver(this);
remote_device_life_cycle_->Start(); remote_device_life_cycle_->Start();
......
...@@ -16,6 +16,12 @@ ...@@ -16,6 +16,12 @@
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/cryptauth/remote_device_ref.h" #include "components/cryptauth/remote_device_ref.h"
namespace chromeos {
namespace secure_channel {
class SecureChannelClient;
} // namespace secure_channel
} // namespace chromeos
namespace proximity_auth { namespace proximity_auth {
class ProximityAuthClient; class ProximityAuthClient;
...@@ -33,8 +39,10 @@ class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer, ...@@ -33,8 +39,10 @@ class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer,
public: public:
enum ScreenlockType { SESSION_LOCK, SIGN_IN }; enum ScreenlockType { SESSION_LOCK, SIGN_IN };
ProximityAuthSystem(ScreenlockType screenlock_type, ProximityAuthSystem(
ProximityAuthClient* proximity_auth_client); ScreenlockType screenlock_type,
ProximityAuthClient* proximity_auth_client,
chromeos::secure_channel::SecureChannelClient* secure_channel_client);
~ProximityAuthSystem() override; ~ProximityAuthSystem() override;
// Starts the system to connect and authenticate when a registered user is // Starts the system to connect and authenticate when a registered user is
...@@ -45,11 +53,13 @@ class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer, ...@@ -45,11 +53,13 @@ class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer,
void Stop(); void Stop();
// Registers a list of |remote_devices| for |account_id| that can be used for // Registers a list of |remote_devices| for |account_id| that can be used for
// sign-in/unlock. If devices were previously registered for the user, then // sign-in/unlock. |local_device| represents this device (i.e. this Chrome OS
// they will be replaced. // device) for this particular user profile context. If devices were
// previously registered for the user, then they will be replaced.
void SetRemoteDevicesForUser( void SetRemoteDevicesForUser(
const AccountId& account_id, const AccountId& account_id,
const cryptauth::RemoteDeviceRefList& remote_devices); const cryptauth::RemoteDeviceRefList& remote_devices,
base::Optional<cryptauth::RemoteDeviceRef> local_device);
// Returns the RemoteDevices registered for |account_id|. Returns an empty // Returns the RemoteDevices registered for |account_id|. Returns an empty
// list // list
...@@ -69,15 +79,21 @@ class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer, ...@@ -69,15 +79,21 @@ class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer,
protected: protected:
// Constructor which allows passing in a custom |unlock_manager_|. // Constructor which allows passing in a custom |unlock_manager_|.
// Exposed for testing. // Exposed for testing.
ProximityAuthSystem(ScreenlockType screenlock_type, ProximityAuthSystem(
ProximityAuthClient* proximity_auth_client, ScreenlockType screenlock_type,
std::unique_ptr<UnlockManager> unlock_manager, ProximityAuthClient* proximity_auth_client,
ProximityAuthPrefManager* pref_manager); chromeos::secure_channel::SecureChannelClient* secure_channel_client,
std::unique_ptr<UnlockManager> unlock_manager,
// Creates the RemoteDeviceLifeCycle for |remote_device|. ProximityAuthPrefManager* pref_manager);
// Creates the RemoteDeviceLifeCycle for |remote_device| and |local_device|.
// |remote_device| is the host intended to be connected to, and |local_device|
// represents this device (i.e. this Chrome OS device) for this particular
// user profile context.
// Exposed for testing. // Exposed for testing.
virtual std::unique_ptr<RemoteDeviceLifeCycle> CreateRemoteDeviceLifeCycle( virtual std::unique_ptr<RemoteDeviceLifeCycle> CreateRemoteDeviceLifeCycle(
cryptauth::RemoteDeviceRef remote_device); cryptauth::RemoteDeviceRef remote_device,
base::Optional<cryptauth::RemoteDeviceRef> local_device);
// RemoteDeviceLifeCycle::Observer: // RemoteDeviceLifeCycle::Observer:
void OnLifeCycleStateChanged(RemoteDeviceLifeCycle::State old_state, void OnLifeCycleStateChanged(RemoteDeviceLifeCycle::State old_state,
...@@ -101,9 +117,17 @@ class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer, ...@@ -101,9 +117,17 @@ class ProximityAuthSystem : public RemoteDeviceLifeCycle::Observer,
// Lists of remote devices, keyed by user account id. // Lists of remote devices, keyed by user account id.
std::map<AccountId, cryptauth::RemoteDeviceRefList> remote_devices_map_; std::map<AccountId, cryptauth::RemoteDeviceRefList> remote_devices_map_;
// A mapping from each profile's account ID to the profile-specific
// representation of this device (i.e. this Chrome OS device) for that
// particular user profile.
std::map<AccountId, cryptauth::RemoteDeviceRef> local_device_map_;
// Delegate for Chrome dependent functionality. // Delegate for Chrome dependent functionality.
ProximityAuthClient* proximity_auth_client_; ProximityAuthClient* proximity_auth_client_;
// Entry point to the SecureChannel API.
chromeos::secure_channel::SecureChannelClient* secure_channel_client_;
// Responsible for the life cycle of connecting and authenticating to // Responsible for the life cycle of connecting and authenticating to
// the RemoteDevice of the currently focused user. // the RemoteDevice of the currently focused user.
std::unique_ptr<RemoteDeviceLifeCycle> remote_device_life_cycle_; std::unique_ptr<RemoteDeviceLifeCycle> remote_device_life_cycle_;
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#include "chromeos/components/proximity_auth/proximity_auth_system.h" #include "chromeos/components/proximity_auth/proximity_auth_system.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_simple_task_runner.h" #include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/components/proximity_auth/fake_lock_handler.h" #include "chromeos/components/proximity_auth/fake_lock_handler.h"
#include "chromeos/components/proximity_auth/fake_remote_device_life_cycle.h" #include "chromeos/components/proximity_auth/fake_remote_device_life_cycle.h"
#include "chromeos/components/proximity_auth/logging/logging.h" #include "chromeos/components/proximity_auth/logging/logging.h"
...@@ -14,6 +16,7 @@ ...@@ -14,6 +16,7 @@
#include "chromeos/components/proximity_auth/proximity_auth_profile_pref_manager.h" #include "chromeos/components/proximity_auth/proximity_auth_profile_pref_manager.h"
#include "chromeos/components/proximity_auth/switches.h" #include "chromeos/components/proximity_auth/switches.h"
#include "chromeos/components/proximity_auth/unlock_manager.h" #include "chromeos/components/proximity_auth/unlock_manager.h"
#include "chromeos/services/secure_channel/public/cpp/client/fake_secure_channel_client.h"
#include "components/cryptauth/remote_device_ref.h" #include "components/cryptauth/remote_device_ref.h"
#include "components/cryptauth/remote_device_test_util.h" #include "components/cryptauth/remote_device_test_util.h"
#include "components/cryptauth/software_feature_state.h" #include "components/cryptauth/software_feature_state.h"
...@@ -85,12 +88,15 @@ class MockProximityAuthPrefManager : public ProximityAuthProfilePrefManager { ...@@ -85,12 +88,15 @@ class MockProximityAuthPrefManager : public ProximityAuthProfilePrefManager {
// Harness for ProximityAuthSystem to make it testable. // Harness for ProximityAuthSystem to make it testable.
class TestableProximityAuthSystem : public ProximityAuthSystem { class TestableProximityAuthSystem : public ProximityAuthSystem {
public: public:
TestableProximityAuthSystem(ScreenlockType screenlock_type, TestableProximityAuthSystem(
ProximityAuthClient* proximity_auth_client, ScreenlockType screenlock_type,
std::unique_ptr<UnlockManager> unlock_manager, ProximityAuthClient* proximity_auth_client,
ProximityAuthPrefManager* pref_manager) chromeos::secure_channel::SecureChannelClient* secure_channel_client,
std::unique_ptr<UnlockManager> unlock_manager,
ProximityAuthPrefManager* pref_manager)
: ProximityAuthSystem(screenlock_type, : ProximityAuthSystem(screenlock_type,
proximity_auth_client, proximity_auth_client,
secure_channel_client,
std::move(unlock_manager), std::move(unlock_manager),
pref_manager), pref_manager),
life_cycle_(nullptr) {} life_cycle_(nullptr) {}
...@@ -100,9 +106,10 @@ class TestableProximityAuthSystem : public ProximityAuthSystem { ...@@ -100,9 +106,10 @@ class TestableProximityAuthSystem : public ProximityAuthSystem {
private: private:
std::unique_ptr<RemoteDeviceLifeCycle> CreateRemoteDeviceLifeCycle( std::unique_ptr<RemoteDeviceLifeCycle> CreateRemoteDeviceLifeCycle(
cryptauth::RemoteDeviceRef remote_device) override { cryptauth::RemoteDeviceRef remote_device,
base::Optional<cryptauth::RemoteDeviceRef> local_device) override {
std::unique_ptr<FakeRemoteDeviceLifeCycle> life_cycle( std::unique_ptr<FakeRemoteDeviceLifeCycle> life_cycle(
new FakeRemoteDeviceLifeCycle(remote_device)); new FakeRemoteDeviceLifeCycle(remote_device, local_device));
life_cycle_ = life_cycle.get(); life_cycle_ = life_cycle.get();
return std::move(life_cycle); return std::move(life_cycle);
} }
...@@ -118,6 +125,8 @@ class ProximityAuthSystemTest : public testing::Test { ...@@ -118,6 +125,8 @@ class ProximityAuthSystemTest : public testing::Test {
protected: protected:
ProximityAuthSystemTest() ProximityAuthSystemTest()
: pref_manager_(new NiceMock<MockProximityAuthPrefManager>()), : pref_manager_(new NiceMock<MockProximityAuthPrefManager>()),
user1_local_device_(CreateRemoteDevice(kUser1, "user1_local_device")),
user2_local_device_(CreateRemoteDevice(kUser2, "user2_local_device")),
task_runner_(new base::TestSimpleTaskRunner()), task_runner_(new base::TestSimpleTaskRunner()),
thread_task_runner_handle_(task_runner_) {} thread_task_runner_handle_(task_runner_) {}
...@@ -136,21 +145,30 @@ class ProximityAuthSystemTest : public testing::Test { ...@@ -136,21 +145,30 @@ class ProximityAuthSystemTest : public testing::Test {
InitProximityAuthSystem(ProximityAuthSystem::SESSION_LOCK); InitProximityAuthSystem(ProximityAuthSystem::SESSION_LOCK);
proximity_auth_system_->SetRemoteDevicesForUser( proximity_auth_system_->SetRemoteDevicesForUser(
AccountId::FromUserEmail(kUser1), user1_remote_devices_); AccountId::FromUserEmail(kUser1), user1_remote_devices_,
user1_local_device_);
proximity_auth_system_->Start(); proximity_auth_system_->Start();
LockScreen(); LockScreen();
} }
void TearDown() override { UnlockScreen(); } void TearDown() override { UnlockScreen(); }
void SetMultiDeviceApiEnabled() {
scoped_feature_list_.InitAndEnableFeature(
chromeos::features::kMultiDeviceApi);
}
void InitProximityAuthSystem(ProximityAuthSystem::ScreenlockType type) { void InitProximityAuthSystem(ProximityAuthSystem::ScreenlockType type) {
std::unique_ptr<MockUnlockManager> unlock_manager( std::unique_ptr<MockUnlockManager> unlock_manager(
new NiceMock<MockUnlockManager>()); new NiceMock<MockUnlockManager>());
unlock_manager_ = unlock_manager.get(); unlock_manager_ = unlock_manager.get();
fake_secure_channel_client_ =
std::make_unique<chromeos::secure_channel::FakeSecureChannelClient>();
proximity_auth_system_.reset(new TestableProximityAuthSystem( proximity_auth_system_.reset(new TestableProximityAuthSystem(
type, &proximity_auth_client_, std::move(unlock_manager), type, &proximity_auth_client_, fake_secure_channel_client_.get(),
pref_manager_.get())); std::move(unlock_manager), pref_manager_.get()));
} }
void LockScreen() { void LockScreen() {
...@@ -176,18 +194,24 @@ class ProximityAuthSystemTest : public testing::Test { ...@@ -176,18 +194,24 @@ class ProximityAuthSystemTest : public testing::Test {
FakeLockHandler lock_handler_; FakeLockHandler lock_handler_;
NiceMock<MockProximityAuthClient> proximity_auth_client_; NiceMock<MockProximityAuthClient> proximity_auth_client_;
std::unique_ptr<chromeos::secure_channel::FakeSecureChannelClient>
fake_secure_channel_client_;
std::unique_ptr<TestableProximityAuthSystem> proximity_auth_system_; std::unique_ptr<TestableProximityAuthSystem> proximity_auth_system_;
MockUnlockManager* unlock_manager_; MockUnlockManager* unlock_manager_;
std::unique_ptr<MockProximityAuthPrefManager> pref_manager_; std::unique_ptr<MockProximityAuthPrefManager> pref_manager_;
RemoteDeviceRefList user1_remote_devices_; cryptauth::RemoteDeviceRef user1_local_device_;
RemoteDeviceRefList user2_remote_devices_; cryptauth::RemoteDeviceRef user2_local_device_;
cryptauth::RemoteDeviceRefList user1_remote_devices_;
cryptauth::RemoteDeviceRefList user2_remote_devices_;
scoped_refptr<base::TestSimpleTaskRunner> task_runner_; scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
base::ThreadTaskRunnerHandle thread_task_runner_handle_; base::ThreadTaskRunnerHandle thread_task_runner_handle_;
private: private:
ScopedDisableLoggingForTesting disable_logging_; ScopedDisableLoggingForTesting disable_logging_;
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(ProximityAuthSystemTest); DISALLOW_COPY_AND_ASSIGN(ProximityAuthSystemTest);
}; };
...@@ -197,10 +221,10 @@ TEST_F(ProximityAuthSystemTest, SetRemoteDevicesForUser_NotStarted) { ...@@ -197,10 +221,10 @@ TEST_F(ProximityAuthSystemTest, SetRemoteDevicesForUser_NotStarted) {
AccountId account1 = AccountId::FromUserEmail(kUser1); AccountId account1 = AccountId::FromUserEmail(kUser1);
AccountId account2 = AccountId::FromUserEmail(kUser2); AccountId account2 = AccountId::FromUserEmail(kUser2);
proximity_auth_system_->SetRemoteDevicesForUser(account1, proximity_auth_system_->SetRemoteDevicesForUser(
user1_remote_devices_); account1, user1_remote_devices_, user1_local_device_);
proximity_auth_system_->SetRemoteDevicesForUser(account2, proximity_auth_system_->SetRemoteDevicesForUser(
user2_remote_devices_); account2, user2_remote_devices_, user1_local_device_);
CompareRemoteDeviceRefLists( CompareRemoteDeviceRefLists(
user1_remote_devices_, user1_remote_devices_,
...@@ -220,11 +244,11 @@ TEST_F(ProximityAuthSystemTest, SetRemoteDevicesForUser_Started) { ...@@ -220,11 +244,11 @@ TEST_F(ProximityAuthSystemTest, SetRemoteDevicesForUser_Started) {
InitProximityAuthSystem(ProximityAuthSystem::SESSION_LOCK); InitProximityAuthSystem(ProximityAuthSystem::SESSION_LOCK);
AccountId account1 = AccountId::FromUserEmail(kUser1); AccountId account1 = AccountId::FromUserEmail(kUser1);
AccountId account2 = AccountId::FromUserEmail(kUser2); AccountId account2 = AccountId::FromUserEmail(kUser2);
proximity_auth_system_->SetRemoteDevicesForUser(account1, proximity_auth_system_->SetRemoteDevicesForUser(
user1_remote_devices_); account1, user1_remote_devices_, user1_local_device_);
proximity_auth_system_->Start(); proximity_auth_system_->Start();
proximity_auth_system_->SetRemoteDevicesForUser(account2, proximity_auth_system_->SetRemoteDevicesForUser(
user2_remote_devices_); account2, user2_remote_devices_, user2_local_device_);
CompareRemoteDeviceRefLists( CompareRemoteDeviceRefLists(
user1_remote_devices_, user1_remote_devices_,
...@@ -266,13 +290,47 @@ TEST_F(ProximityAuthSystemTest, FocusUnregisteredUser) { ...@@ -266,13 +290,47 @@ TEST_F(ProximityAuthSystemTest, FocusUnregisteredUser) {
TEST_F(ProximityAuthSystemTest, ToggleFocus_RegisteredUsers) { TEST_F(ProximityAuthSystemTest, ToggleFocus_RegisteredUsers) {
proximity_auth_system_->SetRemoteDevicesForUser( proximity_auth_system_->SetRemoteDevicesForUser(
AccountId::FromUserEmail(kUser2), user2_remote_devices_); AccountId::FromUserEmail(kUser2), user2_remote_devices_,
user2_local_device_);
RemoteDeviceLifeCycle* life_cycle1 = nullptr;
EXPECT_CALL(*unlock_manager_, SetRemoteDeviceLifeCycle(_))
.WillOnce(SaveArg<0>(&life_cycle1));
FocusUser(kUser1);
EXPECT_EQ(kUser1, life_cycle1->GetRemoteDevice().user_id());
RemoteDeviceLifeCycle* life_cycle2 = nullptr;
{
InSequence sequence;
EXPECT_CALL(*unlock_manager_, SetRemoteDeviceLifeCycle(nullptr))
.Times(AtLeast(1));
EXPECT_CALL(*unlock_manager_, SetRemoteDeviceLifeCycle(_))
.WillOnce(SaveArg<0>(&life_cycle2));
}
FocusUser(kUser2);
EXPECT_EQ(kUser2, life_cycle2->GetRemoteDevice().user_id());
EXPECT_CALL(*unlock_manager_, SetRemoteDeviceLifeCycle(nullptr))
.Times(AtLeast(1));
}
TEST_F(ProximityAuthSystemTest,
ToggleFocus_RegisteredUsers_MultiDeviceApiEnabled) {
SetMultiDeviceApiEnabled();
proximity_auth_system_->SetRemoteDevicesForUser(
AccountId::FromUserEmail(kUser1), user1_remote_devices_,
user1_local_device_);
proximity_auth_system_->SetRemoteDevicesForUser(
AccountId::FromUserEmail(kUser2), user2_remote_devices_,
user2_local_device_);
RemoteDeviceLifeCycle* life_cycle1 = nullptr; RemoteDeviceLifeCycle* life_cycle1 = nullptr;
EXPECT_CALL(*unlock_manager_, SetRemoteDeviceLifeCycle(_)) EXPECT_CALL(*unlock_manager_, SetRemoteDeviceLifeCycle(_))
.WillOnce(SaveArg<0>(&life_cycle1)); .WillOnce(SaveArg<0>(&life_cycle1));
FocusUser(kUser1); FocusUser(kUser1);
EXPECT_EQ(kUser1, life_cycle1->GetRemoteDevice().user_id()); EXPECT_EQ(kUser1, life_cycle1->GetRemoteDevice().user_id());
EXPECT_EQ(user1_local_device_, life_cycle()->local_device());
RemoteDeviceLifeCycle* life_cycle2 = nullptr; RemoteDeviceLifeCycle* life_cycle2 = nullptr;
{ {
...@@ -284,6 +342,7 @@ TEST_F(ProximityAuthSystemTest, ToggleFocus_RegisteredUsers) { ...@@ -284,6 +342,7 @@ TEST_F(ProximityAuthSystemTest, ToggleFocus_RegisteredUsers) {
} }
FocusUser(kUser2); FocusUser(kUser2);
EXPECT_EQ(kUser2, life_cycle2->GetRemoteDevice().user_id()); EXPECT_EQ(kUser2, life_cycle2->GetRemoteDevice().user_id());
EXPECT_EQ(user2_local_device_, life_cycle()->local_device());
EXPECT_CALL(*unlock_manager_, SetRemoteDeviceLifeCycle(nullptr)) EXPECT_CALL(*unlock_manager_, SetRemoteDeviceLifeCycle(nullptr))
.Times(AtLeast(1)); .Times(AtLeast(1));
......
...@@ -153,7 +153,8 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test { ...@@ -153,7 +153,8 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test {
public: public:
ProximityAuthUnlockManagerImplTest() ProximityAuthUnlockManagerImplTest()
: remote_device_(cryptauth::CreateRemoteDeviceRefForTest()), : remote_device_(cryptauth::CreateRemoteDeviceRefForTest()),
life_cycle_(remote_device_), local_device_(cryptauth::CreateRemoteDeviceRefForTest()),
life_cycle_(remote_device_, local_device_),
connection_(remote_device_), connection_(remote_device_),
bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()), bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()),
task_runner_(new base::TestSimpleTaskRunner()), task_runner_(new base::TestSimpleTaskRunner()),
...@@ -210,6 +211,7 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test { ...@@ -210,6 +211,7 @@ class ProximityAuthUnlockManagerImplTest : public testing::Test {
protected: protected:
cryptauth::RemoteDeviceRef remote_device_; cryptauth::RemoteDeviceRef remote_device_;
cryptauth::RemoteDeviceRef local_device_;
FakeRemoteDeviceLifeCycle life_cycle_; FakeRemoteDeviceLifeCycle life_cycle_;
cryptauth::FakeConnection connection_; cryptauth::FakeConnection connection_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment