From b1923154095df7b26d3e5263b5219f38f7c58c38 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Feb 2017 09:16:19 -0500 Subject: [PATCH] Fix double-hashing issue --- ShiftOS.Server/Program.cs | 42 +++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs index 6a76703..92d672d 100644 --- a/ShiftOS.Server/Program.cs +++ b/ShiftOS.Server/Program.cs @@ -405,11 +405,14 @@ Contents: if(save.Username == args["username"].ToString() && save.Password == hashedPass) { - server.DispatchTo(new Guid(msg.GUID), new NetObject("mud_savefile", new ServerMessage - { - Name = "mud_savefile", - GUID = "server", - Contents = File.ReadAllText(savefile) + if(save.PasswordHashed == true) + save.Password = Encryption.Decrypt(save.Password); + + server.DispatchTo(new Guid(msg.GUID), new NetObject("mud_savefile", new ServerMessage + { + Name = "mud_savefile", + GUID = "server", + Contents = JsonConvert.SerializeObject(save) })); return; } @@ -1281,7 +1284,34 @@ The page you requested at was not found on this multi-user domain." } } + + public static string Decrypt(string cipherText) + { + byte[] cipherTextBytes = Convert.FromBase64String(cipherText); + using (PasswordDeriveBytes password = new PasswordDeriveBytes(GetMacAddress(), null)) + { + byte[] keyBytes = password.GetBytes(keysize / 8); + using (RijndaelManaged symmetricKey = new RijndaelManaged()) + { + symmetricKey.Mode = CipherMode.CBC; + using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)) + { + using (MemoryStream memoryStream = new MemoryStream(cipherTextBytes)) + { + using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)) + { + byte[] plainTextBytes = new byte[cipherTextBytes.Length]; + int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length); + return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount); + } + } + } + } + } + } } + + } -// Commenting by Carver +// Uncommenting by Michael \ No newline at end of file