From bdd5635abc4b250c0442c41c05ce8a56aac7286e Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 10 Apr 2026 13:48:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=20VLESS/Trojan=20URI?= =?UTF-8?q?=20=E4=B8=8E=20mihomo=20=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/parsers/index.js | 2 +- .../proxy-utils/parsers/peggy/trojan-uri.js | 1 + backend/src/core/proxy-utils/producers/uri.js | 12 +++-- backend/src/test/proxy-parsers/uri.spec.js | 22 +++++++++ .../proxy-parsers/v2ray-and-platforms.spec.js | 25 ++++++++++ backend/src/test/proxy-producers/text.spec.js | 48 +++++++++++++++++++ 7 files changed, 107 insertions(+), 5 deletions(-) diff --git a/backend/package.json b/backend/package.json index 7e836c42..07fb8f79 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.21.84", + "version": "2.21.85", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/parsers/index.js b/backend/src/core/proxy-utils/parsers/index.js index 8357bd99..d8ad3f06 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -868,7 +868,7 @@ function URI_VLESS() { proxy.alpn = params.alpn ? params.alpn.split(',') : undefined; proxy['skip-cert-verify'] = /(TRUE)|1/i.test(params.allowInsecure); proxy._echConfigList = getIfPresent(params.ech); - proxy._pcs = getIfPresent(params.pcs); + proxy['tls-fingerprint'] = getIfPresent(params.pcs); proxy._h2 = /(TRUE)|1/i.test(params.h2); switch (`${params.packetEncoding || ''}`.toLowerCase()) { diff --git a/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js b/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js index 92fc7a85..f1ebc94f 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js +++ b/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js @@ -86,6 +86,7 @@ params = "?" head:param tail:("&"@param)* { proxy["skip-cert-verify"] = toBool(params["allowInsecure"]); proxy.sni = params["sni"] || params["peer"]; proxy['client-fingerprint'] = params.fp; + proxy['tls-fingerprint'] = params.pcs; proxy.alpn = params.alpn ? decodeURIComponent(params.alpn).split(',') : undefined; if (toBool(params["ws"])) { diff --git a/backend/src/core/proxy-utils/producers/uri.js b/backend/src/core/proxy-utils/producers/uri.js index 57fe54bb..a87dd550 100644 --- a/backend/src/core/proxy-utils/producers/uri.js +++ b/backend/src/core/proxy-utils/producers/uri.js @@ -194,8 +194,8 @@ function vless(proxy) { h2 = `&h2=1`; } let pcs = ''; - if (proxy._pcs) { - pcs = `&pcs=${encodeURIComponent(proxy._pcs)}`; + if (proxy['tls-fingerprint']) { + pcs = `&pcs=${encodeURIComponent(proxy['tls-fingerprint'])}`; } let ech = ''; if (proxy._echConfigList) { @@ -697,6 +697,12 @@ export default function URI_Producer() { proxy['client-fingerprint'], )}`; } + let trojanPcs = ''; + if (proxy['tls-fingerprint']) { + trojanPcs = `&pcs=${encodeURIComponent( + proxy['tls-fingerprint'], + )}`; + } let trojanAlpn = ''; if (proxy.alpn) { trojanAlpn = `&alpn=${encodeURIComponent( @@ -739,7 +745,7 @@ export default function URI_Producer() { proxy.port }?sni=${encodeURIComponent(proxy.sni || proxy.server)}${ proxy['skip-cert-verify'] ? '&allowInsecure=1' : '' - }${trojanTransport}${trojanAlpn}${trojanFp}${trojanSecurity}${trojanSid}${trojanPbk}${trojanSpx}${trojanMode}${trojanExtra}#${encodeURIComponent( + }${trojanTransport}${trojanAlpn}${trojanFp}${trojanPcs}${trojanSecurity}${trojanSid}${trojanPbk}${trojanSpx}${trojanMode}${trojanExtra}#${encodeURIComponent( proxy.name, )}`; break; diff --git a/backend/src/test/proxy-parsers/uri.spec.js b/backend/src/test/proxy-parsers/uri.spec.js index 3a892322..cb0b10ac 100644 --- a/backend/src/test/proxy-parsers/uri.spec.js +++ b/backend/src/test/proxy-parsers/uri.spec.js @@ -367,6 +367,28 @@ describe('Proxy URI parser coverage', function () { }); }); + it('parses Trojan URIs with pcs as tls fingerprint', function () { + const proxy = parseOne( + 'trojan://trojan-pass@trojan-ws.example.com?type=ws&host=ws.example.com&path=%2Fws&pcs=fingerprint#Trojan%20WS%20PCS', + ); + + expectSubset(proxy, { + type: 'trojan', + name: 'Trojan WS PCS', + server: 'trojan-ws.example.com', + port: 443, + password: 'trojan-pass', + 'tls-fingerprint': 'fingerprint', + network: 'ws', + 'ws-opts': { + path: '/ws', + headers: { + Host: 'ws.example.com', + }, + }, + }); + }); + it('parses Trojan URIs with grpc reality metadata', function () { const proxy = parseOne( 'trojan://trojan-pass@trojan-grpc.example.com?type=grpc&serviceName=grpc-service&authority=grpc.example.com&mode=multi&security=reality&pbk=pubkey&sid=08&spx=%2Fspider&udp=1&tfo=1#Trojan%20Reality', 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 42c4f39b..7c392817 100644 --- a/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js +++ b/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js @@ -284,6 +284,31 @@ describe('VMess and VLESS parser coverage', function () { expect(proxy).to.not.have.property('xudp'); }); + it('parses websocket VLESS shares with pcs as tls fingerprint', function () { + const proxy = parseOne( + `vless://${UUID}@vless-ws.example.com:443?type=ws&security=tls&host=cdn.example.com&path=%2Fws&pcs=fingerprint#VLESS%20WS%20PCS`, + ); + + expectSubset(proxy, { + type: 'vless', + name: 'VLESS WS PCS', + server: 'vless-ws.example.com', + port: 443, + uuid: UUID, + tls: true, + udp: true, + xudp: true, + 'tls-fingerprint': 'fingerprint', + network: 'ws', + 'ws-opts': { + path: '/ws', + headers: { + Host: 'cdn.example.com', + }, + }, + }); + }); + it('rejects websocket VLESS shares with malformed early data size', function () { expect( parseAll( diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index c1cb2a67..cdaaa591 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -475,6 +475,30 @@ describe('Proxy text producers', function () { ); }); + it('produces URI VLESS websocket links with pcs from tls fingerprint', function () { + const output = produceExternal('URI', { + type: 'vless', + name: 'URI WS PCS', + server: 'vless.example.com', + port: 443, + uuid: UUID, + tls: true, + sni: 'sni.example.com', + 'tls-fingerprint': 'fingerprint', + network: 'ws', + 'ws-opts': { + path: '/ws', + headers: { + Host: 'cdn.example.com', + }, + }, + }); + + expect(output).to.equal( + `vless://${UUID}@vless.example.com:443?security=tls&type=ws&path=%2Fws&host=cdn.example.com&pcs=fingerprint&sni=sni.example.com#URI%20WS%20PCS`, + ); + }); + it('produces URI VLESS fake-http links with method and headerType', function () { const output = produceExternal('URI', { type: 'vless', @@ -687,6 +711,30 @@ describe('Proxy text producers', function () { ); }); + it('produces URI Trojan websocket links with pcs from tls fingerprint', function () { + const output = produceExternal('URI', { + type: 'trojan', + name: 'URI Trojan PCS', + server: 'trojan.example.com', + port: 443, + password: 'secret', + tls: true, + sni: 'sni.example.com', + 'tls-fingerprint': 'fingerprint', + network: 'ws', + 'ws-opts': { + path: '/ws', + headers: { + Host: 'cdn.example.com', + }, + }, + }); + + expect(output).to.equal( + 'trojan://secret@trojan.example.com:443?sni=sni.example.com&type=ws&path=%2Fws&host=cdn.example.com&pcs=fingerprint#URI%20Trojan%20PCS', + ); + }); + it('produces V2Ray exports as base64 encoded URI lists', function () { const output = produceExternal('V2Ray', { type: 'vless',