コード例 #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);
        }
コード例 #2
0
ファイル: ProxyForm.cs プロジェクト: ArtjomP/KeePass2.x
        private void OnBtnOK(object sender, EventArgs e)
        {
            ProxyServerType pst = ProxyServerType.System;

            if (m_rbNoProxy.Checked)
            {
                pst = ProxyServerType.None;
            }
            else if (m_rbManualProxy.Checked)
            {
                pst = ProxyServerType.Manual;
            }

            ProxyAuthType pat = ProxyAuthType.Default;

            if (m_rbAuthNone.Checked)
            {
                pat = ProxyAuthType.None;
            }
            else if (m_rbAuthManual.Checked)
            {
                pat = ProxyAuthType.Manual;
            }

            AceIntegration ace = Program.Config.Integration;

            ace.ProxyType     = pst;
            ace.ProxyAddress  = m_tbAddress.Text;
            ace.ProxyPort     = m_tbPort.Text;
            ace.ProxyAuthType = pat;
            ace.ProxyUserName = m_tbUser.Text;
            ace.ProxyPassword = StrUtil.Utf8.GetString(m_secPassword.ToUtf8());

            Program.Config.Apply(AceApplyFlags.Proxy);
        }
コード例 #3
0
        private void OnBtnOK(object sender, EventArgs e)
        {
            byte[] pbUtf8 = m_secWord.ToUtf8();
            m_psSelected = new ProtectedString(true, pbUtf8);
            Array.Clear(pbUtf8, 0, pbUtf8.Length);

            CleanUpEx();
        }
        private void OnPwGenOpen(object sender, EventArgs e)
        {
            PwGeneratorForm pgf             = new PwGeneratorForm();
            ProtectedString ps              = new ProtectedString(true, current_password_field.ToUtf8());
            bool            bAtLeastOneChar = (ps.Length > 0);
            PwProfile       opt             = PwProfile.DeriveFromPassword(ps);

            pgf.InitEx(bAtLeastOneChar ? opt : null, true, false);
            if (pgf.ShowDialog() == DialogResult.OK)
            {
                byte[]          pbEntropy = EntropyForm.CollectEntropyIfEnabled(pgf.SelectedProfile);
                ProtectedString psNew;
                PwGenerator.Generate(out psNew, pgf.SelectedProfile, pbEntropy,
                                     Program.PwGeneratorPool);

                current_password_field.SetPassword(psNew.ReadUtf8());
                current_password_confirm_field.SetPassword(psNew.ReadUtf8());
            }
        }
コード例 #5
0
        private CompositeKey CreateCompositeKey(string masterKey)
        {
            CompositeKey m_pKey = new CompositeKey();

            SecureEdit se = new SecureEdit(masterKey);

            byte[] pb = se.ToUtf8();
            m_pKey.AddUserKey(new KcpPassword(pb));
            Array.Clear(pb, 0, pb.Length);

            return(m_pKey);
        }
コード例 #6
0
        private void keyPromtForm_onConfirmClick(object sender, EventArgs e)
        {
            if (!_keyPromtForm_usePw.Checked)
            {
                return;
            }

            // use the password from the input field as challange for the Yubikey
            string challenge = Encoding.UTF8.GetString(_keyPromtForm_secureEdit.ToUtf8());
            string response;

            if (yubiChallengeResponse(challenge, out response))
            {
                string password = deriveMasterPassword(challenge, response);
                _keyPromtForm_secureEdit.SetPassword(Encoding.UTF8.GetBytes(password));
            }
        }
コード例 #7
0
 private void OnBtnOK(object sender, EventArgs e)
 {
     byte[] pbUtf8 = m_secWord.ToUtf8();
     m_psSelected = new ProtectedString(true, pbUtf8);
     MemUtil.ZeroByteArray(pbUtf8);
 }
コード例 #8
0
        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);
        }
コード例 #9
0
        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 void save_child_vals()
 {
     foreach (KeyValuePair <EntryTemplate, Control> pair in et_to_control)
     {
         if (pair.Value == null)
         {
             continue;
         }
         EntryTemplate   t = pair.Key;
         ProtectedString str;
         if (t.type == "Date" || t.type == "Time" || t.type == "Date Time")
         {
             DateTimePicker picker = (DateTimePicker)pair.Value;
             if (t.fieldName == "@exp_date")
             {
                 find_expires_control(form);
                 Debug.Assert(expires_control != null && expires_cbx_control != null);
                 expires_cbx_control.Checked = picker.Checked;
                 expires_control.Value       = picker.Value;
                 continue;
             }
             str = new ProtectedString(false, picker.Value.ToString());
         }
         else if (t.type == "Checkbox")
         {
             CheckBox checkbox = (CheckBox)pair.Value;
             str = new ProtectedString(false, checkbox.Checked.ToString());
         }
         else if (t.type == "Inline" || t.type == "Inline URL")
         {
             TextBox box = (TextBox)pair.Value;
             str = new ProtectedString(false, box.Text == null ? "" : box.Text.Replace("\r", ""));
         }
         else if (t.type == "Listbox")
         {
             ComboBox combobox = (ComboBox)pair.Value;
             str = new ProtectedString(false, combobox.SelectedItem == null ? "" : combobox.SelectedItem.ToString());
         }
         else if (t.type == "Protected Inline")
         {
             SecureEdit sedit = et_to_secure_edit[t];
             str = new ProtectedString(true, sedit.ToUtf8());
         }
         else
         {
             continue;
         }
         str = str.WithProtection(t.type.StartsWith("Protected"));
         if (t.fieldName == "@confirm")
         {
             //form.m_secRepeat.SetProtectedString(str, form.EntryRef, "Viewing/Editing Entry");
             continue;
         }
         if (t.fieldName == "@override")
         {
             find_override_url_control(form);
             Debug.Assert(new_override_url_control != null || override_url_control != null);
             if (new_override_url_control != null)
             {
                 new_override_url_control.Text = str.ReadString();
             }
             else
             {
                 override_url_control.Text = str.ReadString();
             }
             continue;
         }
         form.EntryStrings.Set(t.fieldName, str);
         //if (t.fieldName == PwDefs.PasswordField && current_password_confirm_field == null)
         //form.m_secRepeat.SetProtectedString(str, form.EntryRef, "Viewing/Editing Entry");
     }
 }
コード例 #11
0
        private void OnBtnOK(object sender, EventArgs e)
        {
            string strUrl = m_tbUrl.Text;

            if (strUrl.IndexOf("://") < 0)
            {
                // m_ttInvalidUrl.Show(KPRes.InvalidUrl, m_tbUrl);
                MessageService.ShowWarning(strUrl, KPRes.InvalidUrl);
                this.DialogResult = DialogResult.None;
                return;
            }

            m_ioc.Path     = strUrl;
            m_ioc.UserName = m_tbUserName.Text;
            m_ioc.Password = StrUtil.Utf8.GetString(m_secPassword.ToUtf8());

            if (m_cmbCredSaveMode.SelectedIndex == 1)
            {
                m_ioc.CredSaveMode = IOCredSaveMode.UserNameOnly;
            }
            else if (m_cmbCredSaveMode.SelectedIndex == 2)
            {
                m_ioc.CredSaveMode = IOCredSaveMode.SaveCred;
            }
            else
            {
                m_ioc.CredSaveMode = IOCredSaveMode.NoSave;
            }

            IocProperties p = m_ioc.Properties;

            foreach (KeyValuePair <IocPropertyInfo, Control> kvp in m_lProps)
            {
                IocPropertyInfo pi      = kvp.Key;
                string          strName = pi.Name;
                Type            t       = pi.Type;
                Control         c       = kvp.Value;

                try
                {
                    if (t == typeof(string))
                    {
                        TextBox tb = (c as TextBox);
                        if (tb != null)
                        {
                            p.Set(strName, tb.Text.Trim());
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                    }
                    else if (t == typeof(bool))
                    {
                        ComboBox cmb = (c as ComboBox);
                        if (cmb != null)
                        {
                            int iSel = cmb.SelectedIndex;
                            if (iSel == 0)
                            {
                                p.SetBool(strName, null);
                            }
                            else
                            {
                                p.SetBool(strName, (iSel == 1));
                            }
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                    }
                    else if (t == typeof(long))
                    {
                        TextBox tb = (c as TextBox);
                        if (tb != null)
                        {
                            string str = tb.Text.Trim();
                            if (str.Length == 0)
                            {
                                p.SetLong(strName, null);
                            }
                            else
                            {
                                // Validate and store number
                                long l = long.Parse(str, NumberFormatInfo.InvariantInfo);
                                p.SetLong(strName, l);
                            }
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
                catch (Exception ex)
                {
                    string strMsg = KPRes.Field + @" '" + pi.DisplayName +
                                    @"':" + MessageService.NewLine + ex.Message;
                    // if(!VistaTaskDialog.ShowMessageBox(strMsg, KPRes.ValidationFailed,
                    //	PwDefs.ShortProductName, VtdIcon.Warning, this))
                    MessageService.ShowWarning(strMsg);

                    this.DialogResult = DialogResult.None;
                    return;
                }
            }

            if (m_bTestConnection && !m_bSave)
            {
                if (!TestConnectionEx())
                {
                    this.DialogResult = DialogResult.None;
                }
            }
        }
コード例 #12
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);
        }
コード例 #13
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);
        }