Files
Vole/scripts/src/vcore_scripts/checks.py
T
yiguodev 608a8f255c feat: add client protocols, TLS capabilities, and platform validation (#1)
* chore: download latest official mihomo for interop tests

* test: capture N0 baseline and protocol feasibility probes

* docs: record N0 hybrid REALITY fork verification

* test: verify N0 controlled Hysteria2 auth and streams

Add an isolated Quinn adapter over existing DIRECT and SOCKS5 datagrams, bounded queues, protect rejection probes, and official latest peer fixtures. Record passing auth/TCP checks and the native Hysteria half-close failure separately. N0 remains incomplete; production sources and dependency locks are unchanged.

* test: validate N0 native QUIC hopping and XHTTP H3

Keep the probes isolated from production. Verify one-state Hysteria hopping, protected rebind rejection, Xray H3 entry and existing HY2 regressions. Set only the owned Linux peer MTU to avoid Initial-packet EMSGSIZE; retain native half-close failures as separate gates.

* fix: align XHTTP shutdown with Mihomo connection close

* test: verify N0 supplied-stream transport interfaces

Add isolated TLS, ordinary WebSocket and gRPC probes with owned I/O, bounded buffers and cancellation barriers.

Match Mihomo close behavior: preserve TLS/WS reads, distinguish clean WS underlay EOF from truncation, and close both gRPC directions. Use separate official SOCKS5 peers to avoid fixture loop detection.

Record 12 Debug/Release tests, 42 official Mihomo checks, dependency audits and Apple/Android compile checks. Keep production dependencies, third-party sources and remaining N0 gates unchanged.

* fix: upgrade h2 and retain completed responses after reset

* chore: use the current OneXray rustls fork origin

* chore: adopt published rustls 0.23.45 and official TLS binding

* chore: refresh N1 foundation and spike dependencies

* feat: validate next-protocol field and combination catalogs

* feat: share immutable TLS policies and bounded close semantics

* feat: add shared stream transports and decouple XUDP framing

* feat: add controlled datagram foundations and N1 acceptance harness

* chore: finalize N1 with verified x25519 dependency

* chore: publish N1 against the rustls release branch

* feat: add bounded Trojan request and datagram codecs

* feat: connect Trojan TLS TCP and UDP through the runtime

* feat: support Trojan WebSocket and duplex gRPC transports

* feat: enable Trojan and complete N2 consumer acceptance

* feat(vmess): add bounded AEAD header and body codecs

* fix(vmess): align close acceptance with Mihomo transports

* feat(vmess): add UDP codecs and isolated peer comparisons

* feat(vmess): complete public runtime and N3 acceptance

* docs: bind N3 acceptance and refresh validation guidance

* feat(vless): complete N4 transports, Vision and UDP support

Extract VLESS assembly, add plain/TLS stream transports, HTTPUpgrade, node-owned gRPC pooling, mTLS and classic REALITY, and implement Vision through public TLS record boundaries. Preserve XHTTP and the XUDP default while adding raw and packetaddr.

Complete 145 required groups and 39 field rows against isolated latest official peers, with 160 lifecycle/resource rounds, independent coverage and Apple/Android release builds. Preserve the three explicit WS/REALITY layered close comparisons and historical failures in the acceptance report. No third-party or dependency-lock changes.

* feat(vless): complete N5 XHTTP and sing-mux support

Add H1/H2/H3 request fields, independent download security and pools, bounded packet-up batching, and h2mux/smux/yamux over controlled transports.

Keep Mihomo-aligned close and path semantics, node-owned shutdown barriers, and isolated official-peer fixtures including the approved Caddy mTLS gateway.

Validate 416 required groups, 57 fields, 112 two-leg security checks, 240 lifecycle/resource cycles, independent coverage, and Apple/Android release builds. Record native-peer gaps and leave N6-N10, devices, CI, and release gates separate.

* feat: integrate boring TLS profiles and retire rustls fork

* test(tls): freeze selected fingerprint reference baseline

* docs(tls): record selected-profile library acceptance

* feat(tls): integrate selected client fingerprints and REALITY profiles

* feat(tls): complete selected fingerprint CF5 acceptance

* feat(hysteria2): complete N6 client support and acceptance

Implement Hysteria2 over official Quinn/h3/rustls and shared controlled IO, including TCP/UDP, bandwidth pacing, Salamander, port hopping, upstream snapshots and synchronous Stop.

Keep old-path receives active for the full bounded handover window, preserve independent reader wakeups, and require the exact nested TCP evidence assertions.

Validate one frozen N6 run: 36 required groups, 20 field rows, native Mihomo/Hysteria peers, H3 regression, 40 lifecycle rounds and Apple/Android production builds. Record independent coverage, artifact hashes and native-peer limitations.

* test(tls): record N7 hybrid REALITY prerequisite evidence

Preserve the locked classic-only API failure and distinguish the locally accepted boring hybrid extension from pending VCore S03/D16 integration. Record wrapper feasibility and publication boundaries without changing production configuration or dependencies.

* feat(vless): support explicitly required hybrid REALITY

* feat(crypto): wrap official BLAKE3 binary-context derivation

* feat(vless): implement authenticated Encryption wire transport

* feat(vless): enable authenticated Encryption across public transports

* build(tls): pin the authenticated ShadowTLS ClientHello hook

* feat(vless): add authenticated JLS transport security

Pin the separately approved boring JLS revision and expose strict main/download credentials under schema 24. Preserve native CertificateVerify and Finished, cancellation, and controlled IO ownership. Accept the JLS field slice with 122 isolated cases, 80 lifecycle/resource cycles, and Apple/Android release libraries; keep broader N7 gates separate.

* docs(n7): reconcile current JLS acceptance progress

* chore(vless): retire Restls while retaining JLS

* feat(vless): complete N7 static ECH and security combinations

Add static ECH for VLESS main and XHTTP download legs using existing TLS backends and official Rust HPKE. Keep Invoke v5 and advance the internal schema to revision 27.

Accept the narrowed N7 scope with 43 required groups, 11 fields, 301 isolated native cases, 240 lifecycle/resource rounds, and Apple/Android release builds. Record frozen inputs, 470 container cleanups, explicit upstream comparison gaps, and prior failed runs in docs/acceptance/next-protocols/N7.md.

* chore(protocols): retire WireGuard scope and foundations

* test: complete N9 protocol integration and resource gates

* build: add N10 production artifact evidence gates

* fix: restore Windows snapshot encoding and fail-closed delivery CI

* fix: use native ARM64 LLVM assembly and scoped delivery CI

* build: keep delivery lockfile bytes stable across platforms

* fix: preserve production guard lifecycle and isolate CI feature checks

* build: adopt released boring and registry shadowsocks

* ci: use release-oriented workflow names

* docs: consolidate contracts and streamline test tooling

Merge current protocol and platform contracts, remove milestone reports and obsolete spikes, and share core checks between local development and CI. Preserve all 884 executable case definitions and unique legacy assertions.

Validation: core Debug/Release, feature checks, Clippy, netstack, offline script tests, formatting and documentation links passed locally. Container interop smoke attempts failed during official peer downloads; business paths remain NOT RUN.

* test: replace milestone names with capability-based validation

Rename protocol and fingerprint suites, fixtures, and evidence identifiers by capability. Preserve acceptance cases and golden wire data while documenting reference, wire, and interoperability evidence separately.

* fix: address review findings and stabilize core CI

Flush accepted gRPC/H2 data through the supplied IO before reset, and wait for pending smux writes before FIN. Sanitize AnyTLS peer failures, reject XHTTP userinfo, and remove stale Android delivery artifacts.

Close container log capture even when inventory fails. Keep legacy host suites blocked before resource acquisition.

Separate Shadowsocks adapter codec checks from upstream strict server acceptance. Lock the random empty-request zero-padding failure with deterministic negative and positive fixtures, without changing the dependency or production behavior.

* test: isolate delivery fixture from Windows home lookup

* test: preserve UDP socket semantics during peer teardown

The memory peer treated its counterpart closing an mpsc channel as a local UDP BrokenPipe. That could terminate Quinn endpoint IO without waking a pending wait_idle, despite all four datagrams and CONNECTION_CLOSE having arrived.

Keep a closed peer link silent and late sends best-effort, add a deterministic fixture regression, and preserve the existing data and shutdown deadlines. Debug/Release, Clippy, and 300 consecutive regression iterations pass.

* fix: drain XHTTP uploads before releasing connection drivers

* fix: enforce lazy setup deadlines and safe delivery paths

Check the original deadline before accepting ready gRPC/H2 headers or sing-mux status, without limiting established reads. Reject symlinks and Windows reparse points in every delivery output path before filesystem mutations. Add deterministic memory and temporary-filesystem regressions.

* test: join XHTTP H3 peer tasks during cleanup

Quinn retains closed connections for three probe timeouts, so a delayed handshake can legitimately exceed the fixture's two-second wait_idle budget. Own, abort, and join the passive peer tasks after upload and client shutdown instead. Preserve upload integrity and client close bounds, and cover delayed handshakes in both streaming modes.
2026-09-28 12:50:01 +08:00

343 lines
12 KiB
Python

from __future__ import annotations
import json
import platform
import shutil
import subprocess
import tempfile
from pathlib import Path
from typing import Any
CORE_DIR = Path(__file__).resolve().parents[3]
CRATES_IO_SOURCES = {
"registry+https://github.com/rust-lang/crates.io-index",
"registry+https://index.crates.io/",
}
BORING_REVISION = "d5a5d41850886aef5b269015130ee6d6eb2129ba"
BORING_GIT_SOURCE = (
f"git+https://github.com/OneXray/boring?branch=release#{BORING_REVISION}"
)
_C_SOURCE = r"""#include "vcore.h"
int main(void) {
char *response = VCoreInvoke(
"{\"apiVersion\":5,\"method\":\"version\",\"payload\":{}}");
VCoreFree(response);
VCoreFree((char *)0);
return 0;
}
"""
_CPP_SOURCE = r"""#include "vcore.h"
int main() {
char *response = VCoreInvoke(
"{\"apiVersion\":5,\"method\":\"version\",\"payload\":{}}");
VCoreFree(response);
VCoreFree(nullptr);
return 0;
}
"""
def check_c_header() -> None:
if platform.system() == "Darwin":
c_compiler = ["xcrun", "clang"]
cpp_compiler = ["xcrun", "clang++"]
else:
clang = shutil.which("clang")
clang_cpp = shutil.which("clang++")
if not clang or not clang_cpp:
raise RuntimeError("clang and clang++ are required to check vcore.h")
c_compiler = [clang]
cpp_compiler = [clang_cpp]
with tempfile.TemporaryDirectory(prefix="vcore-header-") as directory:
root = Path(directory)
c_source = root / "header.c"
cpp_source = root / "header.cc"
c_source.write_text(_C_SOURCE, encoding="utf-8")
cpp_source.write_text(_CPP_SOURCE, encoding="utf-8")
subprocess.run(
[
*c_compiler,
"-std=c11",
"-Wall",
"-Wextra",
"-Werror",
"-fsyntax-only",
"-I",
str(CORE_DIR / "include"),
str(c_source),
],
check=True,
)
subprocess.run(
[
*cpp_compiler,
"-std=c++17",
"-Wall",
"-Wextra",
"-Werror",
"-fsyntax-only",
"-I",
str(CORE_DIR / "include"),
str(cpp_source),
],
check=True,
)
def _shadowsocks_aws_lc_errors(metadata: dict[str, Any]) -> list[str]:
"""Allow only the pinned official SS -> crypto -> AWS-LC dependency chain."""
packages = metadata["packages"]
aws = [p for p in packages if p["name"].lower().startswith("aws-lc")]
if not aws:
return []
errors: list[str] = []
allowed: dict[str, dict[str, Any]] = {}
expected = {
"shadowsocks": ("1.25.0", CRATES_IO_SOURCES),
"shadowsocks-crypto": ("0.8.0", CRATES_IO_SOURCES),
"aws-lc-rs": (None, CRATES_IO_SOURCES),
"aws-lc-sys": (None, CRATES_IO_SOURCES),
}
for name, (version, sources) in expected.items():
matches = [p for p in packages if p["name"] == name]
if (
len(matches) != 1
or (version is not None and matches[0]["version"] != version)
or matches[0].get("source") not in sources
):
errors.append(
f"AWS-LC package is forbidden without the official {name} graph"
)
else:
allowed[name] = matches[0]
for package in aws:
if package["name"] not in {"aws-lc-rs", "aws-lc-sys"}:
errors.append(f"AWS-LC package is forbidden: {package['name']}")
if len(allowed) != len(expected):
return errors
nodes = {n["id"]: n for n in metadata["resolve"]["nodes"]}
parents: dict[str, set[str]] = {}
for node in nodes.values():
for dependency in node.get("deps", []):
parents.setdefault(dependency["pkg"], set()).add(node["id"])
for child, parent in (
("shadowsocks-crypto", "shadowsocks"),
("aws-lc-rs", "shadowsocks-crypto"),
("aws-lc-sys", "aws-lc-rs"),
):
child_id = allowed[child]["id"]
if child_id not in nodes or parents.get(child_id) != {allowed[parent]["id"]}:
errors.append(
f"AWS-LC exception requires {child} to be used only by {parent}"
)
for name, required in (
("shadowsocks", {"aead-cipher-2022"}),
("shadowsocks-crypto", {"v2", "aws-lc"}),
):
features = set(nodes.get(allowed[name]["id"], {}).get("features", []))
if not required <= features:
errors.append(f"AWS-LC exception requires the SS 2022 features of {name}")
if features & {"aead-cipher-2022-extra", "v2-extra"}:
errors.append(
f"only the three standard SS 2022 ciphers are allowed: {name}"
)
return errors
def _tls_dependency_errors(metadata: dict[str, Any]) -> list[str]:
packages = metadata["packages"]
nodes = metadata["resolve"]["nodes"]
errors: list[str] = []
def named(name: str) -> list[dict[str, Any]]:
return [package for package in packages if package["name"] == name]
def require_single(name: str, version: str) -> dict[str, Any] | None:
matches = named(name)
resolved = (
", ".join(
sorted(
f"{package['version']} ({package.get('source') or 'path'})"
for package in matches
)
)
or "none"
)
if len(matches) != 1 or matches[0]["version"] != version:
errors.append(
f"expected exactly one {name} {version}; resolved: {resolved}"
)
return None
return matches[0]
rustls = require_single("rustls", "0.23.45")
tokio_rustls = require_single("tokio-rustls", "0.26.5")
ring = named("ring")
if len(ring) != 1:
resolved = ", ".join(sorted(package["version"] for package in ring)) or "none"
errors.append(
f"expected exactly one ring provider package; resolved: {resolved}"
)
else:
ring_source = ring[0].get("source") or ""
if ring_source not in CRATES_IO_SOURCES:
resolved = ring_source or "path"
errors.append(f"ring must come from crates.io; resolved source: {resolved}")
if rustls is not None:
rustls_source = rustls.get("source") or ""
if rustls_source not in CRATES_IO_SOURCES:
errors.append(
"rustls must come from crates.io; "
f"resolved source: {rustls_source or 'path'}"
)
if tokio_rustls is not None:
source = tokio_rustls.get("source") or ""
if source not in CRATES_IO_SOURCES:
errors.append(
"tokio-rustls must be the crates.io release; "
f"resolved source: {source or 'path'}"
)
for package in packages:
source = (package.get("source") or "").lower()
if "watfaq" in source:
errors.append(
f"Watfaq dependency is forbidden: {package['name']} "
f"{package['version']} ({source})"
)
if rustls is not None:
rustls_node = next((node for node in nodes if node["id"] == rustls["id"]), None)
if rustls_node is None:
errors.append("rustls is missing from the resolved dependency graph")
else:
features = set(rustls_node["features"])
missing = {"ring"} - features
forbidden = {"reality", "aws_lc_rs", "fips"} & features
if missing:
errors.append(
f"rustls is missing required features: {', '.join(sorted(missing))}"
)
if forbidden:
errors.append(
"rustls enables forbidden provider features: "
f"{', '.join(sorted(forbidden))}"
)
native = {}
node_by_id = {node["id"]: node for node in nodes}
hpke = require_single("hpke", "0.14.1")
if hpke is not None:
if hpke.get("source") not in CRATES_IO_SOURCES:
errors.append("hpke must be the unmodified crates.io release")
hpke_node = node_by_id.get(hpke["id"])
if hpke_node is None or set(hpke_node.get("features", [])) != {
"alloc",
"aes",
"chacha",
"x25519",
"hkdfsha2",
}:
errors.append("hpke must use only the approved ECH algorithms")
for name, required in (
("boring", {"reality", "client-fingerprint", "shadow-tls-v3", "jls"}),
("boring-sys", {"reality", "shadow-tls-v3", "jls"}),
("tokio-boring", set()),
):
package = require_single(name, "5.2.0")
if package is None:
continue
native[name] = package
if package.get("source") != BORING_GIT_SOURCE:
errors.append(
f"{name} must use the approved boring release branch "
"and locked revision"
)
node = node_by_id.get(package["id"])
if node is None:
errors.append(f"{name} is missing from the resolved graph")
continue
features = set(node["features"])
if not required <= features:
errors.append(f"{name} is missing required TLS features")
if features & {
"fips",
"fips-precompiled",
"rpk",
"pq-experimental",
"restls",
}:
errors.append(f"{name} enables an unapproved native TLS mode")
for parent, children in (
("boring", {"boring-sys"}),
("tokio-boring", {"boring", "boring-sys"}),
):
if parent in native:
deps = {
dep["pkg"]
for dep in node_by_id.get(native[parent]["id"], {}).get("deps", [])
}
for child in children:
if child not in native or native[child]["id"] not in deps:
errors.append(f"{parent} must directly use the locked {child}")
errors.extend(_shadowsocks_aws_lc_errors(metadata))
return errors
def check_tls_dependencies() -> None:
result = subprocess.run(
[
"cargo",
"metadata",
"--manifest-path",
str(CORE_DIR / "Cargo.toml"),
"--locked",
"--all-features",
"--format-version",
"1",
],
cwd=CORE_DIR,
check=True,
stdout=subprocess.PIPE,
text=True,
encoding="utf-8",
)
metadata = json.loads(result.stdout)
errors = _tls_dependency_errors(metadata)
if errors:
raise RuntimeError(
"\n".join(f"TLS dependency check failed: {error}" for error in errors)
)
ring = next(
package for package in metadata["packages"] if package["name"] == "ring"
)
rustls = next(
package for package in metadata["packages"] if package["name"] == "rustls"
)
print("TLS dependency check passed:")
print(f"- one official crates.io rustls {rustls['version']}")
print("- one official tokio-rustls 0.26.5")
print("- one official hpke 0.14.1 with the approved static ECH algorithms")
print(
"- one boring/boring-sys/tokio-boring 5.2.0 release branch "
f"@ {BORING_REVISION[:12]}"
)
print(f"- one registry ring {ring['version']} provider")
print(
"- unprofiled TLS/QUIC use rustls + ring; REALITY/named profiles use BoringSSL"
)
print("- no Watfaq, second rustls source or rustls REALITY backend")
if any(p["name"] == "aws-lc-rs" for p in metadata["packages"]):
print("- AWS-LC is restricted to the pinned official Shadowsocks 2022 chain")
else:
print("- no AWS-LC packages")