Beispiel #1
0
        public bool ContentsEqualTo(SecureEdit secOther)
        {
            Debug.Assert(secOther != null); if (secOther == null)
            {
                return(false);
            }

            byte[] pbThis  = this.ToUtf8();
            byte[] pbOther = secOther.ToUtf8();

            bool bEqual = true;

            if (pbThis.Length != pbOther.Length)
            {
                bEqual = false;
            }
            else
            {
                for (int i = 0; i < pbThis.Length; ++i)
                {
                    if (pbThis[i] != pbOther[i])
                    {
                        bEqual = false;
                        break;
                    }
                }
            }

            Array.Clear(pbThis, 0, pbThis.Length);
            Array.Clear(pbOther, 0, pbOther.Length);
            return(bEqual);
        }
Beispiel #2
0
        public bool ContentsEqualTo(SecureEdit secOther)
        {
            Debug.Assert(secOther != null); if (secOther == null)
            {
                return(false);
            }

            byte[] pbThis  = ToUtf8();
            byte[] pbOther = secOther.ToUtf8();

            bool bEqual = MemUtil.ArraysEqual(pbThis, pbOther);

            MemUtil.ZeroByteArray(pbThis);
            MemUtil.ZeroByteArray(pbOther);
            return(bEqual);
        }
        private void UpdateUI()
        {
            if ((m_uBlockUIUpdate > 0) || m_bInitializing)
            {
                return;
            }
            ++m_uBlockUIUpdate;

            ulong uFlags = 0;

            if (m_fParent is KeyCreationForm)
            {
                uFlags = Program.Config.UI.KeyCreationFlags;
            }

            byte[] pbUtf8 = m_secPassword.ToUtf8();
            string str    = StrUtil.Utf8.GetString(pbUtf8);

#if DEBUG
            byte[] pbTest = StrUtil.Utf8.GetBytes(str);
            Debug.Assert(MemUtil.ArraysEqual(pbUtf8, pbTest));
#endif

            m_tbPassword.Enabled = m_bEnabled;
            m_cbHide.Enabled     = (m_bEnabled && ((uFlags &
                                                    (ulong)AceKeyUIFlags.DisableHidePassword) == 0));

            if ((uFlags & (ulong)AceKeyUIFlags.CheckHidePassword) != 0)
            {
                ++m_uPrgmCheck;
                m_cbHide.Checked = true;
                --m_uPrgmCheck;
            }
            if ((uFlags & (ulong)AceKeyUIFlags.UncheckHidePassword) != 0)
            {
                ++m_uPrgmCheck;
                m_cbHide.Checked = false;
                --m_uPrgmCheck;
            }

            bool bAutoRepeat = this.AutoRepeat;
            if (bAutoRepeat && (m_secRepeat.TextLength > 0))
            {
                m_secRepeat.SetPassword(MemUtil.EmptyByteArray);
            }

            byte[] pbRepeat = m_secRepeat.ToUtf8();
            if (!MemUtil.ArraysEqual(pbUtf8, pbRepeat) && !bAutoRepeat)
            {
                m_tbRepeat.BackColor = AppDefs.ColorEditError;
            }
            else
            {
                m_tbRepeat.ResetBackColor();
            }

            bool bRepeatEnable = (m_bEnabled && !bAutoRepeat);
            m_lblRepeat.Enabled = bRepeatEnable;
            m_tbRepeat.Enabled  = bRepeatEnable;

            bool bQuality = m_bEnabled;
            if (m_bSprVar && bQuality)
            {
                if (SprEngine.MightChange(str))                // Perf. opt.
                {
                    // {S:...} and {REF:...} may reference the entry that
                    // is currently being edited and SprEngine will not see
                    // the current data entered in the dialog; thus we
                    // disable quality estimation for all strings containing
                    // one of these placeholders
                    if ((str.IndexOf(@"{S:", StrUtil.CaseIgnoreCmp) >= 0) ||
                        (str.IndexOf(@"{REF:", StrUtil.CaseIgnoreCmp) >= 0))
                    {
                        bQuality = false;
                    }
                    else
                    {
                        SprContext ctx = new SprContext(m_ctxEntry, m_ctxDatabase,
                                                        SprCompileFlags.NonActive, false, false);
                        string strCmp = SprEngine.Compile(str, ctx);
                        if (strCmp != str)
                        {
                            bQuality = false;
                        }
                    }
                }
#if DEBUG
                else
                {
                    SprContext ctx = new SprContext(m_ctxEntry, m_ctxDatabase,
                                                    SprCompileFlags.NonActive, false, false);
                    string strCmp = SprEngine.Compile(str, ctx);
                    Debug.Assert(strCmp == str);
                }
#endif
            }

            m_lblQualityPrompt.Enabled = bQuality;
            m_pbQuality.Enabled        = bQuality;
            m_lblQualityInfo.Enabled   = bQuality;

            if ((Program.Config.UI.UIFlags & (ulong)AceUIFlags.HidePwQuality) != 0)
            {
                m_lblQualityPrompt.Visible = false;
                m_pbQuality.Visible        = false;
                m_lblQualityInfo.Visible   = false;
            }
            else if (bQuality || !m_bSprVar)
            {
                UpdateQualityInfo(str);
            }
            else
            {
                UqiShowQuality(0, 0);
            }

            // MemUtil.ZeroByteArray(pbUtf8);
            // MemUtil.ZeroByteArray(pbRepeat);
            --m_uBlockUIUpdate;
        }
        private void UpdateUI()
        {
            if ((m_uBlockUIUpdate > 0) || m_bInitializing)
            {
                return;
            }
            ++m_uBlockUIUpdate;

            ulong uFlags = 0;

            if (m_fParent is KeyCreationForm)
            {
                uFlags = Program.Config.UI.KeyCreationFlags;
            }

            byte[] pbUtf8 = m_secPassword.ToUtf8();

            m_tbPassword.Enabled = m_bEnabled;
            m_cbHide.Enabled     = (m_bEnabled && ((uFlags &
                                                    (ulong)AceKeyUIFlags.DisableHidePassword) == 0));

            if ((uFlags & (ulong)AceKeyUIFlags.CheckHidePassword) != 0)
            {
                m_bPrgmCheck     = true;
                m_cbHide.Checked = true;
                m_bPrgmCheck     = false;
            }
            if ((uFlags & (ulong)AceKeyUIFlags.UncheckHidePassword) != 0)
            {
                m_bPrgmCheck     = true;
                m_cbHide.Checked = false;
                m_bPrgmCheck     = false;
            }

            bool bAutoRepeat = this.AutoRepeat;

            if (bAutoRepeat && (m_secRepeat.TextLength > 0))
            {
                m_secRepeat.SetPassword(new byte[0]);
            }

            byte[] pbRepeat = m_secRepeat.ToUtf8();
            if (!MemUtil.ArraysEqual(pbUtf8, pbRepeat) && !bAutoRepeat)
            {
                m_tbRepeat.BackColor = AppDefs.ColorEditError;
            }
            else
            {
                m_tbRepeat.ResetBackColor();
            }

            bool bRepeatEnable = (m_bEnabled && !bAutoRepeat);

            m_lblRepeat.Enabled = bRepeatEnable;
            m_tbRepeat.Enabled  = bRepeatEnable;

            m_lblQualityPrompt.Enabled = m_bEnabled;
            m_pbQuality.Enabled        = m_bEnabled;
            m_lblQualityBits.Enabled   = m_bEnabled;

            uint uBits = QualityEstimation.EstimatePasswordBits(pbUtf8);

            m_lblQualityBits.Text = uBits.ToString() + " " + KPRes.Bits;
            int iPos = (int)((100 * uBits) / (256 / 2));

            if (iPos < 0)
            {
                iPos = 0;
            }
            else if (iPos > 100)
            {
                iPos = 100;
            }
            m_pbQuality.Value = iPos;

            MemUtil.ZeroByteArray(pbUtf8);
            MemUtil.ZeroByteArray(pbRepeat);
            --m_uBlockUIUpdate;
        }
Beispiel #5
0
        private void UpdateUI()
        {
            if ((m_uBlockUIUpdate > 0) || m_bInitializing)
            {
                return;
            }
            ++m_uBlockUIUpdate;

            ulong uFlags = 0;

            if (m_fParent is KeyCreationForm)
            {
                uFlags = Program.Config.UI.KeyCreationFlags;
            }

            byte[] pbUtf8 = m_secPassword.ToUtf8();

            m_tbPassword.Enabled = m_bEnabled;
            m_cbHide.Enabled     = (m_bEnabled && ((uFlags &
                                                    (ulong)AceKeyUIFlags.DisableHidePassword) == 0));

            if ((uFlags & (ulong)AceKeyUIFlags.CheckHidePassword) != 0)
            {
                ++m_uPrgmCheck;
                m_cbHide.Checked = true;
                --m_uPrgmCheck;
            }
            if ((uFlags & (ulong)AceKeyUIFlags.UncheckHidePassword) != 0)
            {
                ++m_uPrgmCheck;
                m_cbHide.Checked = false;
                --m_uPrgmCheck;
            }

            bool bAutoRepeat = this.AutoRepeat;

            if (bAutoRepeat && (m_secRepeat.TextLength > 0))
            {
                m_secRepeat.SetPassword(new byte[0]);
            }

            byte[] pbRepeat = m_secRepeat.ToUtf8();
            if (!MemUtil.ArraysEqual(pbUtf8, pbRepeat) && !bAutoRepeat)
            {
                m_tbRepeat.BackColor = AppDefs.ColorEditError;
            }
            else
            {
                m_tbRepeat.ResetBackColor();
            }

            bool bRepeatEnable = (m_bEnabled && !bAutoRepeat);

            m_lblRepeat.Enabled = bRepeatEnable;
            m_tbRepeat.Enabled  = bRepeatEnable;

            m_lblQualityPrompt.Enabled = m_bEnabled;
            m_pbQuality.Enabled        = m_bEnabled;
            m_lblQualityBits.Enabled   = m_bEnabled;

            UpdateQualityInfo(pbUtf8);

            // MemUtil.ZeroByteArray(pbUtf8);
            // MemUtil.ZeroByteArray(pbRepeat);
            --m_uBlockUIUpdate;
        }
Beispiel #6
0
        public bool ContentsEqualTo(SecureEdit secOther)
        {
            Debug.Assert(secOther != null); if(secOther == null) return false;

            byte[] pbThis = ToUtf8();
            byte[] pbOther = secOther.ToUtf8();

            bool bEqual = MemUtil.ArraysEqual(pbThis, pbOther);

            MemUtil.ZeroByteArray(pbThis);
            MemUtil.ZeroByteArray(pbOther);
            return bEqual;
        }
Beispiel #7
0
        public bool ContentsEqualTo(SecureEdit secOther)
        {
            Debug.Assert(secOther != null); if(secOther == null) return false;

            byte[] pbThis = this.ToUtf8();
            byte[] pbOther = secOther.ToUtf8();

            bool bEqual = true;

            if(pbThis.Length != pbOther.Length) bEqual = false;
            else
            {
                for(int i = 0; i < pbThis.Length; ++i)
                {
                    if(pbThis[i] != pbOther[i])
                    {
                        bEqual = false;
                        break;
                    }
                }
            }

            Array.Clear(pbThis, 0, pbThis.Length);
            Array.Clear(pbOther, 0, pbOther.Length);
            return bEqual;
        }
        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;
        }