Skip to content

Commit 25d1077

Browse files
committed
feat: sing-box shadow-tls 支持 insecure, 非官方版支持 certificate_server_name
1 parent 4daac9e commit 25d1077

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ const shadowTLSOutboundParser = (proxy = {}, pluginOpts) => {
576576
server_name: pluginOpts.host,
577577
},
578578
};
579+
if (proxy['skip-cert-verify']) stPart.tls.insecure = true;
579580
if (fingerprint) {
580581
stPart.tls.utls = {
581582
enabled: true,
@@ -1338,6 +1339,7 @@ export default function singbox_Producer() {
13381339
throw new Error(
13391340
`Platform sing-box does not support network: ${proxy.network}`,
13401341
);
1342+
const listStart = list.length;
13411343
switch (proxy.type) {
13421344
case 'ssh':
13431345
list.push(sshParser(proxy));
@@ -1501,6 +1503,17 @@ export default function singbox_Producer() {
15011503
`Platform sing-box does not support proxy type: ${proxy.type}`,
15021504
);
15031505
}
1506+
if (
1507+
opts['include-unsupported-proxy'] &&
1508+
proxy['name-cert-verify']
1509+
) {
1510+
for (let i = listStart; i < list.length; i++) {
1511+
const outbound = list[i];
1512+
if (outbound.tls)
1513+
outbound.tls.certificate_server_name =
1514+
proxy['name-cert-verify'];
1515+
}
1516+
}
15041517
} catch (e) {
15051518
// console.log(e);
15061519
$.error(e.message ?? e);

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ describe('Proxy structured producers', function () {
758758
});
759759
});
760760

761-
it('exports Shadowsocks shadow-tls plugin ALPN to sing-box shadowtls tls options', function () {
761+
it('exports Shadowsocks shadow-tls plugin TLS options to sing-box', function () {
762762
const [proxy] = ProxyUtils.parse(`proxies:
763763
- name: SS ShadowTLS ALPN
764764
type: ss
@@ -768,6 +768,8 @@ describe('Proxy structured producers', function () {
768768
password: password
769769
plugin: shadow-tls
770770
client-fingerprint: chrome
771+
skip-cert-verify: true
772+
name-cert-verify: verify.example.com
771773
plugin-opts:
772774
host: cloud.tencent.com
773775
password: shadow_tls_password
@@ -776,7 +778,9 @@ describe('Proxy structured producers', function () {
776778
- h2
777779
- http/1.1`);
778780

779-
const output = loadProducedJson('sing-box', proxy);
781+
const output = loadProducedJson('sing-box', proxy, {
782+
'include-unsupported-proxy': true,
783+
});
780784

781785
expect(output.outbounds).to.have.length(2);
782786
expectSubset(output.outbounds[0], {
@@ -796,6 +800,8 @@ describe('Proxy structured producers', function () {
796800
tls: {
797801
enabled: true,
798802
server_name: 'cloud.tencent.com',
803+
insecure: true,
804+
certificate_server_name: 'verify.example.com',
799805
alpn: ['h2', 'http/1.1'],
800806
utls: {
801807
enabled: true,
@@ -4449,6 +4455,28 @@ describe('Proxy structured producers', function () {
44494455
});
44504456
});
44514457

4458+
it('emits sing-box certificate_server_name only with unsupported proxies enabled', function () {
4459+
const proxy = {
4460+
type: 'vless',
4461+
name: 'Certificate Server Name',
4462+
server: 'vless.example.com',
4463+
port: 443,
4464+
uuid: UUID,
4465+
tls: true,
4466+
'name-cert-verify': 'verify.example.com',
4467+
};
4468+
4469+
const supported = loadProducedJson('sing-box', proxy).outbounds[0];
4470+
const unsupported = loadProducedJson('sing-box', proxy, {
4471+
'include-unsupported-proxy': true,
4472+
}).outbounds[0];
4473+
4474+
expect(supported.tls).to.not.have.property('certificate_server_name');
4475+
expect(unsupported.tls.certificate_server_name).to.equal(
4476+
'verify.example.com',
4477+
);
4478+
});
4479+
44524480
it('validates sing-box uTLS fingerprints for regular TLS and Reality outbounds', function () {
44534481
const output = loadProducedJson('sing-box', [
44544482
{

0 commit comments

Comments
 (0)