From: Stricted Date: Tue, 13 Sep 2016 19:32:08 +0000 (+0200) Subject: replace static aes implementation with secure rsa implementation X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=79ff307c36600259c9a3a265684655509597f8a4;p=GitHub%2FStricted%2FSpeedportHybridControl.git replace static aes implementation with secure rsa implementation --- diff --git a/SpeedportHybridControl.Implementations/Cryptography.cs b/SpeedportHybridControl.Implementations/Cryptography.cs index a4a1b25..478ecd0 100644 --- a/SpeedportHybridControl.Implementations/Cryptography.cs +++ b/SpeedportHybridControl.Implementations/Cryptography.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Security.Cryptography; using System.Text; @@ -7,72 +6,34 @@ namespace SpeedportHybridControl.Implementations { public static class Cryptography { - private static string KEY = "8E16A57381AFDA47856682CEBE85DCF5982F59321AE28B2822C1C9E1FC481C50"; - private static string IV = "7CD37E78623793D4C4BB81DB73B08522"; + private static string GetKeyFromContainer() + { + // store key in keycontainer, this generates a new key if none exist + CspParameters cp = new CspParameters(); + cp.KeyContainerName = "SpeedportHybridControl"; + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp); + return rsa.ToXmlString(true); + } public static string Encrypt(string clearText) { + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048); byte[] clearBytes = Encoding.Unicode.GetBytes(clearText); - string result; - using (Aes encryptor = Aes.Create()) - { - if (Object.Equals(encryptor, null)) - { - result = null; - return result; - } + rsa.FromXmlString(GetKeyFromContainer()); + string result = Convert.ToBase64String(rsa.Encrypt(clearBytes, true)); + rsa.Dispose(); - 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); - cs.Close(); - } - clearText = Convert.ToBase64String(ms.ToArray()); - } - } - result = clearText; return result; } public static string Decrypt(string cipherText) { + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048); byte[] cipherBytes = Convert.FromBase64String(cipherText); - string result; - using (Aes encryptor = Aes.Create()) - { - if (Object.Equals(encryptor, null)) - { - result = null; - return result; - } - - encryptor.KeySize = 256; - encryptor.BlockSize = 128; - encryptor.Mode = CipherMode.CBC; - encryptor.Padding = PaddingMode.PKCS7; - encryptor.Key = util.HexToByte(KEY); - encryptor.IV = util.HexToByte(IV); + rsa.FromXmlString(GetKeyFromContainer()); + string result = Encoding.Unicode.GetString(rsa.Decrypt(cipherBytes, true)); + rsa.Dispose(); - using (MemoryStream ms = new MemoryStream()) - { - using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)) - { - cs.Write(cipherBytes, 0, cipherBytes.Length); - cs.Close(); - } - cipherText = Encoding.Unicode.GetString(ms.ToArray()); - } - } - result = cipherText; return result; } } diff --git a/SpeedportHybridControl/Data/SpeedportHybrid.cs b/SpeedportHybridControl/Data/SpeedportHybrid.cs index 0193500..b92d5c2 100644 --- a/SpeedportHybridControl/Data/SpeedportHybrid.cs +++ b/SpeedportHybridControl/Data/SpeedportHybrid.cs @@ -707,17 +707,16 @@ namespace SpeedportHybridControl.Data //2016-09-01 17:15:20: LTE-ZellInfo: PLMN = 26201, CellID = 25721859, Band = LTE1800, RSRP = -90dBm, RSRQ = -8dB (LT004) //01.09.2016 19:44:48: Funkzellen Info: 26201,34701569,3,-96,-11 (LT004) LteInfoModel lte = Application.Current.FindResource("LteInfoModel") as LteInfoModel; + + parts = line.Split(','); + string frequenz = parts[2]; + if (line.Contains("Band = LTE")) { - parts = line.Split(','); - string frequenz = parts[2]; lte.frequenz = string.Concat(frequenz.Substring(10, frequenz.Length - 10), " MHz"); } else { - parts = line.Split(','); - string frequenz = parts[2]; - if (frequenz.Equals("20")) { frequenz = "800 MHz"; diff --git a/SpeedportHybridControl/page/AboutPage.xaml b/SpeedportHybridControl/page/AboutPage.xaml index 4646af3..6985082 100644 --- a/SpeedportHybridControl/page/AboutPage.xaml +++ b/SpeedportHybridControl/page/AboutPage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SpeedportHybridControl.page" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="AboutPage"> diff --git a/SpeedportHybridControl/page/ControlsPage.xaml b/SpeedportHybridControl/page/ControlsPage.xaml index 9aa326c..39af7a9 100644 --- a/SpeedportHybridControl/page/ControlsPage.xaml +++ b/SpeedportHybridControl/page/ControlsPage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="ControlsPage"> diff --git a/SpeedportHybridControl/page/DslPage.xaml b/SpeedportHybridControl/page/DslPage.xaml index 460c09a..508c28e 100644 --- a/SpeedportHybridControl/page/DslPage.xaml +++ b/SpeedportHybridControl/page/DslPage.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:SpeedportHybridControl.page" xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="DslPage"> diff --git a/SpeedportHybridControl/page/InterfacePage.xaml b/SpeedportHybridControl/page/InterfacePage.xaml index 10bd5e1..76ba577 100644 --- a/SpeedportHybridControl/page/InterfacePage.xaml +++ b/SpeedportHybridControl/page/InterfacePage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="InterfacePage"> diff --git a/SpeedportHybridControl/page/LanPage.xaml b/SpeedportHybridControl/page/LanPage.xaml index e0935fb..ff28d5f 100644 --- a/SpeedportHybridControl/page/LanPage.xaml +++ b/SpeedportHybridControl/page/LanPage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="LanPage"> diff --git a/SpeedportHybridControl/page/LoginPage.xaml b/SpeedportHybridControl/page/LoginPage.xaml index 33b14fc..d105d1c 100644 --- a/SpeedportHybridControl/page/LoginPage.xaml +++ b/SpeedportHybridControl/page/LoginPage.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:SpeedportHybridControl" xmlns:Implementations="clr-namespace:SpeedportHybridControl.Implementations;assembly=SpeedportHybridControl.Implementations" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="LoginPage"> diff --git a/SpeedportHybridControl/page/LteInfoPage.xaml b/SpeedportHybridControl/page/LteInfoPage.xaml index fdca91b..9696e88 100644 --- a/SpeedportHybridControl/page/LteInfoPage.xaml +++ b/SpeedportHybridControl/page/LteInfoPage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="LteInfoPage"> diff --git a/SpeedportHybridControl/page/OverviewPage.xaml b/SpeedportHybridControl/page/OverviewPage.xaml index 9e2466b..081966c 100644 --- a/SpeedportHybridControl/page/OverviewPage.xaml +++ b/SpeedportHybridControl/page/OverviewPage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="OverviewPage"> diff --git a/SpeedportHybridControl/page/PhonePage.xaml b/SpeedportHybridControl/page/PhonePage.xaml index a6f6b62..14e34f7 100644 --- a/SpeedportHybridControl/page/PhonePage.xaml +++ b/SpeedportHybridControl/page/PhonePage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="PhonePage"> diff --git a/SpeedportHybridControl/page/StatusPage.xaml b/SpeedportHybridControl/page/StatusPage.xaml index dfa348b..06b6c62 100644 --- a/SpeedportHybridControl/page/StatusPage.xaml +++ b/SpeedportHybridControl/page/StatusPage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="StatusPage"> diff --git a/SpeedportHybridControl/page/SyslogPage.xaml b/SpeedportHybridControl/page/SyslogPage.xaml index a5ea34c..0a5ac2b 100644 --- a/SpeedportHybridControl/page/SyslogPage.xaml +++ b/SpeedportHybridControl/page/SyslogPage.xaml @@ -5,6 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SpeedportHybridControl" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="SyslogPage"> diff --git a/SpeedportHybridControl/page/TR181Page.xaml b/SpeedportHybridControl/page/TR181Page.xaml index 7377bbb..8556c5a 100644 --- a/SpeedportHybridControl/page/TR181Page.xaml +++ b/SpeedportHybridControl/page/TR181Page.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:SpeedportHybridControl" xmlns:Implementations="clr-namespace:SpeedportHybridControl.Implementations;assembly=SpeedportHybridControl.Implementations" mc:Ignorable="d" + d:DesignWidth="514" d:DesignHeight="287" Width="Auto" Height="Auto" Title="TR181Page">