From 8d0a71d983f2cd0da5dec7cd8cf27e3e0da0cfaa Mon Sep 17 00:00:00 2001 From: xream Date: Thu, 28 Nov 2024 16:04:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20VMess=20URI=20=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20alterId;=20Trojan=20=E6=94=AF=E6=8C=81=20f?= =?UTF-8?q?p=20=E5=92=8C=20alpn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../proxy-utils/parsers/peggy/trojan-uri.js | 2 ++ .../proxy-utils/parsers/peggy/trojan-uri.peg | 2 ++ backend/src/core/proxy-utils/producers/uri.js | 20 +++++++++++++++++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/backend/package.json b/backend/package.json index a79886f..4fe893a 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.430", + "version": "2.14.431", "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/peggy/trojan-uri.js b/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js index 107b8ce..69ae285 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js +++ b/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js @@ -82,6 +82,8 @@ port = digits:[0-9]+ { params = "?" head:param tail:("&"@param)* { proxy["skip-cert-verify"] = toBool(params["allowInsecure"]); proxy.sni = params["sni"] || params["peer"]; + proxy['client-fingerprint'] = params.fp; + proxy.alpn = params.alpn ? decodeURIComponent(params.alpn).split(',') : undefined; if (toBool(params["ws"])) { proxy.network = "ws"; diff --git a/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.peg b/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.peg index 28a8b87..d2fec0a 100644 --- a/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.peg +++ b/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.peg @@ -80,6 +80,8 @@ port = digits:[0-9]+ { params = "?" head:param tail:("&"@param)* { proxy["skip-cert-verify"] = toBool(params["allowInsecure"]); proxy.sni = params["sni"] || params["peer"]; + proxy['client-fingerprint'] = params.fp; + proxy.alpn = params.alpn ? decodeURIComponent(params.alpn).split(',') : undefined; if (toBool(params["ws"])) { proxy.network = "ws"; diff --git a/backend/src/core/proxy-utils/producers/uri.js b/backend/src/core/proxy-utils/producers/uri.js index 1313501..e49c6d4 100644 --- a/backend/src/core/proxy-utils/producers/uri.js +++ b/backend/src/core/proxy-utils/producers/uri.js @@ -102,7 +102,7 @@ export default function URI_Producer() { port: proxy.port, id: proxy.uuid, type, - aid: 0, + aid: proxy.alterId || 0, net, tls: proxy.tls ? 'tls' : '', }; @@ -290,11 +290,27 @@ export default function URI_Producer() { )}`; } } + let trojanFp = ''; + if (proxy['client-fingerprint']) { + trojanFp = `&fp=${encodeURIComponent( + proxy['client-fingerprint'], + )}`; + } + let trojanAlpn = ''; + if (proxy.alpn) { + trojanAlpn = `&alpn=${encodeURIComponent( + Array.isArray(proxy.alpn) + ? proxy.alpn + : proxy.alpn.join(','), + )}`; + } result = `trojan://${proxy.password}@${proxy.server}:${ proxy.port }?sni=${encodeURIComponent(proxy.sni || proxy.server)}${ proxy['skip-cert-verify'] ? '&allowInsecure=1' : '' - }${trojanTransport}#${encodeURIComponent(proxy.name)}`; + }${trojanTransport}${trojanAlpn}${trojanFp}#${encodeURIComponent( + proxy.name, + )}`; break; case 'hysteria2': let hysteria2params = [];