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 @@ ...@@ -5,6 +5,12 @@
#ifndef CHROMEOS_COMPONENTS_PROXIMITY_AUTH_MESSENGER_H_ #ifndef CHROMEOS_COMPONENTS_PROXIMITY_AUTH_MESSENGER_H_
#define 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 { namespace cryptauth {
class Connection; class Connection;
class SecureContext; class SecureContext;
...@@ -48,6 +54,8 @@ class Messenger { ...@@ -48,6 +54,8 @@ class Messenger {
// |GetSecureContext()| instead if you want to send and receive messages // |GetSecureContext()| instead if you want to send and receive messages
// securely. // securely.
virtual cryptauth::Connection* GetConnection() const = 0; virtual cryptauth::Connection* GetConnection() const = 0;
virtual chromeos::secure_channel::ClientChannel* GetChannel() const = 0;
}; };
} // namespace proximity_auth } // namespace proximity_auth
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "chromeos/components/proximity_auth/messenger.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.h"
#include "components/cryptauth/connection_observer.h" #include "components/cryptauth/connection_observer.h"
...@@ -26,14 +27,24 @@ class SecureContext; ...@@ -26,14 +27,24 @@ class SecureContext;
namespace proximity_auth { namespace proximity_auth {
// Concrete implementation of the Messenger interface. // 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: public:
// Constructs a messenger that sends and receives messages over the given // Constructs a messenger that sends and receives messages.
// |connection|, using the |secure_context| to encrypt and decrypt the //
// messages. The |connection| must be connected. The messenger begins // If the |chromeos::features::kMultiDeviceApi| flag is enabled, messages are
// observing messages as soon as it is constructed. // relayed over the provided |channel|, and |connection| and |secure_context|
MessengerImpl(std::unique_ptr<cryptauth::Connection> connection, // are ignored.
std::unique_ptr<cryptauth::SecureContext> secure_context); //
// 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; ~MessengerImpl() override;
// Messenger: // Messenger:
...@@ -45,6 +56,7 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver { ...@@ -45,6 +56,7 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver {
void RequestUnlock() override; void RequestUnlock() override;
cryptauth::SecureContext* GetSecureContext() const override; cryptauth::SecureContext* GetSecureContext() const override;
cryptauth::Connection* GetConnection() const override; cryptauth::Connection* GetConnection() const override;
chromeos::secure_channel::ClientChannel* GetChannel() const override;
// Exposed for testing. // Exposed for testing.
cryptauth::Connection* connection() { return connection_.get(); } cryptauth::Connection* connection() { return connection_.get(); }
...@@ -72,9 +84,6 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver { ...@@ -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. // Called when the message is encoded so it can be sent over the connection.
void OnMessageEncoded(const std::string& encoded_message); 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 // Handles an incoming "status_update" |message|, parsing and notifying
// observers of the content. // observers of the content.
void HandleRemoteStatusUpdateMessage(const base::DictionaryValue& message); void HandleRemoteStatusUpdateMessage(const base::DictionaryValue& message);
...@@ -98,6 +107,17 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver { ...@@ -98,6 +107,17 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver {
const cryptauth::WireMessage& wire_message, const cryptauth::WireMessage& wire_message,
bool success) override; 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. // The connection used to send and receive events and status updates.
std::unique_ptr<cryptauth::Connection> connection_; std::unique_ptr<cryptauth::Connection> connection_;
...@@ -105,6 +125,10 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver { ...@@ -105,6 +125,10 @@ class MessengerImpl : public Messenger, public cryptauth::ConnectionObserver {
// |connection_|. // |connection_|.
std::unique_ptr<cryptauth::SecureContext> secure_context_; 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. // The registered observers of |this_| messenger.
base::ObserverList<MessengerObserver> observers_; base::ObserverList<MessengerObserver> observers_;
......
...@@ -148,9 +148,12 @@ void RemoteDeviceLifeCycleImpl::OnAuthenticationResult( ...@@ -148,9 +148,12 @@ void RemoteDeviceLifeCycleImpl::OnAuthenticationResult(
void RemoteDeviceLifeCycleImpl::CreateMessenger() { void RemoteDeviceLifeCycleImpl::CreateMessenger() {
DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING); DCHECK(state_ == RemoteDeviceLifeCycle::State::AUTHENTICATING);
DCHECK(secure_context_);
messenger_.reset( // TODO(crbug.com/752273): Inject a real ClientChannel.
new MessengerImpl(std::move(connection_), std::move(secure_context_))); messenger_.reset(new MessengerImpl(std::move(connection_),
std::move(secure_context_),
nullptr /* channel */));
messenger_->AddObserver(this); messenger_->AddObserver(this);
TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED); TransitionToState(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED);
......
...@@ -69,6 +69,7 @@ class MockMessenger : public Messenger { ...@@ -69,6 +69,7 @@ class MockMessenger : public Messenger {
MOCK_METHOD0(RequestUnlock, void()); MOCK_METHOD0(RequestUnlock, void());
MOCK_CONST_METHOD0(GetSecureContext, cryptauth::SecureContext*()); MOCK_CONST_METHOD0(GetSecureContext, cryptauth::SecureContext*());
MOCK_CONST_METHOD0(GetConnection, cryptauth::Connection*()); MOCK_CONST_METHOD0(GetConnection, cryptauth::Connection*());
MOCK_CONST_METHOD0(GetChannel, chromeos::secure_channel::ClientChannel*());
private: private:
DISALLOW_COPY_AND_ASSIGN(MockMessenger); 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