Each profile without asOutbound is a tunnel service of its own, AmneziaWGTunnel$<interface>, as amneziawg-windows's client installs one: amneziawg-go on Wintun, its routes and DNS, and for one peer that takes everything its firewall blocking what would leave outside the tunnel. It runs awg-tunnel.exe, amneziawg-windows built from its pinned commit with a main of ours (its Run(), its log in a file) instead of its tunnel.dll, beside Wintun's signed DLL (tools/build-amneziawg.sh). The service writes each profile's .conf below its state root, registers the tunnel (unrestricted service SID, which its firewall exempts it by), starts the autostart ones with itself, and removes the tunnels of profiles gone, and all of them on uninstall. proxy-ctl awg list|on|off|log, and the app's AmneziaWG page: profiles (a system-wide one switched on and off, its log), one added from a vpn:// link or a .conf, or removed. tools/lib.sh: clone_commit, and fetch_pinned, which fetches in pieces a download that stalls (some networks cut TLS after about 16 KB, as wintun.net's here). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
3.0 KiB
Bash
Executable File
77 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# AmneziaWG as a system-wide VPN: amneziawg-windows's tunnel (amneziawg-go on Wintun, its
|
|
# firewall that blocks what leaves outside a full tunnel, its DNS and routes), built from its
|
|
# pinned commit as awg-tunnel.exe rather than its tunnel.dll: the same Run() a tunnel service
|
|
# makes, with a main that takes the config's path and the tunnel's name, and its log in a
|
|
# file beside the config (not its ring log). Wintun's signed driver DLL from wintun.net,
|
|
# pinned as amneziawg-windows's own build pins it.
|
|
#
|
|
# tools/build-amneziawg.sh OUT_DIR (needs git, go, curl, unzip)
|
|
set -euo pipefail
|
|
. "$(dirname "$0")/lib.sh"
|
|
OUT=$(realpath -m "${1:?output directory}")
|
|
COMMIT=e90531d15802cb976773f3b63443bc281f738ca3
|
|
VERSION=0-unstable-2026-08-14+e90531d
|
|
WINTUN_URL=https://www.wintun.net/builds/wintun-0.14.1.zip
|
|
WINTUN_SHA256=07c256185d6ee3652e09fa55c0b673e2624b565e02c4b9091c79ca7d2f24ef51
|
|
WORK=$(mktemp -d)
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
|
|
clone_commit https://github.com/amnezia-vpn/amneziawg-windows "$COMMIT" "$WORK/src"
|
|
cd "$WORK/src"
|
|
# Its exports (tunnel.dll's, through cgo) out; a main of ours in.
|
|
rm main.go
|
|
grep -q 'err = ringlogger.InitGlobalLogger("TUN")' service.go || { echo "service.go changed: no ring logger to replace"; exit 1; }
|
|
sed -i 's|err = ringlogger.InitGlobalLogger("TUN")|err = nil|' service.go
|
|
sed -i '/"github.com\/amnezia-vpn\/amneziawg-windows\/v3\/ringlogger"/d' service.go
|
|
cat > proxysuite_main.go <<'GO'
|
|
/* SPDX-License-Identifier: MIT
|
|
*
|
|
* Proxy Suite's AmneziaWG tunnel service: run by the Service Control Manager as
|
|
* `awg-tunnel <config path> <tunnel name>`, as amneziawg-windows's tunnel.dll is from its
|
|
* client's service. Its log goes to <config path>.log, written anew at each start.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) != 3 {
|
|
fmt.Fprintln(os.Stderr, "usage: awg-tunnel <config> <tunnel name> (as a Windows service)")
|
|
os.Exit(2)
|
|
}
|
|
confPath, name := os.Args[1], os.Args[2]
|
|
if f, err := os.OpenFile(confPath+".log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600); err == nil {
|
|
log.SetOutput(f)
|
|
}
|
|
text, err := os.ReadFile(confPath)
|
|
if err != nil {
|
|
log.Printf("reading %s: %v", confPath, err)
|
|
os.Exit(1)
|
|
}
|
|
if err := Run(string(text), name); err != nil {
|
|
log.Printf("the tunnel service: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
GO
|
|
export GOTOOLCHAIN=local GOFLAGS=-mod=mod CGO_ENABLED=0 GOOS=windows GOARCH=amd64
|
|
go build -trimpath -ldflags "-s -w" -o "$WORK/awg-tunnel.exe" .
|
|
|
|
rm -rf "$OUT" && mkdir -p "$OUT"
|
|
cp "$WORK/awg-tunnel.exe" "$OUT/"
|
|
# Its license is the MIT text in its README.
|
|
sed -n '/^```text/,/^```/p' README.md | sed '1d;$d' >"$OUT/LICENSE"
|
|
grep -q 'Permission is hereby granted' "$OUT/LICENSE" || { echo "README.md: no license text"; exit 1; }
|
|
fetch_pinned "$WINTUN_URL" "$WINTUN_SHA256" "$WORK/wintun.zip"
|
|
unzip -q -o "$WORK/wintun.zip" -d "$WORK/wintun"
|
|
cp "$WORK/wintun/wintun/bin/amd64/wintun.dll" "$OUT/"
|
|
cp "$WORK/wintun/wintun/LICENSE.txt" "$OUT/wintun-LICENSE.txt"
|
|
echo "$VERSION" >"$OUT/.version"
|
|
echo "amneziawg $VERSION (windows) in $OUT"
|