feat(sing-box): warn about the dropped certificate fingerprint (#621)

This commit is contained in:
yarrrly authored and GitHub committed 2026-08-14 18:31:39 +08:00
1 parent 98d23445f6
commit 5810884e59
2 files changed
+79 -1

No files matched your search

@@ -401,7 +401,21 @@ const tlsParser = (proxy, parsedProxy) => {
if (proxy['_client_key']) parsedProxy.tls.client_key = proxy['_client_key'];
if (proxy['_client_key_path'])
parsedProxy.tls.client_key_path = proxy['_client_key_path'];
if (!parsedProxy.tls.enabled) delete parsedProxy.tls;
if (!parsedProxy.tls.enabled) {
delete parsedProxy.tls;
} else if (
(proxy.fingerprint || proxy['tls-fingerprint']) &&
!parsedProxy.tls.reality &&
!parsedProxy.tls.certificate &&
!parsedProxy.tls.certificate_path &&
!parsedProxy.tls.certificate_public_key_sha256
) {
// sing-box can only pin the SHA-256 of the certificate public key
// https://sing-box.sagernet.org/configuration/shared/tls/#certificate_public_key_sha256
$.warn(
`Platform sing-box does not support certificate fingerprint pinning, it is dropped for proxy ${proxy.name}. Set _certificate_public_key_sha256 to pin the certificate public key instead`,
);
}
};
const sshParser = (proxy = {}) => {
@@ -4442,6 +4442,70 @@ describe('Proxy structured producers', function () {
});
});
it('warns about the dropped certificate fingerprint for sing-box', function () {
const fingerprint =
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
const publicKeySha256 = '428F7quaQJvBhEr5TclcjPpsl1ryyNQo7oLBGhhC3UU=';
const { result, warnings } = captureWarns(() =>
produceInternal('sing-box', [
{
type: 'trojan',
name: 'Trojan Pinned',
server: 'trojan.example.com',
port: 443,
password: 'secret',
tls: true,
'tls-fingerprint': fingerprint,
},
{
type: 'hysteria2',
name: 'Hysteria2 Public Key Pinned',
server: 'hy2.example.com',
port: 443,
password: 'secret',
'tls-fingerprint': fingerprint,
_certificate_public_key_sha256: [publicKeySha256],
},
{
type: 'vless',
name: 'VLESS Reality Pinned',
server: 'vless.example.com',
port: 443,
uuid: UUID,
tls: true,
'tls-fingerprint': fingerprint,
'reality-opts': {
'public-key': 'pubkey',
'short-id': '08',
},
},
]),
);
expect(warnings).to.have.length(1);
expect(warnings[0]).to.include('Trojan Pinned');
expect(warnings[0]).to.include('_certificate_public_key_sha256');
expect(result[0].tls).to.not.have.property(
'certificate_public_key_sha256',
);
expectSubset(result[1], {
tls: {
enabled: true,
certificate_public_key_sha256: [publicKeySha256],
},
});
expectSubset(result[2], {
tls: {
enabled: true,
reality: {
enabled: true,
public_key: 'pubkey',
short_id: '08',
},
},
});
});
it('emits WireGuard interface CIDR suffixes for Egern exports', function () {
const proxies = [
{