fork: security=tls (self-signed + pinnedPeerCertSha256) becomes the default hop transport

reverse-over-REALITY is broken on xray >= 26.7 (Rvs control channel never
registers; XTLS/Xray-core #6242/#6248 family). Verified loopback e2e with
hub-generated configs on 26.11.9<->26.11.9 and 26.11.9<->26.7.28: portal
entry-* -> reverse mux -> router-admin redirect = HTTP 200 over pinned TLS.

- hub: OWRT_REMOTE_TRANSPORT=tls|reality|none (default tls); generates
  self-signed cert (openssl) + exposes pin; serves tls streamSettings.
- agent: uci tls_sni/tls_pin, validation, tls branch in render_client_config.
- CGI: reality_short_id/tls_sni/tls_pin fields; uci config lines extended.
- docs: REALITY_TRANSPORT.md extended with the bisect results and pitfalls
  (freedom finalRules for reverse egress, bridge registers ~2s late,
  legacy reverse objects removed).
This commit is contained in:
cyril committed 2026-11-22 12:28:43 +03:00
1 parent d482ed97c4
commit 05972f8c24
6 files changed
+151 -11

No files matched your search

+91 -5
View File
@@ -119,8 +119,17 @@ DEFAULT_VLESS_PORT = int(os.environ.get("OWRT_REMOTE_VLESS_PORT", "8443"))
# LuCI credentials and logs travel in cleartext inside that hop. This fork wraps
# it in VLESS+Reality: a real TLS handshake camouflaged against a public dest,
# no CA-issued certificates, no renewal. Per-router UUIDs still authenticate.
# Set OWRT_REMOTE_TRANSPORT=none to fall back to upstream behavior.
TRANSPORT_MODE = os.environ.get("OWRT_REMOTE_TRANSPORT", "reality").strip().lower()
# OWRT_REMOTE_TRANSPORT: tls (default) | reality | none.
# tls - self-signed hub cert + pinnedPeerCertSha256 on the router.
# Works with the modern tag-form VLESS reverse on xray >= 26.5.
# reality - REALITY camouflage. NOTE: tag-form reverse (Rvs control channel)
# does NOT register over REALITY on xray 26.7.28/26.11.9
# (XTLS/Xray-core #6242/#6248 family); verified broken in e2e
# 22.11.2026. The hop itself authenticates fine, so keep this
# switch ready for when upstream fixes reverse-over-REALITY.
# none - upstream behavior (cleartext hop).
TRANSPORT_MODE = os.environ.get("OWRT_REMOTE_TRANSPORT", "tls").strip().lower()
TLS_SNI = os.environ.get("OWRT_REMOTE_TLS_SNI", "www.microsoft.com").strip()
# NOTE: do NOT default to www.microsoft.com — Microsoft now serves post-quantum
# (ML-DSA) cert chains and REALITY cannot re-sign them; the handshake silently
# falls back to passthrough ("received real certificate"). Verified working
@@ -4664,17 +4673,56 @@ def generate_reality_profile():
}
def generate_tls_profile():
# Self-signed cert via the openssl CLI (stdlib cannot sign). The router
# pins the leaf certificate hash (pinnedPeerCertSha256); allowInsecure
# was removed from xray >= 26.x, pinning is the supported replacement.
import hashlib
binary = shutil.which("openssl") or ""
if not binary:
raise RuntimeError("openssl not found for TLS transport generation")
with tempfile.TemporaryDirectory() as tmp:
crt = os.path.join(tmp, "hub.crt")
key = os.path.join(tmp, "hub.key")
result = subprocess.run(
[binary, "req", "-x509", "-newkey", "rsa:2048", "-nodes", "-days", "3650",
"-subj", f"/CN={TLS_SNI}", "-addext", f"subjectAltName=DNS:{TLS_SNI}",
"-keyout", key, "-out", crt],
text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=60, check=False,
)
if result.returncode != 0:
raise RuntimeError(f"openssl cert generation failed: {(result.stderr or '').strip()[:300]}")
cert_pem = open(crt, encoding="utf-8").read()
key_pem = open(key, encoding="utf-8").read()
der = subprocess.run(
[binary, "x509", "-in", crt, "-outform", "der"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=30, check=True,
).stdout
return {
"mode": "tls",
"serverName": TLS_SNI,
"certificate": cert_pem,
"key": key_pem,
"pin": hashlib.sha256(der).hexdigest(),
"fingerprint": "chrome",
}
def transport_profile():
if TRANSPORT_MODE != "reality":
if TRANSPORT_MODE not in ("reality", "tls"):
return {"mode": "none"}
if TRANSPORT_FILE.exists():
try:
data = json.loads(TRANSPORT_FILE.read_text(encoding="utf-8"))
if data.get("mode") == "reality" and data.get("privateKey") and data.get("publicKey"):
return data
if TRANSPORT_MODE == "reality":
return data
if data.get("mode") == "tls" and data.get("certificate") and data.get("key") and data.get("pin"):
if TRANSPORT_MODE == "tls":
return data
except (OSError, ValueError):
pass
data = generate_reality_profile()
data = generate_tls_profile() if TRANSPORT_MODE == "tls" else generate_reality_profile()
TRANSPORT_FILE.parent.mkdir(parents=True, exist_ok=True)
atomic_write_text(TRANSPORT_FILE, json.dumps(data, ensure_ascii=False, indent=2) + "\n", mode=0o600)
try:
@@ -4686,6 +4734,13 @@ def transport_profile():
def transport_public_summary():
profile = transport_profile()
if profile.get("mode") == "tls":
return {
"mode": "tls",
"serverName": profile["serverName"],
"pin": profile["pin"],
"fingerprint": profile.get("fingerprint", "chrome"),
}
if profile.get("mode") != "reality":
return {"mode": "none"}
return {
@@ -4699,6 +4754,18 @@ def transport_public_summary():
def transport_server_stream():
profile = transport_profile()
if profile.get("mode") == "tls":
return {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"certificates": [{
"certificate": [profile["certificate"]],
"key": [profile["key"]],
}],
"alpn": ["h2", "http/1.1"],
},
}
if profile.get("mode") != "reality":
return {"network": "tcp", "security": "none"}
return {
@@ -4717,6 +4784,17 @@ def transport_server_stream():
def transport_client_stream():
profile = transport_profile()
if profile.get("mode") == "tls":
return {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"serverName": profile["serverName"],
"pinnedPeerCertSha256": profile["pin"],
"alpn": ["h2", "http/1.1"],
"fingerprint": profile.get("fingerprint", "chrome"),
},
}
if profile.get("mode") != "reality":
return {"network": "tcp", "security": "none"}
return {
@@ -5068,6 +5146,11 @@ def build_openwrt_config_payload(row, hub_url, vps_host_override="", public_url_
"public_url": effective_public_url,
}
profile = transport_profile()
if profile.get("mode") == "tls":
payload["security"] = "tls"
payload["tls_sni"] = profile["serverName"]
payload["tls_pin"] = profile["pin"]
payload["reality_fingerprint"] = profile.get("fingerprint", "chrome")
if profile.get("mode") == "reality":
payload["security"] = "reality"
payload["reality_public_key"] = profile["publicKey"]
@@ -5111,8 +5194,11 @@ def build_openwrt_config_lines(payload, mode="manual"):
f"uci set owrtremote.main.public_url='{sh_quote(payload['public_url'])}'",
f"uci set owrtremote.main.security='{sh_quote(payload.get('security', 'none'))}'",
f"uci set owrtremote.main.reality_public_key='{sh_quote(payload.get('reality_public_key', ''))}'",
f"uci set owrtremote.main.reality_short_id='{sh_quote(payload.get('reality_short_id', ''))}'",
f"uci set owrtremote.main.reality_server_name='{sh_quote(payload.get('reality_server_name', ''))}'",
f"uci set owrtremote.main.reality_fingerprint='{sh_quote(payload.get('reality_fingerprint', ''))}'",
f"uci set owrtremote.main.tls_sni='{sh_quote(payload.get('tls_sni', ''))}'",
f"uci set owrtremote.main.tls_pin='{sh_quote(payload.get('tls_pin', ''))}'",
"uci commit owrtremote",
"owrt-remote render-client",
"/etc/init.d/owrt-remote enable",