public static Authenticator FromFile(string filePath) { try { using (BinaryReader binReader = new BinaryReader(File.OpenRead(filePath))) { string fileHeader = ""; for (int i = 0; i < 9; i++) { fileHeader += binReader.ReadChar(); } if (fileHeader != "WINBMAEXP") { return(null); } int fileVersion = binReader.ReadInt32(); if (fileVersion > 2) { return(null); } string name = binReader.ReadString(); string serial = binReader.ReadString(); bool?isRestorable = null; AuthAPI.Security.EncryptionProvider.EncryptionType encType = AuthAPI.Security.EncryptionProvider.EncryptionType.None; int tokenLen = 20; if (fileVersion > 1) { isRestorable = binReader.ReadBoolean(); encType = (AuthAPI.Security.EncryptionProvider.EncryptionType)binReader.ReadByte(); tokenLen = binReader.ReadInt32(); } byte[] token = binReader.ReadBytes(tokenLen); return(new Authenticator(name, serial, token, isRestorable, encType)); } } catch (Exception) { return(null); } }
private void WIZARD_PageChanged(object sender, RoutedEventArgs e) { if (WIZARD.CurrentPage == WIZARDPAGE_SettingsSummary) { string strEncryptionType = null; if (CHECK_ProtectPassword.IsChecked == true) { strEncryptionType = "Password"; } if (strEncryptionType == null) { LABEL_EncryptionType.IsEnabled = false; LABEL_EncryptionType.Content = "(None)"; } else { LABEL_EncryptionType.IsEnabled = true; LABEL_EncryptionType.Content = strEncryptionType; } if (String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { LABEL_FriendlyName.IsEnabled = false; LABEL_FriendlyName.Content = "(Serial will be used)"; } else { LABEL_FriendlyName.IsEnabled = true; LABEL_FriendlyName.Content = TEXT_FriendlyName.Text.Trim(); } } else if (WIZARD.CurrentPage == WIZARDPAGE_Progress) { bgWorker.ReportProgress(0, "Selecting File..."); encryptionType = AuthAPI.Security.EncryptionProvider.EncryptionType.None; if (CHECK_ProtectPassword.IsChecked == true) { userPassword = TEXT_Password.Text; encryptionType |= AuthAPI.Security.EncryptionProvider.EncryptionType.Password; } if (!String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { authenticatorName = TEXT_FriendlyName.Text.Trim(); } Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.Title = "Export Authenticator"; dlg.FileName = Settings.SettingsDatabase.SelectedAuthenticator.Serial + ".bma"; dlg.DefaultExt = ".bma"; // Default file extension dlg.AddExtension = true; dlg.OverwritePrompt = true; dlg.Filter = "WinBMA Exported Authenticator (.bma)|*.bma"; // Filter files by extension // Show open file dialog box Nullable<bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document savePath = dlg.FileName; bgWorker.RunWorkerAsync(); } else { this.Close(); return; } } }
private void WIZARD_PageChanged(object sender, RoutedEventArgs e) { if (WIZARD.CurrentPage == WIZARDPAGE_SettingsSummary) { string strEncryptionType = null; if (CHECK_ProtectPassword.IsChecked == true) { strEncryptionType = "Password"; } if (CHECK_ProtectWindows.IsChecked == true) { if (strEncryptionType != null) strEncryptionType += "\n"; else strEncryptionType = ""; strEncryptionType += (RADIO_ProtectLocalMachine.IsChecked == true) ? "Locked to local machine (" + TEXTBLOCK_LocalMachine.Text + ")" : "Locked to current user (" + TEXTBLOCK_CurrentUser.Text + ")"; } if (strEncryptionType == null) { LABEL_EncryptionType.IsEnabled = false; LABEL_EncryptionType.Content = "(None)"; } else { LABEL_EncryptionType.IsEnabled = true; LABEL_EncryptionType.Content = strEncryptionType; } if (String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { LABEL_FriendlyName.IsEnabled = false; LABEL_FriendlyName.Content = "(Serial will be used)"; } else { LABEL_FriendlyName.IsEnabled = true; LABEL_FriendlyName.Content = TEXT_FriendlyName.Text.Trim(); } } else if (WIZARD.CurrentPage == WIZARDPAGE_Progress) { encryptionType = AuthAPI.Security.EncryptionProvider.EncryptionType.None; if (CHECK_ProtectPassword.IsChecked == true) { userPassword = TEXT_Password.Text; encryptionType |= AuthAPI.Security.EncryptionProvider.EncryptionType.Password; } if (CHECK_ProtectWindows.IsChecked == true) { encryptionType |= (RADIO_ProtectLocalMachine.IsChecked == true) ? AuthAPI.Security.EncryptionProvider.EncryptionType.LocalMachine : AuthAPI.Security.EncryptionProvider.EncryptionType.LocalUser; } if (!String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { authenticatorName = TEXT_FriendlyName.Text.Trim(); } bgWorker.RunWorkerAsync(); } else if (WIZARD.CurrentPage == WIZARDPAGE_SelectFile) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.CheckFileExists = true; dlg.Title = "Select Authenticator"; dlg.DefaultExt = ".bma"; // Default file extension dlg.Filter = "WinBMA Exported Authenticator (.bma)|*.bma"; // Filter files by extension // Show open file dialog box Nullable<bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document string filename = dlg.FileName; newAuthenticator = AuthAPI.Authenticator.FromFile(filename); if (newAuthenticator == null) { this.Close(); return; } if (!this.DecryptAuthenticator()) { this.Close(); return; } TEXT_FriendlyName.Text = newAuthenticator.Name; WIZARD.CurrentPage = WIZARDPAGE_Protect; } else { this.Close(); } } }
private void WIZARD_PageChanged(object sender, RoutedEventArgs e) { if (WIZARD.CurrentPage == WIZARDPAGE_SettingsSummary) { string strEncryptionType = null; if (CHECK_ProtectPassword.IsChecked == true) { strEncryptionType = "Password"; } if (CHECK_ProtectWindows.IsChecked == true) { if (strEncryptionType != null) { strEncryptionType += "\n"; } else { strEncryptionType = ""; } strEncryptionType += (RADIO_ProtectLocalMachine.IsChecked == true) ? "Locked to local machine (" + TEXTBLOCK_LocalMachine.Text + ")" : "Locked to current user (" + TEXTBLOCK_CurrentUser.Text + ")"; } if (strEncryptionType == null) { LABEL_EncryptionType.IsEnabled = false; LABEL_EncryptionType.Content = "(None)"; } else { LABEL_EncryptionType.IsEnabled = true; LABEL_EncryptionType.Content = strEncryptionType; } if (String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { LABEL_FriendlyName.IsEnabled = false; LABEL_FriendlyName.Content = "(Serial will be used)"; } else { LABEL_FriendlyName.IsEnabled = true; LABEL_FriendlyName.Content = TEXT_FriendlyName.Text.Trim(); } } else if (WIZARD.CurrentPage == WIZARDPAGE_Progress) { encryptionType = AuthAPI.Security.EncryptionProvider.EncryptionType.None; if (CHECK_ProtectPassword.IsChecked == true) { userPassword = TEXT_Password.Text; encryptionType |= AuthAPI.Security.EncryptionProvider.EncryptionType.Password; } if (CHECK_ProtectWindows.IsChecked == true) { encryptionType |= (RADIO_ProtectLocalMachine.IsChecked == true) ? AuthAPI.Security.EncryptionProvider.EncryptionType.LocalMachine : AuthAPI.Security.EncryptionProvider.EncryptionType.LocalUser; } if (!String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { authenticatorName = TEXT_FriendlyName.Text.Trim(); } bgWorker.RunWorkerAsync(); } else if (WIZARD.CurrentPage == WIZARDPAGE_VerifyCode) { newAuthenticator = null; PROGRESS_VerifyTasks.Value = 0; checkSerial = TEXT_RestoreSerial.Text; checkRestoreCode = TEXT_RestoreCodeInput.Text; bgVerifier.RunWorkerAsync(); } }
private void WIZARD_PageChanged(object sender, RoutedEventArgs e) { if (WIZARD.CurrentPage == WIZARDPAGE_SettingsSummary) { string strEncryptionType = null; if (CHECK_ProtectPassword.IsChecked == true) { strEncryptionType = "Password"; } if (strEncryptionType == null) { LABEL_EncryptionType.IsEnabled = false; LABEL_EncryptionType.Content = "(None)"; } else { LABEL_EncryptionType.IsEnabled = true; LABEL_EncryptionType.Content = strEncryptionType; } if (String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { LABEL_FriendlyName.IsEnabled = false; LABEL_FriendlyName.Content = "(Serial will be used)"; } else { LABEL_FriendlyName.IsEnabled = true; LABEL_FriendlyName.Content = TEXT_FriendlyName.Text.Trim(); } } else if (WIZARD.CurrentPage == WIZARDPAGE_Progress) { bgWorker.ReportProgress(0, "Selecting File..."); encryptionType = AuthAPI.Security.EncryptionProvider.EncryptionType.None; if (CHECK_ProtectPassword.IsChecked == true) { userPassword = TEXT_Password.Text; encryptionType |= AuthAPI.Security.EncryptionProvider.EncryptionType.Password; } if (!String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { authenticatorName = TEXT_FriendlyName.Text.Trim(); } Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.Title = "Export Authenticator"; dlg.FileName = Settings.SettingsDatabase.SelectedAuthenticator.Serial + ".bma"; dlg.DefaultExt = ".bma"; // Default file extension dlg.AddExtension = true; dlg.OverwritePrompt = true; dlg.Filter = "WinBMA Exported Authenticator (.bma)|*.bma"; // Filter files by extension // Show open file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document savePath = dlg.FileName; bgWorker.RunWorkerAsync(); } else { this.Close(); return; } } }
private void WIZARD_PageChanged(object sender, RoutedEventArgs e) { if (WIZARD.CurrentPage == WIZARDPAGE_SettingsSummary) { string strEncryptionType = null; if (CHECK_ProtectPassword.IsChecked == true) { strEncryptionType = "Password"; } if (CHECK_ProtectWindows.IsChecked == true) { if (strEncryptionType != null) strEncryptionType += "\n"; else strEncryptionType = ""; strEncryptionType += (RADIO_ProtectLocalMachine.IsChecked == true) ? "Locked to local machine (" + TEXTBLOCK_LocalMachine.Text + ")" : "Locked to current user (" + TEXTBLOCK_CurrentUser.Text + ")"; } if (strEncryptionType == null) { LABEL_EncryptionType.IsEnabled = false; LABEL_EncryptionType.Content = "(None)"; } else { LABEL_EncryptionType.IsEnabled = true; LABEL_EncryptionType.Content = strEncryptionType; } if (String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { LABEL_FriendlyName.IsEnabled = false; LABEL_FriendlyName.Content = "(Serial will be used)"; } else { LABEL_FriendlyName.IsEnabled = true; LABEL_FriendlyName.Content = TEXT_FriendlyName.Text.Trim(); } } else if (WIZARD.CurrentPage == WIZARDPAGE_Progress) { encryptionType = AuthAPI.Security.EncryptionProvider.EncryptionType.None; if (CHECK_ProtectPassword.IsChecked == true) { userPassword = TEXT_Password.Text; encryptionType |= AuthAPI.Security.EncryptionProvider.EncryptionType.Password; } if (CHECK_ProtectWindows.IsChecked == true) { encryptionType |= (RADIO_ProtectLocalMachine.IsChecked == true) ? AuthAPI.Security.EncryptionProvider.EncryptionType.LocalMachine : AuthAPI.Security.EncryptionProvider.EncryptionType.LocalUser; } if (!String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { authenticatorName = TEXT_FriendlyName.Text.Trim(); } bgWorker.RunWorkerAsync(); } }
public static void Load() { InitializeDefaults(); if (!File.Exists(SettingsFile)) { return; } using (BinaryReader binReader = new BinaryReader(File.OpenRead(SettingsFile))) { string fileHeader = ""; for (int i = 0; i < 9; i++) { fileHeader += binReader.ReadChar(); } if (fileHeader != "WINBMACFG") { return; } int fileVersion = binReader.ReadInt32(); if (fileVersion > 4) { System.Windows.MessageBox.Show("The settings database was created with a newer version of WinBMA. We were unable to load your settings.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); return; } int numOfAuths = binReader.ReadInt32(); for (int i = 0; i < numOfAuths; i++) { string name = binReader.ReadString(); string serial = binReader.ReadString(); bool? isRestorable = null; AuthAPI.Security.EncryptionProvider.EncryptionType encType = AuthAPI.Security.EncryptionProvider.EncryptionType.None; int tokenLen = 20; if (fileVersion > 2) { isRestorable = binReader.ReadBoolean(); encType = (AuthAPI.Security.EncryptionProvider.EncryptionType)binReader.ReadByte(); tokenLen = binReader.ReadInt32(); } byte[] token = binReader.ReadBytes(tokenLen); Authenticators.Add(new AuthAPI.Authenticator(name, serial, token, isRestorable, encType)); } if (fileVersion < 3) { for (int i = 0; i < 2; i++) { DateTime storedLastSync = DateTime.FromBinary(binReader.ReadInt64()); Int64 storedOffset = binReader.ReadInt64(); if (storedLastSync > _lastSyncTime) { _lastSyncTime = storedLastSync; _timeOffset = storedOffset; } } } else { _lastSyncTime = DateTime.FromBinary(binReader.ReadInt64()); _timeOffset = binReader.ReadInt64(); } if (fileVersion == 1) { return; } SelectedAuthenticatorIndex = binReader.ReadInt32(); if (fileVersion == 2) { return; } _autoSync = binReader.ReadBoolean(); _alwaysOnTop = binReader.ReadBoolean(); _autoCopyToClipboard = binReader.ReadBoolean(); _theme = binReader.ReadString(); _checkForUpdates = binReader.ReadBoolean(); _lastUpdateCheck = DateTime.FromBinary(binReader.ReadInt64()); if (fileVersion == 3) { return; } _hotkeyEnabled = binReader.ReadBoolean(); _hotkeyModifiers = (Utilities.SystemHotKey.ModifierKeys)binReader.ReadByte(); _hotkey = (Utilities.Keys)binReader.ReadInt32(); } }
private void WIZARD_PageChanged(object sender, RoutedEventArgs e) { if (WIZARD.CurrentPage == WIZARDPAGE_SettingsSummary) { string strEncryptionType = null; if (CHECK_ProtectPassword.IsChecked == true) { strEncryptionType = "Password"; } if (CHECK_ProtectWindows.IsChecked == true) { if (strEncryptionType != null) { strEncryptionType += "\n"; } else { strEncryptionType = ""; } strEncryptionType += (RADIO_ProtectLocalMachine.IsChecked == true) ? "Locked to local machine (" + TEXTBLOCK_LocalMachine.Text + ")" : "Locked to current user (" + TEXTBLOCK_CurrentUser.Text + ")"; } if (strEncryptionType == null) { LABEL_EncryptionType.IsEnabled = false; LABEL_EncryptionType.Content = "(None)"; } else { LABEL_EncryptionType.IsEnabled = true; LABEL_EncryptionType.Content = strEncryptionType; } if (String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { LABEL_FriendlyName.IsEnabled = false; LABEL_FriendlyName.Content = "(Serial will be used)"; } else { LABEL_FriendlyName.IsEnabled = true; LABEL_FriendlyName.Content = TEXT_FriendlyName.Text.Trim(); } } else if (WIZARD.CurrentPage == WIZARDPAGE_Progress) { encryptionType = AuthAPI.Security.EncryptionProvider.EncryptionType.None; if (CHECK_ProtectPassword.IsChecked == true) { userPassword = TEXT_Password.Text; encryptionType |= AuthAPI.Security.EncryptionProvider.EncryptionType.Password; } if (CHECK_ProtectWindows.IsChecked == true) { encryptionType |= (RADIO_ProtectLocalMachine.IsChecked == true) ? AuthAPI.Security.EncryptionProvider.EncryptionType.LocalMachine : AuthAPI.Security.EncryptionProvider.EncryptionType.LocalUser; } if (!String.IsNullOrWhiteSpace(TEXT_FriendlyName.Text)) { authenticatorName = TEXT_FriendlyName.Text.Trim(); } bgWorker.RunWorkerAsync(); } else if (WIZARD.CurrentPage == WIZARDPAGE_SelectFile) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.CheckFileExists = true; dlg.Title = "Select Authenticator"; dlg.DefaultExt = ".bma"; // Default file extension dlg.Filter = "WinBMA Exported Authenticator (.bma)|*.bma"; // Filter files by extension // Show open file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document string filename = dlg.FileName; newAuthenticator = AuthAPI.Authenticator.FromFile(filename); if (newAuthenticator == null) { this.Close(); return; } if (!this.DecryptAuthenticator()) { this.Close(); return; } TEXT_FriendlyName.Text = newAuthenticator.Name; WIZARD.CurrentPage = WIZARDPAGE_Protect; } else { this.Close(); } } }