fix: vless fixes

This commit is contained in:
FUFSoB committed 2026-06-06 13:47:59 +05:00
1 parent 334755fd0e
commit 32bf2266c0
7 files changed
+171 -13

No files matched your search

+41 -2
View File
@@ -23,6 +23,7 @@ Update module option docs there instead of editing this file by hand.
- [quiet](#services-proxy-suite-perapprouting-proxychains-quiet)
- singBox
- [enable](#services-proxy-suite-singbox-enable)
- [package](#services-proxy-suite-singbox-package)
- auth
- [password](#services-proxy-suite-singbox-auth-password)
- [passwordFile](#services-proxy-suite-singbox-auth-passwordfile)
@@ -197,6 +198,7 @@ services.proxy-suite = {
enable = true;
listenAddress = "127.0.0.1";
outbounds = [ ];
package = pkgs.sing-box;
port = 1080;
proxyByDefault = true;
routing = {
@@ -375,6 +377,7 @@ services.proxy-suite = {
url = "hy2://password@example.com:443?sni=example.com";
}
];
package = pkgs.sing-box;
port = 1080;
proxyByDefault = true;
routing = {
@@ -972,6 +975,42 @@ true
<a id="services-proxy-suite-singbox-package"></a>
## services\.proxy-suite\.singBox\.package
sing-box package used by proxy-suite systemd services\.
Override this to pin or test a specific sing-box build when upstream
protocol behavior changes\.
*Type:*
package
*Default:*
```nix
pkgs.sing-box
```
*Example:*
```nix
pkgs.sing-box
```
*Declared by:*
- [modules/proxy-suite/options/sing-box\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options/sing-box.nix)
<a id="services-proxy-suite-singbox-auth-password"></a>
## services\.proxy-suite\.singBox\.auth\.password
@@ -4238,6 +4277,8 @@ true
<a id="services-proxy-suite-zapret-cidrexemption-enable"></a>
## services\.proxy-suite\.zapret\.cidrExemption\.enable
Whether to enable CIDR exemption from zapret NFQUEUE\.
@@ -4269,8 +4310,6 @@ true
<a id="services-proxy-suite-zapret-cidrexemption-cidrs"></a>
## services\.proxy-suite\.zapret\.cidrExemption\.cidrs
Subnets to exempt from zapret’s NFQUEUE mangle rules\.
Useful when a VM (libvirt, etc\.) is behind NAT and zapret
would corrupt its traffic through the host’s nftables\.
+15 -2
View File
@@ -1,8 +1,8 @@
# Core sing-box options. Feature-area options live in sing-box-{outbounds,dns,tun,tproxy,routing}.nix.
{ lib, ... }:
{ lib, pkgs, ... }:
let
inherit (lib) mkOption mkEnableOption types;
inherit (lib) literalExpression mkOption mkEnableOption types;
in
{
options.services.proxy-suite.singBox = {
@@ -16,6 +16,19 @@ in
'';
};
package = mkOption {
type = types.package;
default = pkgs.sing-box;
defaultText = literalExpression "pkgs.sing-box";
example = literalExpression "pkgs.sing-box";
description = ''
sing-box package used by proxy-suite systemd services.
Override this to pin or test a specific sing-box build when upstream
protocol behavior changes.
'';
};
listenAddress = mkOption {
type = types.str;
default = "127.0.0.1";
+1 -1
View File
@@ -38,7 +38,7 @@ let
# Tool paths – defined once here and passed into sub-modules as needed.
jq = "${pkgs.jq}/bin/jq";
python3 = "${pkgs.python3}/bin/python3";
singBox = "${pkgs.sing-box}/bin/sing-box";
singBox = "${singBoxCfg.package}/bin/sing-box";
grepBin = "${pkgs.gnugrep}/bin/grep";
awk = "${pkgs.gawk}/bin/awk";
sleepBin = "${pkgs.coreutils}/bin/sleep";
+18
View File
@@ -200,6 +200,19 @@ let
minimalProxyCtlWrapper = _minimalProxyCtl.wrapper;
minimalProxyCtlScript = _minimalProxyCtl.script;
minimalSocksService = minimal.config.systemd.services."proxy-suite-socks";
customSingBoxPackage = pkgs.writeShellScriptBin "sing-box" ''
exit 0
'';
customSingBoxPackageFixture = evalProxySuite [
baseModule
{
services.proxy-suite.singBox.package = customSingBoxPackage;
}
];
customSingBoxPackageBin = "${builtins.unsafeDiscardStringContext (toString customSingBoxPackage)}/bin/sing-box";
customSingBoxPackageStartScript = builtins.readFile (
customSingBoxPackageFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
);
routeModeFixture = evalProxySuite [
baseModule
@@ -1415,6 +1428,11 @@ let
assert builtins.elem "network-online.target" zapretSyncService.wants;
true
)
# -- sing-box package override propagates into generated service scripts --
(
assert pkgs.lib.hasInfix customSingBoxPackageBin customSingBoxPackageStartScript;
true
)
(
assert duplicateTags.success == false;
true
+18 -2
View File
@@ -19,6 +19,22 @@ let
];
};
filterGeneratedOptions = lib.filterAttrs (name: _: name != "_module");
docPackagePlaceholder = "__proxy_suite_doc_pkg_sing_box__";
sanitizeConfigForDocs =
config:
config
// {
singBox =
(config.singBox or { })
// lib.optionalAttrs ((config.singBox or { }) ? package) {
package = docPackagePlaceholder;
};
};
renderConfigText =
config:
lib.replaceStrings [ "\"${docPackagePlaceholder}\"" ] [ "pkgs.sing-box" ] (
lib.generators.toPretty { } (sanitizeConfigForDocs config)
);
mkGeneratedExampleValue =
option:
if (option ? _type) && option._type == "option" then
@@ -32,8 +48,8 @@ let
throw "Cannot generate example value for option ${lib.showOption option.loc}"
else
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions option);
defaultConfigText = lib.generators.toPretty { } eval.config.services.proxy-suite;
exampleConfigText = lib.generators.toPretty { } (
defaultConfigText = renderConfigText eval.config.services.proxy-suite;
exampleConfigText = renderConfigText (
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions eval.options.services.proxy-suite)
);
repoRoot = toString ../.;
+42 -4
View File
@@ -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", ""),
+36 -2
View File
@@ -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")