Fix VPN internet connectivity and simplify client setup

Initialize Android physical interfaces and preserve macOS scoped routes. Add redacted diagnostics, default DNS, ordered auto-save, simplified controls, scanner rotation settings, and native regression coverage. Restore vendored build sources and document validation and stability checks.
This commit is contained in:
shen
2026-10-12 06:51:25 -07:00
parent 2f185f914d
commit c7cc2aa865
41 changed files with 2841 additions and 247 deletions
+133
View File
@@ -0,0 +1,133 @@
#!/usr/bin/env python3
"""Isolated LAN SOCKS5 fixture for android_proxy_test.dart; no user profiles.
Only the explicitly supplied device IP is accepted. Documentation addresses
serve deterministic TCP/UDP replies; other TCP destinations use real sockets
to verify default DoH and certificate-validated HTTPS through the proxy.
"""
import argparse
import ipaddress
import select
import socket
import socketserver
import struct
def read_exact(sock, length):
result = b""
while len(result) < length:
chunk = sock.recv(length - len(result))
if not chunk:
raise EOFError()
result += chunk
return result
def address(sock, kind):
if kind == 1:
host = socket.inet_ntop(socket.AF_INET, read_exact(sock, 4))
elif kind == 4:
host = socket.inet_ntop(socket.AF_INET6, read_exact(sock, 16))
elif kind == 3:
host = read_exact(sock, read_exact(sock, 1)[0]).decode("ascii")
else:
raise ValueError("Invalid SOCKS address")
return host, struct.unpack("!H", read_exact(sock, 2))[0]
class Handler(socketserver.BaseRequestHandler):
def handle(self):
if self.client_address[0] != self.server.device:
return
client = self.request
client.settimeout(45)
try:
version, count = read_exact(client, 2)
methods = read_exact(client, count)
if version != 5 or 0 not in methods:
return
client.sendall(b"\x05\x00")
version, command, _, kind = read_exact(client, 4)
host, port = address(client, kind)
if command == 3:
self.udp(client)
return
if version != 5 or command != 1:
return
if host == "198.51.100.45" and port == 18082:
client.sendall(b"\x05\x00\x00\x01" + b"\x00" * 6)
data = b""
while b"\r\n\r\n" not in data and len(data) < 8192:
data += client.recv(4096)
body = b"MeshPort proxy fixture"
client.sendall(b"HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: "
+ str(len(body)).encode() + b"\r\n\r\n" + body)
print("FIXTURE_TCP_PASS", flush=True)
return
# No connections to private hosts, other devices, or host services.
destinations = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
public = [x for x in destinations if ipaddress.ip_address(x[4][0]).is_global]
if not public:
raise ValueError("Only public upstreams allowed")
remote = None
for family, kind, proto, _, destination in public:
candidate = socket.socket(family, kind, proto)
candidate.settimeout(10)
try:
candidate.connect(destination)
remote = candidate
break
except OSError:
candidate.close()
if remote is None:
raise OSError("No reachable public upstream")
with remote:
client.sendall(b"\x05\x00\x00\x01" + b"\x00" * 6)
print("FIXTURE_PUBLIC_TCP_CONNECTED", flush=True)
while True:
readable, _, _ = select.select([client, remote], [], [], 45)
if not readable:
return
for source in readable:
data = source.recv(65536)
if not data:
return
(remote if source is client else client).sendall(data)
except (OSError, ValueError, EOFError) as error:
print("FIXTURE_CONNECTION_ERROR", type(error).__name__, flush=True)
def udp(self, client):
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as udp:
udp.bind((self.server.server_address[0], 0))
endpoint = udp.getsockname()
client.sendall(b"\x05\x00\x00\x01" + socket.inet_aton(endpoint[0])
+ struct.pack("!H", endpoint[1]))
while True:
readable, _, _ = select.select([client, udp], [], [], 45)
if not readable or client in readable:
return
data, peer = udp.recvfrom(65536)
if peer[0] != self.server.device:
continue
if data[:4] == b"\x00\x00\x00\x01" and len(data) >= 10:
target = socket.inet_ntoa(data[4:8])
port = struct.unpack("!H", data[8:10])[0]
if target == "198.51.100.45" and port == 18083:
udp.sendto(data, peer)
print("FIXTURE_UDP_PASS", flush=True)
class Server(socketserver.ThreadingTCPServer):
allow_reuse_address = True
daemon_threads = True
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--host", required=True)
parser.add_argument("--device", required=True)
args = parser.parse_args()
with Server((args.host, 18084), Handler) as server:
server.device = args.device
print("Android proxy fixture ready", flush=True)
server.serve_forever()
+3
View File
@@ -1,6 +1,9 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
if [ -x work/toolchain/go-sdk/go/bin/go ]; then
export PATH="$PWD/work/toolchain/go-sdk/go/bin:$PATH"
fi
export GOPATH="$PWD/work/toolchain/go"
export GOMODCACHE="$GOPATH/pkg/mod"
export GOCACHE="$PWD/work/cache/go-build"
+50
View File
@@ -0,0 +1,50 @@
#!/bin/sh
# Keep user storage and restore the normal APP even when device tests fail.
set -eu
cd "$(dirname "$0")/.."
root="$PWD"
if [ "$#" -lt 4 ]; then
printf '%s\n' 'usage: test-android-device.sh SERIAL NORMAL_APK BUILD_NUMBER network|proxy [FIXTURE_IP]' >&2
exit 2
fi
serial="$1"
apk="$2"
case "$apk" in /*) ;; *) apk="$root/$apk" ;; esac
[ -f "$apk" ] || { printf '%s\n' 'Normal APK not found' >&2; exit 2; }
number="$3"
case "$number" in ''|*[!0-9]*) printf '%s\n' 'Numeric build number required' >&2; exit 2 ;; esac
case "$4" in
network) target=integration_test/android_network_test.dart ;;
proxy) target=integration_test/android_proxy_test.dart; [ "$#" -ge 5 ] || exit 2 ;;
*) exit 2 ;;
esac
restore() {
result=$?
trap - EXIT HUP INT TERM
printf '%s\n' 'Restoring the normal MeshPort APP (keeping stored profiles)'
adb -s "$serial" shell am force-stop com.example.meshport_lab || true
if adb -s "$serial" install -r -d "$apk"; then
adb -s "$serial" shell am start -W -n com.example.meshport_lab/.MainActivity || result=1
else
result=1
fi
exit "$result"
}
trap restore EXIT
trap 'exit 130' HUP INT TERM
cd apps/meshport_lab
# Matching build numbers avoid Flutter's uninstall/reinstall downgrade fallback.
# drive's keep-app-running also suppresses the default test-package uninstall.
if [ "$4" = proxy ]; then
flutter build apk --debug --target-platform android-arm64 --target="$target" \
--build-number="$number" --dart-define="ANDROID_PROXY_FIXTURE=$5"
flutter drive -d "$serial" --target="$target" \
--driver=test_driver/integration_test.dart --keep-app-running \
--use-application-binary="$PWD/build/app/outputs/flutter-apk/app-debug.apk"
else
flutter build apk --debug --target-platform android-arm64 --target="$target" \
--build-number="$number"
flutter drive -d "$serial" --target="$target" \
--driver=test_driver/integration_test.dart --keep-app-running \
--use-application-binary="$PWD/build/app/outputs/flutter-apk/app-debug.apk"
fi