public static bool CreateAuxFile(OtpInfo otpInfo, KeyProviderQueryContext ctx, IOConnectionInfo auxFileIoc) { otpInfo.Type = ProvType; otpInfo.Version = ProvVersion; otpInfo.Generator = ProductName; otpInfo.EncryptSecret(); if(!OtpInfo.Save(auxFileIoc, otpInfo)) { MessageService.ShowWarning("Failed to save auxiliary OTP info file:", auxFileIoc.GetDisplayName()); return false; } return true; }
internal byte[] GetKey(string strProviderName, KeyProviderQueryContext ctx, out bool bPerformHash) { Debug.Assert(strProviderName != null); if (strProviderName == null) { throw new ArgumentNullException("strProviderName"); } bPerformHash = true; foreach (KeyProvider prov in m_vProviders) { if (prov.Name == strProviderName) { bPerformHash = !prov.DirectKey; return(prov.GetKey(ctx)); } } Debug.Assert(false); return(null); }
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); 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) { 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; } 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; }
public override byte[] GetKey(KeyProviderQueryContext ctx) { return(new byte[] { 2, 3, 5, 7, 11, 13 }); }
// public virtual PwIcon ImageIndex // { // get { return PwIcon.UserKey; } // } public abstract byte[] GetKey(KeyProviderQueryContext ctx);
public static CompositeKey KeyFromCommandLine(CommandLineArgs args) { if(args == null) throw new ArgumentNullException("args"); CompositeKey cmpKey = new CompositeKey(); string strPassword = args[AppDefs.CommandLineOptions.Password]; string strPasswordEnc = args[AppDefs.CommandLineOptions.PasswordEncrypted]; string strPasswordStdIn = args[AppDefs.CommandLineOptions.PasswordStdIn]; string strKeyFile = args[AppDefs.CommandLineOptions.KeyFile]; string strUserAcc = args[AppDefs.CommandLineOptions.UserAccount]; if(strPassword != null) cmpKey.AddUserKey(new KcpPassword(strPassword)); else if(strPasswordEnc != null) cmpKey.AddUserKey(new KcpPassword(StrUtil.DecryptString(strPasswordEnc))); else if(strPasswordStdIn != null) { KcpPassword kcpPw = ReadPasswordStdIn(true); if(kcpPw != null) cmpKey.AddUserKey(kcpPw); } if(strKeyFile != null) { if(Program.KeyProviderPool.IsKeyProvider(strKeyFile)) { KeyProviderQueryContext ctxKP = new KeyProviderQueryContext( IOConnectionInfo.FromPath(args.FileName), false, false); bool bPerformHash; byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP, out bPerformHash); if((pbProvKey != null) && (pbProvKey.Length > 0)) { try { cmpKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); } catch(Exception exCKP) { MessageService.ShowWarning(exCKP); return null; } Array.Clear(pbProvKey, 0, pbProvKey.Length); } else return null; // Provider has shown error message } else // Key file { try { cmpKey.AddUserKey(new KcpKeyFile(strKeyFile)); } catch(Exception exKey) { MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKey); return null; } } } if(strUserAcc != null) { try { cmpKey.AddUserKey(new KcpUserAccount()); } catch(Exception exUA) { MessageService.ShowWarning(exUA); return null; } } if(cmpKey.UserKeyCount > 0) { ClearKeyOptions(args, true); return cmpKey; } return null; }
public override byte[] GetKey(KeyProviderQueryContext ctx) { return new byte[]{ 2, 3, 5, 7, 11, 13 }; }
public abstract byte[] GetKey(KeyProviderQueryContext ctx);
private static Stream GetAuxFile(KeyProviderQueryContext ctx) { var auxPath = UrlUtil.StripExtension(ctx.DatabasePath) + ProviderAuxExt; return File.OpenRead(auxPath); }
private static byte[] DecryptKey(KeyProviderQueryContext ctx) { return Gpg.Decrypt(GetAuxFile(ctx)).GetBuffer(); }
public override byte[] GetKey(KeyProviderQueryContext ctx) { return DecryptKey(ctx); }
private bool CreateCompositeKey() { m_pKey = new CompositeKey(); if(m_cbPassword.Checked) // Use a password { byte[] pb = m_secPassword.ToUtf8(); m_pKey.AddUserKey(new KcpPassword(pb)); MemUtil.ZeroByteArray(pb); } string strKeyFile = m_cmbKeyFile.Text; Debug.Assert(strKeyFile != null); if(strKeyFile == null) strKeyFile = string.Empty; bool bIsProvKey = Program.KeyProviderPool.IsKeyProvider(strKeyFile); if(m_cbKeyFile.Checked && !strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta) && !bIsProvKey) { if(!ValidateKeyFile()) return false; try { m_pKey.AddUserKey(new KcpKeyFile(strKeyFile)); } catch(Exception) { MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError); return false; } } else if(m_cbKeyFile.Checked && !strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta) && bIsProvKey) { KeyProvider kp = Program.KeyProviderPool.Get(strKeyFile); if((kp != null) && m_bSecureDesktop) { if(!kp.SecureDesktopCompatible) { MessageService.ShowWarning(KPRes.KeyProvIncmpWithSD, KPRes.KeyProvIncmpWithSDHint); return false; } } KeyProviderQueryContext ctxKP = new KeyProviderQueryContext( m_ioInfo, false, m_bSecureDesktop); bool bPerformHash; byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP, out bPerformHash); if((pbProvKey != null) && (pbProvKey.Length > 0)) { try { m_pKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); } catch(Exception exCKP) { MessageService.ShowWarning(exCKP); return false; } MemUtil.ZeroByteArray(pbProvKey); } 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; }
private bool CreateCompositeKey() { m_pKey = new CompositeKey(); if(m_cbPassword.Checked) // Use a password { byte[] pb = m_secPassword.ToUtf8(); m_pKey.AddUserKey(new KcpPassword(pb)); Array.Clear(pb, 0, pb.Length); } string strKeyFile = m_cmbKeyFile.Text; Debug.Assert(strKeyFile != null); if(strKeyFile == null) strKeyFile = string.Empty; bool bIsProvKey = Program.KeyProviderPool.IsKeyProvider(strKeyFile); if(m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) && (bIsProvKey == false)) { if(ValidateKeyFileLocation() == false) return false; try { m_pKey.AddUserKey(new KcpKeyFile(strKeyFile)); } catch(Exception) { MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError); return false; } } else if(m_cbKeyFile.Checked && (!strKeyFile.Equals(KPRes.NoKeyFileSpecifiedMeta)) && (bIsProvKey == true)) { KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(m_ioInfo, false); bool bPerformHash; byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP, out bPerformHash); if((pbProvKey != null) && (pbProvKey.Length > 0)) { try { m_pKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); } catch(Exception exCKP) { MessageService.ShowWarning(exCKP); return false; } Array.Clear(pbProvKey, 0, pbProvKey.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; }
public override void Run() { try { StatusLogger.UpdateMessage(UiStringKey.SavingOtpAuxFile); KeyProviderQueryContext ctx = new KeyProviderQueryContext(_act._ioConnection, false, false); if (!OathHotpKeyProv.CreateAuxFile(_act._otpInfo, ctx, _act._otpAuxIoc)) Toast.MakeText(_act, _act.GetString(Resource.String.ErrorUpdatingOtpAuxFile), ToastLength.Long).Show(); App.Kp2a.GetDb().OtpAuxFileIoc = _act._otpAuxIoc; } catch (Exception e) { Kp2aLog.Log(e.Message); Toast.MakeText(_act, _act.GetString(Resource.String.ErrorUpdatingOtpAuxFile) + " " + e.Message, ToastLength.Long).Show(); } base.Run(); }
private static IOConnectionInfo GetAuxFileIoc(KeyProviderQueryContext ctx) { IOConnectionInfo ioc = ctx.DatabaseIOInfo.CloneDeep(); var iocAux = GetAuxFileIoc(ioc); return iocAux; }