replace static aes implementation with secure rsa implementation
authorStricted <info@stricted.net>
Tue, 13 Sep 2016 19:32:08 +0000 (21:32 +0200)
committerStricted <info@stricted.net>
Tue, 13 Sep 2016 19:32:08 +0000 (21:32 +0200)
14 files changed:
SpeedportHybridControl.Implementations/Cryptography.cs
SpeedportHybridControl/Data/SpeedportHybrid.cs
SpeedportHybridControl/page/AboutPage.xaml
SpeedportHybridControl/page/ControlsPage.xaml
SpeedportHybridControl/page/DslPage.xaml
SpeedportHybridControl/page/InterfacePage.xaml
SpeedportHybridControl/page/LanPage.xaml
SpeedportHybridControl/page/LoginPage.xaml
SpeedportHybridControl/page/LteInfoPage.xaml
SpeedportHybridControl/page/OverviewPage.xaml
SpeedportHybridControl/page/PhonePage.xaml
SpeedportHybridControl/page/StatusPage.xaml
SpeedportHybridControl/page/SyslogPage.xaml
SpeedportHybridControl/page/TR181Page.xaml

index a4a1b252b6f6319628cbd877c91b49ab3abfd01e..478ecd01f68e82cdc15fc0acd19792ac9d1a36af 100644 (file)
@@ -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;
         }
     }
index 0193500dad5e38ec26f27fb71710a0e8c8398c5f..b92d5c27ac20199eec4e0e0eb772f83b3d10abe9 100644 (file)
@@ -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";
index 4646af34ef3a0014083c859bea9b717438779839..6985082d5489a6a8ae2ee629ef4601c3fcdf3154 100644 (file)
@@ -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">
 
index 9aa326c4960d685fc63a15f56d9ae34b1ba4b1e8..39af7a983ad1af63b0993205f7af7e06e0efd538 100644 (file)
@@ -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">
 
index 460c09a33323f744b5b9fc7603fe7054ef08eaa8..508c28edd3d48100b746507256eb9b61e11c518a 100644 (file)
@@ -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">
 
index 10bd5e1f52b268792151dd07ad82b6b8099ef7d1..76ba577d9459df4ac23608c7d41f137251b7dd51 100644 (file)
@@ -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">
 
index e0935fb2fa352e3c8ac3ec5434f75af5ebdcf76e..ff28d5f909fdee30ebffa367abfc1a5ee67d162a 100644 (file)
@@ -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">
 
index 33b14fcda86e481169d8cae6a075845ce6c7b26f..d105d1c39ec3e9727a60d6fb7facce1e0f5e70ee 100644 (file)
@@ -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">
 
index fdca91b3aa701fd766de465b4375da27b9f5e84f..9696e8858f8281d141cf961f6def5c325125cb98 100644 (file)
@@ -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">
 
index 9e2466b99264fed47f88751ff515d2366d09cd3e..081966c4276c511bc8768379a7aad6259fc0af05 100644 (file)
@@ -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">
 
index a6f6b62fd71aa82fbf478202f15520252d918a49..14e34f7c2d6c1a5050767199743710e7c8b9293f 100644 (file)
@@ -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">
     <Grid DataContext="{StaticResource PhonePageModel}">
index dfa348bb66b3deb4e65f86b09b56c9cd802095f4..06b6c62c1406a2ffd35acbc7504b6ff7f2001bd9 100644 (file)
@@ -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">
 
index a5ea34c39640943018bd0b25fb40439bd3eddd31..0a5ac2b481cf8d4500486927b46d5942da60c240 100644 (file)
@@ -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">
     <Grid DataContext="{StaticResource SyslogPageModel}">
index 7377bbbdbcc82ff4df26abb55ec73dbfdf57c06f..8556c5a41a9c4864138f67b6226ded3eae11b016 100644 (file)
@@ -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">