diff --git a/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs index 73cb6a85..e13dcbb7 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs @@ -27,6 +27,7 @@ public class WireguardFmt : BaseFmt item.SetProtocolExtra(item.GetProtocolExtra() with { WgPublicKey = GetQueryDecoded(query, "publickey"), + WgPresharedKey = GetQueryDecoded(query, "presharedkey"), WgReserved = GetQueryDecoded(query, "reserved"), WgInterfaceAddress = GetQueryDecoded(query, "address"), WgMtu = int.TryParse(GetQueryDecoded(query, "mtu"), out var mtuVal) ? mtuVal : 1280, @@ -48,20 +49,25 @@ public class WireguardFmt : BaseFmt remark = "#" + Utils.UrlEncode(item.Remarks); } + var protoExtra = item.GetProtocolExtra(); var dicQuery = new Dictionary(); - if (!item.GetProtocolExtra().WgPublicKey.IsNullOrEmpty()) + if (!protoExtra.WgPublicKey.IsNullOrEmpty()) { - dicQuery.Add("publickey", Utils.UrlEncode(item.GetProtocolExtra().WgPublicKey)); + dicQuery.Add("publickey", Utils.UrlEncode(protoExtra.WgPublicKey)); } - if (!item.GetProtocolExtra().WgReserved.IsNullOrEmpty()) + if (!protoExtra.WgPresharedKey.IsNullOrEmpty()) { - dicQuery.Add("reserved", Utils.UrlEncode(item.GetProtocolExtra().WgReserved)); + dicQuery.Add("presharedkey", Utils.UrlEncode(protoExtra.WgPresharedKey)); } - if (!item.GetProtocolExtra().WgInterfaceAddress.IsNullOrEmpty()) + if (!protoExtra.WgReserved.IsNullOrEmpty()) { - dicQuery.Add("address", Utils.UrlEncode(item.GetProtocolExtra().WgInterfaceAddress)); + dicQuery.Add("reserved", Utils.UrlEncode(protoExtra.WgReserved)); } - dicQuery.Add("mtu", Utils.UrlEncode(item.GetProtocolExtra().WgMtu > 0 ? item.GetProtocolExtra().WgMtu.ToString() : "1280")); + if (!protoExtra.WgInterfaceAddress.IsNullOrEmpty()) + { + dicQuery.Add("address", Utils.UrlEncode(protoExtra.WgInterfaceAddress)); + } + dicQuery.Add("mtu", Utils.UrlEncode(protoExtra.WgMtu > 0 ? protoExtra.WgMtu.ToString() : "1280")); return ToUri(EConfigType.WireGuard, item.Address, item.Port, item.Password, dicQuery, remark); } } diff --git a/v2rayN/ServiceLib/Models/SingboxConfig.cs b/v2rayN/ServiceLib/Models/SingboxConfig.cs index 2282e830..0e2bb530 100644 --- a/v2rayN/ServiceLib/Models/SingboxConfig.cs +++ b/v2rayN/ServiceLib/Models/SingboxConfig.cs @@ -173,7 +173,7 @@ public class Peer4Sbox public string? pre_shared_key { get; set; } public List allowed_ips { get; set; } public int? persistent_keepalive_interval { get; set; } - public List reserved { get; set; } + public List? reserved { get; set; } } public class Tls4Sbox diff --git a/v2rayN/ServiceLib/Models/V2rayConfig.cs b/v2rayN/ServiceLib/Models/V2rayConfig.cs index 26739b69..10420dad 100644 --- a/v2rayN/ServiceLib/Models/V2rayConfig.cs +++ b/v2rayN/ServiceLib/Models/V2rayConfig.cs @@ -163,6 +163,7 @@ public class WireguardPeer4Ray { public string endpoint { get; set; } public string publicKey { get; set; } + public string? preSharedKey { get; set; } } public class VnextItem4Ray diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 61b96007..9e2340af 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -3321,6 +3321,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 PreSharedKey 的本地化字符串。 + /// + public static string TbPreSharedKey { + get { + return ResourceManager.GetString("TbPreSharedKey", resourceCulture); + } + } + /// /// 查找类似 Socks port 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index dd1895e3..26f1b4c4 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1725,4 +1725,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.fr.resx b/v2rayN/ServiceLib/Resx/ResUI.fr.resx index ee633bd0..eec8f04b 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fr.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fr.resx @@ -1716,4 +1716,13 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if Pour les environnements multi-interfaces, entrez le nom de l'interface à lier. Ne fonctionne que sur les systèmes Windows et en mode TUN + + Test Configurations UDP Delay + + + UDP Test Url + + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index c0456ba4..435dadf6 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1725,4 +1725,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 7e4275c0..242cc5c0 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1725,4 +1725,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index a956b5f1..59111376 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1725,4 +1725,7 @@ Для среды с несколькими сетевыми интерфейсами укажите имя интерфейса для привязки. Работает только в Windows и режиме TUN + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 6a3e2d75..08fd1ce1 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1722,4 +1722,7 @@ 用于多网口环境,填写要绑定的网口名称,仅生效于 Windows 系统和 TUN 模式 + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index a197592d..2ee14c77 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1722,4 +1722,7 @@ For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs index c438dabd..2634e388 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs @@ -318,13 +318,12 @@ public partial class CoreConfigSingboxService { var peer = new Peer4Sbox { - public_key = protocolExtra.WgPublicKey, + public_key = protocolExtra.WgPublicKey ?? string.Empty, pre_shared_key = protocolExtra.WgPresharedKey, reserved = Utils.String2List(protocolExtra.WgReserved)?.Select(int.Parse).ToList(), address = _node.Address, port = _node.Port, - // TODO default ["0.0.0.0/0", "::/0"] - allowed_ips = new() { "0.0.0.0/0", "::/0" }, + allowed_ips = ["0.0.0.0/0", "::/0"], }; endpoint.private_key = _node.Password; endpoint.mtu = protocolExtra.WgMtu > 0 ? protocolExtra.WgMtu : Global.TunMtus.First(); diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index aeae3618..f840492f 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -258,7 +258,8 @@ public partial class CoreConfigV2rayService var peer = new WireguardPeer4Ray { publicKey = protocolExtra.WgPublicKey ?? "", - endpoint = address + ":" + _node.Port.ToString() + endpoint = address + ":" + _node.Port.ToString(), + preSharedKey = protocolExtra.WgPresharedKey, }; var setting = new Outboundsettings4Ray { diff --git a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs index 20439a03..169e8a44 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs @@ -53,8 +53,9 @@ public class AddServerViewModel : MyReactiveObject [Reactive] public string WgPublicKey { get; set; } - //[Reactive] - //public string WgPresharedKey { get; set; } + [Reactive] + public string WgPresharedKey { get; set; } + [Reactive] public string WgInterfaceAddress { get; set; } @@ -159,17 +160,8 @@ public class AddServerViewModel : MyReactiveObject switch (SelectedSource.GetNetwork()) { case nameof(ETransport.raw): - Host = value; - break; - case nameof(ETransport.ws): - Host = value; - break; - case nameof(ETransport.httpupgrade): - Host = value; - break; - case nameof(ETransport.xhttp): Host = value; break; @@ -202,13 +194,7 @@ public class AddServerViewModel : MyReactiveObject break; case nameof(ETransport.ws): - Path = value; - break; - case nameof(ETransport.httpupgrade): - Path = value; - break; - case nameof(ETransport.xhttp): Path = value; break; @@ -303,6 +289,7 @@ public class AddServerViewModel : MyReactiveObject VlessEncryption = protocolExtra.VlessEncryption?.IsNullOrEmpty() == false ? protocolExtra.VlessEncryption : Global.None; SsMethod = protocolExtra.SsMethod ?? string.Empty; WgPublicKey = protocolExtra.WgPublicKey ?? string.Empty; + WgPresharedKey = protocolExtra.WgPresharedKey ?? string.Empty; WgInterfaceAddress = protocolExtra.WgInterfaceAddress ?? string.Empty; WgReserved = protocolExtra.WgReserved ?? string.Empty; WgMtu = protocolExtra.WgMtu ?? 1280; @@ -401,6 +388,7 @@ public class AddServerViewModel : MyReactiveObject VlessEncryption = VlessEncryption.NullIfEmpty(), SsMethod = SsMethod.NullIfEmpty(), WgPublicKey = WgPublicKey.NullIfEmpty(), + WgPresharedKey = WgPresharedKey.NullIfEmpty(), WgInterfaceAddress = WgInterfaceAddress.NullIfEmpty(), WgReserved = WgReserved.NullIfEmpty(), WgMtu = WgMtu >= 576 ? WgMtu : null, diff --git a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml index 1417bc99..2aaa83ad 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml @@ -508,7 +508,7 @@ Grid.Row="2" ColumnDefinitions="300,Auto" IsVisible="False" - RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto"> + RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto"> + + + case EConfigType.WireGuard: this.Bind(ViewModel, vm => vm.SelectedSource.Password, v => v.txtId9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgPublicKey, v => v.txtPublicKey9.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.WgPresharedKey, v => v.txtPreSharedKey9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgReserved, v => v.txtPath9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgInterfaceAddress, v => v.txtRequestHost9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgMtu, v => v.txtShortId9.Text).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml b/v2rayN/v2rayN/Views/AddServerWindow.xaml index 5ba850f5..81e8244a 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml @@ -678,6 +678,7 @@ + @@ -721,10 +722,26 @@ Margin="{StaticResource Margin4}" VerticalAlignment="Center" Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbPreSharedKey}" /> + + + vm.SelectedSource.Password, v => v.txtId9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgPublicKey, v => v.txtPublicKey9.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.WgPresharedKey, v => v.txtPreSharedKey9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgReserved, v => v.txtPath9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgInterfaceAddress, v => v.txtRequestHost9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgMtu, v => v.txtShortId9.Text).DisposeWith(disposables);