From 0c97a7fc50e25a9ff6689f1db30b7de0bedc23e1 Mon Sep 17 00:00:00 2001 From: klzgrad Date: Mon, 14 Jan 2019 22:13:26 -0500 Subject: [PATCH] Fix option parsing Fix parsing of socks://ip:port, which got parsed to socks://ip. Also, path cleanup in CI configs. Use prebuilt gn binaries for all platforms, which failed to build on MacOS for unclear reason. --- .appveyor.yml | 9 ++--- .travis.yml | 9 ++--- src/get-clang.sh | 33 +++++------------ src/net/tools/naive/naive_proxy_bin.cc | 51 ++++++++++++++++++-------- 4 files changed, 54 insertions(+), 48 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 93f2a8c386..3b4e2b1e62 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -7,14 +7,13 @@ cache: - '%LOCALAPPDATA%\Mozilla\sccache' build_script: - bash ./tools/import-upstream.sh - - cd src - - bash ./get-clang.sh + - bash -c 'cd src; ./get-clang.sh' - bash -c '~/.cargo/bin/sccache -s' - - bash ./build.sh + - bash -c 'cd src; ./build.sh' - bash -c '~/.cargo/bin/sccache -s' - bash -c 'mkdir naive-$APPVEYOR_REPO_TAG_NAME-win64' - - bash -c 'cp out/Release/naive.exe config.json LICENSE naive-$APPVEYOR_REPO_TAG_NAME-win64/' - - bash -c '7z a ../naive-$APPVEYOR_REPO_TAG_NAME-win64.zip naive-$APPVEYOR_REPO_TAG_NAME-win64/' + - bash -c 'cp src/out/Release/naive.exe src/config.json LICENSE naive-$APPVEYOR_REPO_TAG_NAME-win64/' + - bash -c '7z a naive-$APPVEYOR_REPO_TAG_NAME-win64.zip naive-$APPVEYOR_REPO_TAG_NAME-win64/' test: off artifacts: - path: naive-$(APPVEYOR_REPO_TAG_NAME)-win64.zip diff --git a/.travis.yml b/.travis.yml index 37aab0ab02..091fa1b9b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,13 +18,12 @@ addons: cache: ccache script: - ./tools/import-upstream.sh - - cd src - - ./get-clang.sh + - ( cd src; ./get-clang.sh ) - ccache -s - - ./build.sh + - ( cd src; ./build.sh ) - mkdir naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME - - cp out/Release/naive config.json LICENSE naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME/ - - tar cJf ../naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME.tar.xz naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME/ + - cp src/out/Release/naive src/config.json LICENSE naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME/ + - tar cJf naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME.tar.xz naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME/ deploy: provider: releases api_key: diff --git a/src/get-clang.sh b/src/get-clang.sh index c1c3252f5d..1d3396f743 100755 --- a/src/get-clang.sh +++ b/src/get-clang.sh @@ -19,14 +19,14 @@ case "$ARCH" in esac if [ ! -d third_party/llvm-build/Release+Asserts/bin ]; then mkdir -p third_party/llvm-build/Release+Asserts - curl "$clang_url" -o- | tar xzf - -C third_party/llvm-build/Release+Asserts + curl "$clang_url" | tar xzf - -C third_party/llvm-build/Release+Asserts fi # AFDO profile (Linux) if [ "$ARCH" = Linux -a ! -f chrome/android/profiles/afdo.prof ]; then AFDO_PATH=$(cat chrome/android/profiles/newest.txt) afdo_url="https://storage.googleapis.com/chromeos-prebuilt/afdo-job/llvm/$AFDO_PATH" - curl "$afdo_url" -o- | bzip2 -cd >chrome/android/profiles/afdo.prof + curl "$afdo_url" | bzip2 -cd >chrome/android/profiles/afdo.prof fi # sccache (Windows) @@ -43,25 +43,12 @@ fi # gn if [ ! -f gn/out/gn ]; then - if [ "$CI" -o "$ARCH" = Windows ]; then - mkdir -p gn/out - cd gn/out - case "$ARCH" in - Linux) curl -L https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest -o gn.zip;; - Darwin) curl -L https://chrome-infra-packages.appspot.com/dl/gn/gn/mac-amd64/+/latest -o gn.zip;; - Windows) curl -L https://chrome-infra-packages.appspot.com/dl/gn/gn/windows-amd64/+/latest -o gn.zip;; - esac - unzip gn.zip - else - rm -rf gn - git clone --single-branch https://gn.googlesource.com/gn - export PATH="$PWD/third_party/llvm-build/Release+Asserts/bin:$PATH" - cd gn - if which ccache >/dev/null 2>&1; then - export CC='ccache clang' CXX='ccache clang++' CCACHE_BASEDIR="$PWD" - fi - python2=$(which python2 2>/dev/null || which python 2>/dev/null) - $python2 build/gen.py - ninja -C out gn - fi + mkdir -p gn/out + cd gn/out + case "$ARCH" in + Linux) curl -L https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest -o gn.zip;; + Darwin) curl -L https://chrome-infra-packages.appspot.com/dl/gn/gn/mac-amd64/+/latest -o gn.zip;; + Windows) curl -L https://chrome-infra-packages.appspot.com/dl/gn/gn/windows-amd64/+/latest -o gn.zip;; + esac + unzip gn.zip fi diff --git a/src/net/tools/naive/naive_proxy_bin.cc b/src/net/tools/naive/naive_proxy_bin.cc index 3df53890f7..997065aca0 100644 --- a/src/net/tools/naive/naive_proxy_bin.cc +++ b/src/net/tools/naive/naive_proxy_bin.cc @@ -128,6 +128,7 @@ std::unique_ptr BuildURLRequestContext( net::ProxyConfig proxy_config; proxy_config.proxy_rules().ParseFromString(params.proxy_url); + LOG(INFO) << "Proxying via " << params.proxy_url; auto proxy_service = net::ProxyResolutionService::CreateWithoutProxyResolver( std::make_unique( net::ProxyConfigWithAnnotation(proxy_config, kTrafficAnnotation)), @@ -187,20 +188,23 @@ void GetCommandLine(const base::CommandLine& proc, CommandLine* cmdline) { cmdline->listen = proc.GetSwitchValueASCII("listen"); cmdline->proxy = proc.GetSwitchValueASCII("proxy"); cmdline->padding = proc.HasSwitch("padding"); - cmdline->host_resolver_rules = proc.GetSwitchValueASCII("host-resolver-rules"); + cmdline->host_resolver_rules = + proc.GetSwitchValueASCII("host-resolver-rules"); cmdline->no_log = !proc.HasSwitch("log"); cmdline->log = proc.GetSwitchValuePath("log"); cmdline->log_net_log = proc.GetSwitchValuePath("log-net-log"); cmdline->ssl_key_log_file = proc.GetSwitchValuePath("ssl-key-log-file"); } -void GetCommandLineFromConfig(const base::FilePath& config_path, CommandLine* cmdline) { +void GetCommandLineFromConfig(const base::FilePath& config_path, + CommandLine* cmdline) { JSONFileValueDeserializer reader(config_path); int error_code; std::string error_message; auto value = reader.Deserialize(&error_code, &error_message); if (value == nullptr) { - std::cerr << "Error reading " << config_path << ": (" << error_code << ") " << error_message << std::endl; + std::cerr << "Error reading " << config_path << ": (" << error_code << ") " + << error_message << std::endl; exit(EXIT_FAILURE); } if (!value->is_dict()) { @@ -218,18 +222,32 @@ void GetCommandLineFromConfig(const base::FilePath& config_path, CommandLine* cm cmdline->padding = value->FindKey("padding")->GetBool(); } if (value->FindKeyOfType("host-resolver-rules", base::Value::Type::STRING)) { - cmdline->host_resolver_rules = value->FindKey("host-resolver-rules")->GetString(); + cmdline->host_resolver_rules = + value->FindKey("host-resolver-rules")->GetString(); } cmdline->no_log = true; if (value->FindKeyOfType("log", base::Value::Type::STRING)) { cmdline->no_log = false; - cmdline->log = base::FilePath::FromUTF8Unsafe(value->FindKey("log")->GetString()); + cmdline->log = + base::FilePath::FromUTF8Unsafe(value->FindKey("log")->GetString()); } if (value->FindKeyOfType("log-net-log", base::Value::Type::STRING)) { - cmdline->log_net_log = base::FilePath::FromUTF8Unsafe(value->FindKey("log-net-log")->GetString()); + cmdline->log_net_log = base::FilePath::FromUTF8Unsafe( + value->FindKey("log-net-log")->GetString()); } if (value->FindKeyOfType("ssl-key-log-file", base::Value::Type::STRING)) { - cmdline->ssl_key_log_file = base::FilePath::FromUTF8Unsafe(value->FindKey("ssl-key-log-file")->GetString()); + cmdline->ssl_key_log_file = base::FilePath::FromUTF8Unsafe( + value->FindKey("ssl-key-log-file")->GetString()); + } +} + +std::string GetProxyFromURL(const GURL& url) { + auto shp = url::SchemeHostPort(url); + if (url::DefaultPortForScheme(shp.scheme().c_str(), shp.scheme().size()) == + url::PORT_UNSPECIFIED) { + return shp.Serialize() + ":" + base::IntToString(shp.port()); + } else { + return shp.Serialize(); } } @@ -270,16 +288,17 @@ bool ParseCommandLine(const CommandLine& cmdline, Params* params) { url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION); params->proxy_url = "direct://"; GURL url(cmdline.proxy); + GURL::Replacements remove_auth; + remove_auth.ClearUsername(); + remove_auth.ClearPassword(); + GURL url_no_auth = url.ReplaceComponents(remove_auth); if (!cmdline.proxy.empty()) { if (!url.is_valid()) { std::cerr << "Invalid proxy URL" << std::endl; return false; } - if (url.scheme() != "https" && url.scheme() != "quic") { - std::cerr << "Must be HTTPS or QUIC proxy" << std::endl; - return false; - } - params->proxy_url = url::SchemeHostPort(url).Serialize(); + params->proxy_url = GetProxyFromURL(url_no_auth); + params->proxy_url.erase(); params->proxy_user = url.username(); params->proxy_pass = url.password(); } @@ -291,10 +310,10 @@ bool ParseCommandLine(const CommandLine& cmdline, Params* params) { } else { // SNI should only contain DNS hostnames not IP addresses per RFC 6066. if (url.HostIsIPAddress()) { - GURL::Replacements replacements; - replacements.SetHostStr(kDefaultHostName); + GURL::Replacements set_host; + set_host.SetHostStr(kDefaultHostName); params->proxy_url = - url::SchemeHostPort(url.ReplaceComponents(replacements)).Serialize(); + GetProxyFromURL(url_no_auth.ReplaceComponents(set_host)); LOG(INFO) << "Using '" << kDefaultHostName << "' as the hostname for " << url.host(); params->host_resolver_rules = @@ -444,6 +463,8 @@ int main(int argc, char* argv[]) { LOG(ERROR) << "Failed to listen: " << result; return EXIT_FAILURE; } + LOG(INFO) << "Listening on " << params.listen_addr << ":" + << params.listen_port; net::NaiveProxy naive_proxy(std::move(listen_socket), params.protocol, params.use_padding, session, kTrafficAnnotation);