sub-store-convert 2.33.1 → 2.36.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +768 -605
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -425,7 +425,7 @@ shadowsocks = tag equals "ss" address (method/passwordk/obfs/obfs_host/obfs_uri/
|
|
|
425
425
|
}
|
|
426
426
|
handleShadowTLS();
|
|
427
427
|
}
|
|
428
|
-
vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/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/alpn/tls_fingerprint/tls_verification/client_cert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
|
428
|
+
vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/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)* {
|
|
429
429
|
proxy.type = "vmess";
|
|
430
430
|
proxy.cipher = proxy.cipher || "auto";
|
|
431
431
|
// Surfboard 与 Surge 默认不一致, 不管 Surfboard https://getsurfboard.com/docs/profile-format/proxy/external-proxy/vmess
|
|
@@ -437,17 +437,17 @@ vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/ws_path/ws_headers/
|
|
|
437
437
|
handleWebsocket();
|
|
438
438
|
handleShadowTLS();
|
|
439
439
|
}
|
|
440
|
-
trojan = tag equals "trojan" address (passwordk/ws/ws_path/ws_headers/tls/sni/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)* {
|
|
440
|
+
trojan = tag equals "trojan" address (passwordk/ws/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)* {
|
|
441
441
|
proxy.type = "trojan";
|
|
442
442
|
handleWebsocket();
|
|
443
443
|
handleShadowTLS();
|
|
444
444
|
}
|
|
445
|
-
https = tag equals "https" address (username password)? (usernamek passwordk)? (headers/sni/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)* {
|
|
445
|
+
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)* {
|
|
446
446
|
proxy.type = "http";
|
|
447
447
|
proxy.tls = true;
|
|
448
448
|
handleShadowTLS();
|
|
449
449
|
}
|
|
450
|
-
h2_connect = tag equals "h2-connect" address (username password)? (usernamek passwordk)? (headers/max_streams/sni/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)* {
|
|
450
|
+
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)* {
|
|
451
451
|
proxy.type = "h2-connect";
|
|
452
452
|
proxy.tls = true;
|
|
453
453
|
handleShadowTLS();
|
|
@@ -470,11 +470,11 @@ snell = tag equals "snell" address (snell_version/snell_mode/snell_psk/obfs/obfs
|
|
|
470
470
|
}
|
|
471
471
|
handleShadowTLS();
|
|
472
472
|
}
|
|
473
|
-
tuic = tag equals "tuic" address (alpn/token/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/fast_open/tfo/ecn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/port_hopping_interval/others)* {
|
|
473
|
+
tuic = tag equals "tuic" address (alpn/token/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/fast_open/tfo/ecn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/port_hopping_interval/others)* {
|
|
474
474
|
proxy.type = "tuic";
|
|
475
475
|
handleShadowTLS();
|
|
476
476
|
}
|
|
477
|
-
tuic_v5 = tag equals "tuic-v5" address (alpn/passwordk/uuidk/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/fast_open/tfo/ecn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/port_hopping_interval/others)* {
|
|
477
|
+
tuic_v5 = tag equals "tuic-v5" address (alpn/passwordk/uuidk/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/fast_open/tfo/ecn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/port_hopping_interval/others)* {
|
|
478
478
|
proxy.type = "tuic";
|
|
479
479
|
proxy.version = 5;
|
|
480
480
|
handleShadowTLS();
|
|
@@ -483,7 +483,7 @@ wireguard = tag equals "wireguard" (section_name/no_error_alert/ip_version/under
|
|
|
483
483
|
proxy.type = "wireguard-surge";
|
|
484
484
|
handleShadowTLS();
|
|
485
485
|
}
|
|
486
|
-
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/alpn/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)* {
|
|
486
|
+
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/cert_verify_name/alpn/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)* {
|
|
487
487
|
proxy.type = "hysteria2";
|
|
488
488
|
handleShadowTLS();
|
|
489
489
|
}
|
|
@@ -491,16 +491,16 @@ socks5 = tag equals "socks5" address (username password)? (usernamek passwordk)?
|
|
|
491
491
|
proxy.type = "socks5";
|
|
492
492
|
handleShadowTLS();
|
|
493
493
|
}
|
|
494
|
-
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/alpn/tls_fingerprint/tls_verification/client_cert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
|
|
494
|
+
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)* {
|
|
495
495
|
proxy.type = "socks5";
|
|
496
496
|
proxy.tls = true;
|
|
497
497
|
handleShadowTLS();
|
|
498
498
|
}
|
|
499
|
-
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/alpn/fast_open/tfo/block_quic/others)* {
|
|
499
|
+
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)* {
|
|
500
500
|
proxy.type = "anytls";
|
|
501
501
|
proxy.tls = true;
|
|
502
502
|
}
|
|
503
|
-
trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/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/alpn/fast_open/tfo/block_quic/others)* {
|
|
503
|
+
trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/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/fast_open/tfo/block_quic/others)* {
|
|
504
504
|
proxy.type = "trusttunnel";
|
|
505
505
|
proxy.tls = true;
|
|
506
506
|
}
|
|
@@ -577,6 +577,7 @@ sni = comma "sni" equals match:[^,]+ {
|
|
|
577
577
|
proxy.sni = sni;
|
|
578
578
|
}
|
|
579
579
|
}
|
|
580
|
+
cert_verify_name = comma "server-cert-verify-name" equals match:[^,]+ { proxy["name-cert-verify"] = stripQuotes(match.join("")); }
|
|
580
581
|
tls_verification = comma "skip-cert-verify" equals flag:bool { proxy["skip-cert-verify"] = flag; }
|
|
581
582
|
tls_fingerprint = comma "server-cert-fingerprint-sha256" equals tls_fingerprint:$[^,]+ { proxy["tls-fingerprint"] = tls_fingerprint.trim(); }
|
|
582
583
|
client_cert = comma "client-cert" equals match:[^,]+ { proxy["keystore-client-cert"] = stripQuotes(match.join("")); }
|
|
@@ -1222,279 +1223,325 @@ function getParser3() {
|
|
|
1222
1223
|
return parser3;
|
|
1223
1224
|
}
|
|
1224
1225
|
|
|
1225
|
-
// src/vendors/Sub-Store/backend/src/core/proxy-utils/
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
{
|
|
1230
|
-
|
|
1231
|
-
if (Object(obj) !== obj) return obj;
|
|
1232
|
-
if (!Array.isArray(path)) path = path.toString().match(/[^.[\]]+/g) || [];
|
|
1233
|
-
path
|
|
1234
|
-
.slice(0, -1)
|
|
1235
|
-
.reduce((a, c, i) => (Object(a[c]) === a[c] ? a[c] : (a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {})), obj)[
|
|
1236
|
-
path[path.length - 1]
|
|
1237
|
-
] = value;
|
|
1238
|
-
return obj;
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
function toBool(str) {
|
|
1242
|
-
if (typeof str === 'undefined' || str === null) return undefined;
|
|
1243
|
-
return /(TRUE)|1/i.test(str);
|
|
1226
|
+
// src/vendors/Sub-Store/backend/src/core/proxy-utils/transport-path.js
|
|
1227
|
+
function decodeQueryComponent(value) {
|
|
1228
|
+
try {
|
|
1229
|
+
return decodeURIComponent(`${value}`.replace(/\+/g, "%20"));
|
|
1230
|
+
} catch (e) {
|
|
1231
|
+
return value;
|
|
1244
1232
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1233
|
+
}
|
|
1234
|
+
function splitQueryPart(part) {
|
|
1235
|
+
const separatorIndex = part.indexOf("=");
|
|
1236
|
+
if (separatorIndex === -1) {
|
|
1237
|
+
return {
|
|
1238
|
+
key: decodeQueryComponent(part),
|
|
1239
|
+
value: ""
|
|
1240
|
+
};
|
|
1252
1241
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1242
|
+
return {
|
|
1243
|
+
key: decodeQueryComponent(part.slice(0, separatorIndex)),
|
|
1244
|
+
value: decodeQueryComponent(part.slice(separatorIndex + 1))
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
function parseSafeIntegerValue(value) {
|
|
1248
|
+
if (!/^\d+$/.test(`${value}`))
|
|
1249
|
+
return null;
|
|
1250
|
+
const parsed = parseInt(`${value}`, 10);
|
|
1251
|
+
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
1252
|
+
}
|
|
1253
|
+
function extractPathQueryParam(rawPath, paramName) {
|
|
1254
|
+
const path = rawPath == null ? "" : `${rawPath}`;
|
|
1255
|
+
const queryIndex = path.indexOf("?");
|
|
1256
|
+
if (queryIndex === -1) {
|
|
1263
1257
|
return {
|
|
1264
|
-
|
|
1265
|
-
value:
|
|
1258
|
+
path,
|
|
1259
|
+
value: ""
|
|
1266
1260
|
};
|
|
1267
1261
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
return parsed.value;
|
|
1262
|
+
const basePath = path.slice(0, queryIndex);
|
|
1263
|
+
const query = path.slice(queryIndex + 1);
|
|
1264
|
+
const keptParts = [];
|
|
1265
|
+
let value = "";
|
|
1266
|
+
for (const part of query.split("&")) {
|
|
1267
|
+
if (part === "")
|
|
1268
|
+
continue;
|
|
1269
|
+
const parsed = splitQueryPart(part);
|
|
1270
|
+
if (parsed.key === paramName) {
|
|
1271
|
+
if (value === "" && parsed.value !== "") {
|
|
1272
|
+
value = parsed.value;
|
|
1280
1273
|
}
|
|
1274
|
+
continue;
|
|
1281
1275
|
}
|
|
1282
|
-
|
|
1283
|
-
return '';
|
|
1276
|
+
keptParts.push(part);
|
|
1284
1277
|
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
const parsed = splitQueryPart(part);
|
|
1304
|
-
if (parsed.key === paramName) {
|
|
1305
|
-
if (value === '' && parsed.value !== '') {
|
|
1306
|
-
value = parsed.value;
|
|
1307
|
-
}
|
|
1308
|
-
continue;
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
keptParts.push(part);
|
|
1278
|
+
return {
|
|
1279
|
+
path: keptParts.length > 0 ? `${basePath}?${keptParts.join("&")}` : basePath,
|
|
1280
|
+
value
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
function getPathQueryParam(rawPath, paramName) {
|
|
1284
|
+
const path = rawPath == null ? "" : `${rawPath}`;
|
|
1285
|
+
const queryIndex = path.indexOf("?");
|
|
1286
|
+
if (queryIndex === -1)
|
|
1287
|
+
return "";
|
|
1288
|
+
const query = path.slice(queryIndex + 1);
|
|
1289
|
+
for (const part of query.split("&")) {
|
|
1290
|
+
if (part === "")
|
|
1291
|
+
continue;
|
|
1292
|
+
const parsed = splitQueryPart(part);
|
|
1293
|
+
if (parsed.key === paramName && parsed.value !== "") {
|
|
1294
|
+
return parsed.value;
|
|
1312
1295
|
}
|
|
1313
|
-
|
|
1296
|
+
}
|
|
1297
|
+
return "";
|
|
1298
|
+
}
|
|
1299
|
+
function getSafeIntegerPathQueryParam(rawPath, paramName) {
|
|
1300
|
+
const value = getPathQueryParam(rawPath, paramName);
|
|
1301
|
+
const parsed = parseSafeIntegerValue(value);
|
|
1302
|
+
if (parsed == null) {
|
|
1314
1303
|
return {
|
|
1315
|
-
|
|
1316
|
-
|
|
1304
|
+
value: "",
|
|
1305
|
+
parsed: null
|
|
1317
1306
|
};
|
|
1318
1307
|
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1308
|
+
return {
|
|
1309
|
+
value,
|
|
1310
|
+
parsed
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
function appendPathQueryParam(path, paramName, value) {
|
|
1314
|
+
const separator = path.includes("?") ? path.endsWith("?") || path.endsWith("&") ? "" : "&" : "?";
|
|
1315
|
+
return `${path}${separator}${encodeURIComponent(
|
|
1316
|
+
paramName
|
|
1317
|
+
)}=${encodeURIComponent(`${value}`)}`;
|
|
1318
|
+
}
|
|
1319
|
+
function setPathQueryParam(rawPath, paramName, value) {
|
|
1320
|
+
const path = rawPath == null || rawPath === "" ? "/" : `${rawPath}`;
|
|
1321
|
+
const { path: pathWithoutParam } = extractPathQueryParam(path, paramName);
|
|
1322
|
+
return appendPathQueryParam(pathWithoutParam, paramName, value);
|
|
1323
|
+
}
|
|
1324
|
+
function normalizeWebSocketEarlyDataPath(wsOpts) {
|
|
1325
|
+
const networkPath = wsOpts?.path;
|
|
1326
|
+
if (!wsOpts)
|
|
1327
|
+
return;
|
|
1328
|
+
const { value: ed, parsed: maxEarlyData } = getSafeIntegerPathQueryParam(
|
|
1329
|
+
networkPath,
|
|
1330
|
+
"ed"
|
|
1331
|
+
);
|
|
1332
|
+
if (wsOpts["v2ray-http-upgrade"]) {
|
|
1333
|
+
if (ed !== "") {
|
|
1334
|
+
wsOpts.path = extractPathQueryParam(networkPath, "ed").path;
|
|
1335
|
+
wsOpts["v2ray-http-upgrade-fast-open"] = true;
|
|
1336
|
+
if (wsOpts["_v2ray-http-upgrade-ed"] == null || `${wsOpts["_v2ray-http-upgrade-ed"]}` === "") {
|
|
1337
|
+
wsOpts["_v2ray-http-upgrade-ed"] = ed;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
delete wsOpts["early-data-header-name"];
|
|
1341
|
+
delete wsOpts["max-early-data"];
|
|
1342
|
+
return;
|
|
1325
1343
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1344
|
+
if (ed === "")
|
|
1345
|
+
return;
|
|
1346
|
+
wsOpts.path = extractPathQueryParam(networkPath, "ed").path;
|
|
1347
|
+
if (wsOpts["early-data-header-name"] == null) {
|
|
1348
|
+
wsOpts["early-data-header-name"] = "Sec-WebSocket-Protocol";
|
|
1349
|
+
}
|
|
1350
|
+
if (wsOpts["max-early-data"] == null) {
|
|
1351
|
+
wsOpts["max-early-data"] = maxEarlyData;
|
|
1329
1352
|
}
|
|
1330
|
-
}}
|
|
1331
|
-
|
|
1332
|
-
{
|
|
1333
|
-
const proxy = {};
|
|
1334
|
-
const obfs = {};
|
|
1335
|
-
const $ = {};
|
|
1336
|
-
const params = {};
|
|
1337
1353
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1354
|
+
function deleteHttpUpgradeEarlyDataMetadata(wsOpts) {
|
|
1355
|
+
if (!wsOpts)
|
|
1356
|
+
return;
|
|
1357
|
+
delete wsOpts["_v2ray-http-upgrade-ed"];
|
|
1341
1358
|
}
|
|
1342
1359
|
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
if (
|
|
1352
|
-
|
|
1353
|
-
}
|
|
1354
|
-
};
|
|
1355
|
-
|
|
1356
|
-
password = match:$[^@]+ {
|
|
1357
|
-
return decodeURIComponent(match);
|
|
1358
|
-
};
|
|
1359
|
-
|
|
1360
|
-
server = ip/domain;
|
|
1361
|
-
|
|
1362
|
-
domain = match:[0-9a-zA-z-_.]+ {
|
|
1363
|
-
const domain = match.join("");
|
|
1364
|
-
if (/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]/.test(domain)) {
|
|
1365
|
-
return domain;
|
|
1360
|
+
// src/vendors/Sub-Store/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js
|
|
1361
|
+
var unsafePathSegments = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
1362
|
+
var parser4;
|
|
1363
|
+
function $set(obj, path, value) {
|
|
1364
|
+
if (Object(obj) !== obj)
|
|
1365
|
+
return obj;
|
|
1366
|
+
if (!Array.isArray(path))
|
|
1367
|
+
path = path.toString().match(/[^.[\]]+/g) || [];
|
|
1368
|
+
if (path.some((segment) => unsafePathSegments.has(segment))) {
|
|
1369
|
+
throw new Error("Unsafe property path");
|
|
1366
1370
|
}
|
|
1371
|
+
path.slice(0, -1).reduce((a, c, i) => Object.prototype.hasOwnProperty.call(a, c) && Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
|
|
1372
|
+
return obj;
|
|
1367
1373
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
} { return $.ip; }
|
|
1382
|
-
|
|
1383
|
-
port = digits:[0-9]+ {
|
|
1384
|
-
const port = parseInt(digits.join(""), 10);
|
|
1385
|
-
if (port >= 0 && port <= 65535) {
|
|
1386
|
-
return port;
|
|
1387
|
-
} else {
|
|
1388
|
-
throw new Error("Invalid port: " + port);
|
|
1374
|
+
function toBool(str) {
|
|
1375
|
+
if (str == null)
|
|
1376
|
+
return void 0;
|
|
1377
|
+
return /(TRUE)|1/i.test(str);
|
|
1378
|
+
}
|
|
1379
|
+
function isNumericEarlyData(value) {
|
|
1380
|
+
return parseSafeIntegerValue(value) != null;
|
|
1381
|
+
}
|
|
1382
|
+
function decode(value) {
|
|
1383
|
+
try {
|
|
1384
|
+
return decodeURIComponent(value);
|
|
1385
|
+
} catch {
|
|
1386
|
+
return value;
|
|
1389
1387
|
}
|
|
1390
1388
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1389
|
+
function parseTrojan(url) {
|
|
1390
|
+
const proxy = {};
|
|
1391
|
+
const match = url.match(
|
|
1392
|
+
/^trojan:\/\/([^@]+)@(\[[^\]]+\]|[^/?#]+):(\d+)(?:\/)?(?:\?([^#]*))?(?:#(.*))?$/
|
|
1393
|
+
);
|
|
1394
|
+
if (!match) {
|
|
1395
|
+
throw new Error("Invalid trojan url");
|
|
1396
|
+
}
|
|
1397
|
+
const [
|
|
1398
|
+
,
|
|
1399
|
+
password,
|
|
1400
|
+
server,
|
|
1401
|
+
port,
|
|
1402
|
+
query,
|
|
1403
|
+
name
|
|
1404
|
+
] = match;
|
|
1405
|
+
const normalizedServer = server.replace(/^\[|\]$/g, "");
|
|
1406
|
+
if ((server.startsWith("[") || server.includes(":")) && !isIPv6(normalizedServer)) {
|
|
1407
|
+
throw new Error(`Invalid server: ${server}`);
|
|
1395
1408
|
}
|
|
1396
|
-
proxy
|
|
1397
|
-
proxy.
|
|
1398
|
-
proxy
|
|
1399
|
-
proxy
|
|
1400
|
-
proxy.
|
|
1401
|
-
|
|
1402
|
-
|
|
1409
|
+
proxy.type = "trojan";
|
|
1410
|
+
proxy.password = decode(password);
|
|
1411
|
+
proxy.server = server;
|
|
1412
|
+
proxy.port = Number(port);
|
|
1413
|
+
if (!Number.isSafeInteger(proxy.port) || proxy.port < 1 || proxy.port > 65535) {
|
|
1414
|
+
throw new Error(`Invalid port: ${port}`);
|
|
1415
|
+
}
|
|
1416
|
+
proxy.name = name ? decode(name) : `${server}:${port}`;
|
|
1417
|
+
const params = {};
|
|
1418
|
+
if (query) {
|
|
1419
|
+
for (const item of query.split("&")) {
|
|
1420
|
+
const separatorIndex = item.indexOf("=");
|
|
1421
|
+
const key = separatorIndex === -1 ? item : item.slice(0, separatorIndex);
|
|
1422
|
+
params[key] = separatorIndex === -1 ? true : decode(item.slice(separatorIndex + 1));
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
proxy["skip-cert-verify"] = toBool(params.allowInsecure);
|
|
1426
|
+
proxy.sni = params.sni || params.peer;
|
|
1427
|
+
proxy["client-fingerprint"] = params.fp;
|
|
1428
|
+
proxy["tls-fingerprint"] = params.pcs;
|
|
1429
|
+
proxy._vcn = params.vcn?.split(",").map((name2) => name2.trim()).filter(Boolean);
|
|
1430
|
+
proxy["name-cert-verify"] = proxy._vcn?.[0];
|
|
1431
|
+
if (params.alpn) {
|
|
1432
|
+
proxy.alpn = params.alpn.split(",");
|
|
1433
|
+
}
|
|
1434
|
+
if (toBool(params.ws)) {
|
|
1403
1435
|
proxy.network = "ws";
|
|
1404
|
-
$set(
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1436
|
+
$set(
|
|
1437
|
+
proxy,
|
|
1438
|
+
"ws-opts.path",
|
|
1439
|
+
params.wspath
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
if (params.type) {
|
|
1443
|
+
let httpupgrade = false;
|
|
1444
|
+
let httpUpgradeEd = "";
|
|
1445
|
+
let pathEarlyData = "";
|
|
1446
|
+
proxy.network = params.type;
|
|
1447
|
+
if (proxy.network === "httpupgrade") {
|
|
1448
|
+
proxy.network = "ws";
|
|
1449
|
+
httpupgrade = true;
|
|
1450
|
+
}
|
|
1451
|
+
if (proxy.network === "grpc") {
|
|
1452
|
+
proxy["grpc-opts"] = {
|
|
1453
|
+
"grpc-service-name": params.serviceName,
|
|
1454
|
+
"_grpc-type": params.mode,
|
|
1455
|
+
"_grpc-authority": params.authority
|
|
1456
|
+
};
|
|
1422
1457
|
} else {
|
|
1423
|
-
if (params
|
|
1424
|
-
let
|
|
1425
|
-
if (proxy.network ===
|
|
1426
|
-
const
|
|
1427
|
-
if (isNumericEarlyData(
|
|
1428
|
-
|
|
1429
|
-
if (httpupgrade)
|
|
1430
|
-
httpUpgradeEd =
|
|
1431
|
-
|
|
1432
|
-
pathEarlyData =
|
|
1433
|
-
}
|
|
1458
|
+
if (params.path) {
|
|
1459
|
+
let path = params.path;
|
|
1460
|
+
if (proxy.network === "ws") {
|
|
1461
|
+
const ed = getPathQueryParam(path, "ed");
|
|
1462
|
+
if (isNumericEarlyData(ed)) {
|
|
1463
|
+
path = extractPathQueryParam(path, "ed").path;
|
|
1464
|
+
if (httpupgrade)
|
|
1465
|
+
httpUpgradeEd = ed;
|
|
1466
|
+
else
|
|
1467
|
+
pathEarlyData = ed;
|
|
1434
1468
|
}
|
|
1435
1469
|
}
|
|
1436
|
-
$set(
|
|
1470
|
+
$set(
|
|
1471
|
+
proxy,
|
|
1472
|
+
`${proxy.network}-opts.path`,
|
|
1473
|
+
path
|
|
1474
|
+
);
|
|
1437
1475
|
}
|
|
1438
|
-
if (params
|
|
1439
|
-
$set(
|
|
1476
|
+
if (params.host) {
|
|
1477
|
+
$set(
|
|
1478
|
+
proxy,
|
|
1479
|
+
`${proxy.network}-opts.headers.Host`,
|
|
1480
|
+
params.host
|
|
1481
|
+
);
|
|
1440
1482
|
}
|
|
1441
1483
|
if (httpupgrade) {
|
|
1442
|
-
httpUpgradeEd = httpUpgradeEd || (isNumericEarlyData(params.ed) ? String(params.ed) :
|
|
1443
|
-
$set(
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1484
|
+
httpUpgradeEd = httpUpgradeEd || (isNumericEarlyData(params.ed) ? String(params.ed) : "");
|
|
1485
|
+
$set(
|
|
1486
|
+
proxy,
|
|
1487
|
+
"ws-opts.v2ray-http-upgrade",
|
|
1488
|
+
true
|
|
1489
|
+
);
|
|
1490
|
+
if (httpUpgradeEd) {
|
|
1491
|
+
$set(
|
|
1492
|
+
proxy,
|
|
1493
|
+
"ws-opts.v2ray-http-upgrade-fast-open",
|
|
1494
|
+
true
|
|
1495
|
+
);
|
|
1496
|
+
$set(
|
|
1497
|
+
proxy,
|
|
1498
|
+
"ws-opts._v2ray-http-upgrade-ed",
|
|
1499
|
+
httpUpgradeEd
|
|
1500
|
+
);
|
|
1447
1501
|
}
|
|
1448
|
-
} else if (proxy.network ===
|
|
1449
|
-
$set(
|
|
1450
|
-
|
|
1502
|
+
} else if (proxy.network === "ws" && pathEarlyData) {
|
|
1503
|
+
$set(
|
|
1504
|
+
proxy,
|
|
1505
|
+
"ws-opts.max-early-data",
|
|
1506
|
+
parseSafeIntegerValue(pathEarlyData)
|
|
1507
|
+
);
|
|
1508
|
+
$set(
|
|
1509
|
+
proxy,
|
|
1510
|
+
"ws-opts.early-data-header-name",
|
|
1511
|
+
"Sec-WebSocket-Protocol"
|
|
1512
|
+
);
|
|
1451
1513
|
}
|
|
1452
1514
|
}
|
|
1453
|
-
if (
|
|
1515
|
+
if (params.security === "reality") {
|
|
1454
1516
|
const opts = {};
|
|
1455
|
-
if (params.pbk)
|
|
1456
|
-
opts[
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
if (params.
|
|
1462
|
-
opts['_spider-x'] = params.spx;
|
|
1463
|
-
}
|
|
1464
|
-
if (params.mode) {
|
|
1517
|
+
if (params.pbk)
|
|
1518
|
+
opts["public-key"] = params.pbk;
|
|
1519
|
+
if (params.sid)
|
|
1520
|
+
opts["short-id"] = params.sid;
|
|
1521
|
+
if (params.spx)
|
|
1522
|
+
opts["_spider-x"] = params.spx;
|
|
1523
|
+
if (params.mode)
|
|
1465
1524
|
proxy._mode = params.mode;
|
|
1466
|
-
|
|
1467
|
-
if (params.extra) {
|
|
1525
|
+
if (params.extra)
|
|
1468
1526
|
proxy._extra = params.extra;
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1527
|
+
if (Object.keys(opts).length) {
|
|
1528
|
+
$set(
|
|
1529
|
+
proxy,
|
|
1530
|
+
"reality-opts",
|
|
1531
|
+
opts
|
|
1532
|
+
);
|
|
1472
1533
|
}
|
|
1473
1534
|
}
|
|
1474
1535
|
}
|
|
1475
|
-
|
|
1476
|
-
proxy.
|
|
1477
|
-
proxy
|
|
1536
|
+
proxy.udp = toBool(params.udp);
|
|
1537
|
+
proxy.tfo = toBool(params.tfo);
|
|
1538
|
+
return proxy;
|
|
1478
1539
|
}
|
|
1479
|
-
|
|
1480
|
-
param = kv/single;
|
|
1481
|
-
|
|
1482
|
-
kv = key:$[a-z]i+ "=" value:$[^&#]i* {
|
|
1483
|
-
params[key] = value;
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
|
-
single = key:$[a-z]i+ {
|
|
1487
|
-
params[key] = true;
|
|
1488
|
-
};
|
|
1489
|
-
|
|
1490
|
-
name = "#" + match:$.* {
|
|
1491
|
-
return decodeURIComponent(match);
|
|
1492
|
-
}
|
|
1493
|
-
`;
|
|
1494
|
-
var parser4;
|
|
1495
1540
|
function getParser4() {
|
|
1496
1541
|
if (!parser4) {
|
|
1497
|
-
parser4 =
|
|
1542
|
+
parser4 = {
|
|
1543
|
+
parse: parseTrojan
|
|
1544
|
+
};
|
|
1498
1545
|
}
|
|
1499
1546
|
return parser4;
|
|
1500
1547
|
}
|
|
@@ -1708,133 +1755,6 @@ function normalizeXhttpIntegerValue(value, { allowNegative = true } = {}) {
|
|
|
1708
1755
|
return parsedInteger;
|
|
1709
1756
|
}
|
|
1710
1757
|
|
|
1711
|
-
// src/vendors/Sub-Store/backend/src/core/proxy-utils/transport-path.js
|
|
1712
|
-
function decodeQueryComponent(value) {
|
|
1713
|
-
try {
|
|
1714
|
-
return decodeURIComponent(`${value}`.replace(/\+/g, "%20"));
|
|
1715
|
-
} catch (e) {
|
|
1716
|
-
return value;
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
function splitQueryPart(part) {
|
|
1720
|
-
const separatorIndex = part.indexOf("=");
|
|
1721
|
-
if (separatorIndex === -1) {
|
|
1722
|
-
return {
|
|
1723
|
-
key: decodeQueryComponent(part),
|
|
1724
|
-
value: ""
|
|
1725
|
-
};
|
|
1726
|
-
}
|
|
1727
|
-
return {
|
|
1728
|
-
key: decodeQueryComponent(part.slice(0, separatorIndex)),
|
|
1729
|
-
value: decodeQueryComponent(part.slice(separatorIndex + 1))
|
|
1730
|
-
};
|
|
1731
|
-
}
|
|
1732
|
-
function parseSafeIntegerValue(value) {
|
|
1733
|
-
if (!/^\d+$/.test(`${value}`)) return null;
|
|
1734
|
-
const parsed = parseInt(`${value}`, 10);
|
|
1735
|
-
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
1736
|
-
}
|
|
1737
|
-
function extractPathQueryParam(rawPath, paramName) {
|
|
1738
|
-
const path = rawPath == null ? "" : `${rawPath}`;
|
|
1739
|
-
const queryIndex = path.indexOf("?");
|
|
1740
|
-
if (queryIndex === -1) {
|
|
1741
|
-
return {
|
|
1742
|
-
path,
|
|
1743
|
-
value: ""
|
|
1744
|
-
};
|
|
1745
|
-
}
|
|
1746
|
-
const basePath = path.slice(0, queryIndex);
|
|
1747
|
-
const query = path.slice(queryIndex + 1);
|
|
1748
|
-
const keptParts = [];
|
|
1749
|
-
let value = "";
|
|
1750
|
-
for (const part of query.split("&")) {
|
|
1751
|
-
if (part === "") continue;
|
|
1752
|
-
const parsed = splitQueryPart(part);
|
|
1753
|
-
if (parsed.key === paramName) {
|
|
1754
|
-
if (value === "" && parsed.value !== "") {
|
|
1755
|
-
value = parsed.value;
|
|
1756
|
-
}
|
|
1757
|
-
continue;
|
|
1758
|
-
}
|
|
1759
|
-
keptParts.push(part);
|
|
1760
|
-
}
|
|
1761
|
-
return {
|
|
1762
|
-
path: keptParts.length > 0 ? `${basePath}?${keptParts.join("&")}` : basePath,
|
|
1763
|
-
value
|
|
1764
|
-
};
|
|
1765
|
-
}
|
|
1766
|
-
function getPathQueryParam(rawPath, paramName) {
|
|
1767
|
-
const path = rawPath == null ? "" : `${rawPath}`;
|
|
1768
|
-
const queryIndex = path.indexOf("?");
|
|
1769
|
-
if (queryIndex === -1) return "";
|
|
1770
|
-
const query = path.slice(queryIndex + 1);
|
|
1771
|
-
for (const part of query.split("&")) {
|
|
1772
|
-
if (part === "") continue;
|
|
1773
|
-
const parsed = splitQueryPart(part);
|
|
1774
|
-
if (parsed.key === paramName && parsed.value !== "") {
|
|
1775
|
-
return parsed.value;
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
return "";
|
|
1779
|
-
}
|
|
1780
|
-
function getSafeIntegerPathQueryParam(rawPath, paramName) {
|
|
1781
|
-
const value = getPathQueryParam(rawPath, paramName);
|
|
1782
|
-
const parsed = parseSafeIntegerValue(value);
|
|
1783
|
-
if (parsed == null) {
|
|
1784
|
-
return {
|
|
1785
|
-
value: "",
|
|
1786
|
-
parsed: null
|
|
1787
|
-
};
|
|
1788
|
-
}
|
|
1789
|
-
return {
|
|
1790
|
-
value,
|
|
1791
|
-
parsed
|
|
1792
|
-
};
|
|
1793
|
-
}
|
|
1794
|
-
function appendPathQueryParam(path, paramName, value) {
|
|
1795
|
-
const separator = path.includes("?") ? path.endsWith("?") || path.endsWith("&") ? "" : "&" : "?";
|
|
1796
|
-
return `${path}${separator}${encodeURIComponent(
|
|
1797
|
-
paramName
|
|
1798
|
-
)}=${encodeURIComponent(`${value}`)}`;
|
|
1799
|
-
}
|
|
1800
|
-
function setPathQueryParam(rawPath, paramName, value) {
|
|
1801
|
-
const path = rawPath == null || rawPath === "" ? "/" : `${rawPath}`;
|
|
1802
|
-
const { path: pathWithoutParam } = extractPathQueryParam(path, paramName);
|
|
1803
|
-
return appendPathQueryParam(pathWithoutParam, paramName, value);
|
|
1804
|
-
}
|
|
1805
|
-
function normalizeWebSocketEarlyDataPath(wsOpts) {
|
|
1806
|
-
const networkPath = wsOpts?.path;
|
|
1807
|
-
if (!wsOpts) return;
|
|
1808
|
-
const { value: ed, parsed: maxEarlyData } = getSafeIntegerPathQueryParam(
|
|
1809
|
-
networkPath,
|
|
1810
|
-
"ed"
|
|
1811
|
-
);
|
|
1812
|
-
if (wsOpts["v2ray-http-upgrade"]) {
|
|
1813
|
-
if (ed !== "") {
|
|
1814
|
-
wsOpts.path = extractPathQueryParam(networkPath, "ed").path;
|
|
1815
|
-
wsOpts["v2ray-http-upgrade-fast-open"] = true;
|
|
1816
|
-
if (wsOpts["_v2ray-http-upgrade-ed"] == null || `${wsOpts["_v2ray-http-upgrade-ed"]}` === "") {
|
|
1817
|
-
wsOpts["_v2ray-http-upgrade-ed"] = ed;
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
|
-
delete wsOpts["early-data-header-name"];
|
|
1821
|
-
delete wsOpts["max-early-data"];
|
|
1822
|
-
return;
|
|
1823
|
-
}
|
|
1824
|
-
if (ed === "") return;
|
|
1825
|
-
wsOpts.path = extractPathQueryParam(networkPath, "ed").path;
|
|
1826
|
-
if (wsOpts["early-data-header-name"] == null) {
|
|
1827
|
-
wsOpts["early-data-header-name"] = "Sec-WebSocket-Protocol";
|
|
1828
|
-
}
|
|
1829
|
-
if (wsOpts["max-early-data"] == null) {
|
|
1830
|
-
wsOpts["max-early-data"] = maxEarlyData;
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
function deleteHttpUpgradeEarlyDataMetadata(wsOpts) {
|
|
1834
|
-
if (!wsOpts) return;
|
|
1835
|
-
delete wsOpts["_v2ray-http-upgrade-ed"];
|
|
1836
|
-
}
|
|
1837
|
-
|
|
1838
1758
|
// src/vendors/Sub-Store/backend/src/core/proxy-utils/ech-utils.js
|
|
1839
1759
|
var ECH_DNS_FIELD = "_dns";
|
|
1840
1760
|
var ECH_FORCE_QUERY_FIELD = "_force-query";
|
|
@@ -1962,7 +1882,8 @@ var VMESS_SECURITY_ALIASES = {
|
|
|
1962
1882
|
"chacha20-ietf-poly1305": "chacha20-poly1305"
|
|
1963
1883
|
};
|
|
1964
1884
|
function normalizeSecurityValue(security) {
|
|
1965
|
-
if (security == null)
|
|
1885
|
+
if (security == null)
|
|
1886
|
+
return "";
|
|
1966
1887
|
return `${security}`.trim().toLowerCase();
|
|
1967
1888
|
}
|
|
1968
1889
|
function canonicalizeVmessSecurity(security) {
|
|
@@ -1970,7 +1891,8 @@ function canonicalizeVmessSecurity(security) {
|
|
|
1970
1891
|
}
|
|
1971
1892
|
function normalizeVmessSecurity(security, supportedValues = VMESS_SECURITY_COMMON_VALUES, { acceptAliases = true, fallback = VMESS_SECURITY_AUTO } = {}) {
|
|
1972
1893
|
const normalized = normalizeSecurityValue(security);
|
|
1973
|
-
if (!normalized)
|
|
1894
|
+
if (!normalized)
|
|
1895
|
+
return fallback;
|
|
1974
1896
|
const normalizedSupported = supportedValues.map(normalizeSecurityValue);
|
|
1975
1897
|
if (normalizedSupported.includes(normalized)) {
|
|
1976
1898
|
return canonicalizeVmessSecurity(normalized);
|
|
@@ -2001,7 +1923,8 @@ function formatSurgeVmessEncryptMethod(security) {
|
|
|
2001
1923
|
"aes-128-gcm",
|
|
2002
1924
|
"chacha20-poly1305"
|
|
2003
1925
|
]);
|
|
2004
|
-
if (normalized === VMESS_SECURITY_AUTO)
|
|
1926
|
+
if (normalized === VMESS_SECURITY_AUTO)
|
|
1927
|
+
return void 0;
|
|
2005
1928
|
return normalized === "chacha20-poly1305" ? "chacha20-ietf-poly1305" : normalized;
|
|
2006
1929
|
}
|
|
2007
1930
|
|
|
@@ -2036,13 +1959,14 @@ function decodeShadowsocksUserInfo(rawUserInfoStr) {
|
|
|
2036
1959
|
}
|
|
2037
1960
|
return Base64.decode(decodedUserInfoStr);
|
|
2038
1961
|
}
|
|
2039
|
-
function
|
|
2040
|
-
if (value == null || !/^\d+$/.test(`${value}`))
|
|
1962
|
+
function isNumericEarlyData2(value) {
|
|
1963
|
+
if (value == null || !/^\d+$/.test(`${value}`))
|
|
1964
|
+
return false;
|
|
2041
1965
|
return Number.isSafeInteger(parseInt(`${value}`, 10));
|
|
2042
1966
|
}
|
|
2043
1967
|
function extractEarlyDataFromPath(path) {
|
|
2044
1968
|
const ed = getPathQueryParam(path, "ed");
|
|
2045
|
-
if (!
|
|
1969
|
+
if (!isNumericEarlyData2(ed)) {
|
|
2046
1970
|
return {
|
|
2047
1971
|
path,
|
|
2048
1972
|
ed: ""
|
|
@@ -2075,16 +1999,21 @@ function splitURIHostList(host) {
|
|
|
2075
1999
|
return hosts.length > 0 ? hosts : void 0;
|
|
2076
2000
|
}
|
|
2077
2001
|
function parseWireGuardURIAddressValue(value) {
|
|
2078
|
-
if (value == null)
|
|
2002
|
+
if (value == null)
|
|
2003
|
+
return null;
|
|
2079
2004
|
const raw = `${value}`.trim();
|
|
2080
|
-
if (!raw)
|
|
2005
|
+
if (!raw)
|
|
2006
|
+
return null;
|
|
2081
2007
|
const [, hostRaw = raw, cidrRaw] = /^(.*?)(?:\/(\d+))?$/.exec(raw) || [];
|
|
2082
2008
|
const host = `${hostRaw}`.trim().replace(/^\[/, "").replace(/\]$/, "");
|
|
2083
2009
|
const normalizeCIDR = (cidr, max) => {
|
|
2084
|
-
if (cidr == null)
|
|
2085
|
-
|
|
2010
|
+
if (cidr == null)
|
|
2011
|
+
return void 0;
|
|
2012
|
+
if (!/^\d+$/.test(cidr))
|
|
2013
|
+
return void 0;
|
|
2086
2014
|
const parsed = parseInt(cidr, 10);
|
|
2087
|
-
if (parsed < 0 || parsed > max)
|
|
2015
|
+
if (parsed < 0 || parsed > max)
|
|
2016
|
+
return void 0;
|
|
2088
2017
|
return parsed;
|
|
2089
2018
|
};
|
|
2090
2019
|
if (isIPv4(host)) {
|
|
@@ -2267,7 +2196,7 @@ function URI_SS() {
|
|
|
2267
2196
|
);
|
|
2268
2197
|
}
|
|
2269
2198
|
if (httpupgrade) {
|
|
2270
|
-
httpUpgradeEd = httpUpgradeEd || (
|
|
2199
|
+
httpUpgradeEd = httpUpgradeEd || (isNumericEarlyData2(params.ed) ? `${params.ed}` : "");
|
|
2271
2200
|
_.set(
|
|
2272
2201
|
proxy,
|
|
2273
2202
|
proxy.network + "-opts.v2ray-http-upgrade",
|
|
@@ -2339,12 +2268,14 @@ function URI_SS() {
|
|
|
2339
2268
|
for (const item of pluginInfo) {
|
|
2340
2269
|
const separatorIndex = item.indexOf("=");
|
|
2341
2270
|
if (separatorIndex === -1) {
|
|
2342
|
-
if (item)
|
|
2271
|
+
if (item)
|
|
2272
|
+
params2[item] = true;
|
|
2343
2273
|
continue;
|
|
2344
2274
|
}
|
|
2345
2275
|
const key = item.slice(0, separatorIndex);
|
|
2346
2276
|
const val = item.slice(separatorIndex + 1).replace(/\\=/g, "=");
|
|
2347
|
-
if (key)
|
|
2277
|
+
if (key)
|
|
2278
|
+
params2[key] = val || true;
|
|
2348
2279
|
}
|
|
2349
2280
|
switch (params2.plugin) {
|
|
2350
2281
|
case "obfs-local":
|
|
@@ -2693,7 +2624,7 @@ function URI_VMess() {
|
|
|
2693
2624
|
}
|
|
2694
2625
|
if (httpupgrade) {
|
|
2695
2626
|
opts["v2ray-http-upgrade"] = true;
|
|
2696
|
-
httpUpgradeEd = httpUpgradeEd || (
|
|
2627
|
+
httpUpgradeEd = httpUpgradeEd || (isNumericEarlyData2(params.ed) ? `${params.ed}` : "");
|
|
2697
2628
|
if (httpUpgradeEd !== "") {
|
|
2698
2629
|
opts["v2ray-http-upgrade-fast-open"] = true;
|
|
2699
2630
|
opts["_v2ray-http-upgrade-ed"] = httpUpgradeEd;
|
|
@@ -3496,6 +3427,8 @@ function URI_VLESS() {
|
|
|
3496
3427
|
proxy["ech-opts"] = echOpts;
|
|
3497
3428
|
}
|
|
3498
3429
|
proxy["tls-fingerprint"] = getIfPresent(params.pcs);
|
|
3430
|
+
proxy._vcn = params.vcn?.split(",").map((name3) => name3.trim()).filter(Boolean);
|
|
3431
|
+
proxy["name-cert-verify"] = proxy._vcn?.[0];
|
|
3499
3432
|
proxy._h2 = /(TRUE)|1/i.test(params.h2);
|
|
3500
3433
|
switch (`${params.packetEncoding || ""}`.trim().toLowerCase()) {
|
|
3501
3434
|
case "none":
|
|
@@ -3821,6 +3754,12 @@ function URI_Hysteria2() {
|
|
|
3821
3754
|
if (params.downmbps) {
|
|
3822
3755
|
proxy.down = params.downmbps;
|
|
3823
3756
|
}
|
|
3757
|
+
const echOpts = buildMihomoEchOptsFromXrayFields({
|
|
3758
|
+
echConfigList: params.ech
|
|
3759
|
+
});
|
|
3760
|
+
if (echOpts) {
|
|
3761
|
+
proxy["ech-opts"] = echOpts;
|
|
3762
|
+
}
|
|
3824
3763
|
return proxy;
|
|
3825
3764
|
};
|
|
3826
3765
|
return { name, test, parse: parse2 };
|
|
@@ -3999,7 +3938,8 @@ function URI_WireGuard() {
|
|
|
3999
3938
|
} else if (["address", "ip"].includes(key)) {
|
|
4000
3939
|
value.split(",").map((i) => {
|
|
4001
3940
|
const parsed = parseWireGuardURIAddressValue(i);
|
|
4002
|
-
if (!parsed)
|
|
3941
|
+
if (!parsed)
|
|
3942
|
+
return;
|
|
4003
3943
|
if (parsed.family === "ipv4") {
|
|
4004
3944
|
proxy.ip = parsed.address;
|
|
4005
3945
|
if (typeof parsed.cidr !== "undefined") {
|
|
@@ -4076,6 +4016,7 @@ function Clash_All() {
|
|
|
4076
4016
|
proxy = yaml_default.parse(line);
|
|
4077
4017
|
}
|
|
4078
4018
|
if (![
|
|
4019
|
+
"shadowquic",
|
|
4079
4020
|
"gost-relay",
|
|
4080
4021
|
"openvpn",
|
|
4081
4022
|
"tailscale",
|
|
@@ -4675,7 +4616,7 @@ function Base64Encoded() {
|
|
|
4675
4616
|
// tuic://
|
|
4676
4617
|
];
|
|
4677
4618
|
const test = function(raw) {
|
|
4678
|
-
return !/^\w+:\/\/\w+/im.test(raw) && keys.some((k) => raw.indexOf(k) !== -1);
|
|
4619
|
+
return Base642.isValid(raw) && !/^\w+:\/\/\w+/im.test(raw) && keys.some((k) => raw.indexOf(k) !== -1);
|
|
4679
4620
|
};
|
|
4680
4621
|
const parse2 = function(raw) {
|
|
4681
4622
|
const decoded = Base642.decode(raw);
|
|
@@ -4692,7 +4633,7 @@ function Base64Encoded() {
|
|
|
4692
4633
|
function fallbackBase64Encoded() {
|
|
4693
4634
|
const name = "Fallback Base64 Pre-processor";
|
|
4694
4635
|
const test = function(raw) {
|
|
4695
|
-
return
|
|
4636
|
+
return Base642.isValid(raw);
|
|
4696
4637
|
};
|
|
4697
4638
|
const parse2 = function(raw) {
|
|
4698
4639
|
const decoded = Base642.decode(raw);
|
|
@@ -4709,14 +4650,15 @@ function fallbackBase64Encoded() {
|
|
|
4709
4650
|
function Clash() {
|
|
4710
4651
|
const name = "Clash Pre-processor";
|
|
4711
4652
|
const test = function(raw) {
|
|
4712
|
-
if (!/proxies/.test(raw))
|
|
4653
|
+
if (!/proxies/.test(raw))
|
|
4654
|
+
return false;
|
|
4713
4655
|
const content = safeLoad(raw);
|
|
4714
|
-
return content.proxies
|
|
4656
|
+
return Array.isArray(content.proxies) || Array.isArray(content["proxy-groups"]);
|
|
4715
4657
|
};
|
|
4716
4658
|
const parse2 = function(raw, includeProxies) {
|
|
4717
4659
|
const afterReplace = normalizeClashYaml(raw);
|
|
4718
4660
|
const { proxies } = safeLoad(afterReplace);
|
|
4719
|
-
return (includeProxies ? "proxies:\n" : "") + proxies.map((p) => {
|
|
4661
|
+
return (includeProxies ? "proxies:\n" : "") + (Array.isArray(proxies) ? proxies : []).map((p) => {
|
|
4720
4662
|
return `${includeProxies ? " - " : ""}${JSON.stringify(
|
|
4721
4663
|
p
|
|
4722
4664
|
)}
|
|
@@ -4806,12 +4748,16 @@ function isShadowsocksOverTls(proxy) {
|
|
|
4806
4748
|
return proxy?.type === "ss" && proxy?.tls === true && !isPresent2(proxy, "plugin") && (!isPresent2(proxy, "network") || normalizedNetwork === "tcp");
|
|
4807
4749
|
}
|
|
4808
4750
|
function normalizePluginMuxValue(mux) {
|
|
4809
|
-
if (typeof mux === "boolean")
|
|
4751
|
+
if (typeof mux === "boolean")
|
|
4752
|
+
return Number(mux);
|
|
4810
4753
|
if (typeof mux === "string") {
|
|
4811
4754
|
const normalized = mux.trim().toLowerCase();
|
|
4812
|
-
if (normalized === "true")
|
|
4813
|
-
|
|
4814
|
-
if (
|
|
4755
|
+
if (normalized === "true")
|
|
4756
|
+
return 1;
|
|
4757
|
+
if (normalized === "false")
|
|
4758
|
+
return 0;
|
|
4759
|
+
if (/^\d+$/.test(normalized))
|
|
4760
|
+
return parseInt(normalized, 10);
|
|
4815
4761
|
}
|
|
4816
4762
|
return mux;
|
|
4817
4763
|
}
|
|
@@ -4819,27 +4765,34 @@ function normalizePluginMuxBooleanValue(mux) {
|
|
|
4819
4765
|
return Boolean(normalizePluginMuxValue(mux));
|
|
4820
4766
|
}
|
|
4821
4767
|
function supportsShadowsocksV2rayPluginMode(proxy, supportedModes) {
|
|
4822
|
-
if (proxy?.type !== "ss" || proxy?.plugin !== "v2ray-plugin")
|
|
4768
|
+
if (proxy?.type !== "ss" || proxy?.plugin !== "v2ray-plugin")
|
|
4769
|
+
return true;
|
|
4823
4770
|
const normalizedMode = typeof proxy?.["plugin-opts"]?.mode === "string" ? proxy["plugin-opts"].mode.trim().toLowerCase() : proxy?.["plugin-opts"]?.mode;
|
|
4824
4771
|
return supportedModes.includes(normalizedMode);
|
|
4825
4772
|
}
|
|
4826
4773
|
function parseWireGuardCIDR(cidr, max) {
|
|
4827
|
-
if (cidr == null)
|
|
4774
|
+
if (cidr == null)
|
|
4775
|
+
return void 0;
|
|
4828
4776
|
const normalized = `${cidr}`.trim();
|
|
4829
|
-
if (!/^\d+$/.test(normalized))
|
|
4777
|
+
if (!/^\d+$/.test(normalized))
|
|
4778
|
+
return void 0;
|
|
4830
4779
|
const parsed = parseInt(normalized, 10);
|
|
4831
|
-
if (parsed < 0 || parsed > max)
|
|
4780
|
+
if (parsed < 0 || parsed > max)
|
|
4781
|
+
return void 0;
|
|
4832
4782
|
return parsed;
|
|
4833
4783
|
}
|
|
4834
4784
|
function parseWireGuardInterfaceAddress(value, family) {
|
|
4835
|
-
if (value == null)
|
|
4785
|
+
if (value == null)
|
|
4786
|
+
return null;
|
|
4836
4787
|
const raw = `${value}`.trim();
|
|
4837
|
-
if (!raw)
|
|
4788
|
+
if (!raw)
|
|
4789
|
+
return null;
|
|
4838
4790
|
const [, hostRaw = raw, cidrRaw] = /^(.*?)(?:\/(\d+))?$/.exec(raw) || [];
|
|
4839
4791
|
const host = `${hostRaw}`.trim().replace(/^\[/, "").replace(/\]$/, "");
|
|
4840
4792
|
const isIPv4Family = family === "ipv4";
|
|
4841
4793
|
const isValid = isIPv4Family ? isIPv4(host) : isIPv6(host);
|
|
4842
|
-
if (!isValid)
|
|
4794
|
+
if (!isValid)
|
|
4795
|
+
return null;
|
|
4843
4796
|
const max = isIPv4Family ? 32 : 128;
|
|
4844
4797
|
return {
|
|
4845
4798
|
address: host,
|
|
@@ -4852,7 +4805,8 @@ function getWireGuardAddressWithCIDR(proxy = {}, family = "ipv4") {
|
|
|
4852
4805
|
proxy[config.addressKey],
|
|
4853
4806
|
family
|
|
4854
4807
|
);
|
|
4855
|
-
if (!parsed)
|
|
4808
|
+
if (!parsed)
|
|
4809
|
+
return void 0;
|
|
4856
4810
|
const normalizedCIDR = parseWireGuardCIDR(
|
|
4857
4811
|
proxy[config.cidrKey],
|
|
4858
4812
|
config.defaultCIDR
|
|
@@ -4860,7 +4814,8 @@ function getWireGuardAddressWithCIDR(proxy = {}, family = "ipv4") {
|
|
|
4860
4814
|
return `${parsed.address}/${normalizedCIDR ?? parsed.cidr ?? config.defaultCIDR}`;
|
|
4861
4815
|
}
|
|
4862
4816
|
function produceProxyListOutput(list, type, opts = {}) {
|
|
4863
|
-
if (type === "internal")
|
|
4817
|
+
if (type === "internal")
|
|
4818
|
+
return list;
|
|
4864
4819
|
if (opts.prettyYaml || opts["pretty-yaml"]) {
|
|
4865
4820
|
return normalizeClashYaml(
|
|
4866
4821
|
yaml_default.safeDump(
|
|
@@ -4895,7 +4850,8 @@ var ipVersions = {
|
|
|
4895
4850
|
"ipv6-prefer": "prefer-v6"
|
|
4896
4851
|
};
|
|
4897
4852
|
function stripSurgeQuotes(value) {
|
|
4898
|
-
if (typeof value !== "string")
|
|
4853
|
+
if (typeof value !== "string")
|
|
4854
|
+
return value;
|
|
4899
4855
|
const trimmed = value.trim();
|
|
4900
4856
|
const quote = trimmed[0];
|
|
4901
4857
|
if ((quote === '"' || quote === "'") && trimmed[trimmed.length - 1] === quote) {
|
|
@@ -4916,19 +4872,23 @@ function formatSurgeAlpn(alpn) {
|
|
|
4916
4872
|
}
|
|
4917
4873
|
function appendAlpn(result, proxy) {
|
|
4918
4874
|
const alpn = formatSurgeAlpn(proxy.alpn);
|
|
4919
|
-
if (alpn)
|
|
4875
|
+
if (alpn)
|
|
4876
|
+
result.append(`,alpn="${alpn}"`);
|
|
4920
4877
|
}
|
|
4921
4878
|
function getShadowTLSAlpn(proxy) {
|
|
4922
4879
|
return formatSurgeAlpn(proxy?.["plugin-opts"]?.alpn ?? proxy?.alpn);
|
|
4923
4880
|
}
|
|
4924
4881
|
function appendShadowTLS(result, proxy, includeUdpPort = false) {
|
|
4925
|
-
if (proxy.plugin !== "shadow-tls" || !proxy["plugin-opts"])
|
|
4882
|
+
if (proxy.plugin !== "shadow-tls" || !proxy["plugin-opts"])
|
|
4883
|
+
return;
|
|
4926
4884
|
const password = proxy["plugin-opts"].password;
|
|
4927
4885
|
const host = proxy["plugin-opts"].host;
|
|
4928
4886
|
const version = proxy["plugin-opts"].version;
|
|
4929
|
-
if (!password)
|
|
4887
|
+
if (!password)
|
|
4888
|
+
return;
|
|
4930
4889
|
result.append(`,shadow-tls-password="${password}"`);
|
|
4931
|
-
if (host)
|
|
4890
|
+
if (host)
|
|
4891
|
+
result.append(`,shadow-tls-sni=${host}`);
|
|
4932
4892
|
if (version) {
|
|
4933
4893
|
if (version < 2) {
|
|
4934
4894
|
throw unsupported(`shadow-tls version ${version} is not supported`);
|
|
@@ -4936,7 +4896,8 @@ function appendShadowTLS(result, proxy, includeUdpPort = false) {
|
|
|
4936
4896
|
result.append(`,shadow-tls-version=${version}`);
|
|
4937
4897
|
}
|
|
4938
4898
|
const alpn = getShadowTLSAlpn(proxy);
|
|
4939
|
-
if (alpn)
|
|
4899
|
+
if (alpn)
|
|
4900
|
+
result.append(`,alpn="${alpn}"`);
|
|
4940
4901
|
if (includeUdpPort) {
|
|
4941
4902
|
result.appendIfPresent(`,udp-port=${proxy["udp-port"]}`, "udp-port");
|
|
4942
4903
|
}
|
|
@@ -4950,6 +4911,12 @@ function appendTlsProxyParams(result, proxy, enabled = true) {
|
|
|
4950
4911
|
"tls-fingerprint"
|
|
4951
4912
|
);
|
|
4952
4913
|
result.appendIfPresent(`,sni="${proxy.sni}"`, "sni");
|
|
4914
|
+
result.appendIfPresent(
|
|
4915
|
+
`,server-cert-verify-name=${quoteSurgeValue(
|
|
4916
|
+
proxy["name-cert-verify"]
|
|
4917
|
+
)}`,
|
|
4918
|
+
"name-cert-verify"
|
|
4919
|
+
);
|
|
4953
4920
|
if (proxy.plugin !== "shadow-tls") {
|
|
4954
4921
|
appendAlpn(result, proxy);
|
|
4955
4922
|
}
|
|
@@ -4969,9 +4936,11 @@ function appendSshPrivateKey(result, proxy) {
|
|
|
4969
4936
|
}
|
|
4970
4937
|
}
|
|
4971
4938
|
function warnMaxStreamsIfNeeded(proxy) {
|
|
4972
|
-
if (!isPresent2(proxy, "max-streams"))
|
|
4939
|
+
if (!isPresent2(proxy, "max-streams"))
|
|
4940
|
+
return;
|
|
4973
4941
|
const maxStreams = Number(stripSurgeQuotes(proxy["max-streams"]));
|
|
4974
|
-
if (!Number.isInteger(maxStreams) || maxStreams <= 3)
|
|
4942
|
+
if (!Number.isInteger(maxStreams) || maxStreams <= 3)
|
|
4943
|
+
return;
|
|
4975
4944
|
app_default.warn(
|
|
4976
4945
|
`Surge ${proxy.type} proxy ${proxy.name}: max-streams=${maxStreams} is greater than 3. Too many streams sharing one TCP connection may hurt performance.`
|
|
4977
4946
|
);
|
|
@@ -5895,7 +5864,8 @@ function ClashMeta_Producer() {
|
|
|
5895
5864
|
const type = "ALL";
|
|
5896
5865
|
const produce2 = (proxies, type2, opts = {}) => {
|
|
5897
5866
|
const list = proxies.filter((proxy) => {
|
|
5898
|
-
if (opts["include-unsupported-proxy"])
|
|
5867
|
+
if (opts["include-unsupported-proxy"])
|
|
5868
|
+
return true;
|
|
5899
5869
|
if (proxy.type === "h2-connect") {
|
|
5900
5870
|
app_default.error(
|
|
5901
5871
|
`mihomo does not support HTTP/2 CONNECT proxy type. Proxy ${proxy.name} has been filtered.`
|
|
@@ -6024,6 +5994,9 @@ function ClashMeta_Producer() {
|
|
|
6024
5994
|
ds["reality-opts"] = { "public-key": "" };
|
|
6025
5995
|
}
|
|
6026
5996
|
}
|
|
5997
|
+
} else if (["anytls"].includes(proxy.type) && proxy.reuse != null && !proxy.reuse) {
|
|
5998
|
+
proxy["disable-reuse"] = true;
|
|
5999
|
+
delete proxy.reuse;
|
|
6027
6000
|
}
|
|
6028
6001
|
if (isPresent2(proxy, "plugin-opts.mux")) {
|
|
6029
6002
|
proxy["plugin-opts"].mux = normalizePluginMuxBooleanValue(
|
|
@@ -6094,7 +6067,9 @@ function ClashMeta_Producer() {
|
|
|
6094
6067
|
"juicity",
|
|
6095
6068
|
"anytls",
|
|
6096
6069
|
"trusttunnel",
|
|
6097
|
-
"naive"
|
|
6070
|
+
"naive",
|
|
6071
|
+
"masque",
|
|
6072
|
+
"shadowquic"
|
|
6098
6073
|
].includes(proxy.type)) {
|
|
6099
6074
|
delete proxy.tls;
|
|
6100
6075
|
}
|
|
@@ -6180,8 +6155,6 @@ function SurgeMac_Producer() {
|
|
|
6180
6155
|
switch (proxy.type) {
|
|
6181
6156
|
case "external":
|
|
6182
6157
|
return external(proxy);
|
|
6183
|
-
// case 'ssr':
|
|
6184
|
-
// return shadowsocksr(proxy);
|
|
6185
6158
|
default: {
|
|
6186
6159
|
if (opts.mihomoExternal || proxy._mihomoExternal) {
|
|
6187
6160
|
return mihomo(proxy, type, opts) || "";
|
|
@@ -6368,7 +6341,8 @@ function Clash_Producer() {
|
|
|
6368
6341
|
const type = "ALL";
|
|
6369
6342
|
const produce2 = (proxies, type2, opts = {}) => {
|
|
6370
6343
|
const list = proxies.filter((proxy) => {
|
|
6371
|
-
if (opts["include-unsupported-proxy"])
|
|
6344
|
+
if (opts["include-unsupported-proxy"])
|
|
6345
|
+
return true;
|
|
6372
6346
|
if (![
|
|
6373
6347
|
"ss",
|
|
6374
6348
|
"ssr",
|
|
@@ -6523,7 +6497,8 @@ function Stash_Producer() {
|
|
|
6523
6497
|
const type = "ALL";
|
|
6524
6498
|
const produce2 = (proxies, type2, opts = {}) => {
|
|
6525
6499
|
const list = proxies.filter((proxy) => {
|
|
6526
|
-
if (opts["include-unsupported-proxy"])
|
|
6500
|
+
if (opts["include-unsupported-proxy"])
|
|
6501
|
+
return true;
|
|
6527
6502
|
if (![
|
|
6528
6503
|
"ss",
|
|
6529
6504
|
"ssr",
|
|
@@ -6813,11 +6788,13 @@ function Loon_Producer() {
|
|
|
6813
6788
|
}
|
|
6814
6789
|
function appendTlsProfile(result, proxy) {
|
|
6815
6790
|
const tlsProfile = getLoonTlsProfile(proxy);
|
|
6816
|
-
if (tlsProfile)
|
|
6791
|
+
if (tlsProfile)
|
|
6792
|
+
result.append(`,tls-profile=${tlsProfile}`);
|
|
6817
6793
|
}
|
|
6818
6794
|
function appendAlpn2(result, proxy) {
|
|
6819
6795
|
const alpn = getLoonAlpn(proxy);
|
|
6820
|
-
if (alpn)
|
|
6796
|
+
if (alpn)
|
|
6797
|
+
result.append(`,alpn="${alpn}"`);
|
|
6821
6798
|
}
|
|
6822
6799
|
function getLoonShadowTLSAlpn(proxy) {
|
|
6823
6800
|
const values = proxy?.["plugin-opts"]?.alpn ?? proxy?.alpn;
|
|
@@ -6825,13 +6802,16 @@ function getLoonShadowTLSAlpn(proxy) {
|
|
|
6825
6802
|
return normalized.map((item) => `${item}`.trim()).filter((item) => item !== "").join(",");
|
|
6826
6803
|
}
|
|
6827
6804
|
function appendShadowTLS2(result, proxy) {
|
|
6828
|
-
if (proxy.plugin !== "shadow-tls" || !proxy["plugin-opts"])
|
|
6805
|
+
if (proxy.plugin !== "shadow-tls" || !proxy["plugin-opts"])
|
|
6806
|
+
return;
|
|
6829
6807
|
const password = proxy["plugin-opts"].password;
|
|
6830
6808
|
const host = proxy["plugin-opts"].host;
|
|
6831
6809
|
const version = proxy["plugin-opts"].version;
|
|
6832
|
-
if (!password)
|
|
6810
|
+
if (!password)
|
|
6811
|
+
return;
|
|
6833
6812
|
result.append(`,shadow-tls-password=${password}`);
|
|
6834
|
-
if (host)
|
|
6813
|
+
if (host)
|
|
6814
|
+
result.append(`,shadow-tls-sni=${host}`);
|
|
6835
6815
|
if (version) {
|
|
6836
6816
|
if (version < 2) {
|
|
6837
6817
|
throw new Error(`shadow-tls version ${version} is not supported`);
|
|
@@ -6840,7 +6820,8 @@ function appendShadowTLS2(result, proxy) {
|
|
|
6840
6820
|
}
|
|
6841
6821
|
appendTlsProfile(result, proxy);
|
|
6842
6822
|
const alpn = getLoonShadowTLSAlpn(proxy);
|
|
6843
|
-
if (alpn)
|
|
6823
|
+
if (alpn)
|
|
6824
|
+
result.append(`,alpn="${alpn}"`);
|
|
6844
6825
|
result.appendIfPresent(`,udp-port=${proxy["udp-port"]}`, "udp-port");
|
|
6845
6826
|
}
|
|
6846
6827
|
function appendReality(result, proxy) {
|
|
@@ -7423,7 +7404,8 @@ function getHttpUpgradeEarlyData(transportOpts, path) {
|
|
|
7423
7404
|
const httpUpgradeEd = getSafeEarlyDataValue(
|
|
7424
7405
|
transportOpts?.["_v2ray-http-upgrade-ed"]
|
|
7425
7406
|
);
|
|
7426
|
-
if (httpUpgradeEd !== "")
|
|
7407
|
+
if (httpUpgradeEd !== "")
|
|
7408
|
+
return httpUpgradeEd;
|
|
7427
7409
|
const pathEd = getSafeEarlyDataValue(
|
|
7428
7410
|
extractPathQueryParam(path || "/", "ed").value
|
|
7429
7411
|
);
|
|
@@ -7455,7 +7437,8 @@ function setWebSocketEarlyDataPath(path, transportOpts) {
|
|
|
7455
7437
|
return setPathQueryParam(path || "/", "ed", earlyData);
|
|
7456
7438
|
}
|
|
7457
7439
|
function getSafeEarlyDataValue(value) {
|
|
7458
|
-
if (value == null || `${value}` === "")
|
|
7440
|
+
if (value == null || `${value}` === "")
|
|
7441
|
+
return "";
|
|
7459
7442
|
return parseSafeIntegerValue(value) == null ? "" : `${value}`;
|
|
7460
7443
|
}
|
|
7461
7444
|
function parseIntegerLikeValue(value) {
|
|
@@ -7844,6 +7827,11 @@ function vless2(proxy) {
|
|
|
7844
7827
|
if (proxy["tls-fingerprint"]) {
|
|
7845
7828
|
pcs = `&pcs=${encodeURIComponent(proxy["tls-fingerprint"])}`;
|
|
7846
7829
|
}
|
|
7830
|
+
let vcn = "";
|
|
7831
|
+
const certNames = Array.isArray(proxy._vcn) ? proxy._vcn.join(",") : proxy["name-cert-verify"];
|
|
7832
|
+
if (Array.isArray(proxy._vcn) || certNames) {
|
|
7833
|
+
vcn = `&vcn=${encodeURIComponent(certNames)}`;
|
|
7834
|
+
}
|
|
7847
7835
|
let ech = "";
|
|
7848
7836
|
const echConfigList = buildXrayEchConfigListFromMihomo(
|
|
7849
7837
|
proxy["ech-opts"],
|
|
@@ -7995,7 +7983,7 @@ function vless2(proxy) {
|
|
|
7995
7983
|
}
|
|
7996
7984
|
return `vless://${proxy.uuid}@${proxy.server}:${proxy.port}?security=${encodeURIComponent(
|
|
7997
7985
|
security
|
|
7998
|
-
)}${vlessTransport}${packetEncoding}${alpn}${allowInsecure}${pcs}${ech}${h2}${sni}${fp}${flow}${sid}${spx}${pbk}${mode}${extra}${pqv}${encryption}#${encodeURIComponent(
|
|
7986
|
+
)}${vlessTransport}${packetEncoding}${alpn}${allowInsecure}${pcs}${vcn}${ech}${h2}${sni}${fp}${flow}${sid}${spx}${pbk}${mode}${extra}${pqv}${encryption}#${encodeURIComponent(
|
|
7999
7987
|
proxy.name
|
|
8000
7988
|
)}`;
|
|
8001
7989
|
}
|
|
@@ -8315,6 +8303,11 @@ function URI_Producer() {
|
|
|
8315
8303
|
proxy["tls-fingerprint"]
|
|
8316
8304
|
)}`;
|
|
8317
8305
|
}
|
|
8306
|
+
let trojanVcn = "";
|
|
8307
|
+
const trojanCertNames = Array.isArray(proxy._vcn) ? proxy._vcn.join(",") : proxy["name-cert-verify"];
|
|
8308
|
+
if (Array.isArray(proxy._vcn) || trojanCertNames) {
|
|
8309
|
+
trojanVcn = `&vcn=${encodeURIComponent(trojanCertNames)}`;
|
|
8310
|
+
}
|
|
8318
8311
|
let trojanAlpn = "";
|
|
8319
8312
|
if (proxy.alpn) {
|
|
8320
8313
|
trojanAlpn = `&alpn=${encodeURIComponent(
|
|
@@ -8351,7 +8344,7 @@ function URI_Producer() {
|
|
|
8351
8344
|
trojanMode = `&mode=${encodeURIComponent(proxy._mode)}`;
|
|
8352
8345
|
}
|
|
8353
8346
|
}
|
|
8354
|
-
result = `trojan://${proxy.password}@${proxy.server}:${proxy.port}?sni=${encodeURIComponent(proxy.sni || proxy.server)}${proxy["skip-cert-verify"] ? "&allowInsecure=1" : ""}${trojanTransport}${trojanAlpn}${trojanFp}${trojanPcs}${trojanSecurity}${trojanSid}${trojanPbk}${trojanSpx}${trojanMode}${trojanExtra}#${encodeURIComponent(
|
|
8347
|
+
result = `trojan://${proxy.password}@${proxy.server}:${proxy.port}?sni=${encodeURIComponent(proxy.sni || proxy.server)}${proxy["skip-cert-verify"] ? "&allowInsecure=1" : ""}${trojanTransport}${trojanAlpn}${trojanFp}${trojanPcs}${trojanVcn}${trojanSecurity}${trojanSid}${trojanPbk}${trojanSpx}${trojanMode}${trojanExtra}#${encodeURIComponent(
|
|
8355
8348
|
proxy.name
|
|
8356
8349
|
)}`;
|
|
8357
8350
|
break;
|
|
@@ -8398,6 +8391,14 @@ function URI_Producer() {
|
|
|
8398
8391
|
if (proxy.tfo) {
|
|
8399
8392
|
hysteria2params.push(`fastopen=1`);
|
|
8400
8393
|
}
|
|
8394
|
+
const hysteria2Ech = buildXrayEchConfigListFromMihomo(
|
|
8395
|
+
proxy["ech-opts"]
|
|
8396
|
+
);
|
|
8397
|
+
if (hysteria2Ech) {
|
|
8398
|
+
hysteria2params.push(
|
|
8399
|
+
`ech=${encodeURIComponent(hysteria2Ech)}`
|
|
8400
|
+
);
|
|
8401
|
+
}
|
|
8401
8402
|
result = `hysteria2://${encodeURIComponent(proxy.password)}@${proxy.server}:${proxy.port}?${hysteria2params.join(
|
|
8402
8403
|
"&"
|
|
8403
8404
|
)}#${encodeURIComponent(proxy.name)}`;
|
|
@@ -8767,8 +8768,10 @@ function shadowsocks3(proxy) {
|
|
|
8767
8768
|
}
|
|
8768
8769
|
} else if (proxy.plugin === "v2ray-plugin" && proxy["plugin-opts"].mode === "websocket") {
|
|
8769
8770
|
const opts = proxy["plugin-opts"];
|
|
8770
|
-
if (opts.tls)
|
|
8771
|
-
|
|
8771
|
+
if (opts.tls)
|
|
8772
|
+
append(`,obfs=wss`);
|
|
8773
|
+
else
|
|
8774
|
+
append(`,obfs=ws`);
|
|
8772
8775
|
} else {
|
|
8773
8776
|
throw new Error(`plugin is not supported`);
|
|
8774
8777
|
}
|
|
@@ -8856,8 +8859,10 @@ function trojan3(proxy) {
|
|
|
8856
8859
|
append(`,password=${proxy.password}`);
|
|
8857
8860
|
if (isPresent2(proxy, "network")) {
|
|
8858
8861
|
if (proxy.network === "ws") {
|
|
8859
|
-
if (needTls(proxy))
|
|
8860
|
-
|
|
8862
|
+
if (needTls(proxy))
|
|
8863
|
+
append(`,obfs=wss`);
|
|
8864
|
+
else
|
|
8865
|
+
append(`,obfs=ws`);
|
|
8861
8866
|
appendIfPresent(
|
|
8862
8867
|
`,obfs-uri=${proxy["ws-opts"]?.path}`,
|
|
8863
8868
|
"ws-opts.path"
|
|
@@ -8919,12 +8924,15 @@ function vmess3(proxy) {
|
|
|
8919
8924
|
}
|
|
8920
8925
|
if (isPresent2(proxy, "network")) {
|
|
8921
8926
|
if (proxy.network === "ws") {
|
|
8922
|
-
if (proxy.tls)
|
|
8923
|
-
|
|
8927
|
+
if (proxy.tls)
|
|
8928
|
+
append(`,obfs=wss`);
|
|
8929
|
+
else
|
|
8930
|
+
append(`,obfs=ws`);
|
|
8924
8931
|
} else if (proxy.network === "http") {
|
|
8925
8932
|
append(`,obfs=${getQxHttpObfs(proxy)}`);
|
|
8926
8933
|
} else if (["tcp"].includes(proxy.network)) {
|
|
8927
|
-
if (proxy.tls)
|
|
8934
|
+
if (proxy.tls)
|
|
8935
|
+
append(`,obfs=over-tls`);
|
|
8928
8936
|
} else if (!["tcp"].includes(proxy.network)) {
|
|
8929
8937
|
throw new Error(`network ${proxy.network} is unsupported`);
|
|
8930
8938
|
}
|
|
@@ -8939,7 +8947,8 @@ function vmess3(proxy) {
|
|
|
8939
8947
|
`${proxy.network}-opts.headers.Host`
|
|
8940
8948
|
);
|
|
8941
8949
|
} else {
|
|
8942
|
-
if (proxy.tls)
|
|
8950
|
+
if (proxy.tls)
|
|
8951
|
+
append(`,obfs=over-tls`);
|
|
8943
8952
|
}
|
|
8944
8953
|
if (needTls(proxy)) {
|
|
8945
8954
|
appendIfPresent(
|
|
@@ -8994,12 +9003,15 @@ function vless3(proxy) {
|
|
|
8994
9003
|
}
|
|
8995
9004
|
if (isPresent2(proxy, "network")) {
|
|
8996
9005
|
if (proxy.network === "ws") {
|
|
8997
|
-
if (proxy.tls)
|
|
8998
|
-
|
|
9006
|
+
if (proxy.tls)
|
|
9007
|
+
append(`,obfs=wss`);
|
|
9008
|
+
else
|
|
9009
|
+
append(`,obfs=ws`);
|
|
8999
9010
|
} else if (proxy.network === "http") {
|
|
9000
9011
|
append(`,obfs=${getQxHttpObfs(proxy)}`);
|
|
9001
9012
|
} else if (["tcp"].includes(proxy.network)) {
|
|
9002
|
-
if (proxy.tls)
|
|
9013
|
+
if (proxy.tls)
|
|
9014
|
+
append(`,obfs=over-tls`);
|
|
9003
9015
|
} else if (!["tcp"].includes(proxy.network)) {
|
|
9004
9016
|
throw new Error(`network ${proxy.network} is unsupported`);
|
|
9005
9017
|
}
|
|
@@ -9014,7 +9026,8 @@ function vless3(proxy) {
|
|
|
9014
9026
|
`${proxy.network}-opts.headers.Host`
|
|
9015
9027
|
);
|
|
9016
9028
|
} else {
|
|
9017
|
-
if (proxy.tls)
|
|
9029
|
+
if (proxy.tls)
|
|
9030
|
+
append(`,obfs=over-tls`);
|
|
9018
9031
|
}
|
|
9019
9032
|
if (needTls(proxy)) {
|
|
9020
9033
|
appendIfPresent(
|
|
@@ -9192,7 +9205,8 @@ function Shadowrocket_Producer() {
|
|
|
9192
9205
|
const type = "ALL";
|
|
9193
9206
|
const produce2 = (proxies, type2, opts = {}) => {
|
|
9194
9207
|
const list = proxies.filter((proxy) => {
|
|
9195
|
-
if (opts["include-unsupported-proxy"])
|
|
9208
|
+
if (opts["include-unsupported-proxy"])
|
|
9209
|
+
return true;
|
|
9196
9210
|
if (!supportsShadowsocksV2rayPluginMode(proxy, [
|
|
9197
9211
|
"websocket",
|
|
9198
9212
|
"quic",
|
|
@@ -9213,7 +9227,8 @@ function Shadowrocket_Producer() {
|
|
|
9213
9227
|
"sudoku",
|
|
9214
9228
|
"naive",
|
|
9215
9229
|
"openvpn",
|
|
9216
|
-
"gost-relay"
|
|
9230
|
+
"gost-relay",
|
|
9231
|
+
"shadowquic"
|
|
9217
9232
|
].includes(proxy.type)) {
|
|
9218
9233
|
return false;
|
|
9219
9234
|
} else if (["xhttp"].includes(proxy.network)) {
|
|
@@ -9298,6 +9313,9 @@ function Shadowrocket_Producer() {
|
|
|
9298
9313
|
proxy.servername = proxy.sni;
|
|
9299
9314
|
}
|
|
9300
9315
|
}
|
|
9316
|
+
} else if (["anytls"].includes(proxy.type) && proxy.reuse != null && !proxy.reuse) {
|
|
9317
|
+
proxy["disable-reuse"] = true;
|
|
9318
|
+
delete proxy.reuse;
|
|
9301
9319
|
}
|
|
9302
9320
|
if (["vmess", "vless"].includes(proxy.type) && proxy.network === "http") {
|
|
9303
9321
|
let httpPath = proxy["http-opts"]?.path;
|
|
@@ -9681,17 +9699,27 @@ var ipVersionParser = (proxy, parsedProxy) => {
|
|
|
9681
9699
|
}
|
|
9682
9700
|
};
|
|
9683
9701
|
var domainResolverParser = (proxy, parsedProxy) => {
|
|
9684
|
-
if (proxy._domain_resolver) {
|
|
9702
|
+
if (!proxy._domain_resolver) {
|
|
9703
|
+
return;
|
|
9704
|
+
}
|
|
9705
|
+
if (typeof proxy._domain_resolver === "string") {
|
|
9706
|
+
parsedProxy.domain_resolver = {
|
|
9707
|
+
...parsedProxy.domain_resolver ?? {},
|
|
9708
|
+
server: proxy._domain_resolver
|
|
9709
|
+
};
|
|
9710
|
+
} else {
|
|
9685
9711
|
parsedProxy.domain_resolver = {
|
|
9686
|
-
...parsedProxy.domain_resolver,
|
|
9712
|
+
...parsedProxy.domain_resolver ?? {},
|
|
9687
9713
|
...proxy._domain_resolver
|
|
9688
9714
|
};
|
|
9689
9715
|
}
|
|
9690
9716
|
};
|
|
9691
9717
|
var hasControlHTTPClient = (proxy) => {
|
|
9692
9718
|
const value = proxy["control-http-client"];
|
|
9693
|
-
if (value === void 0 || value === null)
|
|
9694
|
-
|
|
9719
|
+
if (value === void 0 || value === null)
|
|
9720
|
+
return false;
|
|
9721
|
+
if (typeof value === "string")
|
|
9722
|
+
return value.trim() !== "";
|
|
9695
9723
|
if (isPlainObject(value)) {
|
|
9696
9724
|
return Object.values(value).some(
|
|
9697
9725
|
(item) => item !== void 0 && item !== null && item !== ""
|
|
@@ -9713,13 +9741,18 @@ var networkParser = (proxy, parsedProxy) => {
|
|
|
9713
9741
|
};
|
|
9714
9742
|
var tfoParser = (proxy, parsedProxy) => {
|
|
9715
9743
|
parsedProxy.tcp_fast_open = false;
|
|
9716
|
-
if (proxy.tfo)
|
|
9717
|
-
|
|
9718
|
-
if (proxy
|
|
9719
|
-
|
|
9744
|
+
if (proxy.tfo)
|
|
9745
|
+
parsedProxy.tcp_fast_open = true;
|
|
9746
|
+
if (proxy.tcp_fast_open)
|
|
9747
|
+
parsedProxy.tcp_fast_open = true;
|
|
9748
|
+
if (proxy["tcp-fast-open"])
|
|
9749
|
+
parsedProxy.tcp_fast_open = true;
|
|
9750
|
+
if (!parsedProxy.tcp_fast_open)
|
|
9751
|
+
delete parsedProxy.tcp_fast_open;
|
|
9720
9752
|
};
|
|
9721
9753
|
var smuxParser = (smux, proxy) => {
|
|
9722
|
-
if (!smux || !smux.enabled)
|
|
9754
|
+
if (!smux || !smux.enabled)
|
|
9755
|
+
return;
|
|
9723
9756
|
proxy.multiplex = { enabled: true };
|
|
9724
9757
|
proxy.multiplex.protocol = smux.protocol;
|
|
9725
9758
|
if (smux["max-connections"])
|
|
@@ -9731,7 +9764,8 @@ var smuxParser = (smux, proxy) => {
|
|
|
9731
9764
|
proxy.multiplex.max_streams = parseInt(`${smux["max-streams"]}`, 10);
|
|
9732
9765
|
if (smux["min-streams"])
|
|
9733
9766
|
proxy.multiplex.min_streams = parseInt(`${smux["min-streams"]}`, 10);
|
|
9734
|
-
if (smux.padding)
|
|
9767
|
+
if (smux.padding)
|
|
9768
|
+
proxy.multiplex.padding = true;
|
|
9735
9769
|
if (smux["brutal-opts"]?.up || smux["brutal-opts"]?.down) {
|
|
9736
9770
|
proxy.multiplex.brutal = {
|
|
9737
9771
|
enabled: true
|
|
@@ -9759,20 +9793,25 @@ var wsParser = (proxy, parsedProxy) => {
|
|
|
9759
9793
|
} = proxy["ws-opts"];
|
|
9760
9794
|
transport.early_data_header_name = early_data_header_name;
|
|
9761
9795
|
transport.max_early_data = max_early_data ? parseInt(max_early_data, 10) : void 0;
|
|
9762
|
-
if (wsPath !== "")
|
|
9796
|
+
if (wsPath !== "")
|
|
9797
|
+
transport.path = `${wsPath}`;
|
|
9763
9798
|
if (Object.keys(wsHeaders).length > 0) {
|
|
9764
9799
|
const headers = {};
|
|
9765
9800
|
for (const key of Object.keys(wsHeaders)) {
|
|
9766
9801
|
let value = wsHeaders[key];
|
|
9767
|
-
if (value === "")
|
|
9768
|
-
|
|
9769
|
-
if (value
|
|
9802
|
+
if (value === "")
|
|
9803
|
+
continue;
|
|
9804
|
+
if (!Array.isArray(value))
|
|
9805
|
+
value = [`${value}`];
|
|
9806
|
+
if (value.length > 0)
|
|
9807
|
+
headers[key] = value;
|
|
9770
9808
|
}
|
|
9771
9809
|
const { Host: wsHost } = headers;
|
|
9772
9810
|
if (wsHost.length === 1)
|
|
9773
9811
|
for (const item of `Host:${wsHost[0]}`.split("\n")) {
|
|
9774
9812
|
const [key, value] = item.split(":");
|
|
9775
|
-
if (value.trim() === "")
|
|
9813
|
+
if (value.trim() === "")
|
|
9814
|
+
continue;
|
|
9776
9815
|
headers[key.trim()] = value.trim().split(",");
|
|
9777
9816
|
}
|
|
9778
9817
|
transport.headers = headers;
|
|
@@ -9782,15 +9821,19 @@ var wsParser = (proxy, parsedProxy) => {
|
|
|
9782
9821
|
const headers = {};
|
|
9783
9822
|
for (const key of Object.keys(proxy["ws-headers"])) {
|
|
9784
9823
|
let value = proxy["ws-headers"][key];
|
|
9785
|
-
if (value === "")
|
|
9786
|
-
|
|
9787
|
-
if (value
|
|
9824
|
+
if (value === "")
|
|
9825
|
+
continue;
|
|
9826
|
+
if (!Array.isArray(value))
|
|
9827
|
+
value = [`${value}`];
|
|
9828
|
+
if (value.length > 0)
|
|
9829
|
+
headers[key] = value;
|
|
9788
9830
|
}
|
|
9789
9831
|
const { Host: wsHost } = headers;
|
|
9790
9832
|
if (wsHost.length === 1)
|
|
9791
9833
|
for (const item of `Host:${wsHost[0]}`.split("\n")) {
|
|
9792
9834
|
const [key, value] = item.split(":");
|
|
9793
|
-
if (value.trim() === "")
|
|
9835
|
+
if (value.trim() === "")
|
|
9836
|
+
continue;
|
|
9794
9837
|
headers[key.trim()] = value.trim().split(",");
|
|
9795
9838
|
}
|
|
9796
9839
|
for (const key of Object.keys(headers))
|
|
@@ -9814,13 +9857,15 @@ var wsParser = (proxy, parsedProxy) => {
|
|
|
9814
9857
|
transport.host = transport.headers.Host[0];
|
|
9815
9858
|
delete transport.headers.Host;
|
|
9816
9859
|
}
|
|
9817
|
-
if (transport.max_early_data)
|
|
9860
|
+
if (transport.max_early_data)
|
|
9861
|
+
delete transport.max_early_data;
|
|
9818
9862
|
if (transport.early_data_header_name)
|
|
9819
9863
|
delete transport.early_data_header_name;
|
|
9820
9864
|
}
|
|
9821
9865
|
for (const key of Object.keys(transport.headers)) {
|
|
9822
9866
|
const value = transport.headers[key];
|
|
9823
|
-
if (value.length === 1)
|
|
9867
|
+
if (value.length === 1)
|
|
9868
|
+
transport.headers[key] = value[0];
|
|
9824
9869
|
}
|
|
9825
9870
|
parsedProxy.transport = transport;
|
|
9826
9871
|
};
|
|
@@ -9832,43 +9877,52 @@ var h1Parser = (proxy, parsedProxy) => {
|
|
|
9832
9877
|
path: h1Path = "",
|
|
9833
9878
|
headers: h1Headers = {}
|
|
9834
9879
|
} = proxy["http-opts"];
|
|
9835
|
-
if (method !== "")
|
|
9880
|
+
if (method !== "")
|
|
9881
|
+
transport.method = method;
|
|
9836
9882
|
if (Array.isArray(h1Path)) {
|
|
9837
9883
|
transport.path = `${h1Path[0]}`;
|
|
9838
|
-
} else if (h1Path !== "")
|
|
9884
|
+
} else if (h1Path !== "")
|
|
9885
|
+
transport.path = `${h1Path}`;
|
|
9839
9886
|
for (const key of Object.keys(h1Headers)) {
|
|
9840
9887
|
let value = h1Headers[key];
|
|
9841
|
-
if (value === "")
|
|
9888
|
+
if (value === "")
|
|
9889
|
+
continue;
|
|
9842
9890
|
if (key.toLowerCase() === "host") {
|
|
9843
9891
|
let host = value;
|
|
9844
9892
|
if (!Array.isArray(host))
|
|
9845
9893
|
host = `${host}`.split(",").map((i) => i.trim());
|
|
9846
|
-
if (host.length > 0)
|
|
9894
|
+
if (host.length > 0)
|
|
9895
|
+
transport.host = host;
|
|
9847
9896
|
continue;
|
|
9848
9897
|
}
|
|
9849
9898
|
if (!Array.isArray(value))
|
|
9850
9899
|
value = `${value}`.split(",").map((i) => i.trim());
|
|
9851
|
-
if (value.length > 0)
|
|
9900
|
+
if (value.length > 0)
|
|
9901
|
+
transport.headers[key] = value;
|
|
9852
9902
|
}
|
|
9853
9903
|
}
|
|
9854
9904
|
if (proxy["http-host"] && proxy["http-host"] !== "") {
|
|
9855
9905
|
let host = proxy["http-host"];
|
|
9856
9906
|
if (!Array.isArray(host))
|
|
9857
9907
|
host = `${host}`.split(",").map((i) => i.trim());
|
|
9858
|
-
if (host.length > 0)
|
|
9908
|
+
if (host.length > 0)
|
|
9909
|
+
transport.host = host;
|
|
9859
9910
|
}
|
|
9860
9911
|
if (proxy["http-path"] && proxy["http-path"] !== "") {
|
|
9861
9912
|
const path = proxy["http-path"];
|
|
9862
9913
|
if (Array.isArray(path)) {
|
|
9863
9914
|
transport.path = `${path[0]}`;
|
|
9864
|
-
} else if (path !== "")
|
|
9915
|
+
} else if (path !== "")
|
|
9916
|
+
transport.path = `${path}`;
|
|
9865
9917
|
}
|
|
9866
9918
|
if (parsedProxy.tls.insecure)
|
|
9867
9919
|
parsedProxy.tls.server_name = transport.host[0];
|
|
9868
|
-
if (transport.host?.length === 1)
|
|
9920
|
+
if (transport.host?.length === 1)
|
|
9921
|
+
transport.host = transport.host[0];
|
|
9869
9922
|
for (const key of Object.keys(transport.headers)) {
|
|
9870
9923
|
const value = transport.headers[key];
|
|
9871
|
-
if (value.length === 1)
|
|
9924
|
+
if (value.length === 1)
|
|
9925
|
+
transport.headers[key] = value[0];
|
|
9872
9926
|
}
|
|
9873
9927
|
parsedProxy.transport = transport;
|
|
9874
9928
|
};
|
|
@@ -9876,25 +9930,29 @@ var h2Parser = (proxy, parsedProxy) => {
|
|
|
9876
9930
|
const transport = { type: "http" };
|
|
9877
9931
|
if (proxy["h2-opts"]) {
|
|
9878
9932
|
let { host = "", path = "" } = proxy["h2-opts"];
|
|
9879
|
-
if (path !== "")
|
|
9933
|
+
if (path !== "")
|
|
9934
|
+
transport.path = `${path}`;
|
|
9880
9935
|
if (host !== "") {
|
|
9881
9936
|
if (!Array.isArray(host))
|
|
9882
9937
|
host = `${host}`.split(",").map((i) => i.trim());
|
|
9883
|
-
if (host.length > 0)
|
|
9938
|
+
if (host.length > 0)
|
|
9939
|
+
transport.host = host;
|
|
9884
9940
|
}
|
|
9885
9941
|
}
|
|
9886
9942
|
if (proxy["h2-host"] && proxy["h2-host"] !== "") {
|
|
9887
9943
|
let host = proxy["h2-host"];
|
|
9888
9944
|
if (!Array.isArray(host))
|
|
9889
9945
|
host = `${host}`.split(",").map((i) => i.trim());
|
|
9890
|
-
if (host.length > 0)
|
|
9946
|
+
if (host.length > 0)
|
|
9947
|
+
transport.host = host;
|
|
9891
9948
|
}
|
|
9892
9949
|
if (proxy["h2-path"] && proxy["h2-path"] !== "")
|
|
9893
9950
|
transport.path = `${proxy["h2-path"]}`;
|
|
9894
9951
|
parsedProxy.tls.enabled = true;
|
|
9895
9952
|
if (parsedProxy.tls.insecure)
|
|
9896
9953
|
parsedProxy.tls.server_name = transport.host[0];
|
|
9897
|
-
if (transport.host.length === 1)
|
|
9954
|
+
if (transport.host.length === 1)
|
|
9955
|
+
transport.host = transport.host[0];
|
|
9898
9956
|
parsedProxy.transport = transport;
|
|
9899
9957
|
};
|
|
9900
9958
|
var grpcParser = (proxy, parsedProxy) => {
|
|
@@ -9911,13 +9969,16 @@ var normalizePemLines = (value, label) => {
|
|
|
9911
9969
|
const lines = [];
|
|
9912
9970
|
for (const item of items) {
|
|
9913
9971
|
const normalized = `${item}`.trim().replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");
|
|
9914
|
-
if (normalized === "")
|
|
9972
|
+
if (normalized === "")
|
|
9973
|
+
continue;
|
|
9915
9974
|
for (const line of normalized.split(/\r?\n/)) {
|
|
9916
9975
|
const trimmed = line.trim();
|
|
9917
|
-
if (trimmed !== "")
|
|
9976
|
+
if (trimmed !== "")
|
|
9977
|
+
lines.push(trimmed);
|
|
9918
9978
|
}
|
|
9919
9979
|
}
|
|
9920
|
-
if (lines.length === 0)
|
|
9980
|
+
if (lines.length === 0)
|
|
9981
|
+
return void 0;
|
|
9921
9982
|
if (lines.some((line) => /^-----BEGIN [A-Za-z0-9 -]+-----$/.test(line))) {
|
|
9922
9983
|
return lines;
|
|
9923
9984
|
}
|
|
@@ -9937,24 +9998,34 @@ var singBoxUtlsFingerprints = [
|
|
|
9937
9998
|
];
|
|
9938
9999
|
var getSingBoxUtlsFingerprint = (value) => {
|
|
9939
10000
|
const fingerprint = `${value || ""}`.trim().toLowerCase();
|
|
9940
|
-
if (singBoxUtlsFingerprints.includes(fingerprint))
|
|
10001
|
+
if (singBoxUtlsFingerprints.includes(fingerprint))
|
|
10002
|
+
return fingerprint;
|
|
9941
10003
|
};
|
|
9942
10004
|
var tlsParser = (proxy, parsedProxy) => {
|
|
9943
|
-
if (proxy.tls)
|
|
10005
|
+
if (proxy.tls)
|
|
10006
|
+
parsedProxy.tls.enabled = true;
|
|
9944
10007
|
if (proxy.servername && proxy.servername !== "")
|
|
9945
10008
|
parsedProxy.tls.server_name = proxy.servername;
|
|
9946
10009
|
if (proxy.peer && proxy.peer !== "")
|
|
9947
10010
|
parsedProxy.tls.server_name = proxy.peer;
|
|
9948
|
-
if (proxy.sni && proxy.sni !== "")
|
|
9949
|
-
|
|
9950
|
-
if (proxy
|
|
9951
|
-
|
|
10011
|
+
if (proxy.sni && proxy.sni !== "")
|
|
10012
|
+
parsedProxy.tls.server_name = proxy.sni;
|
|
10013
|
+
if (proxy["skip-cert-verify"])
|
|
10014
|
+
parsedProxy.tls.insecure = true;
|
|
10015
|
+
if (proxy.insecure)
|
|
10016
|
+
parsedProxy.tls.insecure = true;
|
|
10017
|
+
if (proxy["disable-sni"])
|
|
10018
|
+
parsedProxy.tls.disable_sni = true;
|
|
9952
10019
|
if (typeof proxy.alpn === "string") {
|
|
9953
10020
|
parsedProxy.tls.alpn = [proxy.alpn];
|
|
9954
|
-
} else if (Array.isArray(proxy.alpn))
|
|
9955
|
-
|
|
9956
|
-
if (proxy.
|
|
9957
|
-
|
|
10021
|
+
} else if (Array.isArray(proxy.alpn))
|
|
10022
|
+
parsedProxy.tls.alpn = proxy.alpn;
|
|
10023
|
+
if (proxy.ca)
|
|
10024
|
+
parsedProxy.tls.certificate_path = `${proxy.ca}`;
|
|
10025
|
+
if (proxy.ca_str)
|
|
10026
|
+
parsedProxy.tls.certificate = [proxy.ca_str];
|
|
10027
|
+
if (proxy["ca-str"])
|
|
10028
|
+
parsedProxy.tls.certificate = [proxy["ca-str"]];
|
|
9958
10029
|
if (proxy["reality-opts"]) {
|
|
9959
10030
|
parsedProxy.tls.reality = { enabled: true };
|
|
9960
10031
|
if (proxy["reality-opts"]["public-key"])
|
|
@@ -9982,7 +10053,8 @@ var tlsParser = (proxy, parsedProxy) => {
|
|
|
9982
10053
|
const echOptsConfig = proxy["ech-opts"].config;
|
|
9983
10054
|
if (Array.isArray(echOptsConfig) || typeof echOptsConfig === "string") {
|
|
9984
10055
|
const config = normalizePemLines(echOptsConfig, "ECH CONFIGS");
|
|
9985
|
-
if (config)
|
|
10056
|
+
if (config)
|
|
10057
|
+
parsedProxy.tls.ech.config = config;
|
|
9986
10058
|
}
|
|
9987
10059
|
parsedProxy.tls.ech.query_server_name = proxy["ech-opts"]["query-server-name"];
|
|
9988
10060
|
parsedProxy.tls.ech.config_path = proxy["ech-opts"]["config-path"];
|
|
@@ -9993,7 +10065,8 @@ var tlsParser = (proxy, parsedProxy) => {
|
|
|
9993
10065
|
if (proxy._curve_preferences && Array.isArray(proxy._curve_preferences)) {
|
|
9994
10066
|
parsedProxy.tls.curve_preferences = proxy._curve_preferences;
|
|
9995
10067
|
}
|
|
9996
|
-
if (proxy["_fragment"])
|
|
10068
|
+
if (proxy["_fragment"])
|
|
10069
|
+
parsedProxy.tls.fragment = !!proxy["_fragment"];
|
|
9997
10070
|
if (proxy["_fragment_fallback_delay"])
|
|
9998
10071
|
parsedProxy.tls.fragment_fallback_delay = proxy["_fragment_fallback_delay"];
|
|
9999
10072
|
if (proxy["_record_fragment"])
|
|
@@ -10008,10 +10081,12 @@ var tlsParser = (proxy, parsedProxy) => {
|
|
|
10008
10081
|
parsedProxy.tls.client_certificate = proxy["_client_certificate"];
|
|
10009
10082
|
if (proxy["_client_certificate_path"])
|
|
10010
10083
|
parsedProxy.tls.client_certificate_path = proxy["_client_certificate_path"];
|
|
10011
|
-
if (proxy["_client_key"])
|
|
10084
|
+
if (proxy["_client_key"])
|
|
10085
|
+
parsedProxy.tls.client_key = proxy["_client_key"];
|
|
10012
10086
|
if (proxy["_client_key_path"])
|
|
10013
10087
|
parsedProxy.tls.client_key_path = proxy["_client_key_path"];
|
|
10014
|
-
if (!parsedProxy.tls.enabled)
|
|
10088
|
+
if (!parsedProxy.tls.enabled)
|
|
10089
|
+
delete parsedProxy.tls;
|
|
10015
10090
|
};
|
|
10016
10091
|
var sshParser = (proxy = {}) => {
|
|
10017
10092
|
const parsedProxy = {
|
|
@@ -10022,9 +10097,12 @@ var sshParser = (proxy = {}) => {
|
|
|
10022
10097
|
};
|
|
10023
10098
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10024
10099
|
throw "invalid port";
|
|
10025
|
-
if (proxy.username)
|
|
10026
|
-
|
|
10027
|
-
if (proxy
|
|
10100
|
+
if (proxy.username)
|
|
10101
|
+
parsedProxy.user = proxy.username;
|
|
10102
|
+
if (proxy.password)
|
|
10103
|
+
parsedProxy.password = proxy.password;
|
|
10104
|
+
if (proxy["privateKey"])
|
|
10105
|
+
parsedProxy.private_key_path = proxy["privateKey"];
|
|
10028
10106
|
if (proxy["private-key"])
|
|
10029
10107
|
parsedProxy.private_key_path = proxy["private-key"];
|
|
10030
10108
|
if (proxy["private-key-passphrase"])
|
|
@@ -10035,10 +10113,12 @@ var sshParser = (proxy = {}) => {
|
|
|
10035
10113
|
proxy["server-fingerprint"].split(" ")[0]
|
|
10036
10114
|
];
|
|
10037
10115
|
}
|
|
10038
|
-
if (proxy["host-key"])
|
|
10116
|
+
if (proxy["host-key"])
|
|
10117
|
+
parsedProxy.host_key = proxy["host-key"];
|
|
10039
10118
|
if (proxy["host-key-algorithms"])
|
|
10040
10119
|
parsedProxy.host_key_algorithms = proxy["host-key-algorithms"];
|
|
10041
|
-
if (proxy["fast-open"])
|
|
10120
|
+
if (proxy["fast-open"])
|
|
10121
|
+
parsedProxy.udp_fragment = true;
|
|
10042
10122
|
tfoParser(proxy, parsedProxy);
|
|
10043
10123
|
detourParser(proxy, parsedProxy);
|
|
10044
10124
|
ipVersionParser(proxy, parsedProxy);
|
|
@@ -10055,8 +10135,10 @@ var httpParser = (proxy = {}) => {
|
|
|
10055
10135
|
};
|
|
10056
10136
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10057
10137
|
throw "invalid port";
|
|
10058
|
-
if (proxy.username)
|
|
10059
|
-
|
|
10138
|
+
if (proxy.username)
|
|
10139
|
+
parsedProxy.username = proxy.username;
|
|
10140
|
+
if (proxy.password)
|
|
10141
|
+
parsedProxy.password = proxy.password;
|
|
10060
10142
|
if (proxy.headers) {
|
|
10061
10143
|
parsedProxy.headers = {};
|
|
10062
10144
|
for (const k of Object.keys(proxy.headers)) {
|
|
@@ -10065,7 +10147,8 @@ var httpParser = (proxy = {}) => {
|
|
|
10065
10147
|
if (Object.keys(parsedProxy.headers).length === 0)
|
|
10066
10148
|
delete parsedProxy.headers;
|
|
10067
10149
|
}
|
|
10068
|
-
if (proxy["fast-open"])
|
|
10150
|
+
if (proxy["fast-open"])
|
|
10151
|
+
parsedProxy.udp_fragment = true;
|
|
10069
10152
|
tfoParser(proxy, parsedProxy);
|
|
10070
10153
|
detourParser(proxy, parsedProxy);
|
|
10071
10154
|
tlsParser(proxy, parsedProxy);
|
|
@@ -10083,16 +10166,20 @@ var socks5Parser = (proxy = {}) => {
|
|
|
10083
10166
|
};
|
|
10084
10167
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10085
10168
|
throw "invalid port";
|
|
10086
|
-
if (proxy.username)
|
|
10087
|
-
|
|
10088
|
-
if (proxy.
|
|
10169
|
+
if (proxy.username)
|
|
10170
|
+
parsedProxy.username = proxy.username;
|
|
10171
|
+
if (proxy.password)
|
|
10172
|
+
parsedProxy.password = proxy.password;
|
|
10173
|
+
if (proxy.uot)
|
|
10174
|
+
parsedProxy.udp_over_tcp = true;
|
|
10089
10175
|
if (proxy["udp-over-tcp"]) {
|
|
10090
10176
|
parsedProxy.udp_over_tcp = {
|
|
10091
10177
|
enabled: true,
|
|
10092
10178
|
version: !proxy["udp-over-tcp-version"] || proxy["udp-over-tcp-version"] === 1 ? 1 : 2
|
|
10093
10179
|
};
|
|
10094
10180
|
}
|
|
10095
|
-
if (proxy["fast-open"])
|
|
10181
|
+
if (proxy["fast-open"])
|
|
10182
|
+
parsedProxy.udp_fragment = true;
|
|
10096
10183
|
networkParser(proxy, parsedProxy);
|
|
10097
10184
|
tfoParser(proxy, parsedProxy);
|
|
10098
10185
|
detourParser(proxy, parsedProxy);
|
|
@@ -10109,7 +10196,8 @@ var shadowTLSParser = (proxy = {}) => {
|
|
|
10109
10196
|
password: proxy.password,
|
|
10110
10197
|
detour: getShadowTLSTag(proxy)
|
|
10111
10198
|
};
|
|
10112
|
-
if (proxy.uot)
|
|
10199
|
+
if (proxy.uot)
|
|
10200
|
+
ssPart.udp_over_tcp = true;
|
|
10113
10201
|
if (proxy["udp-over-tcp"]) {
|
|
10114
10202
|
ssPart.udp_over_tcp = {
|
|
10115
10203
|
enabled: true,
|
|
@@ -10143,11 +10231,13 @@ var normalizeALPN = (alpn) => {
|
|
|
10143
10231
|
if (typeof alpn === "string") {
|
|
10144
10232
|
return alpn.split(",").map((item) => item.trim()).filter((item) => item !== "");
|
|
10145
10233
|
}
|
|
10146
|
-
if (Array.isArray(alpn))
|
|
10234
|
+
if (Array.isArray(alpn))
|
|
10235
|
+
return alpn;
|
|
10147
10236
|
return void 0;
|
|
10148
10237
|
};
|
|
10149
10238
|
var shadowTLSOutboundParser = (proxy = {}, pluginOpts) => {
|
|
10150
|
-
if (!pluginOpts)
|
|
10239
|
+
if (!pluginOpts)
|
|
10240
|
+
throw new Error("shadow-tls plugin options are missing");
|
|
10151
10241
|
const fingerprint = getSingBoxUtlsFingerprint(proxy["client-fingerprint"]);
|
|
10152
10242
|
const stPart = {
|
|
10153
10243
|
tag: getShadowTLSTag(proxy),
|
|
@@ -10170,8 +10260,10 @@ var shadowTLSOutboundParser = (proxy = {}, pluginOpts) => {
|
|
|
10170
10260
|
if (stPart.server_port < 0 || stPart.server_port > 65535)
|
|
10171
10261
|
throw "\u7AEF\u53E3\u503C\u975E\u6CD5";
|
|
10172
10262
|
const alpn = normalizeALPN(pluginOpts.alpn) ?? normalizeALPN(proxy.alpn);
|
|
10173
|
-
if (alpn)
|
|
10174
|
-
|
|
10263
|
+
if (alpn)
|
|
10264
|
+
stPart.tls.alpn = alpn;
|
|
10265
|
+
if (proxy["fast-open"] === true)
|
|
10266
|
+
stPart.udp_fragment = true;
|
|
10175
10267
|
tfoParser(proxy, stPart);
|
|
10176
10268
|
detourParser(proxy, stPart);
|
|
10177
10269
|
ipVersionParser(proxy, stPart);
|
|
@@ -10189,14 +10281,16 @@ var ssParser = (proxy = {}) => {
|
|
|
10189
10281
|
};
|
|
10190
10282
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10191
10283
|
throw "invalid port";
|
|
10192
|
-
if (proxy.uot)
|
|
10284
|
+
if (proxy.uot)
|
|
10285
|
+
parsedProxy.udp_over_tcp = true;
|
|
10193
10286
|
if (proxy["udp-over-tcp"]) {
|
|
10194
10287
|
parsedProxy.udp_over_tcp = {
|
|
10195
10288
|
enabled: true,
|
|
10196
10289
|
version: !proxy["udp-over-tcp-version"] || proxy["udp-over-tcp-version"] === 1 ? 1 : 2
|
|
10197
10290
|
};
|
|
10198
10291
|
}
|
|
10199
|
-
if (proxy["fast-open"])
|
|
10292
|
+
if (proxy["fast-open"])
|
|
10293
|
+
parsedProxy.udp_fragment = true;
|
|
10200
10294
|
networkParser(proxy, parsedProxy);
|
|
10201
10295
|
tfoParser(proxy, parsedProxy);
|
|
10202
10296
|
detourParser(proxy, parsedProxy);
|
|
@@ -10226,12 +10320,15 @@ var ssParser = (proxy = {}) => {
|
|
|
10226
10320
|
}
|
|
10227
10321
|
if (proxy.plugin === "v2ray-plugin") {
|
|
10228
10322
|
parsedProxy.plugin = "v2ray-plugin";
|
|
10229
|
-
if (proxy["ws-host"])
|
|
10230
|
-
|
|
10323
|
+
if (proxy["ws-host"])
|
|
10324
|
+
proxy["plugin-opts"].host = proxy["ws-host"];
|
|
10325
|
+
if (proxy["ws-path"])
|
|
10326
|
+
proxy["plugin-opts"].path = proxy["ws-path"];
|
|
10231
10327
|
Object.keys(proxy["plugin-opts"]).forEach((k) => {
|
|
10232
10328
|
switch (k) {
|
|
10233
10329
|
case "tls":
|
|
10234
|
-
if (proxy["plugin-opts"].tls)
|
|
10330
|
+
if (proxy["plugin-opts"].tls)
|
|
10331
|
+
optArr.push("tls");
|
|
10235
10332
|
break;
|
|
10236
10333
|
case "host":
|
|
10237
10334
|
optArr.push(`host=${proxy["plugin-opts"].host}`);
|
|
@@ -10250,7 +10347,8 @@ var ssParser = (proxy = {}) => {
|
|
|
10250
10347
|
const mux = normalizePluginMuxValue(
|
|
10251
10348
|
proxy["plugin-opts"].mux
|
|
10252
10349
|
);
|
|
10253
|
-
if (mux)
|
|
10350
|
+
if (mux)
|
|
10351
|
+
parsedProxy.multiplex = { enabled: true };
|
|
10254
10352
|
optArr.push(`mux=${mux}`);
|
|
10255
10353
|
break;
|
|
10256
10354
|
}
|
|
@@ -10276,10 +10374,12 @@ var ssrParser = (proxy = {}) => {
|
|
|
10276
10374
|
};
|
|
10277
10375
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10278
10376
|
throw "invalid port";
|
|
10279
|
-
if (proxy["obfs-param"])
|
|
10377
|
+
if (proxy["obfs-param"])
|
|
10378
|
+
parsedProxy.obfs_param = proxy["obfs-param"];
|
|
10280
10379
|
if (proxy["protocol-param"] && proxy["protocol-param"] !== "")
|
|
10281
10380
|
parsedProxy.protocol_param = proxy["protocol-param"];
|
|
10282
|
-
if (proxy["fast-open"])
|
|
10381
|
+
if (proxy["fast-open"])
|
|
10382
|
+
parsedProxy.udp_fragment = true;
|
|
10283
10383
|
networkParser(proxy, parsedProxy);
|
|
10284
10384
|
tfoParser(proxy, parsedProxy);
|
|
10285
10385
|
detourParser(proxy, parsedProxy);
|
|
@@ -10289,19 +10389,23 @@ var ssrParser = (proxy = {}) => {
|
|
|
10289
10389
|
return parsedProxy;
|
|
10290
10390
|
};
|
|
10291
10391
|
var getSnellVersion = (version) => {
|
|
10292
|
-
if (version == null)
|
|
10392
|
+
if (version == null)
|
|
10393
|
+
return void 0;
|
|
10293
10394
|
const normalized = `${version}`.trim();
|
|
10294
|
-
if (!/^\d+$/.test(normalized))
|
|
10395
|
+
if (!/^\d+$/.test(normalized))
|
|
10396
|
+
return NaN;
|
|
10295
10397
|
return parseInt(normalized, 10);
|
|
10296
10398
|
};
|
|
10297
|
-
var snellParser = (proxy = {}) => {
|
|
10399
|
+
var snellParser = (proxy = {}, includeUnsupportedProxy = false) => {
|
|
10298
10400
|
const version = getSnellVersion(proxy.version);
|
|
10299
10401
|
const shadowTLSPluginOpts = getShadowTLSPluginOpts(proxy);
|
|
10300
|
-
|
|
10402
|
+
const supportedVersions = includeUnsupportedProxy ? [1, 2, 3, 4, 5, 6] : [4, 5, 6];
|
|
10403
|
+
if (version != null && (!supportedVersions.includes(version) || Number.isNaN(version))) {
|
|
10301
10404
|
throw new Error(
|
|
10302
10405
|
`Platform sing-box does not support snell version ${proxy.version}`
|
|
10303
10406
|
);
|
|
10304
10407
|
}
|
|
10408
|
+
const outputVersion = !includeUnsupportedProxy && version === 5 ? 4 : version;
|
|
10305
10409
|
const parsedProxy = {
|
|
10306
10410
|
tag: proxy.name,
|
|
10307
10411
|
type: "snell",
|
|
@@ -10311,11 +10415,19 @@ var snellParser = (proxy = {}) => {
|
|
|
10311
10415
|
};
|
|
10312
10416
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10313
10417
|
throw "invalid port";
|
|
10314
|
-
if (
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10418
|
+
if (outputVersion != null)
|
|
10419
|
+
parsedProxy.version = outputVersion;
|
|
10420
|
+
if (proxy._userkey)
|
|
10421
|
+
parsedProxy.userkey = proxy._userkey;
|
|
10422
|
+
if (outputVersion === 6) {
|
|
10423
|
+
if (proxy.mode)
|
|
10424
|
+
parsedProxy.mode = proxy.mode;
|
|
10425
|
+
} else {
|
|
10426
|
+
if (proxy["obfs-opts"]?.mode && proxy["obfs-opts"].mode !== "shadow-tls")
|
|
10427
|
+
parsedProxy.obfs_mode = proxy["obfs-opts"].mode;
|
|
10428
|
+
if (proxy["obfs-opts"]?.host && proxy["obfs-opts"]?.mode !== "shadow-tls")
|
|
10429
|
+
parsedProxy.obfs_host = proxy["obfs-opts"].host;
|
|
10430
|
+
}
|
|
10319
10431
|
if (proxy.reuse && (version == null || version >= 4))
|
|
10320
10432
|
parsedProxy.reuse = true;
|
|
10321
10433
|
networkParser(proxy, parsedProxy);
|
|
@@ -10324,7 +10436,8 @@ var snellParser = (proxy = {}) => {
|
|
|
10324
10436
|
delete parsedProxy.server;
|
|
10325
10437
|
delete parsedProxy.server_port;
|
|
10326
10438
|
} else {
|
|
10327
|
-
if (proxy["fast-open"])
|
|
10439
|
+
if (proxy["fast-open"])
|
|
10440
|
+
parsedProxy.udp_fragment = true;
|
|
10328
10441
|
tfoParser(proxy, parsedProxy);
|
|
10329
10442
|
detourParser(proxy, parsedProxy);
|
|
10330
10443
|
ipVersionParser(proxy, parsedProxy);
|
|
@@ -10376,11 +10489,16 @@ var vmessParser = (proxy = {}) => {
|
|
|
10376
10489
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10377
10490
|
throw "invalid port";
|
|
10378
10491
|
vmessProtocolOptionsParser(proxy, parsedProxy);
|
|
10379
|
-
if (proxy["fast-open"])
|
|
10380
|
-
|
|
10381
|
-
if (proxy.network === "
|
|
10382
|
-
|
|
10383
|
-
if (proxy.network === "
|
|
10492
|
+
if (proxy["fast-open"])
|
|
10493
|
+
parsedProxy.udp_fragment = true;
|
|
10494
|
+
if (proxy.network === "ws")
|
|
10495
|
+
wsParser(proxy, parsedProxy);
|
|
10496
|
+
if (proxy.network === "h2")
|
|
10497
|
+
h2Parser(proxy, parsedProxy);
|
|
10498
|
+
if (proxy.network === "http")
|
|
10499
|
+
h1Parser(proxy, parsedProxy);
|
|
10500
|
+
if (proxy.network === "grpc")
|
|
10501
|
+
grpcParser(proxy, parsedProxy);
|
|
10384
10502
|
networkParser(proxy, parsedProxy);
|
|
10385
10503
|
tfoParser(proxy, parsedProxy);
|
|
10386
10504
|
detourParser(proxy, parsedProxy);
|
|
@@ -10402,12 +10520,18 @@ var vlessParser = (proxy = {}) => {
|
|
|
10402
10520
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10403
10521
|
throw "invalid port";
|
|
10404
10522
|
vmessVlessPacketEncodingParser(proxy, parsedProxy);
|
|
10405
|
-
if (proxy["fast-open"])
|
|
10406
|
-
|
|
10407
|
-
if (proxy.
|
|
10408
|
-
|
|
10409
|
-
if (proxy.network === "
|
|
10410
|
-
|
|
10523
|
+
if (proxy["fast-open"])
|
|
10524
|
+
parsedProxy.udp_fragment = true;
|
|
10525
|
+
if (proxy.flow != null)
|
|
10526
|
+
parsedProxy.flow = proxy.flow;
|
|
10527
|
+
if (proxy.network === "ws")
|
|
10528
|
+
wsParser(proxy, parsedProxy);
|
|
10529
|
+
if (proxy.network === "h2")
|
|
10530
|
+
h2Parser(proxy, parsedProxy);
|
|
10531
|
+
if (proxy.network === "http")
|
|
10532
|
+
h1Parser(proxy, parsedProxy);
|
|
10533
|
+
if (proxy.network === "grpc")
|
|
10534
|
+
grpcParser(proxy, parsedProxy);
|
|
10411
10535
|
networkParser(proxy, parsedProxy);
|
|
10412
10536
|
tfoParser(proxy, parsedProxy);
|
|
10413
10537
|
detourParser(proxy, parsedProxy);
|
|
@@ -10428,9 +10552,12 @@ var trojanParser = (proxy = {}) => {
|
|
|
10428
10552
|
};
|
|
10429
10553
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10430
10554
|
throw "invalid port";
|
|
10431
|
-
if (proxy["fast-open"])
|
|
10432
|
-
|
|
10433
|
-
if (proxy.network === "
|
|
10555
|
+
if (proxy["fast-open"])
|
|
10556
|
+
parsedProxy.udp_fragment = true;
|
|
10557
|
+
if (proxy.network === "grpc")
|
|
10558
|
+
grpcParser(proxy, parsedProxy);
|
|
10559
|
+
if (proxy.network === "ws")
|
|
10560
|
+
wsParser(proxy, parsedProxy);
|
|
10434
10561
|
networkParser(proxy, parsedProxy);
|
|
10435
10562
|
tfoParser(proxy, parsedProxy);
|
|
10436
10563
|
detourParser(proxy, parsedProxy);
|
|
@@ -10450,9 +10577,12 @@ var naiveParser = (proxy = {}) => {
|
|
|
10450
10577
|
};
|
|
10451
10578
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10452
10579
|
throw "invalid port";
|
|
10453
|
-
if (proxy.username)
|
|
10454
|
-
|
|
10455
|
-
if (proxy.
|
|
10580
|
+
if (proxy.username)
|
|
10581
|
+
parsedProxy.username = proxy.username;
|
|
10582
|
+
if (proxy.password)
|
|
10583
|
+
parsedProxy.password = proxy.password;
|
|
10584
|
+
if (proxy.uot)
|
|
10585
|
+
parsedProxy.udp_over_tcp = true;
|
|
10456
10586
|
if (proxy["udp-over-tcp"]) {
|
|
10457
10587
|
parsedProxy.udp_over_tcp = {
|
|
10458
10588
|
enabled: true,
|
|
@@ -10467,10 +10597,12 @@ var naiveParser = (proxy = {}) => {
|
|
|
10467
10597
|
parsedProxy.insecure_concurrency = insecure_concurrency;
|
|
10468
10598
|
if (proxy["extra-headers"])
|
|
10469
10599
|
parsedProxy.extra_headers = proxy["extra-headers"];
|
|
10470
|
-
if (proxy.quic)
|
|
10600
|
+
if (proxy.quic)
|
|
10601
|
+
parsedProxy.quic = !!proxy.quic;
|
|
10471
10602
|
if (proxy["quic-congestion-control"])
|
|
10472
10603
|
parsedProxy.quic_congestion_control = proxy["quic-congestion-control"];
|
|
10473
|
-
if (proxy["fast-open"])
|
|
10604
|
+
if (proxy["fast-open"])
|
|
10605
|
+
parsedProxy.udp_fragment = true;
|
|
10474
10606
|
tfoParser(proxy, parsedProxy);
|
|
10475
10607
|
detourParser(proxy, parsedProxy);
|
|
10476
10608
|
tlsParser(proxy, parsedProxy);
|
|
@@ -10503,9 +10635,12 @@ var hysteriaParser = (proxy = {}) => {
|
|
|
10503
10635
|
const range = p.replace(/\s*-\s*/g, ":");
|
|
10504
10636
|
return range.includes(":") ? range : `${range}:${range}`;
|
|
10505
10637
|
});
|
|
10506
|
-
if (proxy.auth_str)
|
|
10507
|
-
|
|
10508
|
-
if (proxy["
|
|
10638
|
+
if (proxy.auth_str)
|
|
10639
|
+
parsedProxy.auth_str = `${proxy.auth_str}`;
|
|
10640
|
+
if (proxy["auth-str"])
|
|
10641
|
+
parsedProxy.auth_str = `${proxy["auth-str"]}`;
|
|
10642
|
+
if (proxy["fast-open"])
|
|
10643
|
+
parsedProxy.udp_fragment = true;
|
|
10509
10644
|
const reg = new RegExp("^[0-9]+[ ]*[KMGT]*[Bb]ps$");
|
|
10510
10645
|
if (reg.test(`${proxy.up}`) && !`${proxy.up}`.endsWith("Mbps")) {
|
|
10511
10646
|
parsedProxy.up = `${proxy.up}`;
|
|
@@ -10517,13 +10652,16 @@ var hysteriaParser = (proxy = {}) => {
|
|
|
10517
10652
|
} else {
|
|
10518
10653
|
parsedProxy.down_mbps = parseInt(`${proxy.down}`, 10);
|
|
10519
10654
|
}
|
|
10520
|
-
if (proxy.obfs)
|
|
10655
|
+
if (proxy.obfs)
|
|
10656
|
+
parsedProxy.obfs = proxy.obfs;
|
|
10521
10657
|
if (proxy.recv_window_conn)
|
|
10522
10658
|
parsedProxy.recv_window_conn = proxy.recv_window_conn;
|
|
10523
10659
|
if (proxy["recv-window-conn"])
|
|
10524
10660
|
parsedProxy.recv_window_conn = proxy["recv-window-conn"];
|
|
10525
|
-
if (proxy.recv_window)
|
|
10526
|
-
|
|
10661
|
+
if (proxy.recv_window)
|
|
10662
|
+
parsedProxy.recv_window = proxy.recv_window;
|
|
10663
|
+
if (proxy["recv-window"])
|
|
10664
|
+
parsedProxy.recv_window = proxy["recv-window"];
|
|
10527
10665
|
if (proxy.disable_mtu_discovery) {
|
|
10528
10666
|
if (typeof proxy.disable_mtu_discovery === "boolean") {
|
|
10529
10667
|
parsedProxy.disable_mtu_discovery = proxy.disable_mtu_discovery;
|
|
@@ -10560,8 +10698,10 @@ var hysteria2Parser = (proxy = {}) => {
|
|
|
10560
10698
|
const range = p.replace(/\s*-\s*/g, ":");
|
|
10561
10699
|
return range.includes(":") ? range : `${range}:${range}`;
|
|
10562
10700
|
});
|
|
10563
|
-
if (proxy.up)
|
|
10564
|
-
|
|
10701
|
+
if (proxy.up)
|
|
10702
|
+
parsedProxy.up_mbps = parseInt(`${proxy.up}`, 10);
|
|
10703
|
+
if (proxy.down)
|
|
10704
|
+
parsedProxy.down_mbps = parseInt(`${proxy.down}`, 10);
|
|
10565
10705
|
if (["salamander", "gecko"].includes(proxy.obfs))
|
|
10566
10706
|
parsedProxy.obfs.type = proxy.obfs;
|
|
10567
10707
|
if (proxy.obfs === "gecko") {
|
|
@@ -10585,14 +10725,17 @@ var hysteria2Parser = (proxy = {}) => {
|
|
|
10585
10725
|
`Invalid obfs packet size for proxy ${proxy.name}: min=${minRaw} max=${maxRaw}`
|
|
10586
10726
|
);
|
|
10587
10727
|
} else {
|
|
10588
|
-
if (hasMin)
|
|
10589
|
-
|
|
10728
|
+
if (hasMin)
|
|
10729
|
+
parsedProxy.obfs.min_packet_size = minPacketSize;
|
|
10730
|
+
if (hasMax)
|
|
10731
|
+
parsedProxy.obfs.max_packet_size = maxPacketSize;
|
|
10590
10732
|
}
|
|
10591
10733
|
}
|
|
10592
10734
|
}
|
|
10593
10735
|
if (proxy["obfs-password"])
|
|
10594
10736
|
parsedProxy.obfs.password = proxy["obfs-password"];
|
|
10595
|
-
if (!parsedProxy.obfs.type)
|
|
10737
|
+
if (!parsedProxy.obfs.type)
|
|
10738
|
+
delete parsedProxy.obfs;
|
|
10596
10739
|
networkParser(proxy, parsedProxy);
|
|
10597
10740
|
tlsParser(proxy, parsedProxy);
|
|
10598
10741
|
tfoParser(proxy, parsedProxy);
|
|
@@ -10614,13 +10757,16 @@ var tuic5Parser = (proxy = {}) => {
|
|
|
10614
10757
|
};
|
|
10615
10758
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10616
10759
|
throw "invalid port";
|
|
10617
|
-
if (proxy["fast-open"])
|
|
10760
|
+
if (proxy["fast-open"])
|
|
10761
|
+
parsedProxy.udp_fragment = true;
|
|
10618
10762
|
if (proxy["congestion-controller"] && proxy["congestion-controller"] !== "cubic")
|
|
10619
10763
|
parsedProxy.congestion_control = proxy["congestion-controller"];
|
|
10620
10764
|
if (proxy["udp-relay-mode"] && proxy["udp-relay-mode"] !== "native")
|
|
10621
10765
|
parsedProxy.udp_relay_mode = proxy["udp-relay-mode"];
|
|
10622
|
-
if (proxy["reduce-rtt"])
|
|
10623
|
-
|
|
10766
|
+
if (proxy["reduce-rtt"])
|
|
10767
|
+
parsedProxy.zero_rtt_handshake = true;
|
|
10768
|
+
if (proxy["udp-over-stream"])
|
|
10769
|
+
parsedProxy.udp_over_stream = true;
|
|
10624
10770
|
if (proxy["heartbeat-interval"])
|
|
10625
10771
|
parsedProxy.heartbeat = `${proxy["heartbeat-interval"]}ms`;
|
|
10626
10772
|
networkParser(proxy, parsedProxy);
|
|
@@ -10650,6 +10796,9 @@ var anytlsParser = (proxy = {}) => {
|
|
|
10650
10796
|
`${proxy["min-idle-session"]}`,
|
|
10651
10797
|
10
|
|
10652
10798
|
);
|
|
10799
|
+
if (proxy["disable-reuse"] != null) {
|
|
10800
|
+
parsedProxy.disable_reuse = !!proxy["disable-reuse"];
|
|
10801
|
+
}
|
|
10653
10802
|
detourParser(proxy, parsedProxy);
|
|
10654
10803
|
tlsParser(proxy, parsedProxy);
|
|
10655
10804
|
ipVersionParser(proxy, parsedProxy);
|
|
@@ -10726,11 +10875,13 @@ var wireguardParser = (proxy = {}) => {
|
|
|
10726
10875
|
};
|
|
10727
10876
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10728
10877
|
throw "invalid port";
|
|
10729
|
-
if (proxy["fast-open"])
|
|
10878
|
+
if (proxy["fast-open"])
|
|
10879
|
+
parsedProxy.udp_fragment = true;
|
|
10730
10880
|
if (typeof proxy.reserved === "string") {
|
|
10731
10881
|
parsedProxy.reserved = proxy.reserved;
|
|
10732
10882
|
} else if (Array.isArray(proxy.reserved)) {
|
|
10733
|
-
for (const r of proxy.reserved)
|
|
10883
|
+
for (const r of proxy.reserved)
|
|
10884
|
+
parsedProxy.reserved.push(r);
|
|
10734
10885
|
} else {
|
|
10735
10886
|
delete parsedProxy.reserved;
|
|
10736
10887
|
}
|
|
@@ -10764,7 +10915,8 @@ var wireguardParser = (proxy = {}) => {
|
|
|
10764
10915
|
if (typeof p.reserved === "string") {
|
|
10765
10916
|
peer.reserved.push(p.reserved);
|
|
10766
10917
|
} else if (Array.isArray(p.reserved)) {
|
|
10767
|
-
for (const r of p.reserved)
|
|
10918
|
+
for (const r of p.reserved)
|
|
10919
|
+
peer.reserved.push(r);
|
|
10768
10920
|
} else {
|
|
10769
10921
|
delete peer.reserved;
|
|
10770
10922
|
}
|
|
@@ -10852,24 +11004,24 @@ function singbox_Producer() {
|
|
|
10852
11004
|
);
|
|
10853
11005
|
}
|
|
10854
11006
|
break;
|
|
10855
|
-
case "snell":
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
10859
|
-
|
|
10860
|
-
|
|
10861
|
-
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
10869
|
-
`Platform sing-box does not support proxy type: ${proxy.type}`
|
|
11007
|
+
case "snell": {
|
|
11008
|
+
list.push(
|
|
11009
|
+
snellParser(
|
|
11010
|
+
proxy,
|
|
11011
|
+
opts["include-unsupported-proxy"]
|
|
11012
|
+
)
|
|
11013
|
+
);
|
|
11014
|
+
const shadowTLSPluginOpts = getShadowTLSPluginOpts(proxy);
|
|
11015
|
+
if (shadowTLSPluginOpts) {
|
|
11016
|
+
list.push(
|
|
11017
|
+
shadowTLSOutboundParser(
|
|
11018
|
+
proxy,
|
|
11019
|
+
shadowTLSPluginOpts
|
|
11020
|
+
)
|
|
10870
11021
|
);
|
|
10871
11022
|
}
|
|
10872
11023
|
break;
|
|
11024
|
+
}
|
|
10873
11025
|
case "vmess":
|
|
10874
11026
|
if (!proxy.network || ["tcp", "ws", "grpc", "h2", "http"].includes(
|
|
10875
11027
|
proxy.network
|
|
@@ -10945,7 +11097,8 @@ function singbox_Producer() {
|
|
|
10945
11097
|
app_default.error(e.message ?? e);
|
|
10946
11098
|
}
|
|
10947
11099
|
});
|
|
10948
|
-
if (type2 === "internal")
|
|
11100
|
+
if (type2 === "internal")
|
|
11101
|
+
return list;
|
|
10949
11102
|
const categorized = list.reduce(
|
|
10950
11103
|
(result, item) => {
|
|
10951
11104
|
if (["wireguard", "tailscale"].includes(item.type)) {
|
|
@@ -11022,11 +11175,6 @@ function Egern_Producer() {
|
|
|
11022
11175
|
return false;
|
|
11023
11176
|
} else if (proxy.type === "snell" && normalizeSnellVersion(proxy.version) === null) {
|
|
11024
11177
|
return false;
|
|
11025
|
-
} else if (proxy.type === "snell" && hasShadowTls(proxy)) {
|
|
11026
|
-
app_default.error(
|
|
11027
|
-
`Platform Egern does not support Snell shadow-tls proxy ${proxy.name}. Proxy has been filtered.`
|
|
11028
|
-
);
|
|
11029
|
-
return false;
|
|
11030
11178
|
} else if (["anytls"].includes(proxy.type) && proxy.network && !["tcp"].includes(proxy.network)) {
|
|
11031
11179
|
return false;
|
|
11032
11180
|
} else if (["ws"].includes(proxy.network) && proxy["ws-opts"]?.["v2ray-http-upgrade"]) {
|
|
@@ -11303,7 +11451,8 @@ function Egern_Producer() {
|
|
|
11303
11451
|
}
|
|
11304
11452
|
};
|
|
11305
11453
|
flow = proxy.flow;
|
|
11306
|
-
if (flow === "")
|
|
11454
|
+
if (flow === "")
|
|
11455
|
+
flow = void 0;
|
|
11307
11456
|
}
|
|
11308
11457
|
proxy = {
|
|
11309
11458
|
type: "vless",
|
|
@@ -11391,7 +11540,8 @@ function Egern_Producer() {
|
|
|
11391
11540
|
"vless",
|
|
11392
11541
|
"vmess",
|
|
11393
11542
|
"anytls",
|
|
11394
|
-
"ssh"
|
|
11543
|
+
"ssh",
|
|
11544
|
+
"snell"
|
|
11395
11545
|
].includes(original.type)) {
|
|
11396
11546
|
if (["shadow-tls"].includes(original.plugin) && original["plugin-opts"]) {
|
|
11397
11547
|
if (original["plugin-opts"].version != 3)
|
|
@@ -11492,22 +11642,24 @@ function getTfo(proxy) {
|
|
|
11492
11642
|
function getUdpRelay(proxy) {
|
|
11493
11643
|
return proxy.udp ?? proxy.udp_relay;
|
|
11494
11644
|
}
|
|
11495
|
-
function hasShadowTls(proxy) {
|
|
11496
|
-
return proxy.plugin === "shadow-tls";
|
|
11497
|
-
}
|
|
11498
11645
|
function getNonEmptyValue(value) {
|
|
11499
|
-
if (value == null)
|
|
11500
|
-
|
|
11646
|
+
if (value == null)
|
|
11647
|
+
return void 0;
|
|
11648
|
+
if (typeof value === "string" && value.length === 0)
|
|
11649
|
+
return void 0;
|
|
11501
11650
|
return value;
|
|
11502
11651
|
}
|
|
11503
11652
|
function getReality(proxy) {
|
|
11504
11653
|
const realityOpts = proxy?.["reality-opts"];
|
|
11505
|
-
if (!realityOpts)
|
|
11654
|
+
if (!realityOpts)
|
|
11655
|
+
return void 0;
|
|
11506
11656
|
const reality = {};
|
|
11507
11657
|
const publicKey = getNonEmptyValue(realityOpts["public-key"]);
|
|
11508
11658
|
const shortId = getNonEmptyValue(realityOpts["short-id"]);
|
|
11509
|
-
if (publicKey != null)
|
|
11510
|
-
|
|
11659
|
+
if (publicKey != null)
|
|
11660
|
+
reality.public_key = publicKey;
|
|
11661
|
+
if (shortId != null)
|
|
11662
|
+
reality.short_id = shortId;
|
|
11511
11663
|
return Object.keys(reality).length > 0 ? reality : void 0;
|
|
11512
11664
|
}
|
|
11513
11665
|
function getGrpcTransport(proxy) {
|
|
@@ -11521,21 +11673,26 @@ function getGrpcTransport(proxy) {
|
|
|
11521
11673
|
};
|
|
11522
11674
|
}
|
|
11523
11675
|
function isEgernGrpcGun(proxy) {
|
|
11524
|
-
if (proxy.network !== "grpc")
|
|
11676
|
+
if (proxy.network !== "grpc")
|
|
11677
|
+
return true;
|
|
11525
11678
|
const grpcType = proxy["grpc-opts"]?.["_grpc-type"];
|
|
11526
|
-
if (grpcType == null)
|
|
11679
|
+
if (grpcType == null)
|
|
11680
|
+
return true;
|
|
11527
11681
|
return `${grpcType}`.trim().toLowerCase() === "gun";
|
|
11528
11682
|
}
|
|
11529
11683
|
function normalizeSnellVersion(version) {
|
|
11530
|
-
if (version == null)
|
|
11684
|
+
if (version == null)
|
|
11685
|
+
return void 0;
|
|
11531
11686
|
const normalized = `${version}`.trim();
|
|
11532
|
-
if (!/^[1-5]$/.test(normalized))
|
|
11687
|
+
if (!/^[1-5]$/.test(normalized))
|
|
11688
|
+
return null;
|
|
11533
11689
|
return parseInt(normalized, 10);
|
|
11534
11690
|
}
|
|
11535
11691
|
function getFirstHeaderValue(headers, ...keys) {
|
|
11536
11692
|
for (const key of keys) {
|
|
11537
11693
|
const value = getFirstValue(headers?.[key]);
|
|
11538
|
-
if (value)
|
|
11694
|
+
if (value)
|
|
11695
|
+
return value;
|
|
11539
11696
|
}
|
|
11540
11697
|
return void 0;
|
|
11541
11698
|
}
|
|
@@ -11546,7 +11703,8 @@ function getH2Headers(h2Opts) {
|
|
|
11546
11703
|
const headers = {};
|
|
11547
11704
|
if (h2Opts?.headers && typeof h2Opts.headers === "object" && !Array.isArray(h2Opts.headers)) {
|
|
11548
11705
|
for (const [key, value] of Object.entries(h2Opts.headers)) {
|
|
11549
|
-
if (/^host$/i.test(key))
|
|
11706
|
+
if (/^host$/i.test(key))
|
|
11707
|
+
continue;
|
|
11550
11708
|
const headerValue = getFirstValue(value);
|
|
11551
11709
|
if (headerValue != null) {
|
|
11552
11710
|
headers[key] = headerValue;
|
|
@@ -11560,13 +11718,16 @@ function getH2Headers(h2Opts) {
|
|
|
11560
11718
|
return Object.keys(headers).length > 0 ? headers : void 0;
|
|
11561
11719
|
}
|
|
11562
11720
|
function getFirstValue(value) {
|
|
11563
|
-
if (Array.isArray(value))
|
|
11564
|
-
|
|
11721
|
+
if (Array.isArray(value))
|
|
11722
|
+
return value[0];
|
|
11723
|
+
if (value != null)
|
|
11724
|
+
return value;
|
|
11565
11725
|
return void 0;
|
|
11566
11726
|
}
|
|
11567
11727
|
function getFingerprintSha256(proxy) {
|
|
11568
11728
|
const fingerprint = proxy?.["tls-fingerprint"];
|
|
11569
|
-
if (typeof fingerprint !== "string")
|
|
11729
|
+
if (typeof fingerprint !== "string")
|
|
11730
|
+
return void 0;
|
|
11570
11731
|
const trimmedFingerprint = fingerprint.trim();
|
|
11571
11732
|
return trimmedFingerprint.length > 0 ? trimmedFingerprint : void 0;
|
|
11572
11733
|
}
|
|
@@ -11576,7 +11737,8 @@ function supportsRootFingerprintSha256(original, proxy) {
|
|
|
11576
11737
|
) || original.type === "socks5" && proxy.type === "socks5_tls" || original.type === "http" && proxy.type === "https";
|
|
11577
11738
|
}
|
|
11578
11739
|
function addTransportFingerprintSha256(transport, fingerprintSha256) {
|
|
11579
|
-
if (!transport)
|
|
11740
|
+
if (!transport)
|
|
11741
|
+
return;
|
|
11580
11742
|
for (const key of ["grpc", "http2", "tls", "wss"]) {
|
|
11581
11743
|
if (transport[key]) {
|
|
11582
11744
|
transport[key].fingerprint_sha256 = fingerprintSha256;
|
|
@@ -11678,7 +11840,8 @@ function parseProxyLines(lines, opts) {
|
|
|
11678
11840
|
const proxyList = [];
|
|
11679
11841
|
let lastParser = null;
|
|
11680
11842
|
for (const line of lines) {
|
|
11681
|
-
if (line.length === 0)
|
|
11843
|
+
if (line.length === 0)
|
|
11844
|
+
continue;
|
|
11682
11845
|
let proxy = null;
|
|
11683
11846
|
if (lastParser) {
|
|
11684
11847
|
proxy = tryParseProxy(lastParser, line);
|