Exemple #1
0
        /// <summary>
        /// Deletes file paths that are no longer protected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteFilesBtn_Click(object sender, RoutedEventArgs e)
        {
            string selectedItem = listBoxFiles.SelectedItem.ToString();

            Files.Remove(selectedItem);
            IOClass.SaveFilesList(Files, @"C:\temp\files.json");
            listBoxFiles.ItemsSource = Files;
        }
Exemple #2
0
        /// <summary>
        /// Provides files recovery feature
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRecoverFiles_Click(object sender, RoutedEventArgs e)
        {
            string securityAnswer = textBoxSecurityAnswer.Text.ToLower();
            string password       = textBoxRecoveryPassword.Password;

            if (EncryptedFiles.Count.Equals(0))
            {
                MessageBox.Show("You have no files to recover.", "No encrypted files found", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                if (DataCryptography.SHA512(securityAnswer).Equals(LoggedUser.GetAnswer()) && DataCryptography.SHA512(password).Equals(LoggedUser.GetPassword()))
                {
                    MessageBoxResult result = MessageBox.Show("Do you want to recover your files? All your program settings and keys will be deleted.", "Files recovery system", MessageBoxButton.YesNo, MessageBoxImage.Question);

                    if (result.Equals(MessageBoxResult.Yes))
                    {
                        string aesKey = DataCryptography.SHA512(DataCryptography.GenerateAesKey(this.Username,
                                                                                                password,
                                                                                                LoggedUser.GetQuestion(),
                                                                                                securityAnswer));

                        List <string> tempEncryptedFiles = new List <string>(EncryptedFiles);
                        EncryptedFiles.Clear();
                        Files.Clear();
                        Folders.Clear();
                        TrustedDevices.Clear();

                        var decryptionTask = Task.Run(() =>
                        {
                            foreach (string encryptedFilePath in tempEncryptedFiles)
                            {
                                string filePath = DataCryptography.FileDecrypt(encryptedFilePath, aesKey);
                            }
                        });
                        decryptionTask.Wait();

                        LoggedUser.SetPublicKeyXmlString(String.Empty);
                        LoggedUser.SetAesKey(aesKey);

                        IOClass.SaveFilesList(Files, this.UserFilesFilepath);
                        IOClass.SaveFilesList(EncryptedFiles, this.UserEncryptedFilesFilepath);
                        IOClass.SaveFoldersList(Folders, this.UserFoldersFilepath);
                        IOClass.SaveTrustedDevicesList(TrustedDevices, this.UserKeyDataFilepath);
                        IOClass.UpdateUser(LoggedUser);

                        bindFilesListBox();
                        bindFoldersListBox();

                        MessageBox.Show("Your files are decrypted now.", "Files recovery system", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Security answer or password incorrect!", "Files recovery system", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Deletes folder paths that are no longer protected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteFoldersBtn_Click(object sender, RoutedEventArgs e)
        {
            string selectedItem = listBoxFolders.SelectedItem.ToString();

            ProcessDirectory(selectedItem, false);
            IOClass.SaveFilesList(Files, this.UserFilesFilepath);
            Folders.Remove(selectedItem);
            IOClass.SaveFoldersList(Folders, this.UserFoldersFilepath);
            listBoxFiles.ItemsSource   = Files;
            listBoxFolders.ItemsSource = Folders;
        }
Exemple #4
0
        /// <summary>
        /// Activates Ffle dialog and saves file paths that will be protected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addFilesBtn_Click(object sender, RoutedEventArgs e)
        {
            CommonOpenFileDialog fileDialog = new CommonOpenFileDialog
            {
                InitialDirectory = @"C:\",
                Multiselect      = true
            };

            if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                Files = IOClass.ReadFilesList(this.UserFilesFilepath);
                Files.AddRange(fileDialog.FileNames);
                listBoxFiles.ItemsSource = Files;
                IOClass.SaveFilesList(Files, this.UserFilesFilepath);
            }
        }
Exemple #5
0
        /// <summary>
        /// Deletes a device from trusted devices list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteTrustedDeviceBtn_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result1 = MessageBox.Show("Do you want to delete " + listBoxTrustedDevices.SelectedItem.ToString() + "?", "Delete an authentication key?", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result1.Equals(MessageBoxResult.Yes))
            {
                if (Files.Count > 0)
                {
                    MessageBoxResult result2 = MessageBox.Show("You want to delete a key with associated files with it. " +
                                                               "They will no longer be protected! Are you sure?", "Associated files found!", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                    if (result2.Equals(MessageBoxResult.Yes))
                    {
                        Files.Clear();
                        IOClass.SaveFilesList(Files, this.UserFilesFilepath);
                        bindFilesListBox();
                        bindDeviceListBoxes();

                        if (deleteTrustedDevice(listBoxTrustedDevices.SelectedItem.ToString()))
                        {
                            MessageBox.Show("The authentication key has been deleted.", "Deleting successful", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else
                        {
                            MessageBox.Show("Couldn't delete an authentication key.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
                else
                {
                    if (deleteTrustedDevice(listBoxTrustedDevices.SelectedItem.ToString()))
                    {
                        MessageBox.Show("The authentication key has been deleted.", "Deleting successful", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Couldn't delete an authentication key.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Activates File Dialog and saves folder paths that will be protected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addFoldersBtn_Click(object sender, RoutedEventArgs e)
        {
            CommonOpenFileDialog folderDialog = new CommonOpenFileDialog
            {
                InitialDirectory = @"C:\",
                IsFolderPicker   = true
            };

            if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                Folders = IOClass.ReadFoldersList(this.UserFoldersFilepath);
                Folders.AddRange(folderDialog.FileNames);

                foreach (string folderPath in folderDialog.FileNames)
                {
                    ProcessDirectory(folderPath, true);
                }

                IOClass.SaveFilesList(Files, this.UserFilesFilepath);
                listBoxFolders.ItemsSource = Folders;
                listBoxFiles.ItemsSource   = Files;
                IOClass.SaveFoldersList(Folders, this.UserFoldersFilepath);
            }
        }
Exemple #7
0
        /// <summary>
        /// Updates all data about devices and sets authorization status
        /// </summary>
        private void UpdateDevicesStatus()
        {
            TrustedDevices = IOClass.ReadTrustedDevicesList(this.UserKeyDataFilepath);
            UpdateConnectedTrustedDevices();
            bindDeviceListBoxes();
            labelKeysCounter.Content = TrustedDevices.Count;

            if (Files.Count > 0)
            {
                labelFilesCounter.Content = Files.Count;
            }
            else if (EncryptedFiles.Count >= 0)
            {
                labelFilesCounter.Content = EncryptedFiles.Count;
            }

            var uiSyncContext = SynchronizationContext.Current;

            // Decrypt all data and inform a user about authorization status
            if (AuthorizationStatus)
            {
                DidUserLoggedUnauthorized = false;

                if (EncryptedFiles.Count > 0)
                {
                    // New Task to decrypt all files
                    var decryptionTask = Task.Run(() =>
                    {
                        string password   = DataCryptography.DecryptAESKey(LoggedUser.GetAesKey(), RsaPrivateKey);
                        GCHandle gCHandle = GCHandle.Alloc(password, GCHandleType.Pinned);
                        foreach (string encryptedFilePath in EncryptedFiles)
                        {
                            string filePath = DataCryptography.FileDecrypt(encryptedFilePath, password);
                            Files.Add(filePath);
                        }
                        DataCryptography.ZeroMemory(gCHandle.AddrOfPinnedObject(), password.Length * 2);
                        gCHandle.Free();
                    });
                    decryptionTask.Wait();
                    EncryptedFiles.Clear();
                    IOClass.SaveFilesList(Files, this.UserFilesFilepath);
                    IOClass.SaveFilesList(EncryptedFiles, this.UserEncryptedFilesFilepath);
                }

                uiSyncContext.Post((s) =>
                {
                    labelStatus.Foreground = new SolidColorBrush(Colors.GreenYellow);
                    labelStatus.Content    = "Authorized";
                    IconLock.Kind          = MahApps.Metro.IconPacks.PackIconMaterialKind.LockOpen;
                    IconLock.Foreground    = new SolidColorBrush(Colors.GreenYellow);
                    bindFilesListBox();
                }, null);
            }
            else // Encrypt all data and inform a user about authorization status
            {
                // Prevents from double encryption if user logs in unauthorized
                if (!DidUserLoggedUnauthorized && Files.Count > 0)
                {
                    // New Task to encrypt all files
                    var encryptionTask = Task.Run(() =>
                    {
                        string password   = DataCryptography.DecryptAESKey(LoggedUser.GetAesKey(), RsaPrivateKey);
                        GCHandle gCHandle = GCHandle.Alloc(password, GCHandleType.Pinned);

                        foreach (string filePath in Files)
                        {
                            string encryptedFilePath = DataCryptography.FileEncrypt(filePath, password);
                            EncryptedFiles.Add(encryptedFilePath);
                        }

                        DataCryptography.ZeroMemory(gCHandle.AddrOfPinnedObject(), password.Length * 2);
                        gCHandle.Free();
                    });
                    encryptionTask.Wait();
                    Files.Clear();
                    IOClass.SaveFilesList(Files, this.UserFilesFilepath);
                    IOClass.SaveFilesList(EncryptedFiles, this.UserEncryptedFilesFilepath);
                }

                uiSyncContext.Post((s) =>
                {
                    labelStatus.Foreground = new SolidColorBrush(Colors.OrangeRed);
                    labelStatus.Content    = "Unauthorized";
                    IconLock.Kind          = MahApps.Metro.IconPacks.PackIconMaterialKind.Lock;
                    IconLock.Foreground    = new SolidColorBrush(Colors.OrangeRed);
                    bindFilesListBox();
                }, null);
            }
        }