feat: mihomo 校验 ShadowTLS, 支持新版 Snell

This commit is contained in:
xream committed 2026-05-22 01:57:10 +08:00
1 parent 5007a345fb
commit 7188d2939f
3 files changed
+148 -2

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.23.18",
"version": "2.23.19",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"packageManager": "pnpm@11.0.9",
@@ -68,7 +68,19 @@ export default function ClashMeta_Producer() {
}
if (!supportsShadowsocksV2rayPluginMode(proxy, ['websocket'])) {
return false;
} else if (proxy.type === 'snell' && proxy.version >= 4) {
} else if (
proxy.type === 'snell' &&
!isSupportedMihomoVersion(proxy.version, [1, 2, 3, 4, 5])
) {
return false;
} else if (
hasMihomoShadowTls(proxy) &&
(proxy.type !== 'ss' ||
!isSupportedMihomoVersion(
getMihomoShadowTlsVersion(proxy),
[1, 2, 3],
))
) {
return false;
} else if (['juicity', 'naive'].includes(proxy.type)) {
return false;
@@ -394,3 +406,39 @@ function hasRootHeaders(proxy) {
Object.keys(proxy.headers).length > 0
);
}
function isSupportedMihomoVersion(version, supportedVersions) {
if (version == null) {
return true;
}
const normalized =
typeof version === 'string' ? version.trim() : `${version}`;
if (!normalized) {
return false;
}
const parsed = Number(normalized);
return Number.isInteger(parsed) && supportedVersions.includes(parsed);
}
function hasMihomoShadowTls(proxy) {
return (
proxy?.plugin === 'shadow-tls' ||
isPresent(proxy, 'shadow-tls-password') ||
isPresent(proxy, 'shadow-tls-sni') ||
isPresent(proxy, 'shadow-tls-version')
);
}
function getMihomoShadowTlsVersion(proxy) {
if (isPresent(proxy, 'shadow-tls-version')) {
return proxy['shadow-tls-version'];
}
if (proxy?.plugin === 'shadow-tls') {
return proxy?.['plugin-opts']?.version;
}
return undefined;
}
@@ -161,6 +161,104 @@ describe('Proxy structured producers', function () {
}
});
it('keeps Mihomo Snell versions 1 through 5', function () {
const proxies = [1, 2, 3, 4, 5, 6].map((version) => ({
type: 'snell',
name: `Snell ${version}`,
server: 'snell.example.com',
port: 44046,
psk: 'secret',
version,
udp: true,
}));
const internal = produceInternal('Mihomo', proxies);
const external = loadProducedYaml('Mihomo', proxies);
expect(internal.map((proxy) => proxy.version)).to.deep.equal([
1, 2, 3, 4, 5,
]);
expect(external.proxies.map((proxy) => proxy.version)).to.deep.equal([
1, 2, 3, 4, 5,
]);
expect(
internal.find((proxy) => proxy.version === 1),
).to.not.have.property('udp');
expect(
internal.find((proxy) => proxy.version === 2),
).to.not.have.property('udp');
expect(internal.find((proxy) => proxy.version === 4).udp).to.equal(
true,
);
expect(internal.find((proxy) => proxy.version === 5).udp).to.equal(
true,
);
});
it('keeps only Shadowsocks shadow-tls versions 1 through 3 for Mihomo', function () {
const buildShadowTlsProxy = (name, version) => ({
type: 'ss',
name,
server: 'ss.example.com',
port: 8388,
cipher: 'aes-128-gcm',
password: 'secret',
'shadow-tls-password': 'shadow-pass',
'shadow-tls-sni': 'mask.example.com',
'shadow-tls-version': version,
});
const proxies = [
buildShadowTlsProxy('ShadowTLS 1', 1),
{
type: 'ss',
name: 'ShadowTLS 2',
server: 'ss.example.com',
port: 8388,
cipher: 'aes-128-gcm',
password: 'secret',
plugin: 'shadow-tls',
'plugin-opts': {
host: 'mask.example.com',
password: 'shadow-pass',
version: 2,
},
},
buildShadowTlsProxy('ShadowTLS 3', 3),
buildShadowTlsProxy('ShadowTLS 4', 4),
{
type: 'vmess',
name: 'VMess ShadowTLS',
server: 'vmess.example.com',
port: 443,
uuid: UUID,
cipher: 'auto',
plugin: 'shadow-tls',
'plugin-opts': {
host: 'mask.example.com',
password: 'shadow-pass',
version: 3,
},
},
];
const internal = produceInternal('Mihomo', proxies);
const external = loadProducedYaml('Mihomo', proxies);
expect(internal.map((proxy) => proxy.name)).to.deep.equal([
'ShadowTLS 1',
'ShadowTLS 2',
'ShadowTLS 3',
]);
expect(
internal.map((proxy) => proxy['plugin-opts'].version),
).to.deep.equal([1, 2, 3]);
expect(external.proxies.map((proxy) => proxy.name)).to.deep.equal([
'ShadowTLS 1',
'ShadowTLS 2',
'ShadowTLS 3',
]);
});
it('keeps only supported shadowsocks v2ray-plugin modes for Shadowrocket by default', function () {
const buildProxy = (name, mode) => ({
type: 'ss',