feat: Surge TrustTunnel 支持 h3

This commit is contained in:
xream committed 2026-08-11 00:20:52 +08:00
1 parent 744941cdce
commit 536bb1cd3e
5 files changed
+36 -2

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.36.33",
"version": "2.36.34",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"packageManager": "pnpm@11.0.9",
@@ -459,7 +459,7 @@ anytls = tag equals "anytls" address (passwordk/reuse/ip_version/underlying_prox
proxy.type = "anytls";
proxy.tls = true;
}
trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/headers/max_streams/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/tls_verification/client_cert/sni/cert_verify_name/alpn/fast_open/tfo/block_quic/others)* {
trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/headers/max_streams/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/tls_verification/client_cert/sni/cert_verify_name/alpn/h3/fast_open/tfo/block_quic/others)* {
proxy.type = "trusttunnel";
proxy.tls = true;
}
@@ -619,6 +619,7 @@ alpn = comma "alpn" equals match:quoted_value {
const values = parseAlpn(match);
if (values.length > 0) proxy.alpn = values;
}
h3 = comma "h3" equals flag:bool { if (flag) proxy.network = "h3"; }
quoted_value = '"' match:$[^"]* '"' { return match; } / "'" match:$[^']* "'" { return match; } / match:$[^,]+ { return match; }
uuidk = comma "uuid" equals match:[^,]+ { proxy.uuid = match.join(""); }
salamander_password = comma "salamander-password" equals match:[^,]+ { proxy['obfs-password'] = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); proxy.obfs = 'salamander'; }
@@ -462,6 +462,7 @@ function trusttunnel(proxy) {
`,max-streams=${proxy['max-streams']}`,
'max-streams',
);
if (proxy.network === 'h3') result.append(',h3=true');
const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];
result.appendIfPresent(`,ip-version=${ip_version}`, 'ip-version');
@@ -998,6 +998,37 @@ describe('Proxy text producers', function () {
});
});
it('round-trips Surge TrustTunnel h3 as network', function () {
const [proxy] = ProxyUtils.parse(
'Surge TrustTunnel H3 = trust-tunnel,trust.example.com,443,h3=true',
);
expect(proxy.network).to.equal('h3');
expect(proxy).to.not.have.property('alpn');
const output = produceExternal('Surge', proxy);
expect(output).to.include(',h3=true');
expect(output).to.not.include(',alpn=');
const [disabled] = ProxyUtils.parse(
'Surge TrustTunnel H3 Disabled = trust-tunnel,trust.example.com,443,h3=false',
);
expect(disabled).to.not.have.property('network');
const disabledOutput = produceExternal('Surge', disabled);
expect(disabledOutput).to.not.include(',h3=true');
expect(disabledOutput).to.not.include(',alpn=');
const alpnOutput = produceExternal('Surge', {
type: 'trusttunnel',
name: 'Surge TrustTunnel ALPN H3',
server: 'trust.example.com',
port: 443,
alpn: ['h3'],
});
expect(alpnOutput).to.include(',alpn="h3"');
expect(alpnOutput).to.not.include(',h3=true');
});
it('omits Surge alpn and server-cert-verify-name for non-TLS outputs', function () {
const output = produceExternal('Surge', [
{
+1
View File
@@ -59,6 +59,7 @@ function operator(proxies = [], targetPlatform, context) {
// 34. VLESS/Trojan URI 的 `vcn` 对应 mihomo 的 `name-cert-verify`. Xray-core 支持用逗号分隔多个 name, mihomo 只支持一个, 因此输入时取第一个有效值, 同时用 `_vcn` 数组保留全部有效值; 输出 URI 时优先用 `_vcn` 还原为 `vcn`, 没有 `_vcn` 时才使用 `name-cert-verify`. 若想设置为其他值, 可使用脚本操作设置, 例如 `$server["name-cert-verify"] = $server._vcn?.[1] || $server._vcn?.[0]`
// 35. sing-box AnyTLS 支持通过节点的字符串字段 `client-metadata` 设置 `client_metadata`
// 36. sing-box Hysteria 2 支持通过节点的字符串字段 `disable-chrome-parrot` 设置 `disable_chrome_parrot`
// 37. Surge TrustTunnel 支持使用 Surge 格式写 `h3=true` 作为输入, 或使用节点字段 `network: 'h3'` 设置 `h3=true`
// require 为 Node.js 的 require, 在 Node.js 运行环境下 可以用来引入模块
// 例如在 Node.js 环境下, 将文件内容写入 /tmp/1.txt 文件