public void SetKeySources(IOConnectionInfo iocDb, CompositeKey cmpKey) { string strID = GetKeyAssocID(iocDb); int idx = GetKeyAssocIndex(strID); if((cmpKey == null) || !m_bRememberKeySources) { if(idx >= 0) m_vKeySources.RemoveAt(idx); return; } AceKeyAssoc a = new AceKeyAssoc(); a.DatabasePath = strID; IUserKey kcpFile = cmpKey.GetUserKey(typeof(KcpKeyFile)); if(kcpFile != null) { string strKeyFile = ((KcpKeyFile)kcpFile).Path; if(!string.IsNullOrEmpty(strKeyFile) && !StrUtil.IsDataUri(strKeyFile)) { if(!UrlUtil.IsAbsolutePath(strKeyFile)) strKeyFile = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(), strKeyFile); a.KeyFilePath = strKeyFile; } } IUserKey kcpCustom = cmpKey.GetUserKey(typeof(KcpCustomKey)); if(kcpCustom != null) a.KeyProvider = ((KcpCustomKey)kcpCustom).Name; IUserKey kcpUser = cmpKey.GetUserKey(typeof(KcpUserAccount)); a.UserAccount = (kcpUser != null); bool bAtLeastOne = ((a.KeyFilePath.Length > 0) || (a.KeyProvider.Length > 0) || a.UserAccount); if(bAtLeastOne) { if(idx >= 0) m_vKeySources[idx] = a; else m_vKeySources.Add(a); } else if(idx >= 0) m_vKeySources.RemoveAt(idx); }
public void SetKeySource(IOConnectionInfo ioDatabase, string strKeySource, bool bIsKeyFile) { if (ioDatabase == null) { throw new ArgumentNullException("ioDatabase"); } string strDb = ioDatabase.Path; if ((strDb.Length > 0) && ioDatabase.IsLocalFile() && !UrlUtil.IsAbsolutePath(strDb)) { strDb = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(), strDb); } string strKey = strKeySource; if (bIsKeyFile && !string.IsNullOrEmpty(strKey)) { if (StrUtil.IsDataUri(strKey)) { strKey = null; // Don't remember data URIs } else if (!UrlUtil.IsAbsolutePath(strKey)) { strKey = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(), strKey); } } if (!m_bRememberKeySources) { strKey = null; } foreach (AceKeyAssoc kfp in m_vKeySources) { if (strDb.Equals(kfp.DatabasePath, StrUtil.CaseIgnoreCmp)) { if (string.IsNullOrEmpty(strKey)) { m_vKeySources.Remove(kfp); } else { kfp.KeyFilePath = (bIsKeyFile ? strKey : string.Empty); kfp.KeyProvider = (bIsKeyFile ? string.Empty : strKey); } return; } } if (string.IsNullOrEmpty(strKey)) { return; } AceKeyAssoc kfpNew = new AceKeyAssoc(); kfpNew.DatabasePath = strDb; if (bIsKeyFile) { kfpNew.KeyFilePath = strKey; } else { kfpNew.KeyProvider = strKey; } m_vKeySources.Add(kfpNew); }
private void OnFormLoad(object sender, EventArgs e) { m_bInitializing = true; GlobalWindowManager.AddWindow(this); // if(m_bRedirectActivation) Program.MainForm.RedirectActivationPush(this); string strBannerTitle = (!string.IsNullOrEmpty(m_strCustomTitle) ? m_strCustomTitle : KPRes.EnterCompositeKey); string strBannerDesc = WinUtil.CompactPath(m_ioInfo.Path, 45); BannerFactory.CreateBannerEx(this, m_bannerImage, Properties.Resources.B48x48_KGPG_Key2, strBannerTitle, strBannerDesc); this.Icon = Properties.Resources.KeePass; FontUtil.SetDefaultFont(m_cbPassword); FontUtil.AssignDefaultBold(m_cbPassword); FontUtil.AssignDefaultBold(m_cbKeyFile); FontUtil.AssignDefaultBold(m_cbUserAccount); UIUtil.ConfigureToolTip(m_ttRect); // m_ttRect.SetToolTip(m_cbHidePassword, KPRes.TogglePasswordAsterisks); m_ttRect.SetToolTip(m_btnOpenKeyFile, KPRes.KeyFileSelect); PwInputControlGroup.ConfigureHideButton(m_cbHidePassword, m_ttRect); string strStart = (!string.IsNullOrEmpty(m_strCustomTitle) ? m_strCustomTitle : KPRes.OpenDatabase); string strNameEx = UrlUtil.GetFileName(m_ioInfo.Path); if(!string.IsNullOrEmpty(strNameEx)) this.Text = strStart + " - " + strNameEx; else this.Text = strStart; m_tbPassword.Text = string.Empty; m_secPassword.SecureDesktopMode = m_bSecureDesktop; m_secPassword.Attach(m_tbPassword, ProcessTextChangedPassword, true); // m_cmbKeyFile.OrderedImageList = m_lKeyFileImages; AddKeyFileSuggPriv(KPRes.NoKeyFileSpecifiedMeta, true); // Do not directly compare with Program.CommandLineArgs.FileName, // because this may be a relative path instead of an absolute one string strCmdLineFile = Program.CommandLineArgs.FileName; if((strCmdLineFile != null) && (Program.MainForm != null)) strCmdLineFile = Program.MainForm.IocFromCommandLine().Path; if((strCmdLineFile != null) && strCmdLineFile.Equals(m_ioInfo.Path, StrUtil.CaseIgnoreCmp)) { string str; str = Program.CommandLineArgs[AppDefs.CommandLineOptions.Password]; if(str != null) { m_cbPassword.Checked = true; m_tbPassword.Text = str; } str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordEncrypted]; if(str != null) { m_cbPassword.Checked = true; m_tbPassword.Text = StrUtil.DecryptString(str); } str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordStdIn]; if(str != null) { KcpPassword kcpPw = KeyUtil.ReadPasswordStdIn(true); if(kcpPw != null) { m_cbPassword.Checked = true; m_tbPassword.Text = kcpPw.Password.ReadString(); } } str = Program.CommandLineArgs[AppDefs.CommandLineOptions.KeyFile]; if(str != null) { m_cbKeyFile.Checked = true; AddKeyFileSuggPriv(str, true); } str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PreSelect]; if(str != null) { m_cbKeyFile.Checked = true; AddKeyFileSuggPriv(str, true); } } m_cbHidePassword.Checked = true; OnCheckedHidePassword(sender, e); Debug.Assert(m_cmbKeyFile.Text.Length != 0); m_btnExit.Enabled = m_bCanExit; m_btnExit.Visible = m_bCanExit; ulong uKpf = Program.Config.UI.KeyPromptFlags; UIUtil.ApplyKeyUIFlags(uKpf, m_cbPassword, m_cbKeyFile, m_cbUserAccount, m_cbHidePassword); if((uKpf & (ulong)AceKeyUIFlags.DisableKeyFile) != 0) { UIUtil.SetEnabled(m_cmbKeyFile, m_cbKeyFile.Checked); UIUtil.SetEnabled(m_btnOpenKeyFile, m_cbKeyFile.Checked); } if(((uKpf & (ulong)AceKeyUIFlags.CheckPassword) != 0) || ((uKpf & (ulong)AceKeyUIFlags.UncheckPassword) != 0)) m_bPwStatePreset = true; if(((uKpf & (ulong)AceKeyUIFlags.CheckUserAccount) != 0) || ((uKpf & (ulong)AceKeyUIFlags.UncheckUserAccount) != 0)) m_bUaStatePreset = true; CustomizeForScreenReader(); EnableUserControls(); m_bInitializing = false; // E.g. command line options have higher priority m_bCanModKeyFile = (m_cmbKeyFile.SelectedIndex == 0); m_aKeyAssoc = Program.Config.Defaults.GetKeySources(m_ioInfo); if(m_aKeyAssoc != null) { if(m_aKeyAssoc.Password && !m_bPwStatePreset) m_cbPassword.Checked = true; if(m_aKeyAssoc.KeyFilePath.Length > 0) AddKeyFileSuggPriv(m_aKeyAssoc.KeyFilePath, null); if(m_aKeyAssoc.UserAccount && !m_bUaStatePreset) m_cbUserAccount.Checked = true; } foreach(KeyProvider prov in Program.KeyProviderPool) AddKeyFileSuggPriv(prov.Name, null); // Local, but thread will continue to run anyway Thread th = new Thread(new ThreadStart(this.AsyncFormLoad)); th.Start(); // ThreadPool.QueueUserWorkItem(new WaitCallback(this.AsyncFormLoad)); this.BringToFront(); this.Activate(); // UIUtil.SetFocus(m_tbPassword, this); // See OnFormShown }
public void SetKeySource(IOConnectionInfo ioDatabase, string strKeySource, bool bIsKeyFile) { if(ioDatabase == null) throw new ArgumentNullException("ioDatabase"); string strDb = ioDatabase.Path; if((strDb.Length > 0) && ioDatabase.IsLocalFile() && !UrlUtil.IsAbsolutePath(strDb)) strDb = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(), strDb); string strKey = strKeySource; if(bIsKeyFile && !string.IsNullOrEmpty(strKey)) { if(StrUtil.IsDataUri(strKey)) strKey = null; // Don't remember data URIs else if(!UrlUtil.IsAbsolutePath(strKey)) strKey = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(), strKey); } if(!m_bRememberKeySources) strKey = null; foreach(AceKeyAssoc kfp in m_vKeySources) { if(strDb.Equals(kfp.DatabasePath, StrUtil.CaseIgnoreCmp)) { if(string.IsNullOrEmpty(strKey)) m_vKeySources.Remove(kfp); else { kfp.KeyFilePath = (bIsKeyFile ? strKey : string.Empty); kfp.KeyProvider = (bIsKeyFile ? string.Empty : strKey); } return; } } if(string.IsNullOrEmpty(strKey)) return; AceKeyAssoc kfpNew = new AceKeyAssoc(); kfpNew.DatabasePath = strDb; if(bIsKeyFile) kfpNew.KeyFilePath = strKey; else kfpNew.KeyProvider = strKey; m_vKeySources.Add(kfpNew); }