From c0b7805c73c6641d787a682708fcee3c95da0a0b Mon Sep 17 00:00:00 2001 From: klzgrad Date: Wed, 12 Dec 2018 23:22:18 -0500 Subject: [PATCH] QUIC WIP 1 --- net/socket/client_socket_pool_manager.cc | 2 +- net/tools/naive/naive_proxy.cc | 4 ++ net/tools/naive/naive_proxy_bin.cc | 59 +++++++++++++++--------- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/net/socket/client_socket_pool_manager.cc b/net/socket/client_socket_pool_manager.cc index d25b67c819..5422cc75ad 100644 --- a/net/socket/client_socket_pool_manager.cc +++ b/net/socket/client_socket_pool_manager.cc @@ -243,7 +243,7 @@ int InitSocketPoolHelper(ClientSocketPoolManager::SocketGroupType group_type, // Finally, get the connection started. - if (proxy_info.is_http() || proxy_info.is_https()) { + if (proxy_info.is_http() || proxy_info.is_https() || proxy_info.is_quic()) { HttpProxyClientSocketPool* pool = session->GetSocketPoolForHTTPProxy(socket_pool_type, *proxy_host_port); if (num_preconnect_streams) { diff --git a/net/tools/naive/naive_proxy.cc b/net/tools/naive/naive_proxy.cc index f202391637..94f41aa1f2 100644 --- a/net/tools/naive/naive_proxy.cc +++ b/net/tools/naive/naive_proxy.cc @@ -90,6 +90,7 @@ void NaiveProxy::DoConnect() { } else { return; } + pad_direction = NaiveConnection::kNone; auto connection_ptr = std::make_unique( ++last_id_, pad_direction, std::move(socket), this, traffic_annotation_); auto* connection = connection_ptr.get(); @@ -149,6 +150,9 @@ int NaiveProxy::OnConnectServer(unsigned int connection_id, << request_endpoint.ToString(); auto quic_version = quic::QUIC_VERSION_UNSUPPORTED; + if (proxy_info.is_quic()) { + quic_version = quic::QUIC_VERSION_43; + } return InitSocketHandleForRawConnect2( request_endpoint, session_, request_load_flags, request_priority, diff --git a/net/tools/naive/naive_proxy_bin.cc b/net/tools/naive/naive_proxy_bin.cc index e5754cc881..690bdd7dd5 100644 --- a/net/tools/naive/naive_proxy_bin.cc +++ b/net/tools/naive/naive_proxy_bin.cc @@ -51,6 +51,8 @@ #include "net/url_request/url_request_context_builder.h" #include "url/gurl.h" #include "url/scheme_host_port.h" +#include "base/strings/strcat.h" +#include "base/strings/string_util.h" #if defined(OS_MACOSX) #include "base/mac/scoped_nsautorelease_pool.h" @@ -72,6 +74,7 @@ struct Params { net::NaiveProxy::Protocol protocol; bool use_proxy; std::string proxy_url; + bool is_quic; std::string proxy_user; std::string proxy_pass; std::string host_resolver_rules; @@ -113,7 +116,11 @@ std::unique_ptr BuildURLRequestContext( net::ProxyConfig proxy_config; if (params.use_proxy) { - proxy_config.proxy_rules().ParseFromString(params.proxy_url); + std::string proxy_url = params.proxy_url; + if (params.is_quic) { + proxy_url = base::StrCat({"quic://", proxy_url.substr(sizeof("https://") - 1)}); + } + proxy_config.proxy_rules().ParseFromString(proxy_url); } auto proxy_service = net::ProxyResolutionService::CreateWithoutProxyResolver( std::make_unique( @@ -131,7 +138,7 @@ std::unique_ptr BuildURLRequestContext( auto context = builder.Build(); - if (params.use_proxy) { + if (params.use_proxy && !params.proxy_user.empty() && !params.proxy_pass.empty()) { net::HttpNetworkSession* session = context->http_transaction_factory()->GetSession(); net::HttpAuthCache* auth_cache = session->http_auth_cache(); @@ -155,10 +162,10 @@ bool ParseCommandLineFlags(Params* params) { "Options:\n" "-h, --help Show this message\n" "--version Print version\n" + "--proto=[socks|http] Protocol to accept (socks)\n" "--addr=
Address to listen on (0.0.0.0)\n" "--port= Port to listen on (1080)\n" - "--proto=[socks|http] Protocol to accept (socks)\n" - "--proxy=https://:@[:]\n" + "--proxy=[https|quic]://:@[:]\n" " Proxy specification.\n" "--log Log to stderr, otherwise no log\n" "--log-net-log= Save NetLog\n" @@ -173,7 +180,24 @@ bool ParseCommandLineFlags(Params* params) { return false; } - params->listen_addr = "0.0.0.0"; + params->protocol = net::NaiveProxy::kSocks5; + if (line.HasSwitch("proto")) { + const auto& proto = line.GetSwitchValueASCII("proto"); + if (proto == "socks") { + params->protocol = net::NaiveProxy::kSocks5; + } else if (proto == "http") { + params->protocol = net::NaiveProxy::kHttp; + } else { + LOG(ERROR) << "Invalid --proto"; + return false; + } + } + + if (params->protocol == net::NaiveProxy::kSocks5) { + params->listen_addr = "0.0.0.0"; + } else { + params->listen_addr = "127.0.0.1"; + } if (line.HasSwitch("addr")) { params->listen_addr = line.GetSwitchValueASCII("addr"); } @@ -196,21 +220,14 @@ bool ParseCommandLineFlags(Params* params) { } } - params->protocol = net::NaiveProxy::kSocks5; - if (line.HasSwitch("proto")) { - const auto& proto = line.GetSwitchValueASCII("proto"); - if (proto == "socks") { - params->protocol = net::NaiveProxy::kSocks5; - } else if (proto == "http") { - params->protocol = net::NaiveProxy::kHttp; - } else { - LOG(ERROR) << "Invalid --proto"; - return false; - } - } - params->use_proxy = false; - GURL url(line.GetSwitchValueASCII("proxy")); + params->is_quic = false; + std::string proxy_str = line.GetSwitchValueASCII("proxy"); + if (base::StartsWith(proxy_str, "quic://", base::CompareCase::SENSITIVE)) { + proxy_str = base::StrCat({"https://", proxy_str.substr(sizeof("quic://") - 1)}); + params->is_quic = true; + } + GURL url(proxy_str); if (line.HasSwitch("proxy")) { params->use_proxy = true; if (!url.is_valid()) { @@ -221,10 +238,6 @@ bool ParseCommandLineFlags(Params* params) { LOG(ERROR) << "Must be HTTPS proxy"; return false; } - if (url.username().empty() || url.password().empty()) { - LOG(ERROR) << "Missing user or pass"; - return false; - } params->proxy_url = url::SchemeHostPort(url).Serialize(); params->proxy_user = url.username(); params->proxy_pass = url.password();