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

This commit is contained in:
xream committed 2025-12-11 15:45:10 +08:00
1 parent ff614b65f5
commit fede003050
7 files changed
+135 -42

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.20.48",
"version": "2.20.50",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {
@@ -1498,6 +1498,14 @@ function Surge_Direct() {
const parse = (line) => getSurgeParser().parse(line);
return { name, test, parse };
}
function Surge_Anytls() {
const name = 'Surge Anytls Parser';
const test = (line) => {
return /^.*=\s*anytls/.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) => {
@@ -1691,6 +1699,7 @@ export default [
URI_AnyTLS(),
Clash_All(),
Surge_Direct(),
Surge_Anytls(),
Surge_SSH(),
Surge_SS(),
Surge_VMess(),
@@ -37,7 +37,7 @@ const grammars = String.raw`
}
}
start = (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/direct) {
return proxy;
}
@@ -118,6 +118,10 @@ socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek pas
proxy.tls = true;
handleShadowTLS();
}
anytls = tag equals "anytls" address (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 = "anytls";
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";
}
@@ -35,7 +35,7 @@
}
}
start = (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/direct) {
return proxy;
}
@@ -116,6 +116,10 @@ socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek pas
proxy.tls = true;
handleShadowTLS();
}
anytls = tag equals "anytls" address (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 = "anytls";
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";
}
@@ -46,6 +46,9 @@ export default function Surge_Producer() {
if (opts['include-unsupported-proxy'] && proxy.type === 'wireguard') {
return wireguard(proxy);
}
if (opts['include-unsupported-proxy'] && proxy.type === 'anytls') {
return anytls(proxy);
}
throw new Error(
`Platform ${targetPlatform} does not support proxy type: ${proxy.type}`,
);
@@ -278,6 +281,71 @@ function trojan(proxy) {
return result.toString();
}
function anytls(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',
);
// 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);
result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
@@ -139,9 +139,14 @@ export default function URI_Producer() {
}
}
if (
['trojan', 'tuic', 'hysteria', 'hysteria2', 'juicity'].includes(
proxy.type,
)
[
'trojan',
'tuic',
'hysteria',
'hysteria2',
'juicity',
'anytls',
].includes(proxy.type)
) {
delete proxy.tls;
}
+39 -36
View File
@@ -60,42 +60,45 @@ export function getPlatformFromHeaders(headers) {
const { UA, ua, accept } = getUserAgentFromHeaders(headers);
return getPlatformFromUserAgent({ ua, UA, accept });
}
export function shouldIncludeUnsupportedProxy(platform, ua) {
// try {
// const target = getPlatformFromUserAgent({
// UA: ua,
// ua: ua.toLowerCase(),
// });
// if (!['Egern'].includes(target)) {
// return false;
// }
// const coerceVersion = coerce(ua);
// $.log(JSON.stringify(coerceVersion, null, 2));
// const { version } = coerceVersion;
// // if (
// // platform === 'Stash' &&
// // target === 'Stash' &&
// // gte(version, '3.1.0')
// // ) {
// // return true;
// // }
// if (
// platform === 'Egern' &&
// target === 'Egern' &&
// gte(version, '2.7.0')
// ) {
// return true;
// }
// // Loon 的 UA 不规范, version 取出来是 build
// // if (
// // platform === 'Loon' &&
// // target === 'Loon' &&
// // gte(version, '842.0.0')
// // ) {
// // return true;
// // }
// } catch (e) {
// $.error(`获取版本号失败: ${e}`);
// }
try {
const target = getPlatformFromUserAgent({
UA: ua,
ua: ua.toLowerCase(),
});
const coerceVersion = coerce(ua);
const { major } = coerceVersion;
if (
(target === 'SurgeMac' && major >= 9860) ||
(target === 'Surge' && major >= 3613)
) {
return true;
}
// // if (
// // platform === 'Stash' &&
// // target === 'Stash' &&
// // gte(version, '3.1.0')
// // ) {
// // return true;
// // }
// if (
// platform === 'Egern' &&
// target === 'Egern' &&
// gte(version, '2.7.0')
// ) {
// return true;
// }
// // Loon 的 UA 不规范, version 取出来是 build
// // if (
// // platform === 'Loon' &&
// // target === 'Loon' &&
// // gte(version, '842.0.0')
// // ) {
// // return true;
// // }
} catch (e) {
// $.error(`获取版本号失败: ${e}`);
}
return false;
}