Skip to content

Commit e21c3ba

Browse files
committed
feat: Surge Hysteria 2 支持 Gecko 混淆
1 parent 0cac63f commit e21c3ba

5 files changed

Lines changed: 42 additions & 6 deletions

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.31.2",
3+
"version": "2.31.3",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"packageManager": "pnpm@11.0.9",

backend/src/core/proxy-utils/parsers/peggy/surge.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ wireguard = tag equals "wireguard" (section_name/no_error_alert/ip_version/under
420420
proxy.type = "wireguard-surge";
421421
handleShadowTLS();
422422
}
423-
hysteria2 = tag equals "hysteria2" address (no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/tls_verification/client_cert/passwordk/tls_fingerprint/download_bandwidth/ecn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/port_hopping_interval/salamander_password/others)* {
423+
hysteria2 = tag equals "hysteria2" address (no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/tls_verification/client_cert/passwordk/tls_fingerprint/download_bandwidth/ecn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/port_hopping_interval/salamander_password/gecko_password/others)* {
424424
proxy.type = "hysteria2";
425425
handleShadowTLS();
426426
}
@@ -595,6 +595,7 @@ token = comma "token" equals match:[^,]+ { proxy.token = match.join(""); }
595595
alpn = comma "alpn" equals match:[^,]+ { proxy.alpn = match.join(""); }
596596
uuidk = comma "uuid" equals match:[^,]+ { proxy.uuid = match.join(""); }
597597
salamander_password = comma "salamander-password" equals match:[^,]+ { proxy['obfs-password'] = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); proxy.obfs = 'salamander'; }
598+
gecko_password = comma "gecko-password" equals match:[^,]+ { proxy['obfs-password'] = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); proxy.obfs = 'gecko'; }
598599
599600
tag = match:[^=,]* { proxy.name = match.join("").trim(); }
600601
comma = _ "," _

backend/src/core/proxy-utils/producers/surge.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,8 +1297,13 @@ function wireguard_surge(proxy) {
12971297
}
12981298

12991299
function hysteria2(proxy) {
1300-
if (proxy['obfs-password'] && proxy.obfs != 'salamander') {
1301-
throw unsupported(`only salamander obfs is supported`);
1300+
const obfsPasswordField = {
1301+
salamander: 'salamander-password',
1302+
gecko: 'gecko-password',
1303+
}[proxy.obfs];
1304+
1305+
if (proxy['obfs-password'] && !obfsPasswordField) {
1306+
throw unsupported(`only salamander and gecko obfs are supported`);
13021307
}
13031308

13041309
const result = new Result(proxy);
@@ -1316,8 +1321,8 @@ function hysteria2(proxy) {
13161321
result.append(`,port-hopping-interval=${proxy['hop-interval']}`);
13171322
}
13181323

1319-
if (proxy['obfs-password'] && proxy.obfs == 'salamander') {
1320-
result.append(`,salamander-password="${proxy['obfs-password']}"`);
1324+
if (proxy['obfs-password'] && obfsPasswordField) {
1325+
result.append(`,${obfsPasswordField}="${proxy['obfs-password']}"`);
13211326
}
13221327

13231328
const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];

backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,6 +3714,20 @@ describe('Platform raw-format parser coverage', function () {
37143714
ports: '8443-8445',
37153715
},
37163716
},
3717+
{
3718+
title: 'parses hysteria2 gecko obfs lines',
3719+
input: 'Surge Hysteria2 Gecko = hysteria2,surge-hy2.example.com,443,password=secret,gecko-password="mask",sni=peer.example.com',
3720+
expected: {
3721+
type: 'hysteria2',
3722+
name: 'Surge Hysteria2 Gecko',
3723+
server: 'surge-hy2.example.com',
3724+
port: 443,
3725+
password: 'secret',
3726+
obfs: 'gecko',
3727+
'obfs-password': 'mask',
3728+
sni: 'peer.example.com',
3729+
},
3730+
},
37173731
{
37183732
title: 'parses external definitions with exec, args, local-port and addresses',
37193733
input: 'Surge External = external, exec="/usr/bin/ssh", local-port="1080", args="-D", args="localhost:1080", addresses="[2001:db8::1]", addresses="1.1.1.1"',

backend/src/test/proxy-producers/text.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,22 @@ describe('Proxy text producers', function () {
903903
);
904904
});
905905

906+
it('produces Surge Hysteria2 gecko obfs lines', function () {
907+
const output = produceExternal('Surge', {
908+
type: 'hysteria2',
909+
name: 'Surge Hysteria2 Gecko',
910+
server: 'hy2.example.com',
911+
port: 443,
912+
password: 'secret',
913+
obfs: 'gecko',
914+
'obfs-password': 'mask',
915+
});
916+
917+
expect(output).to.equal(
918+
'Surge Hysteria2 Gecko=hysteria2,hy2.example.com,443,password="secret",gecko-password="mask"',
919+
);
920+
});
921+
906922
it('produces Surge Snell v6 and filters v6 obfs', function () {
907923
const { result: output, errors } = captureErrors(() =>
908924
ProxyUtils.produce(

0 commit comments

Comments
 (0)