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 | |
| 28 | class SandboxedWorker; |
| 29 | |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 30 | // Implementation of the SystemProxy D-Bus interface. |
| 31 | class SystemProxyAdaptor : public org::chromium::SystemProxyAdaptor, |
| 32 | public org::chromium::SystemProxyInterface { |
| 33 | public: |
| 34 | explicit SystemProxyAdaptor( |
| 35 | std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object); |
| 36 | SystemProxyAdaptor(const SystemProxyAdaptor&) = delete; |
| 37 | SystemProxyAdaptor& operator=(const SystemProxyAdaptor&) = delete; |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 38 | virtual ~SystemProxyAdaptor(); |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 39 | |
| 40 | // Registers the D-Bus object and interfaces. |
| 41 | void RegisterAsync( |
| 42 | const brillo::dbus_utils::AsyncEventSequencer::CompletionAction& |
| 43 | completion_callback); |
| 44 | |
| 45 | // org::chromium::SystemProxyInterface: (see org.chromium.SystemProxy.xml). |
| 46 | std::vector<uint8_t> SetSystemTrafficCredentials( |
| 47 | const std::vector<uint8_t>& request_blob) override; |
| 48 | std::vector<uint8_t> ShutDown() override; |
| 49 | |
Andreea Costinas | 5862b10 | 2020-03-19 14:45:36 +0100 | [diff] [blame] | 50 | void GetChromeProxyServersAsync( |
| 51 | const std::string& target_url, |
| 52 | const brillo::http::GetChromeProxyServersCallback& callback); |
| 53 | |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 54 | protected: |
| 55 | virtual std::unique_ptr<SandboxedWorker> CreateWorker(); |
Andreea Costinas | edb7c8e | 2020-04-22 10:58:04 +0200 | [diff] [blame] | 56 | virtual bool ConnectNamespace(SandboxedWorker* worker, bool user_traffic); |
Andreea Costinas | a89309d | 2020-05-08 15:51:12 +0200 | [diff] [blame] | 57 | // Triggers the |WorkerActive| signal. |
| 58 | void OnNamespaceConnected(SandboxedWorker* worker, bool user_traffic); |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 59 | |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 60 | private: |
Andreea Costinas | 41e0644 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 61 | friend class SystemProxyAdaptorTest; |
| 62 | FRIEND_TEST(SystemProxyAdaptorTest, SetSystemTrafficCredentials); |
| 63 | FRIEND_TEST(SystemProxyAdaptorTest, ShutDown); |
Andreea Costinas | a89309d | 2020-05-08 15:51:12 +0200 | [diff] [blame] | 64 | FRIEND_TEST(SystemProxyAdaptorTest, ConnectNamespace); |
| 65 | FRIEND_TEST(SystemProxyAdaptorTest, ProxyResolutionFilter); |
Andreea Costinas | 41e0644 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 66 | |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 67 | void SetCredentialsTask(SandboxedWorker* worker, |
| 68 | const std::string& username, |
| 69 | const std::string& password); |
| 70 | |
| 71 | void ShutDownTask(); |
| 72 | |
Andreea Costinas | edb7c8e | 2020-04-22 10:58:04 +0200 | [diff] [blame] | 73 | bool StartWorker(SandboxedWorker* worker, bool user_traffic); |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 74 | |
Andreea Costinas | a89309d | 2020-05-08 15:51:12 +0200 | [diff] [blame] | 75 | // Called when the patchpanel D-Bus service becomes available. |
Andreea Costinas | edb7c8e | 2020-04-22 10:58:04 +0200 | [diff] [blame] | 76 | void OnPatchpanelServiceAvailable(bool is_available); |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 77 | |
Andreea Costinas | 5862b10 | 2020-03-19 14:45:36 +0100 | [diff] [blame] | 78 | // The callback of |GetChromeProxyServersAsync|. |
| 79 | void OnGetProxyServers(bool success, const std::vector<std::string>& servers); |
| 80 | |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 81 | // Worker that authenticates and forwards to a remote web proxy traffic |
| 82 | // coming form Chrome OS system services. |
| 83 | std::unique_ptr<SandboxedWorker> system_services_worker_; |
| 84 | // Worker that authenticates and forwards to a remote web proxy traffic |
| 85 | // coming form ARC++ apps. |
| 86 | std::unique_ptr<SandboxedWorker> arc_worker_; |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 87 | std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_; |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 88 | base::WeakPtrFactory<SystemProxyAdaptor> weak_ptr_factory_; |
Andreea Costinas | 942284d | 2020-01-28 16:28:40 +0100 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace system_proxy |
| 92 | #endif // SYSTEM_PROXY_SYSTEM_PROXY_ADAPTOR_H_ |