mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 23:13:43 +00:00
feat: mihomo 输出 snell 支持 shadow-tls(shadowrocket 我也先加了); Loon/Surge/sing-box shadow-tls 支持 apln; Loon shadow-tls 支持 tls-profile
This commit is contained in:
12 files changed
+517
-19
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.32.1",
|
||||
"version": "2.33.0",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -768,6 +768,26 @@ function lastParse(proxy) {
|
||||
.replace(/^\[/, '')
|
||||
.replace(/\]$/, '');
|
||||
}
|
||||
if (
|
||||
proxy.type === 'snell' &&
|
||||
proxy['obfs-opts']?.mode === 'shadow-tls' &&
|
||||
!proxy.plugin
|
||||
) {
|
||||
proxy.plugin = 'shadow-tls';
|
||||
proxy['plugin-opts'] = {
|
||||
host: proxy['obfs-opts'].host,
|
||||
password: proxy['obfs-opts'].password,
|
||||
version: proxy['obfs-opts'].version,
|
||||
alpn: proxy['obfs-opts'].alpn,
|
||||
};
|
||||
delete proxy['obfs-opts'];
|
||||
}
|
||||
if (proxy.plugin === 'shadow-tls' && proxy['plugin-opts']) {
|
||||
if (proxy.alpn && !proxy['plugin-opts'].alpn) {
|
||||
proxy['plugin-opts'].alpn = proxy.alpn;
|
||||
}
|
||||
delete proxy.alpn;
|
||||
}
|
||||
if (proxy.network === 'ws') {
|
||||
if (!proxy['ws-opts'] && (proxy['ws-path'] || proxy['ws-headers'])) {
|
||||
proxy['ws-opts'] = {};
|
||||
|
||||
@@ -37,12 +37,19 @@ const grammars = String.raw`
|
||||
|
||||
function handleShadowTLS() {
|
||||
if (shadowTLS.password) {
|
||||
if (shadowTLS.version < 2) {
|
||||
throw new Error("shadow-tls version " + shadowTLS.version + " is not supported");
|
||||
}
|
||||
proxy.plugin = "shadow-tls";
|
||||
proxy["plugin-opts"] = {
|
||||
host: shadowTLS.host,
|
||||
password: shadowTLS.password,
|
||||
version: shadowTLS.version,
|
||||
};
|
||||
if (proxy.alpn) {
|
||||
$set(proxy, "plugin-opts.alpn", proxy.alpn);
|
||||
delete proxy.alpn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,13 +75,13 @@ start = (shadowsocksr/shadowsocks/vmess/vless/trojan/https/http/socks5/hysteria2
|
||||
return proxy;
|
||||
}
|
||||
|
||||
shadowsocksr = tag equals "shadowsocksr"i address method password (ssr_protocol/ssr_protocol_param/obfs_ssr/obfs_ssr_param/obfs_host/obfs_uri/fast_open/udp_relay/udp_port/shadow_tls_version/shadow_tls_sni/shadow_tls_password/ip_mode/block_quic/others)*{
|
||||
shadowsocksr = tag equals "shadowsocksr"i address method password (ssr_protocol/ssr_protocol_param/obfs_ssr/obfs_ssr_param/obfs_host/obfs_uri/fast_open/udp_relay/udp_port/tls_profile/alpn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/ip_mode/block_quic/others)*{
|
||||
proxy.type = "ssr";
|
||||
// handle ssr obfs
|
||||
proxy.obfs = obfs.type;
|
||||
handleShadowTLS();
|
||||
}
|
||||
shadowsocks = tag equals "shadowsocks"i address method password (obfs_typev obfs_hostv)? (obfs_ss/obfs_host/obfs_uri/fast_open/udp_relay/udp_port/shadow_tls_version/shadow_tls_sni/shadow_tls_password/ip_mode/block_quic/udp_over_tcp/others)* {
|
||||
shadowsocks = tag equals "shadowsocks"i address method password (obfs_typev obfs_hostv)? (obfs_ss/obfs_host/obfs_uri/fast_open/udp_relay/udp_port/tls_profile/alpn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/ip_mode/block_quic/udp_over_tcp/others)* {
|
||||
proxy.type = "ss";
|
||||
// handle ss obfs
|
||||
if (obfs.type == "http" || obfs.type === "tls") {
|
||||
|
||||
@@ -36,12 +36,19 @@ const grammars = String.raw`
|
||||
shadowTLS.version = 2;
|
||||
}
|
||||
if (shadowTLS.password) {
|
||||
if (shadowTLS.version < 2) {
|
||||
throw new Error("shadow-tls version " + shadowTLS.version + " is not supported");
|
||||
}
|
||||
proxy.plugin = "shadow-tls";
|
||||
proxy["plugin-opts"] = {
|
||||
host: shadowTLS.host,
|
||||
password: shadowTLS.password,
|
||||
version: shadowTLS.version,
|
||||
};
|
||||
if (proxy.alpn) {
|
||||
$set(proxy, "plugin-opts.alpn", proxy.alpn);
|
||||
delete proxy.alpn;
|
||||
}
|
||||
}
|
||||
}
|
||||
function stripQuotes(value) {
|
||||
@@ -366,7 +373,7 @@ start = (anytls/shadowsocks/vmess/trojan/h2_connect/https/http/snell/socks5/sock
|
||||
return proxy;
|
||||
}
|
||||
|
||||
shadowsocks = tag equals "ss" address (method/passwordk/obfs/obfs_host/obfs_uri/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/udp_port/others)* {
|
||||
shadowsocks = tag equals "ss" address (method/passwordk/obfs/obfs_host/obfs_uri/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/alpn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/udp_port/others)* {
|
||||
proxy.type = "ss";
|
||||
// handle obfs
|
||||
if (obfs.type == "http" || obfs.type === "tls") {
|
||||
@@ -412,7 +419,7 @@ ssh = tag equals "ssh" address (username password)? (usernamek passwordk)? (serv
|
||||
proxy.type = "ssh";
|
||||
handleShadowTLS();
|
||||
}
|
||||
snell = tag equals "snell" address (snell_version/snell_mode/snell_psk/obfs/obfs_host/obfs_uri/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/reuse/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
snell = tag equals "snell" address (snell_version/snell_mode/snell_psk/obfs/obfs_host/obfs_uri/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/reuse/alpn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
proxy.type = "snell";
|
||||
// handle obfs
|
||||
if (obfs.type == "http" || obfs.type === "tls") {
|
||||
|
||||
@@ -76,13 +76,18 @@ export default function ClashMeta_Producer() {
|
||||
return false;
|
||||
} else if (
|
||||
hasMihomoShadowTls(proxy) &&
|
||||
(proxy.type !== 'ss' ||
|
||||
(!['ss', 'snell'].includes(proxy.type) ||
|
||||
!isSupportedMihomoVersion(
|
||||
getMihomoShadowTlsVersion(proxy),
|
||||
[1, 2, 3],
|
||||
))
|
||||
) {
|
||||
return false;
|
||||
} else if (hasMihomoSnellShadowTlsObfsConflict(proxy)) {
|
||||
$.error(
|
||||
`Platform Mihomo does not support Snell shadow-tls with obfs for proxy ${proxy.name}. Proxy has been filtered.`,
|
||||
);
|
||||
return false;
|
||||
} else if (['juicity', 'naive'].includes(proxy.type)) {
|
||||
return false;
|
||||
} else if (
|
||||
@@ -255,6 +260,23 @@ export default function ClashMeta_Producer() {
|
||||
);
|
||||
}
|
||||
|
||||
if (proxy.type === 'snell') {
|
||||
const shadowTLSOpts = getMihomoShadowTlsOpts(proxy);
|
||||
if (shadowTLSOpts) {
|
||||
proxy['obfs-opts'] = {
|
||||
mode: 'shadow-tls',
|
||||
host: shadowTLSOpts.host,
|
||||
password: shadowTLSOpts.password,
|
||||
version: shadowTLSOpts.version,
|
||||
};
|
||||
if (shadowTLSOpts.alpn) {
|
||||
proxy['obfs-opts'].alpn = shadowTLSOpts.alpn;
|
||||
}
|
||||
delete proxy.plugin;
|
||||
delete proxy['plugin-opts'];
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
['vmess', 'vless'].includes(proxy.type) &&
|
||||
proxy.network === 'http'
|
||||
@@ -413,11 +435,29 @@ function isSupportedMihomoVersion(version, supportedVersions) {
|
||||
}
|
||||
|
||||
function hasMihomoShadowTls(proxy) {
|
||||
return proxy?.plugin === 'shadow-tls';
|
||||
return Boolean(getMihomoShadowTlsOpts(proxy));
|
||||
}
|
||||
|
||||
function hasMihomoSnellShadowTlsObfsConflict(proxy) {
|
||||
return (
|
||||
proxy?.type === 'snell' &&
|
||||
proxy?.plugin === 'shadow-tls' &&
|
||||
(isPresent(proxy, 'obfs-opts.mode') ||
|
||||
isPresent(proxy, 'obfs-opts.host') ||
|
||||
isPresent(proxy, 'obfs-opts.path'))
|
||||
);
|
||||
}
|
||||
|
||||
function getMihomoShadowTlsVersion(proxy) {
|
||||
return proxy?.plugin === 'shadow-tls'
|
||||
? proxy?.['plugin-opts']?.version
|
||||
: undefined;
|
||||
return getMihomoShadowTlsOpts(proxy)?.version;
|
||||
}
|
||||
|
||||
function getMihomoShadowTlsOpts(proxy) {
|
||||
if (proxy?.plugin === 'shadow-tls' && proxy?.['plugin-opts']) {
|
||||
return proxy['plugin-opts'];
|
||||
}
|
||||
if (proxy?.type === 'snell' && proxy?.['obfs-opts']?.mode === 'shadow-tls') {
|
||||
return proxy['obfs-opts'];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -69,6 +69,15 @@ function appendAlpn(result, proxy) {
|
||||
if (alpn) result.append(`,alpn="${alpn}"`);
|
||||
}
|
||||
|
||||
function getLoonShadowTLSAlpn(proxy) {
|
||||
const values = proxy?.['plugin-opts']?.alpn ?? proxy?.alpn;
|
||||
const normalized = Array.isArray(values) ? values : `${values || ''}`.split(',');
|
||||
return normalized
|
||||
.map((item) => `${item}`.trim())
|
||||
.filter((item) => item !== '')
|
||||
.join(',');
|
||||
}
|
||||
|
||||
function appendShadowTLS(result, proxy) {
|
||||
if (proxy.plugin !== 'shadow-tls' || !proxy['plugin-opts']) return;
|
||||
|
||||
@@ -85,6 +94,9 @@ function appendShadowTLS(result, proxy) {
|
||||
}
|
||||
result.append(`,shadow-tls-version=${version}`);
|
||||
}
|
||||
appendTlsProfile(result, proxy);
|
||||
const alpn = getLoonShadowTLSAlpn(proxy);
|
||||
if (alpn) result.append(`,alpn="${alpn}"`);
|
||||
result.appendIfPresent(`,udp-port=${proxy['udp-port']}`, 'udp-port');
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,11 @@ export default function Shadowrocket_Producer() {
|
||||
![1, 2, 3, 4, 5].includes(proxy.version)
|
||||
) {
|
||||
return false;
|
||||
} else if (hasShadowrocketSnellShadowTlsObfsConflict(proxy)) {
|
||||
$.error(
|
||||
`Platform Shadowrocket does not support Snell shadow-tls with obfs for proxy ${proxy.name}. Proxy has been filtered.`,
|
||||
);
|
||||
return false;
|
||||
} else if (
|
||||
[
|
||||
'tailscale',
|
||||
@@ -134,8 +139,24 @@ export default function Shadowrocket_Producer() {
|
||||
proxy['pre-shared-key'] = proxy['preshared-key'];
|
||||
proxy.ip = getWireGuardAddressWithCIDR(proxy, 'ipv4');
|
||||
proxy.ipv6 = getWireGuardAddressWithCIDR(proxy, 'ipv6');
|
||||
} else if (proxy.type === 'snell' && proxy.version < 3) {
|
||||
delete proxy.udp;
|
||||
} else if (proxy.type === 'snell') {
|
||||
if (proxy.version < 3) {
|
||||
delete proxy.udp;
|
||||
}
|
||||
if (proxy.plugin === 'shadow-tls' && proxy['plugin-opts']) {
|
||||
proxy['obfs-opts'] = {
|
||||
mode: 'shadow-tls',
|
||||
host: proxy['plugin-opts'].host,
|
||||
password: proxy['plugin-opts'].password,
|
||||
version: proxy['plugin-opts'].version,
|
||||
};
|
||||
if (proxy['plugin-opts'].alpn) {
|
||||
proxy['obfs-opts'].alpn =
|
||||
proxy['plugin-opts'].alpn;
|
||||
}
|
||||
delete proxy.plugin;
|
||||
delete proxy['plugin-opts'];
|
||||
}
|
||||
} else if (proxy.type === 'vless') {
|
||||
if (isPresent(proxy, 'sni')) {
|
||||
proxy.servername = proxy.sni;
|
||||
@@ -278,3 +299,13 @@ export default function Shadowrocket_Producer() {
|
||||
};
|
||||
return { type, produce };
|
||||
}
|
||||
|
||||
function hasShadowrocketSnellShadowTlsObfsConflict(proxy) {
|
||||
return (
|
||||
proxy?.type === 'snell' &&
|
||||
proxy?.plugin === 'shadow-tls' &&
|
||||
(isPresent(proxy, 'obfs-opts.mode') ||
|
||||
isPresent(proxy, 'obfs-opts.host') ||
|
||||
isPresent(proxy, 'obfs-opts.path'))
|
||||
);
|
||||
}
|
||||
@@ -529,6 +529,17 @@ const getShadowTLSPluginOpts = (proxy = {}) => {
|
||||
if (proxy.plugin === 'shadow-tls' && proxy['plugin-opts']) {
|
||||
return proxy['plugin-opts'];
|
||||
}
|
||||
if (
|
||||
proxy.type === 'snell' &&
|
||||
proxy['obfs-opts']?.mode === 'shadow-tls'
|
||||
) {
|
||||
return {
|
||||
host: proxy['obfs-opts'].host,
|
||||
password: proxy['obfs-opts'].password,
|
||||
version: proxy['obfs-opts'].version,
|
||||
alpn: proxy['obfs-opts'].alpn,
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@@ -567,7 +578,7 @@ const shadowTLSOutboundParser = (proxy = {}, pluginOpts) => {
|
||||
}
|
||||
if (stPart.server_port < 0 || stPart.server_port > 65535)
|
||||
throw '端口值非法';
|
||||
const alpn = normalizeALPN(pluginOpts.alpn);
|
||||
const alpn = normalizeALPN(pluginOpts.alpn) ?? normalizeALPN(proxy.alpn);
|
||||
if (alpn) stPart.tls.alpn = alpn;
|
||||
if (proxy['fast-open'] === true) stPart.udp_fragment = true;
|
||||
tfoParser(proxy, stPart);
|
||||
@@ -723,9 +734,15 @@ const snellParser = (proxy = {}) => {
|
||||
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
||||
throw 'invalid port';
|
||||
if (version != null) parsedProxy.version = version;
|
||||
if (proxy['obfs-opts']?.mode)
|
||||
if (
|
||||
proxy['obfs-opts']?.mode &&
|
||||
proxy['obfs-opts'].mode !== 'shadow-tls'
|
||||
)
|
||||
parsedProxy.obfs_mode = proxy['obfs-opts'].mode;
|
||||
if (proxy['obfs-opts']?.host)
|
||||
if (
|
||||
proxy['obfs-opts']?.host &&
|
||||
proxy['obfs-opts']?.mode !== 'shadow-tls'
|
||||
)
|
||||
parsedProxy.obfs_host = proxy['obfs-opts'].host;
|
||||
if (proxy.reuse && (version == null || version >= 4))
|
||||
parsedProxy.reuse = true;
|
||||
|
||||
@@ -65,6 +65,10 @@ function appendAlpn(result, proxy) {
|
||||
if (alpn) result.append(`,alpn="${alpn}"`);
|
||||
}
|
||||
|
||||
function getShadowTLSAlpn(proxy) {
|
||||
return formatSurgeAlpn(proxy?.['plugin-opts']?.alpn ?? proxy?.alpn);
|
||||
}
|
||||
|
||||
function appendShadowTLS(result, proxy, includeUdpPort = false) {
|
||||
if (proxy.plugin !== 'shadow-tls' || !proxy['plugin-opts']) return;
|
||||
|
||||
@@ -81,6 +85,8 @@ function appendShadowTLS(result, proxy, includeUdpPort = false) {
|
||||
}
|
||||
result.append(`,shadow-tls-version=${version}`);
|
||||
}
|
||||
const alpn = getShadowTLSAlpn(proxy);
|
||||
if (alpn) result.append(`,alpn="${alpn}"`);
|
||||
if (includeUdpPort) {
|
||||
result.appendIfPresent(`,udp-port=${proxy['udp-port']}`, 'udp-port');
|
||||
}
|
||||
@@ -96,7 +102,9 @@ function appendTlsProxyParams(result, proxy, enabled = true) {
|
||||
'tls-fingerprint',
|
||||
);
|
||||
result.appendIfPresent(`,sni="${proxy.sni}"`, 'sni');
|
||||
appendAlpn(result, proxy);
|
||||
if (proxy.plugin !== 'shadow-tls') {
|
||||
appendAlpn(result, proxy);
|
||||
}
|
||||
result.appendIfPresent(
|
||||
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
|
||||
'skip-cert-verify',
|
||||
|
||||
@@ -2892,6 +2892,41 @@ describe('Platform raw-format parser coverage', function () {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'parses shadowsocks shadow-tls alpn into plugin opts',
|
||||
input: 'Loon ShadowTLS ALPN=shadowsocks,loon-st.example.com,8388,aes-128-gcm,"secret",shadow-tls-password=shadow-pass,shadow-tls-sni=mask.example.com,shadow-tls-version=3,alpn="h2,http/1.1"',
|
||||
expected: {
|
||||
type: 'ss',
|
||||
name: 'Loon ShadowTLS ALPN',
|
||||
server: 'loon-st.example.com',
|
||||
port: 8388,
|
||||
cipher: 'aes-128-gcm',
|
||||
password: 'secret',
|
||||
plugin: 'shadow-tls',
|
||||
'plugin-opts': {
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 3,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'parses shadowsocks shadow-tls tls-profile into internal loon fields',
|
||||
input: 'Loon ShadowTLS TLS Profile=shadowsocks,loon-st.example.com,8388,aes-128-gcm,"secret",shadow-tls-password=shadow-pass,shadow-tls-sni=mask.example.com,shadow-tls-version=3,tls-profile=ios26',
|
||||
expected: {
|
||||
type: 'ss',
|
||||
name: 'Loon ShadowTLS TLS Profile',
|
||||
plugin: 'shadow-tls',
|
||||
'plugin-opts': {
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 3,
|
||||
},
|
||||
_loon_tls_profile: 'ios26',
|
||||
'client-fingerprint': 'ios',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'parses shadowsocksr lines',
|
||||
input: 'Loon SSR=shadowsocksr,loon-ssr.example.com,8389,aes-256-cfb,"secret",protocol=auth_chain_b,protocol-param=device-id,obfs=tls1.2_ticket_fastauth,obfs-param=cdn.example.com',
|
||||
@@ -3277,6 +3312,14 @@ describe('Platform raw-format parser coverage', function () {
|
||||
),
|
||||
).to.have.length(0);
|
||||
});
|
||||
|
||||
it('rejects Loon shadow-tls version 1 lines', function () {
|
||||
expect(
|
||||
parseAll(
|
||||
'Loon ShadowTLS Invalid=shadowsocks,loon-invalid.example.com,8388,aes-128-gcm,"secret",shadow-tls-password=shadow-pass,shadow-tls-sni=mask.example.com,shadow-tls-version=1,alpn="h2"',
|
||||
),
|
||||
).to.have.length(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Surge raw inputs', function () {
|
||||
@@ -3669,6 +3712,25 @@ describe('Platform raw-format parser coverage', function () {
|
||||
udp: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'parses snell shadow-tls alpn into plugin opts',
|
||||
input: 'Surge Snell ShadowTLS ALPN = snell,surge-snell-alpn.example.com,443,psk=secret,version=5,alpn="h2,http/1.1",shadow-tls-password=shadow-pass,shadow-tls-sni=mask.example.com,shadow-tls-version=3',
|
||||
expected: {
|
||||
type: 'snell',
|
||||
name: 'Surge Snell ShadowTLS ALPN',
|
||||
server: 'surge-snell-alpn.example.com',
|
||||
port: 443,
|
||||
psk: 'secret',
|
||||
version: 5,
|
||||
plugin: 'shadow-tls',
|
||||
'plugin-opts': {
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 3,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'parses tuic v5 lines',
|
||||
input: `Surge TUIC = tuic-v5,surge-tuic.example.com,443,uuid=${UUID},password=secret,sni=sni.example.com,skip-cert-verify=true,alpn=h3,ecn=true,port-hopping=9000;9002-9004`,
|
||||
@@ -3760,5 +3822,44 @@ describe('Platform raw-format parser coverage', function () {
|
||||
expectSubset(parseOne(input), { alpn });
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects Surge shadow-tls version 1 lines', function () {
|
||||
expect(
|
||||
parseAll(
|
||||
'Surge ShadowTLS Invalid = snell,surge-invalid.example.com,443,psk=secret,version=5,shadow-tls-password=shadow-pass,shadow-tls-sni=mask.example.com,shadow-tls-version=1,alpn="h2"',
|
||||
),
|
||||
).to.have.length(0);
|
||||
});
|
||||
|
||||
it('normalizes Mihomo Snell shadow-tls obfs form into plugin opts', function () {
|
||||
const [proxy] = parseAll(`proxies:
|
||||
- name: Mihomo Snell ShadowTLS
|
||||
type: snell
|
||||
server: mihomo-snell.example.com
|
||||
port: 443
|
||||
psk: secret
|
||||
version: 4
|
||||
obfs-opts:
|
||||
mode: shadow-tls
|
||||
host: mask.example.com
|
||||
password: shadow-pass
|
||||
version: 2
|
||||
alpn:
|
||||
- h2
|
||||
- http/1.1`);
|
||||
|
||||
expectSubset(proxy, {
|
||||
type: 'snell',
|
||||
name: 'Mihomo Snell ShadowTLS',
|
||||
plugin: 'shadow-tls',
|
||||
'plugin-opts': {
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 2,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
});
|
||||
expect(proxy).to.not.have.property('obfs-opts');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -558,7 +558,114 @@ describe('Proxy structured producers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('exports Mihomo-style Snell shadow-tls plugin objects to sing-box chained outbounds', function () {
|
||||
it('exports parsed Surge Snell shadow-tls ALPN lines to sing-box chained outbounds', function () {
|
||||
const [proxy] = ProxyUtils.parse(
|
||||
'Surge Snell ShadowTLS ALPN = snell,surge-snell.example.com,443,psk=secret,version=5,alpn="h2,http/1.1",shadow-tls-password=shadow-pass,shadow-tls-sni=mask.example.com,shadow-tls-version=3',
|
||||
);
|
||||
|
||||
const output = loadProducedJson('sing-box', proxy, {
|
||||
'include-unsupported-proxy': true,
|
||||
});
|
||||
|
||||
expectSubset(output.outbounds[1], {
|
||||
tag: 'Surge Snell ShadowTLS ALPN_shadowtls',
|
||||
type: 'shadowtls',
|
||||
tls: {
|
||||
server_name: 'mask.example.com',
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('emits Mihomo Snell shadow-tls as obfs-opts mode shadow-tls', function () {
|
||||
const proxy = {
|
||||
type: 'snell',
|
||||
name: 'Mihomo Snell ShadowTLS',
|
||||
server: 'mihomo-snell.example.com',
|
||||
port: 443,
|
||||
psk: 'secret',
|
||||
version: 4,
|
||||
udp: false,
|
||||
plugin: 'shadow-tls',
|
||||
'plugin-opts': {
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 2,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
};
|
||||
|
||||
const internal = produceInternal('Mihomo', proxy);
|
||||
const external = loadProducedYaml('Mihomo', proxy);
|
||||
|
||||
expectSubset(internal[0], {
|
||||
type: 'snell',
|
||||
name: 'Mihomo Snell ShadowTLS',
|
||||
server: 'mihomo-snell.example.com',
|
||||
port: 443,
|
||||
psk: 'secret',
|
||||
version: 4,
|
||||
'obfs-opts': {
|
||||
mode: 'shadow-tls',
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 2,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
});
|
||||
expect(internal[0]).to.not.have.property('plugin');
|
||||
expect(internal[0]).to.not.have.property('plugin-opts');
|
||||
expectSubset(external.proxies[0], {
|
||||
type: 'snell',
|
||||
name: 'Mihomo Snell ShadowTLS',
|
||||
'obfs-opts': {
|
||||
mode: 'shadow-tls',
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 2,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
});
|
||||
expect(external.proxies[0]).to.not.have.property('plugin');
|
||||
expect(external.proxies[0]).to.not.have.property('plugin-opts');
|
||||
});
|
||||
|
||||
it('filters Mihomo Snell shadow-tls when obfs also exists', function () {
|
||||
const proxy = {
|
||||
type: 'snell',
|
||||
name: 'Mihomo Snell ShadowTLS With Obfs',
|
||||
server: 'mihomo-snell.example.com',
|
||||
port: 443,
|
||||
psk: 'secret',
|
||||
version: 4,
|
||||
plugin: 'shadow-tls',
|
||||
'plugin-opts': {
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 2,
|
||||
},
|
||||
'obfs-opts': {
|
||||
mode: 'http',
|
||||
host: 'obfs.example.com',
|
||||
},
|
||||
};
|
||||
|
||||
const { result: internal, errors } = captureErrors(() =>
|
||||
produceInternal('Mihomo', proxy),
|
||||
);
|
||||
const { result: external, errors: externalErrors } = captureErrors(() =>
|
||||
loadProducedYaml('Mihomo', proxy),
|
||||
);
|
||||
|
||||
expect(errors).to.deep.equal([
|
||||
'Platform Mihomo does not support Snell shadow-tls with obfs for proxy Mihomo Snell ShadowTLS With Obfs. Proxy has been filtered.',
|
||||
]);
|
||||
expect(externalErrors).to.deep.equal(errors);
|
||||
expect(internal).to.have.length(0);
|
||||
expect(external).to.deep.equal({ proxies: null });
|
||||
});
|
||||
|
||||
it('exports Mihomo-style Snell obfs shadow-tls objects to sing-box chained outbounds', function () {
|
||||
const [proxy] = ProxyUtils.parse(`proxies:
|
||||
- name: Mihomo Snell ShadowTLS
|
||||
type: snell
|
||||
@@ -567,8 +674,8 @@ describe('Proxy structured producers', function () {
|
||||
psk: secret
|
||||
version: 4
|
||||
udp: false
|
||||
plugin: shadow-tls
|
||||
plugin-opts:
|
||||
obfs-opts:
|
||||
mode: shadow-tls
|
||||
host: mask.example.com
|
||||
password: shadow-pass
|
||||
version: 2
|
||||
@@ -1773,6 +1880,86 @@ describe('Proxy structured producers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('emits Snell shadow-tls as obfs-opts mode shadow-tls for Shadowrocket', function () {
|
||||
const proxy = {
|
||||
type: 'snell',
|
||||
name: 'Shadowrocket Snell ShadowTLS',
|
||||
server: 'snell.example.com',
|
||||
port: 44046,
|
||||
psk: 'secret',
|
||||
version: 4,
|
||||
plugin: 'shadow-tls',
|
||||
'plugin-opts': {
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 2,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
};
|
||||
|
||||
const internal = produceInternal('Shadowrocket', proxy)[0];
|
||||
const external = loadProducedYaml('Shadowrocket', proxy);
|
||||
|
||||
expectSubset(internal, {
|
||||
type: 'snell',
|
||||
name: 'Shadowrocket Snell ShadowTLS',
|
||||
'obfs-opts': {
|
||||
mode: 'shadow-tls',
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 2,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
});
|
||||
expect(internal).to.not.have.property('plugin');
|
||||
expect(internal).to.not.have.property('plugin-opts');
|
||||
expectSubset(external.proxies[0], {
|
||||
type: 'snell',
|
||||
'obfs-opts': {
|
||||
mode: 'shadow-tls',
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 2,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('filters Shadowrocket Snell shadow-tls when obfs also exists', function () {
|
||||
const proxy = {
|
||||
type: 'snell',
|
||||
name: 'Shadowrocket Snell ShadowTLS With Obfs',
|
||||
server: 'snell.example.com',
|
||||
port: 44046,
|
||||
psk: 'secret',
|
||||
version: 4,
|
||||
plugin: 'shadow-tls',
|
||||
'plugin-opts': {
|
||||
host: 'mask.example.com',
|
||||
password: 'shadow-pass',
|
||||
version: 2,
|
||||
},
|
||||
'obfs-opts': {
|
||||
mode: 'http',
|
||||
host: 'obfs.example.com',
|
||||
},
|
||||
};
|
||||
|
||||
const { result: internal, errors } = captureErrors(() =>
|
||||
produceInternal('Shadowrocket', proxy),
|
||||
);
|
||||
const { result: external, errors: externalErrors } = captureErrors(() =>
|
||||
loadProducedYaml('Shadowrocket', proxy),
|
||||
);
|
||||
|
||||
expect(errors).to.deep.equal([
|
||||
'Platform Shadowrocket does not support Snell shadow-tls with obfs for proxy Shadowrocket Snell ShadowTLS With Obfs. Proxy has been filtered.',
|
||||
]);
|
||||
expect(externalErrors).to.deep.equal(errors);
|
||||
expect(internal).to.have.length(0);
|
||||
expect(external).to.deep.equal({ proxies: null });
|
||||
});
|
||||
|
||||
it('maps canonical shadowsocks tls fields into Shadowrocket structured output', function () {
|
||||
const proxy = {
|
||||
type: 'ss',
|
||||
|
||||
@@ -570,6 +570,51 @@ describe('Proxy text producers', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('prefers plugin-scoped Loon shadow-tls alpn over top-level alpn', function () {
|
||||
const output = produceExternal('Loon', {
|
||||
type: 'ss',
|
||||
name: 'Loon ShadowTLS ALPN',
|
||||
server: 'ss.example.com',
|
||||
port: 8388,
|
||||
cipher: 'chacha20-ietf-poly1305',
|
||||
password: 'ss-pass',
|
||||
plugin: 'shadow-tls',
|
||||
alpn: ['ignored.example'],
|
||||
'plugin-opts': {
|
||||
password: 'shadow-pass',
|
||||
host: 'mask.example.com',
|
||||
version: 3,
|
||||
alpn: ['http/1.1', 'h2'],
|
||||
},
|
||||
});
|
||||
|
||||
expect(output).to.equal(
|
||||
'Loon ShadowTLS ALPN=shadowsocks,ss.example.com,8388,chacha20-ietf-poly1305,"ss-pass",shadow-tls-password=shadow-pass,shadow-tls-sni=mask.example.com,shadow-tls-version=3,alpn="http/1.1,h2"',
|
||||
);
|
||||
});
|
||||
|
||||
it('emits Loon tls-profile for shadow-tls outputs', function () {
|
||||
const output = produceExternal('Loon', {
|
||||
type: 'ss',
|
||||
name: 'Loon ShadowTLS TLS Profile',
|
||||
server: 'ss.example.com',
|
||||
port: 8388,
|
||||
cipher: 'chacha20-ietf-poly1305',
|
||||
password: 'ss-pass',
|
||||
plugin: 'shadow-tls',
|
||||
_loon_tls_profile: 'ios26',
|
||||
'plugin-opts': {
|
||||
password: 'shadow-pass',
|
||||
host: 'mask.example.com',
|
||||
version: 3,
|
||||
},
|
||||
});
|
||||
|
||||
expect(output).to.equal(
|
||||
'Loon ShadowTLS TLS Profile=shadowsocks,ss.example.com,8388,chacha20-ietf-poly1305,"ss-pass",shadow-tls-password=shadow-pass,shadow-tls-sni=mask.example.com,shadow-tls-version=3,tls-profile=ios26',
|
||||
);
|
||||
});
|
||||
|
||||
it('emits Loon tls-profile and alpn for TLS protocol outputs', function () {
|
||||
const alpn = ['http/1.1', 'h2', 'h3'];
|
||||
const output = produceExternal('Loon', [
|
||||
@@ -1089,6 +1134,29 @@ describe('Proxy text producers', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
it('prefers plugin-scoped Surge shadow-tls alpn over top-level alpn', function () {
|
||||
const output = produceExternal('Surge', {
|
||||
type: 'snell',
|
||||
name: 'Surge Snell ShadowTLS ALPN',
|
||||
server: 'snell.example.com',
|
||||
port: 443,
|
||||
psk: 'secret',
|
||||
version: 5,
|
||||
plugin: 'shadow-tls',
|
||||
alpn: ['ignored.example'],
|
||||
'plugin-opts': {
|
||||
password: 'shadow-pass',
|
||||
host: 'mask.example.com',
|
||||
version: 3,
|
||||
alpn: ['http/1.1', 'h2'],
|
||||
},
|
||||
});
|
||||
|
||||
expect(output).to.equal(
|
||||
'Surge Snell ShadowTLS ALPN=snell,snell.example.com,443,version=5,psk="secret",shadow-tls-password="shadow-pass",shadow-tls-sni=mask.example.com,shadow-tls-version=3,alpn="http/1.1,h2"',
|
||||
);
|
||||
});
|
||||
|
||||
it('omits Surge TLS-only params for plain HTTP, SOCKS5, and VMess nodes', function () {
|
||||
const cases = [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user