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