Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS 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 SHILL_OPENVPN_MANAGEMENT_SERVER_ |
| 6 | #define SHILL_OPENVPN_MANAGEMENT_SERVER_ |
| 7 | |
Darin Petkov | 4646302 | 2012-03-29 14:57:32 +0200 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 11 | #include <base/basictypes.h> |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame] | 12 | #include <base/cancelable_callback.h> |
| 13 | #include <base/memory/weak_ptr.h> |
Darin Petkov | 271fe52 | 2012-03-27 13:47:29 +0200 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 15 | |
| 16 | namespace shill { |
| 17 | |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame] | 18 | class EventDispatcher; |
Darin Petkov | 683942b | 2012-03-27 18:00:04 +0200 | [diff] [blame] | 19 | class GLib; |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame] | 20 | class InputData; |
| 21 | class IOHandler; |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 22 | class OpenVPNDriver; |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame] | 23 | class Sockets; |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 24 | |
| 25 | class OpenVPNManagementServer { |
| 26 | public: |
Darin Petkov | 683942b | 2012-03-27 18:00:04 +0200 | [diff] [blame] | 27 | OpenVPNManagementServer(OpenVPNDriver *driver, GLib *glib); |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 28 | virtual ~OpenVPNManagementServer(); |
| 29 | |
Darin Petkov | 4646302 | 2012-03-29 14:57:32 +0200 | [diff] [blame] | 30 | // Returns false on failure. On success, returns true and appends management |
| 31 | // interface openvpn options to |options|. |
| 32 | virtual bool Start(EventDispatcher *dispatcher, |
| 33 | Sockets *sockets, |
| 34 | std::vector<std::string> *options); |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame] | 35 | |
Darin Petkov | 4646302 | 2012-03-29 14:57:32 +0200 | [diff] [blame] | 36 | virtual void Stop(); |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 37 | |
| 38 | private: |
Darin Petkov | 271fe52 | 2012-03-27 13:47:29 +0200 | [diff] [blame] | 39 | friend class OpenVPNManagementServerTest; |
| 40 | FRIEND_TEST(OpenVPNManagementServerTest, OnInput); |
| 41 | FRIEND_TEST(OpenVPNManagementServerTest, OnReady); |
| 42 | FRIEND_TEST(OpenVPNManagementServerTest, OnReadyAcceptFail); |
Darin Petkov | e0d5dd1 | 2012-04-04 16:10:48 +0200 | [diff] [blame] | 43 | FRIEND_TEST(OpenVPNManagementServerTest, ParseNeedPasswordTag); |
Darin Petkov | 683942b | 2012-03-27 18:00:04 +0200 | [diff] [blame] | 44 | FRIEND_TEST(OpenVPNManagementServerTest, PerformStaticChallenge); |
| 45 | FRIEND_TEST(OpenVPNManagementServerTest, PerformStaticChallengeNoCreds); |
Darin Petkov | 0440b9b | 2012-04-17 16:11:56 +0200 | [diff] [blame] | 46 | FRIEND_TEST(OpenVPNManagementServerTest, ProcessFailedPasswordMessage); |
Darin Petkov | 271fe52 | 2012-03-27 13:47:29 +0200 | [diff] [blame] | 47 | FRIEND_TEST(OpenVPNManagementServerTest, ProcessInfoMessage); |
| 48 | FRIEND_TEST(OpenVPNManagementServerTest, ProcessMessage); |
Darin Petkov | 683942b | 2012-03-27 18:00:04 +0200 | [diff] [blame] | 49 | FRIEND_TEST(OpenVPNManagementServerTest, ProcessNeedPasswordMessageAuthSC); |
Darin Petkov | e0d5dd1 | 2012-04-04 16:10:48 +0200 | [diff] [blame] | 50 | FRIEND_TEST(OpenVPNManagementServerTest, ProcessNeedPasswordMessageTPMToken); |
| 51 | FRIEND_TEST(OpenVPNManagementServerTest, ProcessNeedPasswordMessageUnknown); |
Darin Petkov | 271fe52 | 2012-03-27 13:47:29 +0200 | [diff] [blame] | 52 | FRIEND_TEST(OpenVPNManagementServerTest, ProcessStateMessage); |
| 53 | FRIEND_TEST(OpenVPNManagementServerTest, Send); |
Darin Petkov | 683942b | 2012-03-27 18:00:04 +0200 | [diff] [blame] | 54 | FRIEND_TEST(OpenVPNManagementServerTest, SendPassword); |
Darin Petkov | 271fe52 | 2012-03-27 13:47:29 +0200 | [diff] [blame] | 55 | FRIEND_TEST(OpenVPNManagementServerTest, SendState); |
Darin Petkov | 683942b | 2012-03-27 18:00:04 +0200 | [diff] [blame] | 56 | FRIEND_TEST(OpenVPNManagementServerTest, SendUsername); |
Darin Petkov | 271fe52 | 2012-03-27 13:47:29 +0200 | [diff] [blame] | 57 | FRIEND_TEST(OpenVPNManagementServerTest, Start); |
| 58 | FRIEND_TEST(OpenVPNManagementServerTest, Stop); |
Darin Petkov | e0d5dd1 | 2012-04-04 16:10:48 +0200 | [diff] [blame] | 59 | FRIEND_TEST(OpenVPNManagementServerTest, SupplyTPMToken); |
| 60 | FRIEND_TEST(OpenVPNManagementServerTest, SupplyTPMTokenNoPIN); |
Darin Petkov | 271fe52 | 2012-03-27 13:47:29 +0200 | [diff] [blame] | 61 | |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame] | 62 | // IO handler callbacks. |
| 63 | void OnReady(int fd); |
| 64 | void OnInput(InputData *data); |
| 65 | |
| 66 | void Send(const std::string &data); |
| 67 | void SendState(const std::string &state); |
Darin Petkov | 683942b | 2012-03-27 18:00:04 +0200 | [diff] [blame] | 68 | void SendUsername(const std::string &tag, const std::string &username); |
| 69 | void SendPassword(const std::string &tag, const std::string &password); |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame] | 70 | |
| 71 | void ProcessMessage(const std::string &message); |
Darin Petkov | 271fe52 | 2012-03-27 13:47:29 +0200 | [diff] [blame] | 72 | bool ProcessInfoMessage(const std::string &message); |
| 73 | bool ProcessNeedPasswordMessage(const std::string &message); |
| 74 | bool ProcessFailedPasswordMessage(const std::string &message); |
| 75 | bool ProcessStateMessage(const std::string &message); |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame] | 76 | |
Darin Petkov | e0d5dd1 | 2012-04-04 16:10:48 +0200 | [diff] [blame] | 77 | void PerformStaticChallenge(const std::string &tag); |
| 78 | void SupplyTPMToken(const std::string &tag); |
| 79 | |
| 80 | static std::string ParseNeedPasswordTag(const std::string &message); |
Darin Petkov | 683942b | 2012-03-27 18:00:04 +0200 | [diff] [blame] | 81 | |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 82 | OpenVPNDriver *driver_; |
Darin Petkov | 683942b | 2012-03-27 18:00:04 +0200 | [diff] [blame] | 83 | GLib *glib_; |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame] | 84 | base::WeakPtrFactory<OpenVPNManagementServer> weak_ptr_factory_; |
| 85 | base::Callback<void(int)> ready_callback_; |
| 86 | base::Callback<void(InputData *)> input_callback_; |
| 87 | |
| 88 | Sockets *sockets_; |
| 89 | int socket_; |
| 90 | scoped_ptr<IOHandler> ready_handler_; |
| 91 | EventDispatcher *dispatcher_; |
| 92 | int connected_socket_; |
| 93 | scoped_ptr<IOHandler> input_handler_; |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 94 | |
| 95 | DISALLOW_COPY_AND_ASSIGN(OpenVPNManagementServer); |
| 96 | }; |
| 97 | |
| 98 | } // namespace shill |
| 99 | |
| 100 | #endif // SHILL_OPENVPN_MANAGEMENT_SERVER_ |