From 536bb1cd3e29dac47dad82623d215c5f189ec7d6 Mon Sep 17 00:00:00 2001 From: xream Date: Tue, 11 Aug 2026 00:20:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Surge=20TrustTunnel=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20h3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../core/proxy-utils/parsers/peggy/surge.js | 3 +- .../src/core/proxy-utils/producers/surge.js | 1 + backend/src/test/proxy-producers/text.spec.js | 31 +++++++++++++++++++ scripts/demo.js | 1 + 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/backend/package.json b/backend/package.json index 00823993..8a52b3c8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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", diff --git a/backend/src/core/proxy-utils/parsers/peggy/surge.js b/backend/src/core/proxy-utils/parsers/peggy/surge.js index 4a72a382..8bd5fc58 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/surge.js +++ b/backend/src/core/proxy-utils/parsers/peggy/surge.js @@ -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'; } diff --git a/backend/src/core/proxy-utils/producers/surge.js b/backend/src/core/proxy-utils/producers/surge.js index 1dd23c9a..7544ee99 100644 --- a/backend/src/core/proxy-utils/producers/surge.js +++ b/backend/src/core/proxy-utils/producers/surge.js @@ -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'); diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index f35aeeff..f199ae55 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -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', [ { diff --git a/scripts/demo.js b/scripts/demo.js index bc0c05a2..bec5ae83 100644 --- a/scripts/demo.js +++ b/scripts/demo.js @@ -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 文件