Skip to content

Commit

Permalink
Add reality and remove legacy xtls settings
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Mar 9, 2023
1 parent 6f18105 commit 045af7e
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 140 deletions.
4 changes: 2 additions & 2 deletions v2rayN/v2rayN/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Global
public const string directTag = "direct";
public const string blockTag = "block";
public const string StreamSecurity = "tls";
public const string StreamSecurityX = "xtls";
public const string StreamSecurityReality = "reality";
public const string InboundSocks = "socks";
public const string InboundHttp = "http";
public const string InboundSocks2 = "socks2";
Expand Down Expand Up @@ -92,7 +92,7 @@ class Global
public static readonly List<string> ssSecuritys = new() { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305", "none", "plain" };
public static readonly List<string> ssSecuritysInSagerNet = new() { "none", "2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305", "aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305", "rc4", "rc4-md5", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-cfb8", "aes-192-cfb8", "aes-256-cfb8", "aes-128-ofb", "aes-192-ofb", "aes-256-ofb", "bf-cfb", "cast5-cfb", "des-cfb", "idea-cfb", "rc2-cfb", "seed-cfb", "camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb", "camellia-128-cfb8", "camellia-192-cfb8", "camellia-256-cfb8", "salsa20", "chacha20", "chacha20-ietf", "xchacha20" };
public static readonly List<string> ssSecuritysInXray = new() { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305", "xchacha20-poly1305", "xchacha20-ietf-poly1305", "none", "plain", "2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305" };
public static readonly List<string> xtlsFlows = new() { "", "xtls-rprx-origin", "xtls-rprx-origin-udp443", "xtls-rprx-direct", "xtls-rprx-direct-udp443", "xtls-rprx-vision", "xtls-rprx-vision-udp443" };
public static readonly List<string> flows = new() { "", "xtls-rprx-vision", "xtls-rprx-vision-udp443" };
public static readonly List<string> networks = new() { "tcp", "kcp", "ws", "h2", "quic", "grpc" };
public static readonly List<string> kcpHeaderTypes = new() { "srtp", "utp", "wechat-video", "dtls", "wireguard" };
public static readonly List<string> coreTypes = new() { "v2fly", "SagerNet", "Xray", "v2fly_v5" };
Expand Down
50 changes: 14 additions & 36 deletions v2rayN/v2rayN/Handler/CoreConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,15 @@ private static int outbound(ProfileItem node, ref V2rayConfig v2rayConfig)

boundStreamSettings(node, "out", outbound.streamSettings);

//if xtls
if (node.streamSecurity == Global.StreamSecurityX)
if (node.streamSecurity == Global.StreamSecurityReality)
{
if (Utils.IsNullOrEmpty(node.flow))
{
usersItem.flow = Global.xtlsFlows[1];
usersItem.flow = Global.flows[1];
}
else
{
usersItem.flow = node.flow.Replace("splice", "direct");
usersItem.flow = node.flow;
}

outbound.mux.enabled = false;
Expand Down Expand Up @@ -503,23 +502,7 @@ private static int outbound(ProfileItem node, ref V2rayConfig v2rayConfig)
serversItem.flow = string.Empty;

serversItem.ota = false;
serversItem.level = 1;

//if xtls
if (node.streamSecurity == Global.StreamSecurityX)
{
if (Utils.IsNullOrEmpty(node.flow))
{
serversItem.flow = Global.xtlsFlows[1];
}
else
{
serversItem.flow = node.flow.Replace("splice", "direct");
}

outbound.mux.enabled = false;
outbound.mux.concurrency = -1;
}
serversItem.level = 1;

outbound.mux.enabled = false;
outbound.mux.concurrency = -1;
Expand Down Expand Up @@ -581,26 +564,21 @@ private static int boundStreamSettings(ProfileItem node, string iobound, StreamS
streamSettings.tlsSettings = tlsSettings;
}

//if xtls
if (node.streamSecurity == Global.StreamSecurityX)
//if Reality
if (node.streamSecurity == Global.StreamSecurityReality)
{
streamSettings.security = node.streamSecurity;

TlsSettings xtlsSettings = new()
RealitySettings realitySettings = new()
{
allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? config.coreBasicItem.defAllowInsecure.ToString().ToLower() : node.allowInsecure),
alpn = node.GetAlpn(),
fingerprint = node.fingerprint.IsNullOrEmpty() ? config.coreBasicItem.defFingerprint : node.fingerprint
fingerprint = node.fingerprint.IsNullOrEmpty() ? config.coreBasicItem.defFingerprint : node.fingerprint,
serverName = sni,
publicKey = node.publicKey,
shortId = node.shortId,
spiderX = node.spiderX,
};
if (!string.IsNullOrWhiteSpace(sni))
{
xtlsSettings.serverName = sni;
}
else if (!string.IsNullOrWhiteSpace(host))
{
xtlsSettings.serverName = Utils.String2List(host)[0];
}
streamSettings.xtlsSettings = xtlsSettings;

streamSettings.realitySettings = realitySettings;
}

//streamSettings
Expand Down
104 changes: 23 additions & 81 deletions v2rayN/v2rayN/Mode/ProfileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,158 +85,100 @@ public string GetNetwork()
#endregion

[PrimaryKey]
public string indexId
{
get; set;
}
public string indexId { get; set; }

/// <summary>
/// config type(1=normal,2=custom)
/// </summary>
public EConfigType configType
{
get; set;
}

public EConfigType configType { get; set; }
/// <summary>
/// 版本(现在=2)
/// </summary>
public int configVersion
{
get; set;
}
public int configVersion { get; set; }

/// <summary>
/// 远程服务器地址
/// </summary>
public string address
{
get; set;
}
public string address { get; set; }
/// <summary>
/// 远程服务器端口
/// </summary>
public int port
{
get; set;
}
public int port { get; set; }
/// <summary>
/// 远程服务器ID
/// </summary>
public string id
{
get; set;
}
public string id { get; set; }
/// <summary>
/// 远程服务器额外ID
/// </summary>
public int alterId
{
get; set;
}
public int alterId { get; set; }
/// <summary>
/// 本地安全策略
/// </summary>
public string security
{
get; set;
}
public string security { get; set; }
/// <summary>
/// tcp,kcp,ws,h2,quic
/// </summary>
public string network
{
get; set;
}
public string network { get; set; }
/// <summary>
/// 备注或别名
/// </summary>
public string remarks
{
get; set;
}
public string remarks { get; set; }

/// <summary>
/// 伪装类型
/// </summary>
public string headerType
{
get; set;
}
public string headerType { get; set; }

/// <summary>
/// 伪装的域名
/// </summary>
public string requestHost
{
get; set;
}
public string requestHost { get; set; }

/// <summary>
/// ws h2 path
/// </summary>
public string path
{
get; set;
}
public string path { get; set; }

/// <summary>
/// 传输层安全
/// </summary>
public string streamSecurity
{
get; set;
}
public string streamSecurity { get; set; }

/// <summary>
/// 是否允许不安全连接(用于客户端)
/// </summary>
public string allowInsecure
{
get; set;
}
public string allowInsecure { get; set; }

/// <summary>
/// SubItem id
/// </summary>
public string subid
{
get; set;
}
public string subid { get; set; }
public bool isSub { get; set; } = true;

/// <summary>
/// VLESS flow
/// </summary>
public string flow
{
get; set;
}
public string flow { get; set; }
/// <summary>
/// tls sni
/// </summary>
public string sni
{
get; set;
}
public string sni { get; set; }
/// <summary>
/// tls alpn
/// </summary>
public string alpn { get; set; } = string.Empty;


public ECoreType? coreType
{
get; set;
}
public ECoreType? coreType { get; set; }

public int preSocksPort
{
get; set;
}
public int preSocksPort { get; set; }

public string fingerprint { get; set; }

public bool displayLog { get; set; } = true;
public string publicKey { get; set; }
public string shortId { get; set; }
public string spiderX { get; set; }
}
}
13 changes: 11 additions & 2 deletions v2rayN/v2rayN/Mode/V2rayConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ public class StreamSettings
public QuicSettings quicSettings { get; set; }

/// <summary>
/// VLESS xtls
/// VLESS only
/// </summary>
public TlsSettings xtlsSettings { get; set; }
public RealitySettings realitySettings { get; set; }
/// <summary>
/// grpc
/// </summary>
Expand Down Expand Up @@ -424,6 +424,15 @@ public List<string> alpn
public string fingerprint { get; set; }

}
public class RealitySettings
{
public bool show { get; set; } = false;
public string fingerprint { get; set; }
public string serverName { get; set; }
public string publicKey { get; set; }
public string shortId { get; set; }
public string spiderX { get; set; }
}

public class TcpSettings
{
Expand Down
27 changes: 27 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1132,4 +1132,13 @@
<data name="menuMoveTo" xml:space="preserve">
<value>Move up and down</value>
</data>
<data name="TbPublicKey" xml:space="preserve">
<value>PublicKey</value>
</data>
<data name="TbShortId" xml:space="preserve">
<value>ShortId</value>
</data>
<data name="TbSpiderX" xml:space="preserve">
<value>SpiderX</value>
</data>
</root>
11 changes: 10 additions & 1 deletion v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@
<value>SNI</value>
</data>
<data name="TbStreamSecurity" xml:space="preserve">
<value>TLS</value>
<value>传输层安全(TLS)</value>
</data>
<data name="TipNetwork" xml:space="preserve">
<value>*默认tcp,选错会无法连接</value>
Expand Down Expand Up @@ -1132,4 +1132,13 @@
<data name="menuMoveTo" xml:space="preserve">
<value>移至上下</value>
</data>
<data name="TbPublicKey" xml:space="preserve">
<value>PublicKey</value>
</data>
<data name="TbShortId" xml:space="preserve">
<value>ShortId</value>
</data>
<data name="TbSpiderX" xml:space="preserve">
<value>SpiderX</value>
</data>
</root>
Loading

0 comments on commit 045af7e

Please sign in to comment.