mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-12-05 18:57:43 +00:00
This commit is contained in:
7 files changed
+385
-42
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.44.31",
|
||||
"version": "2.44.32",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -569,7 +569,8 @@ function produce(proxies, targetPlatform, type, opts = {}) {
|
||||
['surge', 'surgemac', 'shadowrocket'].includes(
|
||||
normalizedTarget,
|
||||
) ||
|
||||
(normalizedTarget === 'surfboard' && proxy.type === 'vless')
|
||||
(normalizedTarget === 'surfboard' &&
|
||||
['h2-connect', 'vless'].includes(proxy.type))
|
||||
) {
|
||||
proxy.sni = 'off';
|
||||
} else if (
|
||||
@@ -687,6 +688,10 @@ function supportsRootProxyHeaders(proxy, targetPlatform) {
|
||||
return ['http', 'h2-connect', 'trusttunnel'].includes(proxy.type);
|
||||
}
|
||||
|
||||
if (normalizedTarget === 'surfboard') {
|
||||
return proxy.type === 'h2-connect';
|
||||
}
|
||||
|
||||
if (normalizedTarget === 'egern') {
|
||||
return proxy.type === 'http';
|
||||
}
|
||||
@@ -826,9 +831,12 @@ function lastParse(proxy) {
|
||||
if (proxy.network === 'xhttp') {
|
||||
inferLoonRealityMlkem(proxy['xhttp-opts']?.['download-settings']);
|
||||
}
|
||||
proxy.udp = ![false, 0, '0', 'false', 'off'].includes(
|
||||
typeof proxy.udp === 'string' ? proxy.udp.toLowerCase() : proxy.udp,
|
||||
);
|
||||
// CONNECT-UDP is opt-in for HTTP/2 CONNECT.
|
||||
if (proxy.type !== 'h2-connect' || proxy.udp != null) {
|
||||
proxy.udp = ![false, 0, '0', 'false', 'off'].includes(
|
||||
typeof proxy.udp === 'string' ? proxy.udp.toLowerCase() : proxy.udp,
|
||||
);
|
||||
}
|
||||
if (typeof proxy.cipher === 'string') {
|
||||
proxy.cipher = proxy.cipher.toLowerCase();
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ const grammars = String.raw`
|
||||
function unescapeQuotedValue(value) {
|
||||
return value.replace(/\\(["\\])/g, "$1");
|
||||
}
|
||||
function supportsQuotedEscapes() {
|
||||
return proxy.type === "vless" || proxy.type === "h2-connect";
|
||||
}
|
||||
function readQuotedHeaderKey(text, start) {
|
||||
const quote = text[start];
|
||||
const withEscapes = proxy.type === "vless" && quote === '"';
|
||||
@@ -469,11 +472,29 @@ https = tag equals "https" address (username password)? (usernamek passwordk)? (
|
||||
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/client_fingerprint/tls_verification/client_cert/ech_config/shadow_tls_version/shadow_tls_sni/shadow_tls_password/proxy_policy_parameter/others)* {
|
||||
proxy.type = "h2-connect";
|
||||
h2_connect = tag equals h2_connect_address h2_credentials? (h2_credential/h2_headers/headers/max_streams/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/proxy_policy_parameter/others)* {
|
||||
proxy.tls = true;
|
||||
handleShadowTLS();
|
||||
}
|
||||
h2_connect_address = "h2-connect" address { proxy.type = "h2-connect"; }
|
||||
h2_credentials = comma !([a-zA-Z0-9-]+ equals) user:quoted_value comma pass:quoted_value {
|
||||
proxy.username = user;
|
||||
proxy.password = pass;
|
||||
}
|
||||
h2_credential = comma key:("username"/"password") equals value:quoted_value { proxy[key] = value; }
|
||||
// Keep nested single-quoted Surge header values in the shared header parser.
|
||||
h2_headers = comma "headers" equals value:double_quoted_value &{
|
||||
return !/(?:^|;)\s*[^:;]+:\s*'.*?'\s*(?:;|$)/.test(value);
|
||||
} {
|
||||
const entries = [];
|
||||
for (const pair of value.split(";")) {
|
||||
const separator = pair.indexOf(":");
|
||||
if (separator <= 0) continue;
|
||||
const key = pair.slice(0, separator).trim();
|
||||
if (key) entries.push([key, unescapeQuotedValue(pair.slice(separator + 1).trim())]);
|
||||
}
|
||||
proxy.headers = Object.fromEntries(entries);
|
||||
}
|
||||
http = tag equals "http" address (username password)? (usernamek passwordk)? (headers/shadow_tls_version/shadow_tls_sni/shadow_tls_password/proxy_policy_parameter/others)* {
|
||||
proxy.type = "http";
|
||||
handleShadowTLS();
|
||||
@@ -505,7 +526,7 @@ wireguard = tag equals "wireguard" (section_name/common_policy_parameter/proxy_o
|
||||
if (!proxy["section-name"]) error("WireGuard requires section-name");
|
||||
proxy.type = "wireguard-surge";
|
||||
}
|
||||
hysteria2 = tag equals "hysteria2" address (sni/cert_verify_name/alpn/tls_verification/client_cert/ech_config/passwordk/tls_fingerprint/download_bandwidth/shadow_tls_version/shadow_tls_sni/shadow_tls_password/port_hopping/port_hopping_interval/salamander_password/gecko_password/proxy_policy_parameter/others)* {
|
||||
hysteria2 = tag equals "hysteria2" address (sni/cert_verify_name/alpn/tls_verification/client_cert/ech_config/passwordk/tls_fingerprint/download_bandwidth/shadow_tls_version/shadow_tls_sni/shadow_tls_password/port_hopping/port_hopping_interval/hysteria2_obfs_password/proxy_policy_parameter/others)* {
|
||||
proxy.type = "hysteria2";
|
||||
handleShadowTLS();
|
||||
}
|
||||
@@ -635,7 +656,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(); }
|
||||
tls_fingerprint = comma "server-cert-fingerprint-sha256" equals value:quoted_value { proxy["tls-fingerprint"] = value.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("")); }
|
||||
ech_config = comma "ech-config" equals value:quoted_value { echConfig = value; }
|
||||
@@ -707,7 +728,7 @@ obfs_host = comma "obfs-host" equals match:[^,]+ { obfs.host = match.join("").re
|
||||
obfs_uri = comma "obfs-uri" equals path:uri { obfs.path = path }
|
||||
uri = $[^,]+
|
||||
|
||||
udp_relay = comma "udp-relay" equals flag:bool { proxy.udp = flag; }
|
||||
udp_relay = comma "udp-relay" equals flag:policy_bool { proxy.udp = flag; }
|
||||
fast_open = comma "fast-open" equals flag:policy_bool { proxy.tfo = flag; }
|
||||
reuse = comma "reuse" equals flag:bool { proxy.reuse = flag; }
|
||||
ecn = comma "ecn" equals mode:policy_toggle { if (mode !== undefined) proxy.ecn = mode; }
|
||||
@@ -754,14 +775,21 @@ alpn = comma "alpn" equals match:quoted_value {
|
||||
}
|
||||
h3 = comma "h3" equals flag:bool { if (flag) proxy.network = "h3"; }
|
||||
quoted_value
|
||||
= '"' value:$(("\\" ('"' / "\\") / [^"])*) '"' &(_ ("," / !.)) { return proxy.type === "vless" ? unescapeQuotedValue(value) : value; }
|
||||
= value:double_quoted_value { return supportsQuotedEscapes() ? unescapeQuotedValue(value) : value; }
|
||||
/ '"' match:$[^"]* '"' { return match; }
|
||||
/ "'" match:$[^']* "'" { return proxy.type === "vless" ? unescapeQuotedValue(match) : match; }
|
||||
/ "'" match:$[^']* "'" { return supportsQuotedEscapes() ? unescapeQuotedValue(match) : match; }
|
||||
/ value:uri { return value.trim(); }
|
||||
double_quoted_value = '"' value:$(("\\" ('"' / "\\") / [^"])*) '"' &(_ ("," / !.)) { return value; }
|
||||
vless_quoted_value = &{ return proxy.type === "vless"; } value:quoted_value { return value.trim(); }
|
||||
uuidk = comma "uuid" equals match:[^,]+ { proxy.uuid = match.join(""); }
|
||||
salamander_password = comma "salamander-password" equals match:[^,]+ { proxy['obfs-password'] = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); proxy.obfs = 'salamander'; }
|
||||
gecko_password = comma "gecko-password" equals match:[^,]+ { proxy['obfs-password'] = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); proxy.obfs = 'gecko'; }
|
||||
hysteria2_obfs_password = comma mode:("salamander"/"gecko") "-password" equals value:(
|
||||
text:double_quoted_value { return unescapeQuotedValue(text); }
|
||||
/ quoted_value
|
||||
) {
|
||||
if (proxy.obfs === "gecko" && mode === "salamander") return;
|
||||
proxy.obfs = mode;
|
||||
proxy["obfs-password"] = value;
|
||||
}
|
||||
|
||||
tag = match:[^=,]* { proxy.name = match.join("").trim(); }
|
||||
comma = _ "," _
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import _ from 'lodash';
|
||||
import { Result, isPresent, supportsVlessTransportSecurity } from './utils';
|
||||
import {
|
||||
Result,
|
||||
isPresent,
|
||||
quoteProxyValue,
|
||||
supportsVlessTransportSecurity,
|
||||
} from './utils';
|
||||
import { isNotBlank } from '@/utils';
|
||||
import { SURGE_XHTTP_FIELDS } from '../surge-xhttp';
|
||||
import {
|
||||
VMESS_SECURITY_AUTO,
|
||||
formatSurgeVmessEncryptMethod,
|
||||
} from '../vmess-security';
|
||||
// import $ from '@/core/app';
|
||||
|
||||
const targetPlatform = 'Surfboard';
|
||||
@@ -15,11 +24,16 @@ function appendTlsProxyParams(result, proxy, enabled = true) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fingerprint = String(proxy['tls-fingerprint']);
|
||||
result.appendIfPresent(
|
||||
`,server-cert-fingerprint-sha256=${proxy['tls-fingerprint']}`,
|
||||
`,server-cert-fingerprint-sha256=${
|
||||
fingerprint.includes(',')
|
||||
? quoteProxyValue(fingerprint)
|
||||
: fingerprint
|
||||
}`,
|
||||
'tls-fingerprint',
|
||||
);
|
||||
result.appendIfPresent(`,sni="${proxy.sni}"`, 'sni');
|
||||
result.appendIfPresent(`,sni=${quoteProxyValue(proxy.sni)}`, 'sni');
|
||||
result.appendIfPresent(
|
||||
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
|
||||
'skip-cert-verify',
|
||||
@@ -48,6 +62,8 @@ export default function Surfboard_Producer() {
|
||||
return vless(proxy);
|
||||
case 'http':
|
||||
return http(proxy);
|
||||
case 'h2-connect':
|
||||
return h2Connect(proxy);
|
||||
case 'snell':
|
||||
return snell(proxy);
|
||||
case 'tuic':
|
||||
@@ -109,10 +125,12 @@ function tuic(proxy) {
|
||||
}
|
||||
function hysteria2(proxy) {
|
||||
if (
|
||||
(proxy.obfs && proxy.obfs !== 'salamander') ||
|
||||
(proxy['obfs-password'] && proxy.obfs !== 'salamander')
|
||||
(proxy.obfs || proxy['obfs-password']) &&
|
||||
!['salamander', 'gecko'].includes(proxy.obfs)
|
||||
) {
|
||||
throw new Error(`Surfboard Hysteria2 only supports salamander obfs`);
|
||||
throw new Error(
|
||||
'Surfboard Hysteria2 supports Salamander and Gecko obfs',
|
||||
);
|
||||
}
|
||||
|
||||
const result = new Result(proxy);
|
||||
@@ -131,7 +149,11 @@ function hysteria2(proxy) {
|
||||
}
|
||||
|
||||
if (proxy['obfs-password']) {
|
||||
result.append(`,salamander-password="${proxy['obfs-password']}"`);
|
||||
result.append(
|
||||
`,${proxy.obfs}-password=${quoteProxyValue(
|
||||
proxy['obfs-password'],
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
|
||||
// tls verification
|
||||
@@ -296,9 +318,18 @@ function trojan(proxy) {
|
||||
}
|
||||
|
||||
function vmess(proxy) {
|
||||
const cipher = String(proxy.cipher ?? '')
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
const encryptMethod = formatSurgeVmessEncryptMethod(cipher);
|
||||
if (cipher && cipher !== VMESS_SECURITY_AUTO && !encryptMethod) {
|
||||
throw new Error(`Surfboard does not support VMess cipher ${cipher}`);
|
||||
}
|
||||
|
||||
const result = new Result(proxy);
|
||||
result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
|
||||
result.appendIfPresent(`,username=${proxy.uuid}`, 'uuid');
|
||||
if (encryptMethod) result.append(`,encrypt-method=${encryptMethod}`);
|
||||
|
||||
// transport
|
||||
handleTransport(result, proxy);
|
||||
@@ -344,9 +375,7 @@ function vless(proxy) {
|
||||
if (value == null) return;
|
||||
const text = String(value);
|
||||
const param =
|
||||
!text || /[,;"'\s\\]/.test(text)
|
||||
? `"${text.replace(/["\\]/g, '\\$&')}"`
|
||||
: text;
|
||||
!text || /[,;"'\s\\]/.test(text) ? quoteProxyValue(text) : text;
|
||||
result.append(`,${key}=${param}`);
|
||||
};
|
||||
append('username', proxy.uuid);
|
||||
@@ -447,6 +476,70 @@ function http(proxy) {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
function h2Connect(proxy) {
|
||||
if (proxy.plugin) {
|
||||
throw new Error('Surfboard HTTP/2 CONNECT does not support plugins');
|
||||
}
|
||||
if ((proxy.username == null) !== (proxy.password == null)) {
|
||||
throw new Error(
|
||||
'HTTP/2 CONNECT authentication requires both username and password',
|
||||
);
|
||||
}
|
||||
|
||||
const result = new Result(proxy);
|
||||
result.append(`${proxy.name}=h2-connect,${proxy.server},${proxy.port}`);
|
||||
result.appendIfPresent(
|
||||
`,username=${quoteProxyValue(proxy.username)}`,
|
||||
'username',
|
||||
);
|
||||
result.appendIfPresent(
|
||||
`,password=${quoteProxyValue(proxy.password)}`,
|
||||
'password',
|
||||
);
|
||||
|
||||
const headers = Object.entries(proxy.headers ?? {})
|
||||
.filter(([, value]) => value != null)
|
||||
.map(([key, value]) => {
|
||||
if (
|
||||
!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(key) ||
|
||||
// HTAB is allowed within HTTP field values.
|
||||
// eslint-disable-next-line no-control-regex
|
||||
/[;\x00-\x08\x0a-\x1f\x7f]/.test(String(value))
|
||||
) {
|
||||
throw new Error('Invalid HTTP/2 CONNECT header name or value');
|
||||
}
|
||||
return `${key}:${value}`;
|
||||
});
|
||||
if (headers.length) {
|
||||
result.append(`,headers=${quoteProxyValue(headers.join(';'))}`);
|
||||
}
|
||||
|
||||
if (isPresent(proxy, 'max-streams')) {
|
||||
const maxStreams = Number(String(proxy['max-streams']));
|
||||
if (!Number.isSafeInteger(maxStreams) || maxStreams < 1) {
|
||||
throw new Error(
|
||||
'HTTP/2 CONNECT max-streams must be a positive integer',
|
||||
);
|
||||
}
|
||||
result.append(`,max-streams=${maxStreams}`);
|
||||
}
|
||||
appendTlsProxyParams(result, proxy);
|
||||
result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
|
||||
if (['auto', 'on', 'off'].includes(proxy['block-quic'])) {
|
||||
result.append(`,block-quic=${proxy['block-quic']}`);
|
||||
}
|
||||
result.appendIfPresent(
|
||||
`,underlying-proxy=${quoteProxyValue(proxy['underlying-proxy'])}`,
|
||||
'underlying-proxy',
|
||||
);
|
||||
|
||||
const line = result.toString();
|
||||
if (/[\r\n]/.test(line)) {
|
||||
throw new Error('HTTP/2 CONNECT proxy contains a line break');
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
function socks5(proxy) {
|
||||
const result = new Result(proxy);
|
||||
const type = proxy.tls ? 'socks5-tls' : 'socks5';
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
Result,
|
||||
isPresent,
|
||||
normalizeWireGuardInterface,
|
||||
quoteProxyValue,
|
||||
supportsVlessTransportSecurity,
|
||||
} from './utils';
|
||||
import { isNotBlank, getIfNotBlank, isIPv6, isPlainObject } from '@/utils';
|
||||
@@ -966,7 +967,9 @@ function hysteria2(proxy) {
|
||||
appendPortHopping(result, proxy);
|
||||
|
||||
if (proxy['obfs-password'] && obfsPasswordField) {
|
||||
result.append(`,${obfsPasswordField}="${proxy['obfs-password']}"`);
|
||||
result.append(
|
||||
`,${obfsPasswordField}=${quoteProxyValue(proxy['obfs-password'])}`,
|
||||
);
|
||||
}
|
||||
|
||||
// tls verification
|
||||
|
||||
@@ -33,6 +33,10 @@ export function isPresent(obj, attr) {
|
||||
return typeof data !== 'undefined' && data !== null;
|
||||
}
|
||||
|
||||
export function quoteProxyValue(value) {
|
||||
return `"${String(value).replace(/["\\]/g, '\\$&')}"`;
|
||||
}
|
||||
|
||||
export function supportsVlessTransportSecurity(proxy) {
|
||||
const { network, flow, encryption } = proxy;
|
||||
const reality = proxy['reality-opts'];
|
||||
|
||||
@@ -3186,14 +3186,14 @@ describe('Proxy text producers', function () {
|
||||
it('round-trips Surge max-streams for HTTP/2 CONNECT and TrustTunnel', function () {
|
||||
const proxies = ProxyUtils.parse(
|
||||
[
|
||||
'Surge H2 Round Trip = h2-connect,h2.example.com,443,headers=X-Padding:<random-string(16-32)>,max-streams=1,sni=sni.example.com',
|
||||
"Surge H2 Round Trip = h2-connect,h2.example.com,443,headers=\"X-Padding:<random-string(16-32)>;X-Client:'Surge;Legacy'\",max-streams=1,sni=sni.example.com",
|
||||
'Surge Trust Round Trip = trust-tunnel,trust.example.com,443,username=user,password=pass,headers=X-Client:Surge,max-streams="3",sni=sni.example.com',
|
||||
].join('\n'),
|
||||
);
|
||||
const output = ProxyUtils.produce(proxies, 'Surge', 'external');
|
||||
|
||||
expect(output.split('\n')).to.deep.equal([
|
||||
`Surge H2 Round Trip=h2-connect,h2.example.com,443,headers="X-Padding:"<random-string(16-32)>"",max-streams=1,sni="sni.example.com",udp-relay=true`,
|
||||
`Surge H2 Round Trip=h2-connect,h2.example.com,443,headers="X-Padding:"<random-string(16-32)>";X-Client:"Surge;Legacy"",max-streams=1,sni="sni.example.com"`,
|
||||
`Surge Trust Round Trip=trust-tunnel,trust.example.com,443,username="user",password="pass",headers="X-Client:"Surge"",max-streams=3,sni="sni.example.com"`,
|
||||
]);
|
||||
});
|
||||
@@ -3724,6 +3724,134 @@ describe('Proxy text producers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('round-trips Surfboard HTTP/2 CONNECT options', function () {
|
||||
const prefix = 'Surfboard H2=h2-connect,h2.example.com,443';
|
||||
const headers = String.raw`headers="X-Padding:<random-string(16-32)>;X-Client:O'Reilly,\"agent\"\\path"`;
|
||||
const fingerprints = ['a'.repeat(64), 'b'.repeat(64)].join(',');
|
||||
const params = [
|
||||
'max-streams=4',
|
||||
`server-cert-fingerprint-sha256="${fingerprints}"`,
|
||||
'sni="off"',
|
||||
'skip-cert-verify=false',
|
||||
'udp-relay=true',
|
||||
'block-quic=on',
|
||||
'underlying-proxy="Entry Group"',
|
||||
];
|
||||
const [proxy] = ProxyUtils.parse(
|
||||
[
|
||||
prefix,
|
||||
'"legacy,user"',
|
||||
'legacy-password',
|
||||
headers,
|
||||
'password="pass,word"',
|
||||
'username="proxy,user"',
|
||||
...params,
|
||||
].join(','),
|
||||
);
|
||||
for (const target of ['Surfboard', 'surfboard']) {
|
||||
const output = produceExternal(target, proxy);
|
||||
expect(output).to.equal(
|
||||
[
|
||||
prefix,
|
||||
'username="proxy,user"',
|
||||
'password="pass,word"',
|
||||
headers,
|
||||
...params,
|
||||
].join(','),
|
||||
);
|
||||
const [reparsed] = ProxyUtils.parse(output);
|
||||
expectSubset(reparsed, {
|
||||
type: 'h2-connect',
|
||||
username: 'proxy,user',
|
||||
password: 'pass,word',
|
||||
headers: {
|
||||
'X-Padding': '<random-string(16-32)>',
|
||||
'X-Client': String.raw`O'Reilly,"agent"\path`,
|
||||
},
|
||||
'max-streams': 4,
|
||||
'tls-fingerprint': fingerprints,
|
||||
'disable-sni': true,
|
||||
'skip-cert-verify': false,
|
||||
udp: true,
|
||||
'block-quic': 'on',
|
||||
'underlying-proxy': 'Entry Group',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps omitted and disabled UDP off for Surfboard HTTP/2 CONNECT', function () {
|
||||
const plain = 'Plain=h2-connect,h2.example.com,443';
|
||||
const disabled = 'No UDP=h2-connect,h2.example.com,443,udp-relay="false"';
|
||||
const proxies = ProxyUtils.parse(`${plain}\n${disabled}`);
|
||||
expect(produceInternal('Surfboard', proxies)).to.deep.equal([
|
||||
`${plain},sni="h2.example.com"`,
|
||||
'No UDP=h2-connect,h2.example.com,443,sni="h2.example.com",udp-relay=false',
|
||||
]);
|
||||
});
|
||||
|
||||
it('validates Surfboard HTTP/2 CONNECT header names as HTTP tokens', function () {
|
||||
const proxy = {
|
||||
type: 'h2-connect',
|
||||
name: 'Surfboard H2 Headers',
|
||||
server: 'h2.example.com',
|
||||
port: 443,
|
||||
};
|
||||
const validName = "X!#$%&'*+-.^_`|~09";
|
||||
const output = produceExternal('Surfboard', {
|
||||
...proxy,
|
||||
headers: { [validName]: 'value' },
|
||||
});
|
||||
expect(output).to.include(`,headers="${validName}:value"`);
|
||||
const [reparsed] = ProxyUtils.parse(output);
|
||||
expect(reparsed.headers).to.deep.equal({ [validName]: 'value' });
|
||||
|
||||
const invalidNames = ['X@Client', 'X/Client', 'X Client', 'Xé', ''];
|
||||
const { result, errors } = captureErrors(() =>
|
||||
produceInternal(
|
||||
'Surfboard',
|
||||
invalidNames.map((name) => ({
|
||||
...proxy,
|
||||
headers: { [name]: 'value' },
|
||||
})),
|
||||
),
|
||||
);
|
||||
expect(result).to.deep.equal([]);
|
||||
expect(errors).to.have.length(invalidNames.length);
|
||||
});
|
||||
|
||||
it('rejects forbidden controls in Surfboard HTTP/2 CONNECT header values', function () {
|
||||
const proxy = {
|
||||
type: 'h2-connect',
|
||||
name: 'Surfboard H2 Header Values',
|
||||
server: 'h2.example.com',
|
||||
port: 443,
|
||||
};
|
||||
const headers = { 'X-Test': 'a\tb' };
|
||||
const output = produceExternal('Surfboard', { ...proxy, headers });
|
||||
const [reparsed] = ProxyUtils.parse(output);
|
||||
expect(reparsed.headers).to.deep.equal(headers);
|
||||
|
||||
const invalidValues = [
|
||||
'a\0b',
|
||||
'a\x1fb',
|
||||
'a\x7fb',
|
||||
'a\rb',
|
||||
'a\nb',
|
||||
'a;b',
|
||||
];
|
||||
const { result, errors } = captureErrors(() =>
|
||||
produceInternal(
|
||||
'Surfboard',
|
||||
invalidValues.map((value) => ({
|
||||
...proxy,
|
||||
headers: { 'X-Test': value },
|
||||
})),
|
||||
),
|
||||
);
|
||||
expect(result).to.deep.equal([]);
|
||||
expect(errors).to.have.length(invalidValues.length);
|
||||
});
|
||||
|
||||
it('produces Surfboard Hysteria2 lines', function () {
|
||||
const output = produceExternal('Surfboard', {
|
||||
type: 'hysteria2',
|
||||
@@ -3803,20 +3931,53 @@ describe('Proxy text producers', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('produces Surfboard Hysteria2 salamander obfs lines', function () {
|
||||
const output = produceExternal('Surfboard', {
|
||||
type: 'hysteria2',
|
||||
name: 'Surfboard Hysteria2 Salamander',
|
||||
server: 'hy2.example.com',
|
||||
port: 443,
|
||||
password: 'secret',
|
||||
obfs: 'salamander',
|
||||
'obfs-password': 'mask',
|
||||
});
|
||||
it('round-trips Surfboard and Surge Hysteria2 obfs passwords', function () {
|
||||
const obfsPassword = String.raw`part1,part2"part3\part4`;
|
||||
for (const obfs of ['salamander', 'gecko']) {
|
||||
const proxy = {
|
||||
type: 'hysteria2',
|
||||
name: 'Hysteria2 Obfs',
|
||||
server: 'hy2.example.com',
|
||||
port: 443,
|
||||
password: 'secret',
|
||||
obfs,
|
||||
'obfs-password': obfsPassword,
|
||||
sni: 'peer.example.com',
|
||||
};
|
||||
for (const target of ['Surfboard', 'Surge']) {
|
||||
const output = produceExternal(target, proxy);
|
||||
expect(output).to.equal(
|
||||
String.raw`Hysteria2 Obfs=hysteria2,hy2.example.com,443,password="secret",${obfs}-password="part1,part2\"part3\\part4",sni="peer.example.com"`,
|
||||
);
|
||||
const [reparsed] = ProxyUtils.parse(output);
|
||||
expectSubset(reparsed, {
|
||||
obfs,
|
||||
'obfs-password': obfsPassword,
|
||||
sni: 'peer.example.com',
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
expect(output).to.equal(
|
||||
'Surfboard Hysteria2 Salamander=hysteria2,hy2.example.com,443,password="secret",salamander-password="mask"',
|
||||
);
|
||||
it('prefers Gecko in Surfboard Hysteria2 regardless of password order', function () {
|
||||
const prefix =
|
||||
'Hysteria2=hysteria2,hy2.example.com,443,password=secret';
|
||||
const salamander = 'salamander-password=salamander-mask';
|
||||
const gecko = 'gecko-password="gecko,mask"';
|
||||
for (const fields of [
|
||||
[gecko, salamander],
|
||||
[salamander, gecko],
|
||||
]) {
|
||||
const [proxy] = ProxyUtils.parse([prefix, ...fields].join(','));
|
||||
expectSubset(proxy, {
|
||||
obfs: 'gecko',
|
||||
'obfs-password': 'gecko,mask',
|
||||
});
|
||||
const output = produceExternal('Surfboard', proxy);
|
||||
expect(output)
|
||||
.to.include(`,${gecko}`)
|
||||
.and.not.include(',salamander-password=');
|
||||
}
|
||||
});
|
||||
|
||||
it('omits Surfboard Hysteria2 lines when unsupported obfs is present', function () {
|
||||
@@ -3824,11 +3985,11 @@ describe('Proxy text producers', function () {
|
||||
[
|
||||
{
|
||||
type: 'hysteria2',
|
||||
name: 'Surfboard Hysteria2 Gecko',
|
||||
name: 'Surfboard Hysteria2 Unknown Obfs',
|
||||
server: 'hy2.example.com',
|
||||
port: 443,
|
||||
password: 'secret',
|
||||
obfs: 'gecko',
|
||||
obfs: 'unknown',
|
||||
'obfs-password': 'mask',
|
||||
},
|
||||
],
|
||||
@@ -3839,6 +4000,52 @@ describe('Proxy text producers', function () {
|
||||
expect(output).to.equal('');
|
||||
});
|
||||
|
||||
it('outputs the documented Surfboard VMess encrypt methods', function () {
|
||||
for (const [cipher, parameter] of [
|
||||
['aes-128-gcm', ',encrypt-method=aes-128-gcm'],
|
||||
['chacha20-poly1305', ',encrypt-method=chacha20-ietf-poly1305'],
|
||||
['auto', ''],
|
||||
[undefined, ''],
|
||||
]) {
|
||||
const output = produceExternal('Surfboard', {
|
||||
type: 'vmess',
|
||||
name: 'Surfboard VMess',
|
||||
server: 'vmess.example.com',
|
||||
port: 443,
|
||||
uuid: UUID,
|
||||
alterId: 0,
|
||||
cipher,
|
||||
});
|
||||
expect(output).to.equal(
|
||||
`Surfboard VMess=vmess,vmess.example.com,443,username=${UUID}${parameter},vmess-aead=true`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('filters Surfboard VMess nodes with unsupported ciphers', function () {
|
||||
const proxies = ProxyUtils.parse(
|
||||
['none', 'zero']
|
||||
.map((cipher) =>
|
||||
JSON.stringify({
|
||||
type: 'vmess',
|
||||
name: `VMess ${cipher}`,
|
||||
server: 'vmess.example.com',
|
||||
port: 443,
|
||||
uuid: UUID,
|
||||
cipher,
|
||||
}),
|
||||
)
|
||||
.join('\n'),
|
||||
);
|
||||
const { result, errors } = captureErrors(() =>
|
||||
produceInternal('Surfboard', proxies),
|
||||
);
|
||||
expect(result).to.deep.equal([]);
|
||||
expect(errors).to.have.length(2);
|
||||
expect(errors[0]).to.include('VMess cipher none');
|
||||
expect(errors[1]).to.include('VMess cipher zero');
|
||||
});
|
||||
|
||||
it('produces Surfboard TLS server certificate fingerprints', function () {
|
||||
const fingerprint = 'SHA256:FINGERPRINT';
|
||||
const cases = [
|
||||
|
||||
Reference in new issue
Block a user