/// <summary> /// Initializes the UI, loads the bookmark and history data, and sets up the IPC remoting channel and low-level keyboard hook. /// </summary> protected void Init() { AeroPeekEnabled = false; bool convertingToRsa = false; // If the user hasn't formally selected an encryption type (either they're starting the application for the first time or are running a legacy // version that explicitly used Rijndael), ask them if they want to use RSA if (Options.EncryptionType == null) { string messageBoxText = @"Do you want to use an RSA key container to encrypt your passwords? The RSA encryption mode uses cryptographic keys associated with your Windows user account to encrypt sensitive data without having to enter an encryption password every time you start this application. However, your bookmarks file will be tied uniquely to this user account and you will be unable to share them between multiple users."; if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect")) messageBoxText += @" The alternative is to derive an encryption key from a password that you will need to enter every time that this application starts."; else messageBoxText += @" Since you've already encrypted your data with a password once, you would need to enter it one more time to decrypt it before RSA can be used."; Options.EncryptionType = MessageBox.Show(messageBoxText, "Use RSA?", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes ? EncryptionType.Rsa : EncryptionType.Rijndael; // Since they want to use RSA but already have connection data encrypted with Rijndael, we'll have to capture that password so that we can // decrypt it using Rijndael and then re-encrypt it using the RSA keypair convertingToRsa = Options.EncryptionType == EncryptionType.Rsa && Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"); } // If this is the first time that the user is running the application, pop up and information box informing them that they're going to enter a // password used to encrypt sensitive connection details if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect")) { if (Options.EncryptionType == EncryptionType.Rijndael) MessageBox.Show(Resources.FirstRunPasswordText, Resources.FirstRunPasswordTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"); } if (Options.EncryptionType != null) Options.Save(); bool encryptionTypeSet = false; while (Bookmarks == null || _history == null) { // Get the user's encryption password via the password dialog if (!encryptionTypeSet && (Options.EncryptionType == EncryptionType.Rijndael || convertingToRsa)) { PasswordWindow passwordWindow = new PasswordWindow(); passwordWindow.ShowDialog(); ConnectionFactory.SetEncryptionType(EncryptionType.Rijndael, passwordWindow.Password); } else ConnectionFactory.SetEncryptionType(Options.EncryptionType.Value); // Create the bookmark and history windows which will try to use the password to decrypt sensitive connection details; if it's unable to, an // exception will be thrown that wraps a CryptographicException instance try { _bookmarks = new BookmarksWindow(this); _history = new HistoryWindow(this); ConnectionFactory.GetDefaultProtocol(); encryptionTypeSet = true; } catch (Exception e) { if ((Options.EncryptionType == EncryptionType.Rijndael || convertingToRsa) && !ContainsCryptographicException(e)) throw; // Tell the user that their password is incorrect and, if they click OK, repeat the process DialogResult result = MessageBox.Show( Resources.IncorrectPasswordText, Resources.ErrorTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (result != DialogResult.OK) { IsClosing = true; return; } } } // If we're converting over to RSA, we've already loaded and decrypted the sensitive data using if (convertingToRsa) SetEncryptionType(Options.EncryptionType.Value, null); // Create a remoting channel used to tell this window to open historical connections when entries in the jump list are clicked if (_ipcChannel == null) { _ipcChannel = new IpcServerChannel("EasyConnect"); ChannelServices.RegisterChannel(_ipcChannel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof (HistoryMethods), "HistoryMethods", WellKnownObjectMode.SingleCall); } // Wire up the tab event handlers TabClicked += MainForm_TabClicked; ActiveInstance = this; ConnectToHistoryMethod = ConnectToHistory; TabRenderer = new ChromeTabRenderer(this); // Get the low-level keyboard hook that will be used to process shortcut keys using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { _hookproc = KeyboardHookCallback; _hookId = User32.SetWindowsHookEx(WH.WH_KEYBOARD_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0); } }
public TestApp() { InitializeComponent(); AeroPeekEnabled = true; TabRenderer = new ChromeTabRenderer(this); Icon = Resources.DefaultIcon; }