feat: 协议过滤支持 MASQUE(Surge); Surge 输入输出支持 MASQUE(Surge)

This commit is contained in:
xream committed 2026-09-03 15:49:49 +08:00
1 parent bc56515a6e
commit 6fff06f1cc
6 files changed
+101 -3

No files matched your search

+1 -1
View File
@@ -87,7 +87,7 @@ Sub-Store also supports a configurable browser CORS allowlist for the backend AP
> [NaiveProxy](https://telegram.me/zhetengsha/4308)
- [x] QX (SS, SSR, VMess, Trojan, HTTP, SOCKS5, VLESS, AnyTLS)
- [x] Loon (SS, SSR, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard, VLESS, Hysteria 2, AnyTLS)
- [x] Surge (Direct, SS, VMess, Trojan, HTTP, HTTPS, HTTP/2 CONNECT, SOCKS5, SOCKS5-TLS, AnyTLS, TrustTunnel, TUIC, Snell, Hysteria 2, SSH(Password authentication only), External Proxy Program(only for macOS), WireGuard(Surge to Surge))
- [x] Surge (Direct, SS, VMess, Trojan, HTTP, HTTPS, HTTP/2 CONNECT, SOCKS5, SOCKS5-TLS, AnyTLS, TrustTunnel, TUIC, Snell, Hysteria 2, 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)
Deprecated(The frontend doesn't show it, but the backend still supports it, with the query parameter `target=Clash`):
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.36.57",
"version": "2.37.0",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"packageManager": "pnpm@11.0.9",
@@ -2905,6 +2905,19 @@ function Surge_TrustTunnel() {
const parse = (line) => getSurgeParser().parse(line);
return { name, test, parse };
}
function Surge_Masque() {
const name = 'Surge MASQUE Parser';
const test = (line) => {
return /^.*=\s*masque/.test(line.split(',')[0]);
};
const parse = (raw) => {
const { port_hopping, line } = surge_port_hopping(raw);
const proxy = getSurgeParser().parse(line);
proxy.ports = port_hopping;
return proxy;
};
return { name, test, parse };
}
function Surge_H2Connect() {
const name = 'Surge HTTP/2 CONNECT Parser';
const test = (line) => {
@@ -3117,6 +3130,7 @@ export default [
Surge_Direct(),
Surge_AnyTLS(),
Surge_TrustTunnel(),
Surge_Masque(),
Surge_H2Connect(),
Surge_SSH(),
Surge_SS(),
@@ -369,7 +369,7 @@ const grammars = String.raw`
}
}
start = (anytls/shadowsocks/vmess/trojan/h2_connect/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/trust_tunnel/direct) {
start = (masque/anytls/shadowsocks/vmess/trojan/h2_connect/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/trust_tunnel/direct) {
return proxy;
}
@@ -463,6 +463,10 @@ trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/headers/ma
proxy.type = "trusttunnel";
proxy.tls = true;
}
masque = tag equals "masque" address (usernamek/passwordk/port_hopping_interval/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/tls_verification/client_cert/sni/cert_verify_name/alpn/fast_open/tfo/udp_relay/ecn/block_quic/others)* {
proxy.type = "masque-surge";
proxy.tls = true;
}
direct = tag equals "direct" (udp_relay/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/block_quic/others)* {
proxy.type = "direct";
@@ -202,6 +202,8 @@ export default function Surge_Producer() {
return ssh(proxy);
case 'trusttunnel':
return trusttunnel(proxy);
case 'masque-surge':
return masque_surge(proxy);
}
if (opts['include-unsupported-proxy'] && proxy.type === 'wireguard') {
@@ -514,6 +516,61 @@ function trusttunnel(proxy) {
return result.toString();
}
function masque_surge(proxy) {
const result = new Result(proxy);
result.append(`${proxy.name}=masque,${proxy.server},${proxy.port}`);
result.appendIfPresent(`,username="${proxy.username}"`, 'username');
result.appendIfPresent(`,password="${proxy.password}"`, 'password');
if (hasNonBlankValue(proxy.ports)) {
result.append(
`,port-hopping="${String(proxy.ports).replace(/,/g, ';')}"`,
);
}
if (hasNonBlankValue(proxy['hop-interval'])) {
result.append(`,port-hopping-interval=${proxy['hop-interval']}`);
}
const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];
result.appendIfPresent(`,ip-version=${ip_version}`, 'ip-version');
result.appendIfPresent(
`,no-error-alert=${proxy['no-error-alert']}`,
'no-error-alert',
);
appendTlsProxyParams(result, proxy);
if (isPresent(proxy, 'tfo')) {
result.append(`,tfo=${proxy.tfo}`);
} else if (isPresent(proxy, 'fast-open')) {
result.append(`,tfo=${proxy['fast-open']}`);
}
result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
result.appendIfPresent(`,test-url=${proxy['test-url']}`, 'test-url');
result.appendIfPresent(
`,test-timeout=${proxy['test-timeout']}`,
'test-timeout',
);
result.appendIfPresent(`,test-udp=${proxy['test-udp']}`, 'test-udp');
result.appendIfPresent(`,hybrid=${proxy.hybrid}`, 'hybrid');
result.appendIfPresent(`,tos=${proxy.tos}`, 'tos');
result.appendIfPresent(
`,allow-other-interface=${proxy['allow-other-interface']}`,
'allow-other-interface',
);
result.appendIfPresent(
`,interface=${proxy['interface-name']}`,
'interface-name',
);
result.appendIfPresent(`,interface=${proxy.interface}`, 'interface');
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(
`,underlying-proxy=${proxy['underlying-proxy']}`,
'underlying-proxy',
);
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
return result.toString();
}
function h2Connect(proxy) {
const result = new Result(proxy);
result.append(`${proxy.name}=h2-connect,${proxy.server},${proxy.port}`);
@@ -1029,6 +1029,29 @@ describe('Proxy text producers', function () {
expect(alpnOutput).to.not.include(',h3=true');
});
it('round-trips Surge MASQUE without conflating it with Mihomo MASQUE', function () {
const [proxy] = ProxyUtils.parse(
'Surge MASQUE = masque,masque.example.com,443,username=user,password=secret,port-hopping="8443;8445-8447",port-hopping-interval=30,sni=sni.example.com,alpn=h3,skip-cert-verify=true,udp-relay=false,ecn=false',
);
expect(proxy).to.deep.include({
type: 'masque-surge',
username: 'user',
password: 'secret',
ports: '8443,8445-8447',
'hop-interval': 30,
tls: true,
sni: 'sni.example.com',
alpn: ['h3'],
'skip-cert-verify': true,
udp: false,
ecn: false,
});
expect(produceExternal('Surge', proxy)).to.equal(
'Surge MASQUE=masque,masque.example.com,443,username="user",password="secret",port-hopping="8443;8445-8447",port-hopping-interval=30,sni="sni.example.com",alpn="h3",skip-cert-verify=true,udp-relay=false,ecn=false',
);
});
it('omits Surge alpn and server-cert-verify-name for non-TLS outputs', function () {
const output = produceExternal('Surge', [
{