fix: different xray fixes
This commit is contained in:
7 files changed
+156
-21
No files matched your search
@@ -53,7 +53,10 @@ def _xray_tls(tls: dict | None) -> tuple[str, dict]:
|
||||
if tls.get("alpn"):
|
||||
settings["alpn"] = tls["alpn"]
|
||||
if tls.get("insecure"):
|
||||
settings["allowInsecure"] = True
|
||||
raise ValueError(
|
||||
"XRay no longer supports tlsSettings.allowInsecure; "
|
||||
"remove insecure=1 or use a supported certificate verification option"
|
||||
)
|
||||
if tls.get("ech_config_list"):
|
||||
settings["echConfigList"] = tls["ech_config_list"]
|
||||
utls = tls.get("utls", {})
|
||||
@@ -150,13 +153,21 @@ def render_xray_outbound(ob: dict, routing_mark: int | None = None) -> dict:
|
||||
stream = stream_settings()
|
||||
stream["network"] = "hysteria"
|
||||
stream["security"] = "tls"
|
||||
stream["hysteriaSettings"] = {"version": 2}
|
||||
settings = {
|
||||
"version": 2,
|
||||
"address": ob["server"],
|
||||
"port": ob["server_port"],
|
||||
}
|
||||
if ob.get("password"):
|
||||
settings["password"] = ob["password"]
|
||||
stream["hysteriaSettings"]["auth"] = ob["password"]
|
||||
if ob.get("obfs", {}).get("type") == "salamander":
|
||||
stream.setdefault("finalmask", {}).setdefault("udp", []).append(
|
||||
{
|
||||
"type": "salamander",
|
||||
"settings": {"password": ob["obfs"].get("password", "")},
|
||||
}
|
||||
)
|
||||
return {"protocol": "hysteria", "tag": tag, "settings": settings, "streamSettings": stream}
|
||||
|
||||
if typ == "socks":
|
||||
|
||||
@@ -182,6 +182,25 @@ class BuildOutboundTests(unittest.TestCase):
|
||||
self.assertTrue(ob["tls"]["insecure"])
|
||||
self.assertEqual(ob["obfs"]["password"], "mask")
|
||||
|
||||
def test_xray_hysteria2(self):
|
||||
ob = run_xray_parser(
|
||||
"hy2://secret@example.com:443?sni=hy.example.com&obfs=salamander&obfs-password=mask"
|
||||
)
|
||||
self.assertEqual(ob["protocol"], "hysteria")
|
||||
self.assertEqual(ob["settings"]["address"], "example.com")
|
||||
self.assertNotIn("password", ob["settings"])
|
||||
self.assertEqual(ob["streamSettings"]["network"], "hysteria")
|
||||
self.assertEqual(ob["streamSettings"]["tlsSettings"]["serverName"], "hy.example.com")
|
||||
self.assertEqual(ob["streamSettings"]["hysteriaSettings"]["auth"], "secret")
|
||||
self.assertEqual(
|
||||
ob["streamSettings"]["finalmask"]["udp"],
|
||||
[{"type": "salamander", "settings": {"password": "mask"}}],
|
||||
)
|
||||
|
||||
def test_xray_hysteria2_insecure_fails_loudly(self):
|
||||
with self.assertRaisesRegex(ValueError, "allowInsecure"):
|
||||
run_xray_parser("hy2://secret@example.com:443?sni=hy.example.com&insecure=1")
|
||||
|
||||
def test_tuic(self):
|
||||
ob = run_parser(
|
||||
"tuic://00000000-0000-0000-0000-000000000000:secret@example.com:443?sni=tuic.example.com&alpn=h3,hq-29"
|
||||
|
||||
Reference in new issue
Block a user