Ejemplo n.º 1
0
        private void GlobalWindowManager_WindowAdded(object sender, GwmWindowEventArgs e)
        {
            // get references for password fields on unlocking and creating a database
            // if a yubikey is inserted, the password field is overwriten with a value
            // derived from the password and the yubikey-challenge-response

            if (e.Form is KeyPromptForm)
            {
                _keyPromtForm            = (KeyPromptForm)e.Form;
                _keyPromtForm_okButton   = (Button)_keyPromtForm.Controls.Find("m_btnOK", false)[0];
                _keyPromtForm_usePw      = (CheckBox)_keyPromtForm.Controls.Find("m_cbPassword", false)[0];
                _keyPromtForm_secureEdit = (SecureEdit)typeof(KeyPromptForm)
                                           .GetField("m_secPassword", BindingFlags.NonPublic | BindingFlags.Instance)
                                           .GetValue(_keyPromtForm);

                injectHandler(_keyPromtForm_okButton, keyPromtForm_onConfirmClick);
            }

            else if (e.Form is KeyCreationForm)
            {
                _createKeyForm              = (KeyCreationForm)e.Form;
                _createKeyForm_okButton     = (Button)_createKeyForm.Controls.Find("m_btnCreate", false)[0];
                _createKeyForm_usePw        = (CheckBox)_createKeyForm.Controls.Find("m_cbPassword", false)[0];
                _createKeyForm_pwInputGroup = (PwInputControlGroup)typeof(KeyCreationForm)
                                              .GetField("m_icgPassword", BindingFlags.NonPublic | BindingFlags.Instance)
                                              .GetValue(_createKeyForm);

                _createKeyForm.VisibleChanged += _createKeyForm_VisibleChanged;

                injectHandler(_createKeyForm_okButton, keyCreateForm_onConfirmClick);
            }
        }
Ejemplo n.º 2
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_psWord != null);
            if (m_psWord == null)
            {
                throw new InvalidOperationException();
            }

            m_bFormLoaded = false;

            GlobalWindowManager.AddWindow(this);

            m_nFormHeight = this.Height;             // Before restoring the position/size

            string strRect = Program.Config.UI.CharPickerRect;

            if (strRect.Length > 0)
            {
                UIUtil.SetWindowScreenRect(this, strRect);
            }
            m_strInitialFormRect = UIUtil.GetWindowScreenRect(this);

            m_fontChars = FontUtil.CreateFont("Tahoma", 8.25f, FontStyle.Bold);

            this.Icon = Properties.Resources.KeePass;
            this.Text = KPRes.PickCharacters + " - " + PwDefs.ShortProductName;

            m_secWord.Attach(m_tbSelected, OnSelectedTextChangedEx, true);

            PwInputControlGroup.ConfigureHideButton(m_cbHideChars, null);

            AceColumn colPw = Program.Config.MainWindow.FindColumn(AceColumnType.Password);
            bool      bHide = ((colPw != null) ? colPw.HideWithAsterisks : true);

            if (m_bInitHide.HasValue)
            {
                bHide = m_bInitHide.Value;
            }
            bHide |= !AppPolicy.Current.UnhidePasswords;
            m_cbHideChars.Checked = bHide;

            RecreateResizableWindowControls();

            if (m_uCharCount > 0)
            {
                m_btnOK.Enabled = false;
                // m_btnOK.Visible = false;
            }

            if (m_bSetForeground)
            {
                this.BringToFront();
                this.Activate();
            }

            UIUtil.SetFocus(m_tbSelected, this);
            m_bFormLoaded = true;
        }
Ejemplo n.º 3
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if (m_psWord == null)
            {
                Debug.Assert(false); throw new InvalidOperationException();
            }

            // The password text box should not be focused by default
            // in order to avoid a Caps Lock warning tooltip bug;
            // https://sourceforge.net/p/keepass/bugs/1807/
            Debug.Assert((m_pnlBottom.TabIndex == 0) && !m_tbSelected.Focused);

            m_bFormLoaded = false;

            GlobalWindowManager.AddWindow(this);

            m_nFormHeight = this.Height;             // Before restoring the position/size

            m_strInitialFormRect = UIUtil.SetWindowScreenRectEx(this,
                                                                Program.Config.UI.CharPickerRect);

            m_fontChars = FontUtil.CreateFont("Tahoma", 8.25f, FontStyle.Bold);

            this.Icon = AppIcons.Default;
            this.Text = KPRes.PickCharacters + " - " + PwDefs.ShortProductName;

            // Must be set manually due to possible object override
            m_tbSelected.TextChanged += this.OnSelectedTextChangedEx;

            PwInputControlGroup.ConfigureHideButton(m_cbHideChars, null);

            AceColumn colPw = Program.Config.MainWindow.FindColumn(AceColumnType.Password);
            bool      bHide = ((colPw != null) ? colPw.HideWithAsterisks : true);

            if (m_bInitHide.HasValue)
            {
                bHide = m_bInitHide.Value;
            }
            bHide |= !AppPolicy.Current.UnhidePasswords;
            m_cbHideChars.Checked = bHide;

            RecreateResizableWindowControls();

            if (m_uCharCount > 0)
            {
                m_btnOK.Enabled = false;
                // m_btnOK.Visible = false;
            }

            if (m_bSetForeground)
            {
                this.BringToFront();
                this.Activate();
            }

            m_bFormLoaded = true;
        }
Ejemplo n.º 4
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            m_bInitializing = true;

            GlobalWindowManager.AddWindow(this);
            // if(m_bRedirectActivation) Program.MainForm.RedirectActivationPush(this);

            string strBannerTitle = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                                     m_strCustomTitle : KPRes.EnterCompositeKey);
            string strBannerDesc = WinUtil.CompactPath(m_ioInfo.Path, 45);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_KGPG_Key2, strBannerTitle, strBannerDesc);
            this.Icon = AppIcons.Default;

            FontUtil.SetDefaultFont(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbKeyFile);
            FontUtil.AssignDefaultBold(m_cbUserAccount);

            UIUtil.ConfigureToolTip(m_ttRect);
            // m_ttRect.SetToolTip(m_cbHidePassword, KPRes.TogglePasswordAsterisks);
            m_ttRect.SetToolTip(m_btnOpenKeyFile, KPRes.KeyFileSelect);

            PwInputControlGroup.ConfigureHideButton(m_cbHidePassword, m_ttRect);

            string strStart = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                               m_strCustomTitle : KPRes.OpenDatabase);
            string strNameEx = UrlUtil.GetFileName(m_ioInfo.Path);

            if (!string.IsNullOrEmpty(strNameEx))
            {
                this.Text = strStart + " - " + strNameEx;
            }
            else
            {
                this.Text = strStart;
            }

            // Must be set manually due to possible object override
            m_tbPassword.TextChanged += this.ProcessTextChangedPassword;

            // m_cmbKeyFile.OrderedImageList = m_lKeyFileImages;
            AddKeyFileSuggPriv(KPRes.NoKeyFileSpecifiedMeta, true);

            // Do not directly compare with Program.CommandLineArgs.FileName,
            // because this may be a relative path instead of an absolute one
            string strCmdLineFile = Program.CommandLineArgs.FileName;

            if ((strCmdLineFile != null) && (Program.MainForm != null))
            {
                strCmdLineFile = Program.MainForm.IocFromCommandLine().Path;
            }
            if ((strCmdLineFile != null) && strCmdLineFile.Equals(m_ioInfo.Path,
                                                                  StrUtil.CaseIgnoreCmp))
            {
                string str;

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.Password];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = str;
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordEncrypted];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = StrUtil.DecryptString(str);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordStdIn];
                if (str != null)
                {
                    ProtectedString ps = KeyUtil.ReadPasswordStdIn(true);
                    if (ps != null)
                    {
                        m_cbPassword.Checked = true;
                        m_tbPassword.TextEx  = ps;
                    }
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.KeyFile];
                if (str != null)
                {
                    m_cbKeyFile.Checked = true;
                    AddKeyFileSuggPriv(str, true);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PreSelect];
                if (str != null)
                {
                    m_cbKeyFile.Checked = true;
                    AddKeyFileSuggPriv(str, true);
                }
            }

            m_cbHidePassword.Checked = true;
            OnCheckedHidePassword(sender, e);

            Debug.Assert(m_cmbKeyFile.Text.Length != 0);

            m_btnExit.Enabled = m_bCanExit;
            m_btnExit.Visible = m_bCanExit;

            ulong uKpf = Program.Config.UI.KeyPromptFlags;

            UIUtil.ApplyKeyUIFlags(uKpf, m_cbPassword, m_cbKeyFile,
                                   m_cbUserAccount, m_cbHidePassword);

            if ((uKpf & (ulong)AceKeyUIFlags.DisableKeyFile) != 0)
            {
                UIUtil.SetEnabled(m_cmbKeyFile, m_cbKeyFile.Checked);
                UIUtil.SetEnabled(m_btnOpenKeyFile, m_cbKeyFile.Checked);
            }

            if (((uKpf & (ulong)AceKeyUIFlags.CheckPassword) != 0) ||
                ((uKpf & (ulong)AceKeyUIFlags.UncheckPassword) != 0))
            {
                m_bPwStatePreset = true;
            }
            if (((uKpf & (ulong)AceKeyUIFlags.CheckUserAccount) != 0) ||
                ((uKpf & (ulong)AceKeyUIFlags.UncheckUserAccount) != 0))
            {
                m_bUaStatePreset = true;
            }

            CustomizeForScreenReader();
            EnableUserControls();

            m_bInitializing = false;

            // E.g. command line options have higher priority
            m_bCanModKeyFile = (m_cmbKeyFile.SelectedIndex == 0);

            m_aKeyAssoc = Program.Config.Defaults.GetKeySources(m_ioInfo);
            if (m_aKeyAssoc != null)
            {
                if (m_aKeyAssoc.Password && !m_bPwStatePreset)
                {
                    m_cbPassword.Checked = true;
                }

                if (m_aKeyAssoc.KeyFilePath.Length > 0)
                {
                    AddKeyFileSuggPriv(m_aKeyAssoc.KeyFilePath, null);
                }

                if (m_aKeyAssoc.UserAccount && !m_bUaStatePreset)
                {
                    m_cbUserAccount.Checked = true;
                }
            }

            foreach (KeyProvider prov in Program.KeyProviderPool)
            {
                AddKeyFileSuggPriv(prov.Name, null);
            }

            // Local, but thread will continue to run anyway
            Thread th = new Thread(new ThreadStart(this.AsyncFormLoad));

            th.Start();
            // ThreadPool.QueueUserWorkItem(new WaitCallback(this.AsyncFormLoad));

            this.BringToFront();
            this.Activate();
            // UIUtil.SetFocus(m_tbPassword, this); // See OnFormShown
        }
Ejemplo n.º 5
0
        internal static CompositeKey KeyFromUI(CheckBox cbPassword,
                                               PwInputControlGroup icgPassword, SecureTextBoxEx stbPassword,
                                               CheckBox cbKeyFile, ComboBox cmbKeyFile, CheckBox cbUserAccount,
                                               IOConnectionInfo ioc, bool bSecureDesktop)
        {
            if (cbPassword == null)
            {
                Debug.Assert(false); return(null);
            }
            if (stbPassword == null)
            {
                Debug.Assert(false); return(null);
            }
            if (cbKeyFile == null)
            {
                Debug.Assert(false); return(null);
            }
            if (cmbKeyFile == null)
            {
                Debug.Assert(false); return(null);
            }
            if (cbUserAccount == null)
            {
                Debug.Assert(false); return(null);
            }

            bool bNewKey = (icgPassword != null);

            byte[] pbPasswordUtf8 = null;

            try
            {
                if (cbPassword.Checked)
                {
                    pbPasswordUtf8 = stbPassword.TextEx.ReadUtf8();

                    if (bNewKey)
                    {
                        if (!icgPassword.ValidateData(true))
                        {
                            return(null);
                        }

                        string strError = ValidateNewMasterPassword(pbPasswordUtf8,
                                                                    (uint)stbPassword.TextLength);
                        if (strError != null)
                        {
                            if (strError.Length != 0)
                            {
                                MessageService.ShowWarning(strError);
                            }
                            return(null);
                        }
                    }
                }

                string strKeyFile = null;
                if (cbKeyFile.Checked)
                {
                    strKeyFile = cmbKeyFile.Text;
                }

                return(CreateKey(pbPasswordUtf8, strKeyFile, cbUserAccount.Checked,
                                 ioc, bNewKey, bSecureDesktop));
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }
            finally
            {
                if (pbPasswordUtf8 != null)
                {
                    MemUtil.ZeroByteArray(pbPasswordUtf8);
                }
            }

            return(null);
        }
Ejemplo n.º 6
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            ++m_uUIAutoBlocked;

            // The password text box should not be focused by default
            // in order to avoid a Caps Lock warning tooltip bug;
            // https://sourceforge.net/p/keepass/bugs/1807/
            Debug.Assert((m_tbPassword.TabIndex >= 2) && !m_tbPassword.Focused);

            GlobalWindowManager.AddWindow(this);
            // if(m_bRedirectActivation) Program.MainForm.RedirectActivationPush(this);

            string strBannerTitle = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                                     m_strCustomTitle : KPRes.EnterCompositeKey);
            string strBannerDesc = m_ioInfo.GetDisplayName();             // Compacted by banner

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_KGPG_Key2, strBannerTitle, strBannerDesc);
            this.Icon = AppIcons.Default;

            string strStart = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                               m_strCustomTitle : KPRes.OpenDatabase);
            string strName = UrlUtil.GetFileName(m_ioInfo.Path);

            if (!string.IsNullOrEmpty(strName))
            {
                this.Text = strStart + " - " + strName;
            }
            else
            {
                this.Text = strStart;
            }

            FontUtil.SetDefaultFont(m_cbPassword);
            // FontUtil.AssignDefaultBold(m_cbPassword);
            // FontUtil.AssignDefaultBold(m_cbKeyFile);
            // FontUtil.AssignDefaultBold(m_cbUserAccount);

            UIUtil.ConfigureToolTip(m_ttRect);
            UIUtil.SetToolTip(m_ttRect, m_btnOpenKeyFile, KPRes.KeyFileSelect, true);

            UIUtil.AccSetName(m_tbPassword, m_cbPassword);
            UIUtil.AccSetName(m_cmbKeyFile, m_cbKeyFile);

            PwInputControlGroup.ConfigureHideButton(m_cbHidePassword, m_ttRect);

            // Enable protection before possibly setting a text
            m_cbHidePassword.Checked = true;
            OnHidePasswordCheckedChanged(null, EventArgs.Empty);

            // Must be set manually due to possible object override
            m_tbPassword.TextChanged += this.OnPasswordTextChanged;

            // m_cmbKeyFile.OrderedImageList = m_lKeyFileImages;
            AddKeyFileItem(KPRes.NoKeyFileSpecifiedMeta, true);

            Debug.Assert(!AnyComponentOn());

            // Do not directly compare with Program.CommandLineArgs.FileName,
            // because this may be a relative path instead of an absolute one
            string strCmdLineFile = Program.CommandLineArgs.FileName;

            if (!string.IsNullOrEmpty(strCmdLineFile) && (Program.MainForm != null))
            {
                strCmdLineFile = Program.MainForm.IocFromCommandLine().Path;
            }
            if (!string.IsNullOrEmpty(strCmdLineFile) && strCmdLineFile.Equals(
                    m_ioInfo.Path, StrUtil.CaseIgnoreCmp))
            {
                string str;

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.Password];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = str;
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordEncrypted];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = StrUtil.DecryptString(str);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordStdIn];
                if (str != null)
                {
                    ProtectedString ps = KeyUtil.ReadPasswordStdIn(true);
                    if (ps != null)
                    {
                        m_cbPassword.Checked = true;
                        m_tbPassword.TextEx  = ps;
                    }
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.KeyFile];
                if (!string.IsNullOrEmpty(str))
                {
                    AddKeyFileItem(str, true);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PreSelect];
                if (!string.IsNullOrEmpty(str))
                {
                    AddKeyFileItem(str, true);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.UserAccount];
                if (str != null)
                {
                    m_cbUserAccount.Checked = true;
                }
            }

            AceKeyAssoc a = Program.Config.Defaults.GetKeySources(m_ioInfo);

            if ((a != null) && !AnyComponentOn())
            {
                if (a.Password)
                {
                    m_cbPassword.Checked = true;
                }

                if (!string.IsNullOrEmpty(a.KeyFilePath))
                {
                    AddKeyFileItem(a.KeyFilePath, true);
                }
                if (!string.IsNullOrEmpty(a.KeyProvider))
                {
                    AddKeyFileItem(a.KeyProvider, true);
                }

                if (a.UserAccount)
                {
                    m_cbUserAccount.Checked = true;
                }
            }

            foreach (KeyProvider kp in Program.KeyProviderPool)
            {
                AddKeyFileItem(kp.Name, false);
            }

            UIUtil.ApplyKeyUIFlags(Program.Config.UI.KeyPromptFlags,
                                   m_cbPassword, m_cbKeyFile, m_cbUserAccount, m_cbHidePassword);

            if (!m_cbPassword.Enabled && !m_cbPassword.Checked)
            {
                m_tbPassword.Text = string.Empty;
                UIUtil.SetEnabledFast(false, m_tbPassword, m_cbHidePassword);
            }

            if (!m_cbKeyFile.Enabled && !m_cbKeyFile.Checked)
            {
                UIUtil.SetEnabledFast(false, m_cmbKeyFile, m_btnOpenKeyFile);
            }

            if (WinUtil.IsWindows9x || NativeLib.IsUnix())
            {
                UIUtil.SetChecked(m_cbUserAccount, false);
                UIUtil.SetEnabled(m_cbUserAccount, false);
            }

            m_btnExit.Enabled = m_bCanExit;
            m_btnExit.Visible = m_bCanExit;

            --m_uUIAutoBlocked;
            UpdateUIState();

            // Local, but thread will continue to run anyway
            Thread th = new Thread(new ThreadStart(this.OnFormLoadAsync));

            th.Start();
            // ThreadPool.QueueUserWorkItem(new WaitCallback(this.OnFormLoadAsync));

            this.BringToFront();
            this.Activate();
            // UIUtil.SetFocus(m_tbPassword, this); // See OnFormShown
        }