From: Stricted Date: Fri, 6 Nov 2015 16:09:09 +0000 (+0100) Subject: update some stuff X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a3157ac36586850a3d088966eb9a9e32ca500206;p=GitHub%2FStricted%2FSpeedportHybridControl.git update some stuff --- diff --git a/SpeedportHybridControl.Implementations/Cryptography.cs b/SpeedportHybridControl.Implementations/Cryptography.cs index 1fccf90..d548039 100644 --- a/SpeedportHybridControl.Implementations/Cryptography.cs +++ b/SpeedportHybridControl.Implementations/Cryptography.cs @@ -1,12 +1,13 @@ using System; using System.IO; +using System.Linq; using System.Security.Cryptography; using System.Text; namespace SpeedportHybridControl.Implementations { public static class Cryptography { - private static string EncryptionKey = "FD25B8d0afB9DDB"; - private static byte[] salt = new byte[] { 82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129 }; + private static string KEY = "8E16A57381AFDA47856682CEBE85DCF5982F59321AE28B2822C1C9E1FC481C50"; + private static string IV = "7CD37E78623793D4C4BB81DB73B08522"; public static string Encrypt (string clearText) { byte[] clearBytes = Encoding.Unicode.GetBytes(clearText); @@ -17,9 +18,13 @@ namespace SpeedportHybridControl.Implementations { return result; } - Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, salt); - encryptor.Key = pdb.GetBytes(32); - encryptor.IV = pdb.GetBytes(16); + encryptor.KeySize = 256; + encryptor.BlockSize = 128; + encryptor.Mode = CipherMode.CBC; + encryptor.Padding = PaddingMode.PKCS7; + encryptor.Key = util.HexToByte(KEY); + encryptor.IV = util.HexToByte(IV); + using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(clearBytes, 0, clearBytes.Length); @@ -41,9 +46,13 @@ namespace SpeedportHybridControl.Implementations { return result; } - Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, salt); - encryptor.Key = pdb.GetBytes(32); - encryptor.IV = pdb.GetBytes(16); + encryptor.KeySize = 256; + encryptor.BlockSize = 128; + encryptor.Mode = CipherMode.CBC; + encryptor.Padding = PaddingMode.PKCS7; + encryptor.Key = util.HexToByte(KEY); + encryptor.IV = util.HexToByte(IV); + using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(cipherBytes, 0, cipherBytes.Length); diff --git a/SpeedportHybridControl.Implementations/DelegateCommand.cs b/SpeedportHybridControl.Implementations/DelegateCommand.cs index 9107ff7..b50634f 100644 --- a/SpeedportHybridControl.Implementations/DelegateCommand.cs +++ b/SpeedportHybridControl.Implementations/DelegateCommand.cs @@ -9,13 +9,13 @@ namespace SpeedportHybridControl.Implementations { _executeMethod = executeMethod; } - public bool CanExecute (object parameter) { + public bool CanExecute (object parameter = null) { return true; } public event EventHandler CanExecuteChanged; - public void Execute (object parameter) { + public void Execute (object parameter = null) { _executeMethod.Invoke(); } } diff --git a/SpeedportHybridControl.Implementations/util.cs b/SpeedportHybridControl.Implementations/util.cs index acca4a5..d4bea24 100644 --- a/SpeedportHybridControl.Implementations/util.cs +++ b/SpeedportHybridControl.Implementations/util.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json.Linq; using System; +using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading; @@ -9,6 +10,10 @@ using System.Xml; namespace SpeedportHybridControl.Implementations { public static class util { + public static byte[] HexToByte (string hex) { + return Enumerable.Range(0, hex.Length).Where(x => x % 2 == 0).Select(x => Convert.ToByte(hex.Substring(x, 2), 16)).ToArray(); + } + /** * get sha256 * diff --git a/SpeedportHybridControl/Data/SpeedportHybridAPI.cs b/SpeedportHybridControl/Data/SpeedportHybridAPI.cs index 800c921..bb7fc48 100644 --- a/SpeedportHybridControl/Data/SpeedportHybridAPI.cs +++ b/SpeedportHybridControl/Data/SpeedportHybridAPI.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using SpeedportHybridControl.Implementations; using SpeedportHybridControl.Model; using Newtonsoft.Json; +using System.Security; namespace SpeedportHybridControl.Data { public class SpeedportHybridAPI : SingletonFactory { @@ -70,16 +71,16 @@ namespace SpeedportHybridControl.Data { * @param string $password * @return bool */ - public bool login (string passwort) { - if (passwort.IsNullOrEmpty()) { + public bool login (string password) { + if (password.IsNullOrEmpty()) { return false; } _cookie = new CookieContainer(); - _password = passwort; + _password = password; _challenge = getChallenge(); - _hash = string.Concat(_challenge, ":", _password).sha256(); + _hash = string.Concat(_challenge, ":", password).sha256(); string response = sendRequest("data/Login.json", string.Concat("csrf_token=nulltoken&showpw=0&password=", _hash)); if (response.IsNullOrEmpty()) @@ -174,9 +175,11 @@ namespace SpeedportHybridControl.Data { _derivedk = ""; LoginPageModel lpm = Application.Current.FindResource("LoginPageModel") as LoginPageModel; - lpm.LogoutAction(); + lpm.LoginCommand.Execute(); + MainWindowModel mwm = Application.Current.FindResource("MainWindowModel") as MainWindowModel; + mwm.SwitchToLoginPage.Execute(); - new Thread(() => { MessageBox.Show("Session expired.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start(); + new Thread(() => { MessageBox.Show("Session expired.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start(); _checkIsActive = false; return false; } @@ -244,7 +247,9 @@ namespace SpeedportHybridControl.Data { _derivedk = ""; LoginPageModel lpm = Application.Current.FindResource("LoginPageModel") as LoginPageModel; - lpm.LogoutAction(); + lpm.LoginCommand.Execute(); + MainWindowModel mwm = Application.Current.FindResource("MainWindowModel") as MainWindowModel; + mwm.SwitchToLoginPage.Execute(); } jArray = null; diff --git a/SpeedportHybridControl/MainWindow.xaml b/SpeedportHybridControl/MainWindow.xaml index 15b3040..c8f747a 100644 --- a/SpeedportHybridControl/MainWindow.xaml +++ b/SpeedportHybridControl/MainWindow.xaml @@ -5,8 +5,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" - Closing="Window_Closing" - SizeChanged="update_size" Height="350" Width="530" MinHeight="350" @@ -22,7 +20,7 @@