mirror of
https://github.com/YuanDevTeam/Vole.git
synced 2026-11-23 08:00:30 +00:00
feat: add ShadowTLS v3, UoT v2, TUIC v5, and HTTPUpgrade (#2)
* test: prepare protocol-completion validation * feat: support ShadowTLS v3 for Shadowsocks 2022 * feat: add UoT v2 to Shadowsocks 2022 * feat: support TUIC v5 TCP and UDP * feat: add HTTPUpgrade to VMess and Trojan Reuse the existing raw upgrade stream with typed normal/fast-open options and strict early-data configuration. Reject an expired setup before ready IO can write any prefix. Add isolated official-peer data, UDP, authentication, fingerprint, close and legacy-transport gates. * test: validate extended proxy chains and lifecycle * build: freeze release dependencies for protocol completion * fix: enforce HTTPUpgrade deadline on resumed IO Recheck the absolute setup deadline before each handshake poll and before accepting success, without retaining a timer on established streams. Cover ready late responses, blocked prefix writes, and post-setup IO in both normal and fast-open modes.
This commit is contained in:
@@ -13,12 +13,12 @@ from pathlib import Path
|
||||
|
||||
CORE_DIR = Path(__file__).resolve().parents[3]
|
||||
EXPECTED_IDENTITY = (
|
||||
b"VCore;engine=rust;coreVersion=0.1.0;invokeApiVersion=5;configVersion=27"
|
||||
b"VCore;engine=rust;coreVersion=0.1.0;invokeApiVersion=5;configVersion=31"
|
||||
)
|
||||
DEFAULT_FEATURES = (
|
||||
"ffi,tun,inbound-http,inbound-socks5,outbound-anytls,"
|
||||
"outbound-socks5,outbound-shadowsocks,outbound-trojan,outbound-vmess,outbound-vless,"
|
||||
"outbound-hysteria2"
|
||||
"outbound-hysteria2,outbound-tuic,shadow-tls-v3"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -82,6 +82,12 @@ def _parser() -> argparse.ArgumentParser:
|
||||
action="store_true",
|
||||
help="probe real download-leg client-identity enforcement only",
|
||||
)
|
||||
peers = checks.add_parser(
|
||||
"protocol-peers",
|
||||
help="verify isolated official peer capabilities, not VCore acceptance",
|
||||
)
|
||||
peers.add_argument("--run-dir", type=Path, required=True)
|
||||
peers.add_argument("--case", dest="identifiers", action="append")
|
||||
gateway = checks.add_parser(
|
||||
"xhttp-gateway",
|
||||
help="build xcaddy and test isolated H3/mTLS native topology",
|
||||
@@ -127,6 +133,7 @@ def _parser() -> argparse.ArgumentParser:
|
||||
"vmess",
|
||||
"vless",
|
||||
"hysteria2",
|
||||
"tuic",
|
||||
],
|
||||
)
|
||||
modes = protocol.add_mutually_exclusive_group()
|
||||
@@ -182,6 +189,10 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||
from .protocol_xhttp_peers import main as xhttp_peers
|
||||
|
||||
return xhttp_peers(args.run_dir, identities_only=args.identities_only)
|
||||
elif args.check == "protocol-peers":
|
||||
from .protocol_completion_peers import run
|
||||
|
||||
run(args.run_dir, identifiers=args.identifiers)
|
||||
elif args.check == "xhttp-gateway":
|
||||
from .protocol_xhttp_gateway import main as xhttp_gateway
|
||||
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
"""Container-only comparison client for matched official protocol peers."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def exact(stream, size):
|
||||
data = bytearray()
|
||||
while len(data) < size:
|
||||
part = stream.recv(size - len(data))
|
||||
if not part:
|
||||
raise ValueError("truncated peer response")
|
||||
data.extend(part)
|
||||
return bytes(data)
|
||||
|
||||
|
||||
def socks(stream, command, host, port):
|
||||
stream.sendall(b"\x05\x01\x00")
|
||||
if exact(stream, 2) != b"\x05\x00":
|
||||
raise ValueError("SOCKS authentication failed")
|
||||
stream.sendall(
|
||||
bytes([5, command, 0, 1]) + socket.inet_aton(host) + struct.pack("!H", port)
|
||||
)
|
||||
header = exact(stream, 4)
|
||||
if header[:3] != b"\x05\x00\x00":
|
||||
raise ValueError("SOCKS request failed")
|
||||
if header[3] == 1:
|
||||
address = socket.inet_ntop(socket.AF_INET, exact(stream, 4))
|
||||
elif header[3] == 4:
|
||||
address = socket.inet_ntop(socket.AF_INET6, exact(stream, 16))
|
||||
else:
|
||||
raise ValueError("unexpected SOCKS bound address")
|
||||
return address, struct.unpack("!H", exact(stream, 2))[0]
|
||||
|
||||
|
||||
def probe(option, origin):
|
||||
"""One real TCP exchange and two origin-observed UDP exchanges, no retry."""
|
||||
ingress = (option["socks_host"], option["socks_port"])
|
||||
payload = bytes(range(256)) * 4
|
||||
with socket.create_connection((origin, 24000), timeout=10) as control:
|
||||
control.sendall(b"\x0d")
|
||||
port = struct.unpack("!H", exact(control, 2))[0]
|
||||
with socket.create_connection(ingress, timeout=10) as stream:
|
||||
socks(stream, 1, origin, port)
|
||||
stream.sendall(payload)
|
||||
if exact(control, 1) != b"A" or exact(stream, len(payload)) != payload:
|
||||
raise ValueError("TCP origin exchange differs")
|
||||
with (
|
||||
socket.create_connection((origin, 24000), timeout=10) as control,
|
||||
socket.create_connection(ingress, timeout=10) as association,
|
||||
socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as udp,
|
||||
):
|
||||
control.sendall(b"\x04")
|
||||
port = struct.unpack("!H", exact(control, 2))[0]
|
||||
relay = socks(association, 3, "0.0.0.0", 0)
|
||||
# The ingress explicitly listens on IPv4, so no host/system DNS is used.
|
||||
if relay[0] == "0.0.0.0":
|
||||
relay = (option["socks_host"], relay[1])
|
||||
udp.settimeout(10)
|
||||
udp.connect(relay)
|
||||
header = (
|
||||
b"\x00\x00\x00\x01" + socket.inet_aton(origin) + struct.pack("!H", port)
|
||||
)
|
||||
for size in (64, 1200):
|
||||
payload = bytes(index % 251 for index in range(size))
|
||||
if udp.send(header + payload) != len(header) + size:
|
||||
raise ValueError("partial UDP submission")
|
||||
observed, _source = struct.unpack("!HH", exact(control, 4))
|
||||
if observed != size or exact(control, observed) != payload:
|
||||
raise ValueError("UDP origin exchange differs")
|
||||
if udp.recv(65536) != header + payload:
|
||||
raise ValueError("UDP reply differs")
|
||||
return dict(
|
||||
case_id=option["case_id"],
|
||||
status="PASS",
|
||||
tcp_bytes_each_direction=1024,
|
||||
udp_origin_packets=2,
|
||||
udp_reply_packets=2,
|
||||
udp_sizes=[64, 1200],
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
if sys.platform != "linux" or os.environ.get("VCORE_ISOLATED_CLIENT") != "1":
|
||||
raise SystemExit("isolated container harness required")
|
||||
fixture = json.loads(Path(sys.argv[1]).read_text())
|
||||
for option in fixture["cases"]:
|
||||
try:
|
||||
record = probe(option, fixture["origin"])
|
||||
except (OSError, ValueError) as error:
|
||||
print(
|
||||
json.dumps(
|
||||
dict(
|
||||
case_id=option["case_id"],
|
||||
status="FAIL",
|
||||
error=type(error).__name__,
|
||||
)
|
||||
),
|
||||
flush=True,
|
||||
)
|
||||
raise SystemExit(1) from None
|
||||
print(json.dumps(record), flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,63 @@
|
||||
"""Restart only this guest's owned, unmodified protocol child on a fixture command."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import select
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
def terminate(peer):
|
||||
peer.terminate()
|
||||
try:
|
||||
peer.wait(timeout=3)
|
||||
except subprocess.TimeoutExpired:
|
||||
peer.kill()
|
||||
peer.wait(timeout=3)
|
||||
|
||||
|
||||
def start(argv):
|
||||
peer = subprocess.Popen(argv)
|
||||
try:
|
||||
until = time.monotonic() + 10
|
||||
while peer.poll() is None and time.monotonic() < until:
|
||||
try:
|
||||
with socket.create_connection(("127.0.0.1", 23999), timeout=0.1):
|
||||
return peer
|
||||
except OSError:
|
||||
time.sleep(0.05)
|
||||
raise RuntimeError("owned protocol child not ready")
|
||||
except BaseException:
|
||||
terminate(peer)
|
||||
raise
|
||||
|
||||
|
||||
def main():
|
||||
if sys.platform != "linux" or os.environ.get("VCORE_ISOLATED_ORIGIN") != "1":
|
||||
raise SystemExit("isolated restart peer required")
|
||||
peer = start(sys.argv[1:])
|
||||
try:
|
||||
with socket.socket() as control:
|
||||
control.bind(("0.0.0.0", 23998))
|
||||
control.listen(4)
|
||||
while peer.poll() is None:
|
||||
ready, _, _ = select.select([control], [], [], 0.1)
|
||||
if not ready:
|
||||
continue
|
||||
client, _ = control.accept()
|
||||
with client:
|
||||
client.settimeout(2)
|
||||
if client.recv(1) == b"R":
|
||||
terminate(peer)
|
||||
peer = start(sys.argv[1:])
|
||||
client.sendall(b"R")
|
||||
raise RuntimeError("owned protocol child exited")
|
||||
finally:
|
||||
terminate(peer)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,203 @@
|
||||
"""Bounded container TCP fault relay around an unmodified official ShadowTLS peer.
|
||||
|
||||
Only observes record framing/tags to locate faults; never terminates TLS or SS.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import hashlib
|
||||
import hmac
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path("/data/fixture")
|
||||
EVENTS = Path("/data/fault-events.jsonl")
|
||||
LOCK = threading.Lock()
|
||||
SLOTS = threading.BoundedSemaphore(16)
|
||||
STALL = {"hello_seen": 0, "client_closed": 0}
|
||||
PASSWORD = b"synthetic-shadowtls-fixture"
|
||||
HRR = "cf21ad74e59a6111be1d8c021e65b891c2a211167abb8c5e079e09e2c8a8339c"
|
||||
|
||||
|
||||
def emit(mode, **fields):
|
||||
with LOCK, EVENTS.open("a") as output:
|
||||
output.write(json.dumps(dict(mode=mode, **fields)) + "\n")
|
||||
if mode == "stall":
|
||||
for key in STALL:
|
||||
STALL[key] += fields.get(key) is True
|
||||
|
||||
|
||||
def observe():
|
||||
with socket.socket(socket.AF_INET) as listener:
|
||||
listener.bind(("0.0.0.0", 23998))
|
||||
listener.listen(4)
|
||||
while True:
|
||||
client, _ = listener.accept()
|
||||
with client:
|
||||
client.settimeout(2)
|
||||
try:
|
||||
if client.recv(1) == b"?":
|
||||
with LOCK:
|
||||
data = json.dumps(STALL).encode()
|
||||
client.sendall(data)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def exact(raw, count):
|
||||
data = bytearray()
|
||||
while len(data) < count:
|
||||
part = raw.recv(count - len(data))
|
||||
if not part:
|
||||
if data:
|
||||
raise EOFError("truncated fixture record")
|
||||
return None
|
||||
data.extend(part)
|
||||
return bytes(data)
|
||||
|
||||
|
||||
def record(raw):
|
||||
header = exact(raw, 5)
|
||||
if header is None:
|
||||
return None
|
||||
size = int.from_bytes(header[3:5], "big")
|
||||
if not 0 < size <= 18436:
|
||||
raise ValueError("record bound")
|
||||
body = exact(raw, size)
|
||||
if body is None:
|
||||
raise EOFError("record body missing")
|
||||
return header + body
|
||||
|
||||
|
||||
def upload(client, upstream):
|
||||
try:
|
||||
while data := client.recv(16384):
|
||||
upstream.sendall(data)
|
||||
upstream.shutdown(socket.SHUT_WR)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def serve(client, mode, target):
|
||||
upstream = None
|
||||
worker = None
|
||||
try:
|
||||
with client:
|
||||
client.settimeout(15)
|
||||
if mode == "stall":
|
||||
# Observe a real client hello, then await the client's deadline
|
||||
# or Stop. No business or cover destination is contacted.
|
||||
if record(client) is None:
|
||||
return # Readiness probes are not real stalled handshakes.
|
||||
emit(mode, hello_seen=True)
|
||||
while client.recv(16384):
|
||||
pass
|
||||
emit(mode, client_closed=True)
|
||||
return
|
||||
upstream = socket.create_connection(target, timeout=10)
|
||||
upstream.settimeout(15)
|
||||
client.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
worker = threading.Thread(target=upload, args=(client, upstream))
|
||||
worker.start()
|
||||
cover = business = None
|
||||
count = 0
|
||||
mutated = False
|
||||
while (data := record(upstream)) is not None:
|
||||
count += 1
|
||||
if data[0] == 22 and cover is None:
|
||||
if len(data) < 43 or data[5] != 2:
|
||||
raise ValueError("expected ServerHello")
|
||||
seed = data[11:43]
|
||||
cover = hmac.new(PASSWORD, seed, hashlib.sha1)
|
||||
business = hmac.new(PASSWORD, seed + b"S", hashlib.sha1)
|
||||
if seed.hex() == HRR:
|
||||
emit(mode, hrr_seen=True)
|
||||
if data[0] == 23:
|
||||
if len(data) < 9 or cover is None or business is None:
|
||||
raise ValueError("authenticated record expected")
|
||||
trial = cover.copy()
|
||||
trial.update(data[9:])
|
||||
is_cover = hmac.compare_digest(trial.digest()[:4], data[5:9])
|
||||
if is_cover:
|
||||
cover = trial
|
||||
else:
|
||||
trial = business.copy()
|
||||
trial.update(data[9:])
|
||||
if not hmac.compare_digest(trial.digest()[:4], data[5:9]):
|
||||
raise ValueError("unclassified official record")
|
||||
trial.update(data[5:9])
|
||||
business = trial
|
||||
if not mutated and (
|
||||
(mode == "cover-mac" and is_cover)
|
||||
or (
|
||||
mode in {"business-mac", "business-truncated"}
|
||||
and not is_cover
|
||||
)
|
||||
):
|
||||
mutated = True
|
||||
emit(
|
||||
mode,
|
||||
injected=True,
|
||||
phase="cover" if is_cover else "business",
|
||||
)
|
||||
if mode == "business-truncated":
|
||||
client.sendall(data[:8])
|
||||
client.shutdown(socket.SHUT_WR)
|
||||
break
|
||||
changed = bytearray(data)
|
||||
changed[5] ^= 1
|
||||
data = bytes(changed)
|
||||
if mode == "fragment" and count <= 8:
|
||||
# The same authenticated records, with split headers and
|
||||
# short writes; afterwards data remain bulk, not 10M syscalls.
|
||||
for begin, end in ((0, 1), (1, 3), (3, 5), (5, 9), (9, len(data))):
|
||||
if end > begin:
|
||||
client.sendall(data[begin:end])
|
||||
emit(mode, split_record=True)
|
||||
else:
|
||||
client.sendall(data)
|
||||
except (OSError, EOFError, ValueError):
|
||||
pass
|
||||
finally:
|
||||
for raw in (client, upstream):
|
||||
if raw is not None:
|
||||
with contextlib.suppress(OSError):
|
||||
raw.shutdown(socket.SHUT_RDWR)
|
||||
raw.close()
|
||||
if worker is not None:
|
||||
worker.join(timeout=2)
|
||||
if worker.is_alive():
|
||||
emit(mode, upload_join_failed=True)
|
||||
SLOTS.release()
|
||||
|
||||
|
||||
def listen(item):
|
||||
with socket.socket(socket.AF_INET) as listener:
|
||||
listener.bind(("0.0.0.0", item["port"]))
|
||||
listener.listen(16)
|
||||
while True:
|
||||
client, _ = listener.accept()
|
||||
if not SLOTS.acquire(blocking=False):
|
||||
client.close()
|
||||
continue
|
||||
threading.Thread(
|
||||
target=serve,
|
||||
args=(client, item["mode"], (item["server"], item["server_port"])),
|
||||
daemon=True,
|
||||
).start()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if sys.platform != "linux" or os.environ.get("VCORE_ISOLATED_ORIGIN") != "1":
|
||||
raise SystemExit("isolated fault relay required")
|
||||
EVENTS.touch()
|
||||
threading.Thread(target=observe, daemon=True).start()
|
||||
items = json.loads((ROOT / "config.json").read_text())
|
||||
for item in items[1:]:
|
||||
threading.Thread(target=listen, args=(item,), daemon=True).start()
|
||||
listen(items[0])
|
||||
@@ -0,0 +1,70 @@
|
||||
"""Container-only ShadowTLS cover variations; no proxy protocol implementation."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
import ssl
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import origin
|
||||
|
||||
EVENTS = Path("/data/cover-events.jsonl")
|
||||
LOCK = threading.Lock()
|
||||
SLOTS = threading.BoundedSemaphore(16)
|
||||
|
||||
|
||||
def event(**value):
|
||||
with LOCK, EVENTS.open("a") as output:
|
||||
output.write(json.dumps(value) + "\n")
|
||||
|
||||
|
||||
def handle(raw, context, port):
|
||||
try:
|
||||
with raw:
|
||||
raw.settimeout(5)
|
||||
with context.wrap_socket(raw, server_side=True) as tls:
|
||||
event(
|
||||
port=port, version=tls.version(), alpn=tls.selected_alpn_protocol()
|
||||
)
|
||||
tls.recv(1)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
SLOTS.release()
|
||||
|
||||
|
||||
def cover(port, version, curve):
|
||||
context = origin.tls_context(version)
|
||||
context.set_ecdh_curve(curve)
|
||||
context.set_alpn_protocols(["h2", "http/1.1", "fixture-custom"])
|
||||
with socket.socket(socket.AF_INET) as listener:
|
||||
listener.bind(("0.0.0.0", port))
|
||||
listener.listen(16)
|
||||
while True:
|
||||
raw, _ = listener.accept()
|
||||
if not SLOTS.acquire(blocking=False):
|
||||
raw.close()
|
||||
continue
|
||||
threading.Thread(
|
||||
target=handle, args=(raw, context, port), daemon=True
|
||||
).start()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if sys.platform != "linux" or os.environ.get("VCORE_ISOLATED_ORIGIN") != "1":
|
||||
raise SystemExit("isolated ShadowTLS fixture required")
|
||||
EVENTS.touch()
|
||||
for port, version, curve in (
|
||||
(24001, ssl.TLSVersion.TLSv1_3, "X25519"),
|
||||
(24002, ssl.TLSVersion.TLSv1_3, "secp384r1"),
|
||||
(24003, ssl.TLSVersion.TLSv1_2, "X25519"),
|
||||
):
|
||||
threading.Thread(target=cover, args=(port, version, curve), daemon=True).start()
|
||||
# This fixture owns the cover workers; the shared origin still owns its
|
||||
# independent TCP/UDP control channel and business-byte observations.
|
||||
origin.camouflage = lambda: None
|
||||
origin.main()
|
||||
@@ -37,7 +37,7 @@ def receive_exact(stream, size):
|
||||
|
||||
|
||||
def serve_tcp(control, mode, ipv6=False):
|
||||
"""10=bulk/server-first, 11=close differential, 12=identity probe.
|
||||
"""10=bulk/server-first, 22=bulk/client-first, 11=close, 12=identity probe.
|
||||
|
||||
Observer A proves an actual accept; D proves exact request bytes and normal
|
||||
completion. Rejected identities must produce neither. No host-side server.
|
||||
@@ -112,8 +112,9 @@ def serve_tcp(control, mode, ipv6=False):
|
||||
raise ValueError("identity probe data")
|
||||
stream.sendall(b"ok")
|
||||
else:
|
||||
stream.sendall(b"hello")
|
||||
if mode in (10, 16, 18):
|
||||
if mode != 22:
|
||||
stream.sendall(b"hello")
|
||||
if mode in (10, 16, 18, 22):
|
||||
data = receive_exact(stream, 10 * 1024 * 1024)
|
||||
if data != b"\x5a" * len(data):
|
||||
raise ValueError("bulk data")
|
||||
@@ -138,7 +139,7 @@ def serve(control):
|
||||
control.settimeout(15)
|
||||
control.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
family = control.recv(1)
|
||||
if family and (family[0] & 0x7F) in (*range(10, 17), 18, 21):
|
||||
if family and (family[0] & 0x7F) in (*range(10, 17), 18, 21, 22):
|
||||
serve_tcp(control, family[0] & 0x7F, bool(family[0] & 0x80))
|
||||
return
|
||||
if family not in (b"\x04", b"\x06", b"\x11", b"\x13", b"\x14"):
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
"""Run an unmodified peer with a bounded UDP-side-channel observer in its guest.
|
||||
|
||||
The official server still owns every TCP listener. These otherwise unused UDP
|
||||
ports detect accidental native SS fallback; the observer never replies to UDP.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import select
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main():
|
||||
if sys.platform != "linux" or os.environ.get("VCORE_ISOLATED_ORIGIN") != "1":
|
||||
raise SystemExit("isolated UoT peer required")
|
||||
config = json.loads(Path("/data/fixture/config.json").read_text())
|
||||
native = "servers" in config
|
||||
ports = [
|
||||
item["server_port" if native else "port"]
|
||||
for item in config["servers" if native else "listeners"]
|
||||
]
|
||||
if not 1 <= len(ports) <= 32 or len(ports) != len(set(ports)):
|
||||
raise ValueError("bounded unique peer ports required")
|
||||
with contextlib.ExitStack() as stack:
|
||||
watchers = []
|
||||
for port in ports:
|
||||
udp = stack.enter_context(socket.socket(socket.AF_INET6, socket.SOCK_DGRAM))
|
||||
udp.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
|
||||
udp.bind(("::", port))
|
||||
watchers.append(udp)
|
||||
observer = stack.enter_context(socket.socket())
|
||||
observer.bind(("0.0.0.0", 23998))
|
||||
observer.listen(4)
|
||||
counts = dict(ports=ports, native_udp_packets=0)
|
||||
with subprocess.Popen(sys.argv[1:]) as peer:
|
||||
try:
|
||||
while peer.poll() is None:
|
||||
ready, _, _ = select.select([*watchers, observer], [], [], 0.1)
|
||||
# Drain UDP before answering a snapshot in the same cycle.
|
||||
for udp in watchers:
|
||||
if udp in ready:
|
||||
udp.recvfrom(65536)
|
||||
counts["native_udp_packets"] += 1
|
||||
if observer in ready:
|
||||
client, _ = observer.accept()
|
||||
with client:
|
||||
client.settimeout(1)
|
||||
if client.recv(1) == b"?":
|
||||
client.sendall(json.dumps(counts).encode())
|
||||
raise RuntimeError("official UoT peer exited")
|
||||
finally:
|
||||
peer.terminate()
|
||||
try:
|
||||
peer.wait(timeout=3)
|
||||
except subprocess.TimeoutExpired:
|
||||
peer.kill()
|
||||
peer.wait(timeout=3)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -14,7 +14,16 @@ from .protocol_peers import run_command
|
||||
FEATURE_TEST = (
|
||||
"runtime::tests::integration_feature_admission_is_explicit_without_opening_sockets"
|
||||
)
|
||||
PROTOCOLS = ("socks5", "anytls", "shadowsocks", "trojan", "vmess", "vless", "hysteria2")
|
||||
PROTOCOLS = (
|
||||
"socks5",
|
||||
"anytls",
|
||||
"shadowsocks",
|
||||
"trojan",
|
||||
"vmess",
|
||||
"vless",
|
||||
"hysteria2",
|
||||
"tuic",
|
||||
)
|
||||
TARGETS = (
|
||||
"ech_config",
|
||||
"ech_tls",
|
||||
@@ -39,7 +48,16 @@ TARGETS = (
|
||||
"hysteria2_paths",
|
||||
"hysteria2_config",
|
||||
"shadowsocks_backpressure",
|
||||
"shadowtls_config",
|
||||
"shadowtls_stream",
|
||||
"uot_config",
|
||||
"shadowsocks_uot",
|
||||
"hysteria2_packet_ids",
|
||||
"tuic_config",
|
||||
"tuic_memory",
|
||||
"httpupgrade_config",
|
||||
"httpupgrade_memory",
|
||||
"vmess_lifecycle",
|
||||
)
|
||||
LIB_FILTERS = (
|
||||
"security::",
|
||||
@@ -48,6 +66,8 @@ LIB_FILTERS = (
|
||||
"outbound::hysteria2::",
|
||||
"outbound::shadowsocks::tests::official_tcp_",
|
||||
"outbound::anytls::",
|
||||
"outbound::uot::",
|
||||
"outbound::tuic::",
|
||||
"transport::h2_write::tests::",
|
||||
"transport::sing_mux::smux_driver::tests::",
|
||||
"transport::sing_mux::tests::",
|
||||
@@ -91,6 +111,7 @@ def commands(profile: str) -> list[list[str]]:
|
||||
*features,
|
||||
"stream-transport",
|
||||
"quic-transport",
|
||||
"shadow-tls-v3",
|
||||
"tun",
|
||||
"ffi",
|
||||
]
|
||||
|
||||
@@ -62,6 +62,11 @@ def _download_native(
|
||||
)
|
||||
target = f"{platform.system().lower()}-{architecture}"
|
||||
assets = {
|
||||
"ST": (
|
||||
"ihciah/shadow-tls",
|
||||
"shadow-tls",
|
||||
{"linux-arm64": "shadow-tls-aarch64-unknown-linux-musl"},
|
||||
),
|
||||
"SS": (
|
||||
"shadowsocks/shadowsocks-rust",
|
||||
"ssserver",
|
||||
@@ -136,7 +141,7 @@ def _download_native(
|
||||
):
|
||||
_https_response(response)
|
||||
archive_hash = _copy_and_hash(response, output, MAX_ARCHIVE_BYTES)
|
||||
if kind == "H":
|
||||
if kind in {"H", "ST"}:
|
||||
with archive.open("rb") as source, executable.open("wb") as output:
|
||||
binary_hash = _copy_and_hash(source, output, MAX_BINARY_BYTES)
|
||||
elif kind == "SS":
|
||||
@@ -149,7 +154,7 @@ def _download_native(
|
||||
version = None
|
||||
if not defer_version:
|
||||
result = run_command(
|
||||
[str(executable), "--version" if kind == "SS" else "version"],
|
||||
[str(executable), "--version" if kind in {"SS", "ST"} else "version"],
|
||||
timeout=10,
|
||||
limit=4096,
|
||||
)
|
||||
|
||||
@@ -25,6 +25,10 @@ SUITES = {
|
||||
"HYSTERIA2": ("tcp", "udp", "bandwidth", "salamander", "hopping", "acceptance"),
|
||||
"SECURITY": ("encryption", "reality", "ech", "jls", "acceptance"),
|
||||
"INTEGRATION": ("routing", "lifecycle", "pressure", "regression"),
|
||||
"SHADOWTLS": ("configuration", "stream", "interop", "regression"),
|
||||
"UOT": ("configuration", "datagrams", "interop", "regression"),
|
||||
"TUIC": ("configuration", "datagrams", "interop", "regression"),
|
||||
"HTTPUPGRADE": ("configuration", "stream", "interop", "regression"),
|
||||
}
|
||||
CATEGORIES = {
|
||||
f"{suite}.{category}"
|
||||
|
||||
@@ -0,0 +1,366 @@
|
||||
"""Official peer capability fixtures, never VCore protocol acceptance."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import contextlib
|
||||
import json
|
||||
import shutil
|
||||
import tempfile
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from .builds import CORE_DIR
|
||||
from .mihomo_isolation import exclusive_run
|
||||
from .mihomo_release import download_mihomo
|
||||
from .protocol_containers import ContainerLab, frozen_image
|
||||
from .protocol_fixtures import certificates
|
||||
from .protocol_hysteria2_hop import guest
|
||||
from .protocol_inputs import redact, same_source, source_identity
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class PeerCase:
|
||||
identifier: str
|
||||
protocol: str
|
||||
cipher: str = ""
|
||||
shadow_tls: bool = False
|
||||
uot: bool = False
|
||||
tls: bool = False
|
||||
fast_open: bool = False
|
||||
udp_mode: str = ""
|
||||
|
||||
|
||||
CASES = (
|
||||
tuple(
|
||||
PeerCase(
|
||||
f"ss-{algorithm}-{mode}",
|
||||
"ss",
|
||||
f"2022-blake3-{algorithm}",
|
||||
shadow_tls=shadow_tls,
|
||||
uot=uot,
|
||||
)
|
||||
for algorithm in ("aes-128-gcm", "aes-256-gcm", "chacha20-poly1305")
|
||||
for mode, shadow_tls, uot in (
|
||||
("shadowtls", True, False),
|
||||
("uot-v2", False, True),
|
||||
("shadowtls-uot-v2", True, True),
|
||||
)
|
||||
)
|
||||
+ tuple(
|
||||
PeerCase(f"tuic-v5-{mode}", "tuic", tls=True, udp_mode=mode)
|
||||
for mode in ("native", "quic")
|
||||
)
|
||||
+ tuple(
|
||||
PeerCase(
|
||||
f"{protocol}-upgrade-{'tls' if tls else 'plain'}"
|
||||
f"-{'fast' if fast else 'normal'}",
|
||||
protocol,
|
||||
tls=tls,
|
||||
fast_open=fast,
|
||||
)
|
||||
for protocol, tls in (("vmess", False), ("vmess", True), ("trojan", True))
|
||||
for fast in (False, True)
|
||||
)
|
||||
+ (PeerCase("socks5-upstream", "socks5"),)
|
||||
)
|
||||
|
||||
|
||||
def peer_configuration(case, *, server, cover, port, certificate):
|
||||
"""Build matched Mihomo endpoints with explicit latest-only wire choices."""
|
||||
cert, key, pin = certificate
|
||||
if case.protocol != "ss":
|
||||
password = "synthetic-protocol-fixture"
|
||||
identity = "07070707-0707-0707-0707-070707070707"
|
||||
listener = dict(
|
||||
name=case.identifier, type=case.protocol, listen="::", port=port
|
||||
)
|
||||
node = dict(
|
||||
name=case.identifier, type=case.protocol, server=server, port=port, udp=True
|
||||
)
|
||||
if case.tls:
|
||||
listener.update(
|
||||
certificate=f"/data/fixture/{cert.name}",
|
||||
**{"private-key": f"/data/fixture/{key.name}"},
|
||||
)
|
||||
node.update(fingerprint=pin)
|
||||
if case.protocol == "socks5":
|
||||
listener.update(type="socks", udp=True)
|
||||
elif case.protocol == "tuic":
|
||||
listener.update(users={identity: password}, alpn=["h3"])
|
||||
node.update(uuid=identity, password=password, sni="localhost", alpn=["h3"])
|
||||
node["udp-relay-mode"] = case.udp_mode
|
||||
else:
|
||||
if case.protocol == "vmess":
|
||||
listener["users"] = [dict(username="fixture", uuid=identity, alterId=0)]
|
||||
node.update(uuid=identity, alterId=0, cipher="auto", tls=case.tls)
|
||||
node["packet-encoding"] = "xudp"
|
||||
if case.tls:
|
||||
node["servername"] = "localhost"
|
||||
elif case.protocol == "trojan":
|
||||
listener["users"] = [dict(username="fixture", password=password)]
|
||||
node.update(password=password, sni="localhost")
|
||||
else:
|
||||
raise ValueError("unsupported peer capability")
|
||||
listener["ws-path"] = "/protocol-upgrade"
|
||||
node["network"] = "ws"
|
||||
node["ws-opts"] = {
|
||||
"path": "/protocol-upgrade",
|
||||
"headers": {"Host": "localhost"},
|
||||
"v2ray-http-upgrade": True,
|
||||
"v2ray-http-upgrade-fast-open": case.fast_open,
|
||||
}
|
||||
return node, listener
|
||||
password = base64.b64encode(
|
||||
bytes([7]) * (16 if case.cipher == "2022-blake3-aes-128-gcm" else 32)
|
||||
).decode()
|
||||
listener = dict(
|
||||
name=case.identifier,
|
||||
type="shadowsocks",
|
||||
listen="::",
|
||||
port=port,
|
||||
cipher=case.cipher,
|
||||
password=password,
|
||||
udp=not case.uot,
|
||||
)
|
||||
node = dict(
|
||||
name=case.identifier,
|
||||
type="ss",
|
||||
server=server,
|
||||
port=port,
|
||||
cipher=case.cipher,
|
||||
password=password,
|
||||
udp=True,
|
||||
)
|
||||
if case.uot:
|
||||
node.update({"udp-over-tcp": True, "udp-over-tcp-version": 2})
|
||||
if case.shadow_tls:
|
||||
credential = "synthetic-shadowtls-fixture"
|
||||
listener["shadow-tls"] = {
|
||||
"enable": True,
|
||||
"version": 3,
|
||||
"users": [dict(name="fixture", password=credential)],
|
||||
"handshake": dict(dest=cover),
|
||||
"strict-mode": True,
|
||||
}
|
||||
node["plugin"] = "shadow-tls"
|
||||
node["plugin-opts"] = dict(
|
||||
host="localhost", password=credential, version=3, fingerprint=pin
|
||||
)
|
||||
return node, listener
|
||||
|
||||
|
||||
def run(output, *, identifiers=None):
|
||||
output = output.resolve()
|
||||
if not output.is_relative_to((CORE_DIR / "target/interop/runs").resolve()):
|
||||
raise ValueError("peer evidence must stay inside target/interop/runs")
|
||||
selected = (
|
||||
CASES
|
||||
if identifiers is None
|
||||
else tuple(case for case in CASES if case.identifier in identifiers)
|
||||
)
|
||||
if not selected or (
|
||||
identifiers is not None
|
||||
and (
|
||||
len(identifiers) != len(set(identifiers))
|
||||
or len(selected) != len(identifiers)
|
||||
)
|
||||
):
|
||||
raise ValueError("unknown or repeated peer capability selection")
|
||||
report = dict(
|
||||
scope="official-peer-capability-only",
|
||||
vcore_behavior="NOT RUN",
|
||||
status="NOT RUN",
|
||||
source=source_identity(),
|
||||
peer={},
|
||||
isolation={},
|
||||
selected=[case.identifier for case in selected],
|
||||
cases=[],
|
||||
cleanup=False,
|
||||
)
|
||||
output.mkdir(parents=True, exist_ok=False)
|
||||
try:
|
||||
with exclusive_run(), frozen_image(output / "image-pull.log") as image:
|
||||
report["container_image"] = image
|
||||
binary = download_mihomo(
|
||||
"linux-arm64", directory=output / "binary", identity=report["peer"]
|
||||
)
|
||||
lab = ContainerLab(report["isolation"], mtu=1500)
|
||||
with tempfile.TemporaryDirectory(
|
||||
prefix="private-", dir=output
|
||||
) as temporary:
|
||||
root = Path(temporary)
|
||||
directories, peers = {}, {}
|
||||
try:
|
||||
with contextlib.ExitStack() as stack:
|
||||
for role in ("origin", "server", "client"):
|
||||
directory = root / role
|
||||
directory.mkdir()
|
||||
directories[role] = directory
|
||||
if role == "origin":
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_udp_origin.py"),
|
||||
directory / "origin.py",
|
||||
)
|
||||
argv = [
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"VCORE_ORIGIN_CERT=/data/fixture/cert.pem",
|
||||
"VCORE_ORIGIN_KEY=/data/fixture/key.pem",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/origin.py",
|
||||
]
|
||||
else:
|
||||
shutil.copy2(binary, directory / "mihomo")
|
||||
argv = [
|
||||
"/data/fixture/mihomo",
|
||||
"-d",
|
||||
"/data",
|
||||
"-f",
|
||||
"/data/fixture/config.json",
|
||||
]
|
||||
peers[role] = lab.start(stack, directory, role, argv)
|
||||
origin, server, client = (
|
||||
peers[r] for r in ("origin", "server", "client")
|
||||
)
|
||||
report["peer"]["version"] = guest(
|
||||
server, "/data/fixture/mihomo", "-v"
|
||||
).strip()
|
||||
for peer in (server, client):
|
||||
if (
|
||||
guest(
|
||||
peer, "sha256sum", "/data/fixture/mihomo"
|
||||
).split()[0]
|
||||
!= report["peer"]["binary_sha256"]
|
||||
):
|
||||
raise RuntimeError(
|
||||
"container peer differs from official download"
|
||||
)
|
||||
certificate = certificates(directories["server"])
|
||||
for path, name in zip(
|
||||
certificate[:2], ("cert.pem", "key.pem"), strict=True
|
||||
):
|
||||
shutil.copy2(path, directories["origin"] / name)
|
||||
nodes, listeners, ingresses, options = [], [], [], []
|
||||
for index, case in enumerate(selected):
|
||||
node, listener = peer_configuration(
|
||||
case,
|
||||
server=server.ipv4,
|
||||
cover=f"{origin.ipv4}:24001",
|
||||
port=23000 + index,
|
||||
certificate=certificate,
|
||||
)
|
||||
nodes.append(node)
|
||||
listeners.append(listener)
|
||||
ingresses.append(
|
||||
dict(
|
||||
name=case.identifier,
|
||||
type="socks",
|
||||
listen=client.ipv4,
|
||||
port=25000 + index,
|
||||
udp=True,
|
||||
proxy=case.identifier,
|
||||
)
|
||||
)
|
||||
options.append(
|
||||
dict(
|
||||
case_id=case.identifier,
|
||||
socks_host=client.ipv4,
|
||||
socks_port=25000 + index,
|
||||
)
|
||||
)
|
||||
server_config = {
|
||||
"socks-port": 23999,
|
||||
"allow-lan": True,
|
||||
"bind-address": "*",
|
||||
"ipv6": True,
|
||||
"log-level": "warning",
|
||||
"listeners": listeners,
|
||||
"rules": ["MATCH,DIRECT"],
|
||||
}
|
||||
client_config = {
|
||||
"ipv6": True,
|
||||
"log-level": "warning",
|
||||
"proxies": nodes,
|
||||
"listeners": ingresses,
|
||||
"rules": ["MATCH,REJECT"],
|
||||
}
|
||||
for role, configuration in (
|
||||
("server", server_config),
|
||||
("client", client_config),
|
||||
):
|
||||
(directories[role] / "config.json").write_text(
|
||||
json.dumps(configuration)
|
||||
)
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_protocol_client.py"),
|
||||
directories["client"] / "probe.py",
|
||||
)
|
||||
(directories["client"] / "fixture.json").write_text(
|
||||
json.dumps(dict(origin=origin.ipv4, cases=options))
|
||||
)
|
||||
for peer in peers.values():
|
||||
peer.release()
|
||||
origin.wait_tcp(24000)
|
||||
origin.wait_tcp(24001)
|
||||
server.wait_tcp(23999)
|
||||
client.wait_tcp(25000)
|
||||
raw = guest(
|
||||
client,
|
||||
"env",
|
||||
"VCORE_ISOLATED_CLIENT=1",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/probe.py",
|
||||
"/data/fixture/fixture.json",
|
||||
timeout=30 * len(selected),
|
||||
)
|
||||
(output / "observations.jsonl").write_text(raw)
|
||||
rows = [
|
||||
json.loads(line)
|
||||
for line in raw.splitlines()
|
||||
if line.strip()
|
||||
]
|
||||
expected = [
|
||||
dict(
|
||||
case_id=case.identifier,
|
||||
status="PASS",
|
||||
tcp_bytes_each_direction=1024,
|
||||
udp_origin_packets=2,
|
||||
udp_reply_packets=2,
|
||||
udp_sizes=[64, 1200],
|
||||
)
|
||||
for case in selected
|
||||
]
|
||||
if rows != expected:
|
||||
raise RuntimeError(
|
||||
"official peer data evidence is incomplete"
|
||||
)
|
||||
report["cases"] = rows
|
||||
finally:
|
||||
# A failed start may already own a VM/log before returning
|
||||
# its peer. ExitStack has joined it; preserve that log too.
|
||||
for role, directory in directories.items():
|
||||
log = directory / "peer.log"
|
||||
if log.is_file():
|
||||
(output / f"{role}.log").write_text(
|
||||
redact(log.read_text(errors="replace"))
|
||||
)
|
||||
report["status"] = "PASS"
|
||||
except BaseException as error:
|
||||
report["status"] = "FAIL"
|
||||
report["failure_kind"] = type(error).__name__
|
||||
(output / "failure.log").write_text(redact(str(error)))
|
||||
raise
|
||||
finally:
|
||||
report["cleanup"] = all(
|
||||
peer.get("joined") is True for peer in report["isolation"].get("peers", [])
|
||||
)
|
||||
report["source_unchanged"] = same_source(report["source"], source_identity())
|
||||
if not report["cleanup"] or not report["source_unchanged"]:
|
||||
report["status"] = "FAIL"
|
||||
(output / "report.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
if report["status"] != "PASS":
|
||||
raise RuntimeError("peer capability ownership or source evidence failed")
|
||||
print(f"Official peer capabilities: {len(selected)} PASS; VCore behavior: NOT RUN")
|
||||
@@ -91,9 +91,13 @@ def read_json(path: Path):
|
||||
|
||||
def executable_cases() -> list[dict]:
|
||||
"""Single source: retained foundation fixtures plus current protocol catalogs."""
|
||||
from .protocol_httpupgrade_catalog import definitions as httpupgrade
|
||||
from .protocol_hysteria2_catalog import definitions as hysteria2
|
||||
from .protocol_integration_catalog import definitions as integration
|
||||
from .protocol_security_catalog import definitions as security
|
||||
from .protocol_shadowtls_catalog import definitions as shadowtls
|
||||
from .protocol_tuic_catalog import definitions as tuic
|
||||
from .protocol_uot_catalog import definitions as uot
|
||||
from .protocol_vless_acceptance import definitions as vless
|
||||
from .protocol_vmess_acceptance import definitions as vmess
|
||||
from .protocol_xhttp_acceptance import definitions as xhttp
|
||||
@@ -101,7 +105,18 @@ def executable_cases() -> list[dict]:
|
||||
foundation = read_json(CATALOG_DIR / "foundation-cases.json")["cases"]
|
||||
return foundation + [
|
||||
case
|
||||
for define in (vmess, vless, xhttp, hysteria2, security, integration)
|
||||
for define in (
|
||||
vmess,
|
||||
vless,
|
||||
xhttp,
|
||||
hysteria2,
|
||||
security,
|
||||
integration,
|
||||
shadowtls,
|
||||
uot,
|
||||
tuic,
|
||||
httpupgrade,
|
||||
)
|
||||
for case in define()
|
||||
]
|
||||
|
||||
@@ -311,6 +326,10 @@ def validate_results(required: list[dict], results: list[dict]) -> None:
|
||||
"HYSTERIA2",
|
||||
"SECURITY",
|
||||
"INTEGRATION",
|
||||
"SHADOWTLS",
|
||||
"UOT",
|
||||
"TUIC",
|
||||
"HTTPUPGRADE",
|
||||
}
|
||||
else "foundation-only"
|
||||
)
|
||||
@@ -358,7 +377,19 @@ def new_result(case: dict) -> dict:
|
||||
"peer_kind": case["peer_kind"],
|
||||
"scope": "protocol-consumer"
|
||||
if case["stage"]
|
||||
in {"TROJAN", "VMESS", "VLESS", "XHTTP", "HYSTERIA2", "SECURITY", "INTEGRATION"}
|
||||
in {
|
||||
"TROJAN",
|
||||
"VMESS",
|
||||
"VLESS",
|
||||
"XHTTP",
|
||||
"HYSTERIA2",
|
||||
"SECURITY",
|
||||
"INTEGRATION",
|
||||
"SHADOWTLS",
|
||||
"UOT",
|
||||
"TUIC",
|
||||
"HTTPUPGRADE",
|
||||
}
|
||||
else "foundation-only",
|
||||
"status": "NOT RUN",
|
||||
"assertions": {},
|
||||
@@ -420,6 +451,10 @@ def check_run(run_dir: Path, stage: str, manifest: Path | None = None) -> None:
|
||||
"HYSTERIA2",
|
||||
"SECURITY",
|
||||
"INTEGRATION",
|
||||
"SHADOWTLS",
|
||||
"UOT",
|
||||
"TUIC",
|
||||
"HTTPUPGRADE",
|
||||
}:
|
||||
if stage == "TROJAN":
|
||||
from .protocol_trojan_acceptance import check
|
||||
@@ -433,6 +468,14 @@ def check_run(run_dir: Path, stage: str, manifest: Path | None = None) -> None:
|
||||
from .protocol_hysteria2_acceptance import check
|
||||
elif stage == "SECURITY":
|
||||
from .protocol_security_acceptance import check
|
||||
elif stage == "SHADOWTLS":
|
||||
from .protocol_shadowtls_acceptance import check
|
||||
elif stage == "UOT":
|
||||
from .protocol_uot_acceptance import check
|
||||
elif stage == "TUIC":
|
||||
from .protocol_tuic_acceptance import check
|
||||
elif stage == "HTTPUPGRADE":
|
||||
from .protocol_httpupgrade_acceptance import check
|
||||
else:
|
||||
from .protocol_integration_acceptance import check
|
||||
|
||||
|
||||
@@ -178,9 +178,10 @@ def check_warm_captures(rows):
|
||||
|
||||
|
||||
def run(output):
|
||||
if output.parent != CORE_DIR / "target/interop/runs":
|
||||
raise ValueError("use a fresh directory directly under target/interop/runs")
|
||||
output.mkdir(exist_ok=False)
|
||||
output = output.resolve()
|
||||
if not output.is_relative_to((CORE_DIR / "target/interop/runs").resolve()):
|
||||
raise ValueError("use a fresh directory under target/interop/runs")
|
||||
output.mkdir(parents=True, exist_ok=False)
|
||||
report = dict(
|
||||
stage="FINGERPRINT-WIRE",
|
||||
scope="memory-clienthello-structure",
|
||||
|
||||
@@ -459,7 +459,27 @@ def run_protocol_interop(
|
||||
try:
|
||||
run.update(run_identity(stage, selected, preflight_only))
|
||||
with exclusive_run(), deadline(run["suite_timeout_seconds"]):
|
||||
if preflight_only and stage == "INTEGRATION":
|
||||
if preflight_only and stage == "HTTPUPGRADE":
|
||||
from .protocol_httpupgrade_acceptance import (
|
||||
preflight as upgrade_preflight,
|
||||
)
|
||||
|
||||
upgrade_preflight(output)
|
||||
elif preflight_only and stage == "TUIC":
|
||||
from .protocol_tuic_acceptance import preflight as tuic_preflight
|
||||
|
||||
tuic_preflight(output)
|
||||
elif preflight_only and stage == "UOT":
|
||||
from .protocol_uot_acceptance import preflight as uot_preflight
|
||||
|
||||
uot_preflight(output)
|
||||
elif preflight_only and stage == "SHADOWTLS":
|
||||
from .protocol_shadowtls_acceptance import (
|
||||
preflight as shadowtls_preflight,
|
||||
)
|
||||
|
||||
shadowtls_preflight(output)
|
||||
elif preflight_only and stage == "INTEGRATION":
|
||||
from .protocol_integration_acceptance import (
|
||||
preflight as integration_preflight,
|
||||
)
|
||||
@@ -542,6 +562,22 @@ def run_protocol_interop(
|
||||
elif stage == "INTEGRATION":
|
||||
from .protocol_integration_acceptance import execute
|
||||
|
||||
execute(selected, run, output, records)
|
||||
elif stage == "SHADOWTLS":
|
||||
from .protocol_shadowtls_acceptance import execute
|
||||
|
||||
execute(selected, run, output, records)
|
||||
elif stage == "UOT":
|
||||
from .protocol_uot_acceptance import execute
|
||||
|
||||
execute(selected, run, output, records)
|
||||
elif stage == "TUIC":
|
||||
from .protocol_tuic_acceptance import execute
|
||||
|
||||
execute(selected, run, output, records)
|
||||
elif stage == "HTTPUPGRADE":
|
||||
from .protocol_httpupgrade_acceptance import execute
|
||||
|
||||
execute(selected, run, output, records)
|
||||
else:
|
||||
_execute(selected, run, output, records)
|
||||
@@ -616,6 +652,22 @@ def run_protocol_interop(
|
||||
else "Seven-protocol integration; container-only peers. "
|
||||
"Partial selections do not sign off lifecycle or soak gates.\n\n"
|
||||
if stage == "INTEGRATION"
|
||||
else "SS2022 ShadowTLS v3; official Mihomo and native peers "
|
||||
"in isolated containers. "
|
||||
"UoT and device delivery remain separate gates.\n\n"
|
||||
if stage == "SHADOWTLS"
|
||||
else "SS2022 UoT v2; TCP-only official peers in isolated containers. "
|
||||
"Native unsupported peers are negative cases; "
|
||||
"devices remain separate.\n\n"
|
||||
if stage == "UOT"
|
||||
else "TUIC v5 TCP/native UDP/quic UDP; isolated official Mihomo. "
|
||||
"Shared Hysteria2 and XHTTP H3 regressions included; "
|
||||
"devices remain separate.\n\n"
|
||||
if stage == "TUIC"
|
||||
else "VMess/Trojan HTTPUpgrade normal/fast-open; "
|
||||
"official isolated peers and existing transport regressions. "
|
||||
"Device delivery is separate.\n\n"
|
||||
if stage == "HTTPUPGRADE"
|
||||
else "Foundation-only evidence; "
|
||||
"production protocol field consumers remain NOT RUN.\n\n"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,554 @@
|
||||
"""Public HTTPUpgrade consumers against owned official release containers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from .builds import CORE_DIR
|
||||
from .mihomo_isolation import exclusive_run
|
||||
from .mihomo_release import download_mihomo
|
||||
from .native_release import download_native
|
||||
from .protocol_completion_peers import CASES, peer_configuration
|
||||
from .protocol_containers import ContainerLab, command, frozen_image
|
||||
from .protocol_evidence import read_events
|
||||
from .protocol_fixtures import certificates
|
||||
from .protocol_hysteria2_catalog import assertions_pass
|
||||
from .protocol_inputs import redact, same_source, source_identity
|
||||
from .protocol_peers import run_command
|
||||
from .protocol_security_acceptance import rust_command
|
||||
|
||||
CHECKS = ("tcp", "udp", "udp-domain", "early-data", "profiles", "negative", "close")
|
||||
|
||||
|
||||
def selection(checks):
|
||||
rows = []
|
||||
for case in CASES:
|
||||
if case.protocol not in {"vmess", "trojan"}:
|
||||
continue
|
||||
if checks == "udp-domain" and case.protocol != "trojan":
|
||||
continue
|
||||
if checks == "profiles" and not case.tls:
|
||||
continue
|
||||
variants = (
|
||||
("raw", "xudp", "packetaddr")
|
||||
if checks == "udp" and case.protocol == "vmess"
|
||||
else ("raw",)
|
||||
if checks == "udp"
|
||||
else ("domain",)
|
||||
if checks == "udp-domain"
|
||||
else ("ed1", "ed2048")
|
||||
if checks == "early-data"
|
||||
else ("chrome", "chrome120", "firefox", "safari")
|
||||
if checks == "profiles"
|
||||
else ("identity", "path") + (("certificate",) if case.tls else ())
|
||||
if checks == "negative"
|
||||
else ("",)
|
||||
)
|
||||
for variant in variants:
|
||||
consumer = (
|
||||
"udp"
|
||||
if checks.startswith("udp")
|
||||
else "echo_and_stop"
|
||||
if checks in {"early-data", "profiles"}
|
||||
else "rejected"
|
||||
if checks == "negative"
|
||||
else checks
|
||||
)
|
||||
rows.append(
|
||||
(
|
||||
case.identifier + ("-" + variant if variant else ""),
|
||||
case,
|
||||
variant,
|
||||
consumer,
|
||||
)
|
||||
)
|
||||
return rows
|
||||
|
||||
|
||||
def configure(node, checks, variant):
|
||||
if checks == "udp" and node["type"] == "vmess":
|
||||
node["packet-encoding"] = "" if variant == "raw" else variant
|
||||
elif checks == "early-data":
|
||||
node["ws-opts"].update(
|
||||
{"max-early-data": int(variant[2:]), "path": "/protocol-upgrade?probe=once"}
|
||||
)
|
||||
elif checks == "profiles":
|
||||
node["client-fingerprint"] = variant
|
||||
elif checks == "negative":
|
||||
if variant == "identity":
|
||||
node["uuid" if node["type"] == "vmess" else "password"] = (
|
||||
"08080808-0808-0808-0808-080808080808"
|
||||
)
|
||||
elif variant == "certificate":
|
||||
node["fingerprint"] = "00" * 32
|
||||
elif variant == "path":
|
||||
node["ws-opts"]["path"] = "/wrong"
|
||||
|
||||
|
||||
def families(node, kind):
|
||||
return (
|
||||
["domain"]
|
||||
if kind == "XR"
|
||||
else ["ipv4", "ipv6"]
|
||||
if node["type"] == "trojan"
|
||||
else ["ipv4", "ipv6", "domain"]
|
||||
)
|
||||
|
||||
|
||||
def expected_observation(consumer, node=None, kind="M"):
|
||||
if consumer == "echo_and_stop":
|
||||
return dict(authenticated_echo=True, live_stream_cancelled=True, stop_idle=True)
|
||||
if consumer == "rejected":
|
||||
return dict(origin_connected=False, received_business_bytes=0, stop_idle=True)
|
||||
if consumer == "tcp":
|
||||
return dict(
|
||||
families=["ipv4", "ipv6", "domain"],
|
||||
tcp_bytes_each_family_each_direction=10 * 1024 * 1024,
|
||||
server_first=True,
|
||||
client_first=True,
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer == "udp":
|
||||
vmess = node["type"] == "vmess"
|
||||
rows = []
|
||||
for family in families(node, kind):
|
||||
cap = (
|
||||
15000
|
||||
- (
|
||||
(7 if family == "ipv4" else 19)
|
||||
if node.get("packet-encoding") == "packetaddr"
|
||||
else 0
|
||||
)
|
||||
if vmess
|
||||
else 8166
|
||||
if kind == "XR"
|
||||
else 8192
|
||||
)
|
||||
sizes = ([] if vmess or kind == "XR" else [0]) + [1, 64, 512, 1200, cap]
|
||||
rows.append(dict(family=family, sizes=sizes, packets=len(sizes) * 100))
|
||||
return dict(
|
||||
udp=rows,
|
||||
zero_no_delivery=vmess or kind == "XR",
|
||||
oversize_rejected=True,
|
||||
tcp_sibling=True,
|
||||
stop_idle=True,
|
||||
)
|
||||
raise ValueError("unknown HTTPUpgrade consumer")
|
||||
|
||||
|
||||
def measure_close(lab, root, output, binary, origin, node, name):
|
||||
directory = root / (name + "-reference")
|
||||
directory.mkdir()
|
||||
shutil.copy2(binary, directory / "peer")
|
||||
reference = dict(node, name="reference")
|
||||
(directory / "config.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"socks-port": 23002,
|
||||
"allow-lan": True,
|
||||
"bind-address": "*",
|
||||
"ipv6": True,
|
||||
"log-level": "warning",
|
||||
"proxies": [reference],
|
||||
"rules": ["MATCH,reference"],
|
||||
}
|
||||
)
|
||||
)
|
||||
with contextlib.ExitStack() as stack:
|
||||
peer = lab.start(
|
||||
stack,
|
||||
directory,
|
||||
name + "-reference",
|
||||
["/data/fixture/peer", "-d", "/data", "-f", "/data/fixture/config.json"],
|
||||
)
|
||||
peer.release()
|
||||
peer.wait_tcp(23002)
|
||||
measured = run_command(
|
||||
[
|
||||
"container",
|
||||
"exec",
|
||||
origin.name,
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/close.py",
|
||||
peer.ipv4,
|
||||
origin.ipv4,
|
||||
],
|
||||
timeout=30,
|
||||
)
|
||||
(output / (name + "-close-command.log")).write_text(
|
||||
redact(measured.stdout.decode(errors="replace"))
|
||||
)
|
||||
if measured.returncode or not measured.cleanup:
|
||||
raise RuntimeError("official HTTPUpgrade close comparison failed")
|
||||
value = json.loads(measured.stdout)
|
||||
if (
|
||||
set(value) != {"tail_hex", "terminated", "variant"}
|
||||
or value["terminated"] is not True
|
||||
or value["variant"] != "plain"
|
||||
):
|
||||
raise RuntimeError("invalid official close observation")
|
||||
(output / (name + "-reference.log")).write_text(
|
||||
redact((directory / "peer.log").read_text(errors="replace"))
|
||||
)
|
||||
(output / (name + "-close-reference.json")).write_text(json.dumps(value) + "\n")
|
||||
return value
|
||||
|
||||
|
||||
def events_pass(events, consumer):
|
||||
expected = {("HTTPUPGRADE-PUBLIC", consumer): 1}
|
||||
if consumer == "tcp":
|
||||
expected[("HTTPUPGRADE-BASE", "tcp_10mib_both_directions")] = 3
|
||||
return assertions_pass(events, expected)
|
||||
|
||||
|
||||
def native_configuration(rows, certificate, origin):
|
||||
cert, key, _ = certificate
|
||||
return dict(
|
||||
log={"loglevel": "warning"},
|
||||
dns={"hosts": {"vcore-fixture.test": origin}},
|
||||
inbounds=[
|
||||
dict(
|
||||
listen="::",
|
||||
port=node["port"],
|
||||
protocol="trojan",
|
||||
settings={"clients": [{"password": node["password"]}]},
|
||||
streamSettings={
|
||||
"network": "httpupgrade",
|
||||
"security": "tls",
|
||||
"tlsSettings": {
|
||||
"alpn": ["http/1.1"],
|
||||
"certificates": [
|
||||
{
|
||||
"certificateFile": "/data/fixture/" + cert.name,
|
||||
"keyFile": "/data/fixture/" + key.name,
|
||||
}
|
||||
],
|
||||
},
|
||||
"httpupgradeSettings": {
|
||||
"path": "/protocol-upgrade",
|
||||
"host": "localhost",
|
||||
},
|
||||
},
|
||||
)
|
||||
for _, node, _, _ in rows
|
||||
],
|
||||
outbounds=[dict(protocol="freedom", settings={"domainStrategy": "UseIPv4"})],
|
||||
)
|
||||
|
||||
|
||||
def run(output, *, checks="tcp", selected=None, supplied=None, image=None):
|
||||
if checks not in CHECKS:
|
||||
raise ValueError("unknown HTTPUpgrade check")
|
||||
kind = "XR" if checks == "udp-domain" else "M"
|
||||
output = output.resolve()
|
||||
if not output.is_relative_to((CORE_DIR / "target/interop/runs").resolve()):
|
||||
raise ValueError("HTTPUpgrade evidence must stay in target/interop/runs")
|
||||
cases = selection(checks)
|
||||
if selected is not None:
|
||||
if (
|
||||
not selected
|
||||
or len(set(selected)) != len(selected)
|
||||
or not set(selected) <= {c[0] for c in cases}
|
||||
):
|
||||
raise ValueError("unknown or repeated HTTPUpgrade selection")
|
||||
cases = [c for c in cases if c[0] in selected]
|
||||
output.mkdir(parents=True, exist_ok=False)
|
||||
report = dict(
|
||||
source=source_identity(),
|
||||
status="NOT RUN",
|
||||
peer={},
|
||||
peer_kind=kind,
|
||||
isolation={},
|
||||
cases=[],
|
||||
)
|
||||
try:
|
||||
with (
|
||||
exclusive_run() if supplied is None else contextlib.nullcontext(),
|
||||
frozen_image(output / "image-pull.log")
|
||||
if image is None
|
||||
else contextlib.nullcontext(image) as image,
|
||||
):
|
||||
report["container_image"] = image
|
||||
if supplied is None and kind == "M":
|
||||
binary = download_mihomo(
|
||||
"linux-arm64", directory=output / "binary", identity=report["peer"]
|
||||
)
|
||||
elif supplied is None:
|
||||
artifact = download_native(
|
||||
kind, output / "binary", "linux-arm64", defer_version=True
|
||||
)
|
||||
binary, report["peer"] = artifact.binary, artifact.identity
|
||||
else:
|
||||
binary, report["peer"] = supplied
|
||||
built = run_command(
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--all-features",
|
||||
"--test",
|
||||
"vless_public",
|
||||
"--no-run",
|
||||
],
|
||||
cwd=CORE_DIR,
|
||||
timeout=180,
|
||||
)
|
||||
(output / "build.log").write_text(
|
||||
redact(built.stdout.decode(errors="replace"))
|
||||
)
|
||||
if built.returncode or not built.cleanup:
|
||||
raise RuntimeError("HTTPUpgrade consumer build failed")
|
||||
lab = ContainerLab(report["isolation"], mtu=1500)
|
||||
with tempfile.TemporaryDirectory(prefix="private-", dir=output) as tmp:
|
||||
root = Path(tmp)
|
||||
directories = {role: root / role for role in ("origin", "server")}
|
||||
for directory in directories.values():
|
||||
directory.mkdir()
|
||||
certificate = certificates(directories["server"])
|
||||
shutil.copy2(binary, directories["server"] / "peer")
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_udp_origin.py"),
|
||||
directories["origin"] / "origin.py",
|
||||
)
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_close_client.py"),
|
||||
directories["origin"] / "close.py",
|
||||
)
|
||||
try:
|
||||
with contextlib.ExitStack() as stack:
|
||||
origin = lab.start(
|
||||
stack,
|
||||
directories["origin"],
|
||||
"origin",
|
||||
[
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/origin.py",
|
||||
],
|
||||
)
|
||||
server = lab.start(
|
||||
stack,
|
||||
directories["server"],
|
||||
"server",
|
||||
[
|
||||
"/data/fixture/peer",
|
||||
"-d",
|
||||
"/data",
|
||||
"-f",
|
||||
"/data/fixture/config.json",
|
||||
]
|
||||
if kind == "M"
|
||||
else [
|
||||
"/data/fixture/peer",
|
||||
"run",
|
||||
"-c",
|
||||
"/data/fixture/config.json",
|
||||
],
|
||||
)
|
||||
report["peer"]["version"] = command(
|
||||
"exec",
|
||||
server.name,
|
||||
"/data/fixture/peer",
|
||||
"-v" if kind == "M" else "version",
|
||||
).strip()
|
||||
if (
|
||||
command(
|
||||
"exec", server.name, "sha256sum", "/data/fixture/peer"
|
||||
).split()[0]
|
||||
!= report["peer"]["binary_sha256"]
|
||||
):
|
||||
raise RuntimeError("HTTPUpgrade peer identity mismatch")
|
||||
rows = []
|
||||
for i, (name, case, variant, consumer) in enumerate(cases):
|
||||
node, listener = peer_configuration(
|
||||
case,
|
||||
server=server.ipv4,
|
||||
cover="",
|
||||
port=23000 + i,
|
||||
certificate=certificate,
|
||||
)
|
||||
node["name"] = "peer"
|
||||
listener["name"] = name
|
||||
configure(node, checks, variant)
|
||||
rows.append(
|
||||
(
|
||||
name,
|
||||
node,
|
||||
listener,
|
||||
consumer,
|
||||
)
|
||||
)
|
||||
(directories["server"] / "config.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"socks-port": 23999,
|
||||
"allow-lan": True,
|
||||
"bind-address": "*",
|
||||
"ipv6": True,
|
||||
"log-level": "warning",
|
||||
"hosts": {"vcore-fixture.test": origin.ipv4},
|
||||
"listeners": [r[2] for r in rows],
|
||||
"rules": ["MATCH,DIRECT"],
|
||||
}
|
||||
if kind == "M"
|
||||
else native_configuration(
|
||||
rows, certificate, origin.ipv4
|
||||
)
|
||||
)
|
||||
)
|
||||
checked = run_command(
|
||||
[
|
||||
"container",
|
||||
"exec",
|
||||
server.name,
|
||||
"/data/fixture/peer",
|
||||
"-t",
|
||||
"-d",
|
||||
"/data",
|
||||
"-f",
|
||||
"/data/fixture/config.json",
|
||||
]
|
||||
if kind == "M"
|
||||
else [
|
||||
"container",
|
||||
"exec",
|
||||
server.name,
|
||||
"/data/fixture/peer",
|
||||
"run",
|
||||
"-test",
|
||||
"-c",
|
||||
"/data/fixture/config.json",
|
||||
],
|
||||
timeout=30,
|
||||
)
|
||||
(output / "peer-config.log").write_text(
|
||||
redact(checked.stdout.decode(errors="replace"))
|
||||
)
|
||||
if checked.returncode or not checked.cleanup:
|
||||
raise RuntimeError("HTTPUpgrade peer configuration failed")
|
||||
origin.release()
|
||||
origin.wait_tcp(24000)
|
||||
server.release()
|
||||
server.wait_tcp(23999 if kind == "M" else rows[0][1]["port"])
|
||||
for name, node, _, consumer in rows:
|
||||
reference = (
|
||||
measure_close(
|
||||
lab, root, output, binary, origin, node, name
|
||||
)
|
||||
if consumer == "close"
|
||||
else None
|
||||
)
|
||||
fixture = root / "fixture.json"
|
||||
fixture.write_text(
|
||||
json.dumps(
|
||||
dict(
|
||||
isolation="containers",
|
||||
node=node,
|
||||
peer_kind=kind,
|
||||
families=families(node, kind),
|
||||
origin_ipv4=origin.ipv4,
|
||||
origin_ipv6=origin.ipv6,
|
||||
origin_control=f"{origin.ipv4}:24000",
|
||||
data_dir=str(root / "data"),
|
||||
close_reference=reference,
|
||||
)
|
||||
)
|
||||
)
|
||||
observations = output / (name + "-observations.json")
|
||||
events = output / (name + "-events.jsonl")
|
||||
argv = rust_command(
|
||||
"vless_public", "httpupgrade::" + consumer
|
||||
)
|
||||
result = run_command(
|
||||
argv,
|
||||
cwd=CORE_DIR,
|
||||
timeout=240,
|
||||
env=dict(
|
||||
os.environ,
|
||||
VCORE_VLESS_INPUT=str(fixture),
|
||||
VCORE_HTTPUPGRADE_OBSERVATIONS=str(observations),
|
||||
VCORE_PROTOCOL_STAGE="HTTPUPGRADE",
|
||||
VCORE_CASE_EVENTS=str(events),
|
||||
),
|
||||
)
|
||||
(output / (name + ".log")).write_text(
|
||||
redact(result.stdout.decode(errors="replace"))
|
||||
)
|
||||
observed = (
|
||||
json.loads(observations.read_text())
|
||||
if observations.is_file()
|
||||
else None
|
||||
)
|
||||
good = (
|
||||
result.returncode == 0
|
||||
and result.cleanup
|
||||
and observed
|
||||
== (
|
||||
dict(
|
||||
tail_hex=reference["tail_hex"],
|
||||
terminated=True,
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer == "close"
|
||||
else expected_observation(consumer, node, kind)
|
||||
)
|
||||
and events_pass(read_events(events), consumer)
|
||||
)
|
||||
report["cases"].append(
|
||||
dict(
|
||||
case_id=name,
|
||||
command=argv,
|
||||
exit_code=result.returncode,
|
||||
command_cleanup=result.cleanup,
|
||||
observations=observed,
|
||||
status="PASS" if good else "FAIL",
|
||||
)
|
||||
)
|
||||
print(name + (": PASS" if good else ": FAIL"), flush=True)
|
||||
if not good:
|
||||
raise RuntimeError("HTTPUpgrade consumer failed")
|
||||
finally:
|
||||
for role, directory in directories.items():
|
||||
if (directory / "peer.log").is_file():
|
||||
(output / (role + ".log")).write_text(
|
||||
redact(
|
||||
(directory / "peer.log").read_text(errors="replace")
|
||||
)
|
||||
)
|
||||
report["status"] = "PASS"
|
||||
except BaseException as error:
|
||||
report["status"] = "FAIL"
|
||||
(output / "failure.log").write_text(redact(str(error)))
|
||||
raise
|
||||
finally:
|
||||
report["cleanup"] = all(
|
||||
p.get("joined") is True for p in report["isolation"].get("peers", [])
|
||||
)
|
||||
report["source_unchanged"] = same_source(report["source"], source_identity())
|
||||
if not report["cleanup"] or not report["source_unchanged"]:
|
||||
report["status"] = "FAIL"
|
||||
(output / "report.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
if report["status"] != "PASS":
|
||||
raise RuntimeError("HTTPUpgrade source or cleanup failed")
|
||||
return report
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("--case", action="append")
|
||||
parser.add_argument("--checks", choices=CHECKS, default="tcp")
|
||||
args = parser.parse_args()
|
||||
run(args.output, checks=args.checks, selected=args.case)
|
||||
@@ -0,0 +1,253 @@
|
||||
"""Run HTTPUpgrade gates and independently reconstruct persisted acceptance."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from .core_checks import validate_execution
|
||||
from .protocol_evidence import read_events, read_json
|
||||
from .protocol_httpupgrade import events_pass, expected_observation
|
||||
from .protocol_httpupgrade_catalog import (
|
||||
LOCAL,
|
||||
REGRESSION,
|
||||
UNIT,
|
||||
WIRE,
|
||||
commands,
|
||||
wire_cases,
|
||||
)
|
||||
from .protocol_hysteria2_catalog import assertions_pass
|
||||
from .protocol_inputs import redact
|
||||
from .protocol_integration_checks import envelope
|
||||
from .protocol_security_acceptance import result, rust_command
|
||||
from .protocol_shadowtls_acceptance import source
|
||||
|
||||
|
||||
def wire_pass(name, directory, report):
|
||||
expected = wire_cases(name)
|
||||
rows = report.get("cases", [])
|
||||
if [r.get("case_id") for r in rows] != [r[0] for r in expected]:
|
||||
return False
|
||||
for row, (identifier, consumer) in zip(rows, expected, strict=True):
|
||||
observed = read_json(directory / (identifier + "-observations.json"))
|
||||
if consumer == "close":
|
||||
reference = read_json(directory / (identifier + "-close-reference.json"))
|
||||
raw = json.loads(
|
||||
(directory / (identifier + "-close-command.log")).read_text()
|
||||
)
|
||||
if (
|
||||
reference != raw
|
||||
or raw.get("terminated") is not True
|
||||
or raw.get("variant") != "plain"
|
||||
):
|
||||
return False
|
||||
wanted = dict(tail_hex=raw["tail_hex"], terminated=True, stop_idle=True)
|
||||
else:
|
||||
node = dict(type="vmess" if identifier.startswith("vmess") else "trojan")
|
||||
node["packet-encoding"] = identifier.rsplit("-", 1)[-1]
|
||||
wanted = expected_observation(
|
||||
consumer, node, "XR" if name == "UDP-DOMAIN" else "M"
|
||||
)
|
||||
if not (
|
||||
row.get("command")
|
||||
== rust_command("vless_public", "httpupgrade::" + consumer)
|
||||
and type(row.get("exit_code")) is int
|
||||
and row["exit_code"] == 0
|
||||
and row.get("command_cleanup") is True
|
||||
and observed == row.get("observations") == wanted
|
||||
and events_pass(
|
||||
read_events(directory / (identifier + "-events.jsonl")), consumer
|
||||
)
|
||||
):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def local_pass(name, directory, run):
|
||||
rows = [
|
||||
r for r in run["commands"] if r["name"].startswith("HTTPUPGRADE-" + name + "-")
|
||||
]
|
||||
expected = commands(name)
|
||||
if len(rows) != len(expected):
|
||||
return False
|
||||
events = []
|
||||
for i, (row, argv) in enumerate(zip(rows, expected, strict=True)):
|
||||
label = f"HTTPUPGRADE-{name}-{i}"
|
||||
if row["name"] != label or row["command"] != [redact(v) for v in argv]:
|
||||
return False
|
||||
validate_execution(
|
||||
row["command"],
|
||||
(directory / row["log"]).read_text(),
|
||||
row["exit_code"],
|
||||
row["cleanup"],
|
||||
)
|
||||
path = directory / (label + "-events.jsonl")
|
||||
if path.exists():
|
||||
events += read_events(path)
|
||||
return name not in {"MEMORY", "FEATURES"} or assertions_pass(
|
||||
[e for e in events if e.get("suite", "").startswith("HTTPUPGRADE-")],
|
||||
{("HTTPUPGRADE-UNIT", n): 1 if name == "MEMORY" else 2 for n in UNIT},
|
||||
)
|
||||
|
||||
|
||||
def regression_pass(name, directory, report):
|
||||
from .protocol_vless_public import PUBLIC
|
||||
from .protocol_vless_public import events_pass as vless_events
|
||||
from .protocol_vmess_public import CASES
|
||||
from .protocol_vmess_public import events_pass as vmess_events
|
||||
|
||||
selected = REGRESSION[name]
|
||||
rows = report.get("cases", [])
|
||||
if [r.get("case_id") for r in rows] != selected:
|
||||
return False
|
||||
for row in rows:
|
||||
identifier = row["case_id"]
|
||||
kind, mode, _, consumer = (PUBLIC if name == "VLESS" else CASES)[identifier]
|
||||
observed = read_events(directory / (identifier + "-events.jsonl"))
|
||||
if not (
|
||||
row.get("peer_kind") == kind
|
||||
and row.get("command") == rust_command(name.lower() + "_public", consumer)
|
||||
and type(row.get("exit_code")) is int
|
||||
and row["exit_code"] == 0
|
||||
and row.get("command_cleanup") is True
|
||||
and row.get("cleanup") is True
|
||||
and (
|
||||
vless_events(observed, consumer, mode)
|
||||
if name == "VLESS"
|
||||
else vmess_events(observed, consumer)
|
||||
)
|
||||
):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def group_pass(name, directory, run, peers):
|
||||
if name in LOCAL:
|
||||
return local_pass(name, directory, run)
|
||||
root = directory / name.lower()
|
||||
report = read_json(
|
||||
root / ("report.json" if name in WIRE else name.lower() + "-results.json")
|
||||
)
|
||||
return envelope(
|
||||
report,
|
||||
peers,
|
||||
source(run),
|
||||
run["container_image"]["digest"],
|
||||
single=("XR" if name == "UDP-DOMAIN" else "M") if name in WIRE else None,
|
||||
) and (
|
||||
wire_pass(name, root, report)
|
||||
if name in WIRE
|
||||
else regression_pass(name, root, report)
|
||||
)
|
||||
|
||||
|
||||
def execute(cases, run, output, results):
|
||||
from .protocol_containers import frozen_image
|
||||
from .protocol_harness import _command
|
||||
from .protocol_httpupgrade import run as upgrade
|
||||
from .protocol_hysteria2_acceptance import prepare
|
||||
from .protocol_vless_container import run as vless
|
||||
from .protocol_vmess_container import run as vmess
|
||||
|
||||
selected = {c["case_id"].removeprefix("HTTPUPGRADE-"): c for c in cases}
|
||||
peers = {}
|
||||
|
||||
def save(name):
|
||||
good = group_pass(name, output, run, peers)
|
||||
case = selected[name]
|
||||
results[case["case_id"]] = result(case, good, good)
|
||||
print(case["case_id"] + (": PASS" if good else ": FAIL"), flush=True)
|
||||
if not good:
|
||||
raise RuntimeError("HTTPUpgrade gate failed: " + name)
|
||||
|
||||
try:
|
||||
for name in selected:
|
||||
if name not in LOCAL:
|
||||
continue
|
||||
for i, argv in enumerate(commands(name)):
|
||||
label = f"HTTPUPGRADE-{name}-{i}"
|
||||
completed = _command(
|
||||
run,
|
||||
output,
|
||||
label,
|
||||
argv,
|
||||
3600,
|
||||
events=output / (label + "-events.jsonl"),
|
||||
)
|
||||
validate_execution(
|
||||
argv,
|
||||
completed.stdout.decode(errors="replace"),
|
||||
completed.returncode,
|
||||
completed.cleanup,
|
||||
)
|
||||
save(name)
|
||||
if set(selected) <= LOCAL:
|
||||
return
|
||||
with frozen_image(output / "image-pull.log") as image:
|
||||
run["container_image"] = image
|
||||
kinds = (
|
||||
{"M"}
|
||||
| ({"XR"} if "UDP-DOMAIN" in selected else set())
|
||||
| ({"V2"} if "VMESS" in selected else set())
|
||||
)
|
||||
supplied = prepare(output, kinds)
|
||||
peers.update({k: v[1] for k, v in supplied.items()})
|
||||
for name in selected:
|
||||
if name in LOCAL:
|
||||
continue
|
||||
root = output / name.lower()
|
||||
if name in WIRE:
|
||||
upgrade(
|
||||
root,
|
||||
checks=name.lower(),
|
||||
supplied=supplied["XR" if name == "UDP-DOMAIN" else "M"],
|
||||
image=image,
|
||||
)
|
||||
elif name == "VLESS":
|
||||
vless(root, selected=REGRESSION[name], supplied=supplied)
|
||||
elif name == "VMESS":
|
||||
vmess(root, selected=REGRESSION[name], supplied=supplied)
|
||||
save(name)
|
||||
finally:
|
||||
(output / "peers.json").write_text(json.dumps(peers, indent=2) + "\n")
|
||||
|
||||
|
||||
def check(directory, cases, run, results, peers, paths):
|
||||
if not {"cases.json", "peers.json", "resources.jsonl", "summary.md"} <= set(paths):
|
||||
raise ValueError("missing HTTPUpgrade evidence")
|
||||
expected = [
|
||||
f"{c['case_id']}-{i}"
|
||||
for c in cases
|
||||
for i, _ in enumerate(commands(c["case_id"].removeprefix("HTTPUPGRADE-")))
|
||||
]
|
||||
actual = [r["name"] for r in run["commands"]]
|
||||
if (
|
||||
len(actual) != len(set(actual))
|
||||
or set(actual) != set(expected)
|
||||
or set(peers) != {"M", "XR", "V2"}
|
||||
):
|
||||
raise ValueError("HTTPUpgrade command or peer selection differs")
|
||||
for case in cases:
|
||||
name = case["case_id"].removeprefix("HTTPUPGRADE-")
|
||||
if not group_pass(name, directory, run, peers):
|
||||
raise ValueError("HTTPUpgrade raw evidence failed: " + name)
|
||||
print("HTTPUpgrade coverage: PASS (all required groups; device delivery separate)")
|
||||
|
||||
|
||||
def preflight(output):
|
||||
from .protocol_containers import command, frozen_image
|
||||
from .protocol_hysteria2_acceptance import prepare
|
||||
|
||||
command("system", "status")
|
||||
with frozen_image(output / "image-pull.log"):
|
||||
supplied = prepare(output, {"M", "XR", "V2"})
|
||||
(output / "peers.json").write_text(
|
||||
json.dumps(
|
||||
dict(
|
||||
scope="download-only",
|
||||
wire_acceptance="NOT RUN",
|
||||
peers={k: v[1] for k, v in supplied.items()},
|
||||
),
|
||||
indent=2,
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
@@ -0,0 +1,174 @@
|
||||
"""Independent required HTTPUpgrade consumers and regression selection."""
|
||||
|
||||
from .protocol_shadowtls_catalog import commands as shared_commands
|
||||
|
||||
LOCAL = {"MEMORY", "FEATURES", "QUALITY", "PLATFORMS"}
|
||||
WIRE = ("TCP", "UDP", "UDP-DOMAIN", "EARLY-DATA", "PROFILES", "NEGATIVE", "CLOSE")
|
||||
GATES = ("MEMORY", "FEATURES", "QUALITY", "PLATFORMS", *WIRE, "VLESS", "VMESS")
|
||||
BASES = tuple(
|
||||
f"{protocol}-upgrade-{security}-{mode}"
|
||||
for protocol, security in (("vmess", "plain"), ("vmess", "tls"), ("trojan", "tls"))
|
||||
for mode in ("normal", "fast")
|
||||
)
|
||||
UNIT = (
|
||||
"config_dispatch",
|
||||
"config_bounds",
|
||||
"early_data",
|
||||
"invalid_response",
|
||||
"deadline_cancel",
|
||||
"expired_deadline",
|
||||
"late_response",
|
||||
"late_write",
|
||||
"established_io",
|
||||
)
|
||||
REGRESSION = {
|
||||
"VLESS": [
|
||||
"VLESS-" + mode + "-BASE"
|
||||
for mode in (
|
||||
"WS",
|
||||
"WS-TLS",
|
||||
"UPGRADE",
|
||||
"UPGRADE-FAST",
|
||||
"UPGRADE-TLS",
|
||||
"UPGRADE-FAST-TLS",
|
||||
)
|
||||
]
|
||||
+ [
|
||||
"VLESS-REGRESSION-" + protocol + "-" + network
|
||||
for protocol in ("VMESS", "TROJAN")
|
||||
for network in ("TCP", "WS", "GRPC")
|
||||
],
|
||||
"VMESS": ["VMESS-PUBLIC-" + mode + "-TLS-BASE" for mode in ("HTTP", "H2")],
|
||||
}
|
||||
|
||||
|
||||
def wire_cases(name):
|
||||
rows = []
|
||||
for base in BASES:
|
||||
if name == "UDP-DOMAIN" and not base.startswith("trojan"):
|
||||
continue
|
||||
if name == "PROFILES" and "-plain-" in base:
|
||||
continue
|
||||
variants = {
|
||||
"TCP": ("",),
|
||||
"CLOSE": ("",),
|
||||
"UDP": ("raw", "xudp", "packetaddr")
|
||||
if base.startswith("vmess")
|
||||
else ("raw",),
|
||||
"UDP-DOMAIN": ("domain",),
|
||||
"EARLY-DATA": ("ed1", "ed2048"),
|
||||
"PROFILES": ("chrome", "chrome120", "firefox", "safari"),
|
||||
"NEGATIVE": ("identity", "path")
|
||||
+ (("certificate",) if "-tls-" in base else ()),
|
||||
}[name]
|
||||
consumer = {
|
||||
"TCP": "tcp",
|
||||
"CLOSE": "close",
|
||||
"UDP": "udp",
|
||||
"UDP-DOMAIN": "udp",
|
||||
"EARLY-DATA": "echo_and_stop",
|
||||
"PROFILES": "echo_and_stop",
|
||||
"NEGATIVE": "rejected",
|
||||
}[name]
|
||||
rows += [(base + ("-" + v if v else ""), consumer) for v in variants]
|
||||
return rows
|
||||
|
||||
|
||||
def definitions():
|
||||
return [
|
||||
dict(
|
||||
case_id="HTTPUPGRADE-" + name,
|
||||
stage="HTTPUPGRADE",
|
||||
substage="HTTPUPGRADE."
|
||||
+ (
|
||||
"configuration"
|
||||
if name == "FEATURES"
|
||||
else "stream"
|
||||
if name == "MEMORY"
|
||||
else "interop"
|
||||
if name in WIRE
|
||||
else "regression"
|
||||
),
|
||||
required=True,
|
||||
row_ids=[],
|
||||
protocol="vmess/trojan",
|
||||
network="httpupgrade",
|
||||
security="plain/tls",
|
||||
udp_codec="raw/xudp/packetaddr/trojan",
|
||||
field_values={},
|
||||
outer_family="IPv4",
|
||||
inner_family="IPv4/IPv6/domain",
|
||||
target_type="memory-only/build" if name in LOCAL else "isolated origin",
|
||||
upstream_graph="existing connector",
|
||||
peer_kind="unit"
|
||||
if name in LOCAL
|
||||
else "XR"
|
||||
if name == "UDP-DOMAIN"
|
||||
else "V2"
|
||||
if name == "VMESS"
|
||||
else "M",
|
||||
peer_config={"group": name},
|
||||
gap_source=None,
|
||||
expected_observation=["HTTPUPGRADE-" + name],
|
||||
required_evidence=["command", "structured-assertions", "cleanup"]
|
||||
+ ([] if name in LOCAL else ["peer-identity", "isolated-origins"]),
|
||||
prerequisites=["rust-toolchain"]
|
||||
if name in LOCAL
|
||||
else ["owned-host-only-container-network", "official-latest-peer"],
|
||||
runner="httpupgrade-gate",
|
||||
timeout_seconds=3600,
|
||||
)
|
||||
for name in GATES
|
||||
]
|
||||
|
||||
|
||||
def commands(name):
|
||||
cargo = ["cargo", "test", "--locked", "--all-features"]
|
||||
if name == "MEMORY":
|
||||
return [
|
||||
cargo
|
||||
+ [
|
||||
arg
|
||||
for t in (
|
||||
"httpupgrade_config",
|
||||
"httpupgrade_memory",
|
||||
"vmess_lifecycle",
|
||||
"vmess_config",
|
||||
"trojan",
|
||||
"trojan_config",
|
||||
"vless_config",
|
||||
"vless_lifecycle",
|
||||
"stream_foundations",
|
||||
"stream_shutdown",
|
||||
)
|
||||
for arg in ("--test", t)
|
||||
]
|
||||
]
|
||||
if name == "FEATURES":
|
||||
return (
|
||||
[
|
||||
["cargo", "check", "--locked", "--no-default-features"]
|
||||
+ (["--features", f] if f else [])
|
||||
for f in ("", "stream-transport", "outbound-vmess", "outbound-trojan")
|
||||
]
|
||||
+ [
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--no-default-features",
|
||||
"--features",
|
||||
f + ",interop-test",
|
||||
"--test",
|
||||
"httpupgrade_config",
|
||||
"--test",
|
||||
"httpupgrade_memory",
|
||||
]
|
||||
for f in ("outbound-vmess", "outbound-trojan")
|
||||
]
|
||||
+ [
|
||||
["cargo", "test", "--locked", "--test", "feature_foundations"],
|
||||
cargo + ["--all-targets", "--no-run"],
|
||||
]
|
||||
)
|
||||
return shared_commands(name) if name in {"QUALITY", "PLATFORMS"} else []
|
||||
@@ -6,7 +6,7 @@ import json
|
||||
|
||||
from .protocol_evidence import read_events, read_json
|
||||
from .protocol_hysteria2_catalog import assertions_pass
|
||||
from .protocol_integration_catalog import LOCAL, PAIRS, definitions
|
||||
from .protocol_integration_catalog import CHAINS, LOCAL, ORDERED, PAIRS, definitions
|
||||
from .protocol_integration_checks import envelope, runtime_pass
|
||||
from .protocol_integration_local import commands, passed
|
||||
from .protocol_integration_shared import hops_pass, shared_pass
|
||||
@@ -16,7 +16,7 @@ from .protocol_security_acceptance import result
|
||||
def pair_pass(identifier, record, directory):
|
||||
from .protocol_integration_native import rust_command
|
||||
|
||||
first, last = PAIRS[identifier]
|
||||
first, last = ORDERED[identifier]
|
||||
targets = 2 if last == "trojan" else 3
|
||||
events = read_events(directory / (identifier + "-events.jsonl"))
|
||||
observation = read_json(directory / (identifier + "-observations.json"))
|
||||
@@ -29,9 +29,14 @@ def pair_pass(identifier, record, directory):
|
||||
udp_target_kinds=targets,
|
||||
udp_packets=targets * 400,
|
||||
udp_sizes=[1, 64, 512, 1200],
|
||||
server_first=True,
|
||||
server_first=last != "ss",
|
||||
client_first=True,
|
||||
ports_rebound=True,
|
||||
**(
|
||||
{"server_first_limitation": "official-ss2022-empty-first-write"}
|
||||
if last == "ss"
|
||||
else {}
|
||||
),
|
||||
)
|
||||
for v6 in (False, True)
|
||||
for group in (False, True)
|
||||
@@ -78,10 +83,11 @@ def pair_pass(identifier, record, directory):
|
||||
),
|
||||
carrier_capability=dict(
|
||||
upstream_datagrams="rejected",
|
||||
tcp_allowed=last != "hysteria2",
|
||||
udp_allowed=last not in {"ss", "socks5", "hysteria2"},
|
||||
tcp_allowed=last not in {"hysteria2", "tuic"},
|
||||
udp_allowed=last not in {"ss", "socks5", "hysteria2", "tuic"},
|
||||
no_bypass=True,
|
||||
),
|
||||
**({"variant": CHAINS[identifier]} if identifier in CHAINS else {}),
|
||||
)
|
||||
and assertions_pass(
|
||||
events,
|
||||
@@ -105,6 +111,8 @@ def execute(cases, run, output, results):
|
||||
from .protocol_containers import frozen_image
|
||||
from .protocol_harness import _command
|
||||
from .protocol_hysteria2_acceptance import prepare
|
||||
from .protocol_integration_coupled import passed as coupled_pass
|
||||
from .protocol_integration_coupled import run as coupled_run
|
||||
from .protocol_integration_native import run as run_pairs
|
||||
from .protocol_integration_shared import hops_run, shared_run
|
||||
from .protocol_integration_suite import CONSUMERS
|
||||
@@ -160,7 +168,7 @@ def execute(cases, run, output, results):
|
||||
kinds = {"M"}
|
||||
if "INTEGRATION-SHARED" in by_id:
|
||||
kinds |= {"XR", "V2"}
|
||||
if any(PAIRS[i][1] == "trojan" for i in by_id.keys() & PAIRS.keys()):
|
||||
if any(ORDERED[i][1] == "trojan" for i in by_id.keys() & ORDERED.keys()):
|
||||
kinds.add("XR")
|
||||
if "INTEGRATION-HY2-HOP" in by_id:
|
||||
kinds.add("H")
|
||||
@@ -169,7 +177,7 @@ def execute(cases, run, output, results):
|
||||
digest = snapshot["digest"]
|
||||
# Each group is rerun from this source/image/peer scope. Historical
|
||||
# reports are never imported into results.
|
||||
selected = sorted(by_id.keys() & PAIRS.keys())
|
||||
selected = sorted(by_id.keys() & ORDERED.keys())
|
||||
if selected:
|
||||
directory = output / "pairs"
|
||||
report = run_pairs(
|
||||
@@ -188,6 +196,12 @@ def execute(cases, run, output, results):
|
||||
and pair_pass(identifier, record, directory),
|
||||
report["cleanup"],
|
||||
)
|
||||
if "INTEGRATION-COUPLED" in by_id:
|
||||
coupled_run(output / "coupled", supplied["M"], snapshot)
|
||||
save(
|
||||
"INTEGRATION-COUPLED",
|
||||
coupled_pass(output / "coupled", peers, source, digest),
|
||||
)
|
||||
selected = sorted(
|
||||
by_id.keys() & CONSUMERS.keys(),
|
||||
key=lambda k: (k == "INTEGRATION-SOAK", k),
|
||||
@@ -229,6 +243,7 @@ def check(run_dir, cases, run, results, peers, paths):
|
||||
from .protocol_containers import IMAGE
|
||||
from .protocol_evidence import HEX
|
||||
from .protocol_inputs import redact
|
||||
from .protocol_integration_coupled import passed as coupled_pass
|
||||
from .protocol_integration_suite import CONSUMERS
|
||||
|
||||
observed_paths = {
|
||||
@@ -285,7 +300,7 @@ def check(run_dir, cases, run, results, peers, paths):
|
||||
key=lambda k: (k == "INTEGRATION-SOAK", k),
|
||||
)
|
||||
if (
|
||||
[r.get("case_id") for r in pair_report.get("cases", [])] != sorted(PAIRS)
|
||||
[r.get("case_id") for r in pair_report.get("cases", [])] != sorted(ORDERED)
|
||||
or [r.get("case_id") for r in runtime_report.get("cases", [])]
|
||||
!= expected_runtime
|
||||
or set(pair_report.get("peers", {})) != {"M", "XR"}
|
||||
@@ -325,8 +340,8 @@ def check(run_dir, cases, run, results, peers, paths):
|
||||
if identifier == "INTEGRATION-SCRIPTS"
|
||||
else None,
|
||||
)
|
||||
elif identifier in PAIRS or identifier in CONSUMERS:
|
||||
pair = identifier in PAIRS
|
||||
elif identifier in ORDERED or identifier in CONSUMERS:
|
||||
pair = identifier in ORDERED
|
||||
report = pair_report if pair else runtime_report
|
||||
record = next(r for r in report["cases"] if r["case_id"] == identifier)
|
||||
directory = run_dir / ("pairs" if pair else "runtime")
|
||||
@@ -335,12 +350,15 @@ def check(run_dir, cases, run, results, peers, paths):
|
||||
)(identifier, record, directory)
|
||||
elif identifier == "INTEGRATION-HY2-HOP":
|
||||
good = hops_pass(run_dir / "hop", peers, source, digest)
|
||||
elif identifier == "INTEGRATION-COUPLED":
|
||||
good = coupled_pass(run_dir / "coupled", peers, source, digest)
|
||||
else:
|
||||
good = shared_pass(run_dir / "shared", peers, source, digest)
|
||||
if not good or result(case, good, True) != actual[identifier]:
|
||||
raise ValueError("INTEGRATION raw evidence does not pass: " + identifier)
|
||||
print(
|
||||
f"INTEGRATION: PASS ({len(cases)} required gates; 49 pairs, "
|
||||
f"INTEGRATION: PASS ({len(cases)} required gates; {len(PAIRS)} pairs, "
|
||||
f"{len(CHAINS)} TUIC/ShadowTLS chains, retained UoT/TUIC chains, "
|
||||
"100 lifetimes, 100 rebuilds, 1800-second soak)"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,12 +2,21 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
PROTOCOLS = ("socks5", "anytls", "ss", "trojan", "vmess", "vless", "hysteria2")
|
||||
PROTOCOLS = ("socks5", "anytls", "ss", "trojan", "vmess", "vless", "hysteria2", "tuic")
|
||||
PAIRS = {
|
||||
f"INTEGRATION-PAIR-{first.upper()}-{last.upper()}": (first, last)
|
||||
for first in PROTOCOLS
|
||||
for last in PROTOCOLS
|
||||
}
|
||||
CHAINS = {
|
||||
f"INTEGRATION-CHAIN-TUIC-{mode.upper()}-SS-V3-{cipher.upper()}": {
|
||||
"udp_mode": mode,
|
||||
"cipher": "2022-blake3-" + cipher,
|
||||
}
|
||||
for mode in ("native", "quic")
|
||||
for cipher in ("aes-128-gcm", "aes-256-gcm", "chacha20-poly1305")
|
||||
}
|
||||
ORDERED = PAIRS | dict.fromkeys(CHAINS, ("tuic", "ss"))
|
||||
GATES = {
|
||||
"INTEGRATION-ENTRYPOINTS": "routing",
|
||||
"INTEGRATION-GRAPH": "routing",
|
||||
@@ -25,6 +34,7 @@ GATES = {
|
||||
"INTEGRATION-FEATURES": "regression",
|
||||
"INTEGRATION-SCRIPTS": "regression",
|
||||
"INTEGRATION-SHARED": "regression",
|
||||
"INTEGRATION-COUPLED": "routing",
|
||||
}
|
||||
LOCAL = {
|
||||
"INTEGRATION-DEBUG",
|
||||
@@ -37,8 +47,8 @@ LOCAL = {
|
||||
|
||||
def definitions():
|
||||
result = []
|
||||
for identifier in sorted(PAIRS.keys() | GATES.keys()):
|
||||
pair = PAIRS.get(identifier)
|
||||
for identifier in sorted(ORDERED.keys() | GATES.keys()):
|
||||
pair = ORDERED.get(identifier)
|
||||
local = identifier in LOCAL
|
||||
result.append(
|
||||
dict(
|
||||
@@ -48,10 +58,16 @@ def definitions():
|
||||
required=True,
|
||||
row_ids=["C06"] if pair else [],
|
||||
protocol="integration",
|
||||
network="seven-protocol-graph",
|
||||
network="eight-protocol-graph",
|
||||
security="per-frozen-consumer",
|
||||
udp_codec="per-protocol",
|
||||
field_values={"first": pair[0], "last": pair[1]} if pair else {},
|
||||
field_values={
|
||||
"first": pair[0],
|
||||
"last": pair[1],
|
||||
**CHAINS.get(identifier, {}),
|
||||
}
|
||||
if pair
|
||||
else {},
|
||||
outer_family="IPv4/IPv6",
|
||||
inner_family="IPv4/IPv6/domain",
|
||||
target_type="memory-only/build" if local else "isolated origin",
|
||||
|
||||
@@ -19,6 +19,7 @@ def envelope(report, peers, source, digest, *, single=None):
|
||||
"XR": "XTLS/Xray-core",
|
||||
"V2": "v2fly/v2ray-core",
|
||||
"SS": "shadowsocks/shadowsocks-rust",
|
||||
"ST": "ihciah/shadow-tls",
|
||||
"H": "HyNetworks/hysteria",
|
||||
}
|
||||
return bool(
|
||||
@@ -113,8 +114,10 @@ def runtime_pass(identifier, record, directory):
|
||||
"vmess",
|
||||
"vless",
|
||||
"hysteria2",
|
||||
"tuic",
|
||||
],
|
||||
source_and_oversize_isolated=protocols,
|
||||
tuic_transmit_budget=dict(limit=128, rejected=129, following_roundtrip=128),
|
||||
cancel_preserves_sibling=protocols,
|
||||
no_origin_bytes=True,
|
||||
stop_idle=True,
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
"""Rerun the retained UoT/TUIC chain consumers in one integration source scope."""
|
||||
|
||||
from .protocol_evidence import read_json
|
||||
from .protocol_integration_checks import envelope
|
||||
|
||||
GROUPS = ("MIHOMO-SOCKS5", "MIHOMO-GROUPS", "MIHOMO-PATHS")
|
||||
|
||||
|
||||
def run(directory, supplied, image):
|
||||
from .protocol_tuic import run as tuic
|
||||
from .protocol_uot import run as uot
|
||||
|
||||
for name in GROUPS:
|
||||
print("INTEGRATION coupled: " + name, flush=True)
|
||||
root = directory / name
|
||||
if name == "MIHOMO-PATHS":
|
||||
tuic(root, checks="paths", supplied=supplied, image=image)
|
||||
else:
|
||||
uot(
|
||||
root,
|
||||
checks="group" if name == "MIHOMO-GROUPS" else "data",
|
||||
via_socks5=True,
|
||||
supplied=supplied,
|
||||
image=image,
|
||||
)
|
||||
|
||||
|
||||
def passed(directory, peers, source, digest):
|
||||
from .protocol_tuic_acceptance import wire_pass as tuic
|
||||
from .protocol_uot_acceptance import wire_pass as uot
|
||||
|
||||
for name in GROUPS:
|
||||
root = directory / name
|
||||
report = read_json(root / "report.json")
|
||||
checker = tuic if name == "MIHOMO-PATHS" else uot
|
||||
if not (
|
||||
envelope(report, peers, source, digest, single="M")
|
||||
and checker(name, root, report)
|
||||
):
|
||||
return False
|
||||
return True
|
||||
@@ -16,7 +16,13 @@ def commands(identifier):
|
||||
}:
|
||||
return core_commands(identifier.removeprefix("INTEGRATION-").lower())
|
||||
if identifier == "INTEGRATION-QUALITY":
|
||||
return hysteria2_commands("HYSTERIA2-QUALITY") + [
|
||||
# Behavioral integration also runs with the approved local boring fork.
|
||||
# Strict release-source audit remains a separate mandatory PR/delivery gate.
|
||||
return [
|
||||
row
|
||||
for row in hysteria2_commands("HYSTERIA2-QUALITY")
|
||||
if row != ["vcore-scripts", "check", "tls-dependencies"]
|
||||
] + [
|
||||
["vcore-scripts", "check", "protocol-coverage", "--catalog-only"],
|
||||
["vcore-scripts", "build", "apple"],
|
||||
["vcore-scripts", "build", "android"],
|
||||
@@ -74,7 +80,7 @@ def passed(identifier, records, events, script=None):
|
||||
if identifier == "INTEGRATION-FEATURES":
|
||||
good &= assertions_pass(
|
||||
[e for e in events if e.get("suite") == "INTEGRATION-FEATURE"],
|
||||
{("INTEGRATION-FEATURE", p): 7 for p in PROTOCOLS},
|
||||
{("INTEGRATION-FEATURE", p): 8 for p in PROTOCOLS},
|
||||
)
|
||||
if identifier == "INTEGRATION-SCRIPTS":
|
||||
rows = (script or {}).get("cases", [])
|
||||
@@ -87,6 +93,7 @@ def passed(identifier, records, events, script=None):
|
||||
"test_list_contains_all_ordered_pairs_and_remaining_gates",
|
||||
"test_pressure_evidence_is_recomputed_not_inferred",
|
||||
"test_native_source_identity_and_cleanup_are_required",
|
||||
"test_integration_quality_separates_release_source_policy",
|
||||
)
|
||||
}
|
||||
good &= (
|
||||
|
||||
@@ -6,11 +6,18 @@ from math import isfinite
|
||||
from statistics import median
|
||||
|
||||
from .protocol_evidence import RESOURCE_KINDS, idle_resources
|
||||
from .protocol_integration_profiles import (
|
||||
LIFETIME_GROUPS,
|
||||
TCP_GROUPS,
|
||||
UDP_GROUPS,
|
||||
expected_flows,
|
||||
selected,
|
||||
)
|
||||
|
||||
NEW = ["trojan", "vmess", "vless", "hysteria2"]
|
||||
QUEUES = {
|
||||
"socks_udp": 16,
|
||||
"hysteria2_udp": 32,
|
||||
"hysteria2_udp": 0,
|
||||
"tuic_udp": 32,
|
||||
"quic_incoming": 32,
|
||||
"quic_outgoing": 32,
|
||||
}
|
||||
@@ -44,10 +51,12 @@ def sample(value, *, active=True):
|
||||
and integer(value.get("rss_kib"), 1)
|
||||
and integer(value.get("fd"), 1)
|
||||
and resources(value.get("resources", {}), active=active)
|
||||
and len(queues) == 4
|
||||
and len(queues) == len(QUEUES)
|
||||
and {q.get("kind"): q.get("capacity") for q in queues} == QUEUES
|
||||
and all(
|
||||
integer(q.get("peak"), 1) and q["peak"] <= q["capacity"] for q in queues
|
||||
integer(q.get("peak"), int(q["capacity"] > 0))
|
||||
and q["peak"] <= q["capacity"]
|
||||
for q in queues
|
||||
)
|
||||
)
|
||||
|
||||
@@ -61,10 +70,13 @@ def lifetimes(value, events):
|
||||
stop = row.get("after_stop", {})
|
||||
checkpoints = event.get("checkpoints", [])
|
||||
mode = index % 5
|
||||
group = LIFETIME_GROUPS[(index // 5) % len(LIFETIME_GROUPS)]
|
||||
retained = {0: 0, 1: 10, 2: 1, 3: 0, 4: 8}[mode]
|
||||
if not (
|
||||
row.get("cycle") == index
|
||||
and row.get("protocol") == NEW[(index // 5) % 4]
|
||||
and row.get("group") == group
|
||||
and row.get("profile")
|
||||
== selected(group, index // (5 * len(LIFETIME_GROUPS)))
|
||||
and row.get("mode") == mode
|
||||
and integer(row.get("baseline_fd"), 1)
|
||||
and row.get("retained_fixture_fd") == retained
|
||||
@@ -130,13 +142,15 @@ def rebuild(value, event):
|
||||
return (
|
||||
value.get("count") == 100
|
||||
and value.get("same_running_session") is True
|
||||
and value.get("protocols") == NEW
|
||||
and value.get("tcp_groups") == list(TCP_GROUPS)
|
||||
and value.get("udp_groups") == list(UDP_GROUPS)
|
||||
and len(rows) == 100
|
||||
and stopped(value, event)
|
||||
and all(
|
||||
row.get("generation") == i
|
||||
and row.get("tcp") == row.get("udp") == 20
|
||||
and row.get("per_protocol_tcp") == row.get("per_protocol_udp") == 5
|
||||
and row.get("per_group_tcp") == row.get("per_group_udp") == 5
|
||||
and row.get("flow_profiles") == expected_flows(i)
|
||||
and sample(row.get("active", {}))
|
||||
and sample(row.get("after_clients", {}), active=False)
|
||||
and setup(row.get("setup_us"))
|
||||
@@ -156,9 +170,12 @@ def soak(value, event, curve):
|
||||
if not (
|
||||
value.get("requested_seconds") == 1800
|
||||
and 1800 <= value.get("seconds", 0) < 1860
|
||||
and value.get("protocols") == NEW
|
||||
and value.get("tcp_groups") == list(TCP_GROUPS)
|
||||
and value.get("udp_groups") == list(UDP_GROUPS)
|
||||
and value.get("tcp") == value.get("udp") == 20
|
||||
and value.get("per_protocol_tcp") == value.get("per_protocol_udp") == 5
|
||||
and value.get("per_group_tcp") == value.get("per_group_udp") == 5
|
||||
and value.get("first_profiles") == expected_flows(0)
|
||||
and value.get("last_profiles") == expected_flows(len(faults))
|
||||
and integer(value.get("waves"), 1)
|
||||
and value.get("normal_verified_bytes") == value["waves"] * 20 * 2 * 2 * 257
|
||||
and all(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Seven-protocol integration with owned official peers and container origins."""
|
||||
"""Eight-protocol integration with owned official peers and container origins."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -18,7 +18,7 @@ from .native_release import download_native
|
||||
from .protocol_containers import ContainerLab, command, frozen_image
|
||||
from .protocol_fixtures import certificates
|
||||
from .protocol_inputs import redact, sha256, source_identity
|
||||
from .protocol_integration_catalog import PAIRS
|
||||
from .protocol_integration_catalog import CHAINS, ORDERED
|
||||
from .protocol_peers import run_command
|
||||
|
||||
|
||||
@@ -38,6 +38,16 @@ def peer_configuration(protocol, server, origin, directory, *, certificate=None)
|
||||
cipher = "2022-blake3-aes-128-gcm"
|
||||
listener.update(type="shadowsocks", udp=True, cipher=cipher, password=password)
|
||||
node.update(cipher=cipher, password=password)
|
||||
elif protocol == "tuic":
|
||||
listener.update(users={identity: password}, alpn=["h3"])
|
||||
node.update(
|
||||
uuid=identity,
|
||||
password=password,
|
||||
sni="localhost",
|
||||
fingerprint=pin,
|
||||
alpn=["h3"],
|
||||
**{"udp-relay-mode": "native"},
|
||||
)
|
||||
elif protocol in {"trojan", "anytls", "hysteria2"}:
|
||||
node.update(password=password, sni="localhost", fingerprint=pin)
|
||||
listener["users"] = (
|
||||
@@ -91,7 +101,7 @@ def run(
|
||||
if (
|
||||
not selected
|
||||
or len(selected) != len(set(selected))
|
||||
or not set(selected) <= PAIRS.keys()
|
||||
or not set(selected) <= ORDERED.keys()
|
||||
):
|
||||
raise ValueError("invalid INTEGRATION pair selection")
|
||||
output = output.resolve()
|
||||
@@ -120,7 +130,7 @@ def run(
|
||||
if sha256(binary) != identity["binary_sha256"]:
|
||||
raise RuntimeError("INTEGRATION native peer identity mismatch")
|
||||
report["peers"]["M"] = identity
|
||||
if any(PAIRS[key][1] == "trojan" for key in selected):
|
||||
if any(ORDERED[key][1] == "trojan" for key in selected):
|
||||
if domain_peer is None:
|
||||
artifact = download_native(
|
||||
"XR", output / "binary-xray", "linux-arm64", defer_version=True
|
||||
@@ -131,7 +141,8 @@ def run(
|
||||
report["peers"]["XR"] = domain_peer[1]
|
||||
lab = ContainerLab(report["isolation"], mtu=1500)
|
||||
for index, identifier in enumerate(selected):
|
||||
first_kind, last_kind = PAIRS[identifier]
|
||||
first_kind, last_kind = ORDERED[identifier]
|
||||
variant = CHAINS.get(identifier)
|
||||
print(f"INTEGRATION: {identifier}", flush=True)
|
||||
with tempfile.TemporaryDirectory(
|
||||
prefix="private-", dir=output
|
||||
@@ -144,20 +155,35 @@ def run(
|
||||
Path(__file__).with_name("container_udp_origin.py"),
|
||||
origin_dir / "origin.py",
|
||||
)
|
||||
origin_command = ["env", "VCORE_ISOLATED_ORIGIN=1"]
|
||||
cover_certificate = None
|
||||
if variant:
|
||||
cover_certificate = certificates(origin_dir)
|
||||
shutil.copyfile(
|
||||
Path(__file__).with_name("container_shadowtls_peer.py"),
|
||||
origin_dir / "cover.py",
|
||||
)
|
||||
origin_command += [
|
||||
"VCORE_ORIGIN_CERT=/data/fixture/cert.pem",
|
||||
"VCORE_ORIGIN_KEY=/data/fixture/key.pem",
|
||||
]
|
||||
origin_command += [
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/cover.py"
|
||||
if variant
|
||||
else "/data/fixture/origin.py",
|
||||
]
|
||||
origin = lab.start(
|
||||
stack,
|
||||
origin_dir,
|
||||
f"{index}-origin",
|
||||
[
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/origin.py",
|
||||
],
|
||||
origin_command,
|
||||
)
|
||||
origin.release()
|
||||
origin.wait_tcp(24000)
|
||||
if variant:
|
||||
origin.wait_tcp(24001)
|
||||
fixture = dict(
|
||||
isolation="containers",
|
||||
origin_control=f"{origin.ipv4}:24000",
|
||||
@@ -165,6 +191,8 @@ def run(
|
||||
origin_ipv6=origin.ipv6,
|
||||
data_dir=str(root / "core"),
|
||||
)
|
||||
if variant:
|
||||
fixture["variant"] = variant
|
||||
for role, protocol in (("first", first_kind), ("last", last_kind)):
|
||||
directory = root / role
|
||||
directory.mkdir()
|
||||
@@ -196,6 +224,25 @@ def run(
|
||||
node, config = peer_configuration(
|
||||
protocol, peer.ipv4, origin.ipv4, directory
|
||||
)
|
||||
if variant and role == "first":
|
||||
node["udp-relay-mode"] = variant["udp_mode"]
|
||||
elif variant:
|
||||
from .protocol_completion_peers import PeerCase
|
||||
from .protocol_completion_peers import (
|
||||
peer_configuration as profile,
|
||||
)
|
||||
|
||||
node, listener = profile(
|
||||
PeerCase(
|
||||
identifier, "ss", variant["cipher"], shadow_tls=True
|
||||
),
|
||||
server=peer.ipv4,
|
||||
cover=f"{origin.ipv4}:24001",
|
||||
port=23000,
|
||||
certificate=cover_certificate,
|
||||
)
|
||||
node["name"] = "peer"
|
||||
config["listeners"] = [listener]
|
||||
(directory / "config.json").write_text(json.dumps(config))
|
||||
fixture[role], fixture[role + "_ipv6"] = node, peer.ipv6
|
||||
peer.release()
|
||||
@@ -302,4 +349,4 @@ def run(
|
||||
if __name__ == "__main__":
|
||||
output = Path(sys.argv[1]).resolve()
|
||||
with exclusive_run(), frozen_image(None):
|
||||
run(output, sys.argv[2:] or list(PAIRS))
|
||||
run(output, sys.argv[2:] or list(ORDERED))
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
"""Mixed-load profiles built from the implemented protocol peer fixtures."""
|
||||
|
||||
from .protocol_completion_peers import CASES, peer_configuration
|
||||
|
||||
TCP_GROUPS = ("socks5", "ss-v3", "tuic", "httpupgrade")
|
||||
UDP_GROUPS = ("ss-uot", "ss-uot-v3", "tuic", "httpupgrade")
|
||||
LIFETIME_GROUPS = (
|
||||
"socks5",
|
||||
"anytls",
|
||||
"ss",
|
||||
"trojan",
|
||||
"vmess",
|
||||
"vless",
|
||||
"hysteria2",
|
||||
"tuic",
|
||||
"ss-v3",
|
||||
"ss-uot",
|
||||
"ss-uot-v3",
|
||||
"httpupgrade",
|
||||
)
|
||||
|
||||
|
||||
def group(case):
|
||||
if case.protocol == "ss":
|
||||
return (
|
||||
"ss-uot-v3"
|
||||
if case.uot and case.shadow_tls
|
||||
else "ss-uot"
|
||||
if case.uot
|
||||
else "ss-v3"
|
||||
)
|
||||
return "tuic" if case.protocol == "tuic" else "httpupgrade"
|
||||
|
||||
|
||||
PROFILE_IDS = {
|
||||
name: [c.identifier for c in CASES if c.protocol != "socks5" and group(c) == name]
|
||||
for name in ("ss-v3", "ss-uot", "ss-uot-v3", "tuic", "httpupgrade")
|
||||
}
|
||||
|
||||
|
||||
def configuration(server, cover, certificate):
|
||||
nodes, listeners = {}, []
|
||||
for i, case in enumerate(c for c in CASES if c.protocol != "socks5"):
|
||||
node, listener = peer_configuration(
|
||||
case, server=server, cover=cover, port=23100 + i, certificate=certificate
|
||||
)
|
||||
node["name"] = "peer"
|
||||
nodes[case.identifier] = node
|
||||
listeners.append(listener)
|
||||
return nodes, listeners
|
||||
|
||||
|
||||
def selected(group_name, generation, slot=0):
|
||||
options = PROFILE_IDS.get(group_name, [group_name])
|
||||
return options[(generation + slot) % len(options)]
|
||||
|
||||
|
||||
def expected_flows(generation):
|
||||
return {
|
||||
kind: [
|
||||
selected(group_name, generation, slot)
|
||||
for group_name in groups
|
||||
for slot in range(5)
|
||||
]
|
||||
for kind, groups in (("tcp", TCP_GROUPS), ("udp", UDP_GROUPS))
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
"""INTEGRATION public-runtime gates against seven listeners in an owned native peer."""
|
||||
"""INTEGRATION public-runtime and mixed-profile gates in owned native peers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -21,6 +21,8 @@ from .protocol_fixtures import certificates
|
||||
from .protocol_inputs import redact, sha256, source_identity
|
||||
from .protocol_integration_catalog import PROTOCOLS
|
||||
from .protocol_integration_native import peer_configuration, rust_command
|
||||
from .protocol_integration_profiles import PROFILE_IDS
|
||||
from .protocol_integration_profiles import configuration as profiles
|
||||
from .protocol_peers import run_command
|
||||
|
||||
CONSUMERS = {
|
||||
@@ -79,10 +81,15 @@ def run(output: Path, selected, *, supplied=None):
|
||||
with contextlib.ExitStack() as stack:
|
||||
origin_dir = root / "origin"
|
||||
origin_dir.mkdir()
|
||||
certificate = certificates(origin_dir)
|
||||
shutil.copyfile(
|
||||
Path(__file__).with_name("container_udp_origin.py"),
|
||||
origin_dir / "origin.py",
|
||||
)
|
||||
shutil.copyfile(
|
||||
Path(__file__).with_name("container_shadowtls_peer.py"),
|
||||
origin_dir / "cover.py",
|
||||
)
|
||||
origin = lab.start(
|
||||
stack,
|
||||
origin_dir,
|
||||
@@ -91,13 +98,16 @@ def run(output: Path, selected, *, supplied=None):
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"VCORE_ORIGIN_PROFILE=INTEGRATION",
|
||||
"VCORE_ORIGIN_CERT=/data/fixture/cert.pem",
|
||||
"VCORE_ORIGIN_KEY=/data/fixture/key.pem",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/origin.py",
|
||||
"/data/fixture/cover.py",
|
||||
],
|
||||
)
|
||||
origin.release()
|
||||
origin.wait_tcp(24000)
|
||||
origin.wait_tcp(24001)
|
||||
upstream_dir = root / "upstream"
|
||||
upstream_dir.mkdir()
|
||||
shutil.copy2(binary, upstream_dir / "peer")
|
||||
@@ -156,7 +166,8 @@ def run(output: Path, selected, *, supplied=None):
|
||||
raise RuntimeError(
|
||||
"INTEGRATION container binary differs from download"
|
||||
)
|
||||
certificate = certificates(directory)
|
||||
for path in certificate[:2]:
|
||||
shutil.copy2(path, directory / path.name)
|
||||
nodes, listeners = {}, []
|
||||
config = None
|
||||
for index, protocol in enumerate(PROTOCOLS):
|
||||
@@ -195,6 +206,11 @@ def run(output: Path, selected, *, supplied=None):
|
||||
)
|
||||
)
|
||||
ss_nodes.append(node)
|
||||
extra_nodes, extra_listeners = profiles(
|
||||
peer.ipv4, f"{origin.ipv4}:24001", certificate
|
||||
)
|
||||
nodes.update(extra_nodes)
|
||||
listeners.extend(extra_listeners)
|
||||
config.update(
|
||||
listeners=listeners,
|
||||
**{
|
||||
@@ -211,6 +227,16 @@ def run(output: Path, selected, *, supplied=None):
|
||||
origin_ipv4=origin.ipv4,
|
||||
origin_ipv6=origin.ipv6,
|
||||
nodes=nodes,
|
||||
profile_groups={
|
||||
name: PROFILE_IDS.get(name, [name])
|
||||
for name in (
|
||||
*PROTOCOLS,
|
||||
"ss-v3",
|
||||
"ss-uot",
|
||||
"ss-uot-v3",
|
||||
"httpupgrade",
|
||||
)
|
||||
},
|
||||
ss_nodes=ss_nodes,
|
||||
hop=hop,
|
||||
server_ipv6=peer.ipv6,
|
||||
|
||||
@@ -0,0 +1,568 @@
|
||||
"""SS2022 ShadowTLS v3 through public consumers and isolated official peers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from .builds import CORE_DIR
|
||||
from .mihomo_isolation import exclusive_run
|
||||
from .mihomo_release import download_mihomo
|
||||
from .protocol_completion_peers import CASES, peer_configuration
|
||||
from .protocol_containers import ContainerLab, command, frozen_image
|
||||
from .protocol_fixtures import certificates
|
||||
from .protocol_inputs import redact, same_source, source_identity
|
||||
from .protocol_peers import run_command
|
||||
|
||||
PROFILES = ("none", "chrome120", "chrome", "firefox", "safari")
|
||||
POLICIES = (
|
||||
"alpn-default",
|
||||
"alpn-empty",
|
||||
"alpn-custom",
|
||||
"hrr",
|
||||
"wrong-password",
|
||||
"wrong-pin",
|
||||
"wrong-pin-with-skip",
|
||||
"untrusted",
|
||||
"tls12",
|
||||
)
|
||||
|
||||
|
||||
def policy_inputs(node, listener):
|
||||
for index, policy in enumerate(POLICIES):
|
||||
client, peer = copy.deepcopy(node), copy.deepcopy(listener)
|
||||
client["port"] = peer["port"] = 23500 + index
|
||||
peer["name"] += "-" + policy
|
||||
port, alpn = 24001, "h2"
|
||||
if policy == "alpn-empty":
|
||||
client["plugin-opts"]["alpn"] = []
|
||||
alpn = None
|
||||
elif policy == "alpn-custom":
|
||||
client["plugin-opts"]["alpn"] = ["fixture-custom"]
|
||||
alpn = "fixture-custom"
|
||||
elif policy == "hrr":
|
||||
port = 24002
|
||||
elif policy == "wrong-password":
|
||||
client["plugin-opts"]["password"] = "wrong-synthetic-password"
|
||||
elif policy.startswith("wrong-pin"):
|
||||
client["plugin-opts"]["fingerprint"] = "07" * 32
|
||||
client["plugin-opts"]["skip-cert-verify"] = policy.endswith("skip")
|
||||
elif policy == "untrusted":
|
||||
del client["plugin-opts"]["fingerprint"]
|
||||
elif policy == "tls12":
|
||||
port = 24003
|
||||
host = peer["shadow-tls"]["handshake"]["dest"].rsplit(":", 1)[0]
|
||||
peer["shadow-tls"]["handshake"]["dest"] = f"{host}:{port}"
|
||||
yield (
|
||||
policy,
|
||||
client,
|
||||
peer,
|
||||
policy.startswith("alpn-") or policy == "hrr",
|
||||
port,
|
||||
alpn,
|
||||
)
|
||||
|
||||
|
||||
def run(
|
||||
output: Path,
|
||||
*,
|
||||
profiles=("none",),
|
||||
selected=None,
|
||||
checks="data",
|
||||
supplied=None,
|
||||
image=None,
|
||||
):
|
||||
output = output.resolve()
|
||||
if not output.is_relative_to((CORE_DIR / "target/interop/runs").resolve()):
|
||||
raise ValueError("ShadowTLS evidence must stay inside target/interop/runs")
|
||||
cases = tuple(c for c in CASES if c.shadow_tls and not c.uot)
|
||||
if (
|
||||
checks not in {"data", "policy", "fault"}
|
||||
or not profiles
|
||||
or len(set(profiles)) != len(profiles)
|
||||
or not set(profiles) <= set(PROFILES)
|
||||
):
|
||||
raise ValueError("invalid ShadowTLS checks or profiles")
|
||||
if selected is not None:
|
||||
if len(set(selected)) != len(selected) or not set(selected) <= {
|
||||
c.identifier for c in cases
|
||||
}:
|
||||
raise ValueError("unknown or duplicate ShadowTLS case")
|
||||
cases = tuple(c for c in cases if c.identifier in selected)
|
||||
if checks != "data":
|
||||
cases = cases[:1]
|
||||
if not cases:
|
||||
raise ValueError("empty ShadowTLS selection")
|
||||
report = dict(
|
||||
source=source_identity(), status="NOT RUN", peer={}, isolation={}, cases=[]
|
||||
)
|
||||
output.mkdir(parents=True, exist_ok=False)
|
||||
try:
|
||||
with (
|
||||
exclusive_run() if supplied is None else contextlib.nullcontext(),
|
||||
(
|
||||
frozen_image(output / "image-pull.log")
|
||||
if image is None
|
||||
else contextlib.nullcontext(image)
|
||||
) as image,
|
||||
):
|
||||
report["container_image"] = image
|
||||
if supplied is None:
|
||||
binary = download_mihomo(
|
||||
"linux-arm64", directory=output / "binary", identity=report["peer"]
|
||||
)
|
||||
else:
|
||||
binary, report["peer"] = supplied
|
||||
built = run_command(
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--all-features",
|
||||
"--test",
|
||||
"vless_public",
|
||||
"--no-run",
|
||||
],
|
||||
cwd=CORE_DIR,
|
||||
timeout=180,
|
||||
)
|
||||
(output / "build.log").write_text(
|
||||
redact(built.stdout.decode(errors="replace"))
|
||||
)
|
||||
if built.returncode or not built.cleanup:
|
||||
raise RuntimeError("ShadowTLS consumer build failed")
|
||||
lab = ContainerLab(report["isolation"], mtu=1500)
|
||||
with tempfile.TemporaryDirectory(prefix="private-", dir=output) as temp:
|
||||
root = Path(temp)
|
||||
directories = {}
|
||||
try:
|
||||
with contextlib.ExitStack() as stack:
|
||||
for role in ("origin", "server"):
|
||||
directory = root / role
|
||||
directory.mkdir()
|
||||
directories[role] = directory
|
||||
cert = certificates(directories["server"])
|
||||
for source, name in zip(
|
||||
cert[:2], ("cert.pem", "key.pem"), strict=True
|
||||
):
|
||||
shutil.copy2(source, directories["origin"] / name)
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_udp_origin.py"),
|
||||
directories["origin"] / "origin.py",
|
||||
)
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_shadowtls_peer.py"),
|
||||
directories["origin"] / "peer.py",
|
||||
)
|
||||
origin = lab.start(
|
||||
stack,
|
||||
directories["origin"],
|
||||
"origin",
|
||||
[
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"VCORE_ORIGIN_CERT=/data/fixture/cert.pem",
|
||||
"VCORE_ORIGIN_KEY=/data/fixture/key.pem",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/peer.py",
|
||||
],
|
||||
)
|
||||
shutil.copy2(binary, directories["server"] / "mihomo")
|
||||
server = lab.start(
|
||||
stack,
|
||||
directories["server"],
|
||||
"server",
|
||||
[
|
||||
"/data/fixture/mihomo",
|
||||
"-d",
|
||||
"/data",
|
||||
"-f",
|
||||
"/data/fixture/config.json",
|
||||
],
|
||||
)
|
||||
report["peer"]["version"] = command(
|
||||
"exec", server.name, "/data/fixture/mihomo", "-v"
|
||||
).strip()
|
||||
if (
|
||||
command(
|
||||
"exec", server.name, "sha256sum", "/data/fixture/mihomo"
|
||||
).split()[0]
|
||||
!= report["peer"]["binary_sha256"]
|
||||
):
|
||||
raise RuntimeError("ShadowTLS peer identity mismatch")
|
||||
nodes, listeners = [], []
|
||||
for index, case in enumerate(cases):
|
||||
node, listener = peer_configuration(
|
||||
case,
|
||||
server=server.ipv4,
|
||||
cover=f"{origin.ipv4}:24001",
|
||||
port=23000 + index,
|
||||
certificate=cert,
|
||||
)
|
||||
node["name"] = "peer"
|
||||
if checks == "data":
|
||||
nodes.append((case.identifier, node, True, 24001, "h2"))
|
||||
listeners.append(listener)
|
||||
elif checks == "policy":
|
||||
for (
|
||||
label,
|
||||
client,
|
||||
peer,
|
||||
success,
|
||||
port,
|
||||
alpn,
|
||||
) in policy_inputs(node, listener):
|
||||
nodes.append((label, client, success, port, alpn))
|
||||
listeners.append(peer)
|
||||
else:
|
||||
listeners.append(listener)
|
||||
hrr = copy.deepcopy(listener)
|
||||
hrr["name"] += "-hrr"
|
||||
hrr["port"] = 23001
|
||||
hrr["shadow-tls"]["handshake"]["dest"] = (
|
||||
f"{origin.ipv4}:24002"
|
||||
)
|
||||
listeners.append(hrr)
|
||||
directory = root / "fault"
|
||||
directory.mkdir()
|
||||
directories["fault"] = directory
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name(
|
||||
"container_shadowtls_fault.py"
|
||||
),
|
||||
directory / "fault.py",
|
||||
)
|
||||
fault = lab.start(
|
||||
stack,
|
||||
directory,
|
||||
"fault",
|
||||
[
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/fault.py",
|
||||
],
|
||||
)
|
||||
routes = []
|
||||
for index, label in enumerate(
|
||||
(
|
||||
"fragment",
|
||||
"hrr-wire",
|
||||
"cover-mac",
|
||||
"business-mac",
|
||||
"business-truncated",
|
||||
"stall",
|
||||
"native-udp-disabled",
|
||||
)
|
||||
):
|
||||
port = 23600 + index
|
||||
routes.append(
|
||||
dict(
|
||||
port=port,
|
||||
mode="fragment"
|
||||
if label == "hrr-wire"
|
||||
else label,
|
||||
server=server.ipv4,
|
||||
server_port=23001
|
||||
if label == "hrr-wire"
|
||||
else 23000,
|
||||
)
|
||||
)
|
||||
client = copy.deepcopy(node)
|
||||
client.update(server=fault.ipv4, port=port)
|
||||
nodes.append(
|
||||
(
|
||||
label,
|
||||
client,
|
||||
label not in {"cover-mac", "stall"},
|
||||
24002 if label == "hrr-wire" else 24001,
|
||||
"h2",
|
||||
)
|
||||
)
|
||||
(directory / "config.json").write_text(
|
||||
json.dumps(routes)
|
||||
)
|
||||
(directories["server"] / "config.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"socks-port": 23999,
|
||||
"allow-lan": True,
|
||||
"bind-address": "*",
|
||||
"ipv6": True,
|
||||
"log-level": "warning",
|
||||
"listeners": listeners,
|
||||
"rules": ["MATCH,DIRECT"],
|
||||
}
|
||||
)
|
||||
)
|
||||
origin.release()
|
||||
server.release()
|
||||
origin.wait_tcp(24000)
|
||||
origin.wait_tcp(24001)
|
||||
origin.wait_tcp(24002)
|
||||
origin.wait_tcp(24003)
|
||||
server.wait_tcp(23999)
|
||||
if checks == "fault":
|
||||
fault.release()
|
||||
fault.wait_tcp(23998)
|
||||
for route in routes:
|
||||
fault.wait_tcp(route["port"])
|
||||
for label, node, success, cover_port, alpn in nodes:
|
||||
for profile in profiles:
|
||||
identifier = f"{label}-{profile}"
|
||||
before = len(
|
||||
command(
|
||||
"exec",
|
||||
origin.name,
|
||||
"cat",
|
||||
"/data/cover-events.jsonl",
|
||||
).splitlines()
|
||||
)
|
||||
fault_before = (
|
||||
len(
|
||||
command(
|
||||
"exec",
|
||||
fault.name,
|
||||
"cat",
|
||||
"/data/fault-events.jsonl",
|
||||
).splitlines()
|
||||
)
|
||||
if checks == "fault"
|
||||
else 0
|
||||
)
|
||||
consumer = (
|
||||
checks
|
||||
if checks != "fault"
|
||||
else {
|
||||
"fragment": "native_tcp",
|
||||
"hrr-wire": "native_tcp",
|
||||
"cover-mac": "policy",
|
||||
"stall": "stall",
|
||||
"native-udp-disabled": "native_udp_disabled",
|
||||
}.get(label, "corrupt")
|
||||
)
|
||||
node["client-fingerprint"] = profile
|
||||
fixture = root / "fixture.json"
|
||||
fixture.write_text(
|
||||
json.dumps(
|
||||
dict(
|
||||
isolation="containers",
|
||||
node=node,
|
||||
origin_ipv4=origin.ipv4,
|
||||
origin_ipv6=origin.ipv6,
|
||||
origin_control=f"{origin.ipv4}:24000",
|
||||
data_dir=str(root / "data"),
|
||||
expected_success=success,
|
||||
fault_control=f"{fault.ipv4}:23998"
|
||||
if checks == "fault"
|
||||
else None,
|
||||
)
|
||||
)
|
||||
)
|
||||
observations = (
|
||||
output / f"{identifier}-observations.json"
|
||||
)
|
||||
argv = [
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--all-features",
|
||||
"--test",
|
||||
"vless_public",
|
||||
f"shadowtls::{consumer}",
|
||||
"--",
|
||||
"--ignored",
|
||||
"--exact",
|
||||
"--nocapture",
|
||||
]
|
||||
result = run_command(
|
||||
argv,
|
||||
cwd=CORE_DIR,
|
||||
timeout=240,
|
||||
env=dict(
|
||||
os.environ,
|
||||
VCORE_VLESS_INPUT=str(fixture),
|
||||
VCORE_SHADOWTLS_OBSERVATIONS=str(observations),
|
||||
VCORE_CASE_EVENTS=str(
|
||||
output / f"{identifier}-events.jsonl"
|
||||
),
|
||||
),
|
||||
)
|
||||
(output / f"{identifier}.log").write_text(
|
||||
redact(result.stdout.decode(errors="replace"))
|
||||
)
|
||||
observed = (
|
||||
json.loads(observations.read_text())
|
||||
if observations.is_file()
|
||||
else None
|
||||
)
|
||||
expected = (
|
||||
dict(
|
||||
tcp_bytes_each_direction=10 * 1024 * 1024,
|
||||
udp_packets=500 if consumer == "data" else 0,
|
||||
udp_sizes=[1, 64, 512, 1200, 4096]
|
||||
if consumer == "data"
|
||||
else [],
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer in {"data", "native_tcp"}
|
||||
else dict(
|
||||
origin_connected=True,
|
||||
delivered_bytes=0,
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer == "corrupt"
|
||||
else dict(
|
||||
stop_idle=True,
|
||||
stop_handshake_cancelled=True,
|
||||
measure_deadline=True,
|
||||
origin_connected=False,
|
||||
closed_handshakes=2,
|
||||
)
|
||||
if consumer == "stall"
|
||||
else dict(
|
||||
tcp_accepted=True,
|
||||
udp_delivered=False,
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer == "native_udp_disabled"
|
||||
else dict(
|
||||
accepted=success,
|
||||
origin_connected=success,
|
||||
stop_idle=True,
|
||||
)
|
||||
)
|
||||
cover = [
|
||||
json.loads(line)
|
||||
for line in command(
|
||||
"exec",
|
||||
origin.name,
|
||||
"cat",
|
||||
"/data/cover-events.jsonl",
|
||||
).splitlines()[before:]
|
||||
]
|
||||
cover_pass = (
|
||||
not success
|
||||
or dict(
|
||||
port=cover_port, version="TLSv1.3", alpn=alpn
|
||||
)
|
||||
in cover
|
||||
)
|
||||
fault_events = (
|
||||
[
|
||||
json.loads(line)
|
||||
for line in command(
|
||||
"exec",
|
||||
fault.name,
|
||||
"cat",
|
||||
"/data/fault-events.jsonl",
|
||||
).splitlines()[fault_before:]
|
||||
]
|
||||
if checks == "fault"
|
||||
else []
|
||||
)
|
||||
fault_pass = True
|
||||
if checks == "fault":
|
||||
required = (
|
||||
"split_record"
|
||||
if label == "fragment"
|
||||
else "hrr_seen"
|
||||
if label == "hrr-wire"
|
||||
else "injected"
|
||||
)
|
||||
fault_pass = any(
|
||||
event.get(required) is True
|
||||
for event in fault_events
|
||||
) and not any(
|
||||
event.get("upload_join_failed")
|
||||
for event in fault_events
|
||||
)
|
||||
if label == "stall":
|
||||
fault_pass = not cover and all(
|
||||
sum(
|
||||
event.get(key) is True
|
||||
for event in fault_events
|
||||
)
|
||||
== 2
|
||||
for key in ("hello_seen", "client_closed")
|
||||
)
|
||||
elif label == "native-udp-disabled":
|
||||
fault_pass = not any(
|
||||
event.get("upload_join_failed")
|
||||
for event in fault_events
|
||||
)
|
||||
passed = (
|
||||
result.returncode == 0
|
||||
and result.cleanup
|
||||
and observed == expected
|
||||
and cover_pass
|
||||
and fault_pass
|
||||
)
|
||||
report["cases"].append(
|
||||
dict(
|
||||
case_id=identifier,
|
||||
status="PASS" if passed else "FAIL",
|
||||
command=argv,
|
||||
exit_code=result.returncode,
|
||||
command_cleanup=result.cleanup,
|
||||
observations=observed,
|
||||
cover=cover,
|
||||
fault=fault_events,
|
||||
)
|
||||
)
|
||||
print(
|
||||
f"{identifier}: {'PASS' if passed else 'FAIL'}",
|
||||
flush=True,
|
||||
)
|
||||
if not passed:
|
||||
raise RuntimeError(
|
||||
"ShadowTLS public data validation failed"
|
||||
)
|
||||
finally:
|
||||
for role, directory in directories.items():
|
||||
if (directory / "peer.log").is_file():
|
||||
(output / f"{role}.log").write_text(
|
||||
redact(
|
||||
(directory / "peer.log").read_text(errors="replace")
|
||||
)
|
||||
)
|
||||
report["status"] = "PASS"
|
||||
except BaseException as error:
|
||||
report["status"] = "FAIL"
|
||||
(output / "failure.log").write_text(redact(str(error)))
|
||||
raise
|
||||
finally:
|
||||
report["cleanup"] = all(
|
||||
p.get("joined") is True for p in report["isolation"].get("peers", [])
|
||||
)
|
||||
report["source_unchanged"] = same_source(report["source"], source_identity())
|
||||
if not report["cleanup"] or not report["source_unchanged"]:
|
||||
report["status"] = "FAIL"
|
||||
(output / "report.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
if report["status"] != "PASS":
|
||||
raise RuntimeError("ShadowTLS source or cleanup validation failed")
|
||||
return report
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("--profile", action="append")
|
||||
parser.add_argument("--case", action="append")
|
||||
parser.add_argument("--checks", choices=("data", "policy", "fault"), default="data")
|
||||
args = parser.parse_args()
|
||||
run(
|
||||
args.output,
|
||||
profiles=args.profile or ["none"],
|
||||
selected=args.case,
|
||||
checks=args.checks,
|
||||
)
|
||||
@@ -0,0 +1,376 @@
|
||||
"""ShadowTLS execution and reconstruction from raw, source-bound evidence."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from .core_checks import validate_execution
|
||||
from .protocol_evidence import read_events, read_json
|
||||
from .protocol_hysteria2_catalog import assertions_pass
|
||||
from .protocol_inputs import redact
|
||||
from .protocol_integration_checks import envelope, runtime_pass
|
||||
from .protocol_security_acceptance import REPORTS, result, rust_command, vless_pass
|
||||
from .protocol_shadowtls import POLICIES, PROFILES
|
||||
from .protocol_shadowtls_catalog import (
|
||||
FAULTS,
|
||||
LOCAL,
|
||||
MEMORY_EVENTS,
|
||||
SHARED,
|
||||
SS_CASES,
|
||||
commands,
|
||||
)
|
||||
|
||||
|
||||
def expected_observation(consumer, success):
|
||||
if consumer in {"data", "native_tcp"}:
|
||||
return dict(
|
||||
tcp_bytes_each_direction=10 * 1024 * 1024,
|
||||
udp_packets=500 if consumer == "data" else 0,
|
||||
udp_sizes=[1, 64, 512, 1200, 4096] if consumer == "data" else [],
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer == "policy":
|
||||
return dict(accepted=success, origin_connected=success, stop_idle=True)
|
||||
if consumer == "corrupt":
|
||||
return dict(origin_connected=True, delivered_bytes=0, stop_idle=True)
|
||||
if consumer == "stall":
|
||||
return dict(
|
||||
stop_idle=True,
|
||||
stop_handshake_cancelled=True,
|
||||
measure_deadline=True,
|
||||
origin_connected=False,
|
||||
closed_handshakes=2,
|
||||
)
|
||||
if consumer == "native_udp_disabled":
|
||||
return dict(tcp_accepted=True, udp_delivered=False, stop_idle=True)
|
||||
raise ValueError("unknown ShadowTLS consumer")
|
||||
|
||||
|
||||
def fault_pass(label, events, cover):
|
||||
if any(e.get("upload_join_failed") for e in events):
|
||||
return False
|
||||
if label == "stall":
|
||||
return not cover and all(
|
||||
sum(e.get(key) is True for e in events) == 2
|
||||
for key in ("hello_seen", "client_closed")
|
||||
)
|
||||
if label == "native-udp-disabled":
|
||||
return True
|
||||
required = (
|
||||
"split_record"
|
||||
if label == "fragment"
|
||||
else "hrr_seen"
|
||||
if label == "hrr-wire"
|
||||
else "injected"
|
||||
)
|
||||
return any(e.get(required) is True for e in events)
|
||||
|
||||
|
||||
def wire_pass(name, directory, report):
|
||||
if name == "MIHOMO-DATA":
|
||||
labels = [
|
||||
(f"{c}-{p}", "data", True, 24001, "h2", None)
|
||||
for c in SS_CASES
|
||||
for p in PROFILES
|
||||
]
|
||||
elif name == "MIHOMO-POLICY":
|
||||
labels = [
|
||||
(
|
||||
f"{p}-chrome",
|
||||
"policy",
|
||||
p.startswith("alpn-") or p == "hrr",
|
||||
24002 if p == "hrr" else 24003 if p == "tls12" else 24001,
|
||||
None
|
||||
if p == "alpn-empty"
|
||||
else "fixture-custom"
|
||||
if p == "alpn-custom"
|
||||
else "h2",
|
||||
None,
|
||||
)
|
||||
for p in POLICIES
|
||||
]
|
||||
elif name == "MIHOMO-FAULT":
|
||||
consumers = {
|
||||
"fragment": "native_tcp",
|
||||
"hrr-wire": "native_tcp",
|
||||
"cover-mac": "policy",
|
||||
"stall": "stall",
|
||||
"native-udp-disabled": "native_udp_disabled",
|
||||
}
|
||||
labels = [
|
||||
(
|
||||
f"{f}-chrome",
|
||||
consumers.get(f, "corrupt"),
|
||||
f not in {"cover-mac", "stall"},
|
||||
24002 if f == "hrr-wire" else 24001,
|
||||
"h2",
|
||||
f,
|
||||
)
|
||||
for f in FAULTS
|
||||
]
|
||||
elif name == "NATIVE":
|
||||
labels = [(c, "native_tcp", True, None, None, None) for c in SS_CASES]
|
||||
else:
|
||||
raise ValueError("unknown wire group")
|
||||
rows = report.get("cases", [])
|
||||
if [r.get("case_id") for r in rows] != [item[0] for item in labels]:
|
||||
return False
|
||||
for row, (identifier, consumer, success, port, alpn, fault) in zip(
|
||||
rows, labels, strict=True
|
||||
):
|
||||
observed = read_json(directory / (identifier + "-observations.json"))
|
||||
events = read_events(directory / (identifier + "-events.jsonl"))
|
||||
if not (
|
||||
row.get("command") == rust_command("vless_public", "shadowtls::" + consumer)
|
||||
and type(row.get("exit_code")) is int
|
||||
and row["exit_code"] == 0
|
||||
and row.get("command_cleanup") is True
|
||||
and observed
|
||||
== row.get("observations")
|
||||
== expected_observation(consumer, success)
|
||||
and assertions_pass(events, {("SHADOWTLS", consumer): 1})
|
||||
):
|
||||
return False
|
||||
cover = row.get("cover", [])
|
||||
if (
|
||||
port is not None
|
||||
and success
|
||||
and dict(port=port, version="TLSv1.3", alpn=alpn) not in cover
|
||||
):
|
||||
return False
|
||||
if fault is not None and not fault_pass(fault, row.get("fault", []), cover):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def local_pass(name, directory, run):
|
||||
expected = commands(name)
|
||||
records = [
|
||||
r for r in run["commands"] if r["name"].startswith("SHADOWTLS-" + name + "-")
|
||||
]
|
||||
if len(records) != len(expected):
|
||||
return False
|
||||
events = []
|
||||
for i, (row, argv) in enumerate(zip(records, expected, strict=True)):
|
||||
label = f"SHADOWTLS-{name}-{i}"
|
||||
if row["name"] != label or row["command"] != [
|
||||
redact(v.replace("{output}", str(directory))) for v in argv
|
||||
]:
|
||||
return False
|
||||
validate_execution(
|
||||
row["command"],
|
||||
(directory / row["log"]).read_text(),
|
||||
row["exit_code"],
|
||||
row["cleanup"],
|
||||
)
|
||||
path = directory / (label + "-events.jsonl")
|
||||
if path.exists():
|
||||
events += read_events(path)
|
||||
if name == "MEMORY":
|
||||
return assertions_pass(
|
||||
[e for e in events if e.get("suite", "").startswith("SHADOWTLS-")],
|
||||
MEMORY_EVENTS,
|
||||
)
|
||||
if name == "FEATURES":
|
||||
return assertions_pass(
|
||||
[e for e in events if e.get("suite") == "SHADOWTLS-CFG"],
|
||||
{("SHADOWTLS-CFG", "feature"): 1},
|
||||
)
|
||||
if name == "FINGERPRINT":
|
||||
from .protocol_fingerprint_shape import check_captures, check_warm_captures
|
||||
|
||||
root = directory / "fingerprint"
|
||||
report = read_json(root / "shape-results.json")
|
||||
return (
|
||||
report.get("source") == source(run)
|
||||
and report.get("source_unchanged") is True
|
||||
and report.get("cleanup") is True
|
||||
and report.get("cases") == check_captures(read_json(root / "captures.json"))
|
||||
and report.get("warm_cases")
|
||||
== check_warm_captures(read_json(root / "warm.json"))
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def source(run):
|
||||
return {
|
||||
k: run[k]
|
||||
for k in (
|
||||
"parent_commit",
|
||||
"source_tree_sha256",
|
||||
"dirty_patch_sha256",
|
||||
"lock_sha256",
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
def group_pass(name, directory, run, peers):
|
||||
if name in LOCAL:
|
||||
return local_pass(name, directory, run)
|
||||
root = directory / name.lower()
|
||||
digest = run["container_image"]["digest"]
|
||||
if name == "SHARED":
|
||||
return all(
|
||||
envelope(
|
||||
report := read_json(root / label / REPORTS["vless"]),
|
||||
peers,
|
||||
source(run),
|
||||
digest,
|
||||
)
|
||||
and vless_pass(group, report, root / label)
|
||||
for label, group in SHARED.items()
|
||||
)
|
||||
if name == "BARE-SS":
|
||||
report = read_json(root / "integration-suite.json")
|
||||
rows = report.get("cases", [])
|
||||
return (
|
||||
envelope(report, peers, source(run), digest)
|
||||
and len(rows) == 1
|
||||
and runtime_pass("INTEGRATION-SS-ALGORITHMS", rows[0], root)
|
||||
)
|
||||
report = read_json(root / "report.json")
|
||||
identities = report.get("peers") if name == "NATIVE" else {"M": report.get("peer")}
|
||||
return (
|
||||
set(identities) == ({"SS", "ST"} if name == "NATIVE" else {"M"})
|
||||
and envelope(
|
||||
report, peers, source(run), digest, single=None if name == "NATIVE" else "M"
|
||||
)
|
||||
and wire_pass(name, root, report)
|
||||
)
|
||||
|
||||
|
||||
def prepare(output, *, native):
|
||||
from .native_release import download_native
|
||||
from .protocol_hysteria2_acceptance import prepare as prepare_mihomo
|
||||
|
||||
supplied = prepare_mihomo(output, {"M"})
|
||||
artifacts = (
|
||||
{
|
||||
kind: download_native(
|
||||
kind, output / "binaries" / kind, "linux-arm64", defer_version=True
|
||||
)
|
||||
for kind in ("ST", "SS")
|
||||
}
|
||||
if native
|
||||
else {}
|
||||
)
|
||||
return supplied, artifacts
|
||||
|
||||
|
||||
def execute(cases, run, output, results):
|
||||
from .protocol_containers import frozen_image
|
||||
from .protocol_harness import _command
|
||||
from .protocol_integration_suite import run as integration
|
||||
from .protocol_shadowtls import run as mihomo
|
||||
from .protocol_shadowtls_native import run as native
|
||||
from .protocol_vless_container import run as vless
|
||||
|
||||
selected = {c["case_id"].removeprefix("SHADOWTLS-"): c for c in cases}
|
||||
peers = {}
|
||||
|
||||
def save(name):
|
||||
good = group_pass(name, output, run, peers)
|
||||
case = selected[name]
|
||||
results[case["case_id"]] = result(case, good, good)
|
||||
print(case["case_id"] + (": PASS" if good else ": FAIL"), flush=True)
|
||||
if not good:
|
||||
raise RuntimeError("ShadowTLS gate failed: " + name)
|
||||
|
||||
try:
|
||||
for name in selected:
|
||||
if name not in LOCAL:
|
||||
continue
|
||||
for i, argv in enumerate(commands(name)):
|
||||
label = f"SHADOWTLS-{name}-{i}"
|
||||
command = _command(
|
||||
run,
|
||||
output,
|
||||
label,
|
||||
[v.replace("{output}", str(output)) for v in argv],
|
||||
3600,
|
||||
events=output / (label + "-events.jsonl"),
|
||||
)
|
||||
validate_execution(
|
||||
argv,
|
||||
command.stdout.decode(errors="replace"),
|
||||
command.returncode,
|
||||
command.cleanup,
|
||||
)
|
||||
save(name)
|
||||
if set(selected) <= LOCAL:
|
||||
return
|
||||
with frozen_image(output / "image-pull.log") as image:
|
||||
run["container_image"] = image
|
||||
supplied, artifacts = prepare(output, native="NATIVE" in selected)
|
||||
peers.update({k: v[1] for k, v in supplied.items()})
|
||||
peers.update({k: v.identity for k, v in artifacts.items()})
|
||||
for name in selected:
|
||||
if name in LOCAL:
|
||||
continue
|
||||
root = output / name.lower()
|
||||
if name.startswith("MIHOMO-"):
|
||||
mihomo(
|
||||
root,
|
||||
profiles=PROFILES if name == "MIHOMO-DATA" else ("chrome",),
|
||||
checks=name.removeprefix("MIHOMO-").lower(),
|
||||
supplied=supplied["M"],
|
||||
image=image,
|
||||
)
|
||||
elif name == "NATIVE":
|
||||
native(root, supplied=artifacts, image=image)
|
||||
elif name == "SHARED":
|
||||
for label, group in SHARED.items():
|
||||
vless(root / label, supplied=supplied, **group)
|
||||
elif name == "BARE-SS":
|
||||
integration(
|
||||
root, ["INTEGRATION-SS-ALGORITHMS"], supplied=supplied["M"]
|
||||
)
|
||||
else:
|
||||
raise ValueError("unknown ShadowTLS gate")
|
||||
save(name)
|
||||
finally:
|
||||
(output / "peers.json").write_text(json.dumps(peers, indent=2) + "\n")
|
||||
|
||||
|
||||
def check(directory, cases, run, results, peers, paths):
|
||||
if not {"cases.json", "peers.json", "resources.jsonl", "summary.md"} <= set(paths):
|
||||
raise ValueError("missing ShadowTLS evidence files")
|
||||
expected_commands = [
|
||||
f"SHADOWTLS-{c['case_id'].removeprefix('SHADOWTLS-')}-{i}"
|
||||
for c in cases
|
||||
for i, _ in enumerate(commands(c["case_id"].removeprefix("SHADOWTLS-")))
|
||||
]
|
||||
actual = [r["name"] for r in run["commands"]]
|
||||
if (
|
||||
len(actual) != len(set(actual))
|
||||
or set(actual) != set(expected_commands)
|
||||
or set(peers) != {"M", "SS", "ST"}
|
||||
):
|
||||
raise ValueError("ShadowTLS command or peer selection differs")
|
||||
for case in cases:
|
||||
name = case["case_id"].removeprefix("SHADOWTLS-")
|
||||
if not group_pass(name, directory, run, peers):
|
||||
raise ValueError("ShadowTLS raw evidence failed: " + name)
|
||||
print("SHADOWTLS coverage: PASS (all required groups; device delivery separate)")
|
||||
|
||||
|
||||
def preflight(output):
|
||||
from .protocol_containers import command, frozen_image
|
||||
|
||||
command("system", "status")
|
||||
with frozen_image(output / "image-pull.log"):
|
||||
supplied, artifacts = prepare(output, native=True)
|
||||
(output / "peers.json").write_text(
|
||||
json.dumps(
|
||||
dict(
|
||||
scope="download-only",
|
||||
wire_acceptance="NOT RUN",
|
||||
peers={
|
||||
**{k: v[1] for k, v in supplied.items()},
|
||||
**{k: v.identity for k, v in artifacts.items()},
|
||||
},
|
||||
),
|
||||
indent=2,
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
@@ -0,0 +1,179 @@
|
||||
"""Frozen ShadowTLS v3 acceptance groups, not a duplicate field matrix."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
from .protocol_completion_peers import CASES
|
||||
|
||||
SS_CASES = tuple(c.identifier for c in CASES if c.shadow_tls and not c.uot)
|
||||
FAULTS = (
|
||||
"fragment",
|
||||
"hrr-wire",
|
||||
"cover-mac",
|
||||
"business-mac",
|
||||
"business-truncated",
|
||||
"stall",
|
||||
"native-udp-disabled",
|
||||
)
|
||||
GATES = {
|
||||
"MEMORY": "stream",
|
||||
"FEATURES": "configuration",
|
||||
"QUALITY": "regression",
|
||||
"PLATFORMS": "regression",
|
||||
"FINGERPRINT": "regression",
|
||||
"MIHOMO-DATA": "interop",
|
||||
"MIHOMO-POLICY": "interop",
|
||||
"MIHOMO-FAULT": "interop",
|
||||
"NATIVE": "interop",
|
||||
"SHARED": "regression",
|
||||
"BARE-SS": "regression",
|
||||
}
|
||||
LOCAL = {"MEMORY", "FEATURES", "QUALITY", "PLATFORMS", "FINGERPRINT"}
|
||||
SHARED = {
|
||||
**{
|
||||
p: dict(
|
||||
client_fingerprint=p,
|
||||
selected=[
|
||||
"VLESS-TCP-TLS-BASE",
|
||||
"VLESS-TCP-TLS-NEG",
|
||||
"VLESS-TCP-REALITY-BASE",
|
||||
"VLESS-TCP-REALITY-NEG",
|
||||
"FINGERPRINT-ANYTLS",
|
||||
],
|
||||
)
|
||||
for p in ("none", "chrome")
|
||||
},
|
||||
"jls": dict(
|
||||
jls=True,
|
||||
client_fingerprint="chrome",
|
||||
selected=["SECURITY-JLS-TCP-BASE", "SECURITY-JLS-TCP-AUTH"],
|
||||
),
|
||||
}
|
||||
MEMORY_EVENTS = {
|
||||
**{("SHADOWTLS-CFG", n): 1 for n in ("policy", "reject", "feature")},
|
||||
**{("SHADOWTLS-STREAM", n): 1 for n in ("cancelled_hello", "invalid_record")},
|
||||
**{
|
||||
("SHADOWTLS-UNIT", n): 1
|
||||
for n in (
|
||||
"native_signature",
|
||||
"native_finished",
|
||||
"stream_io",
|
||||
"read_cancel",
|
||||
"close_deadline",
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def definitions():
|
||||
return [
|
||||
dict(
|
||||
case_id="SHADOWTLS-" + name,
|
||||
stage="SHADOWTLS",
|
||||
substage="SHADOWTLS." + category,
|
||||
required=True,
|
||||
row_ids=[],
|
||||
protocol="ss",
|
||||
network="tcp/native-udp",
|
||||
security="shadowtls-v3",
|
||||
udp_codec="ss2022",
|
||||
field_values={},
|
||||
outer_family="IPv4",
|
||||
inner_family="IPv4/IPv6/domain",
|
||||
target_type="memory-only/build" if name in LOCAL else "isolated origin",
|
||||
upstream_graph="existing-controlled-connector",
|
||||
peer_kind="unit" if name in LOCAL else "SS" if name == "NATIVE" else "M",
|
||||
peer_config={"group": name},
|
||||
gap_source=None,
|
||||
expected_observation=["SHADOWTLS-" + name],
|
||||
required_evidence=["command", "structured-assertions", "cleanup"]
|
||||
+ ([] if name in LOCAL else ["peer-identity", "isolated-origins"]),
|
||||
prerequisites=["rust-toolchain"]
|
||||
if name in LOCAL
|
||||
else ["owned-host-only-container-network", "official-latest-peer"],
|
||||
runner="shadowtls-gate",
|
||||
timeout_seconds=3600,
|
||||
)
|
||||
for name, category in GATES.items()
|
||||
]
|
||||
|
||||
|
||||
def commands(name):
|
||||
cargo = ["cargo", "test", "--locked", "--all-features"]
|
||||
if name == "MEMORY":
|
||||
return [
|
||||
cargo
|
||||
+ [
|
||||
arg
|
||||
for target in (
|
||||
"shadowtls_config",
|
||||
"shadowtls_stream",
|
||||
"shadowsocks_backpressure",
|
||||
"jls_config",
|
||||
"reality_config",
|
||||
)
|
||||
for arg in ("--test", target)
|
||||
],
|
||||
cargo + ["--lib", "security::shadow_tls_tests::"],
|
||||
cargo + ["--lib", "security::tls::tests::"],
|
||||
]
|
||||
if name == "FEATURES":
|
||||
return [
|
||||
[
|
||||
"cargo",
|
||||
"check",
|
||||
"--locked",
|
||||
"--no-default-features",
|
||||
"--features",
|
||||
features,
|
||||
]
|
||||
for features in (
|
||||
"outbound-shadowsocks",
|
||||
"shadow-tls-v3",
|
||||
"outbound-shadowsocks,shadow-tls-v3",
|
||||
)
|
||||
] + [
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--no-default-features",
|
||||
"--features",
|
||||
"outbound-shadowsocks,interop-test",
|
||||
"--test",
|
||||
"shadowtls_config",
|
||||
],
|
||||
["cargo", "test", "--locked", "--test", "feature_foundations"],
|
||||
cargo + ["--all-targets", "--no-run"],
|
||||
]
|
||||
if name == "QUALITY":
|
||||
return [
|
||||
["cargo", "fmt", "--all", "--", "--check"],
|
||||
[
|
||||
"cargo",
|
||||
"clippy",
|
||||
"--locked",
|
||||
"--all-features",
|
||||
"--all-targets",
|
||||
"--",
|
||||
"-D",
|
||||
"warnings",
|
||||
],
|
||||
[sys.executable, "-m", "unittest", "discover", "-s", "scripts/tests"],
|
||||
["ruff", "check", "scripts"],
|
||||
["ruff", "format", "--check", "scripts"],
|
||||
["git", "diff", "--check"],
|
||||
]
|
||||
if name == "PLATFORMS":
|
||||
return [["vcore-scripts", "build", target] for target in ("apple", "android")]
|
||||
if name == "FINGERPRINT":
|
||||
return [
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"vcore_scripts.protocol_fingerprint_shape",
|
||||
"{output}/fingerprint",
|
||||
]
|
||||
]
|
||||
return []
|
||||
@@ -0,0 +1,306 @@
|
||||
"""Supplementary native ShadowTLS + unmodified ssserver TCP acceptance."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from .builds import CORE_DIR
|
||||
from .mihomo_isolation import exclusive_run
|
||||
from .native_release import download_native
|
||||
from .protocol_completion_peers import CASES, peer_configuration
|
||||
from .protocol_containers import ContainerLab, command, frozen_image
|
||||
from .protocol_fixtures import certificates
|
||||
from .protocol_inputs import redact, same_source, source_identity
|
||||
from .protocol_peers import run_command
|
||||
|
||||
|
||||
def run(output: Path, *, supplied=None, image=None):
|
||||
output = output.resolve()
|
||||
if not output.is_relative_to((CORE_DIR / "target/interop/runs").resolve()):
|
||||
raise ValueError("native ShadowTLS evidence must stay in the owned run root")
|
||||
output.mkdir(parents=True, exist_ok=False)
|
||||
report = dict(
|
||||
source=source_identity(), status="NOT RUN", peers={}, isolation={}, cases=[]
|
||||
)
|
||||
directories = {}
|
||||
try:
|
||||
with (
|
||||
exclusive_run() if supplied is None else contextlib.nullcontext(),
|
||||
(
|
||||
frozen_image(output / "image-pull.log")
|
||||
if image is None
|
||||
else contextlib.nullcontext(image)
|
||||
) as image,
|
||||
):
|
||||
report["container_image"] = image
|
||||
artifacts = supplied or {
|
||||
kind: download_native(
|
||||
kind, output / kind, "linux-arm64", defer_version=True
|
||||
)
|
||||
for kind in ("ST", "SS")
|
||||
}
|
||||
for kind, artifact in artifacts.items():
|
||||
report["peers"][kind] = artifact.identity
|
||||
built = run_command(
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--all-features",
|
||||
"--test",
|
||||
"vless_public",
|
||||
"--no-run",
|
||||
],
|
||||
cwd=CORE_DIR,
|
||||
timeout=180,
|
||||
)
|
||||
(output / "build.log").write_text(
|
||||
redact(built.stdout.decode(errors="replace"))
|
||||
)
|
||||
if built.returncode or not built.cleanup:
|
||||
raise RuntimeError("native ShadowTLS consumer build failed")
|
||||
lab = ContainerLab(report["isolation"], mtu=1500)
|
||||
with tempfile.TemporaryDirectory(prefix="private-", dir=output) as temp:
|
||||
root = Path(temp)
|
||||
try:
|
||||
with contextlib.ExitStack() as stack:
|
||||
for role in (
|
||||
"origin",
|
||||
"ssserver",
|
||||
"shadow0",
|
||||
"shadow1",
|
||||
"shadow2",
|
||||
):
|
||||
directories[role] = root / role
|
||||
directories[role].mkdir()
|
||||
cert = certificates(directories["origin"])
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_udp_origin.py"),
|
||||
directories["origin"] / "origin.py",
|
||||
)
|
||||
origin = lab.start(
|
||||
stack,
|
||||
directories["origin"],
|
||||
"origin",
|
||||
[
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"VCORE_ORIGIN_CERT=/data/fixture/cert.pem",
|
||||
"VCORE_ORIGIN_KEY=/data/fixture/key.pem",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/origin.py",
|
||||
],
|
||||
)
|
||||
shutil.copy2(
|
||||
artifacts["SS"].binary, directories["ssserver"] / "ssserver"
|
||||
)
|
||||
ss = lab.start(
|
||||
stack,
|
||||
directories["ssserver"],
|
||||
"ssserver",
|
||||
[
|
||||
"/data/fixture/ssserver",
|
||||
"-c",
|
||||
"/data/fixture/config.json",
|
||||
],
|
||||
)
|
||||
peers = {"SS": ss}
|
||||
servers, nodes, relays = [], [], []
|
||||
for index, case in enumerate(
|
||||
c for c in CASES if c.shadow_tls and not c.uot
|
||||
):
|
||||
directory = directories[f"shadow{index}"]
|
||||
shutil.copy2(
|
||||
artifacts["ST"].binary, directory / "shadow-tls"
|
||||
)
|
||||
relay = lab.start(
|
||||
stack,
|
||||
directory,
|
||||
f"shadow{index}",
|
||||
[
|
||||
"env",
|
||||
"RUST_LOG=error",
|
||||
"/data/fixture/shadow-tls",
|
||||
"--threads",
|
||||
"1",
|
||||
"--v3",
|
||||
"--strict",
|
||||
"server",
|
||||
"--listen",
|
||||
"0.0.0.0:23000",
|
||||
"--server",
|
||||
f"{ss.ipv4}:{23100 + index}",
|
||||
"--tls",
|
||||
f"{origin.ipv4}:24001",
|
||||
"--password",
|
||||
"synthetic-shadowtls-fixture",
|
||||
],
|
||||
)
|
||||
peers.setdefault("ST", relay)
|
||||
node, _ = peer_configuration(
|
||||
case,
|
||||
server=relay.ipv4,
|
||||
cover=f"{origin.ipv4}:24001",
|
||||
port=23000,
|
||||
certificate=cert,
|
||||
)
|
||||
node.update(name="peer", udp=False)
|
||||
node["client-fingerprint"] = "chrome"
|
||||
nodes.append((case.identifier, node))
|
||||
relays.append(relay)
|
||||
servers.append(
|
||||
dict(
|
||||
server="::",
|
||||
server_port=23100 + index,
|
||||
method=node["cipher"],
|
||||
password=node["password"],
|
||||
mode="tcp_only",
|
||||
)
|
||||
)
|
||||
for kind, peer in peers.items():
|
||||
name = artifacts[kind].binary.name
|
||||
identity = report["peers"][kind]
|
||||
identity["version"] = command(
|
||||
"exec", peer.name, f"/data/fixture/{name}", "--version"
|
||||
).strip()
|
||||
if (
|
||||
not identity["version"]
|
||||
or command(
|
||||
"exec",
|
||||
peer.name,
|
||||
"sha256sum",
|
||||
f"/data/fixture/{name}",
|
||||
).split()[0]
|
||||
!= identity["binary_sha256"]
|
||||
):
|
||||
raise RuntimeError(
|
||||
"native ShadowTLS peer identity mismatch"
|
||||
)
|
||||
(directories["ssserver"] / "config.json").write_text(
|
||||
json.dumps(dict(servers=servers))
|
||||
)
|
||||
origin.release()
|
||||
origin.wait_tcp(24000)
|
||||
origin.wait_tcp(24001)
|
||||
ss.release()
|
||||
for index in range(3):
|
||||
ss.wait_tcp(23100 + index)
|
||||
for relay in relays:
|
||||
relay.release()
|
||||
relay.wait_tcp(23000)
|
||||
for identifier, node in nodes:
|
||||
fixture = root / "fixture.json"
|
||||
fixture.write_text(
|
||||
json.dumps(
|
||||
dict(
|
||||
isolation="containers",
|
||||
node=node,
|
||||
origin_ipv4=origin.ipv4,
|
||||
origin_ipv6=origin.ipv6,
|
||||
origin_control=f"{origin.ipv4}:24000",
|
||||
data_dir=str(root / "data"),
|
||||
)
|
||||
)
|
||||
)
|
||||
observations = output / f"{identifier}-observations.json"
|
||||
argv = [
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--all-features",
|
||||
"--test",
|
||||
"vless_public",
|
||||
"shadowtls::native_tcp",
|
||||
"--",
|
||||
"--ignored",
|
||||
"--exact",
|
||||
"--nocapture",
|
||||
]
|
||||
result = run_command(
|
||||
argv,
|
||||
cwd=CORE_DIR,
|
||||
timeout=240,
|
||||
env=dict(
|
||||
os.environ,
|
||||
VCORE_VLESS_INPUT=str(fixture),
|
||||
VCORE_SHADOWTLS_OBSERVATIONS=str(observations),
|
||||
VCORE_CASE_EVENTS=str(
|
||||
output / f"{identifier}-events.jsonl"
|
||||
),
|
||||
),
|
||||
)
|
||||
(output / f"{identifier}.log").write_text(
|
||||
redact(result.stdout.decode(errors="replace"))
|
||||
)
|
||||
observed = (
|
||||
json.loads(observations.read_text())
|
||||
if observations.is_file()
|
||||
else None
|
||||
)
|
||||
passed = (
|
||||
result.returncode == 0
|
||||
and result.cleanup
|
||||
and observed
|
||||
== dict(
|
||||
tcp_bytes_each_direction=10 * 1024 * 1024,
|
||||
udp_packets=0,
|
||||
udp_sizes=[],
|
||||
stop_idle=True,
|
||||
)
|
||||
)
|
||||
report["cases"].append(
|
||||
dict(
|
||||
case_id=identifier,
|
||||
status="PASS" if passed else "FAIL",
|
||||
command=argv,
|
||||
exit_code=result.returncode,
|
||||
command_cleanup=result.cleanup,
|
||||
observations=observed,
|
||||
)
|
||||
)
|
||||
print(
|
||||
f"{identifier}: {'PASS' if passed else 'FAIL'}",
|
||||
flush=True,
|
||||
)
|
||||
if not passed:
|
||||
raise RuntimeError(
|
||||
"native ShadowTLS TCP validation failed"
|
||||
)
|
||||
finally:
|
||||
for role, directory in directories.items():
|
||||
if (directory / "peer.log").is_file():
|
||||
(output / f"{role}.log").write_text(
|
||||
redact(
|
||||
(directory / "peer.log").read_text(errors="replace")
|
||||
)
|
||||
)
|
||||
report["status"] = "PASS"
|
||||
except BaseException as error:
|
||||
report["status"] = "FAIL"
|
||||
(output / "failure.log").write_text(redact(str(error)))
|
||||
raise
|
||||
finally:
|
||||
report["cleanup"] = all(
|
||||
p.get("joined") is True for p in report["isolation"].get("peers", [])
|
||||
)
|
||||
report["source_unchanged"] = same_source(report["source"], source_identity())
|
||||
if not report["cleanup"] or not report["source_unchanged"]:
|
||||
report["status"] = "FAIL"
|
||||
(output / "report.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
if report["status"] != "PASS":
|
||||
raise RuntimeError("native ShadowTLS source or cleanup gate failed")
|
||||
return report
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("output", type=Path)
|
||||
run(parser.parse_args().output)
|
||||
@@ -0,0 +1,543 @@
|
||||
"""TUIC v5 public consumers against freshly downloaded, isolated Mihomo."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from .builds import CORE_DIR
|
||||
from .mihomo_isolation import exclusive_run
|
||||
from .mihomo_release import download_mihomo
|
||||
from .protocol_completion_peers import CASES, peer_configuration
|
||||
from .protocol_containers import ContainerLab, command, frozen_image
|
||||
from .protocol_fixtures import certificate_chain
|
||||
from .protocol_inputs import redact, same_source, source_identity
|
||||
from .protocol_peers import run_command
|
||||
from .protocol_security_acceptance import rust_command
|
||||
|
||||
|
||||
def expected_observation(consumer):
|
||||
if consumer == "udp_disabled":
|
||||
return dict(udp_packets=0, tcp_works=True, stop_idle=True)
|
||||
if consumer == "group":
|
||||
return dict(
|
||||
nested_select=True,
|
||||
pooled_path_retained=True,
|
||||
explicit_rebuild=True,
|
||||
reject_no_fallback=True,
|
||||
new_direct=True,
|
||||
node_measure=True,
|
||||
group_measure_rejected=True,
|
||||
rollback=True,
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer == "udp":
|
||||
return dict(
|
||||
udp_packets=2100,
|
||||
udp_sizes=[0, 1, 64, 512, 1200, 4096, 16384],
|
||||
families=["ipv4", "ipv6", "domain"],
|
||||
alternating_origins=True,
|
||||
tcp_sibling=True,
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer == "tcp":
|
||||
return dict(
|
||||
families=["ipv4", "ipv6", "domain"],
|
||||
tcp_bytes_each_family_each_direction=10 * 1024 * 1024,
|
||||
sibling_survives=True,
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer == "rejected":
|
||||
return dict(origin_connected=False, received_business_bytes=0, stop_idle=True)
|
||||
raise ValueError("unknown TUIC consumer")
|
||||
|
||||
|
||||
def inputs(node, listener, checks):
|
||||
if checks == "negative":
|
||||
for index, (kind, mode) in enumerate(
|
||||
(kind, mode)
|
||||
for kind in ("udp-disabled", "socks5-tcp-only")
|
||||
for mode in ("native", "quic")
|
||||
):
|
||||
client, peer = copy.deepcopy(node), copy.deepcopy(listener)
|
||||
client["udp-relay-mode"] = mode
|
||||
client["udp"] = kind != "udp-disabled"
|
||||
client["port"] = peer["port"] = 23000 + index
|
||||
peer["name"] = kind + "-" + mode
|
||||
yield (
|
||||
peer["name"],
|
||||
client,
|
||||
peer,
|
||||
("udp_disabled" if kind == "udp-disabled" else "rejected"),
|
||||
)
|
||||
return
|
||||
if checks == "paths":
|
||||
for index, (upstream, mode) in enumerate(
|
||||
(upstream, mode)
|
||||
for upstream in ("socks5", "ss-uot", "anytls")
|
||||
for mode in ("native", "quic")
|
||||
):
|
||||
client, peer = copy.deepcopy(node), copy.deepcopy(listener)
|
||||
client["udp-relay-mode"] = mode
|
||||
client["port"] = peer["port"] = 23000 + index
|
||||
peer["name"] = upstream + "-" + mode
|
||||
yield peer["name"], client, peer, "group"
|
||||
return
|
||||
if checks == "udp":
|
||||
for index, mode in enumerate(("native", "quic")):
|
||||
client, peer = copy.deepcopy(node), copy.deepcopy(listener)
|
||||
client["udp-relay-mode"] = mode
|
||||
client["port"] = peer["port"] = 23000 + index
|
||||
peer["name"] = "udp-" + mode
|
||||
yield peer["name"], client, peer, "udp"
|
||||
return
|
||||
names = (
|
||||
("tcp-cubic", "tcp-new_reno", "tcp-bbr")
|
||||
if checks == "tcp"
|
||||
else (
|
||||
"alpn-default",
|
||||
"alpn-custom",
|
||||
"empty-password",
|
||||
"raw-password",
|
||||
"skip",
|
||||
"verify-name",
|
||||
"wrong-uuid",
|
||||
"wrong-password",
|
||||
"wrong-pin",
|
||||
"wrong-pin-skip",
|
||||
"untrusted",
|
||||
"wrong-name-skip",
|
||||
"wrong-alpn",
|
||||
)
|
||||
)
|
||||
for index, name in enumerate(names):
|
||||
client, peer = copy.deepcopy(node), copy.deepcopy(listener)
|
||||
client["udp"] = False
|
||||
client.pop("udp-relay-mode")
|
||||
client["port"] = peer["port"] = 23000 + index
|
||||
peer["name"] = name
|
||||
if name.startswith("tcp-"):
|
||||
client["congestion-controller"] = name.removeprefix("tcp-")
|
||||
elif name == "alpn-default":
|
||||
del client["alpn"]
|
||||
elif name == "alpn-custom":
|
||||
client["alpn"] = ["not-selected", "fixture-custom"]
|
||||
peer["alpn"] = ["fixture-custom"]
|
||||
elif name in {"empty-password", "raw-password"}:
|
||||
client["password"] = (
|
||||
"" if name == "empty-password" else " synthetic-原样\t\0 "
|
||||
)
|
||||
peer["users"] = {client["uuid"]: client["password"]}
|
||||
elif name == "skip":
|
||||
del client["fingerprint"]
|
||||
client["skip-cert-verify"] = True
|
||||
elif name == "verify-name":
|
||||
client["sni"] = "unrelated.invalid"
|
||||
client["name-cert-verify"] = "localhost"
|
||||
elif name == "wrong-uuid":
|
||||
client["uuid"] = "09090909-0909-0909-0909-090909090909"
|
||||
elif name == "wrong-password":
|
||||
client["password"] = "incorrect-synthetic-auth"
|
||||
elif name.startswith("wrong-pin"):
|
||||
client["fingerprint"] = "09" * 32
|
||||
client["skip-cert-verify"] = name.endswith("skip")
|
||||
elif name == "untrusted":
|
||||
del client["fingerprint"]
|
||||
elif name == "wrong-name-skip":
|
||||
client["name-cert-verify"] = "unrelated.invalid"
|
||||
client["skip-cert-verify"] = True
|
||||
elif name == "wrong-alpn":
|
||||
client["alpn"] = ["unrelated"]
|
||||
yield (
|
||||
name,
|
||||
client,
|
||||
peer,
|
||||
"rejected" if name.startswith("wrong-") or name == "untrusted" else "tcp",
|
||||
)
|
||||
|
||||
|
||||
def upstream_pair(name, node, certificate, index):
|
||||
cert, key, pin = certificate
|
||||
base = dict(name="hop", server=node["server"], port=23100 + index, udp=True)
|
||||
listener = dict(name="hop-" + str(index), listen="::", port=base["port"])
|
||||
if name.startswith("socks5-"):
|
||||
return dict(base, type="socks5"), dict(listener, type="socks", udp=True)
|
||||
if name.startswith("ss-uot-"):
|
||||
keytext = "BwcHBwcHBwcHBwcHBwcHBw=="
|
||||
return dict(
|
||||
base,
|
||||
type="ss",
|
||||
cipher="2022-blake3-aes-128-gcm",
|
||||
password=keytext,
|
||||
**{"udp-over-tcp": True},
|
||||
), dict(
|
||||
listener,
|
||||
type="shadowsocks",
|
||||
cipher="2022-blake3-aes-128-gcm",
|
||||
password=keytext,
|
||||
udp=False,
|
||||
)
|
||||
if name.startswith("anytls-"):
|
||||
password = "synthetic-hop"
|
||||
return dict(
|
||||
base, type="anytls", password=password, sni="localhost", fingerprint=pin
|
||||
), dict(
|
||||
listener,
|
||||
type="anytls",
|
||||
users={"fixture": password},
|
||||
certificate="/data/fixture/" + cert.name,
|
||||
**{"private-key": "/data/fixture/" + key.name},
|
||||
)
|
||||
raise ValueError("unknown TUIC upstream")
|
||||
|
||||
|
||||
def run(output, *, checks="tcp", selected=None, supplied=None, image=None):
|
||||
if checks not in {"tcp", "policy", "udp", "paths", "negative"}:
|
||||
raise ValueError("unknown TUIC check")
|
||||
output = output.resolve()
|
||||
if not output.is_relative_to((CORE_DIR / "target/interop/runs").resolve()):
|
||||
raise ValueError("TUIC evidence must stay in target/interop/runs")
|
||||
output.mkdir(parents=True, exist_ok=False)
|
||||
report = dict(
|
||||
source=source_identity(), status="NOT RUN", peer={}, isolation={}, cases=[]
|
||||
)
|
||||
try:
|
||||
with (
|
||||
exclusive_run() if supplied is None else contextlib.nullcontext(),
|
||||
frozen_image(output / "image-pull.log")
|
||||
if image is None
|
||||
else contextlib.nullcontext(image) as image,
|
||||
):
|
||||
report["container_image"] = image
|
||||
if supplied is None:
|
||||
binary = download_mihomo(
|
||||
"linux-arm64", directory=output / "binary", identity=report["peer"]
|
||||
)
|
||||
else:
|
||||
binary, report["peer"] = supplied
|
||||
built = run_command(
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--all-features",
|
||||
"--test",
|
||||
"vless_public",
|
||||
"--no-run",
|
||||
],
|
||||
cwd=CORE_DIR,
|
||||
timeout=180,
|
||||
)
|
||||
(output / "build.log").write_text(
|
||||
redact(built.stdout.decode(errors="replace"))
|
||||
)
|
||||
if built.returncode or not built.cleanup:
|
||||
raise RuntimeError("TUIC consumer build failed")
|
||||
lab = ContainerLab(report["isolation"], mtu=1500)
|
||||
with tempfile.TemporaryDirectory(prefix="private-", dir=output) as tmp:
|
||||
root = Path(tmp)
|
||||
directories = {
|
||||
role: root / role
|
||||
for role in (
|
||||
"origin",
|
||||
"server",
|
||||
*(["upstream"] if checks in {"paths", "negative"} else []),
|
||||
)
|
||||
}
|
||||
for d in directories.values():
|
||||
d.mkdir()
|
||||
cert = certificate_chain(directories["server"])
|
||||
shutil.copy2(binary, directories["server"] / "mihomo")
|
||||
if checks in {"paths", "negative"}:
|
||||
for asset in (binary, *cert[:2]):
|
||||
shutil.copy2(
|
||||
asset,
|
||||
directories["upstream"]
|
||||
/ ("mihomo" if asset == binary else asset.name),
|
||||
)
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_restart_peer.py"),
|
||||
directories["server"] / "restart.py",
|
||||
)
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_udp_origin.py"),
|
||||
directories["origin"] / "origin.py",
|
||||
)
|
||||
try:
|
||||
with contextlib.ExitStack() as stack:
|
||||
origin = lab.start(
|
||||
stack,
|
||||
directories["origin"],
|
||||
"origin",
|
||||
[
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/origin.py",
|
||||
],
|
||||
)
|
||||
server = lab.start(
|
||||
stack,
|
||||
directories["server"],
|
||||
"server",
|
||||
[
|
||||
*(
|
||||
[
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/restart.py",
|
||||
]
|
||||
if checks == "paths"
|
||||
else []
|
||||
),
|
||||
"/data/fixture/mihomo",
|
||||
"-d",
|
||||
"/data",
|
||||
"-f",
|
||||
"/data/fixture/config.json",
|
||||
],
|
||||
)
|
||||
upstream = (
|
||||
lab.start(
|
||||
stack,
|
||||
directories["upstream"],
|
||||
"upstream",
|
||||
[
|
||||
"/data/fixture/mihomo",
|
||||
"-d",
|
||||
"/data",
|
||||
"-f",
|
||||
"/data/fixture/config.json",
|
||||
],
|
||||
)
|
||||
if checks in {"paths", "negative"}
|
||||
else None
|
||||
)
|
||||
report["peer"]["version"] = command(
|
||||
"exec", server.name, "/data/fixture/mihomo", "-v"
|
||||
).strip()
|
||||
if (
|
||||
command(
|
||||
"exec", server.name, "sha256sum", "/data/fixture/mihomo"
|
||||
).split()[0]
|
||||
!= report["peer"]["binary_sha256"]
|
||||
):
|
||||
raise RuntimeError("TUIC peer binary identity mismatch")
|
||||
case = next(
|
||||
c for c in CASES if c.identifier == "tuic-v5-native"
|
||||
)
|
||||
node, listener = peer_configuration(
|
||||
case,
|
||||
server=server.ipv4,
|
||||
cover="",
|
||||
port=23000,
|
||||
certificate=cert,
|
||||
)
|
||||
node["name"] = "peer"
|
||||
rows = list(inputs(node, listener, checks))
|
||||
if selected is not None:
|
||||
if len(set(selected)) != len(selected) or not set(
|
||||
selected
|
||||
) <= {r[0] for r in rows}:
|
||||
raise ValueError("unknown or repeated TUIC case")
|
||||
rows = [r for r in rows if r[0] in selected]
|
||||
if not rows:
|
||||
raise ValueError("empty TUIC selection")
|
||||
upstreams = (
|
||||
{
|
||||
r[0]: upstream_pair(
|
||||
r[0], dict(r[1], server=upstream.ipv4), cert, i
|
||||
)
|
||||
for i, r in enumerate(rows)
|
||||
if checks == "paths" or r[0].startswith("socks5-")
|
||||
}
|
||||
if checks in {"paths", "negative"}
|
||||
else {}
|
||||
)
|
||||
if checks == "negative":
|
||||
for client, peer in upstreams.values():
|
||||
client["udp"] = peer["udp"] = False
|
||||
(directories["server"] / "config.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"socks-port": 23999,
|
||||
"allow-lan": True,
|
||||
"bind-address": "*",
|
||||
"ipv6": True,
|
||||
"log-level": "warning",
|
||||
"hosts": {"vcore-fixture.test": origin.ipv4},
|
||||
"listeners": [r[2] for r in rows],
|
||||
"rules": ["MATCH,DIRECT"],
|
||||
}
|
||||
)
|
||||
)
|
||||
if upstream is not None:
|
||||
(directories["upstream"] / "config.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"socks-port": 23999,
|
||||
"allow-lan": True,
|
||||
"bind-address": "*",
|
||||
"ipv6": True,
|
||||
"log-level": "warning",
|
||||
"listeners": [r[1] for r in upstreams.values()],
|
||||
"rules": ["MATCH,DIRECT"],
|
||||
}
|
||||
)
|
||||
)
|
||||
if (
|
||||
command(
|
||||
"exec",
|
||||
upstream.name,
|
||||
"sha256sum",
|
||||
"/data/fixture/mihomo",
|
||||
).split()[0]
|
||||
!= report["peer"]["binary_sha256"]
|
||||
or command(
|
||||
"exec", upstream.name, "/data/fixture/mihomo", "-v"
|
||||
).strip()
|
||||
!= report["peer"]["version"]
|
||||
):
|
||||
raise RuntimeError("TUIC upstream identity mismatch")
|
||||
upstream.release()
|
||||
upstream.wait_tcp(23999)
|
||||
origin.release()
|
||||
origin.wait_tcp(24000)
|
||||
checked = run_command(
|
||||
[
|
||||
"container",
|
||||
"exec",
|
||||
server.name,
|
||||
"/data/fixture/mihomo",
|
||||
"-t",
|
||||
"-d",
|
||||
"/data",
|
||||
"-f",
|
||||
"/data/fixture/config.json",
|
||||
],
|
||||
timeout=30,
|
||||
)
|
||||
(output / "peer-config.log").write_text(
|
||||
redact(checked.stdout.decode(errors="replace"))
|
||||
)
|
||||
if checked.returncode or not checked.cleanup:
|
||||
raise RuntimeError(
|
||||
"TUIC isolated peer configuration rejected"
|
||||
)
|
||||
server.release()
|
||||
server.wait_tcp(23999)
|
||||
if checks == "paths":
|
||||
server.wait_tcp(23998)
|
||||
for name, node, _, consumer in rows:
|
||||
fixture = root / "fixture.json"
|
||||
fixture.write_text(
|
||||
json.dumps(
|
||||
dict(
|
||||
isolation="containers",
|
||||
node=node,
|
||||
origin_ipv4=origin.ipv4,
|
||||
origin_ipv6=origin.ipv6,
|
||||
origin_control=f"{origin.ipv4}:24000",
|
||||
data_dir=str(root / "data"),
|
||||
**(
|
||||
dict(upstream=upstreams[name][0])
|
||||
if name in upstreams
|
||||
else {}
|
||||
),
|
||||
**(
|
||||
dict(restart_control=f"{server.ipv4}:23998")
|
||||
if checks == "paths"
|
||||
else {}
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
observations = output / (name + "-observations.json")
|
||||
events = output / (name + "-events.jsonl")
|
||||
argv = rust_command("vless_public", "tuic::" + consumer)
|
||||
result = run_command(
|
||||
argv,
|
||||
cwd=CORE_DIR,
|
||||
timeout=240,
|
||||
env=dict(
|
||||
os.environ,
|
||||
VCORE_VLESS_INPUT=str(fixture),
|
||||
VCORE_TUIC_OBSERVATIONS=str(observations),
|
||||
VCORE_CASE_EVENTS=str(events),
|
||||
),
|
||||
)
|
||||
(output / (name + ".log")).write_text(
|
||||
redact(result.stdout.decode(errors="replace"))
|
||||
)
|
||||
observed = (
|
||||
json.loads(observations.read_text())
|
||||
if observations.is_file()
|
||||
else None
|
||||
)
|
||||
from .protocol_evidence import read_events
|
||||
from .protocol_hysteria2_catalog import assertions_pass
|
||||
|
||||
good = (
|
||||
result.returncode == 0
|
||||
and result.cleanup
|
||||
and observed == expected_observation(consumer)
|
||||
and assertions_pass(
|
||||
read_events(events), {("TUIC-PUBLIC", consumer): 1}
|
||||
)
|
||||
)
|
||||
report["cases"].append(
|
||||
dict(
|
||||
case_id=name,
|
||||
command=argv,
|
||||
exit_code=result.returncode,
|
||||
command_cleanup=result.cleanup,
|
||||
observations=observed,
|
||||
status="PASS" if good else "FAIL",
|
||||
)
|
||||
)
|
||||
print(name + (": PASS" if good else ": FAIL"), flush=True)
|
||||
if not good:
|
||||
raise RuntimeError("TUIC public consumer failed")
|
||||
finally:
|
||||
for role, d in directories.items():
|
||||
if (d / "peer.log").is_file():
|
||||
(output / (role + ".log")).write_text(
|
||||
redact((d / "peer.log").read_text(errors="replace"))
|
||||
)
|
||||
report["status"] = "PASS"
|
||||
except BaseException as error:
|
||||
report["status"] = "FAIL"
|
||||
(output / "failure.log").write_text(redact(str(error)))
|
||||
raise
|
||||
finally:
|
||||
report["cleanup"] = all(
|
||||
p.get("joined") is True for p in report["isolation"].get("peers", [])
|
||||
)
|
||||
report["source_unchanged"] = same_source(report["source"], source_identity())
|
||||
if not report["cleanup"] or not report["source_unchanged"]:
|
||||
report["status"] = "FAIL"
|
||||
(output / "report.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
if report["status"] != "PASS":
|
||||
raise RuntimeError("TUIC source or cleanup failed")
|
||||
return report
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument(
|
||||
"--checks", choices=("tcp", "policy", "udp", "paths", "negative"), default="tcp"
|
||||
)
|
||||
parser.add_argument("--case", action="append")
|
||||
args = parser.parse_args()
|
||||
run(args.output, checks=args.checks, selected=args.case)
|
||||
@@ -0,0 +1,230 @@
|
||||
"""Execute TUIC gates; reconstruct acceptance from raw local and container evidence."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from .core_checks import validate_execution
|
||||
from .protocol_evidence import read_events, read_json
|
||||
from .protocol_hysteria2_catalog import M, assertions_pass
|
||||
from .protocol_hysteria2_catalog import definitions as hy2_definitions
|
||||
from .protocol_inputs import redact
|
||||
from .protocol_integration_checks import envelope
|
||||
from .protocol_security_acceptance import result, rust_command
|
||||
from .protocol_shadowtls_acceptance import source
|
||||
from .protocol_tuic import expected_observation
|
||||
from .protocol_tuic_catalog import (
|
||||
CFG_EVENTS,
|
||||
LOCAL,
|
||||
MEMORY_EVENTS,
|
||||
commands,
|
||||
wire_cases,
|
||||
)
|
||||
|
||||
|
||||
def wire_pass(name, directory, report):
|
||||
selected = wire_cases(name)
|
||||
rows = report.get("cases", [])
|
||||
if [r.get("case_id") for r in rows] != [c[0] for c in selected]:
|
||||
return False
|
||||
for row, (identifier, consumer) in zip(rows, selected, strict=True):
|
||||
if not (
|
||||
row.get("command") == rust_command("vless_public", "tuic::" + consumer)
|
||||
and type(row.get("exit_code")) is int
|
||||
and row["exit_code"] == 0
|
||||
and row.get("command_cleanup") is True
|
||||
and row.get("observations")
|
||||
== read_json(directory / (identifier + "-observations.json"))
|
||||
== expected_observation(consumer)
|
||||
and assertions_pass(
|
||||
read_events(directory / (identifier + "-events.jsonl")),
|
||||
{("TUIC-PUBLIC", consumer): 1},
|
||||
)
|
||||
):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def local_pass(name, directory, run):
|
||||
expected = commands(name)
|
||||
rows = [r for r in run["commands"] if r["name"].startswith("TUIC-" + name + "-")]
|
||||
if len(rows) != len(expected):
|
||||
return False
|
||||
events = []
|
||||
for index, (row, argv) in enumerate(zip(rows, expected, strict=True)):
|
||||
label = f"TUIC-{name}-{index}"
|
||||
if row["name"] != label or row["command"] != [redact(v) for v in argv]:
|
||||
return False
|
||||
validate_execution(
|
||||
row["command"],
|
||||
(directory / row["log"]).read_text(),
|
||||
row["exit_code"],
|
||||
row["cleanup"],
|
||||
)
|
||||
path = directory / (label + "-events.jsonl")
|
||||
if path.exists():
|
||||
events += read_events(path)
|
||||
if name in {"MEMORY", "FEATURES"}:
|
||||
required = (
|
||||
MEMORY_EVENTS
|
||||
if name == "MEMORY"
|
||||
else {
|
||||
**{
|
||||
key: value
|
||||
for key, value in MEMORY_EVENTS.items()
|
||||
if key[1]
|
||||
not in {"reassembly_order", "reassembly_limits", "delivery_limits"}
|
||||
},
|
||||
**{
|
||||
key: 2 if key[1] in {"identity", "redaction"} else value
|
||||
for key, value in CFG_EVENTS.items()
|
||||
},
|
||||
}
|
||||
)
|
||||
return assertions_pass(
|
||||
[e for e in events if e.get("suite", "").startswith("TUIC-")], required
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def group_pass(name, directory, run, peers):
|
||||
from .protocol_hysteria2_acceptance import h3_result, native_result
|
||||
|
||||
if name in LOCAL:
|
||||
return local_pass(name, directory, run)
|
||||
root = directory / name.lower()
|
||||
digest = run["container_image"]["digest"]
|
||||
if name.startswith("MIHOMO-"):
|
||||
report = read_json(root / "report.json")
|
||||
return envelope(report, peers, source(run), digest, single="M") and wire_pass(
|
||||
name, root, report
|
||||
)
|
||||
if name.startswith("HYSTERIA2-"):
|
||||
case = next(c for c in hy2_definitions() if c["case_id"] == name)
|
||||
report = read_json(root / "report.json")
|
||||
return (
|
||||
envelope(report, peers, source(run), digest)
|
||||
and native_result(case, report, root)["status"] == "PASS"
|
||||
)
|
||||
if name == "XHTTP-H3":
|
||||
from .protocol_hysteria2_catalog import H3
|
||||
|
||||
case = next(c for c in hy2_definitions() if c["case_id"] == H3)
|
||||
report = read_json(root / "xhttp-fields-results.json")
|
||||
return (
|
||||
envelope(report, peers, source(run), digest)
|
||||
and h3_result(case, report, root)["status"] == "PASS"
|
||||
)
|
||||
raise ValueError("unknown TUIC gate")
|
||||
|
||||
|
||||
def execute(cases, run, output, results):
|
||||
from .protocol_containers import frozen_image
|
||||
from .protocol_harness import _command
|
||||
from .protocol_hysteria2 import run as hysteria2
|
||||
from .protocol_hysteria2_acceptance import h3_jobs, prepare
|
||||
from .protocol_tuic import run as tuic
|
||||
from .protocol_xhttp_fields import run as h3
|
||||
|
||||
selected = {c["case_id"].removeprefix("TUIC-"): c for c in cases}
|
||||
peers = {}
|
||||
|
||||
def save(name):
|
||||
good = group_pass(name, output, run, peers)
|
||||
case = selected[name]
|
||||
results[case["case_id"]] = result(case, good, good)
|
||||
print(case["case_id"] + (": PASS" if good else ": FAIL"), flush=True)
|
||||
if not good:
|
||||
raise RuntimeError("TUIC gate failed: " + name)
|
||||
|
||||
try:
|
||||
for name in selected:
|
||||
if name not in LOCAL:
|
||||
continue
|
||||
for i, argv in enumerate(commands(name)):
|
||||
label = f"TUIC-{name}-{i}"
|
||||
completed = _command(
|
||||
run,
|
||||
output,
|
||||
label,
|
||||
argv,
|
||||
3600,
|
||||
events=output / (label + "-events.jsonl"),
|
||||
)
|
||||
validate_execution(
|
||||
argv,
|
||||
completed.stdout.decode(errors="replace"),
|
||||
completed.returncode,
|
||||
completed.cleanup,
|
||||
)
|
||||
save(name)
|
||||
if set(selected) <= LOCAL:
|
||||
return
|
||||
with frozen_image(output / "image-pull.log") as image:
|
||||
run["container_image"] = image
|
||||
supplied = prepare(output, {"M", "XR"} if "XHTTP-H3" in selected else {"M"})
|
||||
peers.update({k: v[1] for k, v in supplied.items()})
|
||||
for name in selected:
|
||||
if name in LOCAL:
|
||||
continue
|
||||
root = output / name.lower()
|
||||
if name.startswith("MIHOMO-"):
|
||||
tuic(
|
||||
root,
|
||||
checks=name.removeprefix("MIHOMO-").lower(),
|
||||
supplied=supplied["M"],
|
||||
image=image,
|
||||
)
|
||||
elif name in M:
|
||||
test, obfs, _ = M[name]
|
||||
hysteria2(root, test, obfs=obfs, supplied=supplied["M"])
|
||||
elif name == "XHTTP-H3":
|
||||
jobs = h3_jobs()
|
||||
h3(root, list(jobs), jobs=jobs, supplied=supplied)
|
||||
else:
|
||||
raise ValueError("unknown TUIC group")
|
||||
save(name)
|
||||
finally:
|
||||
(output / "peers.json").write_text(json.dumps(peers, indent=2) + "\n")
|
||||
|
||||
|
||||
def check(directory, cases, run, results, peers, paths):
|
||||
if not {"cases.json", "peers.json", "resources.jsonl", "summary.md"} <= set(paths):
|
||||
raise ValueError("missing TUIC evidence")
|
||||
expected = [
|
||||
f"{c['case_id']}-{i}"
|
||||
for c in cases
|
||||
for i, _ in enumerate(commands(c["case_id"].removeprefix("TUIC-")))
|
||||
]
|
||||
actual = [r["name"] for r in run["commands"]]
|
||||
if (
|
||||
len(actual) != len(set(actual))
|
||||
or set(actual) != set(expected)
|
||||
or set(peers) != {"M", "XR"}
|
||||
):
|
||||
raise ValueError("TUIC command or peer selection differs")
|
||||
for case in cases:
|
||||
name = case["case_id"].removeprefix("TUIC-")
|
||||
if not group_pass(name, directory, run, peers):
|
||||
raise ValueError("TUIC raw evidence failed: " + name)
|
||||
print("TUIC coverage: PASS (all required groups; device delivery separate)")
|
||||
|
||||
|
||||
def preflight(output):
|
||||
from .protocol_containers import command, frozen_image
|
||||
from .protocol_hysteria2_acceptance import prepare
|
||||
|
||||
command("system", "status")
|
||||
with frozen_image(output / "image-pull.log"):
|
||||
supplied = prepare(output, {"M", "XR"})
|
||||
(output / "peers.json").write_text(
|
||||
json.dumps(
|
||||
dict(
|
||||
scope="download-only",
|
||||
wire_acceptance="NOT RUN",
|
||||
peers={k: v[1] for k, v in supplied.items()},
|
||||
),
|
||||
indent=2,
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
@@ -0,0 +1,183 @@
|
||||
"""TUIC v5 required groups and independently enumerated wire consumers."""
|
||||
|
||||
from .protocol_shadowtls_catalog import commands as shared_commands
|
||||
|
||||
LOCAL = {"MEMORY", "FEATURES", "QUALITY", "PLATFORMS", "SHARED-QUIC"}
|
||||
HY2 = ("TCP", "UDP", "SECURITY", "OWNED", "DEADLINE")
|
||||
GATES = {
|
||||
"MEMORY": "datagrams",
|
||||
"FEATURES": "configuration",
|
||||
"QUALITY": "regression",
|
||||
"PLATFORMS": "regression",
|
||||
"SHARED-QUIC": "regression",
|
||||
**{
|
||||
"MIHOMO-" + name: "interop"
|
||||
for name in ("TCP", "POLICY", "UDP", "PATHS", "NEGATIVE")
|
||||
},
|
||||
**{"HYSTERIA2-" + name: "regression" for name in HY2},
|
||||
"XHTTP-H3": "regression",
|
||||
}
|
||||
CFG_EVENTS = {("TUIC-CFG", n): 1 for n in ("identity", "redaction", "udp", "bounds")}
|
||||
MEMORY_EVENTS = CFG_EVENTS | {
|
||||
("TUIC-UNIT", n): 1
|
||||
for n in (
|
||||
"tcp_owner",
|
||||
"credit_deadline",
|
||||
"path_requirements",
|
||||
"handshake_stop",
|
||||
"udp_wire",
|
||||
"unused_association",
|
||||
"session_retirement",
|
||||
"partial_control_expiry",
|
||||
"udp_credit_cancel",
|
||||
"protect_fail_closed",
|
||||
"heartbeat_full_queue_stop",
|
||||
"receive_windows",
|
||||
"send_buffers",
|
||||
"reassembly_order",
|
||||
"reassembly_limits",
|
||||
"delivery_limits",
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
def definitions():
|
||||
return [
|
||||
dict(
|
||||
case_id="TUIC-" + name,
|
||||
stage="TUIC",
|
||||
substage="TUIC." + category,
|
||||
required=True,
|
||||
row_ids=[],
|
||||
protocol="tuic",
|
||||
network="quic",
|
||||
security="tls13",
|
||||
udp_codec="native/quic",
|
||||
field_values={},
|
||||
outer_family="IPv4",
|
||||
inner_family="IPv4/IPv6/domain",
|
||||
target_type="memory-only/build" if name in LOCAL else "isolated origin",
|
||||
upstream_graph="controlled-datagrams/optional-nested-select",
|
||||
peer_kind="unit" if name in LOCAL else "M",
|
||||
peer_config={"group": name},
|
||||
gap_source=None,
|
||||
expected_observation=["TUIC-" + name],
|
||||
required_evidence=["command", "structured-assertions", "cleanup"]
|
||||
+ ([] if name in LOCAL else ["peer-identity", "isolated-origins"]),
|
||||
prerequisites=["rust-toolchain"]
|
||||
if name in LOCAL
|
||||
else ["owned-host-only-container-network", "official-latest-peer"],
|
||||
runner="tuic-gate",
|
||||
timeout_seconds=3600,
|
||||
)
|
||||
for name, category in GATES.items()
|
||||
]
|
||||
|
||||
|
||||
def wire_cases(name):
|
||||
if name == "MIHOMO-TCP":
|
||||
return [("tcp-" + n, "tcp") for n in ("cubic", "new_reno", "bbr")]
|
||||
if name == "MIHOMO-POLICY":
|
||||
return [
|
||||
(n, "tcp" if i < 6 else "rejected")
|
||||
for i, n in enumerate(
|
||||
(
|
||||
"alpn-default",
|
||||
"alpn-custom",
|
||||
"empty-password",
|
||||
"raw-password",
|
||||
"skip",
|
||||
"verify-name",
|
||||
"wrong-uuid",
|
||||
"wrong-password",
|
||||
"wrong-pin",
|
||||
"wrong-pin-skip",
|
||||
"untrusted",
|
||||
"wrong-name-skip",
|
||||
"wrong-alpn",
|
||||
)
|
||||
)
|
||||
]
|
||||
if name == "MIHOMO-UDP":
|
||||
return [("udp-" + mode, "udp") for mode in ("native", "quic")]
|
||||
if name == "MIHOMO-PATHS":
|
||||
return [
|
||||
(hop + "-" + mode, "group")
|
||||
for hop in ("socks5", "ss-uot", "anytls")
|
||||
for mode in ("native", "quic")
|
||||
]
|
||||
if name == "MIHOMO-NEGATIVE":
|
||||
return [
|
||||
(
|
||||
kind + "-" + mode,
|
||||
"udp_disabled" if kind == "udp-disabled" else "rejected",
|
||||
)
|
||||
for kind in ("udp-disabled", "socks5-tcp-only")
|
||||
for mode in ("native", "quic")
|
||||
]
|
||||
raise ValueError("unknown TUIC wire group")
|
||||
|
||||
|
||||
def commands(name):
|
||||
cargo = ["cargo", "test", "--locked", "--all-features"]
|
||||
if name == "MEMORY":
|
||||
return [
|
||||
cargo + ["--test", "tuic_config", "--test", "tuic_memory"],
|
||||
cargo + ["--lib", "outbound::tuic::"],
|
||||
]
|
||||
if name == "FEATURES":
|
||||
return [
|
||||
["cargo", "check", "--locked", "--no-default-features"]
|
||||
+ (["--features", f] if f else [])
|
||||
for f in ("", "outbound-tuic", "quic-transport")
|
||||
] + [
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--no-default-features",
|
||||
"--features",
|
||||
"interop-test",
|
||||
"--test",
|
||||
"tuic_config",
|
||||
],
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--no-default-features",
|
||||
"--features",
|
||||
"outbound-tuic,interop-test",
|
||||
"--test",
|
||||
"tuic_config",
|
||||
"--test",
|
||||
"tuic_memory",
|
||||
],
|
||||
["cargo", "test", "--locked", "--test", "feature_foundations"],
|
||||
cargo + ["--all-targets", "--no-run"],
|
||||
]
|
||||
if name == "SHARED-QUIC":
|
||||
return [
|
||||
cargo
|
||||
+ [
|
||||
"--test",
|
||||
"hysteria2_paths",
|
||||
"--test",
|
||||
"hysteria2_packet_ids",
|
||||
"--test",
|
||||
"xhttp_h3_shutdown",
|
||||
"--test",
|
||||
"limit_foundations",
|
||||
],
|
||||
cargo
|
||||
+ [
|
||||
"--test",
|
||||
"quic_datagram_foundations",
|
||||
"pending_send_is_not_restarted_and_stop_cancels_without_waiting_for_writable",
|
||||
"--",
|
||||
"--exact",
|
||||
],
|
||||
cargo + ["--lib", "outbound::hysteria2::"],
|
||||
cargo + ["--lib", "security::tls::tests::"],
|
||||
]
|
||||
return shared_commands(name) if name in {"QUALITY", "PLATFORMS"} else []
|
||||
@@ -0,0 +1,439 @@
|
||||
"""SS UoT v2 public consumers against unmodified TCP-only Mihomo listeners."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import contextlib
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from .builds import CORE_DIR
|
||||
from .mihomo_isolation import exclusive_run
|
||||
from .mihomo_release import download_mihomo
|
||||
from .protocol_completion_peers import CASES, peer_configuration
|
||||
from .protocol_containers import ContainerLab, command, frozen_image
|
||||
from .protocol_fixtures import certificates
|
||||
from .protocol_inputs import redact, same_source, source_identity
|
||||
from .protocol_peers import run_command
|
||||
from .protocol_security_acceptance import rust_command
|
||||
|
||||
|
||||
def expected_observation(consumer, via_socks5=False):
|
||||
if consumer == "group":
|
||||
return dict(
|
||||
nested_select=True,
|
||||
old_association_snapshot=True,
|
||||
new_direct=True,
|
||||
reject_no_fallback=True,
|
||||
native_udp_packets=0,
|
||||
stop_idle=True,
|
||||
)
|
||||
if consumer == "rejected":
|
||||
return dict(
|
||||
origin_packets=0, received_packets=0, native_udp_packets=0, stop_idle=True
|
||||
)
|
||||
if consumer != "data":
|
||||
raise ValueError("unknown UoT consumer")
|
||||
return dict(
|
||||
udp_packets=2100,
|
||||
udp_sizes=[0, 1, 64, 512, 1200, 4096, 16384],
|
||||
families=["ipv4", "ipv6", "domain"],
|
||||
alternating_origins=True,
|
||||
controlled_dns=True,
|
||||
tcp_regression=True,
|
||||
stop_idle=True,
|
||||
tcp_only_upstream=via_socks5,
|
||||
peer_oversize_rejected=True,
|
||||
native_udp_packets=0,
|
||||
)
|
||||
|
||||
|
||||
def run(
|
||||
output,
|
||||
*,
|
||||
selected=None,
|
||||
via_socks5=False,
|
||||
supplied=None,
|
||||
image=None,
|
||||
checks="data",
|
||||
native=False,
|
||||
):
|
||||
if (
|
||||
checks not in {"data", "negative", "group"}
|
||||
or (checks == "group" and not via_socks5)
|
||||
or (native and (checks != "negative" or via_socks5))
|
||||
):
|
||||
raise ValueError("unsupported UoT peer checks")
|
||||
output = output.resolve()
|
||||
if not output.is_relative_to((CORE_DIR / "target/interop/runs").resolve()):
|
||||
raise ValueError("UoT evidence must stay inside target/interop/runs")
|
||||
cases = tuple(c for c in CASES if c.uot and (not native or not c.shadow_tls))
|
||||
if selected is not None:
|
||||
if len(set(selected)) != len(selected) or not set(selected) <= {
|
||||
c.identifier for c in cases
|
||||
}:
|
||||
raise ValueError("unknown or duplicate UoT selection")
|
||||
cases = tuple(c for c in cases if c.identifier in selected)
|
||||
if not cases:
|
||||
raise ValueError("empty UoT selection")
|
||||
output.mkdir(parents=True, exist_ok=False)
|
||||
report = dict(
|
||||
source=source_identity(),
|
||||
status="NOT RUN",
|
||||
peer={},
|
||||
isolation={},
|
||||
cases=[],
|
||||
tcp_only_upstream=via_socks5,
|
||||
)
|
||||
try:
|
||||
with (
|
||||
exclusive_run() if supplied is None else contextlib.nullcontext(),
|
||||
(
|
||||
frozen_image(output / "image-pull.log")
|
||||
if image is None
|
||||
else contextlib.nullcontext(image)
|
||||
) as image,
|
||||
):
|
||||
report["container_image"] = image
|
||||
if supplied is None:
|
||||
if native:
|
||||
from .native_release import download_native
|
||||
|
||||
artifact = download_native(
|
||||
"SS", output / "binary", "linux-arm64", defer_version=True
|
||||
)
|
||||
binary, report["peer"] = artifact.binary, artifact.identity
|
||||
else:
|
||||
binary = download_mihomo(
|
||||
"linux-arm64",
|
||||
directory=output / "binary",
|
||||
identity=report["peer"],
|
||||
)
|
||||
else:
|
||||
binary, report["peer"] = supplied
|
||||
built = run_command(
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--all-features",
|
||||
"--test",
|
||||
"vless_public",
|
||||
"--no-run",
|
||||
],
|
||||
cwd=CORE_DIR,
|
||||
timeout=180,
|
||||
)
|
||||
(output / "build.log").write_text(
|
||||
redact(built.stdout.decode(errors="replace"))
|
||||
)
|
||||
if built.returncode or not built.cleanup:
|
||||
raise RuntimeError("UoT public consumer build failed")
|
||||
lab = ContainerLab(report["isolation"], mtu=1500)
|
||||
with tempfile.TemporaryDirectory(prefix="private-", dir=output) as temp:
|
||||
root = Path(temp)
|
||||
directories = {
|
||||
role: root / role
|
||||
for role in (
|
||||
"origin",
|
||||
"server",
|
||||
*(["upstream"] if via_socks5 else []),
|
||||
)
|
||||
}
|
||||
for d in directories.values():
|
||||
d.mkdir()
|
||||
certificate = certificates(directories["server"])
|
||||
for source, name in zip(
|
||||
certificate[:2], ("cert.pem", "key.pem"), strict=True
|
||||
):
|
||||
shutil.copy2(source, directories["origin"] / name)
|
||||
for source, target in (
|
||||
("container_udp_origin.py", "origin.py"),
|
||||
("container_shadowtls_peer.py", "peer.py"),
|
||||
):
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name(source), directories["origin"] / target
|
||||
)
|
||||
try:
|
||||
with contextlib.ExitStack() as stack:
|
||||
origin = lab.start(
|
||||
stack,
|
||||
directories["origin"],
|
||||
"origin",
|
||||
[
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"VCORE_ORIGIN_CERT=/data/fixture/cert.pem",
|
||||
"VCORE_ORIGIN_KEY=/data/fixture/key.pem",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/peer.py",
|
||||
],
|
||||
)
|
||||
peers = {}
|
||||
peer_name = "ssserver" if native else "mihomo"
|
||||
for role in ("server", *(["upstream"] if via_socks5 else [])):
|
||||
shutil.copy2(binary, directories[role] / peer_name)
|
||||
shutil.copy2(
|
||||
Path(__file__).with_name("container_uot_watch.py"),
|
||||
directories[role] / "watch.py",
|
||||
)
|
||||
peer_argv = (
|
||||
[
|
||||
f"/data/fixture/{peer_name}",
|
||||
"-c",
|
||||
"/data/fixture/config.json",
|
||||
]
|
||||
if native
|
||||
else [
|
||||
"/data/fixture/mihomo",
|
||||
"-d",
|
||||
"/data",
|
||||
"-f",
|
||||
"/data/fixture/config.json",
|
||||
]
|
||||
)
|
||||
peers[role] = lab.start(
|
||||
stack,
|
||||
directories[role],
|
||||
role,
|
||||
[
|
||||
"env",
|
||||
"VCORE_ISOLATED_ORIGIN=1",
|
||||
"python",
|
||||
"-B",
|
||||
"/data/fixture/watch.py",
|
||||
*peer_argv,
|
||||
],
|
||||
)
|
||||
if (
|
||||
command(
|
||||
"exec",
|
||||
peers[role].name,
|
||||
"sha256sum",
|
||||
f"/data/fixture/{peer_name}",
|
||||
).split()[0]
|
||||
!= report["peer"]["binary_sha256"]
|
||||
):
|
||||
raise RuntimeError(
|
||||
"UoT peer identity differs from official download"
|
||||
)
|
||||
server = peers["server"]
|
||||
report["peer"]["version"] = command(
|
||||
"exec",
|
||||
server.name,
|
||||
f"/data/fixture/{peer_name}",
|
||||
"--version" if native else "-v",
|
||||
).strip()
|
||||
nodes, listeners = [], []
|
||||
for index, case in enumerate(cases):
|
||||
node, listener = peer_configuration(
|
||||
case,
|
||||
server=server.ipv4,
|
||||
cover=f"{origin.ipv4}:24001",
|
||||
port=23000 + index,
|
||||
certificate=certificate,
|
||||
)
|
||||
node["name"] = "peer"
|
||||
if case.shadow_tls:
|
||||
node["client-fingerprint"] = "chrome"
|
||||
else:
|
||||
del node["udp-over-tcp-version"]
|
||||
assert listener["udp"] is False
|
||||
if native:
|
||||
nodes.append((case.identifier + "-unsupported", node))
|
||||
elif checks == "negative":
|
||||
bad_key = copy.deepcopy(node)
|
||||
bad_key["password"] = base64.b64encode(
|
||||
bytes([9])
|
||||
* (16 if "aes-128" in node["cipher"] else 32)
|
||||
).decode()
|
||||
nodes.append((case.identifier + "-key", bad_key))
|
||||
if case.shadow_tls:
|
||||
bad_cover = copy.deepcopy(node)
|
||||
bad_cover["plugin-opts"]["password"] = (
|
||||
"incorrect-synthetic-cover"
|
||||
)
|
||||
nodes.append(
|
||||
(case.identifier + "-identity", bad_cover)
|
||||
)
|
||||
else:
|
||||
nodes.append((case.identifier, node))
|
||||
listeners.append(
|
||||
dict(
|
||||
server="::",
|
||||
server_port=node["port"],
|
||||
method=node["cipher"],
|
||||
password=node["password"],
|
||||
mode="tcp_only",
|
||||
)
|
||||
if native
|
||||
else listener
|
||||
)
|
||||
|
||||
def configuration(listeners):
|
||||
return {
|
||||
"socks-port": 23999,
|
||||
"allow-lan": True,
|
||||
"bind-address": "*",
|
||||
"ipv6": True,
|
||||
"log-level": "warning",
|
||||
"listeners": listeners,
|
||||
"rules": ["MATCH,DIRECT"],
|
||||
}
|
||||
|
||||
(directories["server"] / "config.json").write_text(
|
||||
json.dumps(
|
||||
dict(servers=listeners)
|
||||
if native
|
||||
else configuration(listeners)
|
||||
)
|
||||
)
|
||||
upstream = None
|
||||
if via_socks5:
|
||||
upstream = dict(
|
||||
name="hop",
|
||||
type="socks5",
|
||||
server=peers["upstream"].ipv4,
|
||||
port=23050,
|
||||
udp=False,
|
||||
)
|
||||
(directories["upstream"] / "config.json").write_text(
|
||||
json.dumps(
|
||||
configuration(
|
||||
[
|
||||
dict(
|
||||
name="hop",
|
||||
type="socks",
|
||||
listen="::",
|
||||
port=23050,
|
||||
udp=False,
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
origin.release()
|
||||
origin.wait_tcp(24000)
|
||||
origin.wait_tcp(24001)
|
||||
for peer in peers.values():
|
||||
peer.release()
|
||||
peer.wait_tcp(23998)
|
||||
peer.wait_tcp(23000 if native else 23999)
|
||||
for identifier, node in nodes:
|
||||
fixture = root / "fixture.json"
|
||||
value = dict(
|
||||
isolation="containers",
|
||||
node=node,
|
||||
origin_ipv4=origin.ipv4,
|
||||
origin_ipv6=origin.ipv6,
|
||||
origin_control=f"{origin.ipv4}:24000",
|
||||
udp_observer=f"{server.ipv4}:23998",
|
||||
data_dir=str(root / "data"),
|
||||
)
|
||||
if upstream is not None:
|
||||
value["upstream"] = upstream
|
||||
fixture.write_text(json.dumps(value))
|
||||
observations = output / (identifier + "-observations.json")
|
||||
consumer = "rejected" if checks == "negative" else checks
|
||||
argv = rust_command("vless_public", "uot::" + consumer)
|
||||
result = run_command(
|
||||
argv,
|
||||
cwd=CORE_DIR,
|
||||
timeout=240,
|
||||
env=dict(
|
||||
os.environ,
|
||||
VCORE_VLESS_INPUT=str(fixture),
|
||||
VCORE_UOT_OBSERVATIONS=str(observations),
|
||||
VCORE_CASE_EVENTS=str(
|
||||
output / (identifier + "-events.jsonl")
|
||||
),
|
||||
),
|
||||
)
|
||||
(output / (identifier + ".log")).write_text(
|
||||
redact(result.stdout.decode(errors="replace"))
|
||||
)
|
||||
observed = (
|
||||
json.loads(observations.read_text())
|
||||
if observations.is_file()
|
||||
else None
|
||||
)
|
||||
expected = expected_observation(consumer, via_socks5)
|
||||
from .protocol_evidence import read_events
|
||||
from .protocol_hysteria2_catalog import assertions_pass
|
||||
|
||||
good = (
|
||||
result.returncode == 0
|
||||
and result.cleanup
|
||||
and observed == expected
|
||||
and assertions_pass(
|
||||
read_events(
|
||||
output / (identifier + "-events.jsonl")
|
||||
),
|
||||
{("UOT-PUBLIC", consumer): 1},
|
||||
)
|
||||
)
|
||||
report["cases"].append(
|
||||
dict(
|
||||
case_id=identifier,
|
||||
command=argv,
|
||||
exit_code=result.returncode,
|
||||
command_cleanup=result.cleanup,
|
||||
observations=observed,
|
||||
listener_native_udp=False,
|
||||
status="PASS" if good else "FAIL",
|
||||
)
|
||||
)
|
||||
print(
|
||||
identifier + (": PASS" if good else ": FAIL"),
|
||||
flush=True,
|
||||
)
|
||||
if not good:
|
||||
raise RuntimeError("UoT public data failed")
|
||||
finally:
|
||||
for role, d in directories.items():
|
||||
if (d / "peer.log").is_file():
|
||||
(output / (role + ".log")).write_text(
|
||||
redact((d / "peer.log").read_text(errors="replace"))
|
||||
)
|
||||
report["status"] = "PASS"
|
||||
except BaseException as error:
|
||||
report["status"] = "FAIL"
|
||||
(output / "failure.log").write_text(redact(str(error)))
|
||||
raise
|
||||
finally:
|
||||
report["cleanup"] = all(
|
||||
p.get("joined") is True for p in report["isolation"].get("peers", [])
|
||||
)
|
||||
report["source_unchanged"] = same_source(report["source"], source_identity())
|
||||
if not report["cleanup"] or not report["source_unchanged"]:
|
||||
report["status"] = "FAIL"
|
||||
(output / "report.json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
if report["status"] != "PASS":
|
||||
raise RuntimeError("UoT source or cleanup failed")
|
||||
return report
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("--case", action="append")
|
||||
parser.add_argument("--via-socks5", action="store_true")
|
||||
parser.add_argument(
|
||||
"--checks", choices=("data", "negative", "group"), default="data"
|
||||
)
|
||||
parser.add_argument("--native", action="store_true")
|
||||
args = parser.parse_args()
|
||||
run(
|
||||
args.output,
|
||||
selected=args.case,
|
||||
via_socks5=args.via_socks5,
|
||||
checks=args.checks,
|
||||
native=args.native,
|
||||
)
|
||||
@@ -0,0 +1,247 @@
|
||||
"""Execute UoT gates and independently verify their raw evidence."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from .core_checks import validate_execution
|
||||
from .protocol_evidence import read_events, read_json
|
||||
from .protocol_hysteria2_catalog import assertions_pass
|
||||
from .protocol_inputs import redact
|
||||
from .protocol_integration_checks import envelope, runtime_pass
|
||||
from .protocol_security_acceptance import REPORTS, result, rust_command, vless_pass
|
||||
from .protocol_shadowtls_acceptance import source
|
||||
from .protocol_uot import expected_observation
|
||||
from .protocol_uot_catalog import LOCAL, MEMORY_EVENTS, commands, wire_cases
|
||||
|
||||
|
||||
def wire_pass(name, directory, report):
|
||||
selected = wire_cases(name)
|
||||
rows = report.get("cases", [])
|
||||
if [r.get("case_id") for r in rows] != [c[0] for c in selected]:
|
||||
return False
|
||||
via_socks5 = name in {"MIHOMO-SOCKS5", "MIHOMO-GROUPS"}
|
||||
if report.get("tcp_only_upstream") is not via_socks5:
|
||||
return False
|
||||
for row, (identifier, consumer) in zip(rows, selected, strict=True):
|
||||
if not (
|
||||
row.get("command") == rust_command("vless_public", "uot::" + consumer)
|
||||
and type(row.get("exit_code")) is int
|
||||
and row["exit_code"] == 0
|
||||
and row.get("command_cleanup") is True
|
||||
and row.get("listener_native_udp") is False
|
||||
and row.get("observations")
|
||||
== read_json(directory / (identifier + "-observations.json"))
|
||||
== expected_observation(consumer, via_socks5)
|
||||
and assertions_pass(
|
||||
read_events(directory / (identifier + "-events.jsonl")),
|
||||
{("UOT-PUBLIC", consumer): 1},
|
||||
)
|
||||
):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def local_pass(name, directory, run):
|
||||
expected = commands(name)
|
||||
rows = [r for r in run["commands"] if r["name"].startswith("UOT-" + name + "-")]
|
||||
if len(rows) != len(expected):
|
||||
return False
|
||||
events = []
|
||||
for index, (row, argv) in enumerate(zip(rows, expected, strict=True)):
|
||||
label = f"UOT-{name}-{index}"
|
||||
if row["name"] != label or row["command"] != [redact(v) for v in argv]:
|
||||
return False
|
||||
validate_execution(
|
||||
row["command"],
|
||||
(directory / row["log"]).read_text(),
|
||||
row["exit_code"],
|
||||
row["cleanup"],
|
||||
)
|
||||
path = directory / (label + "-events.jsonl")
|
||||
if path.exists():
|
||||
events += read_events(path)
|
||||
if name == "MEMORY":
|
||||
return assertions_pass(
|
||||
[e for e in events if e.get("suite", "").startswith("UOT-")], MEMORY_EVENTS
|
||||
)
|
||||
if name == "FEATURES":
|
||||
return assertions_pass(
|
||||
[e for e in events if e.get("suite", "").startswith("UOT-")],
|
||||
MEMORY_EVENTS | {("UOT-CFG", "strict_v2"): 2},
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
ANYTLS = dict(selected=["FINGERPRINT-ANYTLS"], client_fingerprint="none")
|
||||
|
||||
|
||||
def group_pass(name, directory, run, peers):
|
||||
if name in LOCAL:
|
||||
return local_pass(name, directory, run)
|
||||
root = directory / name.lower()
|
||||
digest = run["container_image"]["digest"]
|
||||
if name == "ANYTLS":
|
||||
report = read_json(root / REPORTS["vless"])
|
||||
return envelope(report, peers, source(run), digest) and vless_pass(
|
||||
ANYTLS, report, root
|
||||
)
|
||||
if name == "BARE-SS":
|
||||
report = read_json(root / "integration-suite.json")
|
||||
rows = report.get("cases", [])
|
||||
return (
|
||||
envelope(report, peers, source(run), digest)
|
||||
and len(rows) == 1
|
||||
and runtime_pass("INTEGRATION-SS-ALGORITHMS", rows[0], root)
|
||||
)
|
||||
report = read_json(root / "report.json")
|
||||
return envelope(
|
||||
report,
|
||||
peers,
|
||||
source(run),
|
||||
digest,
|
||||
single="SS" if name == "NATIVE-UNSUPPORTED" else "M",
|
||||
) and wire_pass(name, root, report)
|
||||
|
||||
|
||||
def prepare(output, *, native):
|
||||
from .native_release import download_native
|
||||
from .protocol_hysteria2_acceptance import prepare as mihomo
|
||||
|
||||
supplied = mihomo(output, {"M"})
|
||||
artifact = (
|
||||
download_native("SS", output / "binaries/SS", "linux-arm64", defer_version=True)
|
||||
if native
|
||||
else None
|
||||
)
|
||||
return supplied, artifact
|
||||
|
||||
|
||||
def execute(cases, run, output, results):
|
||||
from .protocol_containers import frozen_image
|
||||
from .protocol_harness import _command
|
||||
from .protocol_integration_suite import run as integration
|
||||
from .protocol_uot import run as uot
|
||||
from .protocol_vless_container import run as vless
|
||||
|
||||
selected = {c["case_id"].removeprefix("UOT-"): c for c in cases}
|
||||
peers = {}
|
||||
|
||||
def save(name):
|
||||
good = group_pass(name, output, run, peers)
|
||||
case = selected[name]
|
||||
results[case["case_id"]] = result(case, good, good)
|
||||
print(case["case_id"] + (": PASS" if good else ": FAIL"), flush=True)
|
||||
if not good:
|
||||
raise RuntimeError("UoT gate failed: " + name)
|
||||
|
||||
try:
|
||||
for name in selected:
|
||||
if name not in LOCAL:
|
||||
continue
|
||||
for i, argv in enumerate(commands(name)):
|
||||
label = f"UOT-{name}-{i}"
|
||||
completed = _command(
|
||||
run,
|
||||
output,
|
||||
label,
|
||||
argv,
|
||||
3600,
|
||||
events=output / (label + "-events.jsonl"),
|
||||
)
|
||||
validate_execution(
|
||||
argv,
|
||||
completed.stdout.decode(errors="replace"),
|
||||
completed.returncode,
|
||||
completed.cleanup,
|
||||
)
|
||||
save(name)
|
||||
if set(selected) <= LOCAL:
|
||||
return
|
||||
with frozen_image(output / "image-pull.log") as image:
|
||||
run["container_image"] = image
|
||||
supplied, artifact = prepare(
|
||||
output, native="NATIVE-UNSUPPORTED" in selected
|
||||
)
|
||||
peers.update({k: v[1] for k, v in supplied.items()})
|
||||
if artifact is not None:
|
||||
peers["SS"] = artifact.identity
|
||||
for name in selected:
|
||||
if name in LOCAL:
|
||||
continue
|
||||
root = output / name.lower()
|
||||
if name.startswith("MIHOMO-"):
|
||||
uot(
|
||||
root,
|
||||
via_socks5=name in {"MIHOMO-SOCKS5", "MIHOMO-GROUPS"},
|
||||
checks="negative"
|
||||
if name == "MIHOMO-NEGATIVE"
|
||||
else "group"
|
||||
if name == "MIHOMO-GROUPS"
|
||||
else "data",
|
||||
supplied=supplied["M"],
|
||||
image=image,
|
||||
)
|
||||
elif name == "NATIVE-UNSUPPORTED":
|
||||
uot(
|
||||
root,
|
||||
native=True,
|
||||
checks="negative",
|
||||
supplied=(artifact.binary, artifact.identity),
|
||||
image=image,
|
||||
)
|
||||
elif name == "ANYTLS":
|
||||
vless(root, supplied=supplied, **ANYTLS)
|
||||
elif name == "BARE-SS":
|
||||
integration(
|
||||
root, ["INTEGRATION-SS-ALGORITHMS"], supplied=supplied["M"]
|
||||
)
|
||||
else:
|
||||
raise ValueError("unknown UoT gate")
|
||||
save(name)
|
||||
finally:
|
||||
(output / "peers.json").write_text(json.dumps(peers, indent=2) + "\n")
|
||||
|
||||
|
||||
def check(directory, cases, run, results, peers, paths):
|
||||
if not {"cases.json", "peers.json", "resources.jsonl", "summary.md"} <= set(paths):
|
||||
raise ValueError("missing UoT evidence")
|
||||
expected = [
|
||||
f"UOT-{c['case_id'].removeprefix('UOT-')}-{i}"
|
||||
for c in cases
|
||||
for i, _ in enumerate(commands(c["case_id"].removeprefix("UOT-")))
|
||||
]
|
||||
actual = [r["name"] for r in run["commands"]]
|
||||
if (
|
||||
len(actual) != len(set(actual))
|
||||
or set(actual) != set(expected)
|
||||
or set(peers) != {"M", "SS"}
|
||||
):
|
||||
raise ValueError("UoT command or peer selection differs")
|
||||
for case in cases:
|
||||
name = case["case_id"].removeprefix("UOT-")
|
||||
if not group_pass(name, directory, run, peers):
|
||||
raise ValueError("UoT raw evidence failed: " + name)
|
||||
print("UOT coverage: PASS (all required groups; device delivery separate)")
|
||||
|
||||
|
||||
def preflight(output):
|
||||
from .protocol_containers import command, frozen_image
|
||||
|
||||
command("system", "status")
|
||||
with frozen_image(output / "image-pull.log"):
|
||||
supplied, artifact = prepare(output, native=True)
|
||||
(output / "peers.json").write_text(
|
||||
json.dumps(
|
||||
dict(
|
||||
scope="download-only",
|
||||
wire_acceptance="NOT RUN",
|
||||
peers={
|
||||
**{k: v[1] for k, v in supplied.items()},
|
||||
"SS": artifact.identity,
|
||||
},
|
||||
),
|
||||
indent=2,
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
@@ -0,0 +1,149 @@
|
||||
"""SS UoT v2 gates, reconstructed from existing runner evidence conventions."""
|
||||
|
||||
from .protocol_completion_peers import CASES
|
||||
from .protocol_shadowtls_catalog import commands as shared_commands
|
||||
|
||||
UOT_CASES = tuple(c for c in CASES if c.uot)
|
||||
GATES = {
|
||||
"MEMORY": "datagrams",
|
||||
"FEATURES": "configuration",
|
||||
"QUALITY": "regression",
|
||||
"PLATFORMS": "regression",
|
||||
"MIHOMO-DIRECT": "interop",
|
||||
"MIHOMO-SOCKS5": "interop",
|
||||
"MIHOMO-GROUPS": "interop",
|
||||
"MIHOMO-NEGATIVE": "interop",
|
||||
"NATIVE-UNSUPPORTED": "interop",
|
||||
"ANYTLS": "regression",
|
||||
"BARE-SS": "regression",
|
||||
}
|
||||
LOCAL = {"MEMORY", "FEATURES", "QUALITY", "PLATFORMS"}
|
||||
MEMORY_EVENTS = {
|
||||
("UOT-CFG", "strict_v2"): 1,
|
||||
**{
|
||||
("UOT-SS", n): 1
|
||||
for n in (
|
||||
"first_packet",
|
||||
"never_sent",
|
||||
"deadline",
|
||||
"cancel_write",
|
||||
"budget_read_cancel",
|
||||
"dns",
|
||||
"stop_full_queue",
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def definitions():
|
||||
return [
|
||||
dict(
|
||||
case_id="UOT-" + name,
|
||||
stage="UOT",
|
||||
substage="UOT." + category,
|
||||
required=True,
|
||||
row_ids=[],
|
||||
protocol="ss",
|
||||
network="tcp",
|
||||
security="ss2022/optional-v3",
|
||||
udp_codec="uot-v2",
|
||||
field_values={},
|
||||
outer_family="IPv4",
|
||||
inner_family="IPv4/IPv6/domain",
|
||||
target_type="memory-only/build" if name in LOCAL else "isolated origin",
|
||||
upstream_graph="controlled-stream/optional-socks5-or-select",
|
||||
peer_kind="unit"
|
||||
if name in LOCAL
|
||||
else "SS"
|
||||
if name == "NATIVE-UNSUPPORTED"
|
||||
else "M",
|
||||
peer_config={"group": name},
|
||||
gap_source=None,
|
||||
expected_observation=["UOT-" + name],
|
||||
required_evidence=["command", "structured-assertions", "cleanup"]
|
||||
+ ([] if name in LOCAL else ["peer-identity", "isolated-origins"]),
|
||||
prerequisites=["rust-toolchain"]
|
||||
if name in LOCAL
|
||||
else ["owned-host-only-container-network", "official-latest-peer"],
|
||||
runner="uot-gate",
|
||||
timeout_seconds=3600,
|
||||
)
|
||||
for name, category in GATES.items()
|
||||
]
|
||||
|
||||
|
||||
def wire_cases(name):
|
||||
if name in {"MIHOMO-DIRECT", "MIHOMO-SOCKS5", "MIHOMO-GROUPS"}:
|
||||
return [
|
||||
(c.identifier, "group" if name == "MIHOMO-GROUPS" else "data")
|
||||
for c in UOT_CASES
|
||||
]
|
||||
if name == "NATIVE-UNSUPPORTED":
|
||||
return [
|
||||
(c.identifier + "-unsupported", "rejected")
|
||||
for c in UOT_CASES
|
||||
if not c.shadow_tls
|
||||
]
|
||||
if name == "MIHOMO-NEGATIVE":
|
||||
return [
|
||||
(c.identifier + "-" + failure, "rejected")
|
||||
for c in UOT_CASES
|
||||
for failure in (("key", "identity") if c.shadow_tls else ("key",))
|
||||
]
|
||||
raise ValueError("unknown UoT wire group")
|
||||
|
||||
|
||||
def commands(name):
|
||||
cargo = ["cargo", "test", "--locked", "--all-features"]
|
||||
if name == "MEMORY":
|
||||
return [
|
||||
cargo
|
||||
+ [
|
||||
arg
|
||||
for target in (
|
||||
"uot_config",
|
||||
"shadowsocks_uot",
|
||||
"shadowsocks_backpressure",
|
||||
)
|
||||
for arg in ("--test", target)
|
||||
],
|
||||
cargo + ["--lib", "outbound::uot::"],
|
||||
cargo + ["--lib", "outbound::anytls::"],
|
||||
]
|
||||
if name == "FEATURES":
|
||||
return [
|
||||
["cargo", "check", "--locked", "--no-default-features"]
|
||||
+ (["--features", feature] if feature else [])
|
||||
for feature in (
|
||||
"",
|
||||
"outbound-shadowsocks",
|
||||
"outbound-anytls",
|
||||
"outbound-shadowsocks,shadow-tls-v3",
|
||||
)
|
||||
] + [
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--no-default-features",
|
||||
"--features",
|
||||
"interop-test",
|
||||
"--test",
|
||||
"uot_config",
|
||||
],
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--no-default-features",
|
||||
"--features",
|
||||
"outbound-shadowsocks,interop-test",
|
||||
"--test",
|
||||
"uot_config",
|
||||
"--test",
|
||||
"shadowsocks_uot",
|
||||
],
|
||||
["cargo", "test", "--locked", "--test", "feature_foundations"],
|
||||
cargo + ["--all-targets", "--no-run"],
|
||||
]
|
||||
return shared_commands(name) if name in {"QUALITY", "PLATFORMS"} else []
|
||||
@@ -24,7 +24,7 @@ from .protocol_vmess_public import events_pass, node_config
|
||||
ALL_CASES = CASES | PUBLIC_CASES
|
||||
|
||||
|
||||
def run(output: Path, selected=None, *, preflight_only=False):
|
||||
def run(output: Path, selected=None, *, preflight_only=False, supplied=None):
|
||||
selected = list(ALL_CASES) if selected is None else selected
|
||||
if (
|
||||
not selected
|
||||
@@ -54,7 +54,10 @@ def run(output: Path, selected=None, *, preflight_only=False):
|
||||
artifacts = {}
|
||||
for kind in sorted({ALL_CASES[case][0] for case in selected} | {"M"}):
|
||||
directory = output / "binaries" / kind
|
||||
if kind == "M":
|
||||
if supplied is not None and kind in supplied:
|
||||
binary, identity = supplied[kind]
|
||||
artifacts[kind] = PeerArtifact(binary, identity)
|
||||
elif kind == "M":
|
||||
identity = {}
|
||||
binary = download_mihomo(
|
||||
"linux-arm64", directory=directory, identity=identity
|
||||
@@ -65,7 +68,7 @@ def run(output: Path, selected=None, *, preflight_only=False):
|
||||
kind, directory, "linux-arm64", defer_version=True
|
||||
)
|
||||
report["peers"][kind] = artifacts[kind].identity
|
||||
lab = ContainerLab(report["isolation"])
|
||||
lab = ContainerLab(report["isolation"], mtu=1500)
|
||||
report["phase"] = "build"
|
||||
built = run_command(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user