Exemplo n.º 1
0
        private bool CreateCompositeKey()
        {
            m_pKey = new CompositeKey();

            if (m_secPassword.ContentsEqualTo(m_secRepeat) == false)
            {
                MessageService.ShowWarning(KPRes.PasswordRepeatFailed);
                return(false);
            }

            if (m_secPassword.TextLength == 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 (m_secPassword.TextLength < uMinLen)
            {
                string strML = KPRes.MasterPasswordMinLengthFailed;
                strML = strML.Replace(@"{PARAM}", uMinLen.ToString());
                MessageService.ShowWarning(strML);
                return(false);
            }

            byte[] pb = m_secPassword.ToUtf8();

            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);
                Array.Clear(pb, 0, pb.Length);
                return(false);
            }

            string strValRes = Program.KeyValidatorPool.Validate(pb,
                                                                 KeyValidationType.MasterPassword);

            if (strValRes != null)
            {
                MessageService.ShowWarning(strValRes);
                Array.Clear(pb, 0, pb.Length);
                return(false);
            }

            m_pKey.AddUserKey(new KcpPassword(pb));
            Array.Clear(pb, 0, pb.Length);

            return(true);
        }
        private bool check_confirm_password_ok()
        {
            if (current_password_field == null || current_password_confirm_field == null)
            {
                return(true);
            }
            if (current_password_field.ContentsEqualTo(current_password_confirm_field) == false)
            {
                init_validation_err();
                current_password_confirm_field_txt.BackColor = KeePass.App.AppDefs.ColorEditError;
                m_ttValidationError.Show(KPRes.PasswordRepeatFailed, current_password_confirm_field_txt);
                return(false);
            }
            else if (m_ttValidationError != null)
            {
                m_ttValidationError.Hide(current_password_confirm_field_txt);
            }
            current_password_confirm_field_txt.BackColor = Color.White;

            return(true);
        }
Exemplo n.º 3
0
        private bool CreateCompositeKey()
        {
            m_pKey = new CompositeKey();

            if (m_cbPassword.Checked)            // Use a password
            {
                if (m_cbHidePassword.Checked)
                {
                    if (m_secPassword.ContentsEqualTo(m_secRepeat) == false)
                    {
                        MessageService.ShowWarning(KPRes.PasswordRepeatFailed);
                        return(false);
                    }
                }

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

                byte[] pb = m_secPassword.ToUtf8();

                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);
                    Array.Clear(pb, 0, pb.Length);
                    return(false);
                }

                m_pKey.AddUserKey(new KcpPassword(pb));
                Array.Clear(pb, 0, pb.Length);
            }

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

            if (m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                (bIsKeyProv == false))
            {
                try { m_pKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                catch (Exception exKF)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKF);
                    return(false);
                }
            }
            else if (m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) &&
                     (bIsKeyProv == true))
            {
                byte[] pbCustomKey = Program.KeyProviderPool.GetKey(strKeyFile);

                try { m_pKey.AddUserKey(new KcpCustomKey(pbCustomKey)); }
                catch (Exception exCKP)
                {
                    MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exCKP);
                    return(false);
                }

                if ((pbCustomKey != null) && (pbCustomKey.Length > 0))
                {
                    Array.Clear(pbCustomKey, 0, pbCustomKey.Length);
                }
            }

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

            return(true);
        }
Exemplo n.º 4
0
        private bool CreateCompositeKey()
        {
            m_pKey = new CompositeKey();

            if (m_cbPassword.Checked)            // Use a password
            {
                if (m_secPassword.ContentsEqualTo(m_secRepeat) == false)
                {
                    MessageService.ShowWarning(KPRes.PasswordRepeatFailed);
                    return(false);
                }

                if (m_secPassword.TextLength == 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 (m_secPassword.TextLength < uMinLen)
                {
                    string strML = KPRes.MasterPasswordMinLengthFailed;
                    strML = strML.Replace(@"{PARAM}", uMinLen.ToString());
                    MessageService.ShowWarning(strML);
                    return(false);
                }

                byte[] pb = m_secPassword.ToUtf8();

                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);
                    Array.Clear(pb, 0, pb.Length);
                    return(false);
                }

                string strValRes = Program.KeyValidatorPool.Validate(pb,
                                                                     KeyValidationType.MasterPassword);
                if (strValRes != null)
                {
                    MessageService.ShowWarning(strValRes);
                    Array.Clear(pb, 0, pb.Length);
                    return(false);
                }

                m_pKey.AddUserKey(new KcpPassword(pb));
                Array.Clear(pb, 0, pb.Length);
            }

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

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

                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);
                    }

                    Array.Clear(pbCustomKey, 0, pbCustomKey.Length);
                }
                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);
        }