diff --git a/backend/package.json b/backend/package.json index d740ec6a..5d0591b9 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.42.0", + "version": "2.42.2", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "packageManager": "pnpm@11.0.9", @@ -19,7 +19,7 @@ "license": "AGPL-3.0", "pnpm": { "patchedDependencies": { - "http-proxy@1.18.1": "patches/http-proxy@1.18.1.patch" + "http-proxy@2.18.1": "patches/http-proxy@1.18.1.patch" } }, "dependencies": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index c64f2587..6b6b9d41 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -781,6 +781,15 @@ function lastParse(proxy) { } normalizeOpts(proxy[normalizedKey]); } + if ( + proxy['reality-opts']?.['public-key'] && + !hasOwn(proxy['reality-opts'], 'support-x25519mlkem768') && + ['safari-ios-26', 'chrome147'].includes( + `${proxy._loon_tls_profile || ''}`.trim(), + ) + ) { + proxy['reality-opts']['support-x25519mlkem768'] = true; + } proxy.udp = ![false, 0, '0', 'false', 'off'].includes( typeof proxy.udp === 'string' ? proxy.udp.toLowerCase() : proxy.udp, ); diff --git a/backend/src/core/proxy-utils/parsers/peggy/loon.js b/backend/src/core/proxy-utils/parsers/peggy/loon.js index e3addbd5..16b2b4df 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/loon.js +++ b/backend/src/core/proxy-utils/parsers/peggy/loon.js @@ -65,8 +65,8 @@ const grammars = String.raw` case "chrome": case "chrome147": return "chrome"; - case "ios18": - case "ios26": + case "safari-ios18": + case "safari-ios-26": return "ios"; } } diff --git a/backend/src/core/proxy-utils/producers/loon.js b/backend/src/core/proxy-utils/producers/loon.js index 9f0b94dc..cfad3bf7 100644 --- a/backend/src/core/proxy-utils/producers/loon.js +++ b/backend/src/core/proxy-utils/producers/loon.js @@ -79,7 +79,9 @@ function appendAlpn(result, proxy) { function getLoonShadowTLSAlpn(proxy) { const values = proxy?.['plugin-opts']?.alpn ?? proxy?.alpn; - const normalized = Array.isArray(values) ? values : `${values || ''}`.split(','); + const normalized = Array.isArray(values) + ? values + : `${values || ''}`.split(','); return normalized .map((item) => `${item}`.trim()) .filter((item) => item !== '') @@ -133,16 +135,31 @@ function getLoonAlpn(proxy) { function getLoonTlsProfile(proxy) { const tlsProfile = `${proxy._loon_tls_profile || ''}`.trim(); if ( - ['default', 'chrome', 'chrome147', 'ios18', 'ios26'].includes(tlsProfile) + [ + 'global', + 'default', + 'safari-ios18', + 'safari-ios-26', + 'chrome', + 'chrome147', + ].includes(tlsProfile) ) { return tlsProfile; } - switch (`${proxy['client-fingerprint'] || ''}`.trim()) { + const fingerprint = `${proxy['client-fingerprint'] || ''}`.trim(); + if (proxy['reality-opts']?.['support-x25519mlkem768']) { + return ['safari', 'ios'].includes(fingerprint) + ? 'safari-ios-26' + : 'chrome147'; + } + + switch (fingerprint) { case 'chrome': - return 'chrome147'; + return 'chrome'; + case 'safari': case 'ios': - return 'ios26'; + return 'safari-ios18'; } } diff --git a/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js b/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js index 94f4541f..664731a3 100644 --- a/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js +++ b/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js @@ -3013,7 +3013,7 @@ describe('Platform raw-format parser coverage', function () { }, { 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', + 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=safari-ios-26', expected: { type: 'ss', name: 'Loon ShadowTLS TLS Profile', @@ -3023,7 +3023,7 @@ describe('Platform raw-format parser coverage', function () { password: 'shadow-pass', version: 3, }, - _loon_tls_profile: 'ios26', + _loon_tls_profile: 'safari-ios-26', 'client-fingerprint': 'ios', }, }, @@ -3374,26 +3374,41 @@ describe('Platform raw-format parser coverage', function () { }, ]); - it('normalizes Loon tls-profile values into client fingerprints', function () { + it('normalizes Loon tls-profile values without overriding explicit REALITY ML-KEM settings', function () { const cases = [ + ['global'], ['default'], ['chrome', 'chrome'], - ['chrome147', 'chrome'], - ['ios18', 'ios'], - ['ios26', 'ios'], + ['chrome147', 'chrome', true], + ['safari-ios18', 'ios'], + ['safari-ios-26', 'ios', true], ]; - for (const [profile, fingerprint] of cases) { - const proxy = parseOne( - `Loon ${profile}=vmess,loon-${profile}.example.com,443,auto,"${UUID}",over-tls=true,tls-profile=${profile},alterId=0`, - ); + for (const [profile, fingerprint, mlkem] of cases) { + const input = `Loon ${profile}=vmess,loon-${profile}.example.com,443,auto,"${UUID}",over-tls=true,tls-profile=${profile},alterId=0`; + const proxy = parseOne(input); expect(proxy._loon_tls_profile).to.equal(profile); + expect(proxy).to.not.have.property('reality-opts'); if (fingerprint) { expect(proxy['client-fingerprint']).to.equal(fingerprint); } else { expect(proxy).to.not.have.property('client-fingerprint'); } + + const realityProxy = parseOne(`${input},public-key=pubkey`); + expect( + realityProxy['reality-opts']['support-x25519mlkem768'], + ).to.equal(mlkem); + + for (const value of [true, false]) { + realityProxy['reality-opts']['support-x25519mlkem768'] = + value; + const reparsed = parseOne(JSON.stringify(realityProxy)); + expect( + reparsed['reality-opts']['support-x25519mlkem768'], + ).to.equal(value); + } } }); diff --git a/backend/src/test/proxy-producers/structured.spec.js b/backend/src/test/proxy-producers/structured.spec.js index 9bc0fccc..57dab9a5 100644 --- a/backend/src/test/proxy-producers/structured.spec.js +++ b/backend/src/test/proxy-producers/structured.spec.js @@ -96,7 +96,8 @@ describe('Proxy structured producers', function () { it('normalizes Loon tls-profile before emitting Mihomo client fingerprints', function () { for (const [profile, fingerprint] of [ - ['ios26', 'ios'], + ['safari-ios18', 'ios'], + ['safari-ios-26', 'ios'], ['chrome147', 'chrome'], ]) { const [proxy] = ProxyUtils.parse( diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index 53084acc..4a575d96 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -750,7 +750,7 @@ describe('Proxy text producers', function () { cipher: 'chacha20-ietf-poly1305', password: 'ss-pass', plugin: 'shadow-tls', - _loon_tls_profile: 'ios26', + _loon_tls_profile: 'safari-ios-26', 'plugin-opts': { password: 'shadow-pass', host: 'mask.example.com', @@ -759,7 +759,7 @@ describe('Proxy text producers', function () { }); 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', + '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=safari-ios-26', ); }); @@ -864,55 +864,79 @@ describe('Proxy text producers', function () { }, ]); - expect(output.match(/tls-profile=chrome147(?=,|$)/gm)).to.have.length( - 9, - ); + expect(output.match(/tls-profile=chrome(?=,|$)/gm)).to.have.length(9); expect(output.match(/alpn="http\/1\.1,h2,h3"/g)).to.have.length(9); }); it('selects Loon tls-profile before client fingerprint fallback', function () { - const buildTrojan = (name, fields) => ({ - type: 'trojan', - name, - server: `${name.toLowerCase().replace(/\s+/g, '-')}.example.com`, - port: 443, - password: 'secret', - ...fields, - }); - const output = produceExternal('Loon', [ - buildTrojan('Loon Source IOS18', { - _loon_tls_profile: 'ios18', - 'client-fingerprint': 'ios', - }), - buildTrojan('Loon Source Default', { - _loon_tls_profile: 'default', - 'client-fingerprint': 'chrome', - }), - buildTrojan('Loon Source Chrome', { - _loon_tls_profile: 'chrome', - 'client-fingerprint': 'ios', - }), - buildTrojan('Loon Source Chrome147', { - _loon_tls_profile: 'chrome147', - 'client-fingerprint': 'ios', - }), - buildTrojan('Loon Fallback Chrome', { - 'client-fingerprint': 'chrome', - }), - buildTrojan('Loon Fallback IOS', { - 'client-fingerprint': 'ios', - }), - ]); + for (const profile of [ + 'global', + 'default', + 'safari-ios18', + 'safari-ios-26', + 'chrome', + 'chrome147', + ]) { + for (const mlkem of [true, false, undefined]) { + const output = produceExternal('Loon', { + type: 'trojan', + name: 'Loon TLS Profile', + server: 'example.com', + port: 443, + password: 'secret', + _loon_tls_profile: ` ${profile} `, + 'client-fingerprint': 'ios', + 'reality-opts': { + 'public-key': 'pubkey', + 'support-x25519mlkem768': mlkem, + }, + }); + expect(output.match(/,tls-profile=([^,]+)/)?.[1]).to.equal( + profile, + ); + } + } + }); - expect(output).to.include('Loon Source IOS18=trojan'); - expect(output).to.include('tls-profile=ios18'); - expect(output).to.include('tls-profile=default'); - expect(output).to.match(/tls-profile=chrome(?=,|$)/m); - expect(output.match(/tls-profile=chrome147(?=,|$)/gm)).to.have.length( - 2, - ); - expect(output).to.include('tls-profile=ios26'); - expect(output.match(/tls-profile=/g)).to.have.length(6); + it('maps Loon REALITY ML-KEM fingerprints and preserves their profiles on re-export', function () { + const cases = [ + ['safari', 'true', 'safari-ios-26'], + ['ios', '1', 'safari-ios-26'], + ['chrome', 'true', 'chrome147'], + ['safari', 'false', 'safari-ios18'], + ['ios', 'false', 'safari-ios18'], + ['chrome', 'false', 'chrome'], + ['safari', undefined, 'safari-ios18'], + ['ios', undefined, 'safari-ios18'], + ['chrome', undefined, 'chrome'], + ['firefox', 'true', 'chrome147'], + ['random', 'true', 'chrome147'], + ['global', 'true', 'chrome147'], + ['default', 'true', 'chrome147'], + ['safari-ios18', 'true', 'chrome147'], + ['', 'true', 'chrome147'], + ['firefox', 'false', undefined], + ['', undefined, undefined], + ]; + for (const type of ['vless', 'vmess']) { + for (const [fingerprint, mlkem, expected] of cases) { + const proxies = ProxyUtils.parse( + `${type}://${UUID}@example.com:443?security=reality&pbk=pubkey&fp=${fingerprint}${ + mlkem == null ? '' : `&support-x25519mlkem768=${mlkem}` + }`, + ); + const output = produceExternal('Loon', proxies); + const reexported = produceExternal( + 'Loon', + ProxyUtils.parse(output), + ); + for (const result of [output, reexported]) { + expect(result.match(/,tls-profile=([^,]+)/)?.[1]).to.equal( + expected, + ); + } + } + } }); it('omits invalid Loon tls-profile fallback values', function () { diff --git a/scripts/demo.js b/scripts/demo.js index c8f9bb33..64922d5f 100644 --- a/scripts/demo.js +++ b/scripts/demo.js @@ -52,7 +52,7 @@ function operator(proxies = [], targetPlatform, context) { // 28. sing-box 1.14.0 起才有 `control_http_client` , 暂时可使用 `control-http-client` 字段设置 sing-box 的 `control_http_client` // 若 `control-http-client` 非空, 输出 sing-box Tailscale endpoint 时会跳过旧版拨号字段映射, 避免和 `detour`/`dialer-proxy` 等 legacy dialer options 冲突. 需要给控制面设置前置代理时, 请写到 `control-http-client.detour`(1.14.0-alpha.26 又改回去了...) // 29. sing-box 支持使用 `ssh-server` 给 tailscale 设置 `ssh_server`, 直接设为 `true` 或 `{ "enabled": true, "disable-pty": true, "disable-sftp": true, "disable-forwarding": true }` - // 30. Loon 支持使用 `_loon_tls_profile` 设置 `tls-profile` 字段('default', 'chrome', 'chrome147', 'ios18', 'ios26'), 优先使用该字段, 否则从 client-fingerprint 自动转换: chrome -> chrome147, ios -> ios26. Loon 输入 chrome147 时, client-fingerprint 转成 chrome, `_loon_tls_profile` 保留原始值 chrome147 + // 30. Loon 支持使用 `_loon_tls_profile` 设置 `tls-profile` 字段('global', 'default', 'safari-ios18', 'safari-ios-26', 'chrome', 'chrome147'), 优先使用该字段, 否则从 client-fingerprint 自动转换: reality-opts.support-x25519mlkem768 为 true 时, safari/ios -> safari-ios-26, 其他值(含空值) -> chrome147; 未开启时, chrome -> chrome, safari/ios -> safari-ios18. Loon 输入 chrome/chrome147 时, client-fingerprint 转成 chrome; 输入 safari-ios18/safari-ios-26 时转成 ios; `_loon_tls_profile` 保留原始值 // 31. `shadow-tls-password`/`shadow-tls-sni`/`shadow-tls-version` 这套旧字段已废弃. 请使用 `plugin: 'shadow-tls'` 和 `plugin-opts: { password, host, version }` // 32. mihomo 中 Snell shadow-tls 字段与 ss shadow-tls 字段不同, 使用的是 obfs-opts 而不是 plugin+plugin-opts, 不能与 obfs http/tls 共存. Sub-Store 内部有字段转换, 建议直接使用单行 Surge 格式 `1=snell,a.com,443,version=4,psk="1",obfs=http,obfs-host=a.com,shadow-tls-password="1",shadow-tls-sni=a.com,shadow-tls-version=3,alpn="http/1.1,h2",reuse=true` . 若想使用 JSON/JSON5/YAML 单行格式输入, 可使用 `{ "name": "1", "server": "a.com", "port": 443, "psk": "1", "version": 4, "reuse": true, "type": "snell", "obfs-opts": { "mode": "http", "host": "a.com" }, "plugin": "shadow-tls", "plugin-opts": { "host": "a.com", "password": "1", "version": 3, "alpn": [ "http/1.1", "h2" ] } }` // 33. sing-box Snell 出站默认允许 version 4/5/6, 其中 version 5 会按 sing-box 行为输出成 version 4. 开启“含不支持的协议”时保留 version 1/2/3/4/5/6, 并支持 version 6 通过节点字段 `quic-proxy-mode` 设置 `quic_proxy_mode`. 节点上的 `_userkey` 会输出为 sing-box 的 `userkey`