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