mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 06:43:08 +00:00
feat: Surge 支持 client-fingerprint
This commit is contained in:
6 files changed
+177
-12
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.44.18",
|
||||
"version": "2.44.19",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -192,6 +192,13 @@ function URI_PROXY() {
|
||||
password != null ? decodeURIComponent(password) : undefined,
|
||||
};
|
||||
|
||||
if (tls && query) {
|
||||
const fingerprint =
|
||||
getPathQueryParam(query, 'fp') ||
|
||||
getPathQueryParam(query, 'client-fingerprint');
|
||||
if (fingerprint) proxy['client-fingerprint'] = fingerprint;
|
||||
}
|
||||
|
||||
return proxy;
|
||||
};
|
||||
return { name, test, parse };
|
||||
@@ -900,7 +907,8 @@ function URI_VMess() {
|
||||
}
|
||||
}
|
||||
|
||||
proxy['client-fingerprint'] = params.fp;
|
||||
proxy['client-fingerprint'] =
|
||||
params.fp ?? params['client-fingerprint'];
|
||||
proxy.alpn = params.alpn ? params.alpn.split(',') : undefined;
|
||||
// 然而 wiki 和 app 实测中都没有字段表示这个
|
||||
// proxy['skip-cert-verify'] = /(TRUE)|1/i.test(params.allowInsecure);
|
||||
@@ -1882,7 +1890,7 @@ function URI_VLESS() {
|
||||
proxy.flow = flow;
|
||||
}
|
||||
}
|
||||
proxy['client-fingerprint'] = params.fp;
|
||||
proxy['client-fingerprint'] = params.fp ?? params['client-fingerprint'];
|
||||
proxy.alpn = params.alpn ? params.alpn.split(',') : undefined;
|
||||
proxy['skip-cert-verify'] =
|
||||
/(TRUE)|1/i.test(params.allowInsecure) ||
|
||||
|
||||
@@ -23,6 +23,7 @@ const grammars = String.raw`
|
||||
const shadowTLS = {};
|
||||
const xhttpOpts = { mode: "auto" };
|
||||
let xhttpEnabled = false;
|
||||
let clientFingerprint;
|
||||
const $ = {};
|
||||
|
||||
function handleWebsocket() {
|
||||
@@ -375,6 +376,15 @@ const grammars = String.raw`
|
||||
}
|
||||
|
||||
start = (masque/anytls/shadowsocks/vmess/vless/trojan/h2_connect/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/trust_tunnel/direct) {
|
||||
if (
|
||||
["auto", "none", "apple-26", "chromium-155"].includes(clientFingerprint) &&
|
||||
proxy.network !== "h3" &&
|
||||
(proxy.tls || proxy.type === "trojan")
|
||||
) {
|
||||
proxy._surge_client_fingerprint = clientFingerprint;
|
||||
if (clientFingerprint === "apple-26") proxy["client-fingerprint"] = "ios";
|
||||
if (clientFingerprint === "chromium-155") proxy["client-fingerprint"] = "chrome";
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@@ -389,7 +399,7 @@ shadowsocks = tag equals "ss" address (method/passwordk/obfs/obfs_host/obfs_uri/
|
||||
}
|
||||
handleShadowTLS();
|
||||
}
|
||||
vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/ws_http_upgrade/ws_path/ws_headers/vmess_method/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls/sni/cert_verify_name/alpn/tls_fingerprint/tls_verification/client_cert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/ws_http_upgrade/ws_path/ws_headers/vmess_method/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
proxy.type = "vmess";
|
||||
proxy.cipher = proxy.cipher || "auto";
|
||||
// Surfboard 与 Surge 默认不一致, 不管 Surfboard https://getsurfboard.com/docs/profile-format/proxy/external-proxy/vmess
|
||||
@@ -401,7 +411,7 @@ vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/ws_http_upgrade/ws_
|
||||
handleWebsocket();
|
||||
handleShadowTLS();
|
||||
}
|
||||
vless = tag equals "vless" address (vless_username/vless_option/reality_option/ws/ws_http_upgrade/ws_path/ws_headers/grpc/grpc_service_name/grpc_mode/grpc_authority/xhttp/xhttp_headers/xhttp_option/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls/sni/cert_verify_name/alpn/tls_fingerprint/tls_verification/client_cert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
vless = tag equals "vless" address (vless_username/vless_option/reality_option/ws/ws_http_upgrade/ws_path/ws_headers/grpc/grpc_service_name/grpc_mode/grpc_authority/xhttp/xhttp_headers/xhttp_option/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
proxy.type = "vless";
|
||||
proxy["packet-encoding"] = "xudp";
|
||||
if (proxy["reality-opts"] && proxy["reality-opts"]["public-key"]) proxy.tls = true;
|
||||
@@ -413,17 +423,17 @@ vless = tag equals "vless" address (vless_username/vless_option/reality_option/w
|
||||
}
|
||||
handleShadowTLS();
|
||||
}
|
||||
trojan = tag equals "trojan" address (passwordk/ws/ws_http_upgrade/ws_path/ws_headers/tls/sni/cert_verify_name/alpn/tls_fingerprint/tls_verification/client_cert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
trojan = tag equals "trojan" address (passwordk/ws/ws_http_upgrade/ws_path/ws_headers/tls/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
proxy.type = "trojan";
|
||||
handleWebsocket();
|
||||
handleShadowTLS();
|
||||
}
|
||||
https = tag equals "https" address (username password)? (usernamek passwordk)? (headers/sni/cert_verify_name/alpn/tls_fingerprint/tls_verification/client_cert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
https = tag equals "https" address (username password)? (usernamek passwordk)? (headers/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
proxy.type = "http";
|
||||
proxy.tls = true;
|
||||
handleShadowTLS();
|
||||
}
|
||||
h2_connect = tag equals "h2-connect" address (username password)? (usernamek passwordk)? (headers/max_streams/sni/cert_verify_name/alpn/tls_fingerprint/tls_verification/client_cert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
h2_connect = tag equals "h2-connect" address (username password)? (usernamek passwordk)? (headers/max_streams/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
proxy.type = "h2-connect";
|
||||
proxy.tls = true;
|
||||
handleShadowTLS();
|
||||
@@ -467,16 +477,16 @@ socks5 = tag equals "socks5" address (username password)? (usernamek passwordk)?
|
||||
proxy.type = "socks5";
|
||||
handleShadowTLS();
|
||||
}
|
||||
socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/cert_verify_name/alpn/tls_fingerprint/tls_verification/client_cert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
||||
proxy.type = "socks5";
|
||||
proxy.tls = true;
|
||||
handleShadowTLS();
|
||||
}
|
||||
anytls = tag equals "anytls" address (passwordk/reuse/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/block_quic/others)* {
|
||||
anytls = tag equals "anytls" address (passwordk/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/client_fingerprint/tls_verification/client_cert/sni/cert_verify_name/alpn/fast_open/tfo/block_quic/others)* {
|
||||
proxy.type = "anytls";
|
||||
proxy.tls = true;
|
||||
}
|
||||
trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/client_random_auth_key/headers/max_streams/reuse/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/h3/fast_open/tfo/block_quic/others)* {
|
||||
trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/client_random_auth_key/headers/max_streams/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/client_fingerprint/tls_verification/client_cert/sni/cert_verify_name/alpn/h3/fast_open/tfo/block_quic/others)* {
|
||||
proxy.type = "trusttunnel";
|
||||
proxy.tls = true;
|
||||
}
|
||||
@@ -560,6 +570,7 @@ sni = comma "sni" equals match:[^,]+ {
|
||||
cert_verify_name = comma "server-cert-verify-name" equals match:[^,]+ { proxy["name-cert-verify"] = stripQuotes(match.join("")); }
|
||||
tls_verification = comma "skip-cert-verify" equals flag:bool { proxy["skip-cert-verify"] = flag; }
|
||||
tls_fingerprint = comma "server-cert-fingerprint-sha256" equals tls_fingerprint:$[^,]+ { proxy["tls-fingerprint"] = tls_fingerprint.trim(); }
|
||||
client_fingerprint = comma "client-fingerprint" equals value:quoted_value { clientFingerprint = value.trim().toLowerCase(); }
|
||||
client_cert = comma "client-cert" equals match:[^,]+ { proxy["keystore-client-cert"] = stripQuotes(match.join("")); }
|
||||
|
||||
snell_psk = comma "psk" equals value:quoted_value { proxy.psk = value; }
|
||||
|
||||
@@ -106,7 +106,7 @@ function parseTrojan(url) {
|
||||
params.sni || params.peer;
|
||||
|
||||
proxy["client-fingerprint"] =
|
||||
params.fp;
|
||||
params.fp ?? params["client-fingerprint"];
|
||||
|
||||
proxy["tls-fingerprint"] =
|
||||
params.pcs;
|
||||
|
||||
@@ -67,6 +67,46 @@ function appendAlpn(result, proxy) {
|
||||
if (alpn) result.append(`,alpn="${alpn}"`);
|
||||
}
|
||||
|
||||
function appendClientFingerprint(result, proxy) {
|
||||
if (
|
||||
proxy.network === 'h3' ||
|
||||
['tuic', 'hysteria2', 'masque-surge'].includes(proxy.type)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const value =
|
||||
proxy._surge_client_fingerprint ?? proxy['client-fingerprint'];
|
||||
if (typeof value !== 'string') return;
|
||||
|
||||
let fingerprint = value.trim().toLowerCase();
|
||||
if (!['auto', 'none', 'apple-26', 'chromium-155'].includes(fingerprint)) {
|
||||
const family = fingerprint
|
||||
.replace(/^hello/, '')
|
||||
.split(/[-_]/, 1)[0]
|
||||
.replace(/([a-z])\d+$/, '$1');
|
||||
if (['chrome', 'edge', 'android', '360', 'qq'].includes(family)) {
|
||||
fingerprint = 'chromium-155';
|
||||
} else if (['safari', 'ios'].includes(family)) {
|
||||
fingerprint = 'apple-26';
|
||||
} else if (
|
||||
[
|
||||
'firefox',
|
||||
'golang',
|
||||
'random',
|
||||
'randomized',
|
||||
'randomizedalpn',
|
||||
'randomizednoalpn',
|
||||
].includes(family)
|
||||
) {
|
||||
fingerprint = 'auto';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
result.append(`,client-fingerprint=${fingerprint}`);
|
||||
}
|
||||
|
||||
function getShadowTLSAlpn(proxy) {
|
||||
return formatSurgeAlpn(proxy?.['plugin-opts']?.alpn ?? proxy?.alpn);
|
||||
}
|
||||
@@ -126,6 +166,7 @@ function appendTlsProxyParams(result, proxy, enabled = true) {
|
||||
) {
|
||||
result.append(`,client-cert=${quoteSurgeValue(clientCert)}`);
|
||||
}
|
||||
appendClientFingerprint(result, proxy);
|
||||
}
|
||||
|
||||
function appendSshPrivateKey(result, proxy) {
|
||||
@@ -747,6 +788,7 @@ function appendVlessParams(result, proxy) {
|
||||
}
|
||||
result.appendIfPresent(`,sni="${proxy.sni}"`, 'sni');
|
||||
appendAlpn(result, proxy);
|
||||
appendClientFingerprint(result, proxy);
|
||||
} else {
|
||||
result.appendIfPresent(`,tls=${proxy.tls}`, 'tls');
|
||||
appendTlsProxyParams(result, proxy, Boolean(tls));
|
||||
|
||||
@@ -1539,6 +1539,110 @@ describe('Proxy text producers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('round-trips Surge client-fingerprint for TLS proxies', function () {
|
||||
const cases = [
|
||||
['https', '', 'auto'],
|
||||
['socks5-tls', '', 'none'],
|
||||
['h2-connect', '', 'apple-26', 'ios'],
|
||||
['trust-tunnel', '', 'chromium-155', 'chrome'],
|
||||
['trojan', ',password=secret', 'chromium-155', 'chrome'],
|
||||
['anytls', ',password=secret', 'none'],
|
||||
['vmess', `,username=${UUID},tls=true`, 'apple-26', 'ios'],
|
||||
['vless', `,username=${UUID},tls=true`, 'auto'],
|
||||
[
|
||||
'vless',
|
||||
`,username=${UUID},reality-public-key=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`,
|
||||
'chromium-155',
|
||||
'chrome',
|
||||
],
|
||||
];
|
||||
|
||||
for (const [type, params, fingerprint, generic] of cases) {
|
||||
const [proxy] = ProxyUtils.parse(
|
||||
`Fingerprint=${type},example.com,443,client-fingerprint="${fingerprint}"${params}`,
|
||||
);
|
||||
expect(proxy, type).to.have.property(
|
||||
'_surge_client_fingerprint',
|
||||
fingerprint,
|
||||
);
|
||||
expect(proxy['client-fingerprint'], type).to.equal(generic);
|
||||
|
||||
for (const target of ['Surge', 'SurgeMac']) {
|
||||
const output = produceExternal(target, proxy);
|
||||
expect(output).to.match(
|
||||
new RegExp(`,client-fingerprint=${fingerprint}(?:,|$)`),
|
||||
);
|
||||
expect(ProxyUtils.parse(output)[0]).to.have.property(
|
||||
'_surge_client_fingerprint',
|
||||
fingerprint,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('maps share links to Surge client-fingerprint values', function () {
|
||||
const trojan = 'trojan://secret@example.com:443';
|
||||
const cases = [
|
||||
[`${trojan}?fp=chrome`, 'chromium-155'],
|
||||
[`${trojan}?fp=edge`, 'chromium-155'],
|
||||
[`${trojan}?fp=360`, 'chromium-155'],
|
||||
[`${trojan}?fp=qq`, 'chromium-155'],
|
||||
[`${trojan}?fp=chrome120`, 'chromium-155'],
|
||||
[`${trojan}?fp=HelloChrome_120`, 'chromium-155'],
|
||||
[`${trojan}?fp=HelloIOS_14`, 'apple-26'],
|
||||
[`${trojan}?fp=firefox`, 'auto'],
|
||||
[`${trojan}?fp=golang`, 'auto'],
|
||||
[`${trojan}?fp=HelloRandomizedNoALPN`, 'auto'],
|
||||
[`${trojan}?fp=unknown`, undefined],
|
||||
[trojan, undefined],
|
||||
['https://example.com:443?fp=android', 'chromium-155'],
|
||||
[
|
||||
'socks5+tls://example.com:443?client-fingerprint=safari',
|
||||
'apple-26',
|
||||
],
|
||||
['anytls://secret@example.com:443?fp=none', 'none'],
|
||||
[`vmess://${UUID}@example.com:443?security=tls&fp=ios`, 'apple-26'],
|
||||
[
|
||||
`vless://${UUID}@example.com:443?security=reality&pbk=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&fp=chrome`,
|
||||
'chromium-155',
|
||||
],
|
||||
];
|
||||
|
||||
for (const [link, fingerprint] of cases) {
|
||||
const output = produceExternal('Surge', ProxyUtils.parse(link));
|
||||
expect(
|
||||
output.match(/,client-fingerprint=([^,]+)/)?.[1],
|
||||
link,
|
||||
).to.equal(fingerprint);
|
||||
}
|
||||
});
|
||||
|
||||
it('omits Surge client-fingerprint for plaintext and QUIC proxies', function () {
|
||||
for (const [type, params] of [
|
||||
['http', ''],
|
||||
['socks5', ''],
|
||||
['vmess', `,username=${UUID},tls=false`],
|
||||
['vless', `,username=${UUID}`],
|
||||
['trust-tunnel', ',h3=true'],
|
||||
['tuic', ',token=secret'],
|
||||
['hysteria2', ',password=secret'],
|
||||
['masque', ''],
|
||||
]) {
|
||||
const [proxy] = ProxyUtils.parse(
|
||||
`Fingerprint=${type},example.com,443,client-fingerprint=apple-26${params}`,
|
||||
);
|
||||
expect(proxy, type).to.not.have.property(
|
||||
'_surge_client_fingerprint',
|
||||
);
|
||||
expect(proxy, type).to.not.have.property('client-fingerprint');
|
||||
const output = produceExternal('Surge', {
|
||||
...proxy,
|
||||
'client-fingerprint': 'chrome',
|
||||
});
|
||||
expect(output).to.not.include('client-fingerprint=');
|
||||
}
|
||||
});
|
||||
|
||||
it('round-trips Surge TrustTunnel h3 as network', function () {
|
||||
const [proxy] = ProxyUtils.parse(
|
||||
'Surge TrustTunnel H3 = trust-tunnel,trust.example.com,443,h3=true',
|
||||
|
||||
Reference in new issue
Block a user