Commit 799f491e authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

[CrOS Multidevice] Integrate the SecureChannel API into proximity_auth::Messenger.

This injects a ClientChannel into Messenger, which is used if the
chromeos::features::kMultiDeviceApi is enabled. The ClientChannel is used
to send and receive messages with the remote device.

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

Bug: 824568, 752273
Change-Id: If927eb84d013657db823f8538d138beb9c2c16be
Reviewed-on: https://chromium-review.googlesource.com/1107482
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569798}
parent 84f58fd6
......@@ -5,6 +5,12 @@
#ifndef CHROMEOS_COMPONENTS_PROXIMITY_AUTH_MESSENGER_H_
#define CHROMEOS_COMPONENTS_PROXIMITY_AUTH_MESSENGER_H_
namespace chromeos {
namespace secure_channel {
class ClientChannel;
} // namespace secure_channel
} // namespace chromeos
namespace cryptauth {
class Connection;
class SecureContext;
......@@ -48,6 +54,8 @@ class Messenger {
// |GetSecureContext()| instead if you want to send and receive messages
// securely.
virtual cryptauth::Connection* GetConnection() const = 0;
virtual chromeos::secure_channel::ClientChannel* GetChannel() const = 0;
};
} // namespace proximity_auth
......
......@@ -12,6 +12,7 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "chromeos/components/proximity_auth/messenger.h"
#include "chromeos/services/secure_channel/public/cpp/client/client_channel.h"
#include "components/cryptauth/connection.h"
#include "components/cryptauth/connection_observer.h"
......@@ -26,14 +27,24 @@ class SecureContext;
namespace proximity_auth {
// Concrete implementation of the Messenger interface.
class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver {
class MessengerImpl : public Messenger,
public cryptauth::ConnectionObserver,
public chromeos::secure_channel::ClientChannel::Observer {
public:
// Constructs a messenger that sends and receives messages over the given
// |connection|, using the |secure_context| to encrypt and decrypt the
// messages. The |connection| must be connected. The messenger begins
// observing messages as soon as it is constructed.
MessengerImpl(std::unique_ptr<cryptauth::Connection> connection,
std::unique_ptr<cryptauth::SecureContext> secure_context);
// Constructs a messenger that sends and receives messages.
//
// If the |chromeos::features::kMultiDeviceApi| flag is enabled, messages are
// relayed over the provided |channel|, and |connection| and |secure_context|
// are ignored.
//
// If not, messages are relayed over |connection|, using the |secure_context|
// to encrypt and decrypt the messages. |channel| is ignored.
//
// The messenger begins observing messages as soon as it is constructed.
MessengerImpl(
std::unique_ptr<cryptauth::Connection> connection,
std::unique_ptr<cryptauth::SecureContext> secure_context,
std::unique_ptr<chromeos::secure_channel::ClientChannel> channel);
~MessengerImpl() override;
// Messenger:
......@@ -45,6 +56,7 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver {
void RequestUnlock() override;
cryptauth::SecureContext* GetSecureContext() const override;
cryptauth::Connection* GetConnection() const override;
chromeos::secure_channel::ClientChannel* GetChannel() const override;
// Exposed for testing.
cryptauth::Connection* connection() { return connection_.get(); }
......@@ -72,9 +84,6 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver {
// Called when the message is encoded so it can be sent over the connection.
void OnMessageEncoded(const std::string& encoded_message);
// Called when the message is decoded so it can be parsed.
void OnMessageDecoded(const std::string& decoded_message);
// Handles an incoming "status_update" |message|, parsing and notifying
// observers of the content.
void HandleRemoteStatusUpdateMessage(const base::DictionaryValue& message);
......@@ -98,6 +107,17 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver {
const cryptauth::WireMessage& wire_message,
bool success) override;
// chromeos::secure_channel::ClientChannel::Observer:
void OnDisconnected() override;
void OnMessageReceived(const std::string& payload) override;
// Called when a message has been recevied from the remote device. The message
// should be a valid JSON string.
void HandleMessage(const std::string& message);
// Called when a message has been sent to the remote device.
void OnSendMessageResult(bool success);
// The connection used to send and receive events and status updates.
std::unique_ptr<cryptauth::Connection> connection_;
......@@ -105,6 +125,10 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver {
// |connection_|.
std::unique_ptr<cryptauth::SecureContext> secure_context_;
// Authenticated end-to-end channel used to communicate with the remote
// device.
std::unique_ptr<chromeos::secure_channel::ClientChannel> channel_;
// The registered observers of |this_| messenger.
base::ObserverList<MessengerObserver> observers_;
......
......@@ -148,9 +148,12 @@ void RemoteDeviceLifeCycleImpl::OnAuthenticationResult(
void RemoteDeviceLifeCycleImpl::CreateMessenger() {
DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING);
DCHECK(secure_context_);
messenger_.reset(
new MessengerImpl(std::move(connection_), std::move(secure_context_)));
// TODO(crbug.com/752273): Inject a real ClientChannel.
messenger_.reset(new MessengerImpl(std::move(connection_),
std::move(secure_context_),
nullptr /* channel */));
messenger_->AddObserver(this);
TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
......
......@@ -69,6 +69,7 @@ class MockMessenger : public Messenger {
MOCK_METHOD0(RequestUnlock, void());
MOCK_CONST_METHOD0(GetSecureContext, cryptauth::SecureContext*());
MOCK_CONST_METHOD0(GetConnection, cryptauth::Connection*());
MOCK_CONST_METHOD0(GetChannel, chromeos::secure_channel::ClientChannel*());
private:
DISALLOW_COPY_AND_ASSIGN(MockMessenger);
......
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