From 045af7e8dfbc71a2807f920f8586da7c9bd6c855 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Thu, 9 Mar 2023 20:57:12 +0800 Subject: [PATCH] Add reality and remove legacy xtls settings --- v2rayN/v2rayN/Global.cs | 4 +- v2rayN/v2rayN/Handler/CoreConfigHandler.cs | 50 ++---- v2rayN/v2rayN/Mode/ProfileItem.cs | 104 +++---------- v2rayN/v2rayN/Mode/V2rayConfig.cs | 13 +- v2rayN/v2rayN/Resx/ResUI.Designer.cs | 27 ++++ v2rayN/v2rayN/Resx/ResUI.resx | 9 ++ v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 11 +- .../v2rayN/ViewModels/AddServerViewModel.cs | 4 + v2rayN/v2rayN/Views/AddServerWindow.xaml | 143 +++++++++++++++--- v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 26 +++- 10 files changed, 241 insertions(+), 150 deletions(-) diff --git a/v2rayN/v2rayN/Global.cs b/v2rayN/v2rayN/Global.cs index 93f07339..1edbe712 100644 --- a/v2rayN/v2rayN/Global.cs +++ b/v2rayN/v2rayN/Global.cs @@ -43,7 +43,7 @@ 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"; @@ -92,7 +92,7 @@ public static readonly List ssSecuritys = new() { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305", "none", "plain" }; public static readonly List 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 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 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 flows = new() { "", "xtls-rprx-vision", "xtls-rprx-vision-udp443" }; public static readonly List networks = new() { "tcp", "kcp", "ws", "h2", "quic", "grpc" }; public static readonly List kcpHeaderTypes = new() { "srtp", "utp", "wechat-video", "dtls", "wireguard" }; public static readonly List coreTypes = new() { "v2fly", "SagerNet", "Xray", "v2fly_v5" }; diff --git a/v2rayN/v2rayN/Handler/CoreConfigHandler.cs b/v2rayN/v2rayN/Handler/CoreConfigHandler.cs index 4b5bc51e..2a5fcca5 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigHandler.cs @@ -456,16 +456,15 @@ namespace v2rayN.Handler 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; @@ -503,23 +502,7 @@ namespace v2rayN.Handler 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; @@ -581,26 +564,21 @@ namespace v2rayN.Handler 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 diff --git a/v2rayN/v2rayN/Mode/ProfileItem.cs b/v2rayN/v2rayN/Mode/ProfileItem.cs index f043dc4f..c26712a2 100644 --- a/v2rayN/v2rayN/Mode/ProfileItem.cs +++ b/v2rayN/v2rayN/Mode/ProfileItem.cs @@ -85,158 +85,100 @@ namespace v2rayN.Mode #endregion [PrimaryKey] - public string indexId - { - get; set; - } + public string indexId { get; set; } /// /// config type(1=normal,2=custom) /// - public EConfigType configType - { - get; set; - } - + public EConfigType configType { get; set; } /// /// 版本(现在=2) /// - public int configVersion - { - get; set; - } + public int configVersion { get; set; } /// /// 远程服务器地址 /// - public string address - { - get; set; - } + public string address { get; set; } /// /// 远程服务器端口 /// - public int port - { - get; set; - } + public int port { get; set; } /// /// 远程服务器ID /// - public string id - { - get; set; - } + public string id { get; set; } /// /// 远程服务器额外ID /// - public int alterId - { - get; set; - } + public int alterId { get; set; } /// /// 本地安全策略 /// - public string security - { - get; set; - } + public string security { get; set; } /// /// tcp,kcp,ws,h2,quic /// - public string network - { - get; set; - } + public string network { get; set; } /// /// 备注或别名 /// - public string remarks - { - get; set; - } + public string remarks { get; set; } /// /// 伪装类型 /// - public string headerType - { - get; set; - } + public string headerType { get; set; } /// /// 伪装的域名 /// - public string requestHost - { - get; set; - } + public string requestHost { get; set; } /// /// ws h2 path /// - public string path - { - get; set; - } + public string path { get; set; } /// /// 传输层安全 /// - public string streamSecurity - { - get; set; - } + public string streamSecurity { get; set; } /// /// 是否允许不安全连接(用于客户端) /// - public string allowInsecure - { - get; set; - } + public string allowInsecure { get; set; } /// /// SubItem id /// - public string subid - { - get; set; - } + public string subid { get; set; } public bool isSub { get; set; } = true; /// /// VLESS flow /// - public string flow - { - get; set; - } + public string flow { get; set; } /// /// tls sni /// - public string sni - { - get; set; - } + public string sni { get; set; } /// /// tls alpn /// 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; } } } diff --git a/v2rayN/v2rayN/Mode/V2rayConfig.cs b/v2rayN/v2rayN/Mode/V2rayConfig.cs index ec1fd03b..f2181742 100644 --- a/v2rayN/v2rayN/Mode/V2rayConfig.cs +++ b/v2rayN/v2rayN/Mode/V2rayConfig.cs @@ -389,9 +389,9 @@ namespace v2rayN.Mode public QuicSettings quicSettings { get; set; } /// - /// VLESS xtls + /// VLESS only /// - public TlsSettings xtlsSettings { get; set; } + public RealitySettings realitySettings { get; set; } /// /// grpc /// @@ -424,6 +424,15 @@ namespace v2rayN.Mode 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 { diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index 5764b679..3de5ca6e 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -2167,6 +2167,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 PublicKey 的本地化字符串。 + /// + public static string TbPublicKey { + get { + return ResourceManager.GetString("TbPublicKey", resourceCulture); + } + } + /// /// 查找类似 Alias (remarks) 的本地化字符串。 /// @@ -2896,6 +2905,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 ShortId 的本地化字符串。 + /// + public static string TbShortId { + get { + return ResourceManager.GetString("TbShortId", resourceCulture); + } + } + /// /// 查找类似 SNI 的本地化字符串。 /// @@ -2905,6 +2923,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 SpiderX 的本地化字符串。 + /// + public static string TbSpiderX { + get { + return ResourceManager.GetString("TbSpiderX", resourceCulture); + } + } + /// /// 查找类似 TLS 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index c6eb3357..fa7d6a43 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1132,4 +1132,13 @@ Move up and down + + PublicKey + + + ShortId + + + SpiderX + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index 08f0ab75..67798f3e 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -710,7 +710,7 @@ SNI - TLS + 传输层安全(TLS) *默认tcp,选错会无法连接 @@ -1132,4 +1132,13 @@ 移至上下 + + PublicKey + + + ShortId + + + SpiderX + \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs b/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs index d27c7db4..fbbdb478 100644 --- a/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/AddServerViewModel.cs @@ -118,6 +118,10 @@ namespace v2rayN.ViewModels item.allowInsecure = SelectedSource.allowInsecure; item.fingerprint = SelectedSource.fingerprint; item.alpn = SelectedSource.alpn; + + item.publicKey = SelectedSource.publicKey; + item.shortId = SelectedSource.shortId; + item.spiderX = SelectedSource.spiderX; } int ret = -1; diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml b/v2rayN/v2rayN/Views/AddServerWindow.xaml index f772794e..991e62a0 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml @@ -11,7 +11,7 @@ xmlns:vms="clr-namespace:v2rayN.ViewModels" Title="{x:Static resx:ResUI.menuServers}" Width="800" - Height="800" + Height="830" x:TypeArguments="vms:AddServerViewModel" Background="{DynamicResource MaterialDesignPaper}" FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" @@ -559,8 +559,10 @@ Margin="{StaticResource ServerItemMargin}" Style="{StaticResource DefComboBox}" /> - - + @@ -595,25 +597,10 @@ Margin="{StaticResource ServerItemMargin}" VerticalAlignment="Center" Style="{StaticResource ToolbarTextBlock}" - Text="{x:Static resx:ResUI.TbAllowInsecure}" /> - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { cmbFingerprint.Items.Add(it); + cmbFingerprint2.Items.Add(it); }); Global.allowInsecures.ForEach(it => { @@ -74,8 +75,8 @@ namespace v2rayN.Views break; case EConfigType.VLESS: gridVLESS.Visibility = Visibility.Visible; - cmbStreamSecurity.Items.Add(Global.StreamSecurityX); - Global.xtlsFlows.ForEach(it => + cmbStreamSecurity.Items.Add(Global.StreamSecurityReality); + Global.flows.ForEach(it => { cmbFlow5.Items.Add(it); }); @@ -86,8 +87,7 @@ namespace v2rayN.Views break; case EConfigType.Trojan: gridTrojan.Visibility = Visibility.Visible; - cmbStreamSecurity.Items.Add(Global.StreamSecurityX); - Global.xtlsFlows.ForEach(it => + Global.flows.ForEach(it => { cmbFlow6.Items.Add(it); }); @@ -138,6 +138,13 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.SelectedSource.allowInsecure, v => v.cmbAllowInsecure.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.fingerprint, v => v.cmbFingerprint.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.alpn, v => v.cmbAlpn.Text).DisposeWith(disposables); + //reality + this.Bind(ViewModel, vm => vm.SelectedSource.sni, v => v.txtSNI2.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedSource.fingerprint, v => v.cmbFingerprint2.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedSource.publicKey, v => v.txtPublicKey.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedSource.shortId, v => v.txtShortId.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedSource.spiderX, v => v.txtSpiderX.Text).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); @@ -159,13 +166,20 @@ namespace v2rayN.Views private void CmbStreamSecurity_SelectionChanged(object sender, SelectionChangedEventArgs e) { var security = cmbStreamSecurity.SelectedItem.ToString(); - if (Utils.IsNullOrEmpty(security)) + if (security == Global.StreamSecurityReality) { + gridRealityMore.Visibility = Visibility.Visible; gridTlsMore.Visibility = Visibility.Hidden; } + else if (security == Global.StreamSecurity) + { + gridRealityMore.Visibility = Visibility.Hidden; + gridTlsMore.Visibility = Visibility.Visible; + } else { - gridTlsMore.Visibility = Visibility.Visible; + gridRealityMore.Visibility = Visibility.Hidden; + gridTlsMore.Visibility = Visibility.Hidden; } } private void btnGUID_Click(object sender, RoutedEventArgs e)