sub-store-convert 2.23.22 → 2.24.7

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.
Files changed (2) hide show
  1. package/index.js +641 -392
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -83,21 +83,10 @@ var grammars = String.raw`
83
83
  (quote === '"' || quote === "'") &&
84
84
  trimmed[trimmed.length - 1] === quote
85
85
  ) {
86
- return trimmed.slice(1, -1).replace(/\\(["'\\])/g, "$1");
87
- }
88
-
89
- return trimmed.replace(/\\(["'\\])/g, "$1");
90
- }
91
- function isEscaped(text, index) {
92
- let count = 0;
93
- let cursor = index - 1;
94
-
95
- while (cursor >= 0 && text[cursor] === "\\") {
96
- count++;
97
- cursor--;
86
+ return trimmed.slice(1, -1);
98
87
  }
99
88
 
100
- return count % 2 === 1;
89
+ return trimmed;
101
90
  }
102
91
  function readQuotedHeaderKey(text, start) {
103
92
  const quote = text[start];
@@ -106,11 +95,6 @@ var grammars = String.raw`
106
95
 
107
96
  while (index < text.length) {
108
97
  const char = text[index];
109
- if (char === "\\" && index + 1 < text.length) {
110
- hasKey = true;
111
- index += 2;
112
- continue;
113
- }
114
98
  if (char === quote) {
115
99
  return hasKey ? index + 1 : -1;
116
100
  }
@@ -166,15 +150,35 @@ var grammars = String.raw`
166
150
  while (index < text.length && /\s/.test(text[index])) index++;
167
151
  return text[index] === ":";
168
152
  }
169
- function isHeaderValueQuoteEnd(text, index) {
153
+ function isOptionStart(text, start) {
154
+ let index = start;
155
+ while (index < text.length && /\s/.test(text[index])) index++;
156
+
157
+ const keyStart = index;
158
+ while (index < text.length && /[0-9A-Za-z-]/.test(text[index])) index++;
159
+ if (index === keyStart) return false;
160
+
161
+ while (index < text.length && /\s/.test(text[index])) index++;
162
+ return text[index] === "=";
163
+ }
164
+ function isHeaderValueQuoteEnd(text, index, pairSeparator, allowCommaEnd, containerQuote) {
170
165
  let cursor = index + 1;
171
166
  while (cursor < text.length && /\s/.test(text[cursor])) cursor++;
172
167
 
173
- return (
174
- cursor >= text.length ||
175
- text[cursor] === "," ||
176
- (text[cursor] === ";" && isHeaderKeyStart(text, cursor + 1))
177
- );
168
+ if (cursor >= text.length) return true;
169
+ if (allowCommaEnd && text[cursor] === "," && isOptionStart(text, cursor + 1)) {
170
+ return true;
171
+ }
172
+ if (text[cursor] === pairSeparator && isHeaderKeyStart(text, cursor + 1)) {
173
+ return true;
174
+ }
175
+ if (containerQuote && text[cursor] === containerQuote) {
176
+ let next = cursor + 1;
177
+ while (next < text.length && /\s/.test(text[next])) next++;
178
+ return next >= text.length || text[next] === ",";
179
+ }
180
+
181
+ return false;
178
182
  }
179
183
  function findHeaderSeparator(pair) {
180
184
  let quote = "";
@@ -183,10 +187,6 @@ var grammars = String.raw`
183
187
  const char = pair[index];
184
188
 
185
189
  if (quote) {
186
- if (char === "\\" && index + 1 < pair.length) {
187
- index++;
188
- continue;
189
- }
190
190
  if (char === quote) {
191
191
  quote = "";
192
192
  }
@@ -205,7 +205,7 @@ var grammars = String.raw`
205
205
 
206
206
  return -1;
207
207
  }
208
- function readUnquotedHeadersEnd(text, start) {
208
+ function readUnquotedHeadersEnd(text, start, pairSeparator) {
209
209
  let index = start;
210
210
  let quote = "";
211
211
  let quoteRole = "";
@@ -215,14 +215,10 @@ var grammars = String.raw`
215
215
  const char = text[index];
216
216
 
217
217
  if (quote) {
218
- if (char === "\\" && index + 1 < text.length) {
219
- index += 2;
220
- continue;
221
- }
222
218
  if (char === quote) {
223
219
  if (
224
220
  quoteRole === "key" ||
225
- isHeaderValueQuoteEnd(text, index)
221
+ isHeaderValueQuoteEnd(text, index, pairSeparator, true)
226
222
  ) {
227
223
  quote = "";
228
224
  quoteRole = "";
@@ -245,7 +241,7 @@ var grammars = String.raw`
245
241
  continue;
246
242
  }
247
243
 
248
- if (char === ";" && isHeaderKeyStart(text, index + 1)) {
244
+ if (char === pairSeparator && isHeaderKeyStart(text, index + 1)) {
249
245
  seenSeparator = false;
250
246
  index++;
251
247
  continue;
@@ -257,24 +253,62 @@ var grammars = String.raw`
257
253
 
258
254
  return index;
259
255
  }
260
- function readQuotedHeadersEnd(text, start) {
256
+ function readQuotedHeadersEnd(text, start, pairSeparator) {
261
257
  const quote = text[start];
262
258
  let index = start + 1;
259
+ let innerQuote = "";
260
+ let quoteRole = "";
261
+ let seenSeparator = false;
263
262
 
264
263
  while (index < text.length) {
265
- if (text[index] === quote && !isEscaped(text, index)) {
264
+ const char = text[index];
265
+
266
+ if (innerQuote) {
267
+ if (char === innerQuote) {
268
+ if (
269
+ quoteRole === "key" ||
270
+ isHeaderValueQuoteEnd(text, index, pairSeparator, false, quote)
271
+ ) {
272
+ innerQuote = "";
273
+ quoteRole = "";
274
+ }
275
+ }
276
+ index++;
277
+ continue;
278
+ }
279
+
280
+ if (char === quote) {
266
281
  let cursor = index + 1;
267
282
  while (cursor < text.length && /\s/.test(text[cursor])) cursor++;
268
283
  if (cursor >= text.length || text[cursor] === ",") {
269
284
  return index + 1;
270
285
  }
271
286
  }
287
+
288
+ if (char === '"' || char === "'") {
289
+ innerQuote = char;
290
+ quoteRole = seenSeparator ? "value" : "key";
291
+ index++;
292
+ continue;
293
+ }
294
+
295
+ if (char === ":" && !seenSeparator) {
296
+ seenSeparator = true;
297
+ index++;
298
+ continue;
299
+ }
300
+
301
+ if (char === pairSeparator && isHeaderKeyStart(text, index + 1)) {
302
+ seenSeparator = false;
303
+ index++;
304
+ continue;
305
+ }
272
306
  index++;
273
307
  }
274
308
 
275
309
  return text.length;
276
310
  }
277
- function readHeadersEnd(text, start) {
311
+ function readHeadersEnd(text, start, pairSeparator) {
278
312
  let index = start;
279
313
  while (index < text.length && /\s/.test(text[index])) index++;
280
314
 
@@ -282,12 +316,12 @@ var grammars = String.raw`
282
316
  (text[index] === '"' || text[index] === "'") &&
283
317
  !startsWithQuotedHeaderKey(text.slice(index))
284
318
  ) {
285
- return readQuotedHeadersEnd(text, index);
319
+ return readQuotedHeadersEnd(text, index, pairSeparator);
286
320
  }
287
321
 
288
- return readUnquotedHeadersEnd(text, start);
322
+ return readUnquotedHeadersEnd(text, start, pairSeparator);
289
323
  }
290
- function splitHeaders(headers) {
324
+ function splitHeaders(headers, pairSeparator) {
291
325
  const result = [];
292
326
  let start = 0;
293
327
  let quote = "";
@@ -298,14 +332,10 @@ var grammars = String.raw`
298
332
  const char = headers[index];
299
333
 
300
334
  if (quote) {
301
- if (char === "\\" && index + 1 < headers.length) {
302
- index++;
303
- continue;
304
- }
305
335
  if (char === quote) {
306
336
  if (
307
337
  quoteRole === "key" ||
308
- isHeaderValueQuoteEnd(headers, index)
338
+ isHeaderValueQuoteEnd(headers, index, pairSeparator, false)
309
339
  ) {
310
340
  quote = "";
311
341
  quoteRole = "";
@@ -325,7 +355,7 @@ var grammars = String.raw`
325
355
  continue;
326
356
  }
327
357
 
328
- if (char === ";" && isHeaderKeyStart(headers, index + 1)) {
358
+ if (char === pairSeparator && isHeaderKeyStart(headers, index + 1)) {
329
359
  result.push(headers.slice(start, index));
330
360
  start = index + 1;
331
361
  seenSeparator = false;
@@ -335,9 +365,9 @@ var grammars = String.raw`
335
365
  result.push(headers.slice(start));
336
366
  return result;
337
367
  }
338
- function parseHeaders(headers) {
368
+ function parseHeaders(headers, pairSeparator) {
339
369
  const result = {};
340
- splitHeaders(stripOuterHeadersQuotes(headers)).forEach((pair) => {
370
+ splitHeaders(stripOuterHeadersQuotes(headers), pairSeparator).forEach((pair) => {
341
371
  const index = findHeaderSeparator(pair);
342
372
  if (index === -1) return;
343
373
 
@@ -350,6 +380,12 @@ var grammars = String.raw`
350
380
  });
351
381
  return result;
352
382
  }
383
+ function normalizeVmessSecurity(security) {
384
+ const normalized = String(security || "").trim().toLowerCase();
385
+ const supported = ["aes-128-gcm", "chacha20-ietf-poly1305"];
386
+ if (!supported.includes(normalized)) return "auto";
387
+ return normalized === "chacha20-ietf-poly1305" ? "chacha20-poly1305" : normalized;
388
+ }
353
389
  }
354
390
 
355
391
  start = (anytls/shadowsocks/vmess/trojan/h2_connect/https/http/snell/socks5/socks5_tls/tuic/tuic_v5/wireguard/hysteria2/ssh/trust_tunnel/direct) {
@@ -367,9 +403,9 @@ shadowsocks = tag equals "ss" address (method/passwordk/obfs/obfs_host/obfs_uri/
367
403
  }
368
404
  handleShadowTLS();
369
405
  }
370
- vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/ws_path/ws_headers/method/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls/sni/tls_fingerprint/tls_verification/client_cert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
406
+ 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/tls_fingerprint/tls_verification/client_cert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
371
407
  proxy.type = "vmess";
372
- proxy.cipher = proxy.cipher || "none";
408
+ proxy.cipher = proxy.cipher || "auto";
373
409
  // Surfboard 与 Surge 默认不一致, 不管 Surfboard https://getsurfboard.com/docs/profile-format/proxy/external-proxy/vmess
374
410
  if (proxy.aead) {
375
411
  proxy.alterId = 0;
@@ -523,7 +559,7 @@ tls_verification = comma "skip-cert-verify" equals flag:bool { proxy["skip-cert-
523
559
  tls_fingerprint = comma "server-cert-fingerprint-sha256" equals tls_fingerprint:$[^,]+ { proxy["tls-fingerprint"] = tls_fingerprint.trim(); }
524
560
  client_cert = comma "client-cert" equals match:[^,]+ { proxy["keystore-client-cert"] = stripQuotes(match.join("")); }
525
561
 
526
- snell_psk = comma "psk" equals match:[^,]+ { proxy.psk = match.join(""); }
562
+ snell_psk = comma "psk" equals match:[^,]+ { proxy.psk = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); }
527
563
  snell_version = comma "version" equals match:$[0-9]+ { proxy.version = parseInt(match.trim()); }
528
564
 
529
565
  usernamek = comma "username" equals match:[^,]+ { proxy.username = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); }
@@ -534,27 +570,29 @@ vmess_aead = comma "vmess-aead" equals flag:bool { proxy.aead = flag; }
534
570
  method = comma "encrypt-method" equals cipher:cipher {
535
571
  proxy.cipher = cipher;
536
572
  }
573
+ vmess_method = comma "encrypt-method" equals cipher:$[^,]+ {
574
+ proxy.cipher = normalizeVmessSecurity(cipher);
575
+ }
537
576
  cipher = ("aes-128-cfb"/"aes-128-ctr"/"aes-128-gcm"/"aes-192-cfb"/"aes-192-ctr"/"aes-192-gcm"/"aes-256-cfb"/"aes-256-ctr"/"aes-256-gcm"/"bf-cfb"/"camellia-128-cfb"/"camellia-192-cfb"/"camellia-256-cfb"/"cast5-cfb"/"chacha20-ietf-poly1305"/"chacha20-ietf"/"chacha20-poly1305"/"chacha20"/"des-cfb"/"idea-cfb"/"none"/"rc2-cfb"/"rc4-md5"/"rc4"/"salsa20"/"seed-cfb"/"xchacha20-ietf-poly1305"/"2022-blake3-aes-128-gcm"/"2022-blake3-aes-256-gcm");
538
577
 
539
578
  ws = comma "ws" equals flag:bool { obfs.type = "ws"; }
540
- ws_headers = comma "ws-headers" equals headers:$[^,]+ {
541
- const pairs = headers.split("|");
542
- const result = {};
543
- pairs.forEach(pair => {
544
- const [key, value] = pair.trim().split(":");
545
- result[key.trim()] = value.trim().replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1');
546
- })
547
- obfs["ws-headers"] = result;
548
- }
579
+ ws_headers = comma "ws-headers" equals & {
580
+ const start = peg$currPos;
581
+ const index = readHeadersEnd(input, start, "|");
582
+
583
+ $.headers = input.substring(start, index);
584
+ peg$currPos = index;
585
+ return $.headers.trim().length > 0;
586
+ } { obfs["ws-headers"] = parseHeaders($.headers, "|"); }
549
587
  ws_path = comma "ws-path" equals path:uri { obfs.path = path.trim().replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); }
550
588
  headers = comma "headers" equals & {
551
589
  const start = peg$currPos;
552
- const index = readHeadersEnd(input, start);
590
+ const index = readHeadersEnd(input, start, ";");
553
591
 
554
592
  $.headers = input.substring(start, index);
555
593
  peg$currPos = index;
556
594
  return $.headers.trim().length > 0;
557
- } { proxy.headers = parseHeaders($.headers); }
595
+ } { proxy.headers = parseHeaders($.headers, ";"); }
558
596
 
559
597
  obfs = comma "obfs" equals type:("http"/"tls") { obfs.type = type; }
560
598
  obfs_host = comma "obfs-host" equals match:[^,]+ { obfs.host = match.join("").replace(/^"(.*)"$/, '$1'); };
@@ -644,6 +682,23 @@ var grammars2 = String.raw`
644
682
  $set(proxy, "http-opts.headers.Host", transport.host);
645
683
  }
646
684
  }
685
+
686
+ function normalizeVmessSecurity(security) {
687
+ const normalized = String(security || "").trim().toLowerCase();
688
+ const supported = ["none", "auto", "aes-128-gcm", "chacha20-ietf-poly1305"];
689
+ if (!supported.includes(normalized)) return "auto";
690
+ return normalized === "chacha20-ietf-poly1305" ? "chacha20-poly1305" : normalized;
691
+ }
692
+
693
+ function loonClientFingerprint(tlsProfile) {
694
+ switch (String(tlsProfile || "").trim()) {
695
+ case "chrome":
696
+ return "chrome";
697
+ case "ios18":
698
+ case "ios26":
699
+ return "ios";
700
+ }
701
+ }
647
702
  }
648
703
 
649
704
  start = (shadowsocksr/shadowsocks/vmess/vless/trojan/https/http/socks5/hysteria2/anytls) {
@@ -665,35 +720,35 @@ shadowsocks = tag equals "shadowsocks"i address method password (obfs_typev obfs
665
720
  $set(proxy, "plugin-opts.path", obfs.path);
666
721
  }
667
722
  }
668
- vmess = tag equals "vmess"i address method uuid (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/vmess_alterId/fast_open/udp_relay/ip_mode/public_key/short_id/block_quic/others)* {
723
+ vmess = tag equals "vmess"i address vmess_method uuid (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/vmess_alterId/fast_open/udp_relay/ip_mode/public_key/short_id/block_quic/others)* {
669
724
  proxy.type = "vmess";
670
- proxy.cipher = proxy.cipher || "none";
725
+ proxy.cipher = proxy.cipher || "auto";
671
726
  proxy.alterId = proxy.alterId || 0;
672
727
  handleTransport();
673
728
  }
674
- vless = tag equals "vless"i address uuid (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/flow/public_key/short_id/block_quic/others)* {
729
+ vless = tag equals "vless"i address uuid (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/fast_open/udp_relay/ip_mode/flow/public_key/short_id/block_quic/others)* {
675
730
  proxy.type = "vless";
676
731
  handleTransport();
677
732
  }
678
- trojan = tag equals "trojan"i address password (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/others)* {
733
+ trojan = tag equals "trojan"i address password (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/fast_open/udp_relay/ip_mode/block_quic/others)* {
679
734
  proxy.type = "trojan";
680
735
  handleTransport();
681
736
  }
682
- anytls = tag equals "anytls"i address password (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/idle_session_check_interval/idle_session_timeout/min_idle_session/max_stream_count/others)* {
737
+ anytls = tag equals "anytls"i address password (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/fast_open/udp_relay/ip_mode/block_quic/idle_session_check_interval/idle_session_timeout/min_idle_session/max_stream_count/others)* {
683
738
  proxy.type = "anytls";
684
739
  handleTransport();
685
740
  }
686
- hysteria2 = tag equals "hysteria2"i address password (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/udp_relay/fast_open/download_bandwidth/server_ports/hop_interval/salamander_password/ecn/ip_mode/block_quic/others)* {
741
+ hysteria2 = tag equals "hysteria2"i address password (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/udp_relay/fast_open/download_bandwidth/server_ports/hop_interval/salamander_password/ecn/ip_mode/block_quic/others)* {
687
742
  proxy.type = "hysteria2";
688
743
  }
689
- https = tag equals "https"i address (username password)? (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/others)* {
744
+ https = tag equals "https"i address (username password)? (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/fast_open/udp_relay/ip_mode/block_quic/others)* {
690
745
  proxy.type = "http";
691
746
  proxy.tls = true;
692
747
  }
693
748
  http = tag equals "http"i address (username password)? (fast_open/udp_relay/ip_mode/block_quic/others)* {
694
749
  proxy.type = "http";
695
750
  }
696
- socks5 = tag equals "socks5"i address (username password)? (over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/others)* {
751
+ socks5 = tag equals "socks5"i address (username password)? (over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/tls_profile/alpn/fast_open/udp_relay/ip_mode/block_quic/others)* {
697
752
  proxy.type = "socks5";
698
753
  }
699
754
 
@@ -735,6 +790,9 @@ port = digits:[0-9]+ {
735
790
  method = comma cipher:cipher {
736
791
  proxy.cipher = cipher;
737
792
  }
793
+ vmess_method = comma cipher:$[^,]+ {
794
+ proxy.cipher = normalizeVmessSecurity(cipher);
795
+ }
738
796
  cipher = ("aes-128-cfb"/"aes-128-ctr"/"aes-128-gcm"/"aes-192-cfb"/"aes-192-ctr"/"aes-192-gcm"/"aes-256-cfb"/"aes-256-ctr"/"aes-256-gcm"/"auto"/"bf-cfb"/"camellia-128-cfb"/"camellia-192-cfb"/"camellia-256-cfb"/"chacha20-ietf-poly1305"/"chacha20-ietf"/"chacha20-poly1305"/"chacha20"/"none"/"rc4-md5"/"rc4"/"salsa20"/"xchacha20-ietf-poly1305"/"2022-blake3-aes-128-gcm"/"2022-blake3-aes-256-gcm");
739
797
 
740
798
  username = & {
@@ -787,7 +845,7 @@ vmess_alterId = comma "alterId" equals alterId:$[0-9]+ { proxy.alterId = parseIn
787
845
  udp_port = comma "udp-port" equals match:$[0-9]+ { proxy["udp-port"] = parseInt(match.trim()); }
788
846
  shadow_tls_version = comma "shadow-tls-version" equals match:$[0-9]+ { proxy["shadow-tls-version"] = parseInt(match.trim()); }
789
847
  shadow_tls_sni = comma "shadow-tls-sni" equals match:[^,]+ { proxy["shadow-tls-sni"] = match.join(""); }
790
- shadow_tls_password = comma "shadow-tls-password" equals match:[^,]+ { proxy["shadow-tls-password"] = match.join(""); }
848
+ shadow_tls_password = comma "shadow-tls-password" equals match:[^,]+ { proxy["shadow-tls-password"] = match.join("").replace(/^"(.*?)"$/, '$1').replace(/^'(.*?)'$/, '$1'); }
791
849
 
792
850
  over_tls = comma "over-tls" equals flag:bool { proxy.tls = flag; }
793
851
  tls_name = comma sni:("tls-name") equals match:[^,]+ { proxy.sni = match.join("").replace(/^"(.*)"$/, '$1'); }
@@ -795,6 +853,19 @@ sni = comma "sni" equals match:[^,]+ { proxy.sni = match.join("").replace(/^"(.*
795
853
  tls_verification = comma "skip-cert-verify" equals flag:bool { proxy["skip-cert-verify"] = flag; }
796
854
  tls_cert_sha256 = comma "tls-cert-sha256" equals match:[^,]+ { proxy["tls-fingerprint"] = match.join("").replace(/^"(.*)"$/, '$1'); }
797
855
  tls_pubkey_sha256 = comma "tls-pubkey-sha256" equals match:[^,]+ { proxy["tls-pubkey-sha256"] = match.join("").replace(/^"(.*)"$/, '$1'); }
856
+ tls_profile = comma "tls-profile" equals match:[^,]+ {
857
+ const tlsProfile = match.join("").replace(/^"(.*)"$/, '$1').trim();
858
+ proxy["_loon_tls_profile"] = tlsProfile;
859
+ const clientFingerprint = loonClientFingerprint(tlsProfile);
860
+ if (clientFingerprint) proxy["client-fingerprint"] = clientFingerprint;
861
+ }
862
+ alpn = comma "alpn" equals '"' match:$[^"]* '"' {
863
+ const values = match
864
+ .split(",")
865
+ .map((item) => item.trim())
866
+ .filter((item) => item !== "");
867
+ if (values.length > 0) proxy.alpn = values;
868
+ }
798
869
 
799
870
  flow = comma "flow" equals match:[^,]+ { proxy["flow"] = match.join("").replace(/^"(.*)"$/, '$1'); }
800
871
  public_key = comma "public-key" equals match:[^,]+ { proxy["reality-opts"] = proxy["reality-opts"] || {}; proxy["reality-opts"]["public-key"] = match.join("").replace(/^"(.*)"$/, '$1'); }
@@ -1743,6 +1814,69 @@ function buildXrayEchConfigListFromMihomo(echOpts, fallbackEchConfigList, option
1743
1814
  return buildXrayEchFieldsFromMihomo(echOpts, fallbackEchConfigList, options).echConfigList;
1744
1815
  }
1745
1816
 
1817
+ // src/vendors/Sub-Store/backend/src/core/proxy-utils/vmess-security.js
1818
+ var VMESS_SECURITY_AUTO = "auto";
1819
+ var VMESS_SECURITY_COMMON_VALUES = [
1820
+ VMESS_SECURITY_AUTO,
1821
+ "none",
1822
+ "zero",
1823
+ "aes-128-gcm",
1824
+ "chacha20-poly1305"
1825
+ ];
1826
+ var VMESS_SECURITY_CLASH_VALUES = [
1827
+ VMESS_SECURITY_AUTO,
1828
+ "aes-128-gcm",
1829
+ "chacha20-poly1305",
1830
+ "none"
1831
+ ];
1832
+ var VMESS_SECURITY_QX_METHOD_VALUES = ["none", "chacha20-poly1305"];
1833
+ var VMESS_SECURITY_ALIASES = {
1834
+ "chacha20-ietf-poly1305": "chacha20-poly1305"
1835
+ };
1836
+ function normalizeSecurityValue(security) {
1837
+ if (security == null) return "";
1838
+ return `${security}`.trim().toLowerCase();
1839
+ }
1840
+ function canonicalizeVmessSecurity(security) {
1841
+ return VMESS_SECURITY_ALIASES[security] || security;
1842
+ }
1843
+ function normalizeVmessSecurity(security, supportedValues = VMESS_SECURITY_COMMON_VALUES, { acceptAliases = true, fallback = VMESS_SECURITY_AUTO } = {}) {
1844
+ const normalized = normalizeSecurityValue(security);
1845
+ if (!normalized) return fallback;
1846
+ const normalizedSupported = supportedValues.map(normalizeSecurityValue);
1847
+ if (normalizedSupported.includes(normalized)) {
1848
+ return canonicalizeVmessSecurity(normalized);
1849
+ }
1850
+ const canonical = canonicalizeVmessSecurity(normalized);
1851
+ const canonicalSupported = normalizedSupported.map(
1852
+ canonicalizeVmessSecurity
1853
+ );
1854
+ if (acceptAliases && canonicalSupported.includes(canonical)) {
1855
+ return canonical;
1856
+ }
1857
+ return fallback;
1858
+ }
1859
+ function normalizeClashVmessSecurity(security) {
1860
+ return normalizeVmessSecurity(security, VMESS_SECURITY_CLASH_VALUES);
1861
+ }
1862
+ function formatQXVmessMethod(security) {
1863
+ return normalizeVmessSecurity(security, VMESS_SECURITY_QX_METHOD_VALUES, {
1864
+ fallback: "chacha20-poly1305"
1865
+ });
1866
+ }
1867
+ function formatLoonVmessSecurity(security) {
1868
+ const normalized = normalizeClashVmessSecurity(security);
1869
+ return normalized === "chacha20-poly1305" ? "chacha20-ietf-poly1305" : normalized;
1870
+ }
1871
+ function formatSurgeVmessEncryptMethod(security) {
1872
+ const normalized = normalizeVmessSecurity(security, [
1873
+ "aes-128-gcm",
1874
+ "chacha20-poly1305"
1875
+ ]);
1876
+ if (normalized === VMESS_SECURITY_AUTO) return void 0;
1877
+ return normalized === "chacha20-poly1305" ? "chacha20-ietf-poly1305" : normalized;
1878
+ }
1879
+
1746
1880
  // src/vendors/Sub-Store/backend/src/core/proxy-utils/parsers/index.js
1747
1881
  function surge_port_hopping(raw) {
1748
1882
  const [parts, port_hopping] = raw.match(
@@ -2255,7 +2389,9 @@ function URI_VMess() {
2255
2389
  type: "vmess",
2256
2390
  server: partitions[1],
2257
2391
  port: partitions[2],
2258
- cipher: getIfNotBlank(partitions[3], "auto"),
2392
+ cipher: normalizeVmessSecurity(
2393
+ getIfNotBlank(partitions[3], "auto")
2394
+ ),
2259
2395
  uuid: partitions[4].match(/^"(.*)"$/)[1],
2260
2396
  tls: params.obfs === "wss",
2261
2397
  udp: getIfPresent(params["udp-relay"]),
@@ -2319,12 +2455,7 @@ function URI_VMess() {
2319
2455
  port,
2320
2456
  // https://github.com/2dust/v2rayN/wiki/Description-of-VMess-share-link
2321
2457
  // https://github.com/XTLS/Xray-core/issues/91
2322
- cipher: [
2323
- "auto",
2324
- "aes-128-gcm",
2325
- "chacha20-poly1305",
2326
- "none"
2327
- ].includes(params.scy) ? params.scy : "auto",
2458
+ cipher: normalizeVmessSecurity(params.scy),
2328
2459
  uuid: params.id,
2329
2460
  alterId: parseInt(
2330
2461
  getIfPresent(params.aid ?? params.alterId, 0),
@@ -2423,7 +2554,9 @@ function URI_VMess() {
2423
2554
  };
2424
2555
  const normalizedTransportHost = getIfNotBlank(transportHost);
2425
2556
  if (proxy.network === "h2") {
2426
- const h2Hosts = splitURIHostList(normalizedTransportHost);
2557
+ const h2Hosts = splitURIHostList(
2558
+ normalizedTransportHost
2559
+ );
2427
2560
  if (h2Hosts) {
2428
2561
  opts.host = h2Hosts;
2429
2562
  }
@@ -3192,14 +3325,15 @@ function URI_VLESS() {
3192
3325
  }
3193
3326
  proxy["tls-fingerprint"] = getIfPresent(params.pcs);
3194
3327
  proxy._h2 = /(TRUE)|1/i.test(params.h2);
3195
- switch (`${params.packetEncoding || ""}`.toLowerCase()) {
3328
+ switch (`${params.packetEncoding || ""}`.trim().toLowerCase()) {
3196
3329
  case "none":
3330
+ proxy["packet-encoding"] = "";
3197
3331
  break;
3198
3332
  case "packet":
3199
- proxy["packet-addr"] = true;
3333
+ proxy["packet-encoding"] = "packetaddr";
3200
3334
  break;
3201
3335
  default:
3202
- proxy.xudp = true;
3336
+ proxy["packet-encoding"] = "xudp";
3203
3337
  break;
3204
3338
  }
3205
3339
  if (["reality"].includes(params.security)) {
@@ -3819,6 +3953,9 @@ function Clash_All() {
3819
3953
  if (proxy["benchmark-timeout"]) {
3820
3954
  proxy["test-timeout"] = proxy["benchmark-timeout"];
3821
3955
  }
3956
+ if (proxy.type === "vmess") {
3957
+ proxy.cipher = normalizeVmessSecurity(proxy.cipher);
3958
+ }
3822
3959
  return proxy;
3823
3960
  };
3824
3961
  return { name, test, parse };
@@ -4299,6 +4436,175 @@ var parsers_default = [
4299
4436
 
4300
4437
  // src/vendors/Sub-Store/backend/src/core/proxy-utils/producers/utils.js
4301
4438
  import _2 from "lodash";
4439
+
4440
+ // src/vendors/Sub-Store/backend/src/core/proxy-utils/preprocessors/index.js
4441
+ import { Base64 as Base642 } from "js-base64";
4442
+ function normalizeClashYaml(raw) {
4443
+ if (typeof raw !== "string" || !raw.includes("proxies:") || !raw.includes("short-id:")) {
4444
+ return raw;
4445
+ }
4446
+ try {
4447
+ const content = safeLoad(raw);
4448
+ if (!Array.isArray(content.proxies) || content.proxies.length === 0)
4449
+ return raw;
4450
+ } catch (e) {
4451
+ return raw;
4452
+ }
4453
+ return raw.replace(/short-id:([ \t]*[^#\n,}]*)/g, (matched, value) => {
4454
+ const afterTrim = value.trim();
4455
+ if (!afterTrim || afterTrim === "") {
4456
+ return 'short-id: ""';
4457
+ }
4458
+ if (/^(['"]).*\1$/.test(afterTrim)) {
4459
+ return `short-id: ${afterTrim}`;
4460
+ } else if (["null"].includes(afterTrim)) {
4461
+ return `short-id: ${afterTrim}`;
4462
+ } else {
4463
+ return `short-id: "${afterTrim}"`;
4464
+ }
4465
+ });
4466
+ }
4467
+ function HTML() {
4468
+ const name = "HTML";
4469
+ const test = (raw) => /^<!DOCTYPE html>/.test(raw);
4470
+ const parse = () => "";
4471
+ return { name, test, parse };
4472
+ }
4473
+ function Base64Encoded() {
4474
+ const name = "Base64 Pre-processor";
4475
+ const keys = [
4476
+ "dm1lc3M",
4477
+ // vmess
4478
+ "c3NyOi8v",
4479
+ // ssr://
4480
+ "c29ja3M6Ly",
4481
+ // socks://
4482
+ "dHJvamFu",
4483
+ // trojan
4484
+ "c3M6Ly",
4485
+ // ss:/
4486
+ "c3NkOi8v",
4487
+ // ssd://
4488
+ "c2hhZG93",
4489
+ // shadow
4490
+ "aHR0c",
4491
+ // htt
4492
+ "dmxlc3M=",
4493
+ // vless
4494
+ "aHlzdGVyaWEy",
4495
+ // hysteria2
4496
+ "aHkyOi8v",
4497
+ // hy2://
4498
+ "d2lyZWd1YXJkOi8v",
4499
+ // wireguard://
4500
+ "d2c6Ly8=",
4501
+ // wg://
4502
+ "dHVpYzovLw=="
4503
+ // tuic://
4504
+ ];
4505
+ const test = function(raw) {
4506
+ return !/^\w+:\/\/\w+/im.test(raw) && keys.some((k) => raw.indexOf(k) !== -1);
4507
+ };
4508
+ const parse = function(raw) {
4509
+ const decoded = Base642.decode(raw);
4510
+ if (!/^\w+(:\/\/|\s*?=\s*?)\w+/m.test(decoded)) {
4511
+ app_default.error(
4512
+ `Base64 Pre-processor error: decoded line does not start with protocol`
4513
+ );
4514
+ return raw;
4515
+ }
4516
+ return decoded;
4517
+ };
4518
+ return { name, test, parse };
4519
+ }
4520
+ function fallbackBase64Encoded() {
4521
+ const name = "Fallback Base64 Pre-processor";
4522
+ const test = function(raw) {
4523
+ return true;
4524
+ };
4525
+ const parse = function(raw) {
4526
+ const decoded = Base642.decode(raw);
4527
+ if (!/^\w+(:\/\/|\s*?=\s*?)\w+/m.test(decoded)) {
4528
+ app_default.error(
4529
+ `Fallback Base64 Pre-processor error: decoded line does not start with protocol`
4530
+ );
4531
+ return raw;
4532
+ }
4533
+ return decoded;
4534
+ };
4535
+ return { name, test, parse };
4536
+ }
4537
+ function Clash() {
4538
+ const name = "Clash Pre-processor";
4539
+ const test = function(raw) {
4540
+ if (!/proxies/.test(raw)) return false;
4541
+ const content = safeLoad(raw);
4542
+ return content.proxies && Array.isArray(content.proxies);
4543
+ };
4544
+ const parse = function(raw, includeProxies) {
4545
+ const afterReplace = normalizeClashYaml(raw);
4546
+ const { proxies } = safeLoad(afterReplace);
4547
+ return (includeProxies ? "proxies:\n" : "") + proxies.map((p) => {
4548
+ return `${includeProxies ? " - " : ""}${JSON.stringify(
4549
+ p
4550
+ )}
4551
+ `;
4552
+ }).join("");
4553
+ };
4554
+ return { name, test, parse };
4555
+ }
4556
+ function SSD() {
4557
+ const name = "SSD Pre-processor";
4558
+ const test = function(raw) {
4559
+ return raw.indexOf("ssd://") === 0;
4560
+ };
4561
+ const parse = function(raw) {
4562
+ const output = [];
4563
+ let ssdinfo = JSON.parse(Base642.decode(raw.split("ssd://")[1]));
4564
+ let port = ssdinfo.port;
4565
+ let method = ssdinfo.encryption;
4566
+ let password = ssdinfo.password;
4567
+ let servers = ssdinfo.servers;
4568
+ for (let i = 0; i < servers.length; i++) {
4569
+ let server = servers[i];
4570
+ method = server.encryption ? server.encryption : method;
4571
+ password = server.password ? server.password : password;
4572
+ let userinfo = Base642.encode(method + ":" + password);
4573
+ let hostname = server.server;
4574
+ port = server.port ? server.port : port;
4575
+ let tag = server.remarks ? server.remarks : i;
4576
+ let plugin = server.plugin_options ? "/?plugin=" + encodeURIComponent(
4577
+ server.plugin + ";" + server.plugin_options
4578
+ ) : "";
4579
+ output[i] = "ss://" + userinfo + "@" + hostname + ":" + port + plugin + "#" + tag;
4580
+ }
4581
+ return output.join("\n");
4582
+ };
4583
+ return { name, test, parse };
4584
+ }
4585
+ function FullConfig() {
4586
+ const name = "Full Config Preprocessor";
4587
+ const test = function(raw) {
4588
+ return /^(\[server_local\]|\[Proxy\])/gm.test(raw);
4589
+ };
4590
+ const parse = function(raw) {
4591
+ const match = raw.match(
4592
+ /^\[server_local|Proxy\]([\s\S]+?)^\[.+?\](\r?\n|$)/im
4593
+ )?.[1];
4594
+ return match || raw;
4595
+ };
4596
+ return { name, test, parse };
4597
+ }
4598
+ var preprocessors_default = [
4599
+ HTML(),
4600
+ Clash(),
4601
+ Base64Encoded(),
4602
+ SSD(),
4603
+ FullConfig(),
4604
+ fallbackBase64Encoded()
4605
+ ];
4606
+
4607
+ // src/vendors/Sub-Store/backend/src/core/proxy-utils/producers/utils.js
4302
4608
  var Result = class {
4303
4609
  constructor(proxy) {
4304
4610
  this.proxy = proxy;
@@ -4384,13 +4690,15 @@ function getWireGuardAddressWithCIDR(proxy = {}, family = "ipv4") {
4384
4690
  function produceProxyListOutput(list, type, opts = {}) {
4385
4691
  if (type === "internal") return list;
4386
4692
  if (opts.prettyYaml || opts["pretty-yaml"]) {
4387
- return yaml_default.safeDump(
4388
- {
4389
- proxies: list
4390
- },
4391
- {
4392
- lineWidth: -1
4393
- }
4693
+ return normalizeClashYaml(
4694
+ yaml_default.safeDump(
4695
+ {
4696
+ proxies: list
4697
+ },
4698
+ {
4699
+ lineWidth: -1
4700
+ }
4701
+ )
4394
4702
  );
4395
4703
  }
4396
4704
  return "proxies:\n" + list.map((proxy) => " - " + JSON.stringify(proxy) + "\n").join("");
@@ -4419,12 +4727,13 @@ function stripSurgeQuotes(value) {
4419
4727
  const trimmed = value.trim();
4420
4728
  const quote = trimmed[0];
4421
4729
  if ((quote === '"' || quote === "'") && trimmed[trimmed.length - 1] === quote) {
4422
- return trimmed.slice(1, -1).replace(/\\(["'\\])/g, "$1");
4730
+ return trimmed.slice(1, -1);
4423
4731
  }
4424
- return trimmed.replace(/\\(["'\\])/g, "$1");
4732
+ return trimmed;
4425
4733
  }
4426
4734
  function quoteSurgeValue(value) {
4427
- return `"${String(stripSurgeQuotes(value)).replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
4735
+ const text = String(stripSurgeQuotes(value));
4736
+ return `"${text}"`;
4428
4737
  }
4429
4738
  function hasNonBlankValue(value) {
4430
4739
  return value != null && `${value}`.trim().length > 0;
@@ -4586,7 +4895,7 @@ function shadowsocks(proxy) {
4586
4895
  );
4587
4896
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
4588
4897
  if (isPresent2(proxy, "shadow-tls-password")) {
4589
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
4898
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
4590
4899
  result.appendIfPresent(
4591
4900
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
4592
4901
  "shadow-tls-version"
@@ -4601,7 +4910,7 @@ function shadowsocks(proxy) {
4601
4910
  const host = proxy["plugin-opts"].host;
4602
4911
  const version = proxy["plugin-opts"].version;
4603
4912
  if (password) {
4604
- result.append(`,shadow-tls-password=${password}`);
4913
+ result.append(`,shadow-tls-password="${password}"`);
4605
4914
  if (host) {
4606
4915
  result.append(`,shadow-tls-sni=${host}`);
4607
4916
  }
@@ -4668,7 +4977,7 @@ function trojan(proxy) {
4668
4977
  );
4669
4978
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
4670
4979
  if (isPresent2(proxy, "shadow-tls-password")) {
4671
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
4980
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
4672
4981
  result.appendIfPresent(
4673
4982
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
4674
4983
  "shadow-tls-version"
@@ -4835,7 +5144,7 @@ function h2Connect(proxy) {
4835
5144
  );
4836
5145
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
4837
5146
  if (isPresent2(proxy, "shadow-tls-password")) {
4838
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
5147
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
4839
5148
  result.appendIfPresent(
4840
5149
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
4841
5150
  "shadow-tls-version"
@@ -4856,6 +5165,10 @@ function vmess(proxy, includeUnsupportedProxy) {
4856
5165
  const result = new Result(proxy);
4857
5166
  result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
4858
5167
  result.appendIfPresent(`,username=${proxy.uuid}`, "uuid");
5168
+ const encryptMethod = formatSurgeVmessEncryptMethod(proxy.cipher);
5169
+ if (encryptMethod) {
5170
+ result.append(`,encrypt-method=${encryptMethod}`);
5171
+ }
4859
5172
  const ip_version = ipVersions[proxy["ip-version"]] || proxy["ip-version"];
4860
5173
  result.appendIfPresent(`,ip-version=${ip_version}`, "ip-version");
4861
5174
  result.appendIfPresent(
@@ -4899,7 +5212,7 @@ function vmess(proxy, includeUnsupportedProxy) {
4899
5212
  );
4900
5213
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
4901
5214
  if (isPresent2(proxy, "shadow-tls-password")) {
4902
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
5215
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
4903
5216
  result.appendIfPresent(
4904
5217
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
4905
5218
  "shadow-tls-version"
@@ -5005,7 +5318,7 @@ function http(proxy) {
5005
5318
  );
5006
5319
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
5007
5320
  if (isPresent2(proxy, "shadow-tls-password")) {
5008
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
5321
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
5009
5322
  result.appendIfPresent(
5010
5323
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
5011
5324
  "shadow-tls-version"
@@ -5102,7 +5415,7 @@ function socks5(proxy) {
5102
5415
  );
5103
5416
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
5104
5417
  if (isPresent2(proxy, "shadow-tls-password")) {
5105
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
5418
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
5106
5419
  result.appendIfPresent(
5107
5420
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
5108
5421
  "shadow-tls-version"
@@ -5122,23 +5435,23 @@ function socks5(proxy) {
5122
5435
  function appendHeaders(result, proxy) {
5123
5436
  const value = formatHeaders(proxy.headers);
5124
5437
  if (isNotBlank(value)) {
5125
- result.append(`,headers="${value}"`);
5438
+ result.append(`,headers=${quoteSurgeValue(value)}`);
5126
5439
  }
5127
5440
  }
5128
5441
  function formatHeaders(headers) {
5442
+ return formatHeaderMap(headers, ";");
5443
+ }
5444
+ function formatHeaderMap(headers, separator) {
5129
5445
  if (!headers || typeof headers !== "object") {
5130
5446
  return "";
5131
5447
  }
5132
- return Object.entries(headers).filter(([key, value]) => isNotBlank(key) && value != null).map(([key, value]) => `${key}:"${escapeHeaderValue(value)}"`).join(";");
5133
- }
5134
- function escapeHeaderValue(value) {
5135
- return String(value).replace(/\\/g, "\\\\").replace(/"/g, '\\"');
5448
+ return Object.entries(headers).filter(([key, value]) => isNotBlank(key) && value != null).map(([key, value]) => `${key}:${quoteSurgeValue(value)}`).join(separator);
5136
5449
  }
5137
5450
  function snell(proxy) {
5138
5451
  const result = new Result(proxy);
5139
5452
  result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
5140
5453
  result.appendIfPresent(`,version=${proxy.version}`, "version");
5141
- result.appendIfPresent(`,psk=${proxy.psk}`, "psk");
5454
+ result.appendIfPresent(`,psk="${proxy.psk}"`, "psk");
5142
5455
  const ip_version = ipVersions[proxy["ip-version"]] || proxy["ip-version"];
5143
5456
  result.appendIfPresent(`,ip-version=${ip_version}`, "ip-version");
5144
5457
  result.appendIfPresent(
@@ -5177,7 +5490,7 @@ function snell(proxy) {
5177
5490
  );
5178
5491
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
5179
5492
  if (isPresent2(proxy, "shadow-tls-password")) {
5180
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
5493
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
5181
5494
  result.appendIfPresent(
5182
5495
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
5183
5496
  "shadow-tls-version"
@@ -5256,7 +5569,7 @@ function tuic(proxy) {
5256
5569
  );
5257
5570
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
5258
5571
  if (isPresent2(proxy, "shadow-tls-password")) {
5259
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
5572
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
5260
5573
  result.appendIfPresent(
5261
5574
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
5262
5575
  "shadow-tls-version"
@@ -5317,7 +5630,7 @@ function wireguard(proxy) {
5317
5630
  );
5318
5631
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
5319
5632
  if (isPresent2(proxy, "shadow-tls-password")) {
5320
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
5633
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
5321
5634
  result.appendIfPresent(
5322
5635
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
5323
5636
  "shadow-tls-version"
@@ -5401,7 +5714,7 @@ function wireguard_surge(proxy) {
5401
5714
  );
5402
5715
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
5403
5716
  if (isPresent2(proxy, "shadow-tls-password")) {
5404
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
5717
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
5405
5718
  result.appendIfPresent(
5406
5719
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
5407
5720
  "shadow-tls-version"
@@ -5475,7 +5788,7 @@ function hysteria2(proxy) {
5475
5788
  );
5476
5789
  result.appendIfPresent(`,interface=${proxy["interface"]}`, "interface");
5477
5790
  if (isPresent2(proxy, "shadow-tls-password")) {
5478
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
5791
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
5479
5792
  result.appendIfPresent(
5480
5793
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
5481
5794
  "shadow-tls-version"
@@ -5508,13 +5821,9 @@ function handleTransport(result, proxy, includeUnsupportedProxy) {
5508
5821
  );
5509
5822
  if (isPresent2(proxy, "ws-opts.headers")) {
5510
5823
  const headers = proxy["ws-opts"].headers;
5511
- const value = Object.keys(headers).map((k) => {
5512
- let v = headers[k];
5513
- v = `"${v}"`;
5514
- return `${k}:${v}`;
5515
- }).join("|");
5824
+ const value = formatHeaderMap(headers, "|");
5516
5825
  if (isNotBlank(value)) {
5517
- result.append(`,ws-headers=${value}`);
5826
+ result.append(`,ws-headers=${quoteSurgeValue(value)}`);
5518
5827
  }
5519
5828
  }
5520
5829
  }
@@ -5533,7 +5842,7 @@ function handleTransport(result, proxy, includeUnsupportedProxy) {
5533
5842
  }
5534
5843
 
5535
5844
  // src/vendors/Sub-Store/backend/src/core/proxy-utils/producers/surgemac.js
5536
- import { Base64 as Base642 } from "js-base64";
5845
+ import { Base64 as Base643 } from "js-base64";
5537
5846
 
5538
5847
  // src/vendors/Sub-Store/backend/src/core/proxy-utils/producers/clashmeta.js
5539
5848
  var ipVersions2 = {
@@ -5650,15 +5959,7 @@ function ClashMeta_Producer() {
5650
5959
  proxy.servername = proxy.sni;
5651
5960
  delete proxy.sni;
5652
5961
  }
5653
- if (isPresent2(proxy, "cipher") && ![
5654
- "auto",
5655
- "none",
5656
- "zero",
5657
- "aes-128-gcm",
5658
- "chacha20-poly1305"
5659
- ].includes(proxy.cipher)) {
5660
- proxy.cipher = "auto";
5661
- }
5962
+ proxy.cipher = normalizeVmessSecurity(proxy.cipher);
5662
5963
  } else if (proxy.type === "tuic") {
5663
5964
  if (isPresent2(proxy, "alpn")) {
5664
5965
  proxy.alpn = Array.isArray(proxy.alpn) ? proxy.alpn : [proxy.alpn];
@@ -5986,7 +6287,7 @@ function mihomo(proxy, type, opts) {
5986
6287
  "local-port": localPort,
5987
6288
  args: [
5988
6289
  "-config",
5989
- Base642.encode(
6290
+ Base643.encode(
5990
6291
  JSON.stringify({
5991
6292
  "mixed-port": localPort,
5992
6293
  ipv6,
@@ -6082,14 +6383,7 @@ function Clash_Producer() {
6082
6383
  proxy.servername = proxy.sni;
6083
6384
  delete proxy.sni;
6084
6385
  }
6085
- if (isPresent2(proxy, "cipher") && ![
6086
- "auto",
6087
- "aes-128-gcm",
6088
- "chacha20-poly1305",
6089
- "none"
6090
- ].includes(proxy.cipher)) {
6091
- proxy.cipher = "auto";
6092
- }
6386
+ proxy.cipher = normalizeClashVmessSecurity(proxy.cipher);
6093
6387
  } else if (proxy.type === "wireguard") {
6094
6388
  proxy.keepalive = proxy.keepalive ?? proxy["persistent-keepalive"];
6095
6389
  proxy["persistent-keepalive"] = proxy.keepalive;
@@ -6212,7 +6506,8 @@ function Stash_Producer() {
6212
6506
  "ssh",
6213
6507
  "juicity",
6214
6508
  "anytls",
6215
- "tailscale"
6509
+ "tailscale",
6510
+ "trusttunnel"
6216
6511
  ].includes(proxy.type) || proxy.type === "ss" && ![
6217
6512
  "aes-128-gcm",
6218
6513
  "aes-192-gcm",
@@ -6258,14 +6553,7 @@ function Stash_Producer() {
6258
6553
  proxy.servername = proxy.sni;
6259
6554
  delete proxy.sni;
6260
6555
  }
6261
- if (isPresent2(proxy, "cipher") && ![
6262
- "auto",
6263
- "aes-128-gcm",
6264
- "chacha20-poly1305",
6265
- "none"
6266
- ].includes(proxy.cipher)) {
6267
- proxy.cipher = "auto";
6268
- }
6556
+ proxy.cipher = normalizeClashVmessSecurity(proxy.cipher);
6269
6557
  } else if (proxy.type === "tuic") {
6270
6558
  if (isPresent2(proxy, "alpn")) {
6271
6559
  proxy.alpn = Array.isArray(proxy.alpn) ? proxy.alpn : [proxy.alpn];
@@ -6489,6 +6777,30 @@ function Loon_Producer() {
6489
6777
  };
6490
6778
  return { produce: produce2 };
6491
6779
  }
6780
+ function appendTlsProfile(result, proxy) {
6781
+ const tlsProfile = getLoonTlsProfile(proxy);
6782
+ if (tlsProfile) result.append(`,tls-profile=${tlsProfile}`);
6783
+ }
6784
+ function appendAlpn(result, proxy) {
6785
+ const alpn = getLoonAlpn(proxy);
6786
+ if (alpn) result.append(`,alpn="${alpn}"`);
6787
+ }
6788
+ function getLoonAlpn(proxy) {
6789
+ const values = Array.isArray(proxy.alpn) ? proxy.alpn : `${proxy.alpn || ""}`.split(",");
6790
+ return values.map((item) => `${item}`.trim()).filter((item) => item !== "").join(",");
6791
+ }
6792
+ function getLoonTlsProfile(proxy) {
6793
+ const tlsProfile = `${proxy._loon_tls_profile || ""}`.trim();
6794
+ if (["default", "chrome", "ios18", "ios26"].includes(tlsProfile)) {
6795
+ return tlsProfile;
6796
+ }
6797
+ switch (`${proxy["client-fingerprint"] || ""}`.trim()) {
6798
+ case "chrome":
6799
+ return "chrome";
6800
+ case "ios":
6801
+ return "ios26";
6802
+ }
6803
+ }
6492
6804
  function shadowsocks2(proxy) {
6493
6805
  const result = new Result(proxy);
6494
6806
  if (![
@@ -6541,7 +6853,7 @@ function shadowsocks2(proxy) {
6541
6853
  }
6542
6854
  }
6543
6855
  if (isPresent2(proxy, "shadow-tls-password")) {
6544
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
6856
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
6545
6857
  result.appendIfPresent(
6546
6858
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
6547
6859
  "shadow-tls-version"
@@ -6556,7 +6868,7 @@ function shadowsocks2(proxy) {
6556
6868
  const host = proxy["plugin-opts"].host;
6557
6869
  const version = proxy["plugin-opts"].version;
6558
6870
  if (password) {
6559
- result.append(`,shadow-tls-password=${password}`);
6871
+ result.append(`,shadow-tls-password="${password}"`);
6560
6872
  if (host) {
6561
6873
  result.append(`,shadow-tls-sni=${host}`);
6562
6874
  }
@@ -6615,7 +6927,7 @@ function shadowsocksr(proxy) {
6615
6927
  result.appendIfPresent(`,obfs=${proxy.obfs}`, "obfs");
6616
6928
  result.appendIfPresent(`,obfs-param=${proxy["obfs-param"]}`, "obfs-param");
6617
6929
  if (isPresent2(proxy, "shadow-tls-password")) {
6618
- result.append(`,shadow-tls-password=${proxy["shadow-tls-password"]}`);
6930
+ result.append(`,shadow-tls-password="${proxy["shadow-tls-password"]}"`);
6619
6931
  result.appendIfPresent(
6620
6932
  `,shadow-tls-version=${proxy["shadow-tls-version"]}`,
6621
6933
  "shadow-tls-version"
@@ -6630,7 +6942,7 @@ function shadowsocksr(proxy) {
6630
6942
  const host = proxy["plugin-opts"].host;
6631
6943
  const version = proxy["plugin-opts"].version;
6632
6944
  if (password) {
6633
- result.append(`,shadow-tls-password=${password}`);
6945
+ result.append(`,shadow-tls-password="${password}"`);
6634
6946
  if (host) {
6635
6947
  result.append(`,shadow-tls-sni=${host}`);
6636
6948
  }
@@ -6688,6 +7000,8 @@ function trojan2(proxy) {
6688
7000
  `,skip-cert-verify=${proxy["skip-cert-verify"]}`,
6689
7001
  "skip-cert-verify"
6690
7002
  );
7003
+ appendTlsProfile(result, proxy);
7004
+ appendAlpn(result, proxy);
6691
7005
  result.appendIfPresent(`,tls-name=${proxy.sni}`, "sni");
6692
7006
  result.appendIfPresent(
6693
7007
  `,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
@@ -6729,6 +7043,8 @@ function anytls2(proxy) {
6729
7043
  `,skip-cert-verify=${proxy["skip-cert-verify"]}`,
6730
7044
  "skip-cert-verify"
6731
7045
  );
7046
+ appendTlsProfile(result, proxy);
7047
+ appendAlpn(result, proxy);
6732
7048
  result.appendIfPresent(`,tls-name=${proxy.sni}`, "sni");
6733
7049
  result.appendIfPresent(
6734
7050
  `,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
@@ -6753,9 +7069,10 @@ function anytls2(proxy) {
6753
7069
  }
6754
7070
  function vmess2(proxy) {
6755
7071
  const isReality = !!proxy["reality-opts"];
7072
+ const security = formatLoonVmessSecurity(proxy.cipher);
6756
7073
  const result = new Result(proxy);
6757
7074
  result.append(
6758
- `${proxy.name}=vmess,${proxy.server},${proxy.port},${proxy.cipher},"${proxy.uuid}"`
7075
+ `${proxy.name}=vmess,${proxy.server},${proxy.port},${security},"${proxy.uuid}"`
6759
7076
  );
6760
7077
  if (proxy.network === "tcp") {
6761
7078
  delete proxy.network;
@@ -6794,6 +7111,10 @@ function vmess2(proxy) {
6794
7111
  `,skip-cert-verify=${proxy["skip-cert-verify"]}`,
6795
7112
  "skip-cert-verify"
6796
7113
  );
7114
+ if (proxy.tls || isReality) {
7115
+ appendTlsProfile(result, proxy);
7116
+ appendAlpn(result, proxy);
7117
+ }
6797
7118
  if (isReality) {
6798
7119
  result.appendIfPresent(`,sni=${proxy.sni}`, "sni");
6799
7120
  result.appendIfPresent(
@@ -6886,6 +7207,10 @@ function vless(proxy) {
6886
7207
  `,skip-cert-verify=${proxy["skip-cert-verify"]}`,
6887
7208
  "skip-cert-verify"
6888
7209
  );
7210
+ if (proxy.tls || isReality || isXtls) {
7211
+ appendTlsProfile(result, proxy);
7212
+ appendAlpn(result, proxy);
7213
+ }
6889
7214
  if (isXtls) {
6890
7215
  result.appendIfPresent(`,flow=${proxy.flow}`, "flow");
6891
7216
  }
@@ -6934,6 +7259,10 @@ function http2(proxy) {
6934
7259
  `,skip-cert-verify=${proxy["skip-cert-verify"]}`,
6935
7260
  "skip-cert-verify"
6936
7261
  );
7262
+ if (proxy.tls) {
7263
+ appendTlsProfile(result, proxy);
7264
+ appendAlpn(result, proxy);
7265
+ }
6937
7266
  result.appendIfPresent(`,tfo=${proxy.tfo}`, "tfo");
6938
7267
  if (proxy["block-quic"] === "on") {
6939
7268
  result.append(",block-quic=true");
@@ -6955,6 +7284,10 @@ function socks52(proxy) {
6955
7284
  `,skip-cert-verify=${proxy["skip-cert-verify"]}`,
6956
7285
  "skip-cert-verify"
6957
7286
  );
7287
+ if (proxy.tls) {
7288
+ appendTlsProfile(result, proxy);
7289
+ appendAlpn(result, proxy);
7290
+ }
6958
7291
  result.appendIfPresent(`,tfo=${proxy.tfo}`, "tfo");
6959
7292
  if (proxy["block-quic"] === "on") {
6960
7293
  result.append(",block-quic=true");
@@ -7052,6 +7385,8 @@ function hysteria22(proxy) {
7052
7385
  `,skip-cert-verify=${proxy["skip-cert-verify"]}`,
7053
7386
  "skip-cert-verify"
7054
7387
  );
7388
+ appendTlsProfile(result, proxy);
7389
+ appendAlpn(result, proxy);
7055
7390
  if (proxy["obfs-password"] && proxy.obfs == "salamander") {
7056
7391
  result.append(`,salamander-password=${proxy["obfs-password"]}`);
7057
7392
  }
@@ -7075,7 +7410,7 @@ function hysteria22(proxy) {
7075
7410
  }
7076
7411
 
7077
7412
  // src/vendors/Sub-Store/backend/src/core/proxy-utils/producers/uri.js
7078
- import { Base64 as Base643 } from "js-base64";
7413
+ import { Base64 as Base644 } from "js-base64";
7079
7414
  function toStringHeaderMap(headers, { excludeHost = false } = {}) {
7080
7415
  if (!isPlainObject(headers)) {
7081
7416
  return void 0;
@@ -7634,10 +7969,26 @@ function vless2(proxy) {
7634
7969
  vlessTransport += `&eh=${encodeURIComponent(earlyDataHeaderName)}`;
7635
7970
  }
7636
7971
  let packetEncoding = "";
7637
- if (proxy["packet-addr"]) {
7638
- packetEncoding = "&packetEncoding=packet";
7639
- } else if (proxy.udp === true && !proxy.xudp) {
7640
- packetEncoding = "&packetEncoding=none";
7972
+ let canonicalPacketEncoding;
7973
+ if (proxy["packet-encoding"] != null) {
7974
+ canonicalPacketEncoding = `${proxy["packet-encoding"]}`.trim().toLowerCase();
7975
+ } else if (proxy.xudp) {
7976
+ canonicalPacketEncoding = "xudp";
7977
+ } else if (proxy["packet-addr"]) {
7978
+ canonicalPacketEncoding = "packetaddr";
7979
+ } else if (proxy.udp === true) {
7980
+ canonicalPacketEncoding = "";
7981
+ }
7982
+ switch (canonicalPacketEncoding) {
7983
+ case "":
7984
+ packetEncoding = "&packetEncoding=none";
7985
+ break;
7986
+ case "packetaddr":
7987
+ packetEncoding = "&packetEncoding=packet";
7988
+ break;
7989
+ case "xudp":
7990
+ packetEncoding = "&packetEncoding=xudp";
7991
+ break;
7641
7992
  }
7642
7993
  return `vless://${proxy.uuid}@${proxy.server}:${proxy.port}?security=${encodeURIComponent(
7643
7994
  security
@@ -7674,7 +8025,7 @@ function URI_Producer() {
7674
8025
  switch (proxy.type) {
7675
8026
  case "socks5":
7676
8027
  result = `socks://${encodeURIComponent(
7677
- Base643.encode(
8028
+ Base644.encode(
7678
8029
  `${proxy.username ?? ""}:${proxy.password ?? ""}`
7679
8030
  )
7680
8031
  )}@${proxy.server}:${proxy.port}#${proxy.name}`;
@@ -7683,7 +8034,7 @@ function URI_Producer() {
7683
8034
  const userinfo = `${proxy.cipher}:${proxy.password}`;
7684
8035
  result = `ss://${proxy.cipher?.startsWith("2022-blake3-") ? `${encodeURIComponent(
7685
8036
  proxy.cipher
7686
- )}:${encodeURIComponent(proxy.password)}` : Base643.encode(userinfo)}@${proxy.server}:${proxy.port}${proxy.plugin ? "/" : ""}`;
8037
+ )}:${encodeURIComponent(proxy.password)}` : Base644.encode(userinfo)}@${proxy.server}:${proxy.port}${proxy.plugin ? "/" : ""}`;
7687
8038
  let query = "";
7688
8039
  if (proxy.plugin) {
7689
8040
  query += "&plugin=";
@@ -7821,9 +8172,9 @@ function URI_Producer() {
7821
8172
  result += query.replace(/^&/, "?");
7822
8173
  break;
7823
8174
  case "ssr":
7824
- result = `${proxy.server}:${proxy.port}:${proxy.protocol}:${proxy.cipher}:${proxy.obfs}:${Base643.encode(proxy.password)}/`;
7825
- result += `?remarks=${Base643.encode(proxy.name)}${proxy["obfs-param"] ? "&obfsparam=" + Base643.encode(proxy["obfs-param"]) : ""}${proxy["protocol-param"] ? "&protocolparam=" + Base643.encode(proxy["protocol-param"]) : ""}`;
7826
- result = "ssr://" + Base643.encode(result);
8175
+ result = `${proxy.server}:${proxy.port}:${proxy.protocol}:${proxy.cipher}:${proxy.obfs}:${Base644.encode(proxy.password)}/`;
8176
+ result += `?remarks=${Base644.encode(proxy.name)}${proxy["obfs-param"] ? "&obfsparam=" + Base644.encode(proxy["obfs-param"]) : ""}${proxy["protocol-param"] ? "&protocolparam=" + Base644.encode(proxy["protocol-param"]) : ""}`;
8177
+ result = "ssr://" + Base644.encode(result);
7827
8178
  break;
7828
8179
  case "vmess":
7829
8180
  let type2 = "";
@@ -7841,7 +8192,7 @@ function URI_Producer() {
7841
8192
  port: `${proxy.port}`,
7842
8193
  id: proxy.uuid,
7843
8194
  aid: `${proxy.alterId || 0}`,
7844
- scy: proxy.cipher,
8195
+ scy: normalizeVmessSecurity(proxy.cipher),
7845
8196
  net,
7846
8197
  type: type2,
7847
8198
  tls: proxy.tls ? "tls" : "",
@@ -7890,7 +8241,7 @@ function URI_Producer() {
7890
8241
  }
7891
8242
  }
7892
8243
  }
7893
- result = "vmess://" + Base643.encode(JSON.stringify(result));
8244
+ result = "vmess://" + Base644.encode(JSON.stringify(result));
7894
8245
  break;
7895
8246
  case "vless":
7896
8247
  result = vless2(proxy);
@@ -8280,7 +8631,7 @@ function URI_Producer() {
8280
8631
  }
8281
8632
 
8282
8633
  // src/vendors/Sub-Store/backend/src/core/proxy-utils/producers/v2ray.js
8283
- import { Base64 as Base644 } from "js-base64";
8634
+ import { Base64 as Base645 } from "js-base64";
8284
8635
  var URI = URI_Producer();
8285
8636
  function V2Ray_Producer() {
8286
8637
  const type = "ALL";
@@ -8294,7 +8645,7 @@ function V2Ray_Producer() {
8294
8645
  Reason: ${err}`);
8295
8646
  }
8296
8647
  });
8297
- return Base644.encode(result.join("\n"));
8648
+ return Base645.encode(result.join("\n"));
8298
8649
  };
8299
8650
  return { type, produce: produce2 };
8300
8651
  }
@@ -8557,12 +8908,7 @@ function vmess3(proxy) {
8557
8908
  const append = result.append.bind(result);
8558
8909
  const appendIfPresent = result.appendIfPresent.bind(result);
8559
8910
  append(`vmess=${proxy.server}:${proxy.port}`);
8560
- let cipher;
8561
- if (proxy.cipher === "auto") {
8562
- cipher = "chacha20-ietf-poly1305";
8563
- } else {
8564
- cipher = proxy.cipher;
8565
- }
8911
+ let cipher = formatQXVmessMethod(proxy.cipher);
8566
8912
  append(`,method=${cipher}`);
8567
8913
  append(`,password=${proxy.uuid}`);
8568
8914
  if (needTls(proxy)) {
@@ -8852,7 +9198,7 @@ function Shadowrocket_Producer() {
8852
9198
  "grpc"
8853
9199
  ])) {
8854
9200
  return false;
8855
- } else if (proxy.type === "snell" && proxy.version >= 4) {
9201
+ } else if (proxy.type === "snell" && ![1, 2, 3, 4, 5].includes(proxy.version)) {
8856
9202
  return false;
8857
9203
  } else if ([
8858
9204
  "tailscale",
@@ -8882,15 +9228,7 @@ function Shadowrocket_Producer() {
8882
9228
  proxy.servername = proxy.sni;
8883
9229
  delete proxy.sni;
8884
9230
  }
8885
- if (isPresent2(proxy, "cipher") && ![
8886
- "auto",
8887
- "none",
8888
- "zero",
8889
- "aes-128-gcm",
8890
- "chacha20-poly1305"
8891
- ].includes(proxy.cipher)) {
8892
- proxy.cipher = "auto";
8893
- }
9231
+ proxy.cipher = normalizeVmessSecurity(proxy.cipher);
8894
9232
  } else if (proxy.type === "tuic") {
8895
9233
  if (isPresent2(proxy, "alpn")) {
8896
9234
  proxy.alpn = Array.isArray(proxy.alpn) ? proxy.alpn : [proxy.alpn];
@@ -9136,7 +9474,7 @@ function snell2(proxy) {
9136
9474
  const result = new Result(proxy);
9137
9475
  result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
9138
9476
  result.appendIfPresent(`,version=${proxy.version}`, "version");
9139
- result.appendIfPresent(`,psk=${proxy.psk}`, "psk");
9477
+ result.appendIfPresent(`,psk="${proxy.psk}"`, "psk");
9140
9478
  result.appendIfPresent(
9141
9479
  `,obfs=${proxy["obfs-opts"]?.mode}`,
9142
9480
  "obfs-opts.mode"
@@ -9569,6 +9907,22 @@ var normalizePemLines = (value, label) => {
9569
9907
  }
9570
9908
  return [`-----BEGIN ${label}-----`, ...lines, `-----END ${label}-----`];
9571
9909
  };
9910
+ var singBoxUtlsFingerprints = [
9911
+ "chrome",
9912
+ "firefox",
9913
+ "edge",
9914
+ "safari",
9915
+ "360",
9916
+ "qq",
9917
+ "ios",
9918
+ "android",
9919
+ "random",
9920
+ "randomized"
9921
+ ];
9922
+ var getSingBoxUtlsFingerprint = (value) => {
9923
+ const fingerprint = `${value || ""}`.trim().toLowerCase();
9924
+ if (singBoxUtlsFingerprints.includes(fingerprint)) return fingerprint;
9925
+ };
9572
9926
  var tlsParser = (proxy, parsedProxy) => {
9573
9927
  if (proxy.tls) parsedProxy.tls.enabled = true;
9574
9928
  if (proxy.servername && proxy.servername !== "")
@@ -9593,11 +9947,17 @@ var tlsParser = (proxy, parsedProxy) => {
9593
9947
  parsedProxy.tls.reality.short_id = proxy["reality-opts"]["short-id"];
9594
9948
  parsedProxy.tls.utls = { enabled: true };
9595
9949
  }
9596
- if (!["hysteria", "hysteria2", "tuic"].includes(proxy.type) && proxy["client-fingerprint"] && proxy["client-fingerprint"] !== "")
9597
- parsedProxy.tls.utls = {
9598
- enabled: true,
9599
- fingerprint: proxy["client-fingerprint"]
9600
- };
9950
+ if (!["hysteria", "hysteria2", "tuic"].includes(proxy.type) && proxy["client-fingerprint"] && proxy["client-fingerprint"] !== "") {
9951
+ const fingerprint = getSingBoxUtlsFingerprint(
9952
+ proxy["client-fingerprint"]
9953
+ );
9954
+ if (fingerprint)
9955
+ parsedProxy.tls.utls = {
9956
+ ...parsedProxy.tls.utls,
9957
+ enabled: true,
9958
+ fingerprint
9959
+ };
9960
+ }
9601
9961
  if (proxy._ech && isPlainObject(proxy._ech)) {
9602
9962
  parsedProxy.tls.ech = proxy._ech;
9603
9963
  } else if (proxy["ech-opts"] && isPlainObject(proxy["ech-opts"])) {
@@ -9771,6 +10131,7 @@ var normalizeALPN = (alpn) => {
9771
10131
  };
9772
10132
  var shadowTLSOutboundParser = (proxy = {}, pluginOpts) => {
9773
10133
  if (!pluginOpts) throw new Error("shadow-tls plugin options are missing");
10134
+ const fingerprint = getSingBoxUtlsFingerprint(proxy["client-fingerprint"]);
9774
10135
  const stPart = {
9775
10136
  tag: getShadowTLSTag(proxy),
9776
10137
  type: "shadowtls",
@@ -9783,7 +10144,7 @@ var shadowTLSOutboundParser = (proxy = {}, pluginOpts) => {
9783
10144
  server_name: pluginOpts.host,
9784
10145
  utls: {
9785
10146
  enabled: true,
9786
- fingerprint: proxy["client-fingerprint"]
10147
+ fingerprint
9787
10148
  }
9788
10149
  }
9789
10150
  };
@@ -9952,6 +10313,36 @@ var snellParser = (proxy = {}) => {
9952
10313
  }
9953
10314
  return parsedProxy;
9954
10315
  };
10316
+ var singBoxPacketEncodings = ["", "packetaddr", "xudp"];
10317
+ var normalizeSingBoxPacketEncoding = (value) => {
10318
+ const packetEncoding = `${value}`.trim().toLowerCase();
10319
+ if (singBoxPacketEncodings.includes(packetEncoding)) {
10320
+ return packetEncoding;
10321
+ }
10322
+ return void 0;
10323
+ };
10324
+ var vmessVlessPacketEncodingParser = (proxy, parsedProxy) => {
10325
+ if (proxy["packet-encoding"] != null) {
10326
+ const packetEncoding = normalizeSingBoxPacketEncoding(
10327
+ proxy["packet-encoding"]
10328
+ );
10329
+ if (packetEncoding != null)
10330
+ parsedProxy.packet_encoding = packetEncoding;
10331
+ } else if (proxy.xudp) {
10332
+ parsedProxy.packet_encoding = "xudp";
10333
+ } else if (proxy["packet-addr"]) {
10334
+ parsedProxy.packet_encoding = "packetaddr";
10335
+ }
10336
+ };
10337
+ var vmessProtocolOptionsParser = (proxy, parsedProxy) => {
10338
+ vmessVlessPacketEncodingParser(proxy, parsedProxy);
10339
+ if (proxy["global-padding"] != null) {
10340
+ parsedProxy.global_padding = !!proxy["global-padding"];
10341
+ }
10342
+ if (proxy["authenticated-length"] != null) {
10343
+ parsedProxy.authenticated_length = !!proxy["authenticated-length"];
10344
+ }
10345
+ };
9955
10346
  var vmessParser = (proxy = {}) => {
9956
10347
  const parsedProxy = {
9957
10348
  tag: proxy.name,
@@ -9959,22 +10350,13 @@ var vmessParser = (proxy = {}) => {
9959
10350
  server: proxy.server,
9960
10351
  server_port: parseInt(`${proxy.port}`, 10),
9961
10352
  uuid: proxy.uuid,
9962
- security: proxy.cipher,
10353
+ security: normalizeVmessSecurity(proxy.cipher),
9963
10354
  alter_id: parseInt(`${proxy.alterId}`, 10),
9964
10355
  tls: { enabled: false, server_name: proxy.server, insecure: false }
9965
10356
  };
9966
- if ([
9967
- "auto",
9968
- "none",
9969
- "zero",
9970
- "aes-128-gcm",
9971
- "chacha20-poly1305",
9972
- "aes-128-ctr"
9973
- ].indexOf(parsedProxy.security) === -1)
9974
- parsedProxy.security = "auto";
9975
10357
  if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
9976
10358
  throw "invalid port";
9977
- if (proxy.xudp) parsedProxy.packet_encoding = "xudp";
10359
+ vmessProtocolOptionsParser(proxy, parsedProxy);
9978
10360
  if (proxy["fast-open"]) parsedProxy.udp_fragment = true;
9979
10361
  if (proxy.network === "ws") wsParser(proxy, parsedProxy);
9980
10362
  if (proxy.network === "h2") h2Parser(proxy, parsedProxy);
@@ -10000,7 +10382,7 @@ var vlessParser = (proxy = {}) => {
10000
10382
  };
10001
10383
  if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
10002
10384
  throw "invalid port";
10003
- if (proxy.xudp) parsedProxy.packet_encoding = "xudp";
10385
+ vmessVlessPacketEncodingParser(proxy, parsedProxy);
10004
10386
  if (proxy["fast-open"]) parsedProxy.udp_fragment = true;
10005
10387
  if (proxy.flow != null) parsedProxy.flow = proxy.flow;
10006
10388
  if (proxy.network === "ws") wsParser(proxy, parsedProxy);
@@ -10161,7 +10543,34 @@ var hysteria2Parser = (proxy = {}) => {
10161
10543
  });
10162
10544
  if (proxy.up) parsedProxy.up_mbps = parseInt(`${proxy.up}`, 10);
10163
10545
  if (proxy.down) parsedProxy.down_mbps = parseInt(`${proxy.down}`, 10);
10164
- if (proxy.obfs === "salamander") parsedProxy.obfs.type = "salamander";
10546
+ if (["salamander", "gecko"].includes(proxy.obfs))
10547
+ parsedProxy.obfs.type = proxy.obfs;
10548
+ if (proxy.obfs === "gecko") {
10549
+ const minRaw = proxy["obfs-min-packet-size"];
10550
+ const maxRaw = proxy["obfs-max-packet-size"];
10551
+ const hasMin = minRaw !== void 0 && minRaw !== null && `${minRaw}` !== "";
10552
+ const hasMax = maxRaw !== void 0 && maxRaw !== null && `${maxRaw}` !== "";
10553
+ if (hasMin || hasMax) {
10554
+ const minPacketSize = hasMin ? parseSafeIntegerValue(`${minRaw}`.trim()) : void 0;
10555
+ const rawMaxPacketSize = hasMax ? parseSafeIntegerValue(`${maxRaw}`.trim()) : void 0;
10556
+ const maxPacketSize = rawMaxPacketSize != null ? Math.min(rawMaxPacketSize, 2048) : rawMaxPacketSize;
10557
+ const effectiveMinPacketSize = minPacketSize ?? 512;
10558
+ const effectiveMaxPacketSize = maxPacketSize ?? 1200;
10559
+ if (hasMax && rawMaxPacketSize != null && rawMaxPacketSize > 2048) {
10560
+ app_default.warn(
10561
+ `Gecko obfs max packet size for proxy ${proxy.name} exceeds 2048, clamped to 2048: ${maxRaw}`
10562
+ );
10563
+ }
10564
+ if (hasMin && (minPacketSize == null || minPacketSize <= 0) || hasMax && (rawMaxPacketSize == null || rawMaxPacketSize <= 0) || effectiveMaxPacketSize < effectiveMinPacketSize) {
10565
+ app_default.error(
10566
+ `Invalid obfs packet size for proxy ${proxy.name}: min=${minRaw} max=${maxRaw}`
10567
+ );
10568
+ } else {
10569
+ if (hasMin) parsedProxy.obfs.min_packet_size = minPacketSize;
10570
+ if (hasMax) parsedProxy.obfs.max_packet_size = maxPacketSize;
10571
+ }
10572
+ }
10573
+ }
10165
10574
  if (proxy["obfs-password"])
10166
10575
  parsedProxy.obfs.password = proxy["obfs-password"];
10167
10576
  if (!parsedProxy.obfs.type) delete parsedProxy.obfs;
@@ -10267,6 +10676,16 @@ var tailscaleParser = (proxy = {}) => {
10267
10676
  ipVersionParser(proxy, parsedProxy);
10268
10677
  domainResolverParser(proxy, parsedProxy);
10269
10678
  }
10679
+ if (isPlainObject(proxy["ssh-server"])) {
10680
+ parsedProxy.ssh_server = {
10681
+ enabled: proxy["ssh-server"].enabled !== false,
10682
+ disable_pty: proxy["ssh-server"]["disable-pty"],
10683
+ disable_sftp: proxy["ssh-server"]["disable-sftp"],
10684
+ disable_forwarding: proxy["ssh-server"]["disable-forwarding"]
10685
+ };
10686
+ } else if (proxy["ssh-server"]) {
10687
+ parsedProxy.ssh_server = !!proxy["ssh-server"];
10688
+ }
10270
10689
  return parsedProxy;
10271
10690
  };
10272
10691
  var wireguardParser = (proxy = {}) => {
@@ -10518,7 +10937,8 @@ function Egern_Producer() {
10518
10937
  "vmess",
10519
10938
  "tuic",
10520
10939
  "wireguard",
10521
- "anytls"
10940
+ "anytls",
10941
+ "ssh"
10522
10942
  ].includes(proxy.type) || proxy.type === "ss" && (proxy.plugin === "obfs" && !["http", "tls"].includes(
10523
10943
  proxy["plugin-opts"]?.mode
10524
10944
  ) || ![
@@ -10583,7 +11003,6 @@ function Egern_Producer() {
10583
11003
  headers: proxy.headers
10584
11004
  } : {},
10585
11005
  tfo: proxy.tfo || proxy["fast-open"],
10586
- next_hop: proxy.next_hop,
10587
11006
  ...proxy.tls ? {
10588
11007
  sni: proxy.sni,
10589
11008
  skip_tls_verify: proxy["skip-cert-verify"]
@@ -10601,7 +11020,6 @@ function Egern_Producer() {
10601
11020
  headers: proxy.headers
10602
11021
  } : {},
10603
11022
  tfo: proxy.tfo || proxy["fast-open"],
10604
- next_hop: proxy.next_hop,
10605
11023
  sni: proxy.sni,
10606
11024
  skip_tls_verify: proxy["skip-cert-verify"]
10607
11025
  };
@@ -10614,8 +11032,7 @@ function Egern_Producer() {
10614
11032
  username: proxy.username,
10615
11033
  password: proxy.password,
10616
11034
  tfo: proxy.tfo || proxy["fast-open"],
10617
- udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay,
10618
- next_hop: proxy.next_hop
11035
+ udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay
10619
11036
  };
10620
11037
  } else if (proxy.type === "ss") {
10621
11038
  proxy = {
@@ -10626,8 +11043,7 @@ function Egern_Producer() {
10626
11043
  port: proxy.port,
10627
11044
  password: proxy.password,
10628
11045
  tfo: proxy.tfo || proxy["fast-open"],
10629
- udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay,
10630
- next_hop: proxy.next_hop
11046
+ udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay
10631
11047
  };
10632
11048
  if (isPresent2(original, "plugin")) {
10633
11049
  if (original.plugin === "obfs") {
@@ -10655,7 +11071,6 @@ function Egern_Producer() {
10655
11071
  } : {},
10656
11072
  tfo: proxy.tfo || proxy["fast-open"],
10657
11073
  udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay,
10658
- next_hop: proxy.next_hop,
10659
11074
  sni: proxy.sni,
10660
11075
  skip_tls_verify: proxy["skip-cert-verify"],
10661
11076
  port_hopping: proxy.ports,
@@ -10673,7 +11088,6 @@ function Egern_Producer() {
10673
11088
  port: proxy.port,
10674
11089
  uuid: proxy.uuid,
10675
11090
  password: proxy.password,
10676
- next_hop: proxy.next_hop,
10677
11091
  sni: proxy.sni,
10678
11092
  alpn: Array.isArray(proxy.alpn) ? proxy.alpn : [proxy.alpn || "h3"],
10679
11093
  skip_tls_verify: proxy["skip-cert-verify"],
@@ -10695,7 +11109,6 @@ function Egern_Producer() {
10695
11109
  password: proxy.password,
10696
11110
  tfo: proxy.tfo || proxy["fast-open"],
10697
11111
  udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay,
10698
- next_hop: proxy.next_hop,
10699
11112
  sni: proxy.sni,
10700
11113
  skip_tls_verify: proxy["skip-cert-verify"],
10701
11114
  websocket: proxy.websocket
@@ -10709,21 +11122,11 @@ function Egern_Producer() {
10709
11122
  password: proxy.password,
10710
11123
  tfo: proxy.tfo || proxy["fast-open"],
10711
11124
  udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay,
10712
- next_hop: proxy.next_hop,
10713
11125
  sni: proxy.sni,
10714
11126
  skip_tls_verify: proxy["skip-cert-verify"]
10715
11127
  };
10716
11128
  } else if (proxy.type === "vmess") {
10717
- let security = proxy.cipher;
10718
- if (security && ![
10719
- "auto",
10720
- "none",
10721
- "zero",
10722
- "aes-128-gcm",
10723
- "chacha20-poly1305"
10724
- ].includes(security)) {
10725
- security = "auto";
10726
- }
11129
+ const security = normalizeVmessSecurity(proxy.cipher);
10727
11130
  if (proxy.network === "ws") {
10728
11131
  proxy.transport = {
10729
11132
  [proxy.tls ? "wss" : "ws"]: {
@@ -10784,7 +11187,6 @@ function Egern_Producer() {
10784
11187
  tfo: proxy.tfo || proxy["fast-open"],
10785
11188
  legacy,
10786
11189
  udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay,
10787
- next_hop: proxy.next_hop,
10788
11190
  transport: proxy.transport
10789
11191
  };
10790
11192
  } else if (proxy.type === "vless") {
@@ -10855,7 +11257,6 @@ function Egern_Producer() {
10855
11257
  security: proxy.cipher,
10856
11258
  tfo: proxy.tfo || proxy["fast-open"],
10857
11259
  udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay,
10858
- next_hop: proxy.next_hop,
10859
11260
  transport: proxy.transport,
10860
11261
  flow
10861
11262
  };
@@ -10891,6 +11292,19 @@ function Egern_Producer() {
10891
11292
  mtu: proxy.mtu,
10892
11293
  keepalive: proxy.keepalive
10893
11294
  };
11295
+ } else if (proxy.type === "ssh") {
11296
+ proxy = {
11297
+ type: "ssh",
11298
+ name: proxy.name,
11299
+ server: proxy.server,
11300
+ port: proxy.port,
11301
+ username: proxy.username,
11302
+ password: proxy.password,
11303
+ private_key: proxy["private-key"],
11304
+ // private_key_passphrase: proxy['private-key-passphrase'],
11305
+ host_keys: proxy["host-key"],
11306
+ tfo: proxy.tfo || proxy["fast-open"]
11307
+ };
10894
11308
  }
10895
11309
  if ([
10896
11310
  "http",
@@ -10900,7 +11314,8 @@ function Egern_Producer() {
10900
11314
  "trojan",
10901
11315
  "vless",
10902
11316
  "vmess",
10903
- "anytls"
11317
+ "anytls",
11318
+ "ssh"
10904
11319
  ].includes(original.type)) {
10905
11320
  if (isPresent2(original, "shadow-tls-password")) {
10906
11321
  if (original["shadow-tls-version"] != 3)
@@ -10941,7 +11356,8 @@ function Egern_Producer() {
10941
11356
  "wireguard",
10942
11357
  "tuic",
10943
11358
  "hysteria2",
10944
- "anytls"
11359
+ "anytls",
11360
+ "ssh"
10945
11361
  ].includes(original.type)) {
10946
11362
  if (["on", "true", true, "1", 1].includes(
10947
11363
  original["block-quic"]
@@ -11096,173 +11512,6 @@ var producers_default = {
11096
11512
  Egern: Egern_Producer()
11097
11513
  };
11098
11514
 
11099
- // src/vendors/Sub-Store/backend/src/core/proxy-utils/preprocessors/index.js
11100
- import { Base64 as Base645 } from "js-base64";
11101
- function normalizeClashYaml(raw) {
11102
- if (typeof raw !== "string" || !raw.includes("proxies:") || !raw.includes("short-id:")) {
11103
- return raw;
11104
- }
11105
- try {
11106
- const content = safeLoad(raw);
11107
- if (!Array.isArray(content.proxies) || content.proxies.length === 0)
11108
- return raw;
11109
- } catch (e) {
11110
- return raw;
11111
- }
11112
- return raw.replace(/short-id:([ \t]*[^#\n,}]*)/g, (matched, value) => {
11113
- const afterTrim = value.trim();
11114
- if (!afterTrim || afterTrim === "") {
11115
- return 'short-id: ""';
11116
- }
11117
- if (/^(['"]).*\1$/.test(afterTrim)) {
11118
- return `short-id: ${afterTrim}`;
11119
- } else if (["null"].includes(afterTrim)) {
11120
- return `short-id: ${afterTrim}`;
11121
- } else {
11122
- return `short-id: "${afterTrim}"`;
11123
- }
11124
- });
11125
- }
11126
- function HTML() {
11127
- const name = "HTML";
11128
- const test = (raw) => /^<!DOCTYPE html>/.test(raw);
11129
- const parse = () => "";
11130
- return { name, test, parse };
11131
- }
11132
- function Base64Encoded() {
11133
- const name = "Base64 Pre-processor";
11134
- const keys = [
11135
- "dm1lc3M",
11136
- // vmess
11137
- "c3NyOi8v",
11138
- // ssr://
11139
- "c29ja3M6Ly",
11140
- // socks://
11141
- "dHJvamFu",
11142
- // trojan
11143
- "c3M6Ly",
11144
- // ss:/
11145
- "c3NkOi8v",
11146
- // ssd://
11147
- "c2hhZG93",
11148
- // shadow
11149
- "aHR0c",
11150
- // htt
11151
- "dmxlc3M=",
11152
- // vless
11153
- "aHlzdGVyaWEy",
11154
- // hysteria2
11155
- "aHkyOi8v",
11156
- // hy2://
11157
- "d2lyZWd1YXJkOi8v",
11158
- // wireguard://
11159
- "d2c6Ly8=",
11160
- // wg://
11161
- "dHVpYzovLw=="
11162
- // tuic://
11163
- ];
11164
- const test = function(raw) {
11165
- return !/^\w+:\/\/\w+/im.test(raw) && keys.some((k) => raw.indexOf(k) !== -1);
11166
- };
11167
- const parse = function(raw) {
11168
- const decoded = Base645.decode(raw);
11169
- if (!/^\w+(:\/\/|\s*?=\s*?)\w+/m.test(decoded)) {
11170
- app_default.error(
11171
- `Base64 Pre-processor error: decoded line does not start with protocol`
11172
- );
11173
- return raw;
11174
- }
11175
- return decoded;
11176
- };
11177
- return { name, test, parse };
11178
- }
11179
- function fallbackBase64Encoded() {
11180
- const name = "Fallback Base64 Pre-processor";
11181
- const test = function(raw) {
11182
- return true;
11183
- };
11184
- const parse = function(raw) {
11185
- const decoded = Base645.decode(raw);
11186
- if (!/^\w+(:\/\/|\s*?=\s*?)\w+/m.test(decoded)) {
11187
- app_default.error(
11188
- `Fallback Base64 Pre-processor error: decoded line does not start with protocol`
11189
- );
11190
- return raw;
11191
- }
11192
- return decoded;
11193
- };
11194
- return { name, test, parse };
11195
- }
11196
- function Clash() {
11197
- const name = "Clash Pre-processor";
11198
- const test = function(raw) {
11199
- if (!/proxies/.test(raw)) return false;
11200
- const content = safeLoad(raw);
11201
- return content.proxies && Array.isArray(content.proxies);
11202
- };
11203
- const parse = function(raw, includeProxies) {
11204
- const afterReplace = normalizeClashYaml(raw);
11205
- const { proxies } = safeLoad(afterReplace);
11206
- return (includeProxies ? "proxies:\n" : "") + proxies.map((p) => {
11207
- return `${includeProxies ? " - " : ""}${JSON.stringify(
11208
- p
11209
- )}
11210
- `;
11211
- }).join("");
11212
- };
11213
- return { name, test, parse };
11214
- }
11215
- function SSD() {
11216
- const name = "SSD Pre-processor";
11217
- const test = function(raw) {
11218
- return raw.indexOf("ssd://") === 0;
11219
- };
11220
- const parse = function(raw) {
11221
- const output = [];
11222
- let ssdinfo = JSON.parse(Base645.decode(raw.split("ssd://")[1]));
11223
- let port = ssdinfo.port;
11224
- let method = ssdinfo.encryption;
11225
- let password = ssdinfo.password;
11226
- let servers = ssdinfo.servers;
11227
- for (let i = 0; i < servers.length; i++) {
11228
- let server = servers[i];
11229
- method = server.encryption ? server.encryption : method;
11230
- password = server.password ? server.password : password;
11231
- let userinfo = Base645.encode(method + ":" + password);
11232
- let hostname = server.server;
11233
- port = server.port ? server.port : port;
11234
- let tag = server.remarks ? server.remarks : i;
11235
- let plugin = server.plugin_options ? "/?plugin=" + encodeURIComponent(
11236
- server.plugin + ";" + server.plugin_options
11237
- ) : "";
11238
- output[i] = "ss://" + userinfo + "@" + hostname + ":" + port + plugin + "#" + tag;
11239
- }
11240
- return output.join("\n");
11241
- };
11242
- return { name, test, parse };
11243
- }
11244
- function FullConfig() {
11245
- const name = "Full Config Preprocessor";
11246
- const test = function(raw) {
11247
- return /^(\[server_local\]|\[Proxy\])/gm.test(raw);
11248
- };
11249
- const parse = function(raw) {
11250
- const match = raw.match(
11251
- /^\[server_local|Proxy\]([\s\S]+?)^\[.+?\](\r?\n|$)/im
11252
- )?.[1];
11253
- return match || raw;
11254
- };
11255
- return { name, test, parse };
11256
- }
11257
- var preprocessors_default = [
11258
- HTML(),
11259
- Clash(),
11260
- Base64Encoded(),
11261
- SSD(),
11262
- FullConfig(),
11263
- fallbackBase64Encoded()
11264
- ];
11265
-
11266
11515
  // src/index.js
11267
11516
  var parsers = parsers_default;
11268
11517
  var produce = producers_default;