mirror of
https://github.com/2dust/v2rayN.git
synced 2025-11-22 15:42:52 +00:00
parent
20ce35bc30
commit
5b82f17995
3 changed files with 41 additions and 23 deletions
|
|
@ -73,13 +73,11 @@ public class ShadowsocksFmt : BaseFmt
|
|||
const string beginMarker = "-----BEGIN CERTIFICATE-----\n";
|
||||
const string endMarker = "\n-----END CERTIFICATE-----";
|
||||
|
||||
var base64Start = beginMarker.Length;
|
||||
var endIndex = cert.IndexOf(endMarker, base64Start, StringComparison.Ordinal);
|
||||
var base64Content = cert.Substring(base64Start, endIndex - base64Start);
|
||||
var base64Content = cert.Replace(beginMarker, "").Replace(endMarker, "").Trim();
|
||||
|
||||
// https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172
|
||||
// Equal signs and commas [and backslashes] must be escaped with a backslash.
|
||||
base64Content = base64Content.Replace("\\", "\\\\").Replace("=", "\\=").Replace(",", "\\,");
|
||||
base64Content = base64Content.Replace("=", "\\=");
|
||||
|
||||
pluginArgs += $"certRaw={base64Content};";
|
||||
}
|
||||
|
|
@ -251,7 +249,7 @@ public class ShadowsocksFmt : BaseFmt
|
|||
{
|
||||
var certBase64 = certRaw.Replace("certRaw=", "");
|
||||
|
||||
certBase64 = certBase64.Replace("\\=", "=").Replace("\\,", ",").Replace("\\\\", "\\");
|
||||
certBase64 = certBase64.Replace("\\=", "=");
|
||||
|
||||
const string beginMarker = "-----BEGIN CERTIFICATE-----\n";
|
||||
const string endMarker = "\n-----END CERTIFICATE-----";
|
||||
|
|
|
|||
|
|
@ -10,6 +10,13 @@ public class ActionPrecheckManager(Config config)
|
|||
|
||||
private readonly Config _config = config;
|
||||
|
||||
// sing-box supported transports for different protocol types
|
||||
private static readonly HashSet<string> SingboxUnsupportedTransports = [nameof(ETransport.kcp), nameof(ETransport.xhttp)];
|
||||
private static readonly HashSet<EConfigType> SingboxTransportSupportedProtocols =
|
||||
[EConfigType.VMess, EConfigType.VLESS, EConfigType.Trojan, EConfigType.Shadowsocks];
|
||||
private static readonly HashSet<string> SingboxShadowsocksAllowedTransports =
|
||||
[nameof(ETransport.tcp), nameof(ETransport.ws), nameof(ETransport.quic)];
|
||||
|
||||
public async Task<List<string>> Check(string? indexId)
|
||||
{
|
||||
if (indexId.IsNullOrEmpty())
|
||||
|
|
@ -174,26 +181,16 @@ public class ActionPrecheckManager(Config config)
|
|||
return errors;
|
||||
}
|
||||
|
||||
var net = item.GetNetwork() ?? item.Network;
|
||||
var net = item.GetNetwork();
|
||||
|
||||
if (coreType == ECoreType.sing_box)
|
||||
{
|
||||
// sing-box does not support xhttp / kcp
|
||||
// sing-box does not support transports like ws/http/httpupgrade/etc. when the node is not vmess/trojan/vless
|
||||
if (net is nameof(ETransport.kcp) or nameof(ETransport.xhttp))
|
||||
var transportError = ValidateSingboxTransport(item.ConfigType, net);
|
||||
if (transportError != null)
|
||||
{
|
||||
errors.Add(string.Format(ResUI.CoreNotSupportNetwork, nameof(ECoreType.sing_box), net));
|
||||
errors.Add(transportError);
|
||||
return errors;
|
||||
}
|
||||
|
||||
if (item.ConfigType is not (EConfigType.VMess or EConfigType.VLESS or EConfigType.Trojan))
|
||||
{
|
||||
if (net is nameof(ETransport.ws) or nameof(ETransport.http) or nameof(ETransport.h2) or nameof(ETransport.quic) or nameof(ETransport.httpupgrade))
|
||||
{
|
||||
errors.Add(string.Format(ResUI.CoreNotSupportProtocolTransport, nameof(ECoreType.sing_box), item.ConfigType.ToString(), net));
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (coreType is ECoreType.Xray)
|
||||
{
|
||||
|
|
@ -209,6 +206,31 @@ public class ActionPrecheckManager(Config config)
|
|||
return errors;
|
||||
}
|
||||
|
||||
private static string? ValidateSingboxTransport(EConfigType configType, string net)
|
||||
{
|
||||
// sing-box does not support xhttp / kcp transports
|
||||
if (SingboxUnsupportedTransports.Contains(net))
|
||||
{
|
||||
return string.Format(ResUI.CoreNotSupportNetwork, nameof(ECoreType.sing_box), net);
|
||||
}
|
||||
|
||||
// sing-box does not support non-tcp transports for protocols other than vmess/trojan/vless/shadowsocks
|
||||
if (!SingboxTransportSupportedProtocols.Contains(configType) && net != nameof(ETransport.tcp))
|
||||
{
|
||||
return string.Format(ResUI.CoreNotSupportProtocolTransport,
|
||||
nameof(ECoreType.sing_box), configType.ToString(), net);
|
||||
}
|
||||
|
||||
// sing-box shadowsocks only supports tcp/ws/quic transports
|
||||
if (configType == EConfigType.Shadowsocks && !SingboxShadowsocksAllowedTransports.Contains(net))
|
||||
{
|
||||
return string.Format(ResUI.CoreNotSupportProtocolTransport,
|
||||
nameof(ECoreType.sing_box), configType.ToString(), net);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task<List<string>> ValidateRelatedNodesExistAndValid(ProfileItem? item)
|
||||
{
|
||||
var errors = new List<string>();
|
||||
|
|
|
|||
|
|
@ -62,13 +62,11 @@ public partial class CoreConfigSingboxService
|
|||
const string beginMarker = "-----BEGIN CERTIFICATE-----\n";
|
||||
const string endMarker = "\n-----END CERTIFICATE-----";
|
||||
|
||||
var base64Start = beginMarker.Length;
|
||||
var endIndex = cert.IndexOf(endMarker, base64Start, StringComparison.Ordinal);
|
||||
var base64Content = cert.Substring(base64Start, endIndex - base64Start);
|
||||
var base64Content = cert.Replace(beginMarker, "").Replace(endMarker, "").Trim();
|
||||
|
||||
// https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172
|
||||
// Equal signs and commas [and backslashes] must be escaped with a backslash.
|
||||
base64Content = base64Content.Replace("\\", "\\\\").Replace("=", "\\=").Replace(",", "\\,");
|
||||
base64Content = base64Content.Replace("=", "\\=");
|
||||
|
||||
pluginArgs += $"certRaw={base64Content};";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue