From bffe2307852bdd38c249149928e45274428a67dd Mon Sep 17 00:00:00 2001 From: xream Date: Tue, 27 Jan 2026 16:05:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Surge=20=E6=94=AF=E6=8C=81=20TrustTunne?= =?UTF-8?q?l.=20=E6=A0=B9=E6=8D=AE=E8=AF=B7=E6=B1=82=E7=9A=84=20User-Agent?= =?UTF-8?q?=20=E4=B8=AD=E7=9A=84=E7=89=88=E6=9C=AC=E5=8F=B7=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=BC=80=E5=90=AF,=20=E6=88=96=E4=BD=BF=E7=94=A8=20in?= =?UTF-8?q?cludeUnsupportedProxy=20=E5=8F=82=E6=95=B0=E6=88=96=E5=BC=80?= =?UTF-8?q?=E5=90=AF=20=E5=8C=85=E5=90=AB=E5=AE=98=E6=96=B9/=E5=95=86?= =?UTF-8?q?=E5=BA=97=E7=89=88=E4=B8=8D=E6=94=AF=E6=8C=81=E7=9A=84=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=20=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/index.js | 1 + backend/src/core/proxy-utils/parsers/index.js | 10 +++ .../core/proxy-utils/parsers/peggy/surge.js | 7 +- .../core/proxy-utils/parsers/peggy/surge.peg | 6 +- .../src/core/proxy-utils/producers/clash.js | 1 + .../core/proxy-utils/producers/clashmeta.js | 5 +- .../proxy-utils/producers/shadowrocket.js | 7 +- .../src/core/proxy-utils/producers/stash.js | 1 + .../src/core/proxy-utils/producers/surge.js | 71 +++++++++++++++++++ backend/src/core/proxy-utils/producers/uri.js | 1 + 11 files changed, 107 insertions(+), 5 deletions(-) diff --git a/backend/package.json b/backend/package.json index e5cf57f2..90082826 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.21.16", + "version": "2.21.17", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 3f266905..49d85323 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -465,6 +465,7 @@ function lastParse(proxy) { 'hysteria2', 'juicity', 'anytls', + 'trust-tunnel', 'naive', ].includes(proxy.type) ) { diff --git a/backend/src/core/proxy-utils/parsers/index.js b/backend/src/core/proxy-utils/parsers/index.js index 64503971..917cb9b6 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -1264,6 +1264,7 @@ function Clash_All() { } if ( ![ + 'trust-tunnel', 'naive', 'anytls', 'mieru', @@ -1597,6 +1598,14 @@ function Surge_Anytls() { const parse = (line) => getSurgeParser().parse(line); return { name, test, parse }; } +function Surge_TrustTunnel() { + const name = 'Surge TrustTunnel Parser'; + const test = (line) => { + return /^.*=\s*trust-tunnel/.test(line.split(',')[0]); + }; + const parse = (line) => getSurgeParser().parse(line); + return { name, test, parse }; +} function Surge_SSH() { const name = 'Surge SSH Parser'; const test = (line) => { @@ -1791,6 +1800,7 @@ export default [ Clash_All(), Surge_Direct(), Surge_Anytls(), + Surge_TrustTunnel(), Surge_SSH(), Surge_SS(), Surge_VMess(), diff --git a/backend/src/core/proxy-utils/parsers/peggy/surge.js b/backend/src/core/proxy-utils/parsers/peggy/surge.js index 85f83fd7..3c90d79f 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/surge.js +++ b/backend/src/core/proxy-utils/parsers/peggy/surge.js @@ -37,7 +37,7 @@ const grammars = String.raw` } } -start = (anytls/shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/direct) { +start = (anytls/shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/trust_tunnel/direct) { return proxy; } @@ -122,6 +122,11 @@ 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/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/tls_verification/sni/fast_open/tfo/block_quic/others)* { + proxy.type = "trust-tunnel"; + proxy.tls = true; +} + direct = tag equals "direct" (udp_relay/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/block_quic/others)* { proxy.type = "direct"; } diff --git a/backend/src/core/proxy-utils/parsers/peggy/surge.peg b/backend/src/core/proxy-utils/parsers/peggy/surge.peg index f110dac2..1545c7f3 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/surge.peg +++ b/backend/src/core/proxy-utils/parsers/peggy/surge.peg @@ -35,7 +35,7 @@ } } -start = (anytls/shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/direct) { +start = (anytls/shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/trust_tunnel/direct) { return proxy; } @@ -120,6 +120,10 @@ 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/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/tls_verification/sni/fast_open/tfo/block_quic/others)* { + proxy.type = "trust-tunnel"; + proxy.tls = true; +} direct = tag equals "direct" (udp_relay/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/block_quic/others)* { proxy.type = "direct"; } diff --git a/backend/src/core/proxy-utils/producers/clash.js b/backend/src/core/proxy-utils/producers/clash.js index 2975710a..e9b78d15 100644 --- a/backend/src/core/proxy-utils/producers/clash.js +++ b/backend/src/core/proxy-utils/producers/clash.js @@ -174,6 +174,7 @@ export default function Clash_Producer() { 'hysteria2', 'juicity', 'anytls', + 'trust-tunnel', 'naive', ].includes(proxy.type) ) { diff --git a/backend/src/core/proxy-utils/producers/clashmeta.js b/backend/src/core/proxy-utils/producers/clashmeta.js index e321b36c..70bb42d2 100644 --- a/backend/src/core/proxy-utils/producers/clashmeta.js +++ b/backend/src/core/proxy-utils/producers/clashmeta.js @@ -16,7 +16,9 @@ export default function ClashMeta_Producer() { if (opts['include-unsupported-proxy']) return true; if (proxy.type === 'snell' && proxy.version >= 4) { return false; - } else if (['juicity', 'naive'].includes(proxy.type)) { + } else if ( + ['trust-tunnel', 'juicity', 'naive'].includes(proxy.type) + ) { return false; } else if ( ['ss'].includes(proxy.type) && @@ -249,6 +251,7 @@ export default function ClashMeta_Producer() { 'hysteria2', 'juicity', 'anytls', + 'trust-tunnel', 'naive', ].includes(proxy.type) ) { diff --git a/backend/src/core/proxy-utils/producers/shadowrocket.js b/backend/src/core/proxy-utils/producers/shadowrocket.js index 5a7115b0..f8b80e27 100644 --- a/backend/src/core/proxy-utils/producers/shadowrocket.js +++ b/backend/src/core/proxy-utils/producers/shadowrocket.js @@ -9,7 +9,11 @@ export default function Shadowrocket_Producer() { if (opts['include-unsupported-proxy']) return true; if (proxy.type === 'snell' && proxy.version >= 4) { return false; - } else if (['mieru', 'sudoku', 'naive'].includes(proxy.type)) { + } else if ( + ['trust-tunnel', 'mieru', 'sudoku', 'naive'].includes( + proxy.type, + ) + ) { return false; } else if ( proxy.encryption && @@ -219,6 +223,7 @@ export default function Shadowrocket_Producer() { 'hysteria2', 'juicity', 'anytls', + 'trust-tunnel', 'naive', ].includes(proxy.type) ) { diff --git a/backend/src/core/proxy-utils/producers/stash.js b/backend/src/core/proxy-utils/producers/stash.js index fd364e51..79e14c02 100644 --- a/backend/src/core/proxy-utils/producers/stash.js +++ b/backend/src/core/proxy-utils/producers/stash.js @@ -300,6 +300,7 @@ export default function Stash_Producer() { 'hysteria2', 'juicity', 'anytls', + 'trust-tunnel', 'naive', ].includes(proxy.type) ) { diff --git a/backend/src/core/proxy-utils/producers/surge.js b/backend/src/core/proxy-utils/producers/surge.js index 7df20126..8d59eb55 100644 --- a/backend/src/core/proxy-utils/producers/surge.js +++ b/backend/src/core/proxy-utils/producers/surge.js @@ -67,6 +67,12 @@ export default function Surge_Producer() { return anytls(proxy); } + if ( + opts['include-unsupported-proxy'] && + proxy.type === 'trust-tunnel' + ) { + return trust_tunnel(proxy); + } throw new Error( `Platform ${targetPlatform} does not support proxy type: ${proxy.type}`, ); @@ -366,6 +372,71 @@ function anytls(proxy) { return result.toString(); } +function trust_tunnel(proxy) { + const result = new Result(proxy); + result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`); + result.appendIfPresent(`,password="${proxy.password}"`, 'password'); + + const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version']; + result.appendIfPresent(`,ip-version=${ip_version}`, 'ip-version'); + + result.appendIfPresent( + `,no-error-alert=${proxy['no-error-alert']}`, + 'no-error-alert', + ); + + // tls fingerprint + result.appendIfPresent( + `,server-cert-fingerprint-sha256=${proxy['tls-fingerprint']}`, + 'tls-fingerprint', + ); + + // tls verification + result.appendIfPresent(`,sni=${proxy.sni}`, 'sni'); + result.appendIfPresent( + `,skip-cert-verify=${proxy['skip-cert-verify']}`, + 'skip-cert-verify', + ); + + // tfo + result.appendIfPresent(`,tfo=${proxy.tfo}`, 'tfo'); + + // udp + result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp'); + + // test-url + result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url'); + result.appendIfPresent( + `,test-timeout=${proxy['test-timeout']}`, + 'test-timeout', + ); + result.appendIfPresent(`,test-udp=${proxy['test-udp']}`, 'test-udp'); + result.appendIfPresent(`,hybrid=${proxy['hybrid']}`, 'hybrid'); + result.appendIfPresent(`,tos=${proxy['tos']}`, 'tos'); + result.appendIfPresent( + `,allow-other-interface=${proxy['allow-other-interface']}`, + 'allow-other-interface', + ); + result.appendIfPresent( + `,interface=${proxy['interface-name']}`, + 'interface-name', + ); + result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface'); + + // block-quic + result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic'); + + // underlying-proxy + result.appendIfPresent( + `,underlying-proxy=${proxy['underlying-proxy']}`, + 'underlying-proxy', + ); + + // reuse + result.appendIfPresent(`,reuse=${proxy['reuse']}`, 'reuse'); + + return result.toString(); +} function vmess(proxy, includeUnsupportedProxy) { const result = new Result(proxy); diff --git a/backend/src/core/proxy-utils/producers/uri.js b/backend/src/core/proxy-utils/producers/uri.js index 07c868af..22a59c58 100644 --- a/backend/src/core/proxy-utils/producers/uri.js +++ b/backend/src/core/proxy-utils/producers/uri.js @@ -157,6 +157,7 @@ export default function URI_Producer() { 'hysteria2', 'juicity', 'anytls', + 'trust-tunnel', ].includes(proxy.type) ) { delete proxy.tls;