| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_HOST_SECURITY_KEY_GNUBBY_AUTH_HANDLER_LINUX_H_ | |
| 6 #define REMOTING_HOST_SECURITY_KEY_GNUBBY_AUTH_HANDLER_LINUX_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/threading/thread_checker.h" | |
| 16 #include "net/base/completion_callback.h" | |
| 17 #include "net/socket/stream_socket.h" | |
| 18 #include "remoting/host/security_key/gnubby_auth_handler.h" | |
| 19 | |
| 20 namespace net { | |
| 21 class UnixDomainServerSocket; | |
| 22 } // namespace net | |
| 23 | |
| 24 namespace remoting { | |
| 25 | |
| 26 class GnubbySocket; | |
| 27 | |
| 28 class GnubbyAuthHandlerLinux : public GnubbyAuthHandler { | |
| 29 public: | |
| 30 GnubbyAuthHandlerLinux(); | |
| 31 ~GnubbyAuthHandlerLinux() override; | |
| 32 | |
| 33 size_t GetActiveSocketsMapSizeForTest() const; | |
| 34 | |
| 35 void SetRequestTimeoutForTest(const base::TimeDelta& timeout); | |
| 36 | |
| 37 private: | |
| 38 typedef std::map<int, GnubbySocket*> ActiveSockets; | |
| 39 | |
| 40 // GnubbyAuthHandler interface. | |
| 41 void CreateGnubbyConnection() override; | |
| 42 bool IsValidConnectionId(int gnubby_connection_id) const override; | |
| 43 void SendClientResponse(int gnubby_connection_id, | |
| 44 const std::string& response) override; | |
| 45 void SendErrorAndCloseConnection(int gnubby_connection_id) override; | |
| 46 void SetSendMessageCallback(const SendMessageCallback& callback) override; | |
| 47 | |
| 48 // Starts listening for connection. | |
| 49 void DoAccept(); | |
| 50 | |
| 51 // Called when a connection is accepted. | |
| 52 void OnAccepted(int result); | |
| 53 | |
| 54 // Called when a GnubbySocket has done reading. | |
| 55 void OnReadComplete(int gnubby_connection_id); | |
| 56 | |
| 57 // Gets an active socket iterator for |gnubby_connection_id|. | |
| 58 ActiveSockets::const_iterator GetSocketForConnectionId( | |
| 59 int gnubby_connection_id) const; | |
| 60 | |
| 61 // Send an error and closes an active socket. | |
| 62 void SendErrorAndCloseActiveSocket(const ActiveSockets::const_iterator& iter); | |
| 63 | |
| 64 // A request timed out. | |
| 65 void RequestTimedOut(int gnubby_connection_id); | |
| 66 | |
| 67 // Ensures GnubbyAuthHandlerLinux methods are called on the same thread. | |
| 68 base::ThreadChecker thread_checker_; | |
| 69 | |
| 70 // Socket used to listen for authorization requests. | |
| 71 scoped_ptr<net::UnixDomainServerSocket> auth_socket_; | |
| 72 | |
| 73 // A temporary holder for an accepted connection. | |
| 74 scoped_ptr<net::StreamSocket> accept_socket_; | |
| 75 | |
| 76 // Used to pass gnubby extension messages to the client. | |
| 77 SendMessageCallback send_message_callback_; | |
| 78 | |
| 79 // The last assigned gnubby connection id. | |
| 80 int last_connection_id_; | |
| 81 | |
| 82 // Sockets by connection id used to process gnubbyd requests. | |
| 83 ActiveSockets active_sockets_; | |
| 84 | |
| 85 // Timeout used for a request. | |
| 86 base::TimeDelta request_timeout_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerLinux); | |
| 89 }; | |
| 90 | |
| 91 } // namespace remoting | |
| 92 | |
| 93 #endif // REMOTING_HOST_SECURITY_KEY_GNUBBY_AUTH_HANDLER_LINUX_H_ | |
| OLD | NEW |