Skip to content

Commit cbcefae

Browse files
committed
fix: 修复 sing-box Snell 输出
1 parent 387d90c commit cbcefae

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.33.0",
3+
"version": "2.33.1",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"packageManager": "pnpm@11.0.9",

backend/src/core/proxy-utils/producers/sing-box.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,10 +1280,41 @@ export default function singbox_Producer() {
12801280
const type = 'ALL';
12811281
const produce = (proxies, type, opts = {}) => {
12821282
const list = [];
1283+
const originalSnellShadowTLS = new Map(
1284+
proxies
1285+
.filter(
1286+
(proxy) =>
1287+
proxy?.type === 'snell' &&
1288+
proxy?.plugin === 'shadow-tls' &&
1289+
proxy?.['plugin-opts'],
1290+
)
1291+
.map((proxy) => [
1292+
proxy,
1293+
{
1294+
plugin: proxy.plugin,
1295+
'plugin-opts': proxy['plugin-opts']
1296+
? JSON.parse(JSON.stringify(proxy['plugin-opts']))
1297+
: undefined,
1298+
'obfs-opts': proxy['obfs-opts']
1299+
? JSON.parse(JSON.stringify(proxy['obfs-opts']))
1300+
: undefined,
1301+
},
1302+
]),
1303+
);
12831304
ClashMeta_Producer()
12841305
.produce(proxies, 'internal', { 'include-unsupported-proxy': true })
12851306
.map((proxy) => {
12861307
try {
1308+
const originalShadowTLS = originalSnellShadowTLS.get(proxy);
1309+
if (originalShadowTLS) {
1310+
proxy.plugin = originalShadowTLS.plugin;
1311+
proxy['plugin-opts'] = originalShadowTLS['plugin-opts'];
1312+
if (originalShadowTLS['obfs-opts']) {
1313+
proxy['obfs-opts'] = originalShadowTLS['obfs-opts'];
1314+
} else {
1315+
delete proxy['obfs-opts'];
1316+
}
1317+
}
12871318
if (['xhttp'].includes(proxy.network))
12881319
throw new Error(
12891320
`Platform sing-box does not support network: ${proxy.network}`,

backend/src/test/proxy-producers/structured.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ describe('Proxy structured producers', function () {
487487
password: 'shadow-pass',
488488
version: 3,
489489
},
490+
'obfs-opts': {
491+
mode: 'http',
492+
host: 'obfs.example.com',
493+
},
490494
},
491495
{ 'include-unsupported-proxy': true },
492496
);
@@ -499,6 +503,8 @@ describe('Proxy structured producers', function () {
499503
version: 4,
500504
reuse: true,
501505
network: 'tcp',
506+
obfs_mode: 'http',
507+
obfs_host: 'obfs.example.com',
502508
detour: 'sing-box Snell ShadowTLS_shadowtls',
503509
});
504510
expect(output.outbounds[0]).to.not.have.property('server');

scripts/demo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function operator(proxies = [], targetPlatform, context) {
5454
// 29. sing-box 支持使用 `ssh-server` 给 tailscale 设置 `ssh_server`, 直接设为 `true` 或 `{ "enabled": true, "disable-pty": true, "disable-sftp": true, "disable-forwarding": true }`
5555
// 30. Loon 支持使用 `_loon_tls_profile` 设置 `tls-profile` 字段('default', 'chrome', 'ios18', 'ios26'), 否则则使用 client-fingerprint 自动转换部分对应的值
5656
// 31. `shadow-tls-password`/`shadow-tls-sni`/`shadow-tls-version` 这套旧字段已废弃. 请使用 `plugin: 'shadow-tls'` 和 `plugin-opts: { password, host, version }`
57+
// 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,h3",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", "h3" ] } }`
5758

5859
// require 为 Node.js 的 require, 在 Node.js 运行环境下 可以用来引入模块
5960
// 例如在 Node.js 环境下, 将文件内容写入 /tmp/1.txt 文件

0 commit comments

Comments
 (0)