Heavier password encryption

I don't think this fixes actual bugs but the encryption seemed kinda weak.
This commit is contained in:
juanjp600
2016-08-29 07:13:19 -03:00
parent 8f675e625b
commit e284ff5f38
4 changed files with 23 additions and 15 deletions

View File

@@ -6,6 +6,7 @@ using Barotrauma.Networking.ReliableMessages;
using FarseerPhysics;
using System.IO;
using System.Linq;
using System.Text;
using Barotrauma.Items.Components;
using System.ComponentModel;
@@ -172,7 +173,7 @@ namespace Barotrauma.Networking
reconnectBox.Buttons[0].OnClicked += reconnectBox.Close;
}
CoroutineManager.StartCoroutine(WaitForStartingInfo(password));
CoroutineManager.StartCoroutine(WaitForStartingInfo(Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password)))));
// Start the timer
//update.Start();
@@ -336,9 +337,12 @@ namespace Barotrauma.Networking
var outmsg = client.CreateMessage();
NetEncryption algo = new NetXtea(client, password);
string saltedPw = password;
saltedPw = saltedPw + Convert.ToString(nonce);
saltedPw = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(saltedPw)));
NetEncryption algo = new NetXtea(client, saltedPw);
outmsg.Write((byte)PacketTypes.Login);
outmsg.Write(nonce);
outmsg.Write(saltedPw);
outmsg.Write(myID);
outmsg.Write(GameMain.Version.ToString());
outmsg.Write(GameMain.SelectedPackage.Name);

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using RestSharp;
@@ -55,7 +56,7 @@ namespace Barotrauma.Networking
name = name.Replace(";", "");
this.name = name;
this.password = password;
this.password = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password)));
config = new NetPeerConfiguration("barotrauma");
@@ -1510,13 +1511,13 @@ namespace Barotrauma.Networking
sender.ChatMessages.RemoveAt(0);
}
if (sender.inGame || (Screen.Selected == GameMain.NetLobbyScreen))
{
if (sender.inGame || (Screen.Selected == GameMain.NetLobbyScreen))
{
AddChatMessage(message);
}
else
{
GameServer.Log(message.Text, message.Color);
else
{
GameServer.Log(message.Text, message.Color);
}
sender.ChatSpamSpeed += 5.0f;

View File

@@ -62,11 +62,14 @@ namespace Barotrauma.Networking
{
unauthenticatedClients.Remove(unauthenticatedClient);
NetEncryption algo = new NetXtea(server, password);
string saltedPw = password;
saltedPw = saltedPw + Convert.ToString(unauthenticatedClient.Nonce);
saltedPw = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(saltedPw)));
NetEncryption algo = new NetXtea(server, saltedPw);
inc.Decrypt(algo);
int nonce = inc.ReadInt32();
if (nonce != unauthenticatedClient.Nonce)
string rdPw = inc.ReadString();
if (rdPw != saltedPw)
{
inc.SenderConnection.Disconnect("Wrong password!");
return;

View File

@@ -647,8 +647,8 @@ namespace Barotrauma.Networking
return false;
}
public void ManagePlayersFrame(GUIFrame infoFrame)
{
public void ManagePlayersFrame(GUIFrame infoFrame)
{
GUIListBox cList = new GUIListBox(new Rectangle(0, 0, 280, 300), Color.White * 0.7f, GUI.Style, infoFrame);
cList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
//crewList.OnSelected = SelectCrewCharacter;
@@ -677,7 +677,7 @@ namespace Barotrauma.Networking
kickButton.OnClicked += GameMain.NetLobbyScreen.KickPlayer;
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
}
}
}
}
}