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