From 5810884e5983dabb83c08ea9ed2af5649e6fee9e Mon Sep 17 00:00:00 2001 From: yarrrly <36712561+yarrrly@users.noreply.github.com> Date: Fri, 14 Aug 2026 12:31:39 +0200 Subject: [PATCH] feat(sing-box): warn about the dropped certificate fingerprint (#621) --- .../core/proxy-utils/producers/sing-box.js | 16 ++++- .../test/proxy-producers/structured.spec.js | 64 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/backend/src/core/proxy-utils/producers/sing-box.js b/backend/src/core/proxy-utils/producers/sing-box.js index f371e6d3..904a7f19 100644 --- a/backend/src/core/proxy-utils/producers/sing-box.js +++ b/backend/src/core/proxy-utils/producers/sing-box.js @@ -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 = {}) => { diff --git a/backend/src/test/proxy-producers/structured.spec.js b/backend/src/test/proxy-producers/structured.spec.js index 8c5626e1..b28f9845 100644 --- a/backend/src/test/proxy-producers/structured.spec.js +++ b/backend/src/test/proxy-producers/structured.spec.js @@ -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 = [ {