sub-store-convert 2.33.1 → 2.36.20
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 +975 -686
- 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("")); }
|
|
@@ -1149,8 +1150,13 @@ fast_open = comma "fast-open" equals flag:bool { proxy.tfo = flag; }
|
|
|
1149
1150
|
|
|
1150
1151
|
over_tls = comma "over-tls" equals flag:bool { proxy.tls = flag; }
|
|
1151
1152
|
tls_host = comma sni:("tls-host") equals match:[^,]+ { proxy.sni = match.join("").replace(/^"(.*)"$/, '$1'); }
|
|
1152
|
-
tls_verification = comma "tls-verification" equals
|
|
1153
|
-
|
|
1153
|
+
tls_verification = comma "tls-verification" equals raw:$[^,]+ {
|
|
1154
|
+
const value = raw.trim();
|
|
1155
|
+
if (value === "true" || value === "false") {
|
|
1156
|
+
proxy["skip-cert-verify"] = value !== "true";
|
|
1157
|
+
} else {
|
|
1158
|
+
proxy["name-cert-verify"] = value;
|
|
1159
|
+
}
|
|
1154
1160
|
}
|
|
1155
1161
|
tls_fingerprint = comma "tls-cert-sha256" equals tls_fingerprint:$[^,]+ { proxy["tls-fingerprint"] = tls_fingerprint.trim(); }
|
|
1156
1162
|
tls_pubkey_sha256 = comma "tls-pubkey-sha256" equals param:$[^=,]+ { proxy["tls-pubkey-sha256"] = param; }
|
|
@@ -1222,279 +1228,325 @@ function getParser3() {
|
|
|
1222
1228
|
return parser3;
|
|
1223
1229
|
}
|
|
1224
1230
|
|
|
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);
|
|
1231
|
+
// src/vendors/Sub-Store/backend/src/core/proxy-utils/transport-path.js
|
|
1232
|
+
function decodeQueryComponent(value) {
|
|
1233
|
+
try {
|
|
1234
|
+
return decodeURIComponent(`${value}`.replace(/\+/g, "%20"));
|
|
1235
|
+
} catch (e) {
|
|
1236
|
+
return value;
|
|
1244
1237
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1238
|
+
}
|
|
1239
|
+
function splitQueryPart(part) {
|
|
1240
|
+
const separatorIndex = part.indexOf("=");
|
|
1241
|
+
if (separatorIndex === -1) {
|
|
1242
|
+
return {
|
|
1243
|
+
key: decodeQueryComponent(part),
|
|
1244
|
+
value: ""
|
|
1245
|
+
};
|
|
1252
1246
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1247
|
+
return {
|
|
1248
|
+
key: decodeQueryComponent(part.slice(0, separatorIndex)),
|
|
1249
|
+
value: decodeQueryComponent(part.slice(separatorIndex + 1))
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
function parseSafeIntegerValue(value) {
|
|
1253
|
+
if (!/^\d+$/.test(`${value}`))
|
|
1254
|
+
return null;
|
|
1255
|
+
const parsed = parseInt(`${value}`, 10);
|
|
1256
|
+
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
1257
|
+
}
|
|
1258
|
+
function extractPathQueryParam(rawPath, paramName) {
|
|
1259
|
+
const path = rawPath == null ? "" : `${rawPath}`;
|
|
1260
|
+
const queryIndex = path.indexOf("?");
|
|
1261
|
+
if (queryIndex === -1) {
|
|
1263
1262
|
return {
|
|
1264
|
-
|
|
1265
|
-
value:
|
|
1263
|
+
path,
|
|
1264
|
+
value: ""
|
|
1266
1265
|
};
|
|
1267
1266
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
return parsed.value;
|
|
1267
|
+
const basePath = path.slice(0, queryIndex);
|
|
1268
|
+
const query = path.slice(queryIndex + 1);
|
|
1269
|
+
const keptParts = [];
|
|
1270
|
+
let value = "";
|
|
1271
|
+
for (const part of query.split("&")) {
|
|
1272
|
+
if (part === "")
|
|
1273
|
+
continue;
|
|
1274
|
+
const parsed = splitQueryPart(part);
|
|
1275
|
+
if (parsed.key === paramName) {
|
|
1276
|
+
if (value === "" && parsed.value !== "") {
|
|
1277
|
+
value = parsed.value;
|
|
1280
1278
|
}
|
|
1279
|
+
continue;
|
|
1281
1280
|
}
|
|
1282
|
-
|
|
1283
|
-
return '';
|
|
1281
|
+
keptParts.push(part);
|
|
1284
1282
|
}
|
|
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);
|
|
1283
|
+
return {
|
|
1284
|
+
path: keptParts.length > 0 ? `${basePath}?${keptParts.join("&")}` : basePath,
|
|
1285
|
+
value
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
function getPathQueryParam(rawPath, paramName) {
|
|
1289
|
+
const path = rawPath == null ? "" : `${rawPath}`;
|
|
1290
|
+
const queryIndex = path.indexOf("?");
|
|
1291
|
+
if (queryIndex === -1)
|
|
1292
|
+
return "";
|
|
1293
|
+
const query = path.slice(queryIndex + 1);
|
|
1294
|
+
for (const part of query.split("&")) {
|
|
1295
|
+
if (part === "")
|
|
1296
|
+
continue;
|
|
1297
|
+
const parsed = splitQueryPart(part);
|
|
1298
|
+
if (parsed.key === paramName && parsed.value !== "") {
|
|
1299
|
+
return parsed.value;
|
|
1312
1300
|
}
|
|
1313
|
-
|
|
1301
|
+
}
|
|
1302
|
+
return "";
|
|
1303
|
+
}
|
|
1304
|
+
function getSafeIntegerPathQueryParam(rawPath, paramName) {
|
|
1305
|
+
const value = getPathQueryParam(rawPath, paramName);
|
|
1306
|
+
const parsed = parseSafeIntegerValue(value);
|
|
1307
|
+
if (parsed == null) {
|
|
1314
1308
|
return {
|
|
1315
|
-
|
|
1316
|
-
|
|
1309
|
+
value: "",
|
|
1310
|
+
parsed: null
|
|
1317
1311
|
};
|
|
1318
1312
|
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1313
|
+
return {
|
|
1314
|
+
value,
|
|
1315
|
+
parsed
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
function appendPathQueryParam(path, paramName, value) {
|
|
1319
|
+
const separator = path.includes("?") ? path.endsWith("?") || path.endsWith("&") ? "" : "&" : "?";
|
|
1320
|
+
return `${path}${separator}${encodeURIComponent(
|
|
1321
|
+
paramName
|
|
1322
|
+
)}=${encodeURIComponent(`${value}`)}`;
|
|
1323
|
+
}
|
|
1324
|
+
function setPathQueryParam(rawPath, paramName, value) {
|
|
1325
|
+
const path = rawPath == null || rawPath === "" ? "/" : `${rawPath}`;
|
|
1326
|
+
const { path: pathWithoutParam } = extractPathQueryParam(path, paramName);
|
|
1327
|
+
return appendPathQueryParam(pathWithoutParam, paramName, value);
|
|
1328
|
+
}
|
|
1329
|
+
function normalizeWebSocketEarlyDataPath(wsOpts) {
|
|
1330
|
+
const networkPath = wsOpts?.path;
|
|
1331
|
+
if (!wsOpts)
|
|
1332
|
+
return;
|
|
1333
|
+
const { value: ed, parsed: maxEarlyData } = getSafeIntegerPathQueryParam(
|
|
1334
|
+
networkPath,
|
|
1335
|
+
"ed"
|
|
1336
|
+
);
|
|
1337
|
+
if (wsOpts["v2ray-http-upgrade"]) {
|
|
1338
|
+
if (ed !== "") {
|
|
1339
|
+
wsOpts.path = extractPathQueryParam(networkPath, "ed").path;
|
|
1340
|
+
wsOpts["v2ray-http-upgrade-fast-open"] = true;
|
|
1341
|
+
if (wsOpts["_v2ray-http-upgrade-ed"] == null || `${wsOpts["_v2ray-http-upgrade-ed"]}` === "") {
|
|
1342
|
+
wsOpts["_v2ray-http-upgrade-ed"] = ed;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
delete wsOpts["early-data-header-name"];
|
|
1346
|
+
delete wsOpts["max-early-data"];
|
|
1347
|
+
return;
|
|
1325
1348
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1349
|
+
if (ed === "")
|
|
1350
|
+
return;
|
|
1351
|
+
wsOpts.path = extractPathQueryParam(networkPath, "ed").path;
|
|
1352
|
+
if (wsOpts["early-data-header-name"] == null) {
|
|
1353
|
+
wsOpts["early-data-header-name"] = "Sec-WebSocket-Protocol";
|
|
1354
|
+
}
|
|
1355
|
+
if (wsOpts["max-early-data"] == null) {
|
|
1356
|
+
wsOpts["max-early-data"] = maxEarlyData;
|
|
1329
1357
|
}
|
|
1330
|
-
}}
|
|
1331
|
-
|
|
1332
|
-
{
|
|
1333
|
-
const proxy = {};
|
|
1334
|
-
const obfs = {};
|
|
1335
|
-
const $ = {};
|
|
1336
|
-
const params = {};
|
|
1337
1358
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1359
|
+
function deleteHttpUpgradeEarlyDataMetadata(wsOpts) {
|
|
1360
|
+
if (!wsOpts)
|
|
1361
|
+
return;
|
|
1362
|
+
delete wsOpts["_v2ray-http-upgrade-ed"];
|
|
1341
1363
|
}
|
|
1342
1364
|
|
|
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;
|
|
1365
|
+
// src/vendors/Sub-Store/backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js
|
|
1366
|
+
var unsafePathSegments = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
1367
|
+
var parser4;
|
|
1368
|
+
function $set(obj, path, value) {
|
|
1369
|
+
if (Object(obj) !== obj)
|
|
1370
|
+
return obj;
|
|
1371
|
+
if (!Array.isArray(path))
|
|
1372
|
+
path = path.toString().match(/[^.[\]]+/g) || [];
|
|
1373
|
+
if (path.some((segment) => unsafePathSegments.has(segment))) {
|
|
1374
|
+
throw new Error("Unsafe property path");
|
|
1366
1375
|
}
|
|
1376
|
+
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;
|
|
1377
|
+
return obj;
|
|
1367
1378
|
}
|
|
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);
|
|
1379
|
+
function toBool(str) {
|
|
1380
|
+
if (str == null)
|
|
1381
|
+
return void 0;
|
|
1382
|
+
return /(TRUE)|1/i.test(str);
|
|
1383
|
+
}
|
|
1384
|
+
function isNumericEarlyData(value) {
|
|
1385
|
+
return parseSafeIntegerValue(value) != null;
|
|
1386
|
+
}
|
|
1387
|
+
function decode(value) {
|
|
1388
|
+
try {
|
|
1389
|
+
return decodeURIComponent(value);
|
|
1390
|
+
} catch {
|
|
1391
|
+
return value;
|
|
1389
1392
|
}
|
|
1390
1393
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1394
|
+
function parseTrojan(url) {
|
|
1395
|
+
const proxy = {};
|
|
1396
|
+
const match = url.match(
|
|
1397
|
+
/^trojan:\/\/([^@]+)@(\[[^\]]+\]|[^/?#]+):(\d+)(?:\/)?(?:\?([^#]*))?(?:#(.*))?$/
|
|
1398
|
+
);
|
|
1399
|
+
if (!match) {
|
|
1400
|
+
throw new Error("Invalid trojan url");
|
|
1401
|
+
}
|
|
1402
|
+
const [
|
|
1403
|
+
,
|
|
1404
|
+
password,
|
|
1405
|
+
server,
|
|
1406
|
+
port,
|
|
1407
|
+
query,
|
|
1408
|
+
name
|
|
1409
|
+
] = match;
|
|
1410
|
+
const normalizedServer = server.replace(/^\[|\]$/g, "");
|
|
1411
|
+
if ((server.startsWith("[") || server.includes(":")) && !isIPv6(normalizedServer)) {
|
|
1412
|
+
throw new Error(`Invalid server: ${server}`);
|
|
1395
1413
|
}
|
|
1396
|
-
proxy
|
|
1397
|
-
proxy.
|
|
1398
|
-
proxy
|
|
1399
|
-
proxy
|
|
1400
|
-
proxy.
|
|
1401
|
-
|
|
1402
|
-
|
|
1414
|
+
proxy.type = "trojan";
|
|
1415
|
+
proxy.password = decode(password);
|
|
1416
|
+
proxy.server = server;
|
|
1417
|
+
proxy.port = Number(port);
|
|
1418
|
+
if (!Number.isSafeInteger(proxy.port) || proxy.port < 1 || proxy.port > 65535) {
|
|
1419
|
+
throw new Error(`Invalid port: ${port}`);
|
|
1420
|
+
}
|
|
1421
|
+
proxy.name = name ? decode(name) : `${server}:${port}`;
|
|
1422
|
+
const params = {};
|
|
1423
|
+
if (query) {
|
|
1424
|
+
for (const item of query.split("&")) {
|
|
1425
|
+
const separatorIndex = item.indexOf("=");
|
|
1426
|
+
const key = separatorIndex === -1 ? item : item.slice(0, separatorIndex);
|
|
1427
|
+
params[key] = separatorIndex === -1 ? true : decode(item.slice(separatorIndex + 1));
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
proxy["skip-cert-verify"] = toBool(params.allowInsecure);
|
|
1431
|
+
proxy.sni = params.sni || params.peer;
|
|
1432
|
+
proxy["client-fingerprint"] = params.fp;
|
|
1433
|
+
proxy["tls-fingerprint"] = params.pcs;
|
|
1434
|
+
proxy._vcn = params.vcn?.split(",").map((name2) => name2.trim()).filter(Boolean);
|
|
1435
|
+
proxy["name-cert-verify"] = proxy._vcn?.[0];
|
|
1436
|
+
if (params.alpn) {
|
|
1437
|
+
proxy.alpn = params.alpn.split(",");
|
|
1438
|
+
}
|
|
1439
|
+
if (toBool(params.ws)) {
|
|
1403
1440
|
proxy.network = "ws";
|
|
1404
|
-
$set(
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1441
|
+
$set(
|
|
1442
|
+
proxy,
|
|
1443
|
+
"ws-opts.path",
|
|
1444
|
+
params.wspath
|
|
1445
|
+
);
|
|
1446
|
+
}
|
|
1447
|
+
if (params.type) {
|
|
1448
|
+
let httpupgrade = false;
|
|
1449
|
+
let httpUpgradeEd = "";
|
|
1450
|
+
let pathEarlyData = "";
|
|
1451
|
+
proxy.network = params.type;
|
|
1452
|
+
if (proxy.network === "httpupgrade") {
|
|
1453
|
+
proxy.network = "ws";
|
|
1454
|
+
httpupgrade = true;
|
|
1455
|
+
}
|
|
1456
|
+
if (proxy.network === "grpc") {
|
|
1457
|
+
proxy["grpc-opts"] = {
|
|
1458
|
+
"grpc-service-name": params.serviceName,
|
|
1459
|
+
"_grpc-type": params.mode,
|
|
1460
|
+
"_grpc-authority": params.authority
|
|
1461
|
+
};
|
|
1422
1462
|
} 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
|
-
}
|
|
1463
|
+
if (params.path) {
|
|
1464
|
+
let path = params.path;
|
|
1465
|
+
if (proxy.network === "ws") {
|
|
1466
|
+
const ed = getPathQueryParam(path, "ed");
|
|
1467
|
+
if (isNumericEarlyData(ed)) {
|
|
1468
|
+
path = extractPathQueryParam(path, "ed").path;
|
|
1469
|
+
if (httpupgrade)
|
|
1470
|
+
httpUpgradeEd = ed;
|
|
1471
|
+
else
|
|
1472
|
+
pathEarlyData = ed;
|
|
1434
1473
|
}
|
|
1435
1474
|
}
|
|
1436
|
-
$set(
|
|
1475
|
+
$set(
|
|
1476
|
+
proxy,
|
|
1477
|
+
`${proxy.network}-opts.path`,
|
|
1478
|
+
path
|
|
1479
|
+
);
|
|
1437
1480
|
}
|
|
1438
|
-
if (params
|
|
1439
|
-
$set(
|
|
1481
|
+
if (params.host) {
|
|
1482
|
+
$set(
|
|
1483
|
+
proxy,
|
|
1484
|
+
`${proxy.network}-opts.headers.Host`,
|
|
1485
|
+
params.host
|
|
1486
|
+
);
|
|
1440
1487
|
}
|
|
1441
1488
|
if (httpupgrade) {
|
|
1442
|
-
httpUpgradeEd = httpUpgradeEd || (isNumericEarlyData(params.ed) ? String(params.ed) :
|
|
1443
|
-
$set(
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1489
|
+
httpUpgradeEd = httpUpgradeEd || (isNumericEarlyData(params.ed) ? String(params.ed) : "");
|
|
1490
|
+
$set(
|
|
1491
|
+
proxy,
|
|
1492
|
+
"ws-opts.v2ray-http-upgrade",
|
|
1493
|
+
true
|
|
1494
|
+
);
|
|
1495
|
+
if (httpUpgradeEd) {
|
|
1496
|
+
$set(
|
|
1497
|
+
proxy,
|
|
1498
|
+
"ws-opts.v2ray-http-upgrade-fast-open",
|
|
1499
|
+
true
|
|
1500
|
+
);
|
|
1501
|
+
$set(
|
|
1502
|
+
proxy,
|
|
1503
|
+
"ws-opts._v2ray-http-upgrade-ed",
|
|
1504
|
+
httpUpgradeEd
|
|
1505
|
+
);
|
|
1447
1506
|
}
|
|
1448
|
-
} else if (proxy.network ===
|
|
1449
|
-
$set(
|
|
1450
|
-
|
|
1507
|
+
} else if (proxy.network === "ws" && pathEarlyData) {
|
|
1508
|
+
$set(
|
|
1509
|
+
proxy,
|
|
1510
|
+
"ws-opts.max-early-data",
|
|
1511
|
+
parseSafeIntegerValue(pathEarlyData)
|
|
1512
|
+
);
|
|
1513
|
+
$set(
|
|
1514
|
+
proxy,
|
|
1515
|
+
"ws-opts.early-data-header-name",
|
|
1516
|
+
"Sec-WebSocket-Protocol"
|
|
1517
|
+
);
|
|
1451
1518
|
}
|
|
1452
1519
|
}
|
|
1453
|
-
if (
|
|
1520
|
+
if (params.security === "reality") {
|
|
1454
1521
|
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) {
|
|
1522
|
+
if (params.pbk)
|
|
1523
|
+
opts["public-key"] = params.pbk;
|
|
1524
|
+
if (params.sid)
|
|
1525
|
+
opts["short-id"] = params.sid;
|
|
1526
|
+
if (params.spx)
|
|
1527
|
+
opts["_spider-x"] = params.spx;
|
|
1528
|
+
if (params.mode)
|
|
1465
1529
|
proxy._mode = params.mode;
|
|
1466
|
-
|
|
1467
|
-
if (params.extra) {
|
|
1530
|
+
if (params.extra)
|
|
1468
1531
|
proxy._extra = params.extra;
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1532
|
+
if (Object.keys(opts).length) {
|
|
1533
|
+
$set(
|
|
1534
|
+
proxy,
|
|
1535
|
+
"reality-opts",
|
|
1536
|
+
opts
|
|
1537
|
+
);
|
|
1472
1538
|
}
|
|
1473
1539
|
}
|
|
1474
1540
|
}
|
|
1475
|
-
|
|
1476
|
-
proxy.
|
|
1477
|
-
proxy
|
|
1478
|
-
}
|
|
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);
|
|
1541
|
+
proxy.udp = toBool(params.udp);
|
|
1542
|
+
proxy.tfo = toBool(params.tfo);
|
|
1543
|
+
return proxy;
|
|
1492
1544
|
}
|
|
1493
|
-
`;
|
|
1494
|
-
var parser4;
|
|
1495
1545
|
function getParser4() {
|
|
1496
1546
|
if (!parser4) {
|
|
1497
|
-
parser4 =
|
|
1547
|
+
parser4 = {
|
|
1548
|
+
parse: parseTrojan
|
|
1549
|
+
};
|
|
1498
1550
|
}
|
|
1499
1551
|
return parser4;
|
|
1500
1552
|
}
|
|
@@ -1657,182 +1709,55 @@ function normalizeXhttpPositiveRange(value) {
|
|
|
1657
1709
|
return void 0;
|
|
1658
1710
|
}
|
|
1659
1711
|
const { lowerBound, upperBound } = normalizedBounds;
|
|
1660
|
-
return lowerBound === upperBound ? upperBound : `${lowerBound}-${upperBound}`;
|
|
1661
|
-
}
|
|
1662
|
-
function normalizeXhttpStrictPositiveRangeString(value) {
|
|
1663
|
-
const normalizedBounds = parseNormalizedXhttpStrictPositiveRangeBounds(value);
|
|
1664
|
-
if (!normalizedBounds) {
|
|
1665
|
-
return void 0;
|
|
1666
|
-
}
|
|
1667
|
-
const { lowerBound, upperBound } = normalizedBounds;
|
|
1668
|
-
return lowerBound === upperBound ? `${upperBound}` : `${lowerBound}-${upperBound}`;
|
|
1669
|
-
}
|
|
1670
|
-
function normalizeXhttpStrictPositiveRangeValue(value) {
|
|
1671
|
-
const normalizedBounds = parseNormalizedXhttpStrictPositiveRangeBounds(value);
|
|
1672
|
-
if (!normalizedBounds) {
|
|
1673
|
-
return void 0;
|
|
1674
|
-
}
|
|
1675
|
-
const { lowerBound, upperBound } = normalizedBounds;
|
|
1676
|
-
return lowerBound === upperBound ? upperBound : `${lowerBound}-${upperBound}`;
|
|
1677
|
-
}
|
|
1678
|
-
function normalizeXhttpNonNegativeRange(value) {
|
|
1679
|
-
const normalizedBounds = parseNormalizedXhttpRangeBounds(value);
|
|
1680
|
-
if (!normalizedBounds) {
|
|
1681
|
-
return void 0;
|
|
1682
|
-
}
|
|
1683
|
-
const { lowerBound, upperBound } = normalizedBounds;
|
|
1684
|
-
return lowerBound === upperBound ? upperBound : `${lowerBound}-${upperBound}`;
|
|
1685
|
-
}
|
|
1686
|
-
function normalizeXhttpIntegerValue(value, { allowNegative = true } = {}) {
|
|
1687
|
-
if (typeof value === "number" && Number.isFinite(value) && Number.isSafeInteger(value)) {
|
|
1688
|
-
if (!allowNegative && value < 0) {
|
|
1689
|
-
return void 0;
|
|
1690
|
-
}
|
|
1691
|
-
return value;
|
|
1692
|
-
}
|
|
1693
|
-
if (typeof value !== "string") {
|
|
1694
|
-
return void 0;
|
|
1695
|
-
}
|
|
1696
|
-
const normalizedValue = value.trim();
|
|
1697
|
-
const integerPattern = allowNegative ? /^[+-]?\d+$/ : /^\+?\d+$/;
|
|
1698
|
-
if (!integerPattern.test(normalizedValue)) {
|
|
1699
|
-
return void 0;
|
|
1700
|
-
}
|
|
1701
|
-
const parsedInteger = parseInt(normalizedValue, 10);
|
|
1702
|
-
if (!Number.isSafeInteger(parsedInteger)) {
|
|
1703
|
-
return void 0;
|
|
1704
|
-
}
|
|
1705
|
-
if (!allowNegative && parsedInteger < 0) {
|
|
1706
|
-
return void 0;
|
|
1707
|
-
}
|
|
1708
|
-
return parsedInteger;
|
|
1709
|
-
}
|
|
1710
|
-
|
|
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 "";
|
|
1712
|
+
return lowerBound === upperBound ? upperBound : `${lowerBound}-${upperBound}`;
|
|
1779
1713
|
}
|
|
1780
|
-
function
|
|
1781
|
-
const
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
return {
|
|
1785
|
-
value: "",
|
|
1786
|
-
parsed: null
|
|
1787
|
-
};
|
|
1714
|
+
function normalizeXhttpStrictPositiveRangeString(value) {
|
|
1715
|
+
const normalizedBounds = parseNormalizedXhttpStrictPositiveRangeBounds(value);
|
|
1716
|
+
if (!normalizedBounds) {
|
|
1717
|
+
return void 0;
|
|
1788
1718
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
parsed
|
|
1792
|
-
};
|
|
1719
|
+
const { lowerBound, upperBound } = normalizedBounds;
|
|
1720
|
+
return lowerBound === upperBound ? `${upperBound}` : `${lowerBound}-${upperBound}`;
|
|
1793
1721
|
}
|
|
1794
|
-
function
|
|
1795
|
-
const
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1722
|
+
function normalizeXhttpStrictPositiveRangeValue(value) {
|
|
1723
|
+
const normalizedBounds = parseNormalizedXhttpStrictPositiveRangeBounds(value);
|
|
1724
|
+
if (!normalizedBounds) {
|
|
1725
|
+
return void 0;
|
|
1726
|
+
}
|
|
1727
|
+
const { lowerBound, upperBound } = normalizedBounds;
|
|
1728
|
+
return lowerBound === upperBound ? upperBound : `${lowerBound}-${upperBound}`;
|
|
1799
1729
|
}
|
|
1800
|
-
function
|
|
1801
|
-
const
|
|
1802
|
-
|
|
1803
|
-
|
|
1730
|
+
function normalizeXhttpNonNegativeRange(value) {
|
|
1731
|
+
const normalizedBounds = parseNormalizedXhttpRangeBounds(value);
|
|
1732
|
+
if (!normalizedBounds) {
|
|
1733
|
+
return void 0;
|
|
1734
|
+
}
|
|
1735
|
+
const { lowerBound, upperBound } = normalizedBounds;
|
|
1736
|
+
return lowerBound === upperBound ? upperBound : `${lowerBound}-${upperBound}`;
|
|
1804
1737
|
}
|
|
1805
|
-
function
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
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
|
-
}
|
|
1738
|
+
function normalizeXhttpIntegerValue(value, { allowNegative = true } = {}) {
|
|
1739
|
+
if (typeof value === "number" && Number.isFinite(value) && Number.isSafeInteger(value)) {
|
|
1740
|
+
if (!allowNegative && value < 0) {
|
|
1741
|
+
return void 0;
|
|
1819
1742
|
}
|
|
1820
|
-
|
|
1821
|
-
delete wsOpts["max-early-data"];
|
|
1822
|
-
return;
|
|
1743
|
+
return value;
|
|
1823
1744
|
}
|
|
1824
|
-
if (
|
|
1825
|
-
|
|
1826
|
-
if (wsOpts["early-data-header-name"] == null) {
|
|
1827
|
-
wsOpts["early-data-header-name"] = "Sec-WebSocket-Protocol";
|
|
1745
|
+
if (typeof value !== "string") {
|
|
1746
|
+
return void 0;
|
|
1828
1747
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1748
|
+
const normalizedValue = value.trim();
|
|
1749
|
+
const integerPattern = allowNegative ? /^[+-]?\d+$/ : /^\+?\d+$/;
|
|
1750
|
+
if (!integerPattern.test(normalizedValue)) {
|
|
1751
|
+
return void 0;
|
|
1831
1752
|
}
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1753
|
+
const parsedInteger = parseInt(normalizedValue, 10);
|
|
1754
|
+
if (!Number.isSafeInteger(parsedInteger)) {
|
|
1755
|
+
return void 0;
|
|
1756
|
+
}
|
|
1757
|
+
if (!allowNegative && parsedInteger < 0) {
|
|
1758
|
+
return void 0;
|
|
1759
|
+
}
|
|
1760
|
+
return parsedInteger;
|
|
1836
1761
|
}
|
|
1837
1762
|
|
|
1838
1763
|
// src/vendors/Sub-Store/backend/src/core/proxy-utils/ech-utils.js
|
|
@@ -1962,7 +1887,8 @@ var VMESS_SECURITY_ALIASES = {
|
|
|
1962
1887
|
"chacha20-ietf-poly1305": "chacha20-poly1305"
|
|
1963
1888
|
};
|
|
1964
1889
|
function normalizeSecurityValue(security) {
|
|
1965
|
-
if (security == null)
|
|
1890
|
+
if (security == null)
|
|
1891
|
+
return "";
|
|
1966
1892
|
return `${security}`.trim().toLowerCase();
|
|
1967
1893
|
}
|
|
1968
1894
|
function canonicalizeVmessSecurity(security) {
|
|
@@ -1970,7 +1896,8 @@ function canonicalizeVmessSecurity(security) {
|
|
|
1970
1896
|
}
|
|
1971
1897
|
function normalizeVmessSecurity(security, supportedValues = VMESS_SECURITY_COMMON_VALUES, { acceptAliases = true, fallback = VMESS_SECURITY_AUTO } = {}) {
|
|
1972
1898
|
const normalized = normalizeSecurityValue(security);
|
|
1973
|
-
if (!normalized)
|
|
1899
|
+
if (!normalized)
|
|
1900
|
+
return fallback;
|
|
1974
1901
|
const normalizedSupported = supportedValues.map(normalizeSecurityValue);
|
|
1975
1902
|
if (normalizedSupported.includes(normalized)) {
|
|
1976
1903
|
return canonicalizeVmessSecurity(normalized);
|
|
@@ -2001,7 +1928,8 @@ function formatSurgeVmessEncryptMethod(security) {
|
|
|
2001
1928
|
"aes-128-gcm",
|
|
2002
1929
|
"chacha20-poly1305"
|
|
2003
1930
|
]);
|
|
2004
|
-
if (normalized === VMESS_SECURITY_AUTO)
|
|
1931
|
+
if (normalized === VMESS_SECURITY_AUTO)
|
|
1932
|
+
return void 0;
|
|
2005
1933
|
return normalized === "chacha20-poly1305" ? "chacha20-ietf-poly1305" : normalized;
|
|
2006
1934
|
}
|
|
2007
1935
|
|
|
@@ -2036,13 +1964,14 @@ function decodeShadowsocksUserInfo(rawUserInfoStr) {
|
|
|
2036
1964
|
}
|
|
2037
1965
|
return Base64.decode(decodedUserInfoStr);
|
|
2038
1966
|
}
|
|
2039
|
-
function
|
|
2040
|
-
if (value == null || !/^\d+$/.test(`${value}`))
|
|
1967
|
+
function isNumericEarlyData2(value) {
|
|
1968
|
+
if (value == null || !/^\d+$/.test(`${value}`))
|
|
1969
|
+
return false;
|
|
2041
1970
|
return Number.isSafeInteger(parseInt(`${value}`, 10));
|
|
2042
1971
|
}
|
|
2043
1972
|
function extractEarlyDataFromPath(path) {
|
|
2044
1973
|
const ed = getPathQueryParam(path, "ed");
|
|
2045
|
-
if (!
|
|
1974
|
+
if (!isNumericEarlyData2(ed)) {
|
|
2046
1975
|
return {
|
|
2047
1976
|
path,
|
|
2048
1977
|
ed: ""
|
|
@@ -2075,16 +2004,21 @@ function splitURIHostList(host) {
|
|
|
2075
2004
|
return hosts.length > 0 ? hosts : void 0;
|
|
2076
2005
|
}
|
|
2077
2006
|
function parseWireGuardURIAddressValue(value) {
|
|
2078
|
-
if (value == null)
|
|
2007
|
+
if (value == null)
|
|
2008
|
+
return null;
|
|
2079
2009
|
const raw = `${value}`.trim();
|
|
2080
|
-
if (!raw)
|
|
2010
|
+
if (!raw)
|
|
2011
|
+
return null;
|
|
2081
2012
|
const [, hostRaw = raw, cidrRaw] = /^(.*?)(?:\/(\d+))?$/.exec(raw) || [];
|
|
2082
2013
|
const host = `${hostRaw}`.trim().replace(/^\[/, "").replace(/\]$/, "");
|
|
2083
2014
|
const normalizeCIDR = (cidr, max) => {
|
|
2084
|
-
if (cidr == null)
|
|
2085
|
-
|
|
2015
|
+
if (cidr == null)
|
|
2016
|
+
return void 0;
|
|
2017
|
+
if (!/^\d+$/.test(cidr))
|
|
2018
|
+
return void 0;
|
|
2086
2019
|
const parsed = parseInt(cidr, 10);
|
|
2087
|
-
if (parsed < 0 || parsed > max)
|
|
2020
|
+
if (parsed < 0 || parsed > max)
|
|
2021
|
+
return void 0;
|
|
2088
2022
|
return parsed;
|
|
2089
2023
|
};
|
|
2090
2024
|
if (isIPv4(host)) {
|
|
@@ -2267,7 +2201,7 @@ function URI_SS() {
|
|
|
2267
2201
|
);
|
|
2268
2202
|
}
|
|
2269
2203
|
if (httpupgrade) {
|
|
2270
|
-
httpUpgradeEd = httpUpgradeEd || (
|
|
2204
|
+
httpUpgradeEd = httpUpgradeEd || (isNumericEarlyData2(params.ed) ? `${params.ed}` : "");
|
|
2271
2205
|
_.set(
|
|
2272
2206
|
proxy,
|
|
2273
2207
|
proxy.network + "-opts.v2ray-http-upgrade",
|
|
@@ -2339,12 +2273,14 @@ function URI_SS() {
|
|
|
2339
2273
|
for (const item of pluginInfo) {
|
|
2340
2274
|
const separatorIndex = item.indexOf("=");
|
|
2341
2275
|
if (separatorIndex === -1) {
|
|
2342
|
-
if (item)
|
|
2276
|
+
if (item)
|
|
2277
|
+
params2[item] = true;
|
|
2343
2278
|
continue;
|
|
2344
2279
|
}
|
|
2345
2280
|
const key = item.slice(0, separatorIndex);
|
|
2346
2281
|
const val = item.slice(separatorIndex + 1).replace(/\\=/g, "=");
|
|
2347
|
-
if (key)
|
|
2282
|
+
if (key)
|
|
2283
|
+
params2[key] = val || true;
|
|
2348
2284
|
}
|
|
2349
2285
|
switch (params2.plugin) {
|
|
2350
2286
|
case "obfs-local":
|
|
@@ -2693,7 +2629,7 @@ function URI_VMess() {
|
|
|
2693
2629
|
}
|
|
2694
2630
|
if (httpupgrade) {
|
|
2695
2631
|
opts["v2ray-http-upgrade"] = true;
|
|
2696
|
-
httpUpgradeEd = httpUpgradeEd || (
|
|
2632
|
+
httpUpgradeEd = httpUpgradeEd || (isNumericEarlyData2(params.ed) ? `${params.ed}` : "");
|
|
2697
2633
|
if (httpUpgradeEd !== "") {
|
|
2698
2634
|
opts["v2ray-http-upgrade-fast-open"] = true;
|
|
2699
2635
|
opts["_v2ray-http-upgrade-ed"] = httpUpgradeEd;
|
|
@@ -3496,6 +3432,8 @@ function URI_VLESS() {
|
|
|
3496
3432
|
proxy["ech-opts"] = echOpts;
|
|
3497
3433
|
}
|
|
3498
3434
|
proxy["tls-fingerprint"] = getIfPresent(params.pcs);
|
|
3435
|
+
proxy._vcn = params.vcn?.split(",").map((name3) => name3.trim()).filter(Boolean);
|
|
3436
|
+
proxy["name-cert-verify"] = proxy._vcn?.[0];
|
|
3499
3437
|
proxy._h2 = /(TRUE)|1/i.test(params.h2);
|
|
3500
3438
|
switch (`${params.packetEncoding || ""}`.trim().toLowerCase()) {
|
|
3501
3439
|
case "none":
|
|
@@ -3821,6 +3759,12 @@ function URI_Hysteria2() {
|
|
|
3821
3759
|
if (params.downmbps) {
|
|
3822
3760
|
proxy.down = params.downmbps;
|
|
3823
3761
|
}
|
|
3762
|
+
const echOpts = buildMihomoEchOptsFromXrayFields({
|
|
3763
|
+
echConfigList: params.ech
|
|
3764
|
+
});
|
|
3765
|
+
if (echOpts) {
|
|
3766
|
+
proxy["ech-opts"] = echOpts;
|
|
3767
|
+
}
|
|
3824
3768
|
return proxy;
|
|
3825
3769
|
};
|
|
3826
3770
|
return { name, test, parse: parse2 };
|
|
@@ -3999,7 +3943,8 @@ function URI_WireGuard() {
|
|
|
3999
3943
|
} else if (["address", "ip"].includes(key)) {
|
|
4000
3944
|
value.split(",").map((i) => {
|
|
4001
3945
|
const parsed = parseWireGuardURIAddressValue(i);
|
|
4002
|
-
if (!parsed)
|
|
3946
|
+
if (!parsed)
|
|
3947
|
+
return;
|
|
4003
3948
|
if (parsed.family === "ipv4") {
|
|
4004
3949
|
proxy.ip = parsed.address;
|
|
4005
3950
|
if (typeof parsed.cidr !== "undefined") {
|
|
@@ -4076,6 +4021,7 @@ function Clash_All() {
|
|
|
4076
4021
|
proxy = yaml_default.parse(line);
|
|
4077
4022
|
}
|
|
4078
4023
|
if (![
|
|
4024
|
+
"shadowquic",
|
|
4079
4025
|
"gost-relay",
|
|
4080
4026
|
"openvpn",
|
|
4081
4027
|
"tailscale",
|
|
@@ -4675,7 +4621,7 @@ function Base64Encoded() {
|
|
|
4675
4621
|
// tuic://
|
|
4676
4622
|
];
|
|
4677
4623
|
const test = function(raw) {
|
|
4678
|
-
return !/^\w+:\/\/\w+/im.test(raw) && keys.some((k) => raw.indexOf(k) !== -1);
|
|
4624
|
+
return Base642.isValid(raw) && !/^\w+:\/\/\w+/im.test(raw) && keys.some((k) => raw.indexOf(k) !== -1);
|
|
4679
4625
|
};
|
|
4680
4626
|
const parse2 = function(raw) {
|
|
4681
4627
|
const decoded = Base642.decode(raw);
|
|
@@ -4692,7 +4638,7 @@ function Base64Encoded() {
|
|
|
4692
4638
|
function fallbackBase64Encoded() {
|
|
4693
4639
|
const name = "Fallback Base64 Pre-processor";
|
|
4694
4640
|
const test = function(raw) {
|
|
4695
|
-
return
|
|
4641
|
+
return Base642.isValid(raw);
|
|
4696
4642
|
};
|
|
4697
4643
|
const parse2 = function(raw) {
|
|
4698
4644
|
const decoded = Base642.decode(raw);
|
|
@@ -4709,14 +4655,15 @@ function fallbackBase64Encoded() {
|
|
|
4709
4655
|
function Clash() {
|
|
4710
4656
|
const name = "Clash Pre-processor";
|
|
4711
4657
|
const test = function(raw) {
|
|
4712
|
-
if (!/proxies/.test(raw))
|
|
4658
|
+
if (!/proxies/.test(raw))
|
|
4659
|
+
return false;
|
|
4713
4660
|
const content = safeLoad(raw);
|
|
4714
|
-
return content.proxies
|
|
4661
|
+
return Array.isArray(content.proxies) || Array.isArray(content["proxy-groups"]);
|
|
4715
4662
|
};
|
|
4716
4663
|
const parse2 = function(raw, includeProxies) {
|
|
4717
4664
|
const afterReplace = normalizeClashYaml(raw);
|
|
4718
4665
|
const { proxies } = safeLoad(afterReplace);
|
|
4719
|
-
return (includeProxies ? "proxies:\n" : "") + proxies.map((p) => {
|
|
4666
|
+
return (includeProxies ? "proxies:\n" : "") + (Array.isArray(proxies) ? proxies : []).map((p) => {
|
|
4720
4667
|
return `${includeProxies ? " - " : ""}${JSON.stringify(
|
|
4721
4668
|
p
|
|
4722
4669
|
)}
|
|
@@ -4806,12 +4753,16 @@ function isShadowsocksOverTls(proxy) {
|
|
|
4806
4753
|
return proxy?.type === "ss" && proxy?.tls === true && !isPresent2(proxy, "plugin") && (!isPresent2(proxy, "network") || normalizedNetwork === "tcp");
|
|
4807
4754
|
}
|
|
4808
4755
|
function normalizePluginMuxValue(mux) {
|
|
4809
|
-
if (typeof mux === "boolean")
|
|
4756
|
+
if (typeof mux === "boolean")
|
|
4757
|
+
return Number(mux);
|
|
4810
4758
|
if (typeof mux === "string") {
|
|
4811
4759
|
const normalized = mux.trim().toLowerCase();
|
|
4812
|
-
if (normalized === "true")
|
|
4813
|
-
|
|
4814
|
-
if (
|
|
4760
|
+
if (normalized === "true")
|
|
4761
|
+
return 1;
|
|
4762
|
+
if (normalized === "false")
|
|
4763
|
+
return 0;
|
|
4764
|
+
if (/^\d+$/.test(normalized))
|
|
4765
|
+
return parseInt(normalized, 10);
|
|
4815
4766
|
}
|
|
4816
4767
|
return mux;
|
|
4817
4768
|
}
|
|
@@ -4819,27 +4770,66 @@ function normalizePluginMuxBooleanValue(mux) {
|
|
|
4819
4770
|
return Boolean(normalizePluginMuxValue(mux));
|
|
4820
4771
|
}
|
|
4821
4772
|
function supportsShadowsocksV2rayPluginMode(proxy, supportedModes) {
|
|
4822
|
-
if (proxy?.type !== "ss" || proxy?.plugin !== "v2ray-plugin")
|
|
4773
|
+
if (proxy?.type !== "ss" || proxy?.plugin !== "v2ray-plugin")
|
|
4774
|
+
return true;
|
|
4823
4775
|
const normalizedMode = typeof proxy?.["plugin-opts"]?.mode === "string" ? proxy["plugin-opts"].mode.trim().toLowerCase() : proxy?.["plugin-opts"]?.mode;
|
|
4824
4776
|
return supportedModes.includes(normalizedMode);
|
|
4825
4777
|
}
|
|
4778
|
+
function restoreShadowTLSOpts(target, serverNameKey) {
|
|
4779
|
+
if (target?.plugin !== "shadow-tls" || !target["plugin-opts"]) {
|
|
4780
|
+
return void 0;
|
|
4781
|
+
}
|
|
4782
|
+
const opts = target["plugin-opts"];
|
|
4783
|
+
const enabled = Boolean(opts.password) || opts.version != null && Number(opts.version) !== 0;
|
|
4784
|
+
target["shadow-tls-opts"] = {
|
|
4785
|
+
password: opts.password,
|
|
4786
|
+
version: opts.version
|
|
4787
|
+
};
|
|
4788
|
+
if (opts.host != null)
|
|
4789
|
+
target[serverNameKey] = opts.host;
|
|
4790
|
+
if (opts.alpn != null)
|
|
4791
|
+
target.alpn = opts.alpn;
|
|
4792
|
+
delete target.plugin;
|
|
4793
|
+
delete target["plugin-opts"];
|
|
4794
|
+
return enabled;
|
|
4795
|
+
}
|
|
4796
|
+
function restoreShadowTLSProxyOpts(proxy) {
|
|
4797
|
+
if (["vmess", "vless", "trojan", "anytls"].includes(proxy.type)) {
|
|
4798
|
+
const restored = restoreShadowTLSOpts(proxy, "sni");
|
|
4799
|
+
if (restored && ["vmess", "vless"].includes(proxy.type)) {
|
|
4800
|
+
proxy.tls = true;
|
|
4801
|
+
}
|
|
4802
|
+
}
|
|
4803
|
+
if (proxy.type === "vless" && proxy.network === "xhttp") {
|
|
4804
|
+
const downloadSettings = proxy["xhttp-opts"]?.["download-settings"];
|
|
4805
|
+
if (restoreShadowTLSOpts(downloadSettings, "servername")) {
|
|
4806
|
+
downloadSettings.tls = true;
|
|
4807
|
+
}
|
|
4808
|
+
}
|
|
4809
|
+
}
|
|
4826
4810
|
function parseWireGuardCIDR(cidr, max) {
|
|
4827
|
-
if (cidr == null)
|
|
4811
|
+
if (cidr == null)
|
|
4812
|
+
return void 0;
|
|
4828
4813
|
const normalized = `${cidr}`.trim();
|
|
4829
|
-
if (!/^\d+$/.test(normalized))
|
|
4814
|
+
if (!/^\d+$/.test(normalized))
|
|
4815
|
+
return void 0;
|
|
4830
4816
|
const parsed = parseInt(normalized, 10);
|
|
4831
|
-
if (parsed < 0 || parsed > max)
|
|
4817
|
+
if (parsed < 0 || parsed > max)
|
|
4818
|
+
return void 0;
|
|
4832
4819
|
return parsed;
|
|
4833
4820
|
}
|
|
4834
4821
|
function parseWireGuardInterfaceAddress(value, family) {
|
|
4835
|
-
if (value == null)
|
|
4822
|
+
if (value == null)
|
|
4823
|
+
return null;
|
|
4836
4824
|
const raw = `${value}`.trim();
|
|
4837
|
-
if (!raw)
|
|
4825
|
+
if (!raw)
|
|
4826
|
+
return null;
|
|
4838
4827
|
const [, hostRaw = raw, cidrRaw] = /^(.*?)(?:\/(\d+))?$/.exec(raw) || [];
|
|
4839
4828
|
const host = `${hostRaw}`.trim().replace(/^\[/, "").replace(/\]$/, "");
|
|
4840
4829
|
const isIPv4Family = family === "ipv4";
|
|
4841
4830
|
const isValid = isIPv4Family ? isIPv4(host) : isIPv6(host);
|
|
4842
|
-
if (!isValid)
|
|
4831
|
+
if (!isValid)
|
|
4832
|
+
return null;
|
|
4843
4833
|
const max = isIPv4Family ? 32 : 128;
|
|
4844
4834
|
return {
|
|
4845
4835
|
address: host,
|
|
@@ -4852,7 +4842,8 @@ function getWireGuardAddressWithCIDR(proxy = {}, family = "ipv4") {
|
|
|
4852
4842
|
proxy[config.addressKey],
|
|
4853
4843
|
family
|
|
4854
4844
|
);
|
|
4855
|
-
if (!parsed)
|
|
4845
|
+
if (!parsed)
|
|
4846
|
+
return void 0;
|
|
4856
4847
|
const normalizedCIDR = parseWireGuardCIDR(
|
|
4857
4848
|
proxy[config.cidrKey],
|
|
4858
4849
|
config.defaultCIDR
|
|
@@ -4860,7 +4851,8 @@ function getWireGuardAddressWithCIDR(proxy = {}, family = "ipv4") {
|
|
|
4860
4851
|
return `${parsed.address}/${normalizedCIDR ?? parsed.cidr ?? config.defaultCIDR}`;
|
|
4861
4852
|
}
|
|
4862
4853
|
function produceProxyListOutput(list, type, opts = {}) {
|
|
4863
|
-
if (type === "internal")
|
|
4854
|
+
if (type === "internal")
|
|
4855
|
+
return list;
|
|
4864
4856
|
if (opts.prettyYaml || opts["pretty-yaml"]) {
|
|
4865
4857
|
return normalizeClashYaml(
|
|
4866
4858
|
yaml_default.safeDump(
|
|
@@ -4895,7 +4887,8 @@ var ipVersions = {
|
|
|
4895
4887
|
"ipv6-prefer": "prefer-v6"
|
|
4896
4888
|
};
|
|
4897
4889
|
function stripSurgeQuotes(value) {
|
|
4898
|
-
if (typeof value !== "string")
|
|
4890
|
+
if (typeof value !== "string")
|
|
4891
|
+
return value;
|
|
4899
4892
|
const trimmed = value.trim();
|
|
4900
4893
|
const quote = trimmed[0];
|
|
4901
4894
|
if ((quote === '"' || quote === "'") && trimmed[trimmed.length - 1] === quote) {
|
|
@@ -4916,19 +4909,23 @@ function formatSurgeAlpn(alpn) {
|
|
|
4916
4909
|
}
|
|
4917
4910
|
function appendAlpn(result, proxy) {
|
|
4918
4911
|
const alpn = formatSurgeAlpn(proxy.alpn);
|
|
4919
|
-
if (alpn)
|
|
4912
|
+
if (alpn)
|
|
4913
|
+
result.append(`,alpn="${alpn}"`);
|
|
4920
4914
|
}
|
|
4921
4915
|
function getShadowTLSAlpn(proxy) {
|
|
4922
4916
|
return formatSurgeAlpn(proxy?.["plugin-opts"]?.alpn ?? proxy?.alpn);
|
|
4923
4917
|
}
|
|
4924
4918
|
function appendShadowTLS(result, proxy, includeUdpPort = false) {
|
|
4925
|
-
if (proxy.plugin !== "shadow-tls" || !proxy["plugin-opts"])
|
|
4919
|
+
if (proxy.plugin !== "shadow-tls" || !proxy["plugin-opts"])
|
|
4920
|
+
return;
|
|
4926
4921
|
const password = proxy["plugin-opts"].password;
|
|
4927
4922
|
const host = proxy["plugin-opts"].host;
|
|
4928
4923
|
const version = proxy["plugin-opts"].version;
|
|
4929
|
-
if (!password)
|
|
4924
|
+
if (!password)
|
|
4925
|
+
return;
|
|
4930
4926
|
result.append(`,shadow-tls-password="${password}"`);
|
|
4931
|
-
if (host)
|
|
4927
|
+
if (host)
|
|
4928
|
+
result.append(`,shadow-tls-sni=${host}`);
|
|
4932
4929
|
if (version) {
|
|
4933
4930
|
if (version < 2) {
|
|
4934
4931
|
throw unsupported(`shadow-tls version ${version} is not supported`);
|
|
@@ -4936,7 +4933,8 @@ function appendShadowTLS(result, proxy, includeUdpPort = false) {
|
|
|
4936
4933
|
result.append(`,shadow-tls-version=${version}`);
|
|
4937
4934
|
}
|
|
4938
4935
|
const alpn = getShadowTLSAlpn(proxy);
|
|
4939
|
-
if (alpn)
|
|
4936
|
+
if (alpn)
|
|
4937
|
+
result.append(`,alpn="${alpn}"`);
|
|
4940
4938
|
if (includeUdpPort) {
|
|
4941
4939
|
result.appendIfPresent(`,udp-port=${proxy["udp-port"]}`, "udp-port");
|
|
4942
4940
|
}
|
|
@@ -4950,6 +4948,12 @@ function appendTlsProxyParams(result, proxy, enabled = true) {
|
|
|
4950
4948
|
"tls-fingerprint"
|
|
4951
4949
|
);
|
|
4952
4950
|
result.appendIfPresent(`,sni="${proxy.sni}"`, "sni");
|
|
4951
|
+
result.appendIfPresent(
|
|
4952
|
+
`,server-cert-verify-name=${quoteSurgeValue(
|
|
4953
|
+
proxy["name-cert-verify"]
|
|
4954
|
+
)}`,
|
|
4955
|
+
"name-cert-verify"
|
|
4956
|
+
);
|
|
4953
4957
|
if (proxy.plugin !== "shadow-tls") {
|
|
4954
4958
|
appendAlpn(result, proxy);
|
|
4955
4959
|
}
|
|
@@ -4969,9 +4973,11 @@ function appendSshPrivateKey(result, proxy) {
|
|
|
4969
4973
|
}
|
|
4970
4974
|
}
|
|
4971
4975
|
function warnMaxStreamsIfNeeded(proxy) {
|
|
4972
|
-
if (!isPresent2(proxy, "max-streams"))
|
|
4976
|
+
if (!isPresent2(proxy, "max-streams"))
|
|
4977
|
+
return;
|
|
4973
4978
|
const maxStreams = Number(stripSurgeQuotes(proxy["max-streams"]));
|
|
4974
|
-
if (!Number.isInteger(maxStreams) || maxStreams <= 3)
|
|
4979
|
+
if (!Number.isInteger(maxStreams) || maxStreams <= 3)
|
|
4980
|
+
return;
|
|
4975
4981
|
app_default.warn(
|
|
4976
4982
|
`Surge ${proxy.type} proxy ${proxy.name}: max-streams=${maxStreams} is greater than 3. Too many streams sharing one TCP connection may hurt performance.`
|
|
4977
4983
|
);
|
|
@@ -5895,7 +5901,8 @@ function ClashMeta_Producer() {
|
|
|
5895
5901
|
const type = "ALL";
|
|
5896
5902
|
const produce2 = (proxies, type2, opts = {}) => {
|
|
5897
5903
|
const list = proxies.filter((proxy) => {
|
|
5898
|
-
if (opts["include-unsupported-proxy"])
|
|
5904
|
+
if (opts["include-unsupported-proxy"])
|
|
5905
|
+
return true;
|
|
5899
5906
|
if (proxy.type === "h2-connect") {
|
|
5900
5907
|
app_default.error(
|
|
5901
5908
|
`mihomo does not support HTTP/2 CONNECT proxy type. Proxy ${proxy.name} has been filtered.`
|
|
@@ -5912,11 +5919,27 @@ function ClashMeta_Producer() {
|
|
|
5912
5919
|
return false;
|
|
5913
5920
|
} else if (proxy.type === "snell" && !isSupportedMihomoVersion(proxy.version, [1, 2, 3, 4, 5])) {
|
|
5914
5921
|
return false;
|
|
5915
|
-
} else if (hasMihomoShadowTls(proxy) && (![
|
|
5922
|
+
} else if (hasMihomoShadowTls(proxy) && (![
|
|
5923
|
+
"ss",
|
|
5924
|
+
"snell",
|
|
5925
|
+
"vmess",
|
|
5926
|
+
"vless",
|
|
5927
|
+
"trojan",
|
|
5928
|
+
"anytls"
|
|
5929
|
+
].includes(proxy.type) || !isSupportedMihomoVersion(
|
|
5916
5930
|
getMihomoShadowTlsVersion(proxy),
|
|
5917
|
-
[1, 2, 3]
|
|
5931
|
+
["ss", "snell"].includes(proxy.type) ? [1, 2, 3] : [0, 1, 2, 3]
|
|
5918
5932
|
))) {
|
|
5919
5933
|
return false;
|
|
5934
|
+
} else if (proxy.type === "vless" && proxy.network === "xhttp" && hasMihomoShadowTls(
|
|
5935
|
+
proxy["xhttp-opts"]?.["download-settings"]
|
|
5936
|
+
) && !isSupportedMihomoVersion(
|
|
5937
|
+
getMihomoShadowTlsVersion(
|
|
5938
|
+
proxy["xhttp-opts"]["download-settings"]
|
|
5939
|
+
),
|
|
5940
|
+
[0, 1, 2, 3]
|
|
5941
|
+
)) {
|
|
5942
|
+
return false;
|
|
5920
5943
|
} else if (hasMihomoSnellShadowTlsObfsConflict(proxy)) {
|
|
5921
5944
|
app_default.error(
|
|
5922
5945
|
`Platform Mihomo does not support Snell shadow-tls with obfs for proxy ${proxy.name}. Proxy has been filtered.`
|
|
@@ -5969,6 +5992,7 @@ function ClashMeta_Producer() {
|
|
|
5969
5992
|
return true;
|
|
5970
5993
|
}).map((proxy) => {
|
|
5971
5994
|
warnMihomoUnsupportedEchDnsFields(proxy, type2);
|
|
5995
|
+
restoreShadowTLSProxyOpts(proxy);
|
|
5972
5996
|
if (proxy["reality-opts"] && !proxy["client-fingerprint"]) {
|
|
5973
5997
|
proxy["client-fingerprint"] = "chrome";
|
|
5974
5998
|
}
|
|
@@ -6024,6 +6048,9 @@ function ClashMeta_Producer() {
|
|
|
6024
6048
|
ds["reality-opts"] = { "public-key": "" };
|
|
6025
6049
|
}
|
|
6026
6050
|
}
|
|
6051
|
+
} else if (["anytls"].includes(proxy.type) && proxy.reuse != null && !proxy.reuse) {
|
|
6052
|
+
proxy["disable-reuse"] = true;
|
|
6053
|
+
delete proxy.reuse;
|
|
6027
6054
|
}
|
|
6028
6055
|
if (isPresent2(proxy, "plugin-opts.mux")) {
|
|
6029
6056
|
proxy["plugin-opts"].mux = normalizePluginMuxBooleanValue(
|
|
@@ -6094,7 +6121,9 @@ function ClashMeta_Producer() {
|
|
|
6094
6121
|
"juicity",
|
|
6095
6122
|
"anytls",
|
|
6096
6123
|
"trusttunnel",
|
|
6097
|
-
"naive"
|
|
6124
|
+
"naive",
|
|
6125
|
+
"masque",
|
|
6126
|
+
"shadowquic"
|
|
6098
6127
|
].includes(proxy.type)) {
|
|
6099
6128
|
delete proxy.tls;
|
|
6100
6129
|
}
|
|
@@ -6180,8 +6209,6 @@ function SurgeMac_Producer() {
|
|
|
6180
6209
|
switch (proxy.type) {
|
|
6181
6210
|
case "external":
|
|
6182
6211
|
return external(proxy);
|
|
6183
|
-
// case 'ssr':
|
|
6184
|
-
// return shadowsocksr(proxy);
|
|
6185
6212
|
default: {
|
|
6186
6213
|
if (opts.mihomoExternal || proxy._mihomoExternal) {
|
|
6187
6214
|
return mihomo(proxy, type, opts) || "";
|
|
@@ -6368,7 +6395,8 @@ function Clash_Producer() {
|
|
|
6368
6395
|
const type = "ALL";
|
|
6369
6396
|
const produce2 = (proxies, type2, opts = {}) => {
|
|
6370
6397
|
const list = proxies.filter((proxy) => {
|
|
6371
|
-
if (opts["include-unsupported-proxy"])
|
|
6398
|
+
if (opts["include-unsupported-proxy"])
|
|
6399
|
+
return true;
|
|
6372
6400
|
if (![
|
|
6373
6401
|
"ss",
|
|
6374
6402
|
"ssr",
|
|
@@ -6523,7 +6551,8 @@ function Stash_Producer() {
|
|
|
6523
6551
|
const type = "ALL";
|
|
6524
6552
|
const produce2 = (proxies, type2, opts = {}) => {
|
|
6525
6553
|
const list = proxies.filter((proxy) => {
|
|
6526
|
-
if (opts["include-unsupported-proxy"])
|
|
6554
|
+
if (opts["include-unsupported-proxy"])
|
|
6555
|
+
return true;
|
|
6527
6556
|
if (![
|
|
6528
6557
|
"ss",
|
|
6529
6558
|
"ssr",
|
|
@@ -6813,11 +6842,13 @@ function Loon_Producer() {
|
|
|
6813
6842
|
}
|
|
6814
6843
|
function appendTlsProfile(result, proxy) {
|
|
6815
6844
|
const tlsProfile = getLoonTlsProfile(proxy);
|
|
6816
|
-
if (tlsProfile)
|
|
6845
|
+
if (tlsProfile)
|
|
6846
|
+
result.append(`,tls-profile=${tlsProfile}`);
|
|
6817
6847
|
}
|
|
6818
6848
|
function appendAlpn2(result, proxy) {
|
|
6819
6849
|
const alpn = getLoonAlpn(proxy);
|
|
6820
|
-
if (alpn)
|
|
6850
|
+
if (alpn)
|
|
6851
|
+
result.append(`,alpn="${alpn}"`);
|
|
6821
6852
|
}
|
|
6822
6853
|
function getLoonShadowTLSAlpn(proxy) {
|
|
6823
6854
|
const values = proxy?.["plugin-opts"]?.alpn ?? proxy?.alpn;
|
|
@@ -6825,13 +6856,16 @@ function getLoonShadowTLSAlpn(proxy) {
|
|
|
6825
6856
|
return normalized.map((item) => `${item}`.trim()).filter((item) => item !== "").join(",");
|
|
6826
6857
|
}
|
|
6827
6858
|
function appendShadowTLS2(result, proxy) {
|
|
6828
|
-
if (proxy.plugin !== "shadow-tls" || !proxy["plugin-opts"])
|
|
6859
|
+
if (proxy.plugin !== "shadow-tls" || !proxy["plugin-opts"])
|
|
6860
|
+
return;
|
|
6829
6861
|
const password = proxy["plugin-opts"].password;
|
|
6830
6862
|
const host = proxy["plugin-opts"].host;
|
|
6831
6863
|
const version = proxy["plugin-opts"].version;
|
|
6832
|
-
if (!password)
|
|
6864
|
+
if (!password)
|
|
6865
|
+
return;
|
|
6833
6866
|
result.append(`,shadow-tls-password=${password}`);
|
|
6834
|
-
if (host)
|
|
6867
|
+
if (host)
|
|
6868
|
+
result.append(`,shadow-tls-sni=${host}`);
|
|
6835
6869
|
if (version) {
|
|
6836
6870
|
if (version < 2) {
|
|
6837
6871
|
throw new Error(`shadow-tls version ${version} is not supported`);
|
|
@@ -6840,7 +6874,8 @@ function appendShadowTLS2(result, proxy) {
|
|
|
6840
6874
|
}
|
|
6841
6875
|
appendTlsProfile(result, proxy);
|
|
6842
6876
|
const alpn = getLoonShadowTLSAlpn(proxy);
|
|
6843
|
-
if (alpn)
|
|
6877
|
+
if (alpn)
|
|
6878
|
+
result.append(`,alpn="${alpn}"`);
|
|
6844
6879
|
result.appendIfPresent(`,udp-port=${proxy["udp-port"]}`, "udp-port");
|
|
6845
6880
|
}
|
|
6846
6881
|
function appendReality(result, proxy) {
|
|
@@ -7423,7 +7458,8 @@ function getHttpUpgradeEarlyData(transportOpts, path) {
|
|
|
7423
7458
|
const httpUpgradeEd = getSafeEarlyDataValue(
|
|
7424
7459
|
transportOpts?.["_v2ray-http-upgrade-ed"]
|
|
7425
7460
|
);
|
|
7426
|
-
if (httpUpgradeEd !== "")
|
|
7461
|
+
if (httpUpgradeEd !== "")
|
|
7462
|
+
return httpUpgradeEd;
|
|
7427
7463
|
const pathEd = getSafeEarlyDataValue(
|
|
7428
7464
|
extractPathQueryParam(path || "/", "ed").value
|
|
7429
7465
|
);
|
|
@@ -7455,7 +7491,8 @@ function setWebSocketEarlyDataPath(path, transportOpts) {
|
|
|
7455
7491
|
return setPathQueryParam(path || "/", "ed", earlyData);
|
|
7456
7492
|
}
|
|
7457
7493
|
function getSafeEarlyDataValue(value) {
|
|
7458
|
-
if (value == null || `${value}` === "")
|
|
7494
|
+
if (value == null || `${value}` === "")
|
|
7495
|
+
return "";
|
|
7459
7496
|
return parseSafeIntegerValue(value) == null ? "" : `${value}`;
|
|
7460
7497
|
}
|
|
7461
7498
|
function parseIntegerLikeValue(value) {
|
|
@@ -7844,6 +7881,11 @@ function vless2(proxy) {
|
|
|
7844
7881
|
if (proxy["tls-fingerprint"]) {
|
|
7845
7882
|
pcs = `&pcs=${encodeURIComponent(proxy["tls-fingerprint"])}`;
|
|
7846
7883
|
}
|
|
7884
|
+
let vcn = "";
|
|
7885
|
+
const certNames = Array.isArray(proxy._vcn) ? proxy._vcn.join(",") : proxy["name-cert-verify"];
|
|
7886
|
+
if (Array.isArray(proxy._vcn) || certNames) {
|
|
7887
|
+
vcn = `&vcn=${encodeURIComponent(certNames)}`;
|
|
7888
|
+
}
|
|
7847
7889
|
let ech = "";
|
|
7848
7890
|
const echConfigList = buildXrayEchConfigListFromMihomo(
|
|
7849
7891
|
proxy["ech-opts"],
|
|
@@ -7995,7 +8037,7 @@ function vless2(proxy) {
|
|
|
7995
8037
|
}
|
|
7996
8038
|
return `vless://${proxy.uuid}@${proxy.server}:${proxy.port}?security=${encodeURIComponent(
|
|
7997
8039
|
security
|
|
7998
|
-
)}${vlessTransport}${packetEncoding}${alpn}${allowInsecure}${pcs}${ech}${h2}${sni}${fp}${flow}${sid}${spx}${pbk}${mode}${extra}${pqv}${encryption}#${encodeURIComponent(
|
|
8040
|
+
)}${vlessTransport}${packetEncoding}${alpn}${allowInsecure}${pcs}${vcn}${ech}${h2}${sni}${fp}${flow}${sid}${spx}${pbk}${mode}${extra}${pqv}${encryption}#${encodeURIComponent(
|
|
7999
8041
|
proxy.name
|
|
8000
8042
|
)}`;
|
|
8001
8043
|
}
|
|
@@ -8315,6 +8357,11 @@ function URI_Producer() {
|
|
|
8315
8357
|
proxy["tls-fingerprint"]
|
|
8316
8358
|
)}`;
|
|
8317
8359
|
}
|
|
8360
|
+
let trojanVcn = "";
|
|
8361
|
+
const trojanCertNames = Array.isArray(proxy._vcn) ? proxy._vcn.join(",") : proxy["name-cert-verify"];
|
|
8362
|
+
if (Array.isArray(proxy._vcn) || trojanCertNames) {
|
|
8363
|
+
trojanVcn = `&vcn=${encodeURIComponent(trojanCertNames)}`;
|
|
8364
|
+
}
|
|
8318
8365
|
let trojanAlpn = "";
|
|
8319
8366
|
if (proxy.alpn) {
|
|
8320
8367
|
trojanAlpn = `&alpn=${encodeURIComponent(
|
|
@@ -8351,7 +8398,7 @@ function URI_Producer() {
|
|
|
8351
8398
|
trojanMode = `&mode=${encodeURIComponent(proxy._mode)}`;
|
|
8352
8399
|
}
|
|
8353
8400
|
}
|
|
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(
|
|
8401
|
+
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
8402
|
proxy.name
|
|
8356
8403
|
)}`;
|
|
8357
8404
|
break;
|
|
@@ -8398,6 +8445,14 @@ function URI_Producer() {
|
|
|
8398
8445
|
if (proxy.tfo) {
|
|
8399
8446
|
hysteria2params.push(`fastopen=1`);
|
|
8400
8447
|
}
|
|
8448
|
+
const hysteria2Ech = buildXrayEchConfigListFromMihomo(
|
|
8449
|
+
proxy["ech-opts"]
|
|
8450
|
+
);
|
|
8451
|
+
if (hysteria2Ech) {
|
|
8452
|
+
hysteria2params.push(
|
|
8453
|
+
`ech=${encodeURIComponent(hysteria2Ech)}`
|
|
8454
|
+
);
|
|
8455
|
+
}
|
|
8401
8456
|
result = `hysteria2://${encodeURIComponent(proxy.password)}@${proxy.server}:${proxy.port}?${hysteria2params.join(
|
|
8402
8457
|
"&"
|
|
8403
8458
|
)}#${encodeURIComponent(proxy.name)}`;
|
|
@@ -8709,6 +8764,13 @@ function getQxHttpObfs(proxy) {
|
|
|
8709
8764
|
proxy._qx_obfs_http
|
|
8710
8765
|
) ? proxy._qx_obfs_http : "http";
|
|
8711
8766
|
}
|
|
8767
|
+
function appendTlsVerification(result, proxy) {
|
|
8768
|
+
const attr = isPresent2(proxy, "name-cert-verify") ? "name-cert-verify" : "skip-cert-verify";
|
|
8769
|
+
result.appendIfPresent(
|
|
8770
|
+
`,tls-verification=${proxy["name-cert-verify"] ?? !proxy["skip-cert-verify"]}`,
|
|
8771
|
+
attr
|
|
8772
|
+
);
|
|
8773
|
+
}
|
|
8712
8774
|
function shadowsocks3(proxy) {
|
|
8713
8775
|
const result = new Result(proxy);
|
|
8714
8776
|
const append = result.append.bind(result);
|
|
@@ -8767,8 +8829,10 @@ function shadowsocks3(proxy) {
|
|
|
8767
8829
|
}
|
|
8768
8830
|
} else if (proxy.plugin === "v2ray-plugin" && proxy["plugin-opts"].mode === "websocket") {
|
|
8769
8831
|
const opts = proxy["plugin-opts"];
|
|
8770
|
-
if (opts.tls)
|
|
8771
|
-
|
|
8832
|
+
if (opts.tls)
|
|
8833
|
+
append(`,obfs=wss`);
|
|
8834
|
+
else
|
|
8835
|
+
append(`,obfs=ws`);
|
|
8772
8836
|
} else {
|
|
8773
8837
|
throw new Error(`plugin is not supported`);
|
|
8774
8838
|
}
|
|
@@ -8799,10 +8863,7 @@ function shadowsocks3(proxy) {
|
|
|
8799
8863
|
`,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
|
|
8800
8864
|
"tls-fingerprint"
|
|
8801
8865
|
);
|
|
8802
|
-
|
|
8803
|
-
`,tls-verification=${!proxy["skip-cert-verify"]}`,
|
|
8804
|
-
"skip-cert-verify"
|
|
8805
|
-
);
|
|
8866
|
+
appendTlsVerification(result, proxy);
|
|
8806
8867
|
if (!isSSOverTls) {
|
|
8807
8868
|
appendIfPresent(`,tls-host=${proxy.sni}`, "sni");
|
|
8808
8869
|
}
|
|
@@ -8856,8 +8917,10 @@ function trojan3(proxy) {
|
|
|
8856
8917
|
append(`,password=${proxy.password}`);
|
|
8857
8918
|
if (isPresent2(proxy, "network")) {
|
|
8858
8919
|
if (proxy.network === "ws") {
|
|
8859
|
-
if (needTls(proxy))
|
|
8860
|
-
|
|
8920
|
+
if (needTls(proxy))
|
|
8921
|
+
append(`,obfs=wss`);
|
|
8922
|
+
else
|
|
8923
|
+
append(`,obfs=ws`);
|
|
8861
8924
|
appendIfPresent(
|
|
8862
8925
|
`,obfs-uri=${proxy["ws-opts"]?.path}`,
|
|
8863
8926
|
"ws-opts.path"
|
|
@@ -8891,10 +8954,7 @@ function trojan3(proxy) {
|
|
|
8891
8954
|
`,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
|
|
8892
8955
|
"tls-fingerprint"
|
|
8893
8956
|
);
|
|
8894
|
-
|
|
8895
|
-
`,tls-verification=${!proxy["skip-cert-verify"]}`,
|
|
8896
|
-
"skip-cert-verify"
|
|
8897
|
-
);
|
|
8957
|
+
appendTlsVerification(result, proxy);
|
|
8898
8958
|
appendIfPresent(`,tls-host=${proxy.sni}`, "sni");
|
|
8899
8959
|
}
|
|
8900
8960
|
appendIfPresent(`,fast-open=${proxy.tfo}`, "tfo");
|
|
@@ -8919,12 +8979,15 @@ function vmess3(proxy) {
|
|
|
8919
8979
|
}
|
|
8920
8980
|
if (isPresent2(proxy, "network")) {
|
|
8921
8981
|
if (proxy.network === "ws") {
|
|
8922
|
-
if (proxy.tls)
|
|
8923
|
-
|
|
8982
|
+
if (proxy.tls)
|
|
8983
|
+
append(`,obfs=wss`);
|
|
8984
|
+
else
|
|
8985
|
+
append(`,obfs=ws`);
|
|
8924
8986
|
} else if (proxy.network === "http") {
|
|
8925
8987
|
append(`,obfs=${getQxHttpObfs(proxy)}`);
|
|
8926
8988
|
} else if (["tcp"].includes(proxy.network)) {
|
|
8927
|
-
if (proxy.tls)
|
|
8989
|
+
if (proxy.tls)
|
|
8990
|
+
append(`,obfs=over-tls`);
|
|
8928
8991
|
} else if (!["tcp"].includes(proxy.network)) {
|
|
8929
8992
|
throw new Error(`network ${proxy.network} is unsupported`);
|
|
8930
8993
|
}
|
|
@@ -8939,7 +9002,8 @@ function vmess3(proxy) {
|
|
|
8939
9002
|
`${proxy.network}-opts.headers.Host`
|
|
8940
9003
|
);
|
|
8941
9004
|
} else {
|
|
8942
|
-
if (proxy.tls)
|
|
9005
|
+
if (proxy.tls)
|
|
9006
|
+
append(`,obfs=over-tls`);
|
|
8943
9007
|
}
|
|
8944
9008
|
if (needTls(proxy)) {
|
|
8945
9009
|
appendIfPresent(
|
|
@@ -8959,10 +9023,7 @@ function vmess3(proxy) {
|
|
|
8959
9023
|
`,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
|
|
8960
9024
|
"tls-fingerprint"
|
|
8961
9025
|
);
|
|
8962
|
-
|
|
8963
|
-
`,tls-verification=${!proxy["skip-cert-verify"]}`,
|
|
8964
|
-
"skip-cert-verify"
|
|
8965
|
-
);
|
|
9026
|
+
appendTlsVerification(result, proxy);
|
|
8966
9027
|
appendIfPresent(`,tls-host=${proxy.sni}`, "sni");
|
|
8967
9028
|
}
|
|
8968
9029
|
if (isPresent2(proxy, "aead")) {
|
|
@@ -8994,12 +9055,15 @@ function vless3(proxy) {
|
|
|
8994
9055
|
}
|
|
8995
9056
|
if (isPresent2(proxy, "network")) {
|
|
8996
9057
|
if (proxy.network === "ws") {
|
|
8997
|
-
if (proxy.tls)
|
|
8998
|
-
|
|
9058
|
+
if (proxy.tls)
|
|
9059
|
+
append(`,obfs=wss`);
|
|
9060
|
+
else
|
|
9061
|
+
append(`,obfs=ws`);
|
|
8999
9062
|
} else if (proxy.network === "http") {
|
|
9000
9063
|
append(`,obfs=${getQxHttpObfs(proxy)}`);
|
|
9001
9064
|
} else if (["tcp"].includes(proxy.network)) {
|
|
9002
|
-
if (proxy.tls)
|
|
9065
|
+
if (proxy.tls)
|
|
9066
|
+
append(`,obfs=over-tls`);
|
|
9003
9067
|
} else if (!["tcp"].includes(proxy.network)) {
|
|
9004
9068
|
throw new Error(`network ${proxy.network} is unsupported`);
|
|
9005
9069
|
}
|
|
@@ -9014,7 +9078,8 @@ function vless3(proxy) {
|
|
|
9014
9078
|
`${proxy.network}-opts.headers.Host`
|
|
9015
9079
|
);
|
|
9016
9080
|
} else {
|
|
9017
|
-
if (proxy.tls)
|
|
9081
|
+
if (proxy.tls)
|
|
9082
|
+
append(`,obfs=over-tls`);
|
|
9018
9083
|
}
|
|
9019
9084
|
if (needTls(proxy)) {
|
|
9020
9085
|
appendIfPresent(
|
|
@@ -9034,10 +9099,7 @@ function vless3(proxy) {
|
|
|
9034
9099
|
`,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
|
|
9035
9100
|
"tls-fingerprint"
|
|
9036
9101
|
);
|
|
9037
|
-
|
|
9038
|
-
`,tls-verification=${!proxy["skip-cert-verify"]}`,
|
|
9039
|
-
"skip-cert-verify"
|
|
9040
|
-
);
|
|
9102
|
+
appendTlsVerification(result, proxy);
|
|
9041
9103
|
appendIfPresent(`,tls-host=${proxy.sni}`, "sni");
|
|
9042
9104
|
}
|
|
9043
9105
|
appendIfPresent(`,vless-flow=${proxy.flow}`, "flow");
|
|
@@ -9081,10 +9143,7 @@ function anytls3(proxy) {
|
|
|
9081
9143
|
`,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
|
|
9082
9144
|
"tls-fingerprint"
|
|
9083
9145
|
);
|
|
9084
|
-
|
|
9085
|
-
`,tls-verification=${!proxy["skip-cert-verify"]}`,
|
|
9086
|
-
"skip-cert-verify"
|
|
9087
|
-
);
|
|
9146
|
+
appendTlsVerification(result, proxy);
|
|
9088
9147
|
appendIfPresent(`,tls-host=${proxy.sni}`, "sni");
|
|
9089
9148
|
appendIfPresent(`,fast-open=${proxy.tfo}`, "tfo");
|
|
9090
9149
|
appendIfPresent(`,udp-relay=${proxy.udp}`, "udp");
|
|
@@ -9124,10 +9183,7 @@ function http3(proxy) {
|
|
|
9124
9183
|
`,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
|
|
9125
9184
|
"tls-fingerprint"
|
|
9126
9185
|
);
|
|
9127
|
-
|
|
9128
|
-
`,tls-verification=${!proxy["skip-cert-verify"]}`,
|
|
9129
|
-
"skip-cert-verify"
|
|
9130
|
-
);
|
|
9186
|
+
appendTlsVerification(result, proxy);
|
|
9131
9187
|
appendIfPresent(`,tls-host=${proxy.sni}`, "sni");
|
|
9132
9188
|
}
|
|
9133
9189
|
appendIfPresent(`,fast-open=${proxy.tfo}`, "tfo");
|
|
@@ -9168,10 +9224,7 @@ function socks53(proxy) {
|
|
|
9168
9224
|
`,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
|
|
9169
9225
|
"tls-fingerprint"
|
|
9170
9226
|
);
|
|
9171
|
-
|
|
9172
|
-
`,tls-verification=${!proxy["skip-cert-verify"]}`,
|
|
9173
|
-
"skip-cert-verify"
|
|
9174
|
-
);
|
|
9227
|
+
appendTlsVerification(result, proxy);
|
|
9175
9228
|
appendIfPresent(`,tls-host=${proxy.sni}`, "sni");
|
|
9176
9229
|
}
|
|
9177
9230
|
appendIfPresent(`,fast-open=${proxy.tfo}`, "tfo");
|
|
@@ -9192,7 +9245,8 @@ function Shadowrocket_Producer() {
|
|
|
9192
9245
|
const type = "ALL";
|
|
9193
9246
|
const produce2 = (proxies, type2, opts = {}) => {
|
|
9194
9247
|
const list = proxies.filter((proxy) => {
|
|
9195
|
-
if (opts["include-unsupported-proxy"])
|
|
9248
|
+
if (opts["include-unsupported-proxy"])
|
|
9249
|
+
return true;
|
|
9196
9250
|
if (!supportsShadowsocksV2rayPluginMode(proxy, [
|
|
9197
9251
|
"websocket",
|
|
9198
9252
|
"quic",
|
|
@@ -9201,7 +9255,7 @@ function Shadowrocket_Producer() {
|
|
|
9201
9255
|
"grpc"
|
|
9202
9256
|
])) {
|
|
9203
9257
|
return false;
|
|
9204
|
-
} else if (proxy.type === "snell" && ![1, 2, 3, 4, 5].includes(proxy.version)) {
|
|
9258
|
+
} else if (proxy.type === "snell" && ![1, 2, 3, 4, 5, 6].includes(proxy.version)) {
|
|
9205
9259
|
return false;
|
|
9206
9260
|
} else if (hasShadowrocketSnellShadowTlsObfsConflict(proxy)) {
|
|
9207
9261
|
app_default.error(
|
|
@@ -9213,7 +9267,8 @@ function Shadowrocket_Producer() {
|
|
|
9213
9267
|
"sudoku",
|
|
9214
9268
|
"naive",
|
|
9215
9269
|
"openvpn",
|
|
9216
|
-
"gost-relay"
|
|
9270
|
+
"gost-relay",
|
|
9271
|
+
"shadowquic"
|
|
9217
9272
|
].includes(proxy.type)) {
|
|
9218
9273
|
return false;
|
|
9219
9274
|
} else if (["xhttp"].includes(proxy.network)) {
|
|
@@ -9224,6 +9279,7 @@ function Shadowrocket_Producer() {
|
|
|
9224
9279
|
}
|
|
9225
9280
|
return true;
|
|
9226
9281
|
}).map((proxy) => {
|
|
9282
|
+
restoreShadowTLSProxyOpts(proxy);
|
|
9227
9283
|
if (proxy.type === "vmess") {
|
|
9228
9284
|
if (isPresent2(proxy, "aead")) {
|
|
9229
9285
|
if (proxy.aead) {
|
|
@@ -9298,6 +9354,9 @@ function Shadowrocket_Producer() {
|
|
|
9298
9354
|
proxy.servername = proxy.sni;
|
|
9299
9355
|
}
|
|
9300
9356
|
}
|
|
9357
|
+
} else if (["anytls"].includes(proxy.type) && proxy.reuse != null && !proxy.reuse) {
|
|
9358
|
+
proxy["disable-reuse"] = true;
|
|
9359
|
+
delete proxy.reuse;
|
|
9301
9360
|
}
|
|
9302
9361
|
if (["vmess", "vless"].includes(proxy.type) && proxy.network === "http") {
|
|
9303
9362
|
let httpPath = proxy["http-opts"]?.path;
|
|
@@ -9431,6 +9490,8 @@ function Surfboard_Producer() {
|
|
|
9431
9490
|
return http4(proxy);
|
|
9432
9491
|
case "snell":
|
|
9433
9492
|
return snell2(proxy);
|
|
9493
|
+
case "tuic":
|
|
9494
|
+
return tuic2(proxy);
|
|
9434
9495
|
case "socks5":
|
|
9435
9496
|
return socks54(proxy);
|
|
9436
9497
|
case "hysteria2":
|
|
@@ -9452,6 +9513,33 @@ function Surfboard_Producer() {
|
|
|
9452
9513
|
};
|
|
9453
9514
|
return { produce: produce2 };
|
|
9454
9515
|
}
|
|
9516
|
+
function tuic2(proxy) {
|
|
9517
|
+
if (proxy.token?.length) {
|
|
9518
|
+
throw new Error(
|
|
9519
|
+
`Platform ${targetPlatform5} does not support proxy type ${proxy.type} v4`
|
|
9520
|
+
);
|
|
9521
|
+
}
|
|
9522
|
+
const result = new Result(proxy);
|
|
9523
|
+
result.append(`${proxy.name}=tuic-v5,${proxy.server},${proxy.port}`);
|
|
9524
|
+
result.appendIfPresent(`,uuid=${proxy.uuid}`, "uuid");
|
|
9525
|
+
result.appendIfPresent(`,password="${proxy.password}"`, "password");
|
|
9526
|
+
if (hasNonBlankValue2(proxy.alpn)) {
|
|
9527
|
+
result.append(
|
|
9528
|
+
`,alpn="${Array.isArray(proxy.alpn) ? proxy.alpn.join(",") : proxy.alpn}"`
|
|
9529
|
+
);
|
|
9530
|
+
}
|
|
9531
|
+
if (hasNonBlankValue2(proxy.ports)) {
|
|
9532
|
+
result.append(
|
|
9533
|
+
`,port-hopping="${String(proxy.ports).replace(/,/g, ";")}"`
|
|
9534
|
+
);
|
|
9535
|
+
}
|
|
9536
|
+
if (hasNonBlankValue2(proxy["hop-interval"])) {
|
|
9537
|
+
result.append(`,port-hopping-interval=${proxy["hop-interval"]}`);
|
|
9538
|
+
}
|
|
9539
|
+
appendTlsProxyParams2(result, proxy);
|
|
9540
|
+
result.appendIfPresent(`,udp-relay=${proxy.udp}`, "udp");
|
|
9541
|
+
return result.toString();
|
|
9542
|
+
}
|
|
9455
9543
|
function hysteria23(proxy) {
|
|
9456
9544
|
if (proxy.obfs && proxy.obfs !== "salamander" || proxy["obfs-password"] && proxy.obfs !== "salamander") {
|
|
9457
9545
|
throw new Error(`Surfboard Hysteria2 only supports salamander obfs`);
|
|
@@ -9681,17 +9769,27 @@ var ipVersionParser = (proxy, parsedProxy) => {
|
|
|
9681
9769
|
}
|
|
9682
9770
|
};
|
|
9683
9771
|
var domainResolverParser = (proxy, parsedProxy) => {
|
|
9684
|
-
if (proxy._domain_resolver) {
|
|
9772
|
+
if (!proxy._domain_resolver) {
|
|
9773
|
+
return;
|
|
9774
|
+
}
|
|
9775
|
+
if (typeof proxy._domain_resolver === "string") {
|
|
9776
|
+
parsedProxy.domain_resolver = {
|
|
9777
|
+
...parsedProxy.domain_resolver ?? {},
|
|
9778
|
+
server: proxy._domain_resolver
|
|
9779
|
+
};
|
|
9780
|
+
} else {
|
|
9685
9781
|
parsedProxy.domain_resolver = {
|
|
9686
|
-
...parsedProxy.domain_resolver,
|
|
9782
|
+
...parsedProxy.domain_resolver ?? {},
|
|
9687
9783
|
...proxy._domain_resolver
|
|
9688
9784
|
};
|
|
9689
9785
|
}
|
|
9690
9786
|
};
|
|
9691
9787
|
var hasControlHTTPClient = (proxy) => {
|
|
9692
9788
|
const value = proxy["control-http-client"];
|
|
9693
|
-
if (value === void 0 || value === null)
|
|
9694
|
-
|
|
9789
|
+
if (value === void 0 || value === null)
|
|
9790
|
+
return false;
|
|
9791
|
+
if (typeof value === "string")
|
|
9792
|
+
return value.trim() !== "";
|
|
9695
9793
|
if (isPlainObject(value)) {
|
|
9696
9794
|
return Object.values(value).some(
|
|
9697
9795
|
(item) => item !== void 0 && item !== null && item !== ""
|
|
@@ -9713,13 +9811,18 @@ var networkParser = (proxy, parsedProxy) => {
|
|
|
9713
9811
|
};
|
|
9714
9812
|
var tfoParser = (proxy, parsedProxy) => {
|
|
9715
9813
|
parsedProxy.tcp_fast_open = false;
|
|
9716
|
-
if (proxy.tfo)
|
|
9717
|
-
|
|
9718
|
-
if (proxy
|
|
9719
|
-
|
|
9814
|
+
if (proxy.tfo)
|
|
9815
|
+
parsedProxy.tcp_fast_open = true;
|
|
9816
|
+
if (proxy.tcp_fast_open)
|
|
9817
|
+
parsedProxy.tcp_fast_open = true;
|
|
9818
|
+
if (proxy["tcp-fast-open"])
|
|
9819
|
+
parsedProxy.tcp_fast_open = true;
|
|
9820
|
+
if (!parsedProxy.tcp_fast_open)
|
|
9821
|
+
delete parsedProxy.tcp_fast_open;
|
|
9720
9822
|
};
|
|
9721
9823
|
var smuxParser = (smux, proxy) => {
|
|
9722
|
-
if (!smux || !smux.enabled)
|
|
9824
|
+
if (!smux || !smux.enabled)
|
|
9825
|
+
return;
|
|
9723
9826
|
proxy.multiplex = { enabled: true };
|
|
9724
9827
|
proxy.multiplex.protocol = smux.protocol;
|
|
9725
9828
|
if (smux["max-connections"])
|
|
@@ -9731,7 +9834,8 @@ var smuxParser = (smux, proxy) => {
|
|
|
9731
9834
|
proxy.multiplex.max_streams = parseInt(`${smux["max-streams"]}`, 10);
|
|
9732
9835
|
if (smux["min-streams"])
|
|
9733
9836
|
proxy.multiplex.min_streams = parseInt(`${smux["min-streams"]}`, 10);
|
|
9734
|
-
if (smux.padding)
|
|
9837
|
+
if (smux.padding)
|
|
9838
|
+
proxy.multiplex.padding = true;
|
|
9735
9839
|
if (smux["brutal-opts"]?.up || smux["brutal-opts"]?.down) {
|
|
9736
9840
|
proxy.multiplex.brutal = {
|
|
9737
9841
|
enabled: true
|
|
@@ -9759,20 +9863,25 @@ var wsParser = (proxy, parsedProxy) => {
|
|
|
9759
9863
|
} = proxy["ws-opts"];
|
|
9760
9864
|
transport.early_data_header_name = early_data_header_name;
|
|
9761
9865
|
transport.max_early_data = max_early_data ? parseInt(max_early_data, 10) : void 0;
|
|
9762
|
-
if (wsPath !== "")
|
|
9866
|
+
if (wsPath !== "")
|
|
9867
|
+
transport.path = `${wsPath}`;
|
|
9763
9868
|
if (Object.keys(wsHeaders).length > 0) {
|
|
9764
9869
|
const headers = {};
|
|
9765
9870
|
for (const key of Object.keys(wsHeaders)) {
|
|
9766
9871
|
let value = wsHeaders[key];
|
|
9767
|
-
if (value === "")
|
|
9768
|
-
|
|
9769
|
-
if (value
|
|
9872
|
+
if (value === "")
|
|
9873
|
+
continue;
|
|
9874
|
+
if (!Array.isArray(value))
|
|
9875
|
+
value = [`${value}`];
|
|
9876
|
+
if (value.length > 0)
|
|
9877
|
+
headers[key] = value;
|
|
9770
9878
|
}
|
|
9771
9879
|
const { Host: wsHost } = headers;
|
|
9772
9880
|
if (wsHost.length === 1)
|
|
9773
9881
|
for (const item of `Host:${wsHost[0]}`.split("\n")) {
|
|
9774
9882
|
const [key, value] = item.split(":");
|
|
9775
|
-
if (value.trim() === "")
|
|
9883
|
+
if (value.trim() === "")
|
|
9884
|
+
continue;
|
|
9776
9885
|
headers[key.trim()] = value.trim().split(",");
|
|
9777
9886
|
}
|
|
9778
9887
|
transport.headers = headers;
|
|
@@ -9782,15 +9891,19 @@ var wsParser = (proxy, parsedProxy) => {
|
|
|
9782
9891
|
const headers = {};
|
|
9783
9892
|
for (const key of Object.keys(proxy["ws-headers"])) {
|
|
9784
9893
|
let value = proxy["ws-headers"][key];
|
|
9785
|
-
if (value === "")
|
|
9786
|
-
|
|
9787
|
-
if (value
|
|
9894
|
+
if (value === "")
|
|
9895
|
+
continue;
|
|
9896
|
+
if (!Array.isArray(value))
|
|
9897
|
+
value = [`${value}`];
|
|
9898
|
+
if (value.length > 0)
|
|
9899
|
+
headers[key] = value;
|
|
9788
9900
|
}
|
|
9789
9901
|
const { Host: wsHost } = headers;
|
|
9790
9902
|
if (wsHost.length === 1)
|
|
9791
9903
|
for (const item of `Host:${wsHost[0]}`.split("\n")) {
|
|
9792
9904
|
const [key, value] = item.split(":");
|
|
9793
|
-
if (value.trim() === "")
|
|
9905
|
+
if (value.trim() === "")
|
|
9906
|
+
continue;
|
|
9794
9907
|
headers[key.trim()] = value.trim().split(",");
|
|
9795
9908
|
}
|
|
9796
9909
|
for (const key of Object.keys(headers))
|
|
@@ -9814,13 +9927,15 @@ var wsParser = (proxy, parsedProxy) => {
|
|
|
9814
9927
|
transport.host = transport.headers.Host[0];
|
|
9815
9928
|
delete transport.headers.Host;
|
|
9816
9929
|
}
|
|
9817
|
-
if (transport.max_early_data)
|
|
9930
|
+
if (transport.max_early_data)
|
|
9931
|
+
delete transport.max_early_data;
|
|
9818
9932
|
if (transport.early_data_header_name)
|
|
9819
9933
|
delete transport.early_data_header_name;
|
|
9820
9934
|
}
|
|
9821
9935
|
for (const key of Object.keys(transport.headers)) {
|
|
9822
9936
|
const value = transport.headers[key];
|
|
9823
|
-
if (value.length === 1)
|
|
9937
|
+
if (value.length === 1)
|
|
9938
|
+
transport.headers[key] = value[0];
|
|
9824
9939
|
}
|
|
9825
9940
|
parsedProxy.transport = transport;
|
|
9826
9941
|
};
|
|
@@ -9832,43 +9947,52 @@ var h1Parser = (proxy, parsedProxy) => {
|
|
|
9832
9947
|
path: h1Path = "",
|
|
9833
9948
|
headers: h1Headers = {}
|
|
9834
9949
|
} = proxy["http-opts"];
|
|
9835
|
-
if (method !== "")
|
|
9950
|
+
if (method !== "")
|
|
9951
|
+
transport.method = method;
|
|
9836
9952
|
if (Array.isArray(h1Path)) {
|
|
9837
9953
|
transport.path = `${h1Path[0]}`;
|
|
9838
|
-
} else if (h1Path !== "")
|
|
9954
|
+
} else if (h1Path !== "")
|
|
9955
|
+
transport.path = `${h1Path}`;
|
|
9839
9956
|
for (const key of Object.keys(h1Headers)) {
|
|
9840
9957
|
let value = h1Headers[key];
|
|
9841
|
-
if (value === "")
|
|
9958
|
+
if (value === "")
|
|
9959
|
+
continue;
|
|
9842
9960
|
if (key.toLowerCase() === "host") {
|
|
9843
9961
|
let host = value;
|
|
9844
9962
|
if (!Array.isArray(host))
|
|
9845
9963
|
host = `${host}`.split(",").map((i) => i.trim());
|
|
9846
|
-
if (host.length > 0)
|
|
9964
|
+
if (host.length > 0)
|
|
9965
|
+
transport.host = host;
|
|
9847
9966
|
continue;
|
|
9848
9967
|
}
|
|
9849
9968
|
if (!Array.isArray(value))
|
|
9850
9969
|
value = `${value}`.split(",").map((i) => i.trim());
|
|
9851
|
-
if (value.length > 0)
|
|
9970
|
+
if (value.length > 0)
|
|
9971
|
+
transport.headers[key] = value;
|
|
9852
9972
|
}
|
|
9853
9973
|
}
|
|
9854
9974
|
if (proxy["http-host"] && proxy["http-host"] !== "") {
|
|
9855
9975
|
let host = proxy["http-host"];
|
|
9856
9976
|
if (!Array.isArray(host))
|
|
9857
9977
|
host = `${host}`.split(",").map((i) => i.trim());
|
|
9858
|
-
if (host.length > 0)
|
|
9978
|
+
if (host.length > 0)
|
|
9979
|
+
transport.host = host;
|
|
9859
9980
|
}
|
|
9860
9981
|
if (proxy["http-path"] && proxy["http-path"] !== "") {
|
|
9861
9982
|
const path = proxy["http-path"];
|
|
9862
9983
|
if (Array.isArray(path)) {
|
|
9863
9984
|
transport.path = `${path[0]}`;
|
|
9864
|
-
} else if (path !== "")
|
|
9985
|
+
} else if (path !== "")
|
|
9986
|
+
transport.path = `${path}`;
|
|
9865
9987
|
}
|
|
9866
9988
|
if (parsedProxy.tls.insecure)
|
|
9867
9989
|
parsedProxy.tls.server_name = transport.host[0];
|
|
9868
|
-
if (transport.host?.length === 1)
|
|
9990
|
+
if (transport.host?.length === 1)
|
|
9991
|
+
transport.host = transport.host[0];
|
|
9869
9992
|
for (const key of Object.keys(transport.headers)) {
|
|
9870
9993
|
const value = transport.headers[key];
|
|
9871
|
-
if (value.length === 1)
|
|
9994
|
+
if (value.length === 1)
|
|
9995
|
+
transport.headers[key] = value[0];
|
|
9872
9996
|
}
|
|
9873
9997
|
parsedProxy.transport = transport;
|
|
9874
9998
|
};
|
|
@@ -9876,25 +10000,29 @@ var h2Parser = (proxy, parsedProxy) => {
|
|
|
9876
10000
|
const transport = { type: "http" };
|
|
9877
10001
|
if (proxy["h2-opts"]) {
|
|
9878
10002
|
let { host = "", path = "" } = proxy["h2-opts"];
|
|
9879
|
-
if (path !== "")
|
|
10003
|
+
if (path !== "")
|
|
10004
|
+
transport.path = `${path}`;
|
|
9880
10005
|
if (host !== "") {
|
|
9881
10006
|
if (!Array.isArray(host))
|
|
9882
10007
|
host = `${host}`.split(",").map((i) => i.trim());
|
|
9883
|
-
if (host.length > 0)
|
|
10008
|
+
if (host.length > 0)
|
|
10009
|
+
transport.host = host;
|
|
9884
10010
|
}
|
|
9885
10011
|
}
|
|
9886
10012
|
if (proxy["h2-host"] && proxy["h2-host"] !== "") {
|
|
9887
10013
|
let host = proxy["h2-host"];
|
|
9888
10014
|
if (!Array.isArray(host))
|
|
9889
10015
|
host = `${host}`.split(",").map((i) => i.trim());
|
|
9890
|
-
if (host.length > 0)
|
|
10016
|
+
if (host.length > 0)
|
|
10017
|
+
transport.host = host;
|
|
9891
10018
|
}
|
|
9892
10019
|
if (proxy["h2-path"] && proxy["h2-path"] !== "")
|
|
9893
10020
|
transport.path = `${proxy["h2-path"]}`;
|
|
9894
10021
|
parsedProxy.tls.enabled = true;
|
|
9895
10022
|
if (parsedProxy.tls.insecure)
|
|
9896
10023
|
parsedProxy.tls.server_name = transport.host[0];
|
|
9897
|
-
if (transport.host.length === 1)
|
|
10024
|
+
if (transport.host.length === 1)
|
|
10025
|
+
transport.host = transport.host[0];
|
|
9898
10026
|
parsedProxy.transport = transport;
|
|
9899
10027
|
};
|
|
9900
10028
|
var grpcParser = (proxy, parsedProxy) => {
|
|
@@ -9911,13 +10039,16 @@ var normalizePemLines = (value, label) => {
|
|
|
9911
10039
|
const lines = [];
|
|
9912
10040
|
for (const item of items) {
|
|
9913
10041
|
const normalized = `${item}`.trim().replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n");
|
|
9914
|
-
if (normalized === "")
|
|
10042
|
+
if (normalized === "")
|
|
10043
|
+
continue;
|
|
9915
10044
|
for (const line of normalized.split(/\r?\n/)) {
|
|
9916
10045
|
const trimmed = line.trim();
|
|
9917
|
-
if (trimmed !== "")
|
|
10046
|
+
if (trimmed !== "")
|
|
10047
|
+
lines.push(trimmed);
|
|
9918
10048
|
}
|
|
9919
10049
|
}
|
|
9920
|
-
if (lines.length === 0)
|
|
10050
|
+
if (lines.length === 0)
|
|
10051
|
+
return void 0;
|
|
9921
10052
|
if (lines.some((line) => /^-----BEGIN [A-Za-z0-9 -]+-----$/.test(line))) {
|
|
9922
10053
|
return lines;
|
|
9923
10054
|
}
|
|
@@ -9937,24 +10068,34 @@ var singBoxUtlsFingerprints = [
|
|
|
9937
10068
|
];
|
|
9938
10069
|
var getSingBoxUtlsFingerprint = (value) => {
|
|
9939
10070
|
const fingerprint = `${value || ""}`.trim().toLowerCase();
|
|
9940
|
-
if (singBoxUtlsFingerprints.includes(fingerprint))
|
|
10071
|
+
if (singBoxUtlsFingerprints.includes(fingerprint))
|
|
10072
|
+
return fingerprint;
|
|
9941
10073
|
};
|
|
9942
10074
|
var tlsParser = (proxy, parsedProxy) => {
|
|
9943
|
-
if (proxy.tls)
|
|
10075
|
+
if (proxy.tls)
|
|
10076
|
+
parsedProxy.tls.enabled = true;
|
|
9944
10077
|
if (proxy.servername && proxy.servername !== "")
|
|
9945
10078
|
parsedProxy.tls.server_name = proxy.servername;
|
|
9946
10079
|
if (proxy.peer && proxy.peer !== "")
|
|
9947
10080
|
parsedProxy.tls.server_name = proxy.peer;
|
|
9948
|
-
if (proxy.sni && proxy.sni !== "")
|
|
9949
|
-
|
|
9950
|
-
if (proxy
|
|
9951
|
-
|
|
10081
|
+
if (proxy.sni && proxy.sni !== "")
|
|
10082
|
+
parsedProxy.tls.server_name = proxy.sni;
|
|
10083
|
+
if (proxy["skip-cert-verify"])
|
|
10084
|
+
parsedProxy.tls.insecure = true;
|
|
10085
|
+
if (proxy.insecure)
|
|
10086
|
+
parsedProxy.tls.insecure = true;
|
|
10087
|
+
if (proxy["disable-sni"])
|
|
10088
|
+
parsedProxy.tls.disable_sni = true;
|
|
9952
10089
|
if (typeof proxy.alpn === "string") {
|
|
9953
10090
|
parsedProxy.tls.alpn = [proxy.alpn];
|
|
9954
|
-
} else if (Array.isArray(proxy.alpn))
|
|
9955
|
-
|
|
9956
|
-
if (proxy.
|
|
9957
|
-
|
|
10091
|
+
} else if (Array.isArray(proxy.alpn))
|
|
10092
|
+
parsedProxy.tls.alpn = proxy.alpn;
|
|
10093
|
+
if (proxy.ca)
|
|
10094
|
+
parsedProxy.tls.certificate_path = `${proxy.ca}`;
|
|
10095
|
+
if (proxy.ca_str)
|
|
10096
|
+
parsedProxy.tls.certificate = [proxy.ca_str];
|
|
10097
|
+
if (proxy["ca-str"])
|
|
10098
|
+
parsedProxy.tls.certificate = [proxy["ca-str"]];
|
|
9958
10099
|
if (proxy["reality-opts"]) {
|
|
9959
10100
|
parsedProxy.tls.reality = { enabled: true };
|
|
9960
10101
|
if (proxy["reality-opts"]["public-key"])
|
|
@@ -9982,7 +10123,8 @@ var tlsParser = (proxy, parsedProxy) => {
|
|
|
9982
10123
|
const echOptsConfig = proxy["ech-opts"].config;
|
|
9983
10124
|
if (Array.isArray(echOptsConfig) || typeof echOptsConfig === "string") {
|
|
9984
10125
|
const config = normalizePemLines(echOptsConfig, "ECH CONFIGS");
|
|
9985
|
-
if (config)
|
|
10126
|
+
if (config)
|
|
10127
|
+
parsedProxy.tls.ech.config = config;
|
|
9986
10128
|
}
|
|
9987
10129
|
parsedProxy.tls.ech.query_server_name = proxy["ech-opts"]["query-server-name"];
|
|
9988
10130
|
parsedProxy.tls.ech.config_path = proxy["ech-opts"]["config-path"];
|
|
@@ -9993,7 +10135,8 @@ var tlsParser = (proxy, parsedProxy) => {
|
|
|
9993
10135
|
if (proxy._curve_preferences && Array.isArray(proxy._curve_preferences)) {
|
|
9994
10136
|
parsedProxy.tls.curve_preferences = proxy._curve_preferences;
|
|
9995
10137
|
}
|
|
9996
|
-
if (proxy["_fragment"])
|
|
10138
|
+
if (proxy["_fragment"])
|
|
10139
|
+
parsedProxy.tls.fragment = !!proxy["_fragment"];
|
|
9997
10140
|
if (proxy["_fragment_fallback_delay"])
|
|
9998
10141
|
parsedProxy.tls.fragment_fallback_delay = proxy["_fragment_fallback_delay"];
|
|
9999
10142
|
if (proxy["_record_fragment"])
|
|
@@ -10008,10 +10151,12 @@ var tlsParser = (proxy, parsedProxy) => {
|
|
|
10008
10151
|
parsedProxy.tls.client_certificate = proxy["_client_certificate"];
|
|
10009
10152
|
if (proxy["_client_certificate_path"])
|
|
10010
10153
|
parsedProxy.tls.client_certificate_path = proxy["_client_certificate_path"];
|
|
10011
|
-
if (proxy["_client_key"])
|
|
10154
|
+
if (proxy["_client_key"])
|
|
10155
|
+
parsedProxy.tls.client_key = proxy["_client_key"];
|
|
10012
10156
|
if (proxy["_client_key_path"])
|
|
10013
10157
|
parsedProxy.tls.client_key_path = proxy["_client_key_path"];
|
|
10014
|
-
if (!parsedProxy.tls.enabled)
|
|
10158
|
+
if (!parsedProxy.tls.enabled)
|
|
10159
|
+
delete parsedProxy.tls;
|
|
10015
10160
|
};
|
|
10016
10161
|
var sshParser = (proxy = {}) => {
|
|
10017
10162
|
const parsedProxy = {
|
|
@@ -10022,9 +10167,12 @@ var sshParser = (proxy = {}) => {
|
|
|
10022
10167
|
};
|
|
10023
10168
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10024
10169
|
throw "invalid port";
|
|
10025
|
-
if (proxy.username)
|
|
10026
|
-
|
|
10027
|
-
if (proxy
|
|
10170
|
+
if (proxy.username)
|
|
10171
|
+
parsedProxy.user = proxy.username;
|
|
10172
|
+
if (proxy.password)
|
|
10173
|
+
parsedProxy.password = proxy.password;
|
|
10174
|
+
if (proxy["privateKey"])
|
|
10175
|
+
parsedProxy.private_key_path = proxy["privateKey"];
|
|
10028
10176
|
if (proxy["private-key"])
|
|
10029
10177
|
parsedProxy.private_key_path = proxy["private-key"];
|
|
10030
10178
|
if (proxy["private-key-passphrase"])
|
|
@@ -10035,10 +10183,12 @@ var sshParser = (proxy = {}) => {
|
|
|
10035
10183
|
proxy["server-fingerprint"].split(" ")[0]
|
|
10036
10184
|
];
|
|
10037
10185
|
}
|
|
10038
|
-
if (proxy["host-key"])
|
|
10186
|
+
if (proxy["host-key"])
|
|
10187
|
+
parsedProxy.host_key = proxy["host-key"];
|
|
10039
10188
|
if (proxy["host-key-algorithms"])
|
|
10040
10189
|
parsedProxy.host_key_algorithms = proxy["host-key-algorithms"];
|
|
10041
|
-
if (proxy["fast-open"])
|
|
10190
|
+
if (proxy["fast-open"])
|
|
10191
|
+
parsedProxy.udp_fragment = true;
|
|
10042
10192
|
tfoParser(proxy, parsedProxy);
|
|
10043
10193
|
detourParser(proxy, parsedProxy);
|
|
10044
10194
|
ipVersionParser(proxy, parsedProxy);
|
|
@@ -10055,8 +10205,10 @@ var httpParser = (proxy = {}) => {
|
|
|
10055
10205
|
};
|
|
10056
10206
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10057
10207
|
throw "invalid port";
|
|
10058
|
-
if (proxy.username)
|
|
10059
|
-
|
|
10208
|
+
if (proxy.username)
|
|
10209
|
+
parsedProxy.username = proxy.username;
|
|
10210
|
+
if (proxy.password)
|
|
10211
|
+
parsedProxy.password = proxy.password;
|
|
10060
10212
|
if (proxy.headers) {
|
|
10061
10213
|
parsedProxy.headers = {};
|
|
10062
10214
|
for (const k of Object.keys(proxy.headers)) {
|
|
@@ -10065,7 +10217,8 @@ var httpParser = (proxy = {}) => {
|
|
|
10065
10217
|
if (Object.keys(parsedProxy.headers).length === 0)
|
|
10066
10218
|
delete parsedProxy.headers;
|
|
10067
10219
|
}
|
|
10068
|
-
if (proxy["fast-open"])
|
|
10220
|
+
if (proxy["fast-open"])
|
|
10221
|
+
parsedProxy.udp_fragment = true;
|
|
10069
10222
|
tfoParser(proxy, parsedProxy);
|
|
10070
10223
|
detourParser(proxy, parsedProxy);
|
|
10071
10224
|
tlsParser(proxy, parsedProxy);
|
|
@@ -10083,16 +10236,20 @@ var socks5Parser = (proxy = {}) => {
|
|
|
10083
10236
|
};
|
|
10084
10237
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10085
10238
|
throw "invalid port";
|
|
10086
|
-
if (proxy.username)
|
|
10087
|
-
|
|
10088
|
-
if (proxy.
|
|
10239
|
+
if (proxy.username)
|
|
10240
|
+
parsedProxy.username = proxy.username;
|
|
10241
|
+
if (proxy.password)
|
|
10242
|
+
parsedProxy.password = proxy.password;
|
|
10243
|
+
if (proxy.uot)
|
|
10244
|
+
parsedProxy.udp_over_tcp = true;
|
|
10089
10245
|
if (proxy["udp-over-tcp"]) {
|
|
10090
10246
|
parsedProxy.udp_over_tcp = {
|
|
10091
10247
|
enabled: true,
|
|
10092
10248
|
version: !proxy["udp-over-tcp-version"] || proxy["udp-over-tcp-version"] === 1 ? 1 : 2
|
|
10093
10249
|
};
|
|
10094
10250
|
}
|
|
10095
|
-
if (proxy["fast-open"])
|
|
10251
|
+
if (proxy["fast-open"])
|
|
10252
|
+
parsedProxy.udp_fragment = true;
|
|
10096
10253
|
networkParser(proxy, parsedProxy);
|
|
10097
10254
|
tfoParser(proxy, parsedProxy);
|
|
10098
10255
|
detourParser(proxy, parsedProxy);
|
|
@@ -10109,7 +10266,8 @@ var shadowTLSParser = (proxy = {}) => {
|
|
|
10109
10266
|
password: proxy.password,
|
|
10110
10267
|
detour: getShadowTLSTag(proxy)
|
|
10111
10268
|
};
|
|
10112
|
-
if (proxy.uot)
|
|
10269
|
+
if (proxy.uot)
|
|
10270
|
+
ssPart.udp_over_tcp = true;
|
|
10113
10271
|
if (proxy["udp-over-tcp"]) {
|
|
10114
10272
|
ssPart.udp_over_tcp = {
|
|
10115
10273
|
enabled: true,
|
|
@@ -10143,11 +10301,13 @@ var normalizeALPN = (alpn) => {
|
|
|
10143
10301
|
if (typeof alpn === "string") {
|
|
10144
10302
|
return alpn.split(",").map((item) => item.trim()).filter((item) => item !== "");
|
|
10145
10303
|
}
|
|
10146
|
-
if (Array.isArray(alpn))
|
|
10304
|
+
if (Array.isArray(alpn))
|
|
10305
|
+
return alpn;
|
|
10147
10306
|
return void 0;
|
|
10148
10307
|
};
|
|
10149
10308
|
var shadowTLSOutboundParser = (proxy = {}, pluginOpts) => {
|
|
10150
|
-
if (!pluginOpts)
|
|
10309
|
+
if (!pluginOpts)
|
|
10310
|
+
throw new Error("shadow-tls plugin options are missing");
|
|
10151
10311
|
const fingerprint = getSingBoxUtlsFingerprint(proxy["client-fingerprint"]);
|
|
10152
10312
|
const stPart = {
|
|
10153
10313
|
tag: getShadowTLSTag(proxy),
|
|
@@ -10161,6 +10321,8 @@ var shadowTLSOutboundParser = (proxy = {}, pluginOpts) => {
|
|
|
10161
10321
|
server_name: pluginOpts.host
|
|
10162
10322
|
}
|
|
10163
10323
|
};
|
|
10324
|
+
if (proxy["skip-cert-verify"])
|
|
10325
|
+
stPart.tls.insecure = true;
|
|
10164
10326
|
if (fingerprint) {
|
|
10165
10327
|
stPart.tls.utls = {
|
|
10166
10328
|
enabled: true,
|
|
@@ -10170,8 +10332,10 @@ var shadowTLSOutboundParser = (proxy = {}, pluginOpts) => {
|
|
|
10170
10332
|
if (stPart.server_port < 0 || stPart.server_port > 65535)
|
|
10171
10333
|
throw "\u7AEF\u53E3\u503C\u975E\u6CD5";
|
|
10172
10334
|
const alpn = normalizeALPN(pluginOpts.alpn) ?? normalizeALPN(proxy.alpn);
|
|
10173
|
-
if (alpn)
|
|
10174
|
-
|
|
10335
|
+
if (alpn)
|
|
10336
|
+
stPart.tls.alpn = alpn;
|
|
10337
|
+
if (proxy["fast-open"] === true)
|
|
10338
|
+
stPart.udp_fragment = true;
|
|
10175
10339
|
tfoParser(proxy, stPart);
|
|
10176
10340
|
detourParser(proxy, stPart);
|
|
10177
10341
|
ipVersionParser(proxy, stPart);
|
|
@@ -10189,14 +10353,16 @@ var ssParser = (proxy = {}) => {
|
|
|
10189
10353
|
};
|
|
10190
10354
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10191
10355
|
throw "invalid port";
|
|
10192
|
-
if (proxy.uot)
|
|
10356
|
+
if (proxy.uot)
|
|
10357
|
+
parsedProxy.udp_over_tcp = true;
|
|
10193
10358
|
if (proxy["udp-over-tcp"]) {
|
|
10194
10359
|
parsedProxy.udp_over_tcp = {
|
|
10195
10360
|
enabled: true,
|
|
10196
10361
|
version: !proxy["udp-over-tcp-version"] || proxy["udp-over-tcp-version"] === 1 ? 1 : 2
|
|
10197
10362
|
};
|
|
10198
10363
|
}
|
|
10199
|
-
if (proxy["fast-open"])
|
|
10364
|
+
if (proxy["fast-open"])
|
|
10365
|
+
parsedProxy.udp_fragment = true;
|
|
10200
10366
|
networkParser(proxy, parsedProxy);
|
|
10201
10367
|
tfoParser(proxy, parsedProxy);
|
|
10202
10368
|
detourParser(proxy, parsedProxy);
|
|
@@ -10226,12 +10392,15 @@ var ssParser = (proxy = {}) => {
|
|
|
10226
10392
|
}
|
|
10227
10393
|
if (proxy.plugin === "v2ray-plugin") {
|
|
10228
10394
|
parsedProxy.plugin = "v2ray-plugin";
|
|
10229
|
-
if (proxy["ws-host"])
|
|
10230
|
-
|
|
10395
|
+
if (proxy["ws-host"])
|
|
10396
|
+
proxy["plugin-opts"].host = proxy["ws-host"];
|
|
10397
|
+
if (proxy["ws-path"])
|
|
10398
|
+
proxy["plugin-opts"].path = proxy["ws-path"];
|
|
10231
10399
|
Object.keys(proxy["plugin-opts"]).forEach((k) => {
|
|
10232
10400
|
switch (k) {
|
|
10233
10401
|
case "tls":
|
|
10234
|
-
if (proxy["plugin-opts"].tls)
|
|
10402
|
+
if (proxy["plugin-opts"].tls)
|
|
10403
|
+
optArr.push("tls");
|
|
10235
10404
|
break;
|
|
10236
10405
|
case "host":
|
|
10237
10406
|
optArr.push(`host=${proxy["plugin-opts"].host}`);
|
|
@@ -10250,7 +10419,8 @@ var ssParser = (proxy = {}) => {
|
|
|
10250
10419
|
const mux = normalizePluginMuxValue(
|
|
10251
10420
|
proxy["plugin-opts"].mux
|
|
10252
10421
|
);
|
|
10253
|
-
if (mux)
|
|
10422
|
+
if (mux)
|
|
10423
|
+
parsedProxy.multiplex = { enabled: true };
|
|
10254
10424
|
optArr.push(`mux=${mux}`);
|
|
10255
10425
|
break;
|
|
10256
10426
|
}
|
|
@@ -10276,10 +10446,12 @@ var ssrParser = (proxy = {}) => {
|
|
|
10276
10446
|
};
|
|
10277
10447
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10278
10448
|
throw "invalid port";
|
|
10279
|
-
if (proxy["obfs-param"])
|
|
10449
|
+
if (proxy["obfs-param"])
|
|
10450
|
+
parsedProxy.obfs_param = proxy["obfs-param"];
|
|
10280
10451
|
if (proxy["protocol-param"] && proxy["protocol-param"] !== "")
|
|
10281
10452
|
parsedProxy.protocol_param = proxy["protocol-param"];
|
|
10282
|
-
if (proxy["fast-open"])
|
|
10453
|
+
if (proxy["fast-open"])
|
|
10454
|
+
parsedProxy.udp_fragment = true;
|
|
10283
10455
|
networkParser(proxy, parsedProxy);
|
|
10284
10456
|
tfoParser(proxy, parsedProxy);
|
|
10285
10457
|
detourParser(proxy, parsedProxy);
|
|
@@ -10289,19 +10461,23 @@ var ssrParser = (proxy = {}) => {
|
|
|
10289
10461
|
return parsedProxy;
|
|
10290
10462
|
};
|
|
10291
10463
|
var getSnellVersion = (version) => {
|
|
10292
|
-
if (version == null)
|
|
10464
|
+
if (version == null)
|
|
10465
|
+
return void 0;
|
|
10293
10466
|
const normalized = `${version}`.trim();
|
|
10294
|
-
if (!/^\d+$/.test(normalized))
|
|
10467
|
+
if (!/^\d+$/.test(normalized))
|
|
10468
|
+
return NaN;
|
|
10295
10469
|
return parseInt(normalized, 10);
|
|
10296
10470
|
};
|
|
10297
|
-
var snellParser = (proxy = {}) => {
|
|
10471
|
+
var snellParser = (proxy = {}, includeUnsupportedProxy = false) => {
|
|
10298
10472
|
const version = getSnellVersion(proxy.version);
|
|
10299
10473
|
const shadowTLSPluginOpts = getShadowTLSPluginOpts(proxy);
|
|
10300
|
-
|
|
10474
|
+
const supportedVersions = includeUnsupportedProxy ? [1, 2, 3, 4, 5, 6] : [4, 5, 6];
|
|
10475
|
+
if (version != null && (!supportedVersions.includes(version) || Number.isNaN(version))) {
|
|
10301
10476
|
throw new Error(
|
|
10302
10477
|
`Platform sing-box does not support snell version ${proxy.version}`
|
|
10303
10478
|
);
|
|
10304
10479
|
}
|
|
10480
|
+
const outputVersion = !includeUnsupportedProxy && version === 5 ? 4 : version;
|
|
10305
10481
|
const parsedProxy = {
|
|
10306
10482
|
tag: proxy.name,
|
|
10307
10483
|
type: "snell",
|
|
@@ -10311,11 +10487,19 @@ var snellParser = (proxy = {}) => {
|
|
|
10311
10487
|
};
|
|
10312
10488
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10313
10489
|
throw "invalid port";
|
|
10314
|
-
if (
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10490
|
+
if (outputVersion != null)
|
|
10491
|
+
parsedProxy.version = outputVersion;
|
|
10492
|
+
if (proxy._userkey)
|
|
10493
|
+
parsedProxy.userkey = proxy._userkey;
|
|
10494
|
+
if (outputVersion === 6) {
|
|
10495
|
+
if (proxy.mode)
|
|
10496
|
+
parsedProxy.mode = proxy.mode;
|
|
10497
|
+
} else {
|
|
10498
|
+
if (proxy["obfs-opts"]?.mode && proxy["obfs-opts"].mode !== "shadow-tls")
|
|
10499
|
+
parsedProxy.obfs_mode = proxy["obfs-opts"].mode;
|
|
10500
|
+
if (proxy["obfs-opts"]?.host && proxy["obfs-opts"]?.mode !== "shadow-tls")
|
|
10501
|
+
parsedProxy.obfs_host = proxy["obfs-opts"].host;
|
|
10502
|
+
}
|
|
10319
10503
|
if (proxy.reuse && (version == null || version >= 4))
|
|
10320
10504
|
parsedProxy.reuse = true;
|
|
10321
10505
|
networkParser(proxy, parsedProxy);
|
|
@@ -10324,7 +10508,8 @@ var snellParser = (proxy = {}) => {
|
|
|
10324
10508
|
delete parsedProxy.server;
|
|
10325
10509
|
delete parsedProxy.server_port;
|
|
10326
10510
|
} else {
|
|
10327
|
-
if (proxy["fast-open"])
|
|
10511
|
+
if (proxy["fast-open"])
|
|
10512
|
+
parsedProxy.udp_fragment = true;
|
|
10328
10513
|
tfoParser(proxy, parsedProxy);
|
|
10329
10514
|
detourParser(proxy, parsedProxy);
|
|
10330
10515
|
ipVersionParser(proxy, parsedProxy);
|
|
@@ -10376,11 +10561,16 @@ var vmessParser = (proxy = {}) => {
|
|
|
10376
10561
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10377
10562
|
throw "invalid port";
|
|
10378
10563
|
vmessProtocolOptionsParser(proxy, parsedProxy);
|
|
10379
|
-
if (proxy["fast-open"])
|
|
10380
|
-
|
|
10381
|
-
if (proxy.network === "
|
|
10382
|
-
|
|
10383
|
-
if (proxy.network === "
|
|
10564
|
+
if (proxy["fast-open"])
|
|
10565
|
+
parsedProxy.udp_fragment = true;
|
|
10566
|
+
if (proxy.network === "ws")
|
|
10567
|
+
wsParser(proxy, parsedProxy);
|
|
10568
|
+
if (proxy.network === "h2")
|
|
10569
|
+
h2Parser(proxy, parsedProxy);
|
|
10570
|
+
if (proxy.network === "http")
|
|
10571
|
+
h1Parser(proxy, parsedProxy);
|
|
10572
|
+
if (proxy.network === "grpc")
|
|
10573
|
+
grpcParser(proxy, parsedProxy);
|
|
10384
10574
|
networkParser(proxy, parsedProxy);
|
|
10385
10575
|
tfoParser(proxy, parsedProxy);
|
|
10386
10576
|
detourParser(proxy, parsedProxy);
|
|
@@ -10402,12 +10592,18 @@ var vlessParser = (proxy = {}) => {
|
|
|
10402
10592
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10403
10593
|
throw "invalid port";
|
|
10404
10594
|
vmessVlessPacketEncodingParser(proxy, parsedProxy);
|
|
10405
|
-
if (proxy["fast-open"])
|
|
10406
|
-
|
|
10407
|
-
if (proxy.
|
|
10408
|
-
|
|
10409
|
-
if (proxy.network === "
|
|
10410
|
-
|
|
10595
|
+
if (proxy["fast-open"])
|
|
10596
|
+
parsedProxy.udp_fragment = true;
|
|
10597
|
+
if (proxy.flow != null)
|
|
10598
|
+
parsedProxy.flow = proxy.flow;
|
|
10599
|
+
if (proxy.network === "ws")
|
|
10600
|
+
wsParser(proxy, parsedProxy);
|
|
10601
|
+
if (proxy.network === "h2")
|
|
10602
|
+
h2Parser(proxy, parsedProxy);
|
|
10603
|
+
if (proxy.network === "http")
|
|
10604
|
+
h1Parser(proxy, parsedProxy);
|
|
10605
|
+
if (proxy.network === "grpc")
|
|
10606
|
+
grpcParser(proxy, parsedProxy);
|
|
10411
10607
|
networkParser(proxy, parsedProxy);
|
|
10412
10608
|
tfoParser(proxy, parsedProxy);
|
|
10413
10609
|
detourParser(proxy, parsedProxy);
|
|
@@ -10428,9 +10624,12 @@ var trojanParser = (proxy = {}) => {
|
|
|
10428
10624
|
};
|
|
10429
10625
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10430
10626
|
throw "invalid port";
|
|
10431
|
-
if (proxy["fast-open"])
|
|
10432
|
-
|
|
10433
|
-
if (proxy.network === "
|
|
10627
|
+
if (proxy["fast-open"])
|
|
10628
|
+
parsedProxy.udp_fragment = true;
|
|
10629
|
+
if (proxy.network === "grpc")
|
|
10630
|
+
grpcParser(proxy, parsedProxy);
|
|
10631
|
+
if (proxy.network === "ws")
|
|
10632
|
+
wsParser(proxy, parsedProxy);
|
|
10434
10633
|
networkParser(proxy, parsedProxy);
|
|
10435
10634
|
tfoParser(proxy, parsedProxy);
|
|
10436
10635
|
detourParser(proxy, parsedProxy);
|
|
@@ -10450,9 +10649,12 @@ var naiveParser = (proxy = {}) => {
|
|
|
10450
10649
|
};
|
|
10451
10650
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10452
10651
|
throw "invalid port";
|
|
10453
|
-
if (proxy.username)
|
|
10454
|
-
|
|
10455
|
-
if (proxy.
|
|
10652
|
+
if (proxy.username)
|
|
10653
|
+
parsedProxy.username = proxy.username;
|
|
10654
|
+
if (proxy.password)
|
|
10655
|
+
parsedProxy.password = proxy.password;
|
|
10656
|
+
if (proxy.uot)
|
|
10657
|
+
parsedProxy.udp_over_tcp = true;
|
|
10456
10658
|
if (proxy["udp-over-tcp"]) {
|
|
10457
10659
|
parsedProxy.udp_over_tcp = {
|
|
10458
10660
|
enabled: true,
|
|
@@ -10467,10 +10669,12 @@ var naiveParser = (proxy = {}) => {
|
|
|
10467
10669
|
parsedProxy.insecure_concurrency = insecure_concurrency;
|
|
10468
10670
|
if (proxy["extra-headers"])
|
|
10469
10671
|
parsedProxy.extra_headers = proxy["extra-headers"];
|
|
10470
|
-
if (proxy.quic)
|
|
10672
|
+
if (proxy.quic)
|
|
10673
|
+
parsedProxy.quic = !!proxy.quic;
|
|
10471
10674
|
if (proxy["quic-congestion-control"])
|
|
10472
10675
|
parsedProxy.quic_congestion_control = proxy["quic-congestion-control"];
|
|
10473
|
-
if (proxy["fast-open"])
|
|
10676
|
+
if (proxy["fast-open"])
|
|
10677
|
+
parsedProxy.udp_fragment = true;
|
|
10474
10678
|
tfoParser(proxy, parsedProxy);
|
|
10475
10679
|
detourParser(proxy, parsedProxy);
|
|
10476
10680
|
tlsParser(proxy, parsedProxy);
|
|
@@ -10503,9 +10707,12 @@ var hysteriaParser = (proxy = {}) => {
|
|
|
10503
10707
|
const range = p.replace(/\s*-\s*/g, ":");
|
|
10504
10708
|
return range.includes(":") ? range : `${range}:${range}`;
|
|
10505
10709
|
});
|
|
10506
|
-
if (proxy.auth_str)
|
|
10507
|
-
|
|
10508
|
-
if (proxy["
|
|
10710
|
+
if (proxy.auth_str)
|
|
10711
|
+
parsedProxy.auth_str = `${proxy.auth_str}`;
|
|
10712
|
+
if (proxy["auth-str"])
|
|
10713
|
+
parsedProxy.auth_str = `${proxy["auth-str"]}`;
|
|
10714
|
+
if (proxy["fast-open"])
|
|
10715
|
+
parsedProxy.udp_fragment = true;
|
|
10509
10716
|
const reg = new RegExp("^[0-9]+[ ]*[KMGT]*[Bb]ps$");
|
|
10510
10717
|
if (reg.test(`${proxy.up}`) && !`${proxy.up}`.endsWith("Mbps")) {
|
|
10511
10718
|
parsedProxy.up = `${proxy.up}`;
|
|
@@ -10517,13 +10724,16 @@ var hysteriaParser = (proxy = {}) => {
|
|
|
10517
10724
|
} else {
|
|
10518
10725
|
parsedProxy.down_mbps = parseInt(`${proxy.down}`, 10);
|
|
10519
10726
|
}
|
|
10520
|
-
if (proxy.obfs)
|
|
10727
|
+
if (proxy.obfs)
|
|
10728
|
+
parsedProxy.obfs = proxy.obfs;
|
|
10521
10729
|
if (proxy.recv_window_conn)
|
|
10522
10730
|
parsedProxy.recv_window_conn = proxy.recv_window_conn;
|
|
10523
10731
|
if (proxy["recv-window-conn"])
|
|
10524
10732
|
parsedProxy.recv_window_conn = proxy["recv-window-conn"];
|
|
10525
|
-
if (proxy.recv_window)
|
|
10526
|
-
|
|
10733
|
+
if (proxy.recv_window)
|
|
10734
|
+
parsedProxy.recv_window = proxy.recv_window;
|
|
10735
|
+
if (proxy["recv-window"])
|
|
10736
|
+
parsedProxy.recv_window = proxy["recv-window"];
|
|
10527
10737
|
if (proxy.disable_mtu_discovery) {
|
|
10528
10738
|
if (typeof proxy.disable_mtu_discovery === "boolean") {
|
|
10529
10739
|
parsedProxy.disable_mtu_discovery = proxy.disable_mtu_discovery;
|
|
@@ -10560,8 +10770,10 @@ var hysteria2Parser = (proxy = {}) => {
|
|
|
10560
10770
|
const range = p.replace(/\s*-\s*/g, ":");
|
|
10561
10771
|
return range.includes(":") ? range : `${range}:${range}`;
|
|
10562
10772
|
});
|
|
10563
|
-
if (proxy.up)
|
|
10564
|
-
|
|
10773
|
+
if (proxy.up)
|
|
10774
|
+
parsedProxy.up_mbps = parseInt(`${proxy.up}`, 10);
|
|
10775
|
+
if (proxy.down)
|
|
10776
|
+
parsedProxy.down_mbps = parseInt(`${proxy.down}`, 10);
|
|
10565
10777
|
if (["salamander", "gecko"].includes(proxy.obfs))
|
|
10566
10778
|
parsedProxy.obfs.type = proxy.obfs;
|
|
10567
10779
|
if (proxy.obfs === "gecko") {
|
|
@@ -10585,14 +10797,17 @@ var hysteria2Parser = (proxy = {}) => {
|
|
|
10585
10797
|
`Invalid obfs packet size for proxy ${proxy.name}: min=${minRaw} max=${maxRaw}`
|
|
10586
10798
|
);
|
|
10587
10799
|
} else {
|
|
10588
|
-
if (hasMin)
|
|
10589
|
-
|
|
10800
|
+
if (hasMin)
|
|
10801
|
+
parsedProxy.obfs.min_packet_size = minPacketSize;
|
|
10802
|
+
if (hasMax)
|
|
10803
|
+
parsedProxy.obfs.max_packet_size = maxPacketSize;
|
|
10590
10804
|
}
|
|
10591
10805
|
}
|
|
10592
10806
|
}
|
|
10593
10807
|
if (proxy["obfs-password"])
|
|
10594
10808
|
parsedProxy.obfs.password = proxy["obfs-password"];
|
|
10595
|
-
if (!parsedProxy.obfs.type)
|
|
10809
|
+
if (!parsedProxy.obfs.type)
|
|
10810
|
+
delete parsedProxy.obfs;
|
|
10596
10811
|
networkParser(proxy, parsedProxy);
|
|
10597
10812
|
tlsParser(proxy, parsedProxy);
|
|
10598
10813
|
tfoParser(proxy, parsedProxy);
|
|
@@ -10614,13 +10829,16 @@ var tuic5Parser = (proxy = {}) => {
|
|
|
10614
10829
|
};
|
|
10615
10830
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10616
10831
|
throw "invalid port";
|
|
10617
|
-
if (proxy["fast-open"])
|
|
10832
|
+
if (proxy["fast-open"])
|
|
10833
|
+
parsedProxy.udp_fragment = true;
|
|
10618
10834
|
if (proxy["congestion-controller"] && proxy["congestion-controller"] !== "cubic")
|
|
10619
10835
|
parsedProxy.congestion_control = proxy["congestion-controller"];
|
|
10620
10836
|
if (proxy["udp-relay-mode"] && proxy["udp-relay-mode"] !== "native")
|
|
10621
10837
|
parsedProxy.udp_relay_mode = proxy["udp-relay-mode"];
|
|
10622
|
-
if (proxy["reduce-rtt"])
|
|
10623
|
-
|
|
10838
|
+
if (proxy["reduce-rtt"])
|
|
10839
|
+
parsedProxy.zero_rtt_handshake = true;
|
|
10840
|
+
if (proxy["udp-over-stream"])
|
|
10841
|
+
parsedProxy.udp_over_stream = true;
|
|
10624
10842
|
if (proxy["heartbeat-interval"])
|
|
10625
10843
|
parsedProxy.heartbeat = `${proxy["heartbeat-interval"]}ms`;
|
|
10626
10844
|
networkParser(proxy, parsedProxy);
|
|
@@ -10650,6 +10868,9 @@ var anytlsParser = (proxy = {}) => {
|
|
|
10650
10868
|
`${proxy["min-idle-session"]}`,
|
|
10651
10869
|
10
|
|
10652
10870
|
);
|
|
10871
|
+
if (proxy["disable-reuse"] != null) {
|
|
10872
|
+
parsedProxy.disable_reuse = !!proxy["disable-reuse"];
|
|
10873
|
+
}
|
|
10653
10874
|
detourParser(proxy, parsedProxy);
|
|
10654
10875
|
tlsParser(proxy, parsedProxy);
|
|
10655
10876
|
ipVersionParser(proxy, parsedProxy);
|
|
@@ -10726,11 +10947,13 @@ var wireguardParser = (proxy = {}) => {
|
|
|
10726
10947
|
};
|
|
10727
10948
|
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
|
10728
10949
|
throw "invalid port";
|
|
10729
|
-
if (proxy["fast-open"])
|
|
10950
|
+
if (proxy["fast-open"])
|
|
10951
|
+
parsedProxy.udp_fragment = true;
|
|
10730
10952
|
if (typeof proxy.reserved === "string") {
|
|
10731
10953
|
parsedProxy.reserved = proxy.reserved;
|
|
10732
10954
|
} else if (Array.isArray(proxy.reserved)) {
|
|
10733
|
-
for (const r of proxy.reserved)
|
|
10955
|
+
for (const r of proxy.reserved)
|
|
10956
|
+
parsedProxy.reserved.push(r);
|
|
10734
10957
|
} else {
|
|
10735
10958
|
delete parsedProxy.reserved;
|
|
10736
10959
|
}
|
|
@@ -10764,7 +10987,8 @@ var wireguardParser = (proxy = {}) => {
|
|
|
10764
10987
|
if (typeof p.reserved === "string") {
|
|
10765
10988
|
peer.reserved.push(p.reserved);
|
|
10766
10989
|
} else if (Array.isArray(p.reserved)) {
|
|
10767
|
-
for (const r of p.reserved)
|
|
10990
|
+
for (const r of p.reserved)
|
|
10991
|
+
peer.reserved.push(r);
|
|
10768
10992
|
} else {
|
|
10769
10993
|
delete peer.reserved;
|
|
10770
10994
|
}
|
|
@@ -10790,9 +11014,9 @@ function singbox_Producer() {
|
|
|
10790
11014
|
const type = "ALL";
|
|
10791
11015
|
const produce2 = (proxies, type2, opts = {}) => {
|
|
10792
11016
|
const list = [];
|
|
10793
|
-
const
|
|
11017
|
+
const originalShadowTLS = new Map(
|
|
10794
11018
|
proxies.filter(
|
|
10795
|
-
(proxy) => proxy?.
|
|
11019
|
+
(proxy) => proxy?.plugin === "shadow-tls" && proxy?.["plugin-opts"]
|
|
10796
11020
|
).map((proxy) => [
|
|
10797
11021
|
proxy,
|
|
10798
11022
|
{
|
|
@@ -10803,17 +11027,57 @@ function singbox_Producer() {
|
|
|
10803
11027
|
])
|
|
10804
11028
|
);
|
|
10805
11029
|
ClashMeta_Producer().produce(proxies, "internal", { "include-unsupported-proxy": true }).map((proxy) => {
|
|
11030
|
+
const listStart = list.length;
|
|
10806
11031
|
try {
|
|
10807
|
-
const
|
|
10808
|
-
if (
|
|
10809
|
-
proxy.plugin =
|
|
10810
|
-
proxy["plugin-opts"] =
|
|
10811
|
-
if (
|
|
10812
|
-
proxy["obfs-opts"] =
|
|
11032
|
+
const shadowTLS = originalShadowTLS.get(proxy);
|
|
11033
|
+
if (shadowTLS) {
|
|
11034
|
+
proxy.plugin = shadowTLS.plugin;
|
|
11035
|
+
proxy["plugin-opts"] = shadowTLS["plugin-opts"];
|
|
11036
|
+
if (shadowTLS["obfs-opts"]) {
|
|
11037
|
+
proxy["obfs-opts"] = shadowTLS["obfs-opts"];
|
|
10813
11038
|
} else {
|
|
10814
11039
|
delete proxy["obfs-opts"];
|
|
10815
11040
|
}
|
|
10816
11041
|
}
|
|
11042
|
+
const shadowTLSPluginOpts = getShadowTLSPluginOpts(proxy);
|
|
11043
|
+
const shadowTLSEnabled = Boolean(
|
|
11044
|
+
shadowTLSPluginOpts && (shadowTLSPluginOpts.password || shadowTLSPluginOpts.version != null && Number(shadowTLSPluginOpts.version) !== 0)
|
|
11045
|
+
);
|
|
11046
|
+
let streamShadowTLSOutbound;
|
|
11047
|
+
if (shadowTLSEnabled && ["vmess", "vless", "trojan"].includes(proxy.type)) {
|
|
11048
|
+
if (proxy["reality-opts"]) {
|
|
11049
|
+
throw new Error(
|
|
11050
|
+
`Platform sing-box cannot chain ShadowTLS with Reality for proxy ${proxy.name}`
|
|
11051
|
+
);
|
|
11052
|
+
}
|
|
11053
|
+
if (["vmess", "vless"].includes(proxy.type) && proxy.network === "h2") {
|
|
11054
|
+
throw new Error(
|
|
11055
|
+
`Platform sing-box cannot chain ShadowTLS with network h2 for proxy ${proxy.name}`
|
|
11056
|
+
);
|
|
11057
|
+
}
|
|
11058
|
+
if (proxy.type === "vless" && proxy.flow === "xtls-rprx-vision") {
|
|
11059
|
+
throw new Error(
|
|
11060
|
+
`Platform sing-box cannot chain ShadowTLS with flow xtls-rprx-vision for proxy ${proxy.name}`
|
|
11061
|
+
);
|
|
11062
|
+
}
|
|
11063
|
+
const rawVersion = shadowTLSPluginOpts.version;
|
|
11064
|
+
const parsedVersion = typeof rawVersion === "string" && rawVersion.trim() === "" ? NaN : Number(rawVersion ?? 0);
|
|
11065
|
+
const version = parsedVersion === 0 ? 2 : parsedVersion;
|
|
11066
|
+
if (!Number.isInteger(version) || ![1, 2, 3].includes(version)) {
|
|
11067
|
+
throw new Error(
|
|
11068
|
+
`Platform sing-box does not support shadow-tls version ${rawVersion} for proxy ${proxy.name}`
|
|
11069
|
+
);
|
|
11070
|
+
}
|
|
11071
|
+
streamShadowTLSOutbound = shadowTLSOutboundParser(
|
|
11072
|
+
proxy,
|
|
11073
|
+
{ ...shadowTLSPluginOpts, version }
|
|
11074
|
+
);
|
|
11075
|
+
}
|
|
11076
|
+
if (proxy.type === "anytls" && shadowTLSEnabled) {
|
|
11077
|
+
throw new Error(
|
|
11078
|
+
"Platform sing-box cannot replace AnyTLS TLS with ShadowTLS"
|
|
11079
|
+
);
|
|
11080
|
+
}
|
|
10817
11081
|
if (["xhttp"].includes(proxy.network))
|
|
10818
11082
|
throw new Error(
|
|
10819
11083
|
`Platform sing-box does not support network: ${proxy.network}`
|
|
@@ -10852,24 +11116,24 @@ function singbox_Producer() {
|
|
|
10852
11116
|
);
|
|
10853
11117
|
}
|
|
10854
11118
|
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}`
|
|
11119
|
+
case "snell": {
|
|
11120
|
+
list.push(
|
|
11121
|
+
snellParser(
|
|
11122
|
+
proxy,
|
|
11123
|
+
opts["include-unsupported-proxy"]
|
|
11124
|
+
)
|
|
11125
|
+
);
|
|
11126
|
+
const shadowTLSPluginOpts2 = getShadowTLSPluginOpts(proxy);
|
|
11127
|
+
if (shadowTLSPluginOpts2) {
|
|
11128
|
+
list.push(
|
|
11129
|
+
shadowTLSOutboundParser(
|
|
11130
|
+
proxy,
|
|
11131
|
+
shadowTLSPluginOpts2
|
|
11132
|
+
)
|
|
10870
11133
|
);
|
|
10871
11134
|
}
|
|
10872
11135
|
break;
|
|
11136
|
+
}
|
|
10873
11137
|
case "vmess":
|
|
10874
11138
|
if (!proxy.network || ["tcp", "ws", "grpc", "h2", "http"].includes(
|
|
10875
11139
|
proxy.network
|
|
@@ -10941,11 +11205,26 @@ function singbox_Producer() {
|
|
|
10941
11205
|
`Platform sing-box does not support proxy type: ${proxy.type}`
|
|
10942
11206
|
);
|
|
10943
11207
|
}
|
|
11208
|
+
if (streamShadowTLSOutbound) {
|
|
11209
|
+
const outbound = list[listStart];
|
|
11210
|
+
outbound.detour = getShadowTLSTag(proxy);
|
|
11211
|
+
delete outbound.tls;
|
|
11212
|
+
list.push(streamShadowTLSOutbound);
|
|
11213
|
+
}
|
|
11214
|
+
if (opts["include-unsupported-proxy"] && proxy["name-cert-verify"]) {
|
|
11215
|
+
for (let i = listStart; i < list.length; i++) {
|
|
11216
|
+
const outbound = list[i];
|
|
11217
|
+
if (outbound.tls)
|
|
11218
|
+
outbound.tls.certificate_server_name = proxy["name-cert-verify"];
|
|
11219
|
+
}
|
|
11220
|
+
}
|
|
10944
11221
|
} catch (e) {
|
|
11222
|
+
list.length = listStart;
|
|
10945
11223
|
app_default.error(e.message ?? e);
|
|
10946
11224
|
}
|
|
10947
11225
|
});
|
|
10948
|
-
if (type2 === "internal")
|
|
11226
|
+
if (type2 === "internal")
|
|
11227
|
+
return list;
|
|
10949
11228
|
const categorized = list.reduce(
|
|
10950
11229
|
(result, item) => {
|
|
10951
11230
|
if (["wireguard", "tailscale"].includes(item.type)) {
|
|
@@ -11022,11 +11301,6 @@ function Egern_Producer() {
|
|
|
11022
11301
|
return false;
|
|
11023
11302
|
} else if (proxy.type === "snell" && normalizeSnellVersion(proxy.version) === null) {
|
|
11024
11303
|
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
11304
|
} else if (["anytls"].includes(proxy.type) && proxy.network && !["tcp"].includes(proxy.network)) {
|
|
11031
11305
|
return false;
|
|
11032
11306
|
} else if (["ws"].includes(proxy.network) && proxy["ws-opts"]?.["v2ray-http-upgrade"]) {
|
|
@@ -11303,7 +11577,8 @@ function Egern_Producer() {
|
|
|
11303
11577
|
}
|
|
11304
11578
|
};
|
|
11305
11579
|
flow = proxy.flow;
|
|
11306
|
-
if (flow === "")
|
|
11580
|
+
if (flow === "")
|
|
11581
|
+
flow = void 0;
|
|
11307
11582
|
}
|
|
11308
11583
|
proxy = {
|
|
11309
11584
|
type: "vless",
|
|
@@ -11391,7 +11666,8 @@ function Egern_Producer() {
|
|
|
11391
11666
|
"vless",
|
|
11392
11667
|
"vmess",
|
|
11393
11668
|
"anytls",
|
|
11394
|
-
"ssh"
|
|
11669
|
+
"ssh",
|
|
11670
|
+
"snell"
|
|
11395
11671
|
].includes(original.type)) {
|
|
11396
11672
|
if (["shadow-tls"].includes(original.plugin) && original["plugin-opts"]) {
|
|
11397
11673
|
if (original["plugin-opts"].version != 3)
|
|
@@ -11492,22 +11768,24 @@ function getTfo(proxy) {
|
|
|
11492
11768
|
function getUdpRelay(proxy) {
|
|
11493
11769
|
return proxy.udp ?? proxy.udp_relay;
|
|
11494
11770
|
}
|
|
11495
|
-
function hasShadowTls(proxy) {
|
|
11496
|
-
return proxy.plugin === "shadow-tls";
|
|
11497
|
-
}
|
|
11498
11771
|
function getNonEmptyValue(value) {
|
|
11499
|
-
if (value == null)
|
|
11500
|
-
|
|
11772
|
+
if (value == null)
|
|
11773
|
+
return void 0;
|
|
11774
|
+
if (typeof value === "string" && value.length === 0)
|
|
11775
|
+
return void 0;
|
|
11501
11776
|
return value;
|
|
11502
11777
|
}
|
|
11503
11778
|
function getReality(proxy) {
|
|
11504
11779
|
const realityOpts = proxy?.["reality-opts"];
|
|
11505
|
-
if (!realityOpts)
|
|
11780
|
+
if (!realityOpts)
|
|
11781
|
+
return void 0;
|
|
11506
11782
|
const reality = {};
|
|
11507
11783
|
const publicKey = getNonEmptyValue(realityOpts["public-key"]);
|
|
11508
11784
|
const shortId = getNonEmptyValue(realityOpts["short-id"]);
|
|
11509
|
-
if (publicKey != null)
|
|
11510
|
-
|
|
11785
|
+
if (publicKey != null)
|
|
11786
|
+
reality.public_key = publicKey;
|
|
11787
|
+
if (shortId != null)
|
|
11788
|
+
reality.short_id = shortId;
|
|
11511
11789
|
return Object.keys(reality).length > 0 ? reality : void 0;
|
|
11512
11790
|
}
|
|
11513
11791
|
function getGrpcTransport(proxy) {
|
|
@@ -11521,21 +11799,26 @@ function getGrpcTransport(proxy) {
|
|
|
11521
11799
|
};
|
|
11522
11800
|
}
|
|
11523
11801
|
function isEgernGrpcGun(proxy) {
|
|
11524
|
-
if (proxy.network !== "grpc")
|
|
11802
|
+
if (proxy.network !== "grpc")
|
|
11803
|
+
return true;
|
|
11525
11804
|
const grpcType = proxy["grpc-opts"]?.["_grpc-type"];
|
|
11526
|
-
if (grpcType == null)
|
|
11805
|
+
if (grpcType == null)
|
|
11806
|
+
return true;
|
|
11527
11807
|
return `${grpcType}`.trim().toLowerCase() === "gun";
|
|
11528
11808
|
}
|
|
11529
11809
|
function normalizeSnellVersion(version) {
|
|
11530
|
-
if (version == null)
|
|
11810
|
+
if (version == null)
|
|
11811
|
+
return void 0;
|
|
11531
11812
|
const normalized = `${version}`.trim();
|
|
11532
|
-
if (!/^[1-5]$/.test(normalized))
|
|
11813
|
+
if (!/^[1-5]$/.test(normalized))
|
|
11814
|
+
return null;
|
|
11533
11815
|
return parseInt(normalized, 10);
|
|
11534
11816
|
}
|
|
11535
11817
|
function getFirstHeaderValue(headers, ...keys) {
|
|
11536
11818
|
for (const key of keys) {
|
|
11537
11819
|
const value = getFirstValue(headers?.[key]);
|
|
11538
|
-
if (value)
|
|
11820
|
+
if (value)
|
|
11821
|
+
return value;
|
|
11539
11822
|
}
|
|
11540
11823
|
return void 0;
|
|
11541
11824
|
}
|
|
@@ -11546,7 +11829,8 @@ function getH2Headers(h2Opts) {
|
|
|
11546
11829
|
const headers = {};
|
|
11547
11830
|
if (h2Opts?.headers && typeof h2Opts.headers === "object" && !Array.isArray(h2Opts.headers)) {
|
|
11548
11831
|
for (const [key, value] of Object.entries(h2Opts.headers)) {
|
|
11549
|
-
if (/^host$/i.test(key))
|
|
11832
|
+
if (/^host$/i.test(key))
|
|
11833
|
+
continue;
|
|
11550
11834
|
const headerValue = getFirstValue(value);
|
|
11551
11835
|
if (headerValue != null) {
|
|
11552
11836
|
headers[key] = headerValue;
|
|
@@ -11560,13 +11844,16 @@ function getH2Headers(h2Opts) {
|
|
|
11560
11844
|
return Object.keys(headers).length > 0 ? headers : void 0;
|
|
11561
11845
|
}
|
|
11562
11846
|
function getFirstValue(value) {
|
|
11563
|
-
if (Array.isArray(value))
|
|
11564
|
-
|
|
11847
|
+
if (Array.isArray(value))
|
|
11848
|
+
return value[0];
|
|
11849
|
+
if (value != null)
|
|
11850
|
+
return value;
|
|
11565
11851
|
return void 0;
|
|
11566
11852
|
}
|
|
11567
11853
|
function getFingerprintSha256(proxy) {
|
|
11568
11854
|
const fingerprint = proxy?.["tls-fingerprint"];
|
|
11569
|
-
if (typeof fingerprint !== "string")
|
|
11855
|
+
if (typeof fingerprint !== "string")
|
|
11856
|
+
return void 0;
|
|
11570
11857
|
const trimmedFingerprint = fingerprint.trim();
|
|
11571
11858
|
return trimmedFingerprint.length > 0 ? trimmedFingerprint : void 0;
|
|
11572
11859
|
}
|
|
@@ -11576,7 +11863,8 @@ function supportsRootFingerprintSha256(original, proxy) {
|
|
|
11576
11863
|
) || original.type === "socks5" && proxy.type === "socks5_tls" || original.type === "http" && proxy.type === "https";
|
|
11577
11864
|
}
|
|
11578
11865
|
function addTransportFingerprintSha256(transport, fingerprintSha256) {
|
|
11579
|
-
if (!transport)
|
|
11866
|
+
if (!transport)
|
|
11867
|
+
return;
|
|
11580
11868
|
for (const key of ["grpc", "http2", "tls", "wss"]) {
|
|
11581
11869
|
if (transport[key]) {
|
|
11582
11870
|
transport[key].fingerprint_sha256 = fingerprintSha256;
|
|
@@ -11678,7 +11966,8 @@ function parseProxyLines(lines, opts) {
|
|
|
11678
11966
|
const proxyList = [];
|
|
11679
11967
|
let lastParser = null;
|
|
11680
11968
|
for (const line of lines) {
|
|
11681
|
-
if (line.length === 0)
|
|
11969
|
+
if (line.length === 0)
|
|
11970
|
+
continue;
|
|
11682
11971
|
let proxy = null;
|
|
11683
11972
|
if (lastParser) {
|
|
11684
11973
|
proxy = tryParseProxy(lastParser, line);
|