Security tweaks
This commit is contained in:
@ -91,6 +91,7 @@ namespace RageCoop.Client.Menus
|
|||||||
PopUp.Error=error;
|
PopUp.Error=error;
|
||||||
PopUp.ShowBackground=showbackground;
|
PopUp.ShowBackground=showbackground;
|
||||||
PopUp.Visible=true;
|
PopUp.Visible=true;
|
||||||
|
Script.Yield();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Game.DisableAllControlsThisFrame();
|
Game.DisableAllControlsThisFrame();
|
||||||
@ -123,13 +124,10 @@ namespace RageCoop.Client.Menus
|
|||||||
private static void _passwordActivated(object sender, System.EventArgs e)
|
private static void _passwordActivated(object sender, System.EventArgs e)
|
||||||
{
|
{
|
||||||
string newPass = Game.GetUserInput(WindowTitle.EnterMessage20, "", 20);
|
string newPass = Game.GetUserInput(WindowTitle.EnterMessage20, "", 20);
|
||||||
if (!string.IsNullOrWhiteSpace(newPass))
|
|
||||||
{
|
|
||||||
Main.Settings.Password = newPass;
|
Main.Settings.Password = newPass;
|
||||||
Util.SaveSettings();
|
Util.SaveSettings();
|
||||||
_passwordItem.AltTitle = new string('*', newPass.Length);
|
_passwordItem.AltTitle = new string('*', newPass.Length);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
public static void ServerIpActivated(object a, System.EventArgs b)
|
public static void ServerIpActivated(object a, System.EventArgs b)
|
||||||
{
|
{
|
||||||
string newServerIp = Game.GetUserInput(WindowTitle.EnterMessage60, ServerIpItem.AltTitle, 60);
|
string newServerIp = Game.GetUserInput(WindowTitle.EnterMessage60, ServerIpItem.AltTitle, 60);
|
||||||
|
@ -91,7 +91,7 @@ namespace RageCoop.Client.Menus
|
|||||||
throw new Exception("Failed to obtain ZeroTier network IP");
|
throw new Exception("Failed to obtain ZeroTier network IP");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Networking.ToggleConnection(address);
|
Networking.ToggleConnection(address,null,null,PublicKey.FromServerInfo(server));
|
||||||
#if !NON_INTERACTIVE
|
#if !NON_INTERACTIVE
|
||||||
CoopMenu.ServerIpItem.AltTitle = address;
|
CoopMenu.ServerIpItem.AltTitle = address;
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ using System.Security.Cryptography;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GTA.UI;
|
using GTA.UI;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace RageCoop.Client
|
namespace RageCoop.Client
|
||||||
{
|
{
|
||||||
internal static partial class Networking
|
internal static partial class Networking
|
||||||
@ -24,8 +26,9 @@ namespace RageCoop.Client
|
|||||||
Security=new Security(Main.Logger);
|
Security=new Security(Main.Logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ToggleConnection(string address, string username = null, string password = null)
|
public static void ToggleConnection(string address, string username = null, string password = null,PublicKey publicKey=null)
|
||||||
{
|
{
|
||||||
|
Menus.CoopMenu.Menu.Visible=false;
|
||||||
Peer?.Shutdown("Bye");
|
Peer?.Shutdown("Bye");
|
||||||
if (IsOnServer)
|
if (IsOnServer)
|
||||||
{
|
{
|
||||||
@ -74,6 +77,11 @@ namespace RageCoop.Client
|
|||||||
|
|
||||||
PlayerList.Cleanup();
|
PlayerList.Cleanup();
|
||||||
EntityPool.AddPlayer();
|
EntityPool.AddPlayer();
|
||||||
|
if (publicKey==null && !string.IsNullOrEmpty(password) && !Menus.CoopMenu.ShowPopUp("WARNING", "WARNING", "Server's IP can be spoofed when using direct connection, do you wish to continue?", "", true))
|
||||||
|
{
|
||||||
|
IsConnecting=false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -88,13 +96,18 @@ namespace RageCoop.Client
|
|||||||
Main.QueueAction(() => { Notification.Show($"~y~Trying to connect..."); });
|
Main.QueueAction(() => { Notification.Show($"~y~Trying to connect..."); });
|
||||||
Menus.CoopMenu._serverConnectItem.Enabled=false;
|
Menus.CoopMenu._serverConnectItem.Enabled=false;
|
||||||
Security.Regen();
|
Security.Regen();
|
||||||
|
if(publicKey==null){
|
||||||
if (!GetServerPublicKey(ip[0],int.Parse(ip[1])))
|
if (!GetServerPublicKey(ip[0],int.Parse(ip[1])))
|
||||||
{
|
{
|
||||||
Menus.CoopMenu._serverConnectItem.Enabled=true;
|
Menus.CoopMenu._serverConnectItem.Enabled=true;
|
||||||
throw new TimeoutException("Failed to retrive server's public key");
|
throw new TimeoutException("Failed to retrive server's public key");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Security.SetServerPublicKey(publicKey.Modulus,publicKey.Exponent);
|
||||||
|
}
|
||||||
|
|
||||||
// Send HandshakePacket
|
// Send handshake packet
|
||||||
NetOutgoingMessage outgoingMessage = Peer.CreateMessage();
|
NetOutgoingMessage outgoingMessage = Peer.CreateMessage();
|
||||||
var handshake = new Packets.Handshake()
|
var handshake = new Packets.Handshake()
|
||||||
{
|
{
|
||||||
|
@ -197,7 +197,7 @@ namespace RageCoop.Client
|
|||||||
}
|
}
|
||||||
case PacketType.PublicKeyResponse:
|
case PacketType.PublicKeyResponse:
|
||||||
{
|
{
|
||||||
|
if(Security.ServerRSA!=null){break;}
|
||||||
var packet = data.GetPacket<Packets.PublicKeyResponse>();
|
var packet = data.GetPacket<Packets.PublicKeyResponse>();
|
||||||
Security.SetServerPublicKey(packet.Modulus, packet.Exponent);
|
Security.SetServerPublicKey(packet.Modulus, packet.Exponent);
|
||||||
_publicKeyReceived.Set();
|
_publicKeyReceived.Set();
|
||||||
|
@ -16,7 +16,7 @@ using System.Resources;
|
|||||||
|
|
||||||
|
|
||||||
// Version informationr(
|
// Version informationr(
|
||||||
[assembly: AssemblyVersion("1.5.0.13")]
|
[assembly: AssemblyVersion("1.5.1.13")]
|
||||||
[assembly: AssemblyFileVersion("1.5.0.13")]
|
[assembly: AssemblyFileVersion("1.5.1.13")]
|
||||||
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
||||||
|
|
||||||
|
@ -533,6 +533,7 @@ namespace RageCoop.Client
|
|||||||
return Function.Call<WeaponGroup>(Hash.GET_WEAPONTYPE_GROUP, hash);
|
return Function.Call<WeaponGroup>(Hash.GET_WEAPONTYPE_GROUP, hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
class WeaponInfo
|
class WeaponInfo
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
@ -545,4 +546,5 @@ namespace RageCoop.Client
|
|||||||
public float SweepPitchMin;
|
public float SweepPitchMin;
|
||||||
public float SweepPitchMax;
|
public float SweepPitchMax;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
22
RageCoop.Core/Networking/PublicKey.cs
Normal file
22
RageCoop.Core/Networking/PublicKey.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Lidgren.Network;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace RageCoop.Core
|
||||||
|
{
|
||||||
|
internal class PublicKey{
|
||||||
|
public PublicKey(){
|
||||||
|
|
||||||
|
}
|
||||||
|
public static PublicKey FromServerInfo(ServerInfo info){
|
||||||
|
return new PublicKey{
|
||||||
|
Modulus=Convert.FromBase64String(info.publicKeyModulus),
|
||||||
|
Exponent=Convert.FromBase64String(info.publicKeyExponent)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public byte[] Modulus;
|
||||||
|
public byte[] Exponent;
|
||||||
|
}
|
||||||
|
}
|
@ -27,5 +27,8 @@ namespace RageCoop.Core
|
|||||||
public string ztID { get; set; }
|
public string ztID { get; set; }
|
||||||
|
|
||||||
public string ztAddress { get; set; }
|
public string ztAddress { get; set; }
|
||||||
|
public string publicKeyModulus{get;set;}
|
||||||
|
public string publicKeyExponent{get;set;}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ namespace RageCoop.Server
|
|||||||
private void GetHandshake(NetConnection connection, Packets.Handshake packet)
|
private void GetHandshake(NetConnection connection, Packets.Handshake packet)
|
||||||
{
|
{
|
||||||
Logger?.Debug("New handshake from: [Name: " + packet.Username + " | Address: " + connection.RemoteEndPoint.Address.ToString() + "]");
|
Logger?.Debug("New handshake from: [Name: " + packet.Username + " | Address: " + connection.RemoteEndPoint.Address.ToString() + "]");
|
||||||
if (!packet.ModVersion.StartsWith(Version.ToString(2)))
|
if (!packet.ModVersion.StartsWith(Version.ToString(3)))
|
||||||
{
|
{
|
||||||
connection.Deny($"RAGECOOP version {Version.ToString(2)} required!");
|
connection.Deny($"RAGECOOP version {Version.ToString(3)} required!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrWhiteSpace(packet.Username))
|
if (string.IsNullOrWhiteSpace(packet.Username))
|
||||||
|
@ -132,6 +132,7 @@ namespace RageCoop.Server
|
|||||||
HttpResponseMessage response = null;
|
HttpResponseMessage response = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Security.GetPublicKey(out var pModulus,out var pExpoenet);
|
||||||
var serverInfo = new ServerInfo
|
var serverInfo = new ServerInfo
|
||||||
{
|
{
|
||||||
address = info.Address,
|
address = info.Address,
|
||||||
@ -149,6 +150,8 @@ namespace RageCoop.Server
|
|||||||
useZT=Settings.UseZeroTier,
|
useZT=Settings.UseZeroTier,
|
||||||
ztID=Settings.UseZeroTier ? Settings.ZeroTierNetworkID : "",
|
ztID=Settings.UseZeroTier ? Settings.ZeroTierNetworkID : "",
|
||||||
ztAddress=Settings.UseZeroTier ? ZeroTierHelper.Networks[Settings.ZeroTierNetworkID].Addresses.Where(x => !x.Contains(":")).First() : "0.0.0.0",
|
ztAddress=Settings.UseZeroTier ? ZeroTierHelper.Networks[Settings.ZeroTierNetworkID].Addresses.Where(x => !x.Contains(":")).First() : "0.0.0.0",
|
||||||
|
publicKeyModulus=Convert.ToBase64String(pModulus),
|
||||||
|
publicKeyExponent=Convert.ToBase64String(pExpoenet)
|
||||||
};
|
};
|
||||||
string msg = JsonConvert.SerializeObject(serverInfo);
|
string msg = JsonConvert.SerializeObject(serverInfo);
|
||||||
|
|
||||||
@ -216,7 +219,7 @@ namespace RageCoop.Server
|
|||||||
Logger?.Info("================");
|
Logger?.Info("================");
|
||||||
Logger?.Info($"Server bound to: 0.0.0.0:{Settings.Port}");
|
Logger?.Info($"Server bound to: 0.0.0.0:{Settings.Port}");
|
||||||
Logger?.Info($"Server version: {Version}");
|
Logger?.Info($"Server version: {Version}");
|
||||||
Logger?.Info($"Compatible RAGECOOP versions: {Version.ToString(2)}");
|
Logger?.Info($"Compatible RAGECOOP versions: {Version.ToString(3)}");
|
||||||
Logger?.Info("================");
|
Logger?.Info("================");
|
||||||
|
|
||||||
if (Settings.UseZeroTier)
|
if (Settings.UseZeroTier)
|
||||||
|
@ -15,7 +15,7 @@ using System.Resources;
|
|||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
// Version informationr(
|
// Version informationr(
|
||||||
[assembly: AssemblyVersion("1.5.0.13")]
|
[assembly: AssemblyVersion("1.5.1.13")]
|
||||||
[assembly: AssemblyFileVersion("1.5.0.13")]
|
[assembly: AssemblyFileVersion("1.5.1.13")]
|
||||||
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user