Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 1 | // Copyright 2020 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 | #ifndef SYSTEM_PROXY_SYSTEM_PROXY_ADAPTOR_H_ |
| 5 | #define SYSTEM_PROXY_SYSTEM_PROXY_ADAPTOR_H_ |
| 6 | |
| 7 | #include <memory> |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 8 | #include <string> |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 11 | #include <base/memory/weak_ptr.h> |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 12 | #include <brillo/dbus/async_event_sequencer.h> |
Andreea Costinas | 5862b10 | 2020-03-19 14:45:36 +0100 | [diff] [blame] | 13 | #include <brillo/http/http_proxy.h> |
Andreea Costinas | 41e0644 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 15 | #include <patchpanel/proto_bindings/patchpanel_service.pb.h> |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 16 | |
| 17 | #include "system_proxy/org.chromium.SystemProxy.h" |
| 18 | |
| 19 | namespace brillo { |
| 20 | namespace dbus_utils { |
| 21 | class DBusObject; |
| 22 | } |
| 23 | |
| 24 | } // namespace brillo |
| 25 | |
| 26 | namespace system_proxy { |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 27 | |
Andreea Costinas | 922fbaf | 2020-05-28 11:55:22 +0200 | [diff] [blame^] | 28 | class KerberosClient; |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 29 | class SandboxedWorker; |
| 30 | |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 31 | // Implementation of the SystemProxy D-Bus interface. |
| 32 | class SystemProxyAdaptor : public org::chromium::SystemProxyAdaptor, |
| 33 | public org::chromium::SystemProxyInterface { |
| 34 | public: |
| 35 | explicit SystemProxyAdaptor( |
| 36 | std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object); |
| 37 | SystemProxyAdaptor(const SystemProxyAdaptor&) = delete; |
| 38 | SystemProxyAdaptor& operator=(const SystemProxyAdaptor&) = delete; |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 39 | virtual ~SystemProxyAdaptor(); |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 40 | |
| 41 | // Registers the D-Bus object and interfaces. |
| 42 | void RegisterAsync( |
| 43 | const brillo::dbus_utils::AsyncEventSequencer::CompletionAction& |
| 44 | completion_callback); |
| 45 | |
| 46 | // org::chromium::SystemProxyInterface: (see org.chromium.SystemProxy.xml). |
Andreea Costinas | 77b180e | 2020-05-12 15:17:32 +0200 | [diff] [blame] | 47 | std::vector<uint8_t> SetAuthenticationDetails( |
| 48 | const std::vector<uint8_t>& request_blob) override; |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 49 | std::vector<uint8_t> SetSystemTrafficCredentials( |
| 50 | const std::vector<uint8_t>& request_blob) override; |
| 51 | std::vector<uint8_t> ShutDown() override; |
| 52 | |
Andreea Costinas | 5862b10 | 2020-03-19 14:45:36 +0100 | [diff] [blame] | 53 | void GetChromeProxyServersAsync( |
| 54 | const std::string& target_url, |
| 55 | const brillo::http::GetChromeProxyServersCallback& callback); |
| 56 | |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 57 | protected: |
| 58 | virtual std::unique_ptr<SandboxedWorker> CreateWorker(); |
Andreea Costinas | edb7c8e | 2020-04-22 10:58:04 +0200 | [diff] [blame] | 59 | virtual bool ConnectNamespace(SandboxedWorker* worker, bool user_traffic); |
Andreea Costinas | a89309d | 2020-05-08 15:51:12 +0200 | [diff] [blame] | 60 | // Triggers the |WorkerActive| signal. |
| 61 | void OnNamespaceConnected(SandboxedWorker* worker, bool user_traffic); |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 62 | |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 63 | private: |
Andreea Costinas | 41e0644 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 64 | friend class SystemProxyAdaptorTest; |
Andreea Costinas | 77b180e | 2020-05-12 15:17:32 +0200 | [diff] [blame] | 65 | FRIEND_TEST(SystemProxyAdaptorTest, SetAuthenticationDetails); |
Andreea Costinas | 41e0644 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 66 | FRIEND_TEST(SystemProxyAdaptorTest, SetSystemTrafficCredentials); |
Andreea Costinas | 922fbaf | 2020-05-28 11:55:22 +0200 | [diff] [blame^] | 67 | FRIEND_TEST(SystemProxyAdaptorTest, KerberosEnabled); |
Andreea Costinas | 41e0644 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 68 | FRIEND_TEST(SystemProxyAdaptorTest, ShutDown); |
Andreea Costinas | a89309d | 2020-05-08 15:51:12 +0200 | [diff] [blame] | 69 | FRIEND_TEST(SystemProxyAdaptorTest, ConnectNamespace); |
| 70 | FRIEND_TEST(SystemProxyAdaptorTest, ProxyResolutionFilter); |
Andreea Costinas | 41e0644 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 71 | |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 72 | void SetCredentialsTask(SandboxedWorker* worker, |
| 73 | const std::string& username, |
| 74 | const std::string& password); |
| 75 | |
Andreea Costinas | 922fbaf | 2020-05-28 11:55:22 +0200 | [diff] [blame^] | 76 | void SetKerberosEnabledTask(SandboxedWorker* worker, |
| 77 | bool kerberos_enabled, |
| 78 | const std::string& principal_name); |
| 79 | |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 80 | void ShutDownTask(); |
| 81 | |
Andreea Costinas | edb7c8e | 2020-04-22 10:58:04 +0200 | [diff] [blame] | 82 | bool StartWorker(SandboxedWorker* worker, bool user_traffic); |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 83 | |
Andreea Costinas | 77b180e | 2020-05-12 15:17:32 +0200 | [diff] [blame] | 84 | // Checks if a worker process exists and if not creates one and sends a |
| 85 | // request to patchpanel to setup the network namespace for it. Returns true |
| 86 | // if the worker exists or was created successfully, false otherwise. |
| 87 | bool CreateWorkerIfNeeded(bool user_traffic); |
| 88 | |
Andreea Costinas | a89309d | 2020-05-08 15:51:12 +0200 | [diff] [blame] | 89 | // Called when the patchpanel D-Bus service becomes available. |
Andreea Costinas | edb7c8e | 2020-04-22 10:58:04 +0200 | [diff] [blame] | 90 | void OnPatchpanelServiceAvailable(bool is_available); |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 91 | |
Andreea Costinas | 5862b10 | 2020-03-19 14:45:36 +0100 | [diff] [blame] | 92 | // The callback of |GetChromeProxyServersAsync|. |
| 93 | void OnGetProxyServers(bool success, const std::vector<std::string>& servers); |
| 94 | |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 95 | // Worker that authenticates and forwards to a remote web proxy traffic |
| 96 | // coming form Chrome OS system services. |
| 97 | std::unique_ptr<SandboxedWorker> system_services_worker_; |
| 98 | // Worker that authenticates and forwards to a remote web proxy traffic |
| 99 | // coming form ARC++ apps. |
| 100 | std::unique_ptr<SandboxedWorker> arc_worker_; |
Andreea Costinas | 922fbaf | 2020-05-28 11:55:22 +0200 | [diff] [blame^] | 101 | std::unique_ptr<KerberosClient> kerberos_client_; |
| 102 | |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 103 | std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_; |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 104 | base::WeakPtrFactory<SystemProxyAdaptor> weak_ptr_factory_; |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | } // namespace system_proxy |
| 108 | #endif // SYSTEM_PROXY_SYSTEM_PROXY_ADAPTOR_H_ |