| Index: remoting/host/security_key/security_key_auth_handler_linux.cc
|
| diff --git a/remoting/host/security_key/gnubby_auth_handler_linux.cc b/remoting/host/security_key/security_key_auth_handler_linux.cc
|
| similarity index 52%
|
| rename from remoting/host/security_key/gnubby_auth_handler_linux.cc
|
| rename to remoting/host/security_key/security_key_auth_handler_linux.cc
|
| index ea66806f7c3aafd681369c2c12e324bd4743f726..346a2febb396c3ed14d25a80041e02610ca61be1 100644
|
| --- a/remoting/host/security_key/gnubby_auth_handler_linux.cc
|
| +++ b/remoting/host/security_key/security_key_auth_handler_linux.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "remoting/host/security_key/gnubby_auth_handler.h"
|
| +#include "remoting/host/security_key/security_key_auth_handler.h"
|
|
|
| #include <stdint.h>
|
| #include <unistd.h>
|
| @@ -22,14 +22,14 @@
|
| #include "net/socket/stream_socket.h"
|
| #include "net/socket/unix_domain_server_socket_posix.h"
|
| #include "remoting/base/logging.h"
|
| -#include "remoting/host/security_key/gnubby_socket.h"
|
| +#include "remoting/host/security_key/security_key_socket.h"
|
|
|
| namespace {
|
|
|
| const int64_t kDefaultRequestTimeoutSeconds = 60;
|
|
|
| -// The name of the socket to listen for gnubby requests on.
|
| -base::LazyInstance<base::FilePath>::Leaky g_gnubby_socket_name =
|
| +// The name of the socket to listen for security key requests on.
|
| +base::LazyInstance<base::FilePath>::Leaky g_security_key_socket_name =
|
| LAZY_INSTANCE_INITIALIZER;
|
|
|
| // Socket authentication function that only allows connections from callers with
|
| @@ -51,20 +51,20 @@ unsigned int GetCommandCode(const std::string& data) {
|
|
|
| namespace remoting {
|
|
|
| -class GnubbyAuthHandlerLinux : public GnubbyAuthHandler {
|
| +class SecurityKeyAuthHandlerLinux : public SecurityKeyAuthHandler {
|
| public:
|
| - GnubbyAuthHandlerLinux();
|
| - ~GnubbyAuthHandlerLinux() override;
|
| + SecurityKeyAuthHandlerLinux();
|
| + ~SecurityKeyAuthHandlerLinux() override;
|
|
|
| private:
|
| - typedef std::map<int, GnubbySocket*> ActiveSockets;
|
| + typedef std::map<int, SecurityKeySocket*> ActiveSockets;
|
|
|
| - // GnubbyAuthHandler interface.
|
| - void CreateGnubbyConnection() override;
|
| - bool IsValidConnectionId(int gnubby_connection_id) const override;
|
| - void SendClientResponse(int gnubby_connection_id,
|
| + // SecurityKeyAuthHandler interface.
|
| + void CreateSecurityKeyConnection() override;
|
| + bool IsValidConnectionId(int security_key_connection_id) const override;
|
| + void SendClientResponse(int security_key_connection_id,
|
| const std::string& response) override;
|
| - void SendErrorAndCloseConnection(int gnubby_connection_id) override;
|
| + void SendErrorAndCloseConnection(int security_key_connection_id) override;
|
| void SetSendMessageCallback(const SendMessageCallback& callback) override;
|
| size_t GetActiveConnectionCountForTest() const override;
|
| void SetRequestTimeoutForTest(base::TimeDelta timeout) override;
|
| @@ -75,20 +75,20 @@ class GnubbyAuthHandlerLinux : public GnubbyAuthHandler {
|
| // Called when a connection is accepted.
|
| void OnAccepted(int result);
|
|
|
| - // Called when a GnubbySocket has done reading.
|
| - void OnReadComplete(int gnubby_connection_id);
|
| + // Called when a SecurityKeySocket has done reading.
|
| + void OnReadComplete(int security_key_connection_id);
|
|
|
| - // Gets an active socket iterator for |gnubby_connection_id|.
|
| + // Gets an active socket iterator for |security_key_connection_id|.
|
| ActiveSockets::const_iterator GetSocketForConnectionId(
|
| - int gnubby_connection_id) const;
|
| + int security_key_connection_id) const;
|
|
|
| // Send an error and closes an active socket.
|
| void SendErrorAndCloseActiveSocket(const ActiveSockets::const_iterator& iter);
|
|
|
| // A request timed out.
|
| - void RequestTimedOut(int gnubby_connection_id);
|
| + void RequestTimedOut(int security_key_connection_id);
|
|
|
| - // Ensures GnubbyAuthHandlerLinux methods are called on the same thread.
|
| + // Ensures SecurityKeyAuthHandlerLinux methods are called on the same thread.
|
| base::ThreadChecker thread_checker_;
|
|
|
| // Socket used to listen for authorization requests.
|
| @@ -97,10 +97,10 @@ class GnubbyAuthHandlerLinux : public GnubbyAuthHandler {
|
| // A temporary holder for an accepted connection.
|
| std::unique_ptr<net::StreamSocket> accept_socket_;
|
|
|
| - // Used to pass gnubby extension messages to the client.
|
| + // Used to pass security key extension messages to the client.
|
| SendMessageCallback send_message_callback_;
|
|
|
| - // The last assigned gnubby connection id.
|
| + // The last assigned security key connection id.
|
| int last_connection_id_;
|
|
|
| // Sockets by connection id used to process gnubbyd requests.
|
| @@ -109,34 +109,35 @@ class GnubbyAuthHandlerLinux : public GnubbyAuthHandler {
|
| // Timeout used for a request.
|
| base::TimeDelta request_timeout_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerLinux);
|
| + DISALLOW_COPY_AND_ASSIGN(SecurityKeyAuthHandlerLinux);
|
| };
|
|
|
| -std::unique_ptr<GnubbyAuthHandler> GnubbyAuthHandler::Create(
|
| +std::unique_ptr<SecurityKeyAuthHandler> SecurityKeyAuthHandler::Create(
|
| ClientSessionDetails* client_session_details,
|
| const SendMessageCallback& send_message_callback) {
|
| - std::unique_ptr<GnubbyAuthHandler> auth_handler(new GnubbyAuthHandlerLinux());
|
| + std::unique_ptr<SecurityKeyAuthHandler> auth_handler(
|
| + new SecurityKeyAuthHandlerLinux());
|
| auth_handler->SetSendMessageCallback(send_message_callback);
|
| return auth_handler;
|
| }
|
|
|
| -void GnubbyAuthHandler::SetGnubbySocketName(
|
| - const base::FilePath& gnubby_socket_name) {
|
| - g_gnubby_socket_name.Get() = gnubby_socket_name;
|
| +void SecurityKeyAuthHandler::SetSecurityKeySocketName(
|
| + const base::FilePath& security_key_socket_name) {
|
| + g_security_key_socket_name.Get() = security_key_socket_name;
|
| }
|
|
|
| -GnubbyAuthHandlerLinux::GnubbyAuthHandlerLinux()
|
| +SecurityKeyAuthHandlerLinux::SecurityKeyAuthHandlerLinux()
|
| : last_connection_id_(0),
|
| request_timeout_(
|
| base::TimeDelta::FromSeconds(kDefaultRequestTimeoutSeconds)) {}
|
|
|
| -GnubbyAuthHandlerLinux::~GnubbyAuthHandlerLinux() {
|
| +SecurityKeyAuthHandlerLinux::~SecurityKeyAuthHandlerLinux() {
|
| STLDeleteValues(&active_sockets_);
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::CreateGnubbyConnection() {
|
| +void SecurityKeyAuthHandlerLinux::CreateSecurityKeyConnection() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - DCHECK(!g_gnubby_socket_name.Get().empty());
|
| + DCHECK(!g_security_key_socket_name.Get().empty());
|
|
|
| {
|
| // DeleteFile() is a blocking operation, but so is creation of the unix
|
| @@ -147,76 +148,78 @@ void GnubbyAuthHandlerLinux::CreateGnubbyConnection() {
|
| base::ThreadRestrictions::ScopedAllowIO allow_io;
|
|
|
| // If the file already exists, a socket in use error is returned.
|
| - base::DeleteFile(g_gnubby_socket_name.Get(), false);
|
| + base::DeleteFile(g_security_key_socket_name.Get(), false);
|
| }
|
|
|
| - HOST_LOG << "Listening for gnubby requests on "
|
| - << g_gnubby_socket_name.Get().value();
|
| + HOST_LOG << "Listening for security key requests on "
|
| + << g_security_key_socket_name.Get().value();
|
|
|
| auth_socket_.reset(
|
| new net::UnixDomainServerSocket(base::Bind(MatchUid), false));
|
| - int rv = auth_socket_->BindAndListen(g_gnubby_socket_name.Get().value(),
|
| + int rv = auth_socket_->BindAndListen(g_security_key_socket_name.Get().value(),
|
| /*backlog=*/1);
|
| if (rv != net::OK) {
|
| - LOG(ERROR) << "Failed to open socket for gnubby requests: '" << rv << "'";
|
| + LOG(ERROR) << "Failed to open socket for auth requests: '" << rv << "'";
|
| return;
|
| }
|
| DoAccept();
|
| }
|
|
|
| -bool GnubbyAuthHandlerLinux::IsValidConnectionId(
|
| - int gnubby_connection_id) const {
|
| - return GetSocketForConnectionId(gnubby_connection_id) !=
|
| +bool SecurityKeyAuthHandlerLinux::IsValidConnectionId(
|
| + int security_key_connection_id) const {
|
| + return GetSocketForConnectionId(security_key_connection_id) !=
|
| active_sockets_.end();
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::SendClientResponse(int gnubby_connection_id,
|
| - const std::string& response) {
|
| +void SecurityKeyAuthHandlerLinux::SendClientResponse(
|
| + int security_key_connection_id,
|
| + const std::string& response) {
|
| ActiveSockets::const_iterator iter =
|
| - GetSocketForConnectionId(gnubby_connection_id);
|
| + GetSocketForConnectionId(security_key_connection_id);
|
| if (iter != active_sockets_.end()) {
|
| iter->second->SendResponse(response);
|
| } else {
|
| LOG(WARNING) << "Unknown gnubby-auth data connection: '"
|
| - << gnubby_connection_id << "'";
|
| + << security_key_connection_id << "'";
|
| }
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::SendErrorAndCloseConnection(
|
| - int gnubby_connection_id) {
|
| +void SecurityKeyAuthHandlerLinux::SendErrorAndCloseConnection(
|
| + int security_key_connection_id) {
|
| ActiveSockets::const_iterator iter =
|
| - GetSocketForConnectionId(gnubby_connection_id);
|
| + GetSocketForConnectionId(security_key_connection_id);
|
| if (iter != active_sockets_.end()) {
|
| - HOST_LOG << "Sending gnubby error";
|
| + HOST_LOG << "Sending security key error";
|
| SendErrorAndCloseActiveSocket(iter);
|
| } else {
|
| LOG(WARNING) << "Unknown gnubby-auth data connection: '"
|
| - << gnubby_connection_id << "'";
|
| + << security_key_connection_id << "'";
|
| }
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::SetSendMessageCallback(
|
| +void SecurityKeyAuthHandlerLinux::SetSendMessageCallback(
|
| const SendMessageCallback& callback) {
|
| send_message_callback_ = callback;
|
| }
|
|
|
| -size_t GnubbyAuthHandlerLinux::GetActiveConnectionCountForTest() const {
|
| +size_t SecurityKeyAuthHandlerLinux::GetActiveConnectionCountForTest() const {
|
| return active_sockets_.size();
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::SetRequestTimeoutForTest(base::TimeDelta timeout) {
|
| +void SecurityKeyAuthHandlerLinux::SetRequestTimeoutForTest(
|
| + base::TimeDelta timeout) {
|
| request_timeout_ = timeout;
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::DoAccept() {
|
| +void SecurityKeyAuthHandlerLinux::DoAccept() {
|
| int result = auth_socket_->Accept(
|
| - &accept_socket_,
|
| - base::Bind(&GnubbyAuthHandlerLinux::OnAccepted, base::Unretained(this)));
|
| + &accept_socket_, base::Bind(&SecurityKeyAuthHandlerLinux::OnAccepted,
|
| + base::Unretained(this)));
|
| if (result != net::ERR_IO_PENDING)
|
| OnAccepted(result);
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::OnAccepted(int result) {
|
| +void SecurityKeyAuthHandlerLinux::OnAccepted(int result) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK_NE(net::ERR_IO_PENDING, result);
|
|
|
| @@ -225,25 +228,26 @@ void GnubbyAuthHandlerLinux::OnAccepted(int result) {
|
| return;
|
| }
|
|
|
| - int gnubby_connection_id = ++last_connection_id_;
|
| - GnubbySocket* socket = new GnubbySocket(
|
| + int security_key_connection_id = ++last_connection_id_;
|
| + SecurityKeySocket* socket = new SecurityKeySocket(
|
| std::move(accept_socket_), request_timeout_,
|
| - base::Bind(&GnubbyAuthHandlerLinux::RequestTimedOut,
|
| - base::Unretained(this), gnubby_connection_id));
|
| - active_sockets_[gnubby_connection_id] = socket;
|
| + base::Bind(&SecurityKeyAuthHandlerLinux::RequestTimedOut,
|
| + base::Unretained(this), security_key_connection_id));
|
| + active_sockets_[security_key_connection_id] = socket;
|
| socket->StartReadingRequest(
|
| - base::Bind(&GnubbyAuthHandlerLinux::OnReadComplete,
|
| - base::Unretained(this), gnubby_connection_id));
|
| + base::Bind(&SecurityKeyAuthHandlerLinux::OnReadComplete,
|
| + base::Unretained(this), security_key_connection_id));
|
|
|
| // Continue accepting new connections.
|
| DoAccept();
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::OnReadComplete(int gnubby_connection_id) {
|
| +void SecurityKeyAuthHandlerLinux::OnReadComplete(
|
| + int security_key_connection_id) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| ActiveSockets::const_iterator iter =
|
| - active_sockets_.find(gnubby_connection_id);
|
| + active_sockets_.find(security_key_connection_id);
|
| DCHECK(iter != active_sockets_.end());
|
| std::string request_data;
|
| if (!iter->second->GetAndClearRequestData(&request_data)) {
|
| @@ -251,31 +255,32 @@ void GnubbyAuthHandlerLinux::OnReadComplete(int gnubby_connection_id) {
|
| return;
|
| }
|
|
|
| - HOST_LOG << "Received gnubby request: " << GetCommandCode(request_data);
|
| - send_message_callback_.Run(gnubby_connection_id, request_data);
|
| + HOST_LOG << "Received security key request: " << GetCommandCode(request_data);
|
| + send_message_callback_.Run(security_key_connection_id, request_data);
|
|
|
| iter->second->StartReadingRequest(
|
| - base::Bind(&GnubbyAuthHandlerLinux::OnReadComplete,
|
| - base::Unretained(this), gnubby_connection_id));
|
| + base::Bind(&SecurityKeyAuthHandlerLinux::OnReadComplete,
|
| + base::Unretained(this), security_key_connection_id));
|
| }
|
|
|
| -GnubbyAuthHandlerLinux::ActiveSockets::const_iterator
|
| -GnubbyAuthHandlerLinux::GetSocketForConnectionId(
|
| - int gnubby_connection_id) const {
|
| - return active_sockets_.find(gnubby_connection_id);
|
| +SecurityKeyAuthHandlerLinux::ActiveSockets::const_iterator
|
| +SecurityKeyAuthHandlerLinux::GetSocketForConnectionId(
|
| + int security_key_connection_id) const {
|
| + return active_sockets_.find(security_key_connection_id);
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::SendErrorAndCloseActiveSocket(
|
| +void SecurityKeyAuthHandlerLinux::SendErrorAndCloseActiveSocket(
|
| const ActiveSockets::const_iterator& iter) {
|
| iter->second->SendSshError();
|
| delete iter->second;
|
| active_sockets_.erase(iter);
|
| }
|
|
|
| -void GnubbyAuthHandlerLinux::RequestTimedOut(int gnubby_connection_id) {
|
| - HOST_LOG << "Gnubby request timed out";
|
| +void SecurityKeyAuthHandlerLinux::RequestTimedOut(
|
| + int security_key_connection_id) {
|
| + HOST_LOG << "SecurityKey request timed out";
|
| ActiveSockets::const_iterator iter =
|
| - active_sockets_.find(gnubby_connection_id);
|
| + active_sockets_.find(security_key_connection_id);
|
| if (iter != active_sockets_.end())
|
| SendErrorAndCloseActiveSocket(iter);
|
| }
|
|
|