mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 06:43:08 +00:00
feat: Quantumult X Hysteria 2 支持 Gecko
This commit is contained in:
6 files changed
+113
-18
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.44.24",
|
||||
"version": "2.44.25",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -1093,7 +1093,7 @@ function lastParse(proxy) {
|
||||
if (
|
||||
['hysteria2'].includes(proxy.type) &&
|
||||
proxy.obfs &&
|
||||
!['salamander'].includes(proxy.obfs) &&
|
||||
!['salamander', 'gecko'].includes(proxy.obfs) &&
|
||||
!proxy['obfs-password']
|
||||
) {
|
||||
proxy['obfs-password'] = proxy.obfs;
|
||||
|
||||
@@ -151,7 +151,7 @@ mieru = "mieru" equals address
|
||||
}
|
||||
|
||||
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)* {
|
||||
(password/tls_host/tls_pubkey_sha256/tls_alpn/tls_no_session_ticket/tls_no_session_reuse/tls_fingerprint/tls_verification/udp_relay/download_bandwidth/hysteria2_obfs_password/port_hopping/port_hopping_interval/server_check_url/tag/others)* {
|
||||
proxy.type = "hysteria2";
|
||||
proxy.tls = true;
|
||||
}
|
||||
@@ -223,9 +223,16 @@ mieru_udp_over_tcp = comma "udp-over-tcp" equals raw:$[^,]* {
|
||||
}
|
||||
|
||||
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();
|
||||
hysteria2_obfs_password = comma type:("salamander"/"gecko") "-password" equals value:$((!next_parameter .)*) {
|
||||
if (proxy.obfs && proxy.obfs !== type) {
|
||||
throw new Error("QX Hysteria 2 cannot combine salamander-password and gecko-password");
|
||||
}
|
||||
const password = value.trim();
|
||||
if (options.byteLength(password, "utf8") < 4) {
|
||||
throw new Error("QX Hysteria 2 " + type + "-password must be at least 4 bytes");
|
||||
}
|
||||
proxy.obfs = type;
|
||||
proxy["obfs-password"] = password;
|
||||
}
|
||||
port_hopping = comma "port-hopping" equals ports:$(hopping_port (comma hopping_port)*) {
|
||||
proxy.ports = ports.replace(/\s/g, "");
|
||||
@@ -318,7 +325,10 @@ export default function getParser() {
|
||||
const generated = peggy.generate(grammars);
|
||||
parser = {
|
||||
parse(input, options) {
|
||||
const proxy = generated.parse(input, options);
|
||||
const proxy = generated.parse(input, {
|
||||
...options,
|
||||
byteLength: Buffer.byteLength,
|
||||
});
|
||||
const alpn = decodeQxAlpn(proxy['tls-alpn']);
|
||||
if (alpn) proxy.alpn = alpn;
|
||||
return proxy;
|
||||
|
||||
@@ -618,8 +618,11 @@ function anytls(proxy) {
|
||||
}
|
||||
|
||||
function hysteria2(proxy) {
|
||||
if (proxy.obfs && proxy.obfs !== 'salamander') {
|
||||
throw new Error('QX Hysteria 2 only supports Salamander obfuscation');
|
||||
const obfs = proxy.obfs || 'salamander';
|
||||
if (!['salamander', 'gecko'].includes(obfs)) {
|
||||
throw new Error(
|
||||
'QX Hysteria 2 only supports Salamander and Gecko obfuscation',
|
||||
);
|
||||
}
|
||||
|
||||
const result = new Result(proxy);
|
||||
@@ -632,10 +635,19 @@ function hysteria2(proxy) {
|
||||
if (Number.isInteger(interval) && interval >= 5 && interval <= 3600) {
|
||||
result.append(`,port-hopping-interval=${interval}`);
|
||||
}
|
||||
result.appendIfPresent(
|
||||
`,salamander-password=${proxy['obfs-password']}`,
|
||||
'obfs-password',
|
||||
);
|
||||
if (isPresent(proxy, 'obfs-password')) {
|
||||
const obfsPassword = String(proxy['obfs-password']);
|
||||
if (Buffer.byteLength(obfsPassword, 'utf8') < 4) {
|
||||
throw new Error(
|
||||
`QX Hysteria 2 ${obfs}-password must be at least 4 bytes`,
|
||||
);
|
||||
}
|
||||
result.append(`,${obfs}-password=${obfsPassword}`);
|
||||
} else if (obfs === 'gecko') {
|
||||
throw new Error(
|
||||
'QX Hysteria 2 Gecko obfuscation requires gecko-password',
|
||||
);
|
||||
}
|
||||
result.appendIfPresent(`,tls-host=${proxy.sni}`, 'sni');
|
||||
result.appendIfPresent(
|
||||
`,tls-pubkey-sha256=${proxy['tls-pubkey-sha256']}`,
|
||||
|
||||
@@ -617,12 +617,14 @@ describe('Proxy URI parser coverage', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects Hysteria2 salamander obfs without obfs-password', function () {
|
||||
const proxies = parseAll(
|
||||
'hy2://hy2-secret@hy2.example.com:443?obfs=salamander#Hy2%20Missing%20Password',
|
||||
);
|
||||
it('rejects Hysteria2 obfs modes without obfs-password', function () {
|
||||
for (const obfs of ['salamander', 'gecko']) {
|
||||
const proxies = parseAll(
|
||||
`hy2://hy2-secret@hy2.example.com:443?obfs=${obfs}#Hy2%20Missing%20Password`,
|
||||
);
|
||||
|
||||
expect(proxies).to.deep.equal([]);
|
||||
expect(proxies).to.be.empty;
|
||||
}
|
||||
});
|
||||
|
||||
it('parses TUIC URIs with colon-containing passwords and booleans', function () {
|
||||
|
||||
@@ -579,6 +579,77 @@ describe('Proxy text producers', function () {
|
||||
).not.to.include(',port-hopping');
|
||||
});
|
||||
|
||||
it('round-trips Quantumult X Hysteria 2 Gecko obfuscation', function () {
|
||||
const raw =
|
||||
'hysteria2=example.com:443,password=pwd,gecko-password=obfskey,tls-host=apple.com,tls-verification=true,udp-relay=true,tag=hy2-05';
|
||||
const [proxy] = ProxyUtils.parse(raw);
|
||||
|
||||
expectSubset(proxy, { obfs: 'gecko', 'obfs-password': 'obfskey' });
|
||||
expect(produceExternal('QX', proxy)).to.equal(raw);
|
||||
});
|
||||
|
||||
it('rejects short Quantumult X Hysteria 2 obfuscation passwords on import', function () {
|
||||
for (const obfs of ['gecko', 'salamander']) {
|
||||
const prefix = `hysteria2=example.com:443,password=pwd,${obfs}-password=`;
|
||||
const input = ['x', '中', '', '中x']
|
||||
.map((key) => `${prefix}${key},tag=hy2`)
|
||||
.join('\n');
|
||||
const { result } = captureErrors(() => ProxyUtils.parse(input));
|
||||
|
||||
expect(result).to.have.length(1);
|
||||
expectSubset(result[0], { obfs, 'obfs-password': '中x' });
|
||||
}
|
||||
});
|
||||
|
||||
it('requires Quantumult X Hysteria 2 obfuscation passwords to be at least 4 bytes', function () {
|
||||
for (const obfs of ['gecko', 'salamander']) {
|
||||
const proxies = ['x', '中', '中x'].map((obfsPassword) => ({
|
||||
type: 'hysteria2',
|
||||
name: 'hy2',
|
||||
server: 'example.com',
|
||||
port: 443,
|
||||
password: 'pwd',
|
||||
obfs,
|
||||
'obfs-password': obfsPassword,
|
||||
}));
|
||||
const { result, errors } = captureErrors(() =>
|
||||
produceExternal('QX', proxies),
|
||||
);
|
||||
|
||||
expect(result).to.equal(
|
||||
`hysteria2=example.com:443,password=pwd,${obfs}-password=中x,tag=hy2`,
|
||||
);
|
||||
expect(errors).to.have.length(2);
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects Quantumult X Hysteria 2 Gecko export without a key', function () {
|
||||
const proxy = {
|
||||
type: 'hysteria2',
|
||||
name: 'hy2',
|
||||
server: 'example.com',
|
||||
port: 443,
|
||||
password: 'pwd',
|
||||
obfs: 'gecko',
|
||||
};
|
||||
const { result, errors } = captureErrors(() =>
|
||||
ProxyUtils.produce([proxy], 'QX', 'external'),
|
||||
);
|
||||
|
||||
expect(result).to.equal('');
|
||||
expect(errors[0]).to.include('requires gecko-password');
|
||||
});
|
||||
|
||||
it('rejects combined Gecko and Salamander in Quantumult X Hysteria 2', function () {
|
||||
const { result } = captureErrors(() =>
|
||||
ProxyUtils.parse(
|
||||
'hysteria2=example.com:443,password=pwd,salamander-password=obfskey,gecko-password=obfskey,udp-relay=true,tag=hy2',
|
||||
),
|
||||
);
|
||||
|
||||
expect(result).to.be.empty;
|
||||
});
|
||||
|
||||
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';
|
||||
|
||||
Reference in new issue
Block a user