Exemple #1
0
        public async void CheckAll()
        {
            bulkCheck = true;

            var progressDisplay = new ProgressDisplay();

            progressDisplay.Show();

            var allEntries = new PwObjectList <PwEntry>();

            Host.Database.RootGroup.SearchEntries(SearchParameters.None, allEntries);

            var entries = allEntries.Select(x =>
                                            new { password = x, hash = GetPasswordHash(x) });
            int index = 0;

            foreach (var entry in entries)
            {
                await Task.Run(() => PasswordCheckWorker(entry.password, entry.hash));;
                TouchEntry(entry.password);

                progressDisplay.progressBar.Value = (index++) * 100 / allEntries.Count();

                if (progressDisplay.UserTerminated)
                {
                    progressDisplay.Close();
                    break;
                }
            }

            UpdateUI();

            progressDisplay.Close();
        }
        private void populateExpiringEntries(PwObjectList <PwEntry> pwObjectList)
        {
            if (pwObjectList.Count() > 0)
            {
                foreach (PwEntry pe in pwObjectList)
                {
                    if (pe.Strings.Exists(PasswordChangeReminderExt._EntryStringKey))
                    {
                        PwListItem pli       = new PwListItem(pe);
                        int        iRemindIn = Convert.ToInt32(pe.Strings.Get(PasswordChangeReminderExt._EntryStringKey).ReadString().ToString());
                        int        iPwAge    = Tools.calculateAge(pe);
                        int        iChangeIn = iRemindIn - iPwAge;

                        ListViewItem lvi = lvExpiringPasswords.Items.Add(pe.Strings.ReadSafe(PwDefs.TitleField));
                        lvi.UseItemStyleForSubItems = false;

                        if (iChangeIn > m_config.pcrPasswordsFormTentativeState)
                        {
                            lvi.SubItems.Add(iChangeIn + " " + Properties.strings.pcr_days).BackColor = m_config.pcrPasswordsFormGreatColor;
                            lvi.Group     = lvExpiringPasswords.Groups[1];
                            lvi.BackColor = m_config.pcrPasswordsFormGreatColor;
                        }
                        else if (iChangeIn > m_config.pcrPasswordsFormCriticalState)
                        {
                            lvi.SubItems.Add(iChangeIn + " " + Properties.strings.pcr_days).BackColor = m_config.pcrPasswordsFormTentativeColor;
                            lvi.Group     = lvExpiringPasswords.Groups[1];
                            lvi.BackColor = m_config.pcrPasswordsFormTentativeColor;
                            lvExpiringPasswords.ShowGroups = true;
                        }
                        else
                        {
                            lvi.SubItems.Add(Properties.strings.pcr_today + " (" + iChangeIn + Properties.strings.pcr_days + ")").BackColor = m_config.pcrPasswordsFormCriticalColor;
                            lvi.Group     = lvExpiringPasswords.Groups[0];
                            lvi.BackColor = m_config.pcrPasswordsFormCriticalColor;
                            lvExpiringPasswords.ShowGroups = true;
                        }

                        lvi.SubItems.Add(iPwAge + " " + Properties.strings.pcr_days).BackColor    = Color.LightGray;
                        lvi.SubItems.Add(iRemindIn + " " + Properties.strings.pcr_days).BackColor = Color.LightGray;
                        lvi.ToolTipText = Properties.strings.pcr_created + ": " + pe.CreationTime + "\r\n" + Properties.strings.pcr_last_modified + ": " + pe.LastModificationTime;
                        lvi.Tag         = pli;


                        if (pe.CustomIconUuid.Equals(PwUuid.Zero))
                        {
                            lvi.ImageIndex = (int)pe.IconId;
                        }
                        else
                        {
                            lvi.ImageIndex = (int)PwIcon.Count + pdb.GetCustomIconIndex(pe.CustomIconUuid);
                        }
                    }
                }
            }
            else
            {
                lvExpiringPasswords.Items.Add(Properties.strings.pcr_nothing + "...");
            }
        }
Exemple #3
0
        internal void checkMaJ(IList <Entry> oldEntriesList)
        {
            if (!m_host.Database.IsOpen)
            {
                return;
            }

            PwObjectList <PwEntry> lEntries = m_host.Database.RootGroup.GetEntries(true);

            if (oldEntriesList.Count() == lEntries.Count())
            {
                //MessageBox.Show(oldEntriesList.Count().ToString() +" "+ lEntries.Count().ToString());
            }
            else if (oldEntriesList.Count() < lEntries.Count()) //ajout d'un element
            {
                int difFlag;
                MessageBox.Show(oldEntriesList.Count().ToString() + " ajout " + lEntries.Count().ToString());
                foreach (PwEntry el in lEntries)
                {
                    difFlag = 0;
                    foreach (Entry oel in oldEntriesList)
                    {
                        if (el.Uuid.ToHexString() != oel.Uuid && el.ParentGroup.Name != "Recycle Bin")
                        {
                            difFlag += 1;
                        }
                    }
                    if (difFlag > (lEntries.Count() - 2))
                    {
                        File.AppendAllText(pathForLogs, DateTime.Today.ToString("[ dd/MM/yyyy ") + "" + DateTime.Now.ToString("HH:mm:ss ] ") + el.Uuid.ToHexString() + " L'entrée a été ajoutée à la base de donnée : Title - " + el.Strings.ReadSafe(PwDefs.TitleField) + Environment.NewLine);

                        oldEntriesList.Add(new Entry {
                            Uuid = el.Uuid.ToHexString(), UserName = el.Strings.ReadSafe(PwDefs.UserNameField), Title = el.Strings.ReadSafe(PwDefs.TitleField), Password = el.Strings.ReadSafe(PwDefs.PasswordField)
                        });
                    }
                }
            }
            else if (oldEntriesList.Count() > lEntries.Count()) //suppression d'un element
            {
            }
        }
        private static string GetValueFromDB(ref KeePassLib.PwDatabase pdb, string searchString = "")
        {
            if (string.IsNullOrWhiteSpace(searchString))
            {
                throw new ArgumentException("Search String Cannot be blank");
            }

            SearchProcessor processor = new SearchProcessor();

            processor.Database = pdb;
            //byte[] keyBytes = System.Text.Encoding.Default.GetBytes(key); //new []{ System.Text.EncodingInfo}
            //Guid i = Guid.Parse(key);
            //var pwUuID = new PwUuid(i.ToByteArray());

            //SearchParameters sp = new SearchParameters();
            //sp.SearchInStringNames = true;
            //sp.SearchString = searchString;
            //PwObjectList<PwEntry> pwl = new PwObjectList<PwEntry>();
            //pdb.RootGroup.SearchEntries(sp, pwl);

            PwObjectList <PwEntry> pwl = processor.GetListOfEntriesBySearchByString(searchString);

            System.Diagnostics.Debug.WriteLine($"Entries Found: {pwl.Count()}");
            string k = string.Empty;

            foreach (var entry in pwl.CloneShallowToList())
            {
                foreach (var l in entry.Strings.ToList())
                {
                    if (l.Key == "Password")
                    {
                        k = l.Value.ReadString();
                    }
                }
            }
            return(k);
        }
Exemple #5
0
        private void runCheckButton_Click(object sender, EventArgs e)
        {
            var checkDups  = checkDuplicates.Checked;
            var checkLen   = checkLength.Checked;
            var lenToCheck = Convert.ToInt32(lengthToCheckInput.Value);
            var checkComp  = checkComplexity.Checked;
            var comp       = (PasswordScore)complexitySlider.Value;

            if (!checkDups && !checkLen && !checkComp)
            {
                MessageBox.Show("You must select at least one criteria to check.", "Error");
                return;
            }

            runCheckButton.Enabled     = false;
            checkDuplicates.Enabled    = false;
            checkLength.Enabled        = false;
            lengthToCheckInput.Enabled = false;
            checkComplexity.Enabled    = false;
            complexitySlider.Enabled   = false;

            try
            {
                this.statusLabel.Text = "Starting Check...";
                PwDatabase pwdb = m_host.Database;

                if (!pwdb.IsOpen)
                {
                    statusLabel.Text = "Please open database first...";
                    return;
                }

                PwObjectList <PwEntry> entries = pwdb.RootGroup.GetEntries(true);

                if (entries != null)
                {
                    statusLabel.Text = "Database opened, " + entries.UCount + " entries to check...";
                }
                else
                {
                    statusLabel.Text = "No entries in Database.";
                    return;
                }

                //Used to check for Duplicate Passwords
                Dictionary <string, List <string> > results = new Dictionary <string, List <string> >(entries.Count <PwEntry>());
                //Used to check password length
                List <string> shortPasses = new List <string>();
                //Used to check password complexity
                List <string> simplePasses = new List <string>();

                foreach (var entry in entries)
                {
                    string pass = entry.Strings.Get(PwDefs.PasswordField).ReadString();
                    if (pass.Equals(""))
                    {
                        continue;
                    }
                    if (checkDups)
                    {
                        if (results.ContainsKey(pass))
                        {
                            results[pass].Add(entry.Strings.Get(PwDefs.TitleField).ReadString());
                        }
                        else
                        {
                            List <string> list = new List <string>();
                            var           xx   = entry.Strings.Get(PwDefs.TitleField);
                            if (xx != null)
                            {
                                list.Add(xx.ReadString());
                            }
                            else
                            {
                                var urlxx = entry.Strings.Get(PwDefs.UrlField);
                                if (urlxx != null)
                                {
                                    list.Add(urlxx.ReadString());
                                }
                                else
                                {
                                    list.Add(entry.ToString());
                                }
                            }
                            results.Add(pass, list);
                        }
                    }
                    if (checkLen)
                    {
                        if (pass.Length < lenToCheck)
                        {
                            shortPasses.Add(entry.Strings.Get(PwDefs.TitleField).ReadString() + " (" + pass.Length + ")");
                        }
                    }

                    if (checkComp)
                    {
                        var tcomp = PasswordAdvisor.CheckStrength(pass);
                        if (tcomp < comp)
                        {
                            simplePasses.Add(entry.Strings.Get(PwDefs.TitleField).ReadString() + " (" + Enum.GetName(typeof(PasswordScore), tcomp) + ")");
                        }
                    }
                }

                checkResultsView.BeginUpdate();

                TreeNodeCollection nodes = checkResultsView.Nodes;

                checkResultsView.Nodes.Clear();

                if (checkDups)
                {
                    int dupPass = 1;
                    foreach (KeyValuePair <string, List <string> > result in results)
                    {
                        if (result.Value.Count > 1)
                        {
                            List <TreeNode> children = new List <TreeNode>();
                            foreach (var title in result.Value)
                            {
                                children.Add(new TreeNode(title));
                            }
                            TreeNode node = new TreeNode(string.Format("Duplicated Password [{0}] ({1})", result.Key, children.Count), children.ToArray());
                            nodes.Add(node);
                            dupPass++;
                        }
                    }
                }

                if (checkLen)
                {
                    if (shortPasses.Count > 0)
                    {
                        List <TreeNode> children = new List <TreeNode>();
                        foreach (var title in shortPasses)
                        {
                            children.Add(new TreeNode(title));
                        }
                        TreeNode node = new TreeNode("Short Passwords", children.ToArray());
                        nodes.Add(node);
                    }
                }

                if (checkComp)
                {
                    if (simplePasses.Count > 0)
                    {
                        List <TreeNode> children = new List <TreeNode>();
                        foreach (var title in simplePasses)
                        {
                            children.Add(new TreeNode(title));
                        }
                        TreeNode node = new TreeNode("Simple Passwords", children.ToArray());
                        nodes.Add(node);
                    }
                }

                checkResultsView.EndUpdate();

                statusLabel.Text = "Check complete.";
            }
            catch (NullReferenceException nre)
            {
                MessageBox.Show(string.Format("I tried to read a null value.\n{0}", nre.StackTrace));
                throw;
            }
            runCheckButton.Enabled     = true;
            checkDuplicates.Enabled    = true;
            checkLength.Enabled        = true;
            lengthToCheckInput.Enabled = true;
            checkComplexity.Enabled    = true;
            complexitySlider.Enabled   = true;
        }
Exemple #6
0
        public override void MigrateFromKeePassOTP(bool bRemove, out int EntriesOverall, out int EntriesMigrated)
        {
            EntriesOverall = EntriesMigrated = -1;
            if (!m_bInitialized)
            {
                return;
            }
            EntriesOverall = EntriesMigrated = 0;

            OTPDAO.OTPHandler_DB h = OTPDAO.GetOTPHandler(m_db);
            if ((h != null) && !h.EnsureOTPUsagePossible(null))
            {
                return;
            }

            PwObjectList <PwEntry> lEntries = m_db.RootGroup.GetEntries(true);

            if (lEntries.Count() == 0)
            {
                return;
            }

            OTPDAO.OTPHandler_Base handler = OTPDAO.GetOTPHandler(lEntries.GetAt(0));
            InitLogger("KeePassOTP -> KeeTrayTOTP", lEntries.Count());
            try
            {
                foreach (PwEntry pe in lEntries)
                {
                    IncreaseLogger();
                    KPOTP otp = OTPDAO.GetOTP(pe);
                    if (!otp.Valid)
                    {
                        continue;
                    }
                    EntriesOverall++;
                    if (otp.Encoding != KPOTPEncoding.BASE32)
                    {
                        PluginDebug.AddError("Migration of entry failed",
                                             "Uuid: " + pe.Uuid.ToHexString(),
                                             "Encoding not supported: " + otp.Encoding.ToString());
                        continue;
                    }
                    if (otp.Hash != KPOTPHash.SHA1)
                    {
                        PluginDebug.AddError("Migration of entry failed",
                                             "Uuid: " + pe.Uuid.ToHexString(),
                                             "Hash not supported: " + otp.Hash.ToString());
                        continue;
                    }
                    if (otp.Type != KPOTPType.TOTP)
                    {
                        PluginDebug.AddError("Migration of entry failed",
                                             "Uuid: " + pe.Uuid.ToHexString(),
                                             "Type not supported: " + otp.Type.ToString());
                        continue;
                    }
                    string settings = otp.TOTPTimestep.ToString() + ";" + otp.Length.ToString();
                    if (otp.TimeCorrectionUrlOwn)
                    {
                        settings += ";" + pe.Strings.ReadSafe(PwDefs.UrlField);
                    }
                    else if (!string.IsNullOrEmpty(otp.TimeCorrectionUrl))
                    {
                        settings += ";" + otp.TimeCorrectionUrl;
                    }
                    pe.Strings.Set("TOTP Seed", otp.OTPSeed);
                    pe.Strings.Set("TOTP Settings", new ProtectedString(false, settings));
                    EntriesMigrated++;
                    if (bRemove)
                    {
                        otp.OTPSeed = ProtectedString.EmptyEx;
                        try
                        {
                            handler.IgnoreBuffer = true;
                            OTPDAO.SaveOTP(otp, pe);
                        }
                        finally { handler.IgnoreBuffer = false; }
                    }
                }
            }
            finally { EndLogger(); }
            MigratePlaceholder(Config.Placeholder, OtherPluginPlaceholder, false);
        }
Exemple #7
0
        public override void MigrateFromKeePassOTP(bool bRemove, out int EntriesOverall, out int EntriesMigrated)
        {
            EntriesOverall = EntriesMigrated = -1;
            if (!m_bInitialized)
            {
                return;
            }
            EntriesOverall = EntriesMigrated = 0;

            OTPDAO.OTPHandler_DB h = OTPDAO.GetOTPHandler(m_db);
            if ((h != null) && !h.EnsureOTPUsagePossible(null))
            {
                return;
            }

            PwObjectList <PwEntry> lEntries = m_db.RootGroup.GetEntries(true);

            if (lEntries.Count() == 0)
            {
                return;
            }

            OTPDAO.OTPHandler_Base handler = OTPDAO.GetOTPHandler(lEntries.GetAt(0));
            InitLogger("KeePassOTP -> KeeOTP", lEntries.Count());
            try
            {
                foreach (PwEntry pe in lEntries)
                {
                    IncreaseLogger();
                    KPOTP otp = OTPDAO.GetOTP(pe);
                    if (!otp.Valid)
                    {
                        continue;
                    }
                    EntriesOverall++;
                    if (otp.Encoding != KPOTPEncoding.BASE32)
                    {
                        PluginDebug.AddError("Migration of entry failed",
                                             "Uuid: " + pe.Uuid.ToHexString(),
                                             "Encoding not supported: " + otp.Encoding.ToString());
                        continue;
                    }
                    if (otp.Hash != KPOTPHash.SHA1)
                    {
                        PluginDebug.AddError("Migration of entry failed",
                                             "Uuid: " + pe.Uuid.ToHexString(),
                                             "Hash not supported: " + otp.Hash.ToString());
                        continue;
                    }
                    if (otp.Type != KPOTPType.TOTP)
                    {
                        PluginDebug.AddError("Migration of entry failed",
                                             "Uuid: " + pe.Uuid.ToHexString(),
                                             "Type not supported: " + otp.Type.ToString());
                        continue;
                    }

                    string s = "key=" + otp.OTPSeed.ReadString();
                    if (otp.Length != 6)
                    {
                        s += "&size=" + otp.Length.ToString();
                    }
                    if (otp.Type == KPOTPType.HOTP)
                    {
                        s += "&type=hotp";
                        if (otp.HOTPCounter > 0)
                        {
                            s += "&counter=" + otp.HOTPCounter.ToString();
                        }
                    }
                    if ((otp.Type == KPOTPType.TOTP) && (otp.TOTPTimestep != 30))
                    {
                        s += "&step=" + otp.TOTPTimestep.ToString();
                    }
                    pe.Strings.Set("otp", new ProtectedString(true, s));
                    if (pe.Strings.Exists("otp"))
                    {
                        EntriesMigrated++;
                    }
                    if (bRemove)
                    {
                        otp.OTPSeed = ProtectedString.EmptyEx;
                        try
                        {
                            handler.IgnoreBuffer = true;
                            OTPDAO.SaveOTP(otp, pe);
                        }
                        finally { handler.IgnoreBuffer = false; }
                    }
                }
            }
            finally
            {
                EndLogger();
            }
            MigratePlaceholder(Config.Placeholder, OtherPluginPlaceholder, false);
        }
Exemple #8
0
        public override void MigrateFromKeePassOTP(bool bRemove, out int EntriesOverall, out int EntriesMigrated)
        {
            EntriesOverall = EntriesMigrated = -1;
            if (!m_bInitialized)
            {
                return;
            }
            EntriesOverall = EntriesMigrated = 0;

            OTPDAO.OTPHandler_DB h = OTPDAO.GetOTPHandler(m_db);
            if ((h != null) && !h.EnsureOTPUsagePossible(null))
            {
                return;
            }

            PwObjectList <PwEntry> lEntries = m_db.RootGroup.GetEntries(true);

            if (lEntries.Count() == 0)
            {
                return;
            }

            OTPDAO.OTPHandler_Base handler = OTPDAO.GetOTPHandler(lEntries.GetAt(0));
            InitLogger("KeePassOTP -> KeeTrayTOTP", lEntries.Count());
            try
            {
                foreach (PwEntry pe in lEntries)
                {
                    IncreaseLogger();
                    KPOTP otp = OTPDAO.GetOTP(pe);
                    if (!otp.Valid)
                    {
                        continue;
                    }
                    EntriesOverall++;
                    if (otp.Type != KPOTPType.HOTP && otp.Type != KPOTPType.TOTP)
                    {
                        PluginDebug.AddError("Migration of entry failed",
                                             "Uuid: " + pe.Uuid.ToHexString(),
                                             "Type not supported: " + otp.Type.ToString());
                        continue;
                    }

                    if (otp.Type == KPOTPType.TOTP)
                    {
                        if (Tools.KeePassVersion < m_vKeePass247)
                        {
                            PluginDebug.AddError("Migration of entry failed",
                                                 "Uuid: " + pe.Uuid.ToHexString(),
                                                 "Type not supported: " + otp.Type.ToString(),
                                                 "Minimum required KeePass version: " + m_vKeePass247.ToString());
                        }
                        foreach (var line in m_dTotpStrings)
                        {
                            if (line.Key == otp.Encoding)
                            {
                                pe.Strings.Set(line.Value, otp.OTPSeed);
                            }
                            else
                            {
                                pe.Strings.Remove(line.Value);
                            }
                        }

                        if (otp.TOTPTimestep == 30)
                        {
                            pe.Strings.Remove(TOTPPERIOD);
                        }
                        else
                        {
                            pe.Strings.Set(TOTPPERIOD, new ProtectedString(false, otp.TOTPTimestep.ToString()));
                        }

                        if (otp.Length == 6)
                        {
                            pe.Strings.Remove(TOTPLENGTH);
                        }
                        else
                        {
                            pe.Strings.Set(TOTPLENGTH, new ProtectedString(false, otp.Length.ToString()));
                        }

                        if (otp.Hash == KPOTPHash.SHA1)
                        {
                            pe.Strings.Remove(TOTPHASH);
                        }
                        else if (otp.Hash == KPOTPHash.SHA256)
                        {
                            pe.Strings.Set(TOTPHASH, new ProtectedString(false, "HMAC-SHA-256"));
                        }
                        else if (otp.Hash == KPOTPHash.SHA512)
                        {
                            pe.Strings.Set(TOTPHASH, new ProtectedString(false, "HMAC-SHA-512"));
                        }

                        bool bDummy;
                        MigratePlaceholder(Config.Placeholder, PLACEHOLDER_TOTP, pe, out bDummy);
                    }
                    else if (otp.Type == KPOTPType.HOTP)
                    {
                        if (otp.Length != 6)
                        {
                            PluginDebug.AddError("Migration of entry failed",
                                                 "Uuid: " + pe.Uuid.ToHexString(),
                                                 "Length not supported: " + otp.Length.ToString());
                            continue;
                        }
                        if (otp.Hash != KPOTPHash.SHA1)
                        {
                            PluginDebug.AddError("Migration of entry failed",
                                                 "Uuid: " + pe.Uuid.ToHexString(),
                                                 "Hash not supported: " + otp.Hash.ToString());
                            continue;
                        }

                        foreach (var line in m_dHotpStrings)
                        {
                            if (line.Key == otp.Encoding)
                            {
                                pe.Strings.Set(line.Value, otp.OTPSeed);
                            }
                            else
                            {
                                pe.Strings.Remove(line.Value);
                            }
                        }
                        pe.Strings.Set(HOTP_COUNTER, new ProtectedString(false, otp.HOTPCounter.ToString()));

                        bool bDummy;
                        MigratePlaceholder(Config.Placeholder, PLACEHOLDER_HOTP, pe, out bDummy);
                    }

                    EntriesMigrated++;
                    if (bRemove)
                    {
                        otp.OTPSeed = ProtectedString.EmptyEx;
                        try
                        {
                            handler.IgnoreBuffer = true;
                            OTPDAO.SaveOTP(otp, pe);
                        }
                        finally { handler.IgnoreBuffer = false; }
                    }
                }
            }
            finally { EndLogger(); }
            MigratePlaceholder(Config.Placeholder, PLACEHOLDER_TOTP);             //In case something is defined on group level (could be right, could be wrong, ...)
        }