mirror of
https://github.com/klzgrad/naiveproxy.git
synced 2024-11-24 14:26:09 +03:00
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.
This commit is contained in:
parent
3307740afb
commit
1f39882089
@ -7,14 +7,13 @@ cache:
|
|||||||
- '%LOCALAPPDATA%\Mozilla\sccache'
|
- '%LOCALAPPDATA%\Mozilla\sccache'
|
||||||
build_script:
|
build_script:
|
||||||
- bash ./tools/import-upstream.sh
|
- bash ./tools/import-upstream.sh
|
||||||
- cd src
|
- bash -c 'cd src; ./get-clang.sh'
|
||||||
- bash ./get-clang.sh
|
|
||||||
- bash -c '~/.cargo/bin/sccache -s'
|
- bash -c '~/.cargo/bin/sccache -s'
|
||||||
- bash ./build.sh
|
- bash -c 'cd src; ./build.sh'
|
||||||
- bash -c '~/.cargo/bin/sccache -s'
|
- bash -c '~/.cargo/bin/sccache -s'
|
||||||
- bash -c 'mkdir naive-$APPVEYOR_REPO_TAG_NAME-win64'
|
- 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 '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/'
|
- bash -c '7z a naive-$APPVEYOR_REPO_TAG_NAME-win64.zip naive-$APPVEYOR_REPO_TAG_NAME-win64/'
|
||||||
test: off
|
test: off
|
||||||
artifacts:
|
artifacts:
|
||||||
- path: naive-$(APPVEYOR_REPO_TAG_NAME)-win64.zip
|
- path: naive-$(APPVEYOR_REPO_TAG_NAME)-win64.zip
|
||||||
|
@ -18,13 +18,12 @@ addons:
|
|||||||
cache: ccache
|
cache: ccache
|
||||||
script:
|
script:
|
||||||
- ./tools/import-upstream.sh
|
- ./tools/import-upstream.sh
|
||||||
- cd src
|
- ( cd src; ./get-clang.sh )
|
||||||
- ./get-clang.sh
|
|
||||||
- ccache -s
|
- ccache -s
|
||||||
- ./build.sh
|
- ( cd src; ./build.sh )
|
||||||
- mkdir naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME
|
- mkdir naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME
|
||||||
- cp out/Release/naive config.json LICENSE 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/
|
- tar cJf naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME.tar.xz naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME/
|
||||||
deploy:
|
deploy:
|
||||||
provider: releases
|
provider: releases
|
||||||
api_key:
|
api_key:
|
||||||
|
@ -19,14 +19,14 @@ case "$ARCH" in
|
|||||||
esac
|
esac
|
||||||
if [ ! -d third_party/llvm-build/Release+Asserts/bin ]; then
|
if [ ! -d third_party/llvm-build/Release+Asserts/bin ]; then
|
||||||
mkdir -p third_party/llvm-build/Release+Asserts
|
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
|
fi
|
||||||
|
|
||||||
# AFDO profile (Linux)
|
# AFDO profile (Linux)
|
||||||
if [ "$ARCH" = Linux -a ! -f chrome/android/profiles/afdo.prof ]; then
|
if [ "$ARCH" = Linux -a ! -f chrome/android/profiles/afdo.prof ]; then
|
||||||
AFDO_PATH=$(cat chrome/android/profiles/newest.txt)
|
AFDO_PATH=$(cat chrome/android/profiles/newest.txt)
|
||||||
afdo_url="https://storage.googleapis.com/chromeos-prebuilt/afdo-job/llvm/$AFDO_PATH"
|
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
|
fi
|
||||||
|
|
||||||
# sccache (Windows)
|
# sccache (Windows)
|
||||||
@ -43,25 +43,12 @@ fi
|
|||||||
|
|
||||||
# gn
|
# gn
|
||||||
if [ ! -f gn/out/gn ]; then
|
if [ ! -f gn/out/gn ]; then
|
||||||
if [ "$CI" -o "$ARCH" = Windows ]; then
|
mkdir -p gn/out
|
||||||
mkdir -p gn/out
|
cd gn/out
|
||||||
cd gn/out
|
case "$ARCH" in
|
||||||
case "$ARCH" in
|
Linux) curl -L https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest -o gn.zip;;
|
||||||
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;;
|
||||||
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;;
|
||||||
Windows) curl -L https://chrome-infra-packages.appspot.com/dl/gn/gn/windows-amd64/+/latest -o gn.zip;;
|
esac
|
||||||
esac
|
unzip gn.zip
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
|
@ -128,6 +128,7 @@ std::unique_ptr<net::URLRequestContext> BuildURLRequestContext(
|
|||||||
|
|
||||||
net::ProxyConfig proxy_config;
|
net::ProxyConfig proxy_config;
|
||||||
proxy_config.proxy_rules().ParseFromString(params.proxy_url);
|
proxy_config.proxy_rules().ParseFromString(params.proxy_url);
|
||||||
|
LOG(INFO) << "Proxying via " << params.proxy_url;
|
||||||
auto proxy_service = net::ProxyResolutionService::CreateWithoutProxyResolver(
|
auto proxy_service = net::ProxyResolutionService::CreateWithoutProxyResolver(
|
||||||
std::make_unique<net::ProxyConfigServiceFixed>(
|
std::make_unique<net::ProxyConfigServiceFixed>(
|
||||||
net::ProxyConfigWithAnnotation(proxy_config, kTrafficAnnotation)),
|
net::ProxyConfigWithAnnotation(proxy_config, kTrafficAnnotation)),
|
||||||
@ -187,20 +188,23 @@ void GetCommandLine(const base::CommandLine& proc, CommandLine* cmdline) {
|
|||||||
cmdline->listen = proc.GetSwitchValueASCII("listen");
|
cmdline->listen = proc.GetSwitchValueASCII("listen");
|
||||||
cmdline->proxy = proc.GetSwitchValueASCII("proxy");
|
cmdline->proxy = proc.GetSwitchValueASCII("proxy");
|
||||||
cmdline->padding = proc.HasSwitch("padding");
|
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->no_log = !proc.HasSwitch("log");
|
||||||
cmdline->log = proc.GetSwitchValuePath("log");
|
cmdline->log = proc.GetSwitchValuePath("log");
|
||||||
cmdline->log_net_log = proc.GetSwitchValuePath("log-net-log");
|
cmdline->log_net_log = proc.GetSwitchValuePath("log-net-log");
|
||||||
cmdline->ssl_key_log_file = proc.GetSwitchValuePath("ssl-key-log-file");
|
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);
|
JSONFileValueDeserializer reader(config_path);
|
||||||
int error_code;
|
int error_code;
|
||||||
std::string error_message;
|
std::string error_message;
|
||||||
auto value = reader.Deserialize(&error_code, &error_message);
|
auto value = reader.Deserialize(&error_code, &error_message);
|
||||||
if (value == nullptr) {
|
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);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (!value->is_dict()) {
|
if (!value->is_dict()) {
|
||||||
@ -218,18 +222,32 @@ void GetCommandLineFromConfig(const base::FilePath& config_path, CommandLine* cm
|
|||||||
cmdline->padding = value->FindKey("padding")->GetBool();
|
cmdline->padding = value->FindKey("padding")->GetBool();
|
||||||
}
|
}
|
||||||
if (value->FindKeyOfType("host-resolver-rules", base::Value::Type::STRING)) {
|
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;
|
cmdline->no_log = true;
|
||||||
if (value->FindKeyOfType("log", base::Value::Type::STRING)) {
|
if (value->FindKeyOfType("log", base::Value::Type::STRING)) {
|
||||||
cmdline->no_log = false;
|
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)) {
|
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)) {
|
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);
|
url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION);
|
||||||
params->proxy_url = "direct://";
|
params->proxy_url = "direct://";
|
||||||
GURL url(cmdline.proxy);
|
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 (!cmdline.proxy.empty()) {
|
||||||
if (!url.is_valid()) {
|
if (!url.is_valid()) {
|
||||||
std::cerr << "Invalid proxy URL" << std::endl;
|
std::cerr << "Invalid proxy URL" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (url.scheme() != "https" && url.scheme() != "quic") {
|
params->proxy_url = GetProxyFromURL(url_no_auth);
|
||||||
std::cerr << "Must be HTTPS or QUIC proxy" << std::endl;
|
params->proxy_url.erase();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
params->proxy_url = url::SchemeHostPort(url).Serialize();
|
|
||||||
params->proxy_user = url.username();
|
params->proxy_user = url.username();
|
||||||
params->proxy_pass = url.password();
|
params->proxy_pass = url.password();
|
||||||
}
|
}
|
||||||
@ -291,10 +310,10 @@ bool ParseCommandLine(const CommandLine& cmdline, Params* params) {
|
|||||||
} else {
|
} else {
|
||||||
// SNI should only contain DNS hostnames not IP addresses per RFC 6066.
|
// SNI should only contain DNS hostnames not IP addresses per RFC 6066.
|
||||||
if (url.HostIsIPAddress()) {
|
if (url.HostIsIPAddress()) {
|
||||||
GURL::Replacements replacements;
|
GURL::Replacements set_host;
|
||||||
replacements.SetHostStr(kDefaultHostName);
|
set_host.SetHostStr(kDefaultHostName);
|
||||||
params->proxy_url =
|
params->proxy_url =
|
||||||
url::SchemeHostPort(url.ReplaceComponents(replacements)).Serialize();
|
GetProxyFromURL(url_no_auth.ReplaceComponents(set_host));
|
||||||
LOG(INFO) << "Using '" << kDefaultHostName << "' as the hostname for "
|
LOG(INFO) << "Using '" << kDefaultHostName << "' as the hostname for "
|
||||||
<< url.host();
|
<< url.host();
|
||||||
params->host_resolver_rules =
|
params->host_resolver_rules =
|
||||||
@ -444,6 +463,8 @@ int main(int argc, char* argv[]) {
|
|||||||
LOG(ERROR) << "Failed to listen: " << result;
|
LOG(ERROR) << "Failed to listen: " << result;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
LOG(INFO) << "Listening on " << params.listen_addr << ":"
|
||||||
|
<< params.listen_port;
|
||||||
|
|
||||||
net::NaiveProxy naive_proxy(std::move(listen_socket), params.protocol,
|
net::NaiveProxy naive_proxy(std::move(listen_socket), params.protocol,
|
||||||
params.use_padding, session, kTrafficAnnotation);
|
params.use_padding, session, kTrafficAnnotation);
|
||||||
|
Loading…
Reference in New Issue
Block a user