mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 06:43:08 +00:00
feat: QX 支持 Hysteria 2
This commit is contained in:
6 files changed
+189
-8
No files matched your search
@@ -100,7 +100,7 @@ Push URLs may contain secrets: treat `SUB_STORE_PUSH_SERVICE` as privileged conf
|
||||
- [x] Clash Proxies YAML
|
||||
- [x] Clash Proxy JSON/JSON5/YAML(single line)
|
||||
> [NaiveProxy](https://telegram.me/zhetengsha/4308)
|
||||
- [x] QX (SS, SSR, VMess, Trojan, HTTP, SOCKS5, VLESS, AnyTLS)
|
||||
- [x] QX (SS, SSR, VMess, Trojan, HTTP, SOCKS5, VLESS, AnyTLS, Hysteria 2)
|
||||
- [x] Loon (SS, SSR, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard, VLESS, Hysteria 2, AnyTLS, TailScale)
|
||||
- [x] Surge (Direct, SS, VMess, Trojan, HTTP, HTTPS, HTTP/2 CONNECT, SOCKS5, SOCKS5-TLS, AnyTLS, TrustTunnel, TUIC, Snell, Hysteria 2, VLESS, MASQUE(Surge), SSH(Password authentication only), External Proxy Program(only for macOS), WireGuard(Surge to Surge))
|
||||
- [x] mihomo(Clash.Meta) Compatible (Direct, SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, Hysteria 2, TUIC, SSH, mieru, sudoku, AnyTLS, MASQUE, Tailscale, GOST Relay, Shadow QUIC, ZeroTier, OpenVPN)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.44.16",
|
||||
"version": "2.44.17",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -2692,6 +2692,13 @@ function QX_AnyTLS() {
|
||||
return { name, test, parse };
|
||||
}
|
||||
|
||||
function QX_Hysteria2() {
|
||||
const name = 'QX Hysteria2 Parser';
|
||||
const test = (line) => /^hysteria2\s*=/.test(line);
|
||||
const parse = (line) => getQXParser().parse(line);
|
||||
return { name, test, parse };
|
||||
}
|
||||
|
||||
function QX_Trojan() {
|
||||
const name = 'QX Trojan Parser';
|
||||
const test = (line) => {
|
||||
@@ -3222,6 +3229,7 @@ export default [
|
||||
QX_VMess(),
|
||||
QX_VLESS(),
|
||||
QX_AnyTLS(),
|
||||
QX_Hysteria2(),
|
||||
QX_Trojan(),
|
||||
QX_Http(),
|
||||
QX_Socks5(),
|
||||
|
||||
@@ -71,7 +71,7 @@ const grammars = String.raw`
|
||||
}
|
||||
}
|
||||
|
||||
start = (trojan/shadowsocks/vmess/vless/anytls/http/socks5) {
|
||||
start = (trojan/shadowsocks/vmess/vless/anytls/hysteria2/http/socks5) {
|
||||
return proxy
|
||||
}
|
||||
|
||||
@@ -143,6 +143,12 @@ anytls = "anytls" equals address
|
||||
proxy.tls = true;
|
||||
}
|
||||
|
||||
hysteria2 = "hysteria2" equals address
|
||||
(password/tls_host/tls_pubkey_sha256/tls_alpn/tls_no_session_ticket/tls_no_session_reuse/tls_fingerprint/tls_verification/udp_relay/download_bandwidth/salamander_password/port_hopping/port_hopping_interval/server_check_url/tag/others)* {
|
||||
proxy.type = "hysteria2";
|
||||
proxy.tls = true;
|
||||
}
|
||||
|
||||
http = "http" equals address
|
||||
(username/password/over_tls/tls_host/tls_pubkey_sha256/tls_alpn/tls_no_session_ticket/tls_no_session_reuse/tls_fingerprint/tls_verification/tag/fast_open/udp_relay/udp_over_tcp/server_check_url/reality_base64_pubkey/reality_hex_shortid/others)*{
|
||||
proxy.type = "http";
|
||||
@@ -202,6 +208,22 @@ udp_relay = comma "udp-relay" equals flag:bool { proxy.udp = flag; }
|
||||
udp_over_tcp = comma "udp-over-tcp" equals flag:bool { throw new Error("UDP over TCP is not supported"); }
|
||||
udp_over_tcp_new = comma "udp-over-tcp" equals param:$[^=,]+ { if (param === "sp.v1") { proxy["udp-over-tcp"] = true; proxy["udp-over-tcp-version"] = 1; } else if (param === "sp.v2") { proxy["udp-over-tcp"] = true; proxy["udp-over-tcp-version"] = 2; } else if (param === "true") { proxy["_ssr_python_uot"] = true; } else { throw new Error("Invalid value for udp-over-tcp"); } }
|
||||
|
||||
download_bandwidth = comma "download-bandwidth" equals value:$[^,]+ { proxy.down = value.trim(); }
|
||||
salamander_password = comma "salamander-password" equals value:$((!next_parameter .)+) {
|
||||
proxy.obfs = "salamander";
|
||||
proxy["obfs-password"] = value.trim();
|
||||
}
|
||||
port_hopping = comma "port-hopping" equals ports:$(hopping_port (comma hopping_port)*) {
|
||||
proxy.ports = ports.replace(/\s/g, "");
|
||||
}
|
||||
hopping_port = [0-9]+ (_ "-" _ [0-9]+)?
|
||||
port_hopping_interval = comma "port-hopping-interval" equals interval:$[0-9]+ {
|
||||
const seconds = Number(interval);
|
||||
if (seconds >= 5 && seconds <= 3600) {
|
||||
proxy["hop-interval"] = seconds;
|
||||
}
|
||||
}
|
||||
|
||||
fast_open = comma "fast-open" equals flag:bool { proxy.tfo = flag; }
|
||||
|
||||
over_tls = comma "over-tls" equals flag:bool { proxy.tls = flag; }
|
||||
@@ -265,7 +287,7 @@ reality_hex_shortid = comma "reality-hex-shortid" equals param:$[^=,]+ {
|
||||
}
|
||||
|
||||
vless_flow = comma "vless-flow" equals param:$[^=,]+ { proxy["flow"] = param; }
|
||||
server_check_url = comma "server_check_url" equals param:$[^=,]+ { proxy["test-url"] = param; }
|
||||
server_check_url = comma "server_check_url" equals param:$[^,]+ { proxy["test-url"] = param.trim(); }
|
||||
|
||||
uri = $[^,]+
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ export default function QX_Producer() {
|
||||
return vless(proxy);
|
||||
case 'anytls':
|
||||
return anytls(proxy);
|
||||
case 'hysteria2':
|
||||
return hysteria2(proxy);
|
||||
}
|
||||
throw new Error(
|
||||
`Platform ${targetPlatform} does not support proxy type: ${proxy.type}`,
|
||||
@@ -192,7 +194,10 @@ function shadowsocks(proxy) {
|
||||
);
|
||||
}
|
||||
|
||||
if (needTls(proxy)) {
|
||||
if (
|
||||
needTls(proxy) ||
|
||||
(proxy.plugin === 'v2ray-plugin' && proxy['plugin-opts']?.tls)
|
||||
) {
|
||||
appendIfPresent(
|
||||
`,tls-pubkey-sha256=${proxy['tls-pubkey-sha256']}`,
|
||||
'tls-pubkey-sha256',
|
||||
@@ -610,6 +615,55 @@ function anytls(proxy) {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
function hysteria2(proxy) {
|
||||
if (proxy.obfs && proxy.obfs !== 'salamander') {
|
||||
throw new Error('QX Hysteria 2 only supports Salamander obfuscation');
|
||||
}
|
||||
|
||||
const result = new Result(proxy);
|
||||
result.append(`hysteria2=${proxy.server}:${proxy.port}`);
|
||||
result.appendIfPresent(`,password=${proxy.password}`, 'password');
|
||||
const ports = String(proxy.ports || '').trim();
|
||||
if (ports) result.append(`,port-hopping=${ports.replace(/;/g, ',')}`);
|
||||
|
||||
const interval = Number(proxy['hop-interval']);
|
||||
if (Number.isInteger(interval) && interval >= 5 && interval <= 3600) {
|
||||
result.append(`,port-hopping-interval=${interval}`);
|
||||
}
|
||||
result.appendIfPresent(
|
||||
`,salamander-password=${proxy['obfs-password']}`,
|
||||
'obfs-password',
|
||||
);
|
||||
result.appendIfPresent(`,tls-host=${proxy.sni}`, 'sni');
|
||||
result.appendIfPresent(
|
||||
`,tls-pubkey-sha256=${proxy['tls-pubkey-sha256']}`,
|
||||
'tls-pubkey-sha256',
|
||||
);
|
||||
appendTlsAlpn(result, proxy);
|
||||
result.appendIfPresent(
|
||||
`,tls-no-session-ticket=${proxy['tls-no-session-ticket']}`,
|
||||
'tls-no-session-ticket',
|
||||
);
|
||||
result.appendIfPresent(
|
||||
`,tls-no-session-reuse=${proxy['tls-no-session-reuse']}`,
|
||||
'tls-no-session-reuse',
|
||||
);
|
||||
result.appendIfPresent(
|
||||
`,tls-cert-sha256=${proxy['tls-fingerprint']}`,
|
||||
'tls-fingerprint',
|
||||
);
|
||||
appendTlsVerification(result, proxy);
|
||||
const bandwidth = String(proxy.down).match(/^\s*(\d+)/)?.[1];
|
||||
if (bandwidth) result.append(`,download-bandwidth=${bandwidth}`);
|
||||
result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
|
||||
result.appendIfPresent(
|
||||
`,server_check_url=${proxy['test-url']}`,
|
||||
'test-url',
|
||||
);
|
||||
result.append(`,tag=${proxy.name}`);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
function http(proxy) {
|
||||
const result = new Result(proxy);
|
||||
const append = result.append.bind(result);
|
||||
|
||||
@@ -53,32 +53,55 @@ describe('Proxy text producers', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('encodes canonical ALPN for every Quantumult X TLS producer', function () {
|
||||
it('round-trips ALPN and TLS session options for every Quantumult X TLS protocol', function () {
|
||||
const credentials = {
|
||||
ss: { cipher: 'aes-128-gcm', password: 'secret' },
|
||||
trojan: { password: 'secret' },
|
||||
vmess: { cipher: 'none', uuid: UUID },
|
||||
vless: { uuid: UUID },
|
||||
anytls: { password: 'secret' },
|
||||
hysteria2: { password: 'secret' },
|
||||
http: {},
|
||||
socks5: {},
|
||||
};
|
||||
|
||||
for (const [type, fields] of Object.entries(credentials)) {
|
||||
const alpn = type === 'hysteria2' ? ['h3'] : ['h2', 'http/1.1'];
|
||||
const tlsAlpn =
|
||||
type === 'hysteria2' ? '026833' : '02683208687474702f312e31';
|
||||
const output = produceExternal('QX', {
|
||||
type,
|
||||
name: type,
|
||||
server: 'example.com',
|
||||
port: 443,
|
||||
tls: true,
|
||||
alpn: ['h2', 'http/1.1'],
|
||||
alpn,
|
||||
'tls-no-session-ticket': true,
|
||||
'tls-no-session-reuse': false,
|
||||
...fields,
|
||||
});
|
||||
|
||||
expect(output).to.include('tls-alpn=02683208687474702f312e31');
|
||||
expectSubset(
|
||||
ProxyUtils.parse(output)[0],
|
||||
{
|
||||
type,
|
||||
alpn,
|
||||
'tls-alpn': tlsAlpn,
|
||||
'tls-no-session-ticket': true,
|
||||
'tls-no-session-reuse': false,
|
||||
},
|
||||
type,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('round-trips TLS options for Quantumult X Shadowsocks WSS', function () {
|
||||
const raw =
|
||||
'shadowsocks=example.com:443,method=aes-128-gcm,password=secret,obfs=wss,tls-alpn=026832,tls-no-session-ticket=true,tls-no-session-reuse=false,udp-relay=true,tag=SS WSS';
|
||||
|
||||
expect(produceExternal('QX', ProxyUtils.parse(raw))).to.equal(raw);
|
||||
});
|
||||
|
||||
it('uses name-cert-verify as Quantumult X tls-verification', function () {
|
||||
const output = produceExternal('QX', {
|
||||
type: 'vless',
|
||||
@@ -466,6 +489,80 @@ describe('Proxy text producers', function () {
|
||||
expect(output).to.equal(raw);
|
||||
});
|
||||
|
||||
it('round-trips Quantumult X Hysteria 2 options', function () {
|
||||
const [proxy] = ProxyUtils.parse(
|
||||
'hysteria2=example.com:443, password=pwd, port-hopping=443, 20000-50000, port-hopping-interval=30, salamander-password=obfskey, tls-host=apple.com, tls-verification=false, download-bandwidth=100, udp-relay=false, tag=hy2',
|
||||
);
|
||||
|
||||
expectSubset(proxy, {
|
||||
type: 'hysteria2',
|
||||
name: 'hy2',
|
||||
server: 'example.com',
|
||||
port: 443,
|
||||
password: 'pwd',
|
||||
tls: true,
|
||||
sni: 'apple.com',
|
||||
'skip-cert-verify': true,
|
||||
udp: false,
|
||||
ports: '443,20000-50000',
|
||||
'hop-interval': 30,
|
||||
obfs: 'salamander',
|
||||
'obfs-password': 'obfskey',
|
||||
down: '100',
|
||||
});
|
||||
const output =
|
||||
'hysteria2=example.com:443,password=pwd,port-hopping=443,20000-50000,port-hopping-interval=30,salamander-password=obfskey,tls-host=apple.com,tls-verification=false,download-bandwidth=100,udp-relay=false,tag=hy2';
|
||||
expect(produceExternal('QX', proxy)).to.equal(output);
|
||||
expect(
|
||||
produceExternal('QX', { ...proxy, ports: '443;20000-50000' }),
|
||||
).to.equal(output);
|
||||
expect(
|
||||
produceExternal('QX', {
|
||||
...proxy,
|
||||
ports: ' ',
|
||||
'hop-interval': ' ',
|
||||
}),
|
||||
).not.to.include(',port-hopping');
|
||||
});
|
||||
|
||||
it('limits Quantumult X Hysteria 2 port hopping intervals to 5–3600 seconds', function () {
|
||||
const prefix =
|
||||
'hysteria2=example.com:443,password=pwd,port-hopping=2000-3000';
|
||||
for (const interval of [1, 5, 3600, 3601]) {
|
||||
const option = `port-hopping-interval=${interval}`;
|
||||
const [proxy] = ProxyUtils.parse(`${prefix},${option},tag=hy2`);
|
||||
const output = produceExternal('QX', {
|
||||
...proxy,
|
||||
'hop-interval': interval,
|
||||
});
|
||||
|
||||
expect(output).to.include(',port-hopping=2000-3000,');
|
||||
if (interval === 5 || interval === 3600) {
|
||||
expect(proxy['hop-interval']).to.equal(interval);
|
||||
expect(output).to.include(`,${option},`);
|
||||
} else {
|
||||
expect(proxy).not.to.have.property('hop-interval');
|
||||
expect(output).not.to.include(',port-hopping-interval=');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('preserves TLS pins and the check URL in Quantumult X Hysteria 2', function () {
|
||||
const fingerprint = 'ab'.repeat(32);
|
||||
const pubkey = 'cd'.repeat(32);
|
||||
const checkUrl = 'https://check.example.com/ping?status=204';
|
||||
const raw = `hysteria2=example.com:443,password=pwd,tls-host=peer.example.com,tls-pubkey-sha256=${pubkey},tls-cert-sha256=${fingerprint},tls-verification=verify.example.com,udp-relay=true,server_check_url=${checkUrl},tag=hy2`;
|
||||
const [proxy] = ProxyUtils.parse(raw);
|
||||
|
||||
expectSubset(proxy, {
|
||||
'tls-fingerprint': fingerprint,
|
||||
'tls-pubkey-sha256': pubkey,
|
||||
'name-cert-verify': 'verify.example.com',
|
||||
'test-url': checkUrl,
|
||||
});
|
||||
expect(produceExternal('QX', proxy)).to.equal(raw);
|
||||
});
|
||||
|
||||
it('round-trips Loon Tailscale with optional authentication and explicit settings', function () {
|
||||
const proxies = ProxyUtils.parse(
|
||||
[
|
||||
|
||||
Reference in new issue
Block a user