Security tweaks
This commit is contained in:
parent
be13e0d102
commit
7566423889
@ -91,6 +91,7 @@ namespace RageCoop.Client.Menus
|
||||
PopUp.Error=error;
|
||||
PopUp.ShowBackground=showbackground;
|
||||
PopUp.Visible=true;
|
||||
Script.Yield();
|
||||
while (true)
|
||||
{
|
||||
Game.DisableAllControlsThisFrame();
|
||||
@ -123,12 +124,9 @@ namespace RageCoop.Client.Menus
|
||||
private static void _passwordActivated(object sender, System.EventArgs e)
|
||||
{
|
||||
string newPass = Game.GetUserInput(WindowTitle.EnterMessage20, "", 20);
|
||||
if (!string.IsNullOrWhiteSpace(newPass))
|
||||
{
|
||||
Main.Settings.Password = newPass;
|
||||
Util.SaveSettings();
|
||||
_passwordItem.AltTitle = new string('*', newPass.Length);
|
||||
}
|
||||
Main.Settings.Password = newPass;
|
||||
Util.SaveSettings();
|
||||
_passwordItem.AltTitle = new string('*', newPass.Length);
|
||||
}
|
||||
public static void ServerIpActivated(object a, System.EventArgs b)
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ namespace RageCoop.Client.Menus
|
||||
throw new Exception("Failed to obtain ZeroTier network IP");
|
||||
}
|
||||
}
|
||||
Networking.ToggleConnection(address);
|
||||
Networking.ToggleConnection(address,null,null,PublicKey.FromServerInfo(server));
|
||||
#if !NON_INTERACTIVE
|
||||
CoopMenu.ServerIpItem.AltTitle = address;
|
||||
|
||||
|
@ -6,6 +6,8 @@ using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GTA.UI;
|
||||
using System.Net;
|
||||
|
||||
namespace RageCoop.Client
|
||||
{
|
||||
internal static partial class Networking
|
||||
@ -24,8 +26,9 @@ namespace RageCoop.Client
|
||||
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");
|
||||
if (IsOnServer)
|
||||
{
|
||||
@ -74,6 +77,11 @@ namespace RageCoop.Client
|
||||
|
||||
PlayerList.Cleanup();
|
||||
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(() =>
|
||||
{
|
||||
try
|
||||
@ -88,13 +96,18 @@ namespace RageCoop.Client
|
||||
Main.QueueAction(() => { Notification.Show($"~y~Trying to connect..."); });
|
||||
Menus.CoopMenu._serverConnectItem.Enabled=false;
|
||||
Security.Regen();
|
||||
if (!GetServerPublicKey(ip[0],int.Parse(ip[1])))
|
||||
{
|
||||
Menus.CoopMenu._serverConnectItem.Enabled=true;
|
||||
throw new TimeoutException("Failed to retrive server's public key");
|
||||
if(publicKey==null){
|
||||
if (!GetServerPublicKey(ip[0],int.Parse(ip[1])))
|
||||
{
|
||||
Menus.CoopMenu._serverConnectItem.Enabled=true;
|
||||
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();
|
||||
var handshake = new Packets.Handshake()
|
||||
{
|
||||
|
@ -197,7 +197,7 @@ namespace RageCoop.Client
|
||||
}
|
||||
case PacketType.PublicKeyResponse:
|
||||
{
|
||||
|
||||
if(Security.ServerRSA!=null){break;}
|
||||
var packet = data.GetPacket<Packets.PublicKeyResponse>();
|
||||
Security.SetServerPublicKey(packet.Modulus, packet.Exponent);
|
||||
_publicKeyReceived.Set();
|
||||
|
@ -16,7 +16,7 @@ using System.Resources;
|
||||
|
||||
|
||||
// Version informationr(
|
||||
[assembly: AssemblyVersion("1.5.0.13")]
|
||||
[assembly: AssemblyFileVersion("1.5.0.13")]
|
||||
[assembly: AssemblyVersion("1.5.1.13")]
|
||||
[assembly: AssemblyFileVersion("1.5.1.13")]
|
||||
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
||||
|
||||
|
@ -533,6 +533,7 @@ namespace RageCoop.Client
|
||||
return Function.Call<WeaponGroup>(Hash.GET_WEAPONTYPE_GROUP, hash);
|
||||
}
|
||||
}
|
||||
/*
|
||||
class WeaponInfo
|
||||
{
|
||||
public string Name;
|
||||
@ -545,4 +546,5 @@ namespace RageCoop.Client
|
||||
public float SweepPitchMin;
|
||||
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 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(packet.Username))
|
||||
|
@ -132,6 +132,7 @@ namespace RageCoop.Server
|
||||
HttpResponseMessage response = null;
|
||||
try
|
||||
{
|
||||
Security.GetPublicKey(out var pModulus,out var pExpoenet);
|
||||
var serverInfo = new ServerInfo
|
||||
{
|
||||
address = info.Address,
|
||||
@ -149,6 +150,8 @@ namespace RageCoop.Server
|
||||
useZT=Settings.UseZeroTier,
|
||||
ztID=Settings.UseZeroTier ? Settings.ZeroTierNetworkID : "",
|
||||
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);
|
||||
|
||||
@ -216,7 +219,7 @@ namespace RageCoop.Server
|
||||
Logger?.Info("================");
|
||||
Logger?.Info($"Server bound to: 0.0.0.0:{Settings.Port}");
|
||||
Logger?.Info($"Server version: {Version}");
|
||||
Logger?.Info($"Compatible RAGECOOP versions: {Version.ToString(2)}");
|
||||
Logger?.Info($"Compatible RAGECOOP versions: {Version.ToString(3)}");
|
||||
Logger?.Info("================");
|
||||
|
||||
if (Settings.UseZeroTier)
|
||||
|
@ -15,7 +15,7 @@ using System.Resources;
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Version informationr(
|
||||
[assembly: AssemblyVersion("1.5.0.13")]
|
||||
[assembly: AssemblyFileVersion("1.5.0.13")]
|
||||
[assembly: AssemblyVersion("1.5.1.13")]
|
||||
[assembly: AssemblyFileVersion("1.5.1.13")]
|
||||
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user