windows: AmneziaWG as a system-wide VPN

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>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 17:23:11 +03:00
1 parent 95ec15e14a
commit 5cf3a237e6
30 files changed
+916 -12

No files matched your search

+60
View File
@@ -28,3 +28,63 @@ clone_tag() {
done
return 1
}
# clone_commit URL COMMIT DIR: COMMIT alone, for a project without release tags; cached and
# tried again as clone_tag is.
clone_commit() {
local url=$1 commit=$2 dir=$3 try cached=""
if [ -n "${SRC_CACHE:-}" ]; then
cached="$SRC_CACHE/$(basename "$url")@$commit"
if [ -d "$cached/.git" ]; then
rm -rf "$dir" && cp -a "$cached" "$dir" && git -C "$dir" reset -q --hard && git -C "$dir" clean -qfdx && return 0
fi
fi
for try in 1 2 3; do
rm -rf "$dir" && mkdir -p "$dir"
if git -C "$dir" init -q && git -C "$dir" remote add origin "$url" &&
git -C "$dir" -c http.lowSpeedLimit=1000 -c http.lowSpeedTime=60 fetch -q --depth 1 origin "$commit" &&
git -C "$dir" -c advice.detachedHead=false checkout -q FETCH_HEAD; then
if [ -n "$cached" ]; then
mkdir -p "$SRC_CACHE" && rm -rf "$cached.tmp" && cp -a "$dir" "$cached.tmp" && mv "$cached.tmp" "$cached"
fi
return 0
fi
echo "fetching $url ($commit) failed, try $try of 3" >&2
sleep 5
done
return 1
}
# fetch_pinned URL SHA256 FILE: a download, checked by its hash; kept in SRC_CACHE.
fetch_pinned() {
local url=$1 sha=$2 out=$3 cached=""
if [ -n "${SRC_CACHE:-}" ]; then
cached="$SRC_CACHE/$sha"
if [ -f "$cached" ] && echo "$sha $cached" | sha256sum -c --quiet 2>/dev/null; then
cp "$cached" "$out" && return 0
fi
fi
# Whole, unless it stalls: some networks cut TLS to some hosts after about 16 KB (as
# zapret2's cutoff option knows). Then in ranges below that, each on a connection of its own.
if ! curl -fsSL --connect-timeout 30 --speed-limit 1 --speed-time 15 --max-time 900 --retry 2 -o "$out" "$url"; then
echo "$url stalled; fetching it in pieces" >&2
local size from=0 step=12000 tries=0
size=$(curl -fsSIL --connect-timeout 30 --max-time 60 "$url" | tr -d '\r' | awk 'tolower($1) == "content-length:" { n = $2 } END { print n }')
[[ "$size" =~ ^[0-9]+$ ]] && [ "$size" -gt 0 ] || { echo "$url: no size to fetch it in pieces by" >&2; return 1; }
: >"$out"
while [ "$from" -lt "$size" ]; do
if curl -fsSL --connect-timeout 30 --max-time 60 -r "$from-$((from + step - 1))" "$url" >>"$out.piece" 2>/dev/null &&
[ "$(stat -c %s "$out.piece")" -gt 0 ]; then
cat "$out.piece" >>"$out"
from=$(stat -c %s "$out")
tries=0
else
tries=$((tries + 1))
[ "$tries" -lt 5 ] || { rm -f "$out.piece"; echo "$url: a piece failed five times" >&2; return 1; }
fi
rm -f "$out.piece"
done
fi
echo "$sha $out" | sha256sum -c --quiet || { echo "$url: not the pinned file" >&2; return 1; }
if [ -n "$cached" ]; then mkdir -p "$SRC_CACHE" && cp "$out" "$cached"; fi
}