Skip to content

Commit bffe230

Browse files
committed
feat: Surge 支持 TrustTunnel. 根据请求的 User-Agent 中的版本号自动开启, 或使用 includeUnsupportedProxy 参数或开启 包含官方/商店版不支持的协议 开关
1 parent a63bf54 commit bffe230

11 files changed

Lines changed: 107 additions & 5 deletions

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.21.16",
3+
"version": "2.21.17",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/core/proxy-utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ function lastParse(proxy) {
465465
'hysteria2',
466466
'juicity',
467467
'anytls',
468+
'trust-tunnel',
468469
'naive',
469470
].includes(proxy.type)
470471
) {

backend/src/core/proxy-utils/parsers/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,7 @@ function Clash_All() {
12641264
}
12651265
if (
12661266
![
1267+
'trust-tunnel',
12671268
'naive',
12681269
'anytls',
12691270
'mieru',
@@ -1597,6 +1598,14 @@ function Surge_Anytls() {
15971598
const parse = (line) => getSurgeParser().parse(line);
15981599
return { name, test, parse };
15991600
}
1601+
function Surge_TrustTunnel() {
1602+
const name = 'Surge TrustTunnel Parser';
1603+
const test = (line) => {
1604+
return /^.*=\s*trust-tunnel/.test(line.split(',')[0]);
1605+
};
1606+
const parse = (line) => getSurgeParser().parse(line);
1607+
return { name, test, parse };
1608+
}
16001609
function Surge_SSH() {
16011610
const name = 'Surge SSH Parser';
16021611
const test = (line) => {
@@ -1791,6 +1800,7 @@ export default [
17911800
Clash_All(),
17921801
Surge_Direct(),
17931802
Surge_Anytls(),
1803+
Surge_TrustTunnel(),
17941804
Surge_SSH(),
17951805
Surge_SS(),
17961806
Surge_VMess(),

backend/src/core/proxy-utils/parsers/peggy/surge.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const grammars = String.raw`
3737
}
3838
}
3939
40-
start = (anytls/shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/direct) {
40+
start = (anytls/shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/trust_tunnel/direct) {
4141
return proxy;
4242
}
4343
@@ -122,6 +122,11 @@ anytls = tag equals "anytls" address (passwordk/reuse/ip_version/underlying_prox
122122
proxy.type = "anytls";
123123
proxy.tls = true;
124124
}
125+
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)* {
126+
proxy.type = "trust-tunnel";
127+
proxy.tls = true;
128+
}
129+
125130
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)* {
126131
proxy.type = "direct";
127132
}

backend/src/core/proxy-utils/parsers/peggy/surge.peg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
}
3636
}
3737

38-
start = (anytls/shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/direct) {
38+
start = (anytls/shadowsocks/vmess/trojan/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/trust_tunnel/direct) {
3939
return proxy;
4040
}
4141

@@ -120,6 +120,10 @@ anytls = tag equals "anytls" address (passwordk/reuse/ip_version/underlying_prox
120120
proxy.type = "anytls";
121121
proxy.tls = true;
122122
}
123+
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)* {
124+
proxy.type = "trust-tunnel";
125+
proxy.tls = true;
126+
}
123127
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)* {
124128
proxy.type = "direct";
125129
}

backend/src/core/proxy-utils/producers/clash.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export default function Clash_Producer() {
174174
'hysteria2',
175175
'juicity',
176176
'anytls',
177+
'trust-tunnel',
177178
'naive',
178179
].includes(proxy.type)
179180
) {

backend/src/core/proxy-utils/producers/clashmeta.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export default function ClashMeta_Producer() {
1616
if (opts['include-unsupported-proxy']) return true;
1717
if (proxy.type === 'snell' && proxy.version >= 4) {
1818
return false;
19-
} else if (['juicity', 'naive'].includes(proxy.type)) {
19+
} else if (
20+
['trust-tunnel', 'juicity', 'naive'].includes(proxy.type)
21+
) {
2022
return false;
2123
} else if (
2224
['ss'].includes(proxy.type) &&
@@ -249,6 +251,7 @@ export default function ClashMeta_Producer() {
249251
'hysteria2',
250252
'juicity',
251253
'anytls',
254+
'trust-tunnel',
252255
'naive',
253256
].includes(proxy.type)
254257
) {

backend/src/core/proxy-utils/producers/shadowrocket.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ export default function Shadowrocket_Producer() {
99
if (opts['include-unsupported-proxy']) return true;
1010
if (proxy.type === 'snell' && proxy.version >= 4) {
1111
return false;
12-
} else if (['mieru', 'sudoku', 'naive'].includes(proxy.type)) {
12+
} else if (
13+
['trust-tunnel', 'mieru', 'sudoku', 'naive'].includes(
14+
proxy.type,
15+
)
16+
) {
1317
return false;
1418
} else if (
1519
proxy.encryption &&
@@ -219,6 +223,7 @@ export default function Shadowrocket_Producer() {
219223
'hysteria2',
220224
'juicity',
221225
'anytls',
226+
'trust-tunnel',
222227
'naive',
223228
].includes(proxy.type)
224229
) {

backend/src/core/proxy-utils/producers/stash.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ export default function Stash_Producer() {
300300
'hysteria2',
301301
'juicity',
302302
'anytls',
303+
'trust-tunnel',
303304
'naive',
304305
].includes(proxy.type)
305306
) {

backend/src/core/proxy-utils/producers/surge.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export default function Surge_Producer() {
6767

6868
return anytls(proxy);
6969
}
70+
if (
71+
opts['include-unsupported-proxy'] &&
72+
proxy.type === 'trust-tunnel'
73+
) {
74+
return trust_tunnel(proxy);
75+
}
7076
throw new Error(
7177
`Platform ${targetPlatform} does not support proxy type: ${proxy.type}`,
7278
);
@@ -366,6 +372,71 @@ function anytls(proxy) {
366372

367373
return result.toString();
368374
}
375+
function trust_tunnel(proxy) {
376+
const result = new Result(proxy);
377+
result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
378+
result.appendIfPresent(`,password="${proxy.password}"`, 'password');
379+
380+
const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];
381+
result.appendIfPresent(`,ip-version=${ip_version}`, 'ip-version');
382+
383+
result.appendIfPresent(
384+
`,no-error-alert=${proxy['no-error-alert']}`,
385+
'no-error-alert',
386+
);
387+
388+
// tls fingerprint
389+
result.appendIfPresent(
390+
`,server-cert-fingerprint-sha256=${proxy['tls-fingerprint']}`,
391+
'tls-fingerprint',
392+
);
393+
394+
// tls verification
395+
result.appendIfPresent(`,sni=${proxy.sni}`, 'sni');
396+
result.appendIfPresent(
397+
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
398+
'skip-cert-verify',
399+
);
400+
401+
// tfo
402+
result.appendIfPresent(`,tfo=${proxy.tfo}`, 'tfo');
403+
404+
// udp
405+
result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
406+
407+
// test-url
408+
result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url');
409+
result.appendIfPresent(
410+
`,test-timeout=${proxy['test-timeout']}`,
411+
'test-timeout',
412+
);
413+
result.appendIfPresent(`,test-udp=${proxy['test-udp']}`, 'test-udp');
414+
result.appendIfPresent(`,hybrid=${proxy['hybrid']}`, 'hybrid');
415+
result.appendIfPresent(`,tos=${proxy['tos']}`, 'tos');
416+
result.appendIfPresent(
417+
`,allow-other-interface=${proxy['allow-other-interface']}`,
418+
'allow-other-interface',
419+
);
420+
result.appendIfPresent(
421+
`,interface=${proxy['interface-name']}`,
422+
'interface-name',
423+
);
424+
result.appendIfPresent(`,interface=${proxy['interface']}`, 'interface');
425+
426+
// block-quic
427+
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
428+
429+
// underlying-proxy
430+
result.appendIfPresent(
431+
`,underlying-proxy=${proxy['underlying-proxy']}`,
432+
'underlying-proxy',
433+
);
434+
435+
// reuse
436+
result.appendIfPresent(`,reuse=${proxy['reuse']}`, 'reuse');
437+
438+
return result.toString();
439+
}
369440

370441
function vmess(proxy, includeUnsupportedProxy) {
371442
const result = new Result(proxy);

0 commit comments

Comments
 (0)