Owner decision 2026-11-16: VLESS, VMess and Trojan run on the official Xray core; sing-box stays the gasket (TUN, routing, DNS, protected sockets) and only keeps Shadowsocks, SOCKS, HTTP and the rest. sing-box had no XHTTP transport for VMess and Trojan and only approximated the other transports, while Xray runs any of its protocols over any transport. - protocol_core: VMess/Trojan in Xray's JSON shape go to Xray; a raw sing-box JSON outbound pasted by the user (type key) stays with sing-box. - link_parser: xray_only for VMess/Trojan (allowInsecure without a pin is dropped like VLESS, Xray 26.x has none), TLS validation for all three, VMess alterId > 0 refused, vmess:// carries XHTTP mode and extra, WebSocket/HTTPUpgrade drop h2/h3 from alpn. - masking: VMess/Trojan are Xray servers (shape, presets); sing-box fragment keeps AnyTLS, HTTP, ShadowTLS. - config_builder: dead VMess/Trojan/transport conversion removed. - tests flipped to Shadowsocks where they need a sing-box server; new tests/test_xray_owns_vmess_trojan.py; docs updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
68 lines
3.5 KiB
Python
68 lines
3.5 KiB
Python
from __future__ import annotations
|
||
|
||
import copy
|
||
import unittest
|
||
|
||
from xray_fluent.engines.singbox.config_builder import build_singbox_outbound
|
||
from xray_fluent.engines.tls_fingerprint import BROWSER_TLS_FINGERPRINT, apply_browser_fingerprint
|
||
from xray_fluent.engines.xray.config_builder import build_xray_config
|
||
from xray_fluent.importer.link_parser import parse_single
|
||
from xray_fluent.network.speed_test_worker import build_speed_test_config
|
||
from xray_fluent.profiles.models import AppSettings, RoutingSettings
|
||
|
||
UUID = "11111111-2222-3333-4444-555555555555"
|
||
REALITY = (
|
||
f"vless://{UUID}@vpn.example.com:443?security=reality&sni=www.example.com"
|
||
"&pbk=Z84J2IelR9ch3k8VtlVhhs5ycBUlXA7wHBWcBrjqnAw&sid=ab&type=tcp#r"
|
||
)
|
||
|
||
|
||
def _proxy(config: dict) -> dict:
|
||
return next(item for item in config["outbounds"] if item.get("tag") == "proxy")
|
||
|
||
|
||
class SingBoxFingerprintTests(unittest.TestCase):
|
||
"""Без fp в ссылке рукопожатие с сервером — как у Chrome, а не ClientHello Go."""
|
||
|
||
# Trojan and VMess run on Xray since 2026-11-16: their fingerprint is Xray's own `fingerprint`.
|
||
def test_trojan_without_fp_gets_chrome(self) -> None:
|
||
node = parse_single("trojan://secret@vpn.example.com:443?sni=vpn.example.com#t")
|
||
outbound = apply_browser_fingerprint(copy.deepcopy(node.outbound))
|
||
self.assertEqual(outbound["streamSettings"]["tlsSettings"]["fingerprint"], BROWSER_TLS_FINGERPRINT)
|
||
|
||
def test_explicit_fp_is_kept(self) -> None:
|
||
node = parse_single("trojan://secret@vpn.example.com:443?sni=vpn.example.com&fp=firefox#t")
|
||
outbound = apply_browser_fingerprint(copy.deepcopy(node.outbound))
|
||
self.assertEqual(outbound["streamSettings"]["tlsSettings"]["fingerprint"], "firefox")
|
||
|
||
def test_plain_tcp_without_tls_is_untouched(self) -> None:
|
||
node = parse_single("ss://YWVzLTI1Ni1nY206c2VjcmV0@vpn.example.com:8388#s")
|
||
self.assertNotIn("tls", build_singbox_outbound(node))
|
||
|
||
|
||
class XrayFingerprintTests(unittest.TestCase):
|
||
def test_reality_without_fp_gets_chrome_in_runtime_config(self) -> None:
|
||
node = parse_single(REALITY)
|
||
self.assertNotIn("fingerprint", node.outbound["streamSettings"]["realitySettings"])
|
||
proxy = _proxy(build_xray_config(node, RoutingSettings(), AppSettings()))
|
||
self.assertEqual(proxy["streamSettings"]["realitySettings"]["fingerprint"], BROWSER_TLS_FINGERPRINT)
|
||
# Хранимый узел не меняется: отпечаток подставляется только в конфиг ядра.
|
||
self.assertNotIn("fingerprint", node.outbound["streamSettings"]["realitySettings"])
|
||
|
||
def test_speed_test_core_uses_the_same_handshake(self) -> None:
|
||
proxy = _proxy(build_speed_test_config(parse_single(REALITY), 18080))
|
||
self.assertEqual(proxy["streamSettings"]["realitySettings"]["fingerprint"], BROWSER_TLS_FINGERPRINT)
|
||
|
||
def test_quic_transport_is_left_alone(self) -> None:
|
||
outbound = {"streamSettings": {"network": "xhttp", "security": "tls", "tlsSettings": {"alpn": ["h3"]}}}
|
||
apply_browser_fingerprint(outbound)
|
||
self.assertNotIn("fingerprint", outbound["streamSettings"]["tlsSettings"])
|
||
|
||
def test_explicit_fingerprint_is_kept(self) -> None:
|
||
outbound = {"streamSettings": {"security": "tls", "tlsSettings": {"fingerprint": "safari"}}}
|
||
apply_browser_fingerprint(outbound)
|
||
self.assertEqual(outbound["streamSettings"]["tlsSettings"]["fingerprint"], "safari")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|