update some stuff
authorStricted <info@stricted.de>
Fri, 6 Nov 2015 16:09:09 +0000 (17:09 +0100)
committerStricted <info@stricted.de>
Fri, 6 Nov 2015 16:09:09 +0000 (17:09 +0100)
SpeedportHybridControl.Implementations/Cryptography.cs
SpeedportHybridControl.Implementations/DelegateCommand.cs
SpeedportHybridControl.Implementations/util.cs
SpeedportHybridControl/Data/SpeedportHybridAPI.cs
SpeedportHybridControl/MainWindow.xaml
SpeedportHybridControl/MainWindow.xaml.cs
SpeedportHybridControl/Model/LoginPageModel.cs
SpeedportHybridControl/page/OverviewPage.xaml.cs
SpeedportHybridControl/page/StatusPage.xaml.cs

index 1fccf90fbf3c2632b97884444278586d0f818d73..d5480393c28ad2b4ed42f8b94381cc028a1c5330 100644 (file)
@@ -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);
index 9107ff79430b1789b43040235f2e062733883a14..b50634f0b899114a18fac1ecadf0e469dc0dad4d 100644 (file)
@@ -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();
                }
        }
index acca4a5f4bf2ec5a5675e814c2eb17d76a67762d..d4bea24d33e30d330c728b6815b9c214e09b9744 100644 (file)
@@ -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
                 *
index 800c9218ce59671496173e9b45a2ce06c56db191..bb7fc4828ef7198574998420223257a420c1f4a6 100644 (file)
@@ -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<SpeedportHybridAPI> {
@@ -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;
index 15b3040211048978b2eeb7a7aace72287cd11fa8..c8f747a053b668a39018ab1f2444ca68cd9f3966 100644 (file)
@@ -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 @@
             </StackPanel.Resources>
 
             <Button Command="{Binding Path=SwitchToLoginPage}" Background="{Binding Path=ButtonLoginPageBackground}" x:Name="btnLogin" Content="{Binding Path=LoginButtonContent}"/>
-            <Button Command="{Binding Path=SwitchToStatusPage}" Background="{Binding Path=ButtonStatusPageBackground}" Click="button_click" x:Name="btnStatus" Content="Status"/>
+            <Button Command="{Binding Path=SwitchToStatusPage}" Background="{Binding Path=ButtonStatusPageBackground}" x:Name="btnStatus" Content="Status"/>
             <Button Command="{Binding Path=SwitchToOverviewPage}" IsEnabled="{Binding Path=ButtonOverviewPageIsActive}" Background="{Binding Path=ButtonOverviewPageBackground}"  x:Name="btnOverview" Content="Overview"/>
             <Button Command="{Binding Path=SwitchToDSLPage}" IsEnabled="{Binding Path=ButtonDSLPageIsActive}" Background="{Binding Path=ButtonDSLPageBackground}" x:Name="btnDsl" Content="DSL"/>
             <Button Command="{Binding Path=SwitchToLteInfoPage}" IsEnabled="{Binding Path=ButtonLteInfoPageIsActive}" Background="{Binding Path=ButtonLteInfoPageBackground}" x:Name="btnLteInfo" Content="LteInfo"/>
@@ -36,7 +34,7 @@
         <Button Command="{Binding Path=SwitchToAboutPage}" Background="{Binding Path=ButtonAboutPageBackground}" x:Name="btnAbout" Content="Über" VerticalAlignment="Top" HorizontalAlignment="Right" Width="32" Margin="0,0,3,0"/>
 
         <DockPanel Margin="0,22,0,0">
-            <Frame x:Name="frame" NavigationUIVisibility="Hidden" Panel.ZIndex="1" Content="{Binding Path=FrameSource}"/>
+            <Frame x:Name="frame" NavigationUIVisibility="Hidden" Panel.ZIndex="1" Content="{Binding Path=FrameSource, NotifyOnSourceUpdated=True}"/>
         </DockPanel>
     </Grid>
 </Window>
index c762d405cca04e9cf3da0c0b0a4e1ee8548daff7..1ff9fa9c895c91e80ec9c83a904a20c9001044cb 100644 (file)
@@ -14,6 +14,7 @@ using System.Windows.Navigation;
 using System.Windows.Shapes;
 using System.ComponentModel;
 using SpeedportHybridControl.Implementations;
+using Microsoft.Win32;
 
 namespace SpeedportHybridControl {
        /// <summary>
@@ -23,14 +24,5 @@ namespace SpeedportHybridControl {
                public MainWindow () {
                        InitializeComponent();
                }
-
-               private void button_click (object sender, RoutedEventArgs e) {
-               }
-
-               void Window_Closing (object sender, CancelEventArgs e) {
-               }
-
-               public void update_size (object sender, SizeChangedEventArgs e) {
-               }
        }
 }
index eea57b235ab3a600f42ab4af2efb81cd8140c51b..4164356921178e96a5fe2efe297e95db59c121ce 100644 (file)
@@ -3,6 +3,7 @@ using SpeedportHybridControl.Implementations;
 using SpeedportHybridControl.Data;
 using System.Windows;
 using System.Threading;
+using System.Security;
 
 namespace SpeedportHybridControl.Model {
        class LoginPageModel : SuperViewModel {
index 838061d003c2fb6d80836a0686570f6376d38d65..44d7b8afb43cd5e55b42a1dd312f1ec1cefa497d 100644 (file)
@@ -1,4 +1,5 @@
-using System.Windows;
+using SpeedportHybridControl.Model;
+using System.Windows;
 using System.Windows.Controls;
 
 namespace SpeedportHybridControl.page {
index 75ec34cc4936b92896f0faae36bec8bdad457aee..12f3f8556585427f647c772081ebb5a6ddf5f597 100644 (file)
@@ -1,4 +1,5 @@
-using System.Windows;
+using SpeedportHybridControl.Model;
+using System.Windows;
 using System.Windows.Controls;
 
 namespace SpeedportHybridControl.page {