fork: REALITY transport for the router<->hub VLESS hop
Upstream ships the router<->hub hop as plain VLESS (tcp, security=none): UUID-authenticated but cleartext — LuCI credentials and logs inside the hop are readable by anyone on-path. This fork wraps the hop in VLESS+Reality (TLS handshake camouflaged against a public dest, no CA certs, no renewal): - vps/owrt-remote-hub.py: transport profile (STATE_DIR/transport.json, x25519 keypair via the xray binary), reality streamSettings in the server inbound and in make_router_xray_config(), uci transport lines in the generated OpenWrt config, transport block in heartbeat hub_update, and xray -test gate before swapping /etc/xray config. - files/usr/sbin/owrt-remote: security/reality_* uci options, validation, reality streamSettings in render_client_config, security-aware compat probe and core-compat checks. - files/etc/config/owrtremote, cgi form fields, PKG_RELEASE bump. Env on the hub: OWRT_REMOTE_TRANSPORT=reality|none, OWRT_REMOTE_REALITY_DEST/FINGERPRINT, OWRT_REMOTE_XRAY_BINARY. NOTE: xray-core >= 26.9.8 REALITY servers reject client hellos (XTLS/Xray-core#7259) — pin the hub core to 26.7.28 until upstream fixes it.
This commit is contained in:
1 parent
9dead7741d
commit
9b7a89257b
5 files changed
+192
-16
No files matched your search
+141
-8
@@ -114,6 +114,17 @@ ACME_WEBROOT = STATE_DIR / "acme-webroot"
|
||||
# take longer than the old 75-second window while the reverse tunnel remains usable.
|
||||
ONLINE_AFTER_SECONDS = max(75, int(os.environ.get("OWRT_REMOTE_ONLINE_AFTER", "180")))
|
||||
DEFAULT_VLESS_PORT = int(os.environ.get("OWRT_REMOTE_VLESS_PORT", "8443"))
|
||||
# Fork change (reality-transport): upstream ships the router<->hub hop as plain
|
||||
# VLESS (network=tcp, security=none) — UUID-authenticated but not encrypted, so
|
||||
# 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()
|
||||
REALITY_DEST = os.environ.get("OWRT_REMOTE_REALITY_DEST", "www.microsoft.com").strip()
|
||||
REALITY_FINGERPRINT = os.environ.get("OWRT_REMOTE_REALITY_FINGERPRINT", "chrome").strip()
|
||||
TRANSPORT_FILE = STATE_DIR / "transport.json"
|
||||
XRAY_BINARY = os.environ.get("OWRT_REMOTE_XRAY_BINARY", "/usr/local/bin/xray")
|
||||
REQUEST_QUEUE_SIZE = int(os.environ.get("OWRT_REMOTE_REQUEST_QUEUE_SIZE", "128"))
|
||||
ROUTER_PROXY_LIMIT = max(1, int(os.environ.get("OWRT_REMOTE_ROUTER_PROXY_LIMIT", "4")))
|
||||
PROXY_TIMEOUT = float(os.environ.get("OWRT_REMOTE_PROXY_TIMEOUT", "25"))
|
||||
@@ -4118,6 +4129,7 @@ def router_current_hub_bundle(router, app_public_url="", request_origin="", fall
|
||||
"hub_url": hub_url,
|
||||
"public_url": public_url,
|
||||
"vps_host": config_vps_host,
|
||||
"transport": transport_public_summary(),
|
||||
}
|
||||
return hub_update, hub_url, config_vps_host
|
||||
|
||||
@@ -4621,6 +4633,98 @@ def delete_router_note_entry(conn, router_id, note_id):
|
||||
return get_router(conn, router_id)
|
||||
|
||||
|
||||
def generate_reality_profile():
|
||||
# X25519 keypair via the local xray binary (stdlib has no X25519). Labels
|
||||
# follow `xray x25519` output of the deployed core.
|
||||
binary = XRAY_BINARY if Path(XRAY_BINARY).exists() else (shutil.which("xray") or "")
|
||||
if not binary:
|
||||
raise RuntimeError(f"xray binary not found for Reality keypair generation: {XRAY_BINARY}")
|
||||
result = subprocess.run(
|
||||
[binary, "x25519"], text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=20, check=False,
|
||||
)
|
||||
out = result.stdout or ""
|
||||
private = re.search(r"PrivateKey:\s*(\S+)", out)
|
||||
public = re.search(r"Password \(PublicKey\):\s*(\S+)", out) or re.search(r"Password \(b64\):\s*(\S+)", out)
|
||||
if not private or not public:
|
||||
detail = (result.stderr or out or "").strip()
|
||||
raise RuntimeError(f"`{binary} x25519` returned no keypair: {detail}")
|
||||
return {
|
||||
"mode": "reality",
|
||||
"privateKey": private.group(1),
|
||||
"publicKey": public.group(1),
|
||||
"shortId": secrets.token_hex(4),
|
||||
"serverName": REALITY_DEST,
|
||||
"dest": f"{REALITY_DEST}:443",
|
||||
"fingerprint": REALITY_FINGERPRINT or "chrome",
|
||||
}
|
||||
|
||||
|
||||
def transport_profile():
|
||||
if TRANSPORT_MODE != "reality":
|
||||
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
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
data = 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:
|
||||
os.chmod(TRANSPORT_FILE, 0o600)
|
||||
except OSError:
|
||||
pass
|
||||
return data
|
||||
|
||||
|
||||
def transport_public_summary():
|
||||
profile = transport_profile()
|
||||
if profile.get("mode") != "reality":
|
||||
return {"mode": "none"}
|
||||
return {
|
||||
"mode": "reality",
|
||||
"publicKey": profile["publicKey"],
|
||||
"serverName": profile["serverName"],
|
||||
"fingerprint": profile.get("fingerprint", "chrome"),
|
||||
}
|
||||
|
||||
|
||||
def transport_server_stream():
|
||||
profile = transport_profile()
|
||||
if profile.get("mode") != "reality":
|
||||
return {"network": "tcp", "security": "none"}
|
||||
return {
|
||||
"network": "tcp",
|
||||
"security": "reality",
|
||||
"realitySettings": {
|
||||
"show": False,
|
||||
"dest": profile["dest"],
|
||||
"xver": 0,
|
||||
"serverNames": [profile["serverName"]],
|
||||
"shortIds": [profile["shortId"]],
|
||||
"privateKey": profile["privateKey"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def transport_client_stream():
|
||||
profile = transport_profile()
|
||||
if profile.get("mode") != "reality":
|
||||
return {"network": "tcp", "security": "none"}
|
||||
return {
|
||||
"network": "tcp",
|
||||
"security": "reality",
|
||||
"realitySettings": {
|
||||
"show": False,
|
||||
"fingerprint": profile.get("fingerprint", "chrome"),
|
||||
"serverName": profile["serverName"],
|
||||
"publicKey": profile["publicKey"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def make_server_xray_config(rows, listen_host="0.0.0.0", listen_port=DEFAULT_VLESS_PORT, decryption="none"):
|
||||
clients = []
|
||||
inbounds = [
|
||||
@@ -4633,10 +4737,7 @@ def make_server_xray_config(rows, listen_host="0.0.0.0", listen_port=DEFAULT_VLE
|
||||
"clients": clients,
|
||||
"decryption": decryption,
|
||||
},
|
||||
"streamSettings": {
|
||||
"network": "tcp",
|
||||
"security": "none",
|
||||
},
|
||||
"streamSettings": transport_server_stream(),
|
||||
}
|
||||
]
|
||||
rules = []
|
||||
@@ -4777,7 +4878,7 @@ def make_router_xray_config(row):
|
||||
"flow": row["vless_flow"],
|
||||
"reverse": {"tag": bridge_tag},
|
||||
},
|
||||
"streamSettings": {"network": "tcp", "security": "none"},
|
||||
"streamSettings": transport_client_stream(),
|
||||
},
|
||||
{
|
||||
"tag": "vps-ssh-interconn",
|
||||
@@ -4790,7 +4891,7 @@ def make_router_xray_config(row):
|
||||
"flow": row["vless_flow"],
|
||||
"reverse": {"tag": ssh_bridge_tag},
|
||||
},
|
||||
"streamSettings": {"network": "tcp", "security": "none"},
|
||||
"streamSettings": transport_client_stream(),
|
||||
},
|
||||
],
|
||||
"routing": {
|
||||
@@ -4826,11 +4927,33 @@ def reload_vps_xray(db_path=DB_PATH):
|
||||
init_db(conn)
|
||||
rows = list_router_rows(conn)
|
||||
config = make_server_xray_config(rows)
|
||||
atomic_write_text(out, json.dumps(config, ensure_ascii=False, indent=2) + "\n", mode=0o600)
|
||||
config_text = json.dumps(config, ensure_ascii=False, indent=2) + "\n"
|
||||
# Never replace a live tunnel config with an invalid one: render to a
|
||||
# candidate, let the deployed xray validate it, then swap atomically.
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
candidate = out.parent / (out.name + ".candidate")
|
||||
atomic_write_text(candidate, config_text, mode=0o600)
|
||||
try:
|
||||
os.chmod(out, 0o600)
|
||||
os.chmod(candidate, 0o600)
|
||||
except OSError:
|
||||
pass
|
||||
binary = XRAY_BINARY if Path(XRAY_BINARY).exists() else (shutil.which("xray") or "")
|
||||
if binary:
|
||||
test = subprocess.run(
|
||||
[binary, "-test", "-config", str(candidate)],
|
||||
text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=30, check=False,
|
||||
)
|
||||
if test.returncode != 0:
|
||||
candidate.unlink(missing_ok=True)
|
||||
detail = (test.stderr or test.stdout or "").strip()
|
||||
raise RuntimeError(f"xray -test rejected generated config: {detail}")
|
||||
os.replace(candidate, out)
|
||||
try:
|
||||
os.chmod(out, 0o600)
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
candidate.rename(out)
|
||||
result = subprocess.run(
|
||||
["systemctl", "restart", service],
|
||||
text=True,
|
||||
@@ -4937,6 +5060,12 @@ 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") == "reality":
|
||||
payload["security"] = "reality"
|
||||
payload["reality_public_key"] = profile["publicKey"]
|
||||
payload["reality_server_name"] = profile["serverName"]
|
||||
payload["reality_fingerprint"] = profile.get("fingerprint", "chrome")
|
||||
return payload
|
||||
|
||||
|
||||
@@ -4972,6 +5101,10 @@ def build_openwrt_config_lines(payload, mode="manual"):
|
||||
f"uci set owrtremote.main.ssh_host='{sh_quote(payload['ssh_host'])}'",
|
||||
f"uci set owrtremote.main.ssh_port='{payload['ssh_port']}'",
|
||||
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_server_name='{sh_quote(payload.get('reality_server_name', ''))}'",
|
||||
f"uci set owrtremote.main.reality_fingerprint='{sh_quote(payload.get('reality_fingerprint', ''))}'",
|
||||
"uci commit owrtremote",
|
||||
"owrt-remote render-client",
|
||||
"/etc/init.d/owrt-remote enable",
|
||||
|
||||
Reference in new issue
Block a user