예제 #1
0
        private void keyCreateForm_onConfirmClick(object sender, EventArgs e)
        {
            if (!_createKeyForm_usePw.Checked)
            {
                return;
            }

            if (!_createKeyForm_pwInputGroup.ValidateData(false))
            {
                return;
            }

            // password should be used, passwords are equal and
            // yubikey is connected at this point in the code
            string challenge = Encoding.UTF8.GetString(_createKeyForm_pwInputGroup.GetPasswordUtf8());
            string response;

            if (yubiChallengeResponse(challenge, out response))
            {
                // workaround for harmless bug
                _backupUIFlags             = KeePass.Program.Config.UI.UIFlags;
                Program.Config.UI.UIFlags &= ~(ulong)KeePass.App.Configuration.AceUIFlags.HidePwQuality;
                _restoreUIFlags            = true;

                string password = deriveMasterPassword(challenge, response);
                _createKeyForm_pwInputGroup.SetPassword(Encoding.UTF8.GetBytes(password), true);

                new YubiPluginForm(password).ShowDialog();
            }
        }
예제 #2
0
 private void bChangePassword_Click(object sender, EventArgs e)
 {
     if (!m_icgNewPassword.ValidateData(true))
     {
         DialogResult = DialogResult.None;
         return;
     }
     if (m_Profile == Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile)
     {
         m_pcadata.Strings.Set(Config.ProfileLastUsedProfile, new ProtectedString(false, Config.ProfileAutoGenerated));
     }
     else if ((m_Profile != null) && !string.IsNullOrEmpty(m_Profile.Name))
     {
         m_pcadata.Strings.Set(Config.ProfileLastUsedProfile, new ProtectedString(false, m_Profile.Name));
     }
     else if (m_Profile == null)
     {
         m_pcadata.Strings.Remove(Config.ProfileLastUsedProfile);
     }
 }
예제 #3
0
        private bool CreateCompositeKey()
        {
            m_pKey = new CompositeKey();

            if (m_cbPassword.Checked)            // Use a password
            {
                if (!m_icgPassword.ValidateData(true))
                {
                    return(false);
                }

                uint uPwLen = m_icgPassword.PasswordLength;
                if (uPwLen == 0)
                {
                    if (!MessageService.AskYesNo(KPRes.EmptyMasterPw +
                                                 MessageService.NewParagraph + KPRes.EmptyMasterPwHint +
                                                 MessageService.NewParagraph + KPRes.EmptyMasterPwQuestion,
                                                 null, false))
                    {
                        return(false);
                    }
                }

                uint uMinLen = Program.Config.Security.MasterPassword.MinimumLength;
                if (uPwLen < uMinLen)
                {
                    string strML = KPRes.MasterPasswordMinLengthFailed;
                    strML = strML.Replace(@"{PARAM}", uMinLen.ToString());
                    MessageService.ShowWarning(strML);
                    return(false);
                }

                byte[] pb = m_icgPassword.GetPasswordUtf8();

                uint uMinQual = Program.Config.Security.MasterPassword.MinimumQuality;
                if (QualityEstimation.EstimatePasswordBits(pb) < uMinQual)
                {
                    string strMQ = KPRes.MasterPasswordMinQualityFailed;
                    strMQ = strMQ.Replace(@"{PARAM}", uMinQual.ToString());
                    MessageService.ShowWarning(strMQ);
                    MemUtil.ZeroByteArray(pb);
                    return(false);
                }

                string strValRes = Program.KeyValidatorPool.Validate(pb,
                                                                     KeyValidationType.MasterPassword);
                if (strValRes != null)
                {
                    MessageService.ShowWarning(strValRes);
                    MemUtil.ZeroByteArray(pb);
                    return(false);
                }

                m_pKey.AddUserKey(new KcpPassword(pb));
                MemUtil.ZeroByteArray(pb);
            }

            string strKeyFile = m_cmbKeyFile.Text;
            bool   bIsKeyProv = Program.KeyProviderPool.IsKeyProvider(strKeyFile);

            if (m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                !bIsKeyProv)
            {
                try { m_pKey.AddUserKey(new KcpKeyFile(strKeyFile, true)); }
                catch (InvalidDataException exID)                // Selected database file
                {
                    MessageService.ShowWarning(strKeyFile, exID);
                    return(false);
                }
                catch (Exception exKF)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKF);
                    return(false);
                }
            }
            else if (m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                     bIsKeyProv)
            {
                KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(
                    m_ioInfo, true, false);

                bool   bPerformHash;
                byte[] pbCustomKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP,
                                                                    out bPerformHash);
                if ((pbCustomKey != null) && (pbCustomKey.Length > 0))
                {
                    try { m_pKey.AddUserKey(new KcpCustomKey(strKeyFile, pbCustomKey, bPerformHash)); }
                    catch (Exception exCKP)
                    {
                        MessageService.ShowWarning(exCKP);
                        return(false);
                    }

                    MemUtil.ZeroByteArray(pbCustomKey);
                }
                else
                {
                    return(false);                 // Provider has shown error message
                }
            }

            if (m_cbUserAccount.Checked)
            {
                try { m_pKey.AddUserKey(new KcpUserAccount()); }
                catch (Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return(false);
                }
            }

            return(true);
        }
예제 #4
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);
        }