From 30d2697f039df174127ee1ff841b2d94fb154039 Mon Sep 17 00:00:00 2001 From: Wayback Archiver <66856220+waybackarchiver@users.noreply.github.com> Date: Sat, 20 May 2023 22:47:19 +0000 Subject: [PATCH 1/2] Add silent flag to reduce output (#67) --- .gitignore | 1 + README.md | 6 ++++-- cmd/wireproxy/main.go | 9 ++++++++- wireguard.go | 4 ++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 7101e62..78af5f4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.sw? /.idea .goreleaser.yml +*.conf diff --git a/README.md b/README.md index 473fcdb..9a46a13 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ anything. ``` ``` -usage: wireproxy [-h|--help] -c|--config "" [-d|--daemon] - [-n|--configtest] +usage: wireproxy [-h|--help] [-c|--config ""] [-s|--silent] + [-d|--daemon] [-v|--version] [-n|--configtest] Userspace wireguard client for proxying @@ -43,7 +43,9 @@ Arguments: -h --help Print help information -c --config Path of configuration file + -s --silent Silent mode -d --daemon Make wireproxy run in background + -v --version Print version -n --configtest Configtest mode. Only check the configuration file for validity. ``` diff --git a/cmd/wireproxy/main.go b/cmd/wireproxy/main.go index 22fd8ed..d0950a8 100644 --- a/cmd/wireproxy/main.go +++ b/cmd/wireproxy/main.go @@ -8,6 +8,7 @@ import ( "github.com/akamensky/argparse" "github.com/octeep/wireproxy" + "golang.zx2c4.com/wireguard/device" "suah.dev/protect" ) @@ -63,6 +64,7 @@ func main() { parser := argparse.NewParser("wireproxy", "Userspace wireguard client for proxying") config := parser.String("c", "config", &argparse.Options{Help: "Path of configuration file"}) + silent := parser.Flag("s", "silent", &argparse.Options{Help: "Silent mode"}) daemon := parser.Flag("d", "daemon", &argparse.Options{Help: "Make wireproxy run in background"}) printVerison := parser.Flag("v", "version", &argparse.Options{Help: "Print version"}) configTest := parser.Flag("n", "configtest", &argparse.Options{Help: "Configtest mode. Only check the configuration file for validity."}) @@ -114,10 +116,15 @@ func main() { return } + logLevel := device.LogLevelVerbose + if *silent { + logLevel = device.LogLevelSilent + } + // no file access is allowed from now on, only networking pledgeOrPanic("stdio inet dns") - tnet, err := wireproxy.StartWireguard(conf.Device) + tnet, err := wireproxy.StartWireguard(conf.Device, logLevel) if err != nil { log.Fatal(err) } diff --git a/wireguard.go b/wireguard.go index 661504b..7d31085 100644 --- a/wireguard.go +++ b/wireguard.go @@ -53,7 +53,7 @@ func createIPCRequest(conf *DeviceConfig) (*DeviceSetting, error) { } // StartWireguard creates a tun interface on netstack given a configuration -func StartWireguard(conf *DeviceConfig) (*VirtualTun, error) { +func StartWireguard(conf *DeviceConfig, logLevel int) (*VirtualTun, error) { setting, err := createIPCRequest(conf) if err != nil { return nil, err @@ -63,7 +63,7 @@ func StartWireguard(conf *DeviceConfig) (*VirtualTun, error) { if err != nil { return nil, err } - dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(device.LogLevelVerbose, "")) + dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(logLevel, "")) err = dev.IpcSet(setting.ipcRequest) if err != nil { return nil, err From d9c6eb7143a8674e0fbd6c2207a22264cc88491c Mon Sep 17 00:00:00 2001 From: pufferfish <74378430+pufferffish@users.noreply.github.com> Date: Mon, 22 May 2023 17:03:27 +0100 Subject: [PATCH 2/2] add test CI (#69) --- .github/workflows/test.yml | 32 ++++++++++++++++++++++++++++++++ test_config.sh | 20 ++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100755 test_config.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6c46d20 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: Test +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + +jobs: + test: + name: Test wireproxy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setting up Go + uses: actions/setup-go@v2 + with: + go-version: 1.19 + - name: Install dependencies + run: sudo apt install wireguard curl + - name: Building wireproxy + run: | + git tag dev + make + - name: Generate test config + run: ./test_config.sh + - name: Start wireproxy + run: ./wireproxy -c test.conf & sleep 1 + - name: Test socks5 + run: curl --proxy socks5://localhost:64423 http://zx2c4.com/ip | grep -q "demo.wireguard.com" + diff --git a/test_config.sh b/test_config.sh new file mode 100755 index 0000000..3f439cd --- /dev/null +++ b/test_config.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -e +exec 3<>/dev/tcp/demo.wireguard.com/42912 +privatekey="$(wg genkey)" +wg pubkey <<<"$privatekey" >&3 +IFS=: read -r status server_pubkey server_port internal_ip <&3 +[[ $status == OK ]] +cat >test.conf <