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
+7 -3
View File
@@ -6,6 +6,7 @@ using Barotrauma.Networking.ReliableMessages;
using FarseerPhysics; using FarseerPhysics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using Barotrauma.Items.Components; using Barotrauma.Items.Components;
using System.ComponentModel; using System.ComponentModel;
@@ -172,7 +173,7 @@ namespace Barotrauma.Networking
reconnectBox.Buttons[0].OnClicked += reconnectBox.Close; 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 // Start the timer
//update.Start(); //update.Start();
@@ -336,9 +337,12 @@ namespace Barotrauma.Networking
var outmsg = client.CreateMessage(); 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((byte)PacketTypes.Login);
outmsg.Write(nonce); outmsg.Write(saltedPw);
outmsg.Write(myID); outmsg.Write(myID);
outmsg.Write(GameMain.Version.ToString()); outmsg.Write(GameMain.Version.ToString());
outmsg.Write(GameMain.SelectedPackage.Name); outmsg.Write(GameMain.SelectedPackage.Name);
+2 -1
View File
@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text;
using Lidgren.Network; using Lidgren.Network;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using RestSharp; using RestSharp;
@@ -55,7 +56,7 @@ namespace Barotrauma.Networking
name = name.Replace(";", ""); name = name.Replace(";", "");
this.name = name; this.name = name;
this.password = password; this.password = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password)));
config = new NetPeerConfiguration("barotrauma"); config = new NetPeerConfiguration("barotrauma");
@@ -62,11 +62,14 @@ namespace Barotrauma.Networking
{ {
unauthenticatedClients.Remove(unauthenticatedClient); 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); inc.Decrypt(algo);
int nonce = inc.ReadInt32(); string rdPw = inc.ReadString();
if (nonce != unauthenticatedClient.Nonce) if (rdPw != saltedPw)
{ {
inc.SenderConnection.Disconnect("Wrong password!"); inc.SenderConnection.Disconnect("Wrong password!");
return; return;