fix: vless fixes
This commit is contained in:
7 files changed
+171
-13
No files matched your search
+41
-2
@@ -23,6 +23,7 @@ Update module option docs there instead of editing this file by hand.
|
|||||||
- [quiet](#services-proxy-suite-perapprouting-proxychains-quiet)
|
- [quiet](#services-proxy-suite-perapprouting-proxychains-quiet)
|
||||||
- singBox
|
- singBox
|
||||||
- [enable](#services-proxy-suite-singbox-enable)
|
- [enable](#services-proxy-suite-singbox-enable)
|
||||||
|
- [package](#services-proxy-suite-singbox-package)
|
||||||
- auth
|
- auth
|
||||||
- [password](#services-proxy-suite-singbox-auth-password)
|
- [password](#services-proxy-suite-singbox-auth-password)
|
||||||
- [passwordFile](#services-proxy-suite-singbox-auth-passwordfile)
|
- [passwordFile](#services-proxy-suite-singbox-auth-passwordfile)
|
||||||
@@ -197,6 +198,7 @@ services.proxy-suite = {
|
|||||||
enable = true;
|
enable = true;
|
||||||
listenAddress = "127.0.0.1";
|
listenAddress = "127.0.0.1";
|
||||||
outbounds = [ ];
|
outbounds = [ ];
|
||||||
|
package = pkgs.sing-box;
|
||||||
port = 1080;
|
port = 1080;
|
||||||
proxyByDefault = true;
|
proxyByDefault = true;
|
||||||
routing = {
|
routing = {
|
||||||
@@ -375,6 +377,7 @@ services.proxy-suite = {
|
|||||||
url = "hy2://password@example.com:443?sni=example.com";
|
url = "hy2://password@example.com:443?sni=example.com";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
package = pkgs.sing-box;
|
||||||
port = 1080;
|
port = 1080;
|
||||||
proxyByDefault = true;
|
proxyByDefault = true;
|
||||||
routing = {
|
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>
|
<a id="services-proxy-suite-singbox-auth-password"></a>
|
||||||
## services\.proxy-suite\.singBox\.auth\.password
|
## services\.proxy-suite\.singBox\.auth\.password
|
||||||
|
|
||||||
@@ -4238,6 +4277,8 @@ true
|
|||||||
<a id="services-proxy-suite-zapret-cidrexemption-enable"></a>
|
<a id="services-proxy-suite-zapret-cidrexemption-enable"></a>
|
||||||
## services\.proxy-suite\.zapret\.cidrExemption\.enable
|
## services\.proxy-suite\.zapret\.cidrExemption\.enable
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Whether to enable CIDR exemption from zapret NFQUEUE\.
|
Whether to enable CIDR exemption from zapret NFQUEUE\.
|
||||||
|
|
||||||
|
|
||||||
@@ -4269,8 +4310,6 @@ true
|
|||||||
<a id="services-proxy-suite-zapret-cidrexemption-cidrs"></a>
|
<a id="services-proxy-suite-zapret-cidrexemption-cidrs"></a>
|
||||||
## services\.proxy-suite\.zapret\.cidrExemption\.cidrs
|
## services\.proxy-suite\.zapret\.cidrExemption\.cidrs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Subnets to exempt from zapret’s NFQUEUE mangle rules\.
|
Subnets to exempt from zapret’s NFQUEUE mangle rules\.
|
||||||
Useful when a VM (libvirt, etc\.) is behind NAT and zapret
|
Useful when a VM (libvirt, etc\.) is behind NAT and zapret
|
||||||
would corrupt its traffic through the host’s nftables\.
|
would corrupt its traffic through the host’s nftables\.
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# Core sing-box options. Feature-area options live in sing-box-{outbounds,dns,tun,tproxy,routing}.nix.
|
# Core sing-box options. Feature-area options live in sing-box-{outbounds,dns,tun,tproxy,routing}.nix.
|
||||||
{ lib, ... }:
|
{ lib, pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption mkEnableOption types;
|
inherit (lib) literalExpression mkOption mkEnableOption types;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.proxy-suite.singBox = {
|
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 {
|
listenAddress = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "127.0.0.1";
|
default = "127.0.0.1";
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ let
|
|||||||
# Tool paths – defined once here and passed into sub-modules as needed.
|
# Tool paths – defined once here and passed into sub-modules as needed.
|
||||||
jq = "${pkgs.jq}/bin/jq";
|
jq = "${pkgs.jq}/bin/jq";
|
||||||
python3 = "${pkgs.python3}/bin/python3";
|
python3 = "${pkgs.python3}/bin/python3";
|
||||||
singBox = "${pkgs.sing-box}/bin/sing-box";
|
singBox = "${singBoxCfg.package}/bin/sing-box";
|
||||||
grepBin = "${pkgs.gnugrep}/bin/grep";
|
grepBin = "${pkgs.gnugrep}/bin/grep";
|
||||||
awk = "${pkgs.gawk}/bin/awk";
|
awk = "${pkgs.gawk}/bin/awk";
|
||||||
sleepBin = "${pkgs.coreutils}/bin/sleep";
|
sleepBin = "${pkgs.coreutils}/bin/sleep";
|
||||||
|
|||||||
@@ -200,6 +200,19 @@ let
|
|||||||
minimalProxyCtlWrapper = _minimalProxyCtl.wrapper;
|
minimalProxyCtlWrapper = _minimalProxyCtl.wrapper;
|
||||||
minimalProxyCtlScript = _minimalProxyCtl.script;
|
minimalProxyCtlScript = _minimalProxyCtl.script;
|
||||||
minimalSocksService = minimal.config.systemd.services."proxy-suite-socks";
|
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 [
|
routeModeFixture = evalProxySuite [
|
||||||
baseModule
|
baseModule
|
||||||
@@ -1415,6 +1428,11 @@ let
|
|||||||
assert builtins.elem "network-online.target" zapretSyncService.wants;
|
assert builtins.elem "network-online.target" zapretSyncService.wants;
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
# -- sing-box package override propagates into generated service scripts --
|
||||||
|
(
|
||||||
|
assert pkgs.lib.hasInfix customSingBoxPackageBin customSingBoxPackageStartScript;
|
||||||
|
true
|
||||||
|
)
|
||||||
(
|
(
|
||||||
assert duplicateTags.success == false;
|
assert duplicateTags.success == false;
|
||||||
true
|
true
|
||||||
|
|||||||
+18
-2
@@ -19,6 +19,22 @@ let
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
filterGeneratedOptions = lib.filterAttrs (name: _: name != "_module");
|
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 =
|
mkGeneratedExampleValue =
|
||||||
option:
|
option:
|
||||||
if (option ? _type) && option._type == "option" then
|
if (option ? _type) && option._type == "option" then
|
||||||
@@ -32,8 +48,8 @@ let
|
|||||||
throw "Cannot generate example value for option ${lib.showOption option.loc}"
|
throw "Cannot generate example value for option ${lib.showOption option.loc}"
|
||||||
else
|
else
|
||||||
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions option);
|
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions option);
|
||||||
defaultConfigText = lib.generators.toPretty { } eval.config.services.proxy-suite;
|
defaultConfigText = renderConfigText eval.config.services.proxy-suite;
|
||||||
exampleConfigText = lib.generators.toPretty { } (
|
exampleConfigText = renderConfigText (
|
||||||
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions eval.options.services.proxy-suite)
|
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions eval.options.services.proxy-suite)
|
||||||
);
|
);
|
||||||
repoRoot = toString ../.;
|
repoRoot = toString ../.;
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ import binascii
|
|||||||
import json
|
import json
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
|
SUPPORTED_VLESS_TRANSPORTS = {
|
||||||
|
"",
|
||||||
|
"tcp",
|
||||||
|
"ws",
|
||||||
|
"grpc",
|
||||||
|
"h2",
|
||||||
|
"http",
|
||||||
|
"httpupgrade",
|
||||||
|
"quic",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _qs(query: str) -> dict:
|
def _qs(query: str) -> dict:
|
||||||
return dict(urllib.parse.parse_qsl(query, keep_blank_values=True))
|
return dict(urllib.parse.parse_qsl(query, keep_blank_values=True))
|
||||||
@@ -37,23 +48,37 @@ def _mk_transport(
|
|||||||
host_header: str = "",
|
host_header: str = "",
|
||||||
service_name: str = "",
|
service_name: str = "",
|
||||||
) -> "dict | None":
|
) -> "dict | None":
|
||||||
if transport_type == "ws":
|
normalized = transport_type.lower()
|
||||||
|
|
||||||
|
if normalized in ("", "tcp"):
|
||||||
|
return None
|
||||||
|
if normalized == "ws":
|
||||||
return {
|
return {
|
||||||
"type": "ws",
|
"type": "ws",
|
||||||
"path": urllib.parse.unquote(path),
|
"path": urllib.parse.unquote(path),
|
||||||
"headers": {"Host": host_header},
|
"headers": {"Host": host_header},
|
||||||
}
|
}
|
||||||
if transport_type == "grpc":
|
if normalized == "grpc":
|
||||||
return {
|
return {
|
||||||
"type": "grpc",
|
"type": "grpc",
|
||||||
"service_name": urllib.parse.unquote(service_name),
|
"service_name": urllib.parse.unquote(service_name),
|
||||||
}
|
}
|
||||||
if transport_type == "h2":
|
if normalized in ("h2", "http"):
|
||||||
return {
|
return {
|
||||||
"type": "http",
|
"type": "http",
|
||||||
"host": [host_header],
|
"host": [host_header],
|
||||||
"path": urllib.parse.unquote(path),
|
"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
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -79,6 +104,19 @@ def parse_vless(url: str, tag: str) -> dict:
|
|||||||
userinfo, host, port, params = _parse_url_parts(url, "vless")
|
userinfo, host, port, params = _parse_url_parts(url, "vless")
|
||||||
security = params.get("security", "none")
|
security = params.get("security", "none")
|
||||||
transport = params.get("type", "tcp")
|
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 = {
|
ob: dict = {
|
||||||
"type": "vless",
|
"type": "vless",
|
||||||
@@ -102,7 +140,7 @@ def parse_vless(url: str, tag: str) -> dict:
|
|||||||
)
|
)
|
||||||
|
|
||||||
tr = _mk_transport(
|
tr = _mk_transport(
|
||||||
transport,
|
normalized_transport,
|
||||||
path=params.get("path", "/"),
|
path=params.get("path", "/"),
|
||||||
host_header=params.get("host", host),
|
host_header=params.get("host", host),
|
||||||
service_name=params.get("serviceName", ""),
|
service_name=params.get("serviceName", ""),
|
||||||
|
|||||||
@@ -20,6 +20,42 @@ class BuildOutboundTests(unittest.TestCase):
|
|||||||
self.assertEqual(ob["server"], "example.com")
|
self.assertEqual(ob["server"], "example.com")
|
||||||
self.assertEqual(ob["tls"]["reality"]["public_key"], "pubkey")
|
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):
|
def test_vmess(self):
|
||||||
payload = {
|
payload = {
|
||||||
"add": "vmess.example.com",
|
"add": "vmess.example.com",
|
||||||
@@ -68,7 +104,6 @@ class BuildOutboundTests(unittest.TestCase):
|
|||||||
self.assertEqual(ob["type"], "shadowsocks")
|
self.assertEqual(ob["type"], "shadowsocks")
|
||||||
self.assertEqual(ob["method"], "chacha20-ietf-poly1305")
|
self.assertEqual(ob["method"], "chacha20-ietf-poly1305")
|
||||||
|
|
||||||
|
|
||||||
def test_shadowsocks_legacy_full_base64(self):
|
def test_shadowsocks_legacy_full_base64(self):
|
||||||
legacy = (
|
legacy = (
|
||||||
base64.urlsafe_b64encode(
|
base64.urlsafe_b64encode(
|
||||||
@@ -84,7 +119,6 @@ class BuildOutboundTests(unittest.TestCase):
|
|||||||
self.assertEqual(ob["method"], "chacha20-ietf-poly1305")
|
self.assertEqual(ob["method"], "chacha20-ietf-poly1305")
|
||||||
self.assertEqual(ob["password"], "passw0rd")
|
self.assertEqual(ob["password"], "passw0rd")
|
||||||
|
|
||||||
|
|
||||||
def test_shadowsocks_plain_userinfo(self):
|
def test_shadowsocks_plain_userinfo(self):
|
||||||
ob = run_parser("ss://none:plain%20pass@plain.example.com:8388")
|
ob = run_parser("ss://none:plain%20pass@plain.example.com:8388")
|
||||||
self.assertEqual(ob["type"], "shadowsocks")
|
self.assertEqual(ob["type"], "shadowsocks")
|
||||||
|
|||||||
Reference in new issue
Block a user