mirror of
https://github.com/2dust/v2rayN.git
synced 2025-11-12 18:32:52 +00:00
Add allowInsecure and insecure to the shared URI
https://github.com/2dust/v2rayN/issues/8267
This commit is contained in:
parent
187356cb9e
commit
70ddf4ecfc
8 changed files with 77 additions and 39 deletions
|
|
@ -23,7 +23,7 @@ public class AnytlsFmt : BaseFmt
|
|||
item.Id = rawUserInfo;
|
||||
|
||||
var query = Utils.ParseQueryString(parsedUrl.Query);
|
||||
_ = ResolveStdTransport(query, ref item);
|
||||
ResolveUriQuery(query, ref item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ public class AnytlsFmt : BaseFmt
|
|||
}
|
||||
var pw = item.Id;
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
_ = GetStdTransport(item, Global.None, ref dicQuery);
|
||||
ToUriQuery(item, Global.None, ref dicQuery);
|
||||
|
||||
return ToUri(EConfigType.Anytls, item.Address, item.Port, pw, dicQuery, remark);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ namespace ServiceLib.Handler.Fmt;
|
|||
|
||||
public class BaseFmt
|
||||
{
|
||||
private static readonly string[] _allowInsecureArray = new[] { "insecure", "allowInsecure", "allow_insecure", "verify" };
|
||||
|
||||
protected static string GetIpv6(string address)
|
||||
{
|
||||
if (Utils.IsIpv6(address))
|
||||
|
|
@ -17,7 +19,7 @@ public class BaseFmt
|
|||
}
|
||||
}
|
||||
|
||||
protected static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
|
||||
protected static int ToUriQuery(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
|
||||
{
|
||||
if (item.Flow.IsNotEmpty())
|
||||
{
|
||||
|
|
@ -37,11 +39,7 @@ public class BaseFmt
|
|||
}
|
||||
if (item.Sni.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("sni", item.Sni);
|
||||
}
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
dicQuery.Add("sni", Utils.UrlEncode(item.Sni));
|
||||
}
|
||||
if (item.Fingerprint.IsNotEmpty())
|
||||
{
|
||||
|
|
@ -63,9 +61,14 @@ public class BaseFmt
|
|||
{
|
||||
dicQuery.Add("pqv", Utils.UrlEncode(item.Mldsa65Verify));
|
||||
}
|
||||
if (item.AllowInsecure.Equals("true"))
|
||||
|
||||
if (item.StreamSecurity.Equals(Global.StreamSecurity))
|
||||
{
|
||||
dicQuery.Add("allowInsecure", "1");
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
ToUriQueryAllowInsecure(item, ref dicQuery);
|
||||
}
|
||||
|
||||
dicQuery.Add("type", item.Network.IsNotEmpty() ? item.Network : nameof(ETransport.tcp));
|
||||
|
|
@ -153,7 +156,40 @@ public class BaseFmt
|
|||
return 0;
|
||||
}
|
||||
|
||||
protected static int ResolveStdTransport(NameValueCollection query, ref ProfileItem item)
|
||||
protected static int ToUriQueryLite(ProfileItem item, ref Dictionary<string, string> dicQuery)
|
||||
{
|
||||
if (item.Sni.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("sni", Utils.UrlEncode(item.Sni));
|
||||
}
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
|
||||
ToUriQueryAllowInsecure(item, ref dicQuery);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int ToUriQueryAllowInsecure(ProfileItem item, ref Dictionary<string, string> dicQuery)
|
||||
{
|
||||
if (item.AllowInsecure.Equals(Global.AllowInsecure.First()))
|
||||
{
|
||||
// Add two for compatibility
|
||||
dicQuery.Add("insecure", "1");
|
||||
dicQuery.Add("allowInsecure", "1");
|
||||
}
|
||||
else
|
||||
{
|
||||
dicQuery.Add("insecure", "0");
|
||||
dicQuery.Add("allowInsecure", "0");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected static int ResolveUriQuery(NameValueCollection query, ref ProfileItem item)
|
||||
{
|
||||
item.Flow = GetQueryValue(query, "flow");
|
||||
item.StreamSecurity = GetQueryValue(query, "security");
|
||||
|
|
@ -164,7 +200,19 @@ public class BaseFmt
|
|||
item.ShortId = GetQueryDecoded(query, "sid");
|
||||
item.SpiderX = GetQueryDecoded(query, "spx");
|
||||
item.Mldsa65Verify = GetQueryDecoded(query, "pqv");
|
||||
item.AllowInsecure = new[] { "allowInsecure", "allow_insecure", "insecure" }.Any(k => (query[k] ?? "") == "1") ? "true" : "";
|
||||
|
||||
if (_allowInsecureArray.Any(k => GetQueryDecoded(query, k) == "1"))
|
||||
{
|
||||
item.AllowInsecure = Global.AllowInsecure.First();
|
||||
}
|
||||
else if (_allowInsecureArray.Any(k => GetQueryDecoded(query, k) == "0"))
|
||||
{
|
||||
item.AllowInsecure = Global.AllowInsecure.Skip(1).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
item.AllowInsecure = string.Empty;
|
||||
}
|
||||
|
||||
item.Network = GetQueryValue(query, "type", nameof(ETransport.tcp));
|
||||
switch (item.Network)
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ public class Hysteria2Fmt : BaseFmt
|
|||
item.Id = Utils.UrlDecode(url.UserInfo);
|
||||
|
||||
var query = Utils.ParseQueryString(url.Query);
|
||||
ResolveStdTransport(query, ref item);
|
||||
ResolveUriQuery(query, ref item);
|
||||
item.Path = GetQueryDecoded(query, "obfs-password");
|
||||
item.AllowInsecure = GetQueryValue(query, "insecure") == "1" ? "true" : "false";
|
||||
|
||||
item.Ports = GetQueryDecoded(query, "mport");
|
||||
|
||||
return item;
|
||||
|
|
@ -46,20 +44,13 @@ public class Hysteria2Fmt : BaseFmt
|
|||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (item.Sni.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("sni", item.Sni);
|
||||
}
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
ToUriQueryLite(item, ref dicQuery);
|
||||
|
||||
if (item.Path.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("obfs", "salamander");
|
||||
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
|
||||
}
|
||||
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0");
|
||||
if (item.Ports.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("mport", Utils.UrlEncode(item.Ports.Replace(':', '-')));
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class TrojanFmt : BaseFmt
|
|||
item.Id = Utils.UrlDecode(url.UserInfo);
|
||||
|
||||
var query = Utils.ParseQueryString(url.Query);
|
||||
_ = ResolveStdTransport(query, ref item);
|
||||
ResolveUriQuery(query, ref item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ public class TrojanFmt : BaseFmt
|
|||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
_ = GetStdTransport(item, null, ref dicQuery);
|
||||
ToUriQuery(item, null, ref dicQuery);
|
||||
|
||||
return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class TuicFmt : BaseFmt
|
|||
}
|
||||
|
||||
var query = Utils.ParseQueryString(url.Query);
|
||||
ResolveStdTransport(query, ref item);
|
||||
ResolveUriQuery(query, ref item);
|
||||
item.HeaderType = GetQueryValue(query, "congestion_control");
|
||||
|
||||
return item;
|
||||
|
|
@ -47,15 +47,10 @@ public class TuicFmt : BaseFmt
|
|||
{
|
||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||
}
|
||||
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
if (item.Sni.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("sni", item.Sni);
|
||||
}
|
||||
if (item.Alpn.IsNotEmpty())
|
||||
{
|
||||
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
||||
}
|
||||
ToUriQueryLite(item, ref dicQuery);
|
||||
|
||||
dicQuery.Add("congestion_control", item.HeaderType);
|
||||
|
||||
return ToUri(EConfigType.TUIC, item.Address, item.Port, $"{item.Id}:{item.Security}", dicQuery, remark);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class VLESSFmt : BaseFmt
|
|||
var query = Utils.ParseQueryString(url.Query);
|
||||
item.Security = GetQueryValue(query, "encryption", Global.None);
|
||||
item.StreamSecurity = GetQueryValue(query, "security");
|
||||
_ = ResolveStdTransport(query, ref item);
|
||||
ResolveUriQuery(query, ref item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ public class VLESSFmt : BaseFmt
|
|||
{
|
||||
dicQuery.Add("encryption", Global.None);
|
||||
}
|
||||
_ = GetStdTransport(item, Global.None, ref dicQuery);
|
||||
ToUriQuery(item, Global.None, ref dicQuery);
|
||||
|
||||
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ public class VmessFmt : BaseFmt
|
|||
tls = item.StreamSecurity,
|
||||
sni = item.Sni,
|
||||
alpn = item.Alpn,
|
||||
fp = item.Fingerprint
|
||||
fp = item.Fingerprint,
|
||||
insecure = item.AllowInsecure.Equals(Global.AllowInsecure.First()) ? "1" : "0"
|
||||
};
|
||||
|
||||
var url = JsonUtils.Serialize(vmessQRCode);
|
||||
|
|
@ -94,6 +95,7 @@ public class VmessFmt : BaseFmt
|
|||
item.Sni = Utils.ToString(vmessQRCode.sni);
|
||||
item.Alpn = Utils.ToString(vmessQRCode.alpn);
|
||||
item.Fingerprint = Utils.ToString(vmessQRCode.fp);
|
||||
item.AllowInsecure = vmessQRCode.insecure == "1" ? Global.AllowInsecure.First() : string.Empty;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
@ -118,7 +120,7 @@ public class VmessFmt : BaseFmt
|
|||
item.Id = Utils.UrlDecode(url.UserInfo);
|
||||
|
||||
var query = Utils.ParseQueryString(url.Query);
|
||||
ResolveStdTransport(query, ref item);
|
||||
ResolveUriQuery(query, ref item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,4 +38,6 @@ public class VmessQRCode
|
|||
public string alpn { get; set; } = string.Empty;
|
||||
|
||||
public string fp { get; set; } = string.Empty;
|
||||
|
||||
public string insecure { get; set; } = string.Empty;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue