Index: remoting/host/security_key/gnubby_auth_handler_linux.cc |
diff --git a/remoting/host/security_key/gnubby_auth_handler_linux.cc b/remoting/host/security_key/gnubby_auth_handler_linux.cc |
index 8a50686f3982c5b7e9a96aa1e0255c7e58b87610..f036434a279699f0cb03f836f5e3aa3c130c1b11 100644 |
--- a/remoting/host/security_key/gnubby_auth_handler_linux.cc |
+++ b/remoting/host/security_key/gnubby_auth_handler_linux.cc |
@@ -1,9 +1,6 @@ |
// Copyright 2016 The Chromium Authors. All rights reserved. |
// 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_linux.h" |
- |
#include <stdint.h> |
#include <unistd.h> |
@@ -11,12 +8,17 @@ |
#include "base/files/file_util.h" |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
+#include "base/memory/scoped_ptr.h" |
#include "base/stl_util.h" |
+#include "base/threading/thread_checker.h" |
#include "base/threading/thread_restrictions.h" |
#include "base/values.h" |
+#include "net/base/completion_callback.h" |
#include "net/base/net_errors.h" |
+#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_auth_handler.h" |
#include "remoting/host/security_key/gnubby_socket.h" |
namespace { |
@@ -46,6 +48,67 @@ unsigned int GetCommandCode(const std::string& data) { |
namespace remoting { |
+class GnubbyAuthHandlerLinux : public GnubbyAuthHandler { |
+ public: |
+ GnubbyAuthHandlerLinux(); |
+ ~GnubbyAuthHandlerLinux() override; |
+ |
+ private: |
+ typedef std::map<int, GnubbySocket*> ActiveSockets; |
+ |
+ // GnubbyAuthHandler interface. |
+ void CreateGnubbyConnection() override; |
+ bool IsValidConnectionId(int gnubby_connection_id) const override; |
+ void SendClientResponse(int gnubby_connection_id, |
+ const std::string& response) override; |
+ void SendErrorAndCloseConnection(int gnubby_connection_id) override; |
+ void SetSendMessageCallback(const SendMessageCallback& callback) override; |
+ size_t GetActiveConnectionCountForTest() const override; |
+ void SetRequestTimeoutForTest(const base::TimeDelta& timeout) override; |
+ |
+ // Starts listening for connection. |
+ void DoAccept(); |
+ |
+ // Called when a connection is accepted. |
+ void OnAccepted(int result); |
+ |
+ // Called when a GnubbySocket has done reading. |
+ void OnReadComplete(int gnubby_connection_id); |
+ |
+ // Gets an active socket iterator for |gnubby_connection_id|. |
+ ActiveSockets::const_iterator GetSocketForConnectionId( |
+ int gnubby_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); |
+ |
+ // Ensures GnubbyAuthHandlerLinux methods are called on the same thread. |
+ base::ThreadChecker thread_checker_; |
+ |
+ // Socket used to listen for authorization requests. |
+ scoped_ptr<net::UnixDomainServerSocket> auth_socket_; |
+ |
+ // A temporary holder for an accepted connection. |
+ scoped_ptr<net::StreamSocket> accept_socket_; |
+ |
+ // Used to pass gnubby extension messages to the client. |
+ SendMessageCallback send_message_callback_; |
+ |
+ // The last assigned gnubby connection id. |
+ int last_connection_id_; |
+ |
+ // Sockets by connection id used to process gnubbyd requests. |
+ ActiveSockets active_sockets_; |
+ |
+ // Timeout used for a request. |
+ base::TimeDelta request_timeout_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerLinux); |
+}; |
+ |
scoped_ptr<GnubbyAuthHandler> GnubbyAuthHandler::Create( |
const SendMessageCallback& callback) { |
scoped_ptr<GnubbyAuthHandler> auth_handler(new GnubbyAuthHandlerLinux()); |
@@ -133,7 +196,7 @@ void GnubbyAuthHandlerLinux::SetSendMessageCallback( |
send_message_callback_ = callback; |
} |
-size_t GnubbyAuthHandlerLinux::GetActiveSocketsMapSizeForTest() const { |
+size_t GnubbyAuthHandlerLinux::GetActiveConnectionCountForTest() const { |
return active_sockets_.size(); |
} |