zapret-kvn/xray_fluent/masking/singbox.py
loop-uh 64f4ee714e Xray owns VMess and Trojan: sidecar path, XHTTP, TLS and masking follow
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>
2026-11-16 09:44:27 -05:00

48 lines
2.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""sing-box's own TLS fragmentation for the TLS protocols sing-box owns (option/tls.go:
`fragment`, `record_fragment`, `fragment_fallback_delay`; client side, std/uTLS engines only,
REALITY ignores it). Same rules as Android `masking/singbox`.
The native `spoof` of the same file needs WinDivert on Windows (common/tlsspoof/raw_windows.go)
and is not offered here.
"""
from __future__ import annotations
from typing import Any
from .model import Core, Problem, ServerShape, SingboxFragment
PROTOCOLS = frozenset({"anytls", "http", "shadowtls"}) # Trojan and VMess moved to Xray (2026-11-16)
MAX_FALLBACK_DELAY_MS = 10_000
def validate(fragment: SingboxFragment) -> list[Problem]:
problems: list[Problem] = []
if fragment.fallback_delay_ms is not None and not 1 <= fragment.fallback_delay_ms <= MAX_FALLBACK_DELAY_MS:
problems.append(Problem("singbox.fallbackDelayMs", f"Задержка: от 1 до {MAX_FALLBACK_DELAY_MS} мс."))
if fragment.enabled and not fragment.fragment and not fragment.record_fragment:
problems.append(Problem("singbox.fragment", "Не выбран ни один способ фрагментации: ничего не изменится.", error=False))
return problems
def applies(shape: ServerShape) -> bool:
return shape.core is Core.SINGBOX and shape.protocol in PROTOCOLS and shape.security == "tls"
def emit(outbound: dict[str, Any], fragment: SingboxFragment, shape: ServerShape) -> tuple[dict[str, Any], list[str]]:
if not fragment.enabled or shape.core is not Core.SINGBOX or shape.protocol not in PROTOCOLS:
return outbound, []
tls = outbound.get("tls")
if not isinstance(tls, dict) or tls.get("enabled") is not True:
return outbound, ["Фрагментация TLS не применена: у сервера нет TLS."]
reality = tls.get("reality")
if isinstance(reality, dict) and reality.get("enabled") is True:
return outbound, ["Фрагментация TLS не применена: REALITY её обходит."]
updated = {key: value for key, value in tls.items() if key not in {"fragment", "record_fragment", "fragment_fallback_delay"}}
if fragment.fragment:
updated["fragment"] = True
if fragment.record_fragment:
updated["record_fragment"] = True
if fragment.fallback_delay_ms is not None:
updated["fragment_fallback_delay"] = f"{fragment.fallback_delay_ms}ms"
return {**outbound, "tls": updated}, []