public async Task WriteBytesToFileAsync(string filename, byte[] data)
        {
            byte[] array = await Authentification.Cryptography.EncryptDataArrayAsync(data,
                                                                                     Authentification.AppPassword.Password, Authentification.AppPassword.Salt).ConfigureAwait(false);

            await IOProxy.WriteBytesToFileAsync(array, filename).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public static bool CheckMasterPassword(SecureString password, bool shortCheck = false)
        {
            EncryptedPassword created = new EncryptedPassword();

            created.GetPasswordFromFile(".key");
            int iterations = cryptography.GenerateIterationsFromSalt(created.Salt);

            if (iterations == 0)
            {
                throw new SecurityException("Password hash was tampered with!");
            }
            byte[] newHash = cryptography.GenerateMasterPasswordHash(password, created.Salt, iterations);
            if (!ConstantTimeComparison(newHash, created.Hash))
            {
                return(false);
            }
            else
            {
                string commonErrorMessage = "New password could be generated but all existing data including plugins state will be lost."
                                            + Environment.NewLine + "Would you like to generate new password?";
                if (shortCheck)
                {
                    return(true);
                }
                if (IOProxy.Exists(".bak_key"))
                {
                    EncryptedPassword appHash = new EncryptedPassword();
                    appHash.GetPasswordFromFile(".bak_key");
                    try
                    {
                        _appPassword = new PasswordObject(cryptography.DecryptAppPassword(appHash.Hash, _appPasswordLenght, password, appHash.Salt), appHash.Salt);
                    }
                    catch (Exception)
                    {
                        if (!ShowAppPasswordDecryptionError("Application password cannot be decrypted! " + Environment.NewLine + commonErrorMessage))
                        {
                            OnAuthentificationComplete(new AuthentificationEventArgs(false));
                        }
                        else
                        {
                            NewApplicationPassword(password);
                        }
                    }
                }
                else
                {
                    if (!ShowAppPasswordDecryptionError("Application password file not found! " + Environment.NewLine + commonErrorMessage))
                    {
                        OnAuthentificationComplete(new AuthentificationEventArgs(false));
                    }
                    else
                    {
                        NewApplicationPassword(password);
                    }
                }
                OnAuthentificationComplete(new AuthentificationEventArgs());
                return(true);
            }
        }
Ejemplo n.º 3
0
        private static async Task LoadSession()
        {
            var encryptedStream = IOProxy.GetMemoryStreamFromFile(".session");

            byte[] array = new byte[1];
            try
            {
                array = await Authentification.Cryptography.DecryptMemoryStreamAsync(encryptedStream,
                                                                                     Authentification.AppPassword.Password, Authentification.AppPassword.Salt);
            }
            catch (System.Security.SecurityException)
            {
                await NewTab();

                return;
            }
            MemoryStream ms = new MemoryStream();
            await ms.WriteAsync(array, 0, array.Length);

            ms.Position = 0;
            BinaryFormatter     formatter       = new BinaryFormatter();
            List <SessionEntry> lastSessionTabs = (List <SessionEntry>)formatter.Deserialize(ms);

            if (lastSessionTabs.Count == 0)
            {
                await NewTab();

                return;
            }
            var plugins = PluginEntryCollection.Plugins;

            foreach (var entry in lastSessionTabs.ToArray())
            {
                if ((!IsSystemTab(entry.Name)) && !plugins.ContainsKey(entry.Name))
                {
                    lastSessionTabs.Remove(lastSessionTabs.Where(w => w.Equals(entry)).FirstOrDefault());
                }
            }
            Task[] loadTasks = new Task[lastSessionTabs.Count];
            for (int index = 0; index < lastSessionTabs.Count; index++)
            {
                ClosableTab tab = new ClosableTab();
                tab.PluginTabClose += CloseTab;
                MainWindowViewModel.tabs.Add(tab);
            }
            for (int ind = 0; ind < MainWindowViewModel.tabs.Count; ind++)
            {
                if (IsSystemTab(lastSessionTabs[ind].Name))
                {
                    loadTasks[ind] = LoadSystemTab(lastSessionTabs[ind], MainWindowViewModel.tabs[ind]);
                }
                else
                {
                    loadTasks[ind] = UpdateTabContent(plugins[lastSessionTabs[ind].Name], MainWindowViewModel.tabs[ind], lastSessionTabs[ind]);
                }
            }
            await Task.WhenAll(loadTasks);
        }
Ejemplo n.º 4
0
        public void GetPasswordFromFile(string filename)
        {
            MemoryStream      ms        = IOProxy.GetMemoryStreamFromFile(filename);
            EncryptedPassword ps        = new EncryptedPassword();
            BinaryFormatter   formatter = new BinaryFormatter();

            ps   = (EncryptedPassword)formatter.Deserialize(ms);
            Hash = ps.Hash;
            Salt = ps.Salt;
        }
        public async Task <byte[]> ReadBytesFromFileAsync(string filename)
        {
            MemoryStream encryptedStream = await IOProxy.GetMemoryStreamFromFileAsync(filename).ConfigureAwait(false);

            if (encryptedStream == null)
            {
                return(null);
            }
            return(await Authentification.Cryptography.DecryptMemoryStreamAsync(encryptedStream,
                                                                                Authentification.AppPassword.Password, Authentification.AppPassword.Salt));
        }
Ejemplo n.º 6
0
        public static void NewApplicationPassword(SecureString password)
        {
            GenerateAppPassword();
            EncryptedPassword result = new EncryptedPassword(cryptography.EncryptAppPassword(_appPassword.Password, password));

            _appPassword.Salt = result.Salt;
            if (!IOProxy.WritePassword(result, ".bak_key"))
            {
                OnAuthentificationComplete(new AuthentificationEventArgs(false));
            }
        }
Ejemplo n.º 7
0
 public static async Task GetSession()
 {
     if (IOProxy.Exists(".session"))
     {
         await LoadSession();
     }
     else
     {
         await NewTab();
     }
 }
Ejemplo n.º 8
0
        public static void NewMasterPassword(SecureString password, bool triggerCompleteEvent = true)
        {
            EncryptedPassword result = new EncryptedPassword(cryptography.EncryptMasterPassword(password));

            if (!IOProxy.WritePassword(result, ".key"))
            {
                OnAuthentificationComplete(new AuthentificationEventArgs(false));
            }
            NewApplicationPassword(password);
            if (triggerCompleteEvent)
            {
                OnAuthentificationComplete(new AuthentificationEventArgs());
            }
        }
Ejemplo n.º 9
0
        public static void LoadSettings()
        {
            paramters = new Parameters();
            if (IOProxy.Exists(".config"))
            {
                paramters.Deserialize(IOProxy.GetMemoryStreamFromFile(".config"));
            }

            if (string.IsNullOrEmpty(CurrentColorScheme))
            {
                CurrentColorScheme = _colorSchemeDict.First().Key;
            }
            else
            {
                UpdateUIColorScheme();
            }
        }
Ejemplo n.º 10
0
        public static void GetAuthentificationTab()
        {
            ClosableTab authTab = new ClosableTab(false)
            {
                Title = "Authentification"
            };

            if (IOProxy.Exists(".key"))
            {
                authTab.Content = new CheckPasswordView();
            }
            else
            {
                authTab.Content = new NewPasswordView();
            }
            MainWindowViewModel.tabs.Add(authTab);
        }
Ejemplo n.º 11
0
        private static async Task WriteSessionToFile()
        {
            List <SessionEntry> openTabsNames = new List <SessionEntry>();

            for (int ind = 0; ind < MainWindowViewModel.tabs.Count; ind++)
            {
                openTabsNames.Add(new SessionEntry(MainWindowViewModel.tabs[ind].Title, ind, MainWindowViewModel.tabs[ind].IsSelected));
            }
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    ms        = new MemoryStream();

            formatter.Serialize(ms, openTabsNames);
            byte[] array = await Authentification.Cryptography.EncryptDataArrayAsync(ms.ToArray(),
                                                                                     Authentification.AppPassword.Password, Authentification.AppPassword.Salt).ConfigureAwait(false);

            MemoryStream encryptedMS = new MemoryStream();
            await encryptedMS.WriteAsync(array, 0, array.Length).ConfigureAwait(false);

            await IOProxy.WriteMemoryStreamToFileAsync(encryptedMS, ".session").ConfigureAwait(false);
        }
Ejemplo n.º 12
0
 public static async void SaveSettings()
 {
     await IOProxy.WriteMemoryStreamToFileAsync(paramters.Serialize(), ".config");
 }