Commit 1c63d2c3 authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

Proximity Auth: Remove kMultiDeviceApi flagging from RDLI.

R=hansberry@chromium.org

Bug: 899324
Test: none
Change-Id: Ib749683f19dad9fad2e0917673f319acb8bb3983
Reviewed-on: https://chromium-review.googlesource.com/c/1325310
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606500}
parent 4808ff32
......@@ -5,24 +5,13 @@
#include "chromeos/components/proximity_auth/remote_device_life_cycle_impl.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/default_tick_clock.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/components/proximity_auth/bluetooth_low_energy_connection_finder.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/proximity_auth/messenger_impl.h"
#include "chromeos/components/proximity_auth/switches.h"
#include "chromeos/services/secure_channel/public/cpp/client/secure_channel_client.h"
#include "chromeos/services/secure_channel/public/cpp/shared/connection_priority.h"
#include "components/cryptauth/connection_finder.h"
#include "components/cryptauth/device_to_device_authenticator.h"
#include "components/cryptauth/secure_context.h"
#include "components/cryptauth/secure_message_delegate_impl.h"
namespace proximity_auth {
......@@ -30,11 +19,6 @@ namespace {
const char kSmartLockFeatureName[] = "easy_unlock";
// The time to wait, in seconds, after authentication fails, before retrying
// another connection. This value is not used if the SecureChannel API fails to
// create an authenticated connection.
const int kAuthenticationRecoveryTimeSeconds = 10;
} // namespace
RemoteDeviceLifeCycleImpl::RemoteDeviceLifeCycleImpl(
......@@ -61,8 +45,6 @@ cryptauth::RemoteDeviceRef RemoteDeviceLifeCycleImpl::GetRemoteDevice() const {
chromeos::secure_channel::ClientChannel* RemoteDeviceLifeCycleImpl::GetChannel()
const {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
if (channel_)
return channel_.get();
if (messenger_)
......@@ -86,18 +68,6 @@ void RemoteDeviceLifeCycleImpl::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
std::unique_ptr<cryptauth::ConnectionFinder>
RemoteDeviceLifeCycleImpl::CreateConnectionFinder() {
return std::make_unique<BluetoothLowEnergyConnectionFinder>(remote_device_);
}
std::unique_ptr<cryptauth::Authenticator>
RemoteDeviceLifeCycleImpl::CreateAuthenticator() {
return std::make_unique<cryptauth::DeviceToDeviceAuthenticator>(
connection_.get(), remote_device_.user_id(),
cryptauth::SecureMessageDelegateImpl::Factory::NewInstance());
}
void RemoteDeviceLifeCycleImpl::TransitionToState(
RemoteDeviceLifeCycle::State new_state) {
PA_LOG(VERBOSE) << "Life cycle transition: " << state_ << " => " << new_state;
......@@ -108,69 +78,14 @@ void RemoteDeviceLifeCycleImpl::TransitionToState(
}
void RemoteDeviceLifeCycleImpl::FindConnection() {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
connection_attempt_ = secure_channel_client_->ListenForConnectionFromDevice(
remote_device_, *local_device_, kSmartLockFeatureName,
chromeos::secure_channel::ConnectionPriority::kHigh);
connection_attempt_->SetDelegate(this);
} else {
connection_finder_ = CreateConnectionFinder();
if (!connection_finder_) {
// TODO(tengs): We need to introduce a failed state if the RemoteDevice
// data is invalid.
TransitionToState(RemoteDeviceLifeCycleImpl::State::FINDING_CONNECTION);
return;
}
connection_finder_->Find(
base::BindRepeating(&RemoteDeviceLifeCycleImpl::OnConnectionFound,
weak_ptr_factory_.GetWeakPtr()));
}
connection_attempt_ = secure_channel_client_->ListenForConnectionFromDevice(
remote_device_, *local_device_, kSmartLockFeatureName,
chromeos::secure_channel::ConnectionPriority::kHigh);
connection_attempt_->SetDelegate(this);
TransitionToState(RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
}
void RemoteDeviceLifeCycleImpl::OnConnectionFound(
std::unique_ptr<cryptauth::Connection> connection) {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
DCHECK(state_ == RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
connection_ = std::move(connection);
authenticator_ = CreateAuthenticator();
authenticator_->Authenticate(
base::Bind(&RemoteDeviceLifeCycleImpl::OnAuthenticationResult,
weak_ptr_factory_.GetWeakPtr()));
TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATING);
}
void RemoteDeviceLifeCycleImpl::OnAuthenticationResult(
cryptauth::Authenticator::Result result,
std::unique_ptr<cryptauth::SecureContext> secure_context) {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING);
authenticator_.reset();
if (result != cryptauth::Authenticator::Result::SUCCESS) {
PA_LOG(WARNING) << "Waiting " << kAuthenticationRecoveryTimeSeconds
<< " seconds to retry after authentication failure.";
connection_->Disconnect();
authentication_recovery_timer_.Start(
FROM_HERE,
base::TimeDelta::FromSeconds(kAuthenticationRecoveryTimeSeconds), this,
&RemoteDeviceLifeCycleImpl::FindConnection);
TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED);
return;
}
// Create the MessengerImpl asynchronously. |messenger_| registers itself as
// an observer of |connection_|, so creating it synchronously would trigger
// |OnSendCompleted()| as an observer call for |messenger_|.
secure_context_ = std::move(secure_context);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&RemoteDeviceLifeCycleImpl::CreateMessenger,
weak_ptr_factory_.GetWeakPtr()));
}
void RemoteDeviceLifeCycleImpl::CreateMessenger() {
DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING);
......@@ -182,8 +97,6 @@ void RemoteDeviceLifeCycleImpl::CreateMessenger() {
void RemoteDeviceLifeCycleImpl::OnConnectionAttemptFailure(
chromeos::secure_channel::mojom::ConnectionAttemptFailureReason reason) {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
connection_attempt_.reset();
if (reason == chromeos::secure_channel::mojom::
......@@ -206,8 +119,6 @@ void RemoteDeviceLifeCycleImpl::OnConnectionAttemptFailure(
void RemoteDeviceLifeCycleImpl::OnConnection(
std::unique_ptr<chromeos::secure_channel::ClientChannel> channel) {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
DCHECK(state_ == RemoteDeviceLifeCycle::State::FINDING_CONNECTION);
TransitionToState(RemoteDeviceLifeCycle::State::AUTHENTICATING);
......
......@@ -16,9 +16,6 @@
#include "chromeos/services/secure_channel/public/cpp/client/connection_attempt.h"
#include "chromeos/services/secure_channel/public/cpp/client/secure_channel_client.h"
#include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h"
#include "components/cryptauth/authenticator.h"
#include "components/cryptauth/connection.h"
#include "components/cryptauth/connection_finder.h"
#include "components/cryptauth/remote_device_ref.h"
namespace chromeos {
......@@ -28,10 +25,6 @@ class SecureChannelClient;
} // namespace secure_channel
} // namespace chromeos
namespace cryptauth {
class SecureContext;
}
namespace proximity_auth {
class Messenger;
......@@ -60,16 +53,6 @@ class RemoteDeviceLifeCycleImpl
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
protected:
// Creates and returns a cryptauth::ConnectionFinder instance for
// |remote_device_|.
// Exposed for testing.
virtual std::unique_ptr<cryptauth::ConnectionFinder> CreateConnectionFinder();
// Creates and returns an Authenticator instance for |connection_|.
// Exposed for testing.
virtual std::unique_ptr<cryptauth::Authenticator> CreateAuthenticator();
private:
// Transitions to |new_state|, and notifies observers.
void TransitionToState(RemoteDeviceLifeCycle::State new_state);
......@@ -81,11 +64,6 @@ class RemoteDeviceLifeCycleImpl
// Called when |connection_finder_| finds a connection.
void OnConnectionFound(std::unique_ptr<cryptauth::Connection> connection);
// Callback when |authenticator_| completes authentication.
void OnAuthenticationResult(
cryptauth::Authenticator::Result result,
std::unique_ptr<cryptauth::SecureContext> secure_context);
// Creates the messenger which parses status updates.
void CreateMessenger();
......@@ -115,25 +93,10 @@ class RemoteDeviceLifeCycleImpl
base::ObserverList<Observer>::Unchecked observers_{
base::ObserverListPolicy::EXISTING_ONLY};
// The connection that is established by |connection_finder_|.
std::unique_ptr<cryptauth::Connection> connection_;
// Context for encrypting and decrypting messages. Created after
// authentication succeeds. Ownership is eventually passed to |messenger_|.
std::unique_ptr<cryptauth::SecureContext> secure_context_;
// The messenger for sending and receiving messages in the
// SECURE_CHANNEL_ESTABLISHED state.
std::unique_ptr<Messenger> messenger_;
// Authenticates the remote device after it is connected. Used in the
// AUTHENTICATING state.
std::unique_ptr<cryptauth::Authenticator> authenticator_;
// Used in the FINDING_CONNECTION state to establish a connection to the
// remote device.
std::unique_ptr<cryptauth::ConnectionFinder> connection_finder_;
std::unique_ptr<chromeos::secure_channel::ConnectionAttempt>
connection_attempt_;
......
......@@ -145,29 +145,8 @@ class TestableRemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycleImpl {
~TestableRemoteDeviceLifeCycleImpl() override {}
FakeConnectionFinder* connection_finder() { return connection_finder_; }
FakeAuthenticator* authenticator() { return authenticator_; }
private:
std::unique_ptr<cryptauth::ConnectionFinder> CreateConnectionFinder()
override {
std::unique_ptr<FakeConnectionFinder> scoped_connection_finder(
new FakeConnectionFinder(remote_device_));
connection_finder_ = scoped_connection_finder.get();
return std::move(scoped_connection_finder);
}
std::unique_ptr<cryptauth::Authenticator> CreateAuthenticator() override {
EXPECT_TRUE(connection_finder_);
std::unique_ptr<FakeAuthenticator> scoped_authenticator(
new FakeAuthenticator(connection_finder_->connection()));
authenticator_ = scoped_authenticator.get();
return std::move(scoped_authenticator);
}
const cryptauth::RemoteDeviceRef remote_device_;
FakeConnectionFinder* connection_finder_;
FakeAuthenticator* authenticator_;
DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl);
};
......@@ -273,42 +252,6 @@ class ProximityAuthRemoteDeviceLifeCycleImplTest
EXPECT_EQ(expected_life_cycle_state, life_cycle_.GetState());
}
cryptauth::FakeConnection* OnConnectionFound() {
EXPECT_EQ(RemoteDeviceLifeCycle::State::FINDING_CONNECTION,
life_cycle_.GetState());
EXPECT_CALL(*this, OnLifeCycleStateChanged(
RemoteDeviceLifeCycle::State::FINDING_CONNECTION,
RemoteDeviceLifeCycle::State::AUTHENTICATING));
life_cycle_.connection_finder()->OnConnectionFound();
Mock::VerifyAndClearExpectations(this);
EXPECT_EQ(RemoteDeviceLifeCycle::State::AUTHENTICATING,
life_cycle_.GetState());
return life_cycle_.connection_finder()->connection();
}
void Authenticate(cryptauth::Authenticator::Result result) {
EXPECT_EQ(RemoteDeviceLifeCycle::State::AUTHENTICATING,
life_cycle_.GetState());
RemoteDeviceLifeCycle::State expected_state =
(result == cryptauth::Authenticator::Result::SUCCESS)
? RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED
: RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED;
EXPECT_CALL(*this, OnLifeCycleStateChanged(
RemoteDeviceLifeCycle::State::AUTHENTICATING,
expected_state));
life_cycle_.authenticator()->OnAuthenticationResult(result);
if (result == cryptauth::Authenticator::Result::SUCCESS)
task_runner_->RunUntilIdle();
EXPECT_EQ(expected_state, life_cycle_.GetState());
Mock::VerifyAndClearExpectations(this);
}
MOCK_METHOD2(OnLifeCycleStateChanged,
void(RemoteDeviceLifeCycle::State old_state,
RemoteDeviceLifeCycle::State new_state));
......
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