From 7188d2939fd84ff9d5626730f97e1caa8f870626 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 22 May 2026 01:57:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20mihomo=20=E6=A0=A1=E9=AA=8C=20ShadowTLS?= =?UTF-8?q?,=20=E6=94=AF=E6=8C=81=E6=96=B0=E7=89=88=20Snell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../core/proxy-utils/producers/clashmeta.js | 50 +++++++++- .../test/proxy-producers/structured.spec.js | 98 +++++++++++++++++++ 3 files changed, 148 insertions(+), 2 deletions(-) diff --git a/backend/package.json b/backend/package.json index 9f691334..b0479465 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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", diff --git a/backend/src/core/proxy-utils/producers/clashmeta.js b/backend/src/core/proxy-utils/producers/clashmeta.js index 608f696c..7e0b46df 100644 --- a/backend/src/core/proxy-utils/producers/clashmeta.js +++ b/backend/src/core/proxy-utils/producers/clashmeta.js @@ -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; +} diff --git a/backend/src/test/proxy-producers/structured.spec.js b/backend/src/test/proxy-producers/structured.spec.js index 7dfa7ca6..e43f3693 100644 --- a/backend/src/test/proxy-producers/structured.spec.js +++ b/backend/src/test/proxy-producers/structured.spec.js @@ -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',