fix: vless fixes
This commit is contained in:
7 files changed
+171
-13
No files matched your search
@@ -5,6 +5,17 @@ import binascii
|
||||
import json
|
||||
import urllib.parse
|
||||
|
||||
SUPPORTED_VLESS_TRANSPORTS = {
|
||||
"",
|
||||
"tcp",
|
||||
"ws",
|
||||
"grpc",
|
||||
"h2",
|
||||
"http",
|
||||
"httpupgrade",
|
||||
"quic",
|
||||
}
|
||||
|
||||
|
||||
def _qs(query: str) -> dict:
|
||||
return dict(urllib.parse.parse_qsl(query, keep_blank_values=True))
|
||||
@@ -37,23 +48,37 @@ def _mk_transport(
|
||||
host_header: str = "",
|
||||
service_name: str = "",
|
||||
) -> "dict | None":
|
||||
if transport_type == "ws":
|
||||
normalized = transport_type.lower()
|
||||
|
||||
if normalized in ("", "tcp"):
|
||||
return None
|
||||
if normalized == "ws":
|
||||
return {
|
||||
"type": "ws",
|
||||
"path": urllib.parse.unquote(path),
|
||||
"headers": {"Host": host_header},
|
||||
}
|
||||
if transport_type == "grpc":
|
||||
if normalized == "grpc":
|
||||
return {
|
||||
"type": "grpc",
|
||||
"service_name": urllib.parse.unquote(service_name),
|
||||
}
|
||||
if transport_type == "h2":
|
||||
if normalized in ("h2", "http"):
|
||||
return {
|
||||
"type": "http",
|
||||
"host": [host_header],
|
||||
"path": urllib.parse.unquote(path),
|
||||
}
|
||||
if normalized == "httpupgrade":
|
||||
return {
|
||||
"type": "httpupgrade",
|
||||
"host": host_header,
|
||||
"path": urllib.parse.unquote(path),
|
||||
}
|
||||
if normalized == "quic":
|
||||
return {
|
||||
"type": "quic",
|
||||
}
|
||||
return None
|
||||
|
||||
|
||||
@@ -79,6 +104,19 @@ def parse_vless(url: str, tag: str) -> dict:
|
||||
userinfo, host, port, params = _parse_url_parts(url, "vless")
|
||||
security = params.get("security", "none")
|
||||
transport = params.get("type", "tcp")
|
||||
normalized_transport = transport.lower()
|
||||
|
||||
if "ech" in params:
|
||||
raise ValueError(
|
||||
"unsupported VLESS parameter 'ech': proxy-suite does not translate "
|
||||
"share-link ECH blobs into sing-box TLS config"
|
||||
)
|
||||
|
||||
if normalized_transport not in SUPPORTED_VLESS_TRANSPORTS:
|
||||
raise ValueError(
|
||||
f"unsupported VLESS transport '{transport}': proxy-suite only maps "
|
||||
"sing-box-documented transports; use raw JSON or another client/core"
|
||||
)
|
||||
|
||||
ob: dict = {
|
||||
"type": "vless",
|
||||
@@ -102,7 +140,7 @@ def parse_vless(url: str, tag: str) -> dict:
|
||||
)
|
||||
|
||||
tr = _mk_transport(
|
||||
transport,
|
||||
normalized_transport,
|
||||
path=params.get("path", "/"),
|
||||
host_header=params.get("host", host),
|
||||
service_name=params.get("serviceName", ""),
|
||||
|
||||
@@ -20,6 +20,42 @@ class BuildOutboundTests(unittest.TestCase):
|
||||
self.assertEqual(ob["server"], "example.com")
|
||||
self.assertEqual(ob["tls"]["reality"]["public_key"], "pubkey")
|
||||
|
||||
def test_vless_reality_germany_main_shape(self):
|
||||
ob = run_parser(
|
||||
"vless://uuid@example.com:443?type=tcp&security=reality&pbk=pubkey&fp=qq&sni=last.fm&sid=8a54&spx=%2F-%2Fen%2Fgp%2Fbestsellers&flow=xtls-rprx-vision&encryption=none"
|
||||
)
|
||||
self.assertEqual(ob["type"], "vless")
|
||||
self.assertEqual(ob["server_port"], 443)
|
||||
self.assertEqual(ob["flow"], "xtls-rprx-vision")
|
||||
self.assertEqual(ob["tls"]["server_name"], "last.fm")
|
||||
self.assertEqual(ob["tls"]["utls"]["fingerprint"], "qq")
|
||||
self.assertEqual(ob["tls"]["reality"]["short_id"], "8a54")
|
||||
self.assertNotIn("transport", ob)
|
||||
|
||||
def test_vless_httpupgrade_transport(self):
|
||||
ob = run_parser(
|
||||
"vless://uuid@example.com:443?type=httpupgrade&security=tls&sni=cdn.example.com&host=cdn.example.com&path=%2Fupgrade"
|
||||
)
|
||||
self.assertEqual(ob["transport"]["type"], "httpupgrade")
|
||||
self.assertEqual(ob["transport"]["host"], "cdn.example.com")
|
||||
self.assertEqual(ob["transport"]["path"], "/upgrade")
|
||||
|
||||
def test_vless_quic_transport(self):
|
||||
ob = run_parser("vless://uuid@example.com:443?type=quic&security=tls&sni=cdn.example.com")
|
||||
self.assertEqual(ob["transport"]["type"], "quic")
|
||||
|
||||
def test_vless_xhttp_fails_loudly(self):
|
||||
with self.assertRaisesRegex(ValueError, "unsupported VLESS transport 'xhttp'"):
|
||||
run_parser(
|
||||
"vless://uuid@example.com:443?type=xhttp&security=tls&sni=cdn.example.com"
|
||||
)
|
||||
|
||||
def test_vless_ech_fails_loudly(self):
|
||||
with self.assertRaisesRegex(ValueError, "unsupported VLESS parameter 'ech'"):
|
||||
run_parser(
|
||||
"vless://uuid@example.com:443?type=tcp&security=tls&sni=cdn.example.com&ech=blob"
|
||||
)
|
||||
|
||||
def test_vmess(self):
|
||||
payload = {
|
||||
"add": "vmess.example.com",
|
||||
@@ -68,7 +104,6 @@ class BuildOutboundTests(unittest.TestCase):
|
||||
self.assertEqual(ob["type"], "shadowsocks")
|
||||
self.assertEqual(ob["method"], "chacha20-ietf-poly1305")
|
||||
|
||||
|
||||
def test_shadowsocks_legacy_full_base64(self):
|
||||
legacy = (
|
||||
base64.urlsafe_b64encode(
|
||||
@@ -84,7 +119,6 @@ class BuildOutboundTests(unittest.TestCase):
|
||||
self.assertEqual(ob["method"], "chacha20-ietf-poly1305")
|
||||
self.assertEqual(ob["password"], "passw0rd")
|
||||
|
||||
|
||||
def test_shadowsocks_plain_userinfo(self):
|
||||
ob = run_parser("ss://none:plain%20pass@plain.example.com:8388")
|
||||
self.assertEqual(ob["type"], "shadowsocks")
|
||||
|
||||
Reference in new issue
Block a user