system-proxy: Accept CONNECT requests
This CL enables workers to process proxy CONNECT requests.
It extracts the url from the incoming request and sets up a
connection to the remote proxy using curl for
authentication.
BUG=chromium:1042626
TEST=unittests
Change-Id: Iebbed5a8229f17aa0f13fb2c7413e084bf276051
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2106136
Reviewed-by: Pavol Marko <pmarko@chromium.org>
Tested-by: Andreea-Elena Costinas <acostinas@google.com>
Commit-Queue: Andreea-Elena Costinas <acostinas@google.com>
diff --git a/system-proxy/curl_socket.h b/system-proxy/curl_socket.h
new file mode 100644
index 0000000..99a22a5
--- /dev/null
+++ b/system-proxy/curl_socket.h
@@ -0,0 +1,38 @@
+// Copyright 2020 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#ifndef SYSTEM_PROXY_CURL_SOCKET_H_
+#define SYSTEM_PROXY_CURL_SOCKET_H_
+
+#include <memory>
+
+#include <curl/curl.h>
+#include <curl/easy.h>
+
+#include <arc/network/socket.h>
+#include <base/files/scoped_file.h>
+
+namespace system_proxy {
+
+// Frees the resources allocated by curl_easy_init.
+struct FreeCurlEasyhandle {
+ void operator()(CURL* ptr) const { curl_easy_cleanup(ptr); }
+};
+
+typedef std::unique_ptr<CURL, FreeCurlEasyhandle> ScopedCurlEasyhandle;
+
+// CurlSocket wraps a socket opened by curl in an arc_networkd::Socket object
+// with an owned CURL handle.
+class CurlSocket : public arc_networkd::Socket {
+ public:
+ CurlSocket(base::ScopedFD fd, ScopedCurlEasyhandle curl_easyhandle);
+ CurlSocket(const CurlSocket&) = delete;
+ CurlSocket& operator=(const CurlSocket&) = delete;
+ ~CurlSocket() override;
+
+ private:
+ ScopedCurlEasyhandle curl_easyhandle_;
+};
+} // namespace system_proxy
+
+#endif // SYSTEM_PROXY_CURL_SOCKET_H_