From bf81ca4acf817847acd6e518745846438941be09 Mon Sep 17 00:00:00 2001 From: xream Date: Wed, 11 Oct 2023 23:35:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BE=93=E5=85=A5=E5=A2=9E=E5=8A=A0=20?= =?UTF-8?q?Hysteria2=20URI=20=E6=94=AF=E6=8C=81;=20Surge=20Hysteria2=20?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=A2=9E=E5=8A=A0=20fingerprint?= 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 | 48 +++++++++++++++++++ .../src/core/proxy-utils/producers/surge.js | 7 +++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index d0b5666..0c6e230 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.67", + "version": "2.14.68", "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 a1a482b..27e89ea 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -404,6 +404,53 @@ function URI_VLESS() { }; return { name, test, parse }; } +function URI_Hysteria2() { + const name = 'URI Hysteria2 Parser'; + const test = (line) => { + return /^hysteria2:\/\//.test(line); + }; + const parse = (line) => { + line = line.split('hysteria2://')[1]; + // eslint-disable-next-line no-unused-vars + let [__, password, server, ___, port, addons, name] = + /^(.*?)@(.*?)(:(\d+))?\/?\?(.*?)(?:#(.*?))$/.exec(line); + port = parseInt(`${port}`, 10); + if (isNaN(port)) { + port = 443; + } + password = decodeURIComponent(password); + name = decodeURIComponent(name) ?? `Hysteria2 ${server}:${port}`; + + const proxy = { + type: 'hysteria2', + name, + server, + port, + password, + }; + + const params = {}; + for (const addon of addons.split('&')) { + const [key, valueRaw] = addon.split('='); + let value = valueRaw; + value = decodeURIComponent(valueRaw); + params[key] = value; + } + + proxy.sni = params.sni; + if (!proxy.sni && params.peer) { + proxy.sni = params.peer; + } + proxy.obfs = params.obfs; + proxy['obfs-password'] = params['obfs-password']; + proxy['skip-cert-verify'] = /(TRUE)|1/i.test(params.insecure); + proxy.tfo = /(TRUE)|1/i.test(params.fastopen); + proxy.fingerprint = params.pinSHA256; + + return proxy; + }; + return { name, test, parse }; +} // Trojan URI format function URI_Trojan() { @@ -798,6 +845,7 @@ export default [ URI_SSR(), URI_VMess(), URI_VLESS(), + URI_Hysteria2(), URI_Trojan(), Clash_All(), Surge_SS(), diff --git a/backend/src/core/proxy-utils/producers/surge.js b/backend/src/core/proxy-utils/producers/surge.js index 9936939..e74bd75 100644 --- a/backend/src/core/proxy-utils/producers/surge.js +++ b/backend/src/core/proxy-utils/producers/surge.js @@ -367,6 +367,9 @@ function wireguard(proxy) { } function hysteria2(proxy) { + if (proxy.obfs || proxy['obfs-password']) { + throw new Error(`obfs is unsupported`); + } const result = new Result(proxy); result.append(`${proxy.name}=hysteria2,${proxy.server},${proxy.port}`); @@ -388,6 +391,10 @@ function hysteria2(proxy) { `,skip-cert-verify=${proxy['skip-cert-verify']}`, 'skip-cert-verify', ); + result.appendIfPresent( + `,server-cert-fingerprint-sha256=${proxy.fingerprint}`, + 'fingerprint', + ); // tfo result.appendIfPresent(`,tfo=${proxy['fast-open']}`, 'fast-open');