Exemple #1
0
        public MainForm()
        {
            InitializeComponent();

            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"))
            {
                MessageBox.Show("Since this is the first time that you have run this application,\nyou will be asked to enter an access password.  This password will\nbe used to protect any passwords that you associate with your\nconnections.", "Create password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect");
            }

            while (_favorites == null || _history == null)
            {
                PasswordWindow passwordWindow = new PasswordWindow();
                passwordWindow.ShowDialog();

                _password = passwordWindow.Password;
                _password.MakeReadOnly();

                try
                {
                    _favorites = new Favorites(Connect, _password);
                    _history = new HistoryWindow(Connect, _favorites, _password);
                }

                catch (CryptographicException)
                {
                    DialogResult result = MessageBox.Show("Password is incorrect.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);

                    if (result != DialogResult.OK)
                    {
                        Closing = true;
                        return;
                    }
                }
            }

            _favorites.Password = _password;
            _history.Password = _password;

            ChannelServices.RegisterChannel(_ipcChannel, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(HistoryMethods), "HistoryMethods", WellKnownObjectMode.SingleCall);

            TabSelected += MainForm_TabSelected;
            TabDeselecting += MainForm_TabDeselecting;

            ActiveInstance = this;
            ConnectToHistoryMethod = ConnectToHistory;

            TabRenderer = new ChromeTabRenderer(this);
            Tabs.Add(new TitleBarTab(this)
                         {
                             Content = new RDCWindow(_password)
                         });
            SelectedTabIndex = 0;
        }
Exemple #2
0
        /// <summary>
        /// Handler method that's called when the selected item in <see cref="_encryptionTypeDropdown"/> is changed.  If the user selected
        /// <see cref="EncryptionType.Rijndael"/>, we prompt them to enter a password and save it to <see cref="_encryptionPassword"/>, otherwise we set
        /// <see cref="_encryptionPassword"/> to null.
        /// </summary>
        /// <param name="sender">Object from which this event originated, <see cref="_encryptionTypeDropdown"/> in this case.</param>
        /// <param name="e">Arguments associated with this event.</param>
        private void _encryptionTypeDropdown_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((_encryptionTypeDropdown.SelectedItem as ListItem).Value == "Rsa")
            {
                _encryptionPassword = null;
            }

            // ReSharper disable PossibleInvalidOperationException
            else if ((_encryptionTypeDropdown.SelectedItem as ListItem).Value != GlobalSettings.Instance.EncryptionType.Value.ToString("G"))
            // ReSharper restore PossibleInvalidOperationException
            {
                PasswordWindow passwordWindow = new PasswordWindow();

                if (passwordWindow.ShowDialog(this) == DialogResult.OK)
                {
                    _encryptionPassword = passwordWindow.Password;
                }
            }
        }
Exemple #3
0
        /// <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);
                }
        }
        /// <summary>
        /// Handler method that's called when the selected item in <see cref="_encryptionTypeDropdown"/> is changed.  If the user selected 
        /// <see cref="EncryptionType.Rijndael"/>, we prompt them to enter a password and save it to <see cref="_encryptionPassword"/>, otherwise we set
        /// <see cref="_encryptionPassword"/> to null.
        /// </summary>
        /// <param name="sender">Object from which this event originated, <see cref="_encryptionTypeDropdown"/> in this case.</param>
        /// <param name="e">Arguments associated with this event.</param>
        private void _encryptionTypeDropdown_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((_encryptionTypeDropdown.SelectedItem as ListItem).Value == "Rsa")
                _encryptionPassword = null;

                // ReSharper disable PossibleInvalidOperationException
            else if ((_encryptionTypeDropdown.SelectedItem as ListItem).Value != _parentTabs.Options.EncryptionType.Value.ToString("G"))
                // ReSharper restore PossibleInvalidOperationException
            {
                PasswordWindow passwordWindow = new PasswordWindow();

                if (passwordWindow.ShowDialog(this) == DialogResult.OK)
                    _encryptionPassword = passwordWindow.Password;
            }
        }
Exemple #5
0
        /// <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);
            }
        }
Exemple #6
0
        private static async Task<bool> SetupEncryption()
        {
            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.Instance.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 (Options.Instance.FirstLaunch)
                    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.Instance.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.Instance.EncryptionType == EncryptionType.Rsa && !Options.Instance.FirstLaunch;
            }

            // 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 (Options.Instance.FirstLaunch)
            {
                if (Options.Instance.EncryptionType == EncryptionType.Rijndael)
                    MessageBox.Show(Resources.FirstRunPasswordText, Resources.FirstRunPasswordTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);

#if !APPX
                Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "EasyConnect"));
#endif
            }

            if (Options.Instance.EncryptionType != null)
                await Options.Instance.Save();

            bool encryptionTypeSet = false;

            while (true)
            {
                // Get the user's encryption password via the password dialog
                if (!encryptionTypeSet && (Options.Instance.EncryptionType == EncryptionType.Rijndael || convertingToRsa))
                {
                    PasswordWindow passwordWindow = new PasswordWindow();
                    passwordWindow.ShowDialog();

                    ConnectionFactory.SetEncryptionType(EncryptionType.Rijndael, passwordWindow.Password);
                }

                else
                    ConnectionFactory.SetEncryptionType(Options.Instance.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
                {
                    await Bookmarks.Init();
                    await History.Init();
                    await ConnectionFactory.GetDefaultProtocol();

                    encryptionTypeSet = true;
                    break;
                }

                catch (Exception e)
                {
                    if ((Options.Instance.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)
                    {
                        return false;
                    }
                }
            }

            // If we're converting over to RSA, we've already loaded and decrypted the sensitive data using 
            if (convertingToRsa)
            {
                ConnectionFactory.SetEncryptionType(Options.Instance.EncryptionType.Value, null);

                await Bookmarks.Instance.Save();
                await History.Instance.Save();

                await ConnectionFactory.SetDefaults(await ConnectionFactory.GetDefaults(await ConnectionFactory.GetDefaultProtocol()));
            }

            return true;
        }