예제 #1
0
        public string getDataByGroup(string value, KeePassLib.PwGroup kpGroup, string kpColumn2Search = "Title", string kpColumn2Return = "Password")
        {
            string returnValue = string.Empty;
            var    ioconninfo  = new KeePassLib.Serialization.IOConnectionInfo();

            if (!(string.IsNullOrEmpty(kpGroup.ToString())))
            {
                try
                {
                    KeePassLib.PwEntry pw = kpGroup.Entries.FirstOrDefault(i => i.Strings.ReadSafe(kpColumn2Search) == value);

                    if (pw != null)
                    {
                        returnValue = pw.Strings.ReadSafe(kpColumn2Return);
                    }
                    else
                    {
                        returnValue = string.Empty;
                    }

                    pw = null;
                }
                catch
                {
                    throw;
                }
            }

            return(returnValue);
        }
예제 #2
0
        public OtpInformation(OtpAuthData data, KeePassLib.PwEntry entry, IPluginHost host)
        {
            InitializeComponent();
            this.Shown += (sender, e) => FormWasShown();

            pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width,
                                                                           pictureBoxBanner.Height,
                                                                           KeePass.UI.BannerStyle.Default,
                                                                           Resources.lock_key.GetThumbnailImage(32, 32, null, IntPtr.Zero),
                                                                           "Configuration",
                                                                           "Set up the key for generating one time passwords");

            this.Icon = host.MainWindow.Icon;

            this.Data  = data;
            this.entry = entry;
            this.host  = host;

            if (this.Data != null && this.Data.KeeOtp1Mode)
            {
                buttonMigrate.Visible = true;
                pictureBoxMigrateQuestionmark.Visible = true;
                pictureBoxMigrateQuestionmark.Image   = SystemIcons.Question.ToBitmap();

                ToolTip toolTip = new ToolTip();
                toolTip.ToolTipTitle = "Why am I seeing this?";
                toolTip.IsBalloon    = true;
                toolTip.SetToolTip(buttonMigrate, "Since KeePass 2.47, TOTPs can generated by a built-in function.\nYou can use this button to easily migrate to the built-in function.\n\n(It is also recommended!)");
                toolTip.SetToolTip(pictureBoxMigrateQuestionmark, "Since KeePass 2.47, TOTPs can generated by a built-in function.\nYou can use this button to easily migrate to the built-in function.\n\n(It is also recommended!)");
            }
        }
예제 #3
0
        private static void OnLVEntriesClick(object sender, EventArgs e)
        {
            if (!Enabled)
            {
                return;
            }
            KeePassLib.PwEntry pe = GetEntryFromClick();
            if (pe == null)
            {
                return;
            }
            Timer t;

            if (m_CheckDoubleClick.TryGetValue(pe.Uuid, out t) && t != null)
            {
                t.Stop();
                t.Dispose();
                m_CheckDoubleClick.Remove(pe.Uuid);
            }
            t          = new Timer();
            t.Interval = SystemInformation.DoubleClickTime;
            t.Tick    += (o, e1) =>
            {
                AddOrRemove(pe);
                t.Dispose();
                m_CheckDoubleClick.Remove(pe.Uuid);
            };
            m_CheckDoubleClick[pe.Uuid] = t;
            t.Start();
        }
예제 #4
0
        public ShowOneTimePasswords(KeePassLib.PwEntry entry, IPluginHost host)
        {
            InitializeComponent();

            pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width,
                                                                           pictureBoxBanner.Height,
                                                                           KeePass.UI.BannerStyle.Default,
                                                                           Resources.clock_white,
                                                                           KeeOtp2Statics.ShowOtp,
                                                                           KeeOtp2Statics.ShowOtpSubline);

            this.Icon    = host.MainWindow.Icon;
            this.TopMost = host.MainWindow.TopMost;

            this.host  = host;
            this.entry = entry;

            groupboxTotp.Text           = KeeOtp2Statics.TOTP;
            linkLabelIncorrectNext.Text = KeeOtp2Statics.ShowOtpIncorrect;
            buttonShowQR.Text           = KeeOtp2Statics.ShowOtpShowQr + KeeOtp2Statics.InformationChar;
            buttonEdit.Text             = KeeOtp2Statics.Edit;
            buttonCopyTotp.Text         = KeeOtp2Statics.Copy;
            buttonClose.Text            = KeeOtp2Statics.Close;

            ToolTip toolTip = new ToolTip();

            toolTip.ToolTipTitle = KeeOtp2Statics.ShowOtp;
            toolTip.IsBalloon    = true;
            toolTip.SetToolTip(buttonShowQR, KeeOtp2Statics.ToolTipShowQrCode);
        }
예제 #5
0
        private static bool AddOrRemove(KeePassLib.PwEntry pe)
        {
            if (!Enabled)
            {
                return(false);
            }
            int        idx         = IndexOf(pe);
            int        iPwColIndex = GetPwColumnIndex();
            SingleItem si          = m_lItems.Find(x => x.Entry.Uuid.Equals(pe.Uuid));
            bool       bAdd        = si == null;

            if (bAdd)
            {
                si = new SingleItem(pe);
                m_lItems.Add(si);
            }
            else
            {
                m_lItems.Remove(si);
            }
            if (idx >= 0 && iPwColIndex >= 0)
            {
                if (bAdd)
                {
                    EntriesListView.Items[idx].SubItems[iPwColIndex].Text = pe.Strings.ReadSafe(KeePassLib.PwDefs.PasswordField);
                }
                else
                {
                    EntriesListView.Items[idx].SubItems[iPwColIndex].Text = KeePassLib.PwDefs.HiddenPassword;
                }
            }
            return(true);
        }
        public void GetCellData_WithAnInvalidColumn_ShouldReturnEmptyString()
        {
            var column  = new TrayTOTP_ColumnProvider(_plugin);
            var pwEntry = new KeePassLib.PwEntry(true, true);

            pwEntry.Strings.Set(_plugin.Settings.TOTPSeedStringName, new ProtectedString(false, ValidSeed));
            pwEntry.Strings.Set(_plugin.Settings.TOTPSettingsStringName, new ProtectedString(false, ValidSettings));

            var actual = column.GetCellData("InvalidColumnName", pwEntry);

            actual.Should().BeEmpty();
        }
예제 #7
0
        private ExportItem ConvertToExportItem(KeePassLib.PwEntry entry)
        {
            string   urlValue = entry.Strings.ReadSafe(KeePassLib.PwDefs.UrlField);
            string   lastExportTimestampStr = entry.Strings.ReadSafe(LastExportTimeKeyName);
            DateTime?lastExportTimestamp    = null;

            if (!string.IsNullOrEmpty(lastExportTimestampStr))
            {
                lastExportTimestamp = DateTime.Parse(lastExportTimestampStr);
                lastExportTimestamp = new DateTime(lastExportTimestamp.Value.Ticks, DateTimeKind.Utc);
            }
            return(new ExportItem(entry.Uuid.ToHexString(), new Uri(urlValue), lastExportTimestamp));
        }
        public void GetCellDataCode_WithValidSeedAndSettings_ShouldReturnA6DigitCodeWithDuration(bool showTimer, string regex)
        {
            _plugin.Settings.TOTPColumnTimerVisible = showTimer;

            var column  = new TrayTOTP_ColumnProvider(_plugin);
            var pwEntry = new KeePassLib.PwEntry(true, true);

            pwEntry.Strings.Set(_plugin.Settings.TOTPSeedStringName, new ProtectedString(false, ValidSeed));
            pwEntry.Strings.Set(_plugin.Settings.TOTPSettingsStringName, new ProtectedString(false, ValidSettings));

            var actual = column.GetCellData("TOTP", pwEntry);

            actual.Should().MatchRegex(regex);
        }
예제 #9
0
 private static int IndexOf(KeePassLib.PwEntry pe)
 {
     if (!Enabled)
     {
         return(-1);
     }
     foreach (ListViewItem lvi in EntriesListView.Items)
     {
         if (((PwListItem)lvi.Tag).Entry.Uuid.Equals(pe.Uuid))
         {
             return(lvi.Index);
         }
     }
     return(-1);
 }
예제 #10
0
        public ShowOneTimePasswords(KeePassLib.PwEntry entry, IPluginHost host)
        {
            this.host  = host;
            this.entry = entry;
            InitializeComponent();
            this.timerUpdateTotp.Tick += (sender, e) => UpdateDisplay();

            pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width,
                                                                           pictureBoxBanner.Height,
                                                                           KeePass.UI.BannerStyle.Default,
                                                                           Resources.clock,
                                                                           "Timed Passwords",
                                                                           "Enter this code in the verification system.");

            this.Icon = host.MainWindow.Icon;
        }
예제 #11
0
 public static string GetDBName(KeePassLib.PwEntry pe)
 {
     if (pe == null)
     {
         return(string.Empty);
     }
     KeePassLib.PwDatabase db = KeePass.Program.MainForm.DocumentManager.FindContainerOf(pe);
     if (db == null)
     {
         return(string.Empty);
     }
     if (!string.IsNullOrEmpty(db.Name))
     {
         return(db.Name);
     }
     return(KeePassLib.Utility.UrlUtil.GetFileName(db.IOConnectionInfo.Path));
 }
        public void GetCellDataCode_ShouldReturnExpectedValues(string seed, string settings, string expected)
        {
            var column  = new TrayTOTP_ColumnProvider(_plugin);
            var pwEntry = new KeePassLib.PwEntry(true, true);

            if (seed != null)
            {
                pwEntry.Strings.Set(_plugin.Settings.TOTPSeedStringName, new ProtectedString(false, seed));
            }
            if (settings != null)
            {
                pwEntry.Strings.Set(_plugin.Settings.TOTPSettingsStringName, new ProtectedString(false, settings));
            }

            var actual = column.GetCellData("TOTP", pwEntry);

            actual.Should().Be(expected);
        }
예제 #13
0
        private static void OnLVEntriesDoubleClick(object sender, EventArgs e)
        {
            if (!Enabled)
            {
                return;
            }
            KeePassLib.PwEntry pe = GetEntryFromClick();
            if (pe == null)
            {
                return;
            }
            Timer t;

            if (m_CheckDoubleClick.TryGetValue(pe.Uuid, out t) && t != null)
            {
                t.Stop();
                t.Dispose();
                m_CheckDoubleClick.Remove(pe.Uuid);
            }
            Remove(pe);
        }
예제 #14
0
        private static bool Remove(KeePassLib.PwEntry pe)
        {
            if (!Enabled)
            {
                return(false);
            }
            int        idx         = IndexOf(pe);
            int        iPwColIndex = GetPwColumnIndex();
            SingleItem si          = m_lItems.Find(x => x.Entry.Uuid.Equals(pe.Uuid));

            if (si == null)
            {
                return(true);
            }
            m_lItems.Remove(si);
            if (idx >= 0 && iPwColIndex >= 0)
            {
                EntriesListView.Items[idx].SubItems[iPwColIndex].Text = KeePassLib.PwDefs.HiddenPassword;
            }
            return(true);
        }
예제 #15
0
        public static bool PasswordShown(ListViewItem lvi)
        {
            if (!Enabled)
            {
                return(false);
            }
            if (lvi == null)
            {
                return(false);
            }
            if (!(lvi.Tag is PwListItem))
            {
                return(false);
            }
            KeePassLib.PwEntry pe = (lvi.Tag as PwListItem).Entry;

            if (pe == null)
            {
                return(false);
            }
            SingleItem si = m_lItems.Find(x => x.Entry.Uuid.Equals(pe.Uuid));

            return(si != null && !si.Hidden);
        }
예제 #16
0
        public OtpInformation(OtpAuthData data, KeePassLib.PwEntry entry, IPluginHost host)
        {
            InitializeComponent();

            pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width,
                                                                           pictureBoxBanner.Height,
                                                                           KeePass.UI.BannerStyle.Default,
                                                                           Resources.lock_white,
                                                                           KeeOtp2Statics.OtpInformation,
                                                                           KeeOtp2Statics.OtpInformationSubline);

            this.Icon = host.MainWindow.Icon;

            this.data  = data;
            this.entry = entry;
            this.host  = host;

            this.TopMost = host.MainWindow.TopMost;

            groupBoxKey.Text            = KeeOtp2Statics.OtpInformationKeyUri;
            linkLabelLoadUriScanQR.Text = KeeOtp2Statics.OtpInformationScanQr;
            checkBoxCustomSettings.Text = KeeOtp2Statics.OtpInformationCustomSettings + KeeOtp2Statics.InformationChar;
            linkLabelMigrate.Text       = KeeOtp2Statics.OtpInformationMigrate + KeeOtp2Statics.InformationChar;
            groupBoxPeriodCounter.Text  = KeeOtp2Statics.Period;
            labelPeriodCounter.Text     = KeeOtp2Statics.OtpInformationPeriodSeconds;
            groupboxInfo.Text           = KeeOtp2Statics.OtpInformationKeeOtp1String;
            checkboxOldKeeOtp.Text      = KeeOtp2Statics.OtpInformationKeeOtp1SaveMode + KeeOtp2Statics.InformationChar;
            groupboxGeneral.Text        = KeeOtp2Statics.General;
            labelLength.Text            = KeeOtp2Statics.Length;
            labelType.Text             = KeeOtp2Statics.Type;
            groupboxEncoding.Text      = KeeOtp2Statics.Encoding;
            radioButtonBase32.Text     = KeeOtp2Statics.Base32;
            radioButtonBase64.Text     = KeeOtp2Statics.Base64;
            radioButtonHex.Text        = KeeOtp2Statics.Hex;
            radioButtonUtf8.Text       = KeeOtp2Statics.Utf8;
            groupboxHashAlgorithm.Text = KeeOtp2Statics.HashAlgorithm;
            radioButtonSha1.Text       = KeeOtp2Statics.Sha1;
            radioButtonSha256.Text     = KeeOtp2Statics.Sha256;
            radioButtonSha512.Text     = KeeOtp2Statics.Sha512;
            labelStatus.Text           = KeeOtp2Statics.HoverInformation;
            buttonOk.Text     = KeeOtp2Statics.OK;
            buttonCancel.Text = KeeOtp2Statics.Cancel;

            ToolTip toolTip = new ToolTip();

            toolTip.ToolTipTitle = KeeOtp2Statics.OtpInformation;
            toolTip.IsBalloon    = true;
            toolTip.SetToolTip(checkBoxCustomSettings, KeeOtp2Statics.ToolTipOtpInformationUseCustomSettings);

            toolTip.ToolTipTitle = KeeOtp2Statics.OtpInformation;
            toolTip.IsBalloon    = true;
            toolTip.SetToolTip(checkboxOldKeeOtp, KeeOtp2Statics.ToolTipOtpInformationUseOldKeeOtpSaveMode);

            comboBoxLengthIndexValue = new Dictionary <int, int>();
            for (int i = 5; i <= 10; i++)
            {
                if (i == 6 || i == 8)
                {
                    comboBoxLengthIndexValue[comboBoxLength.Items.Add(String.Format("{0} ({1})", i, KeeOtp2Statics.CommonAbbreviation.ToLower() + KeeOtp2Statics.InformationChar))] = i;
                }
                else
                {
                    comboBoxLengthIndexValue[comboBoxLength.Items.Add(i.ToString())] = i;
                }
            }
            comboBoxTypeIndexValue = new Dictionary <int, OtpType>();
            foreach (OtpType type in Enum.GetValues(typeof(OtpType)))
            {
                comboBoxTypeIndexValue[comboBoxType.Items.Add(type.ToString())] = type;
            }
        }
예제 #17
0
 public static void OpenUrl(string sURL, KeePassLib.PwEntry pe)
 {
     //Use KeePass built-in logic instead of System.Diagnostics.Process.Start
     //For details see: https://sourceforge.net/p/keepass/discussion/329221/thread/f399b6d74b/#4801
     KeePass.Util.WinUtil.OpenUrl(sURL, pe, true);
 }
예제 #18
0
 public EntryHash(KeePassLib.PwEntry entry)
 {
     Entry = entry;
     CalculateHashString();
 }
예제 #19
0
        private void OtpInformation_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }
            try
            {
                int textBoxKeyLength = this.textBoxKey.Text.Length;
                if (string.IsNullOrEmpty(this.textBoxKey.Text))
                {
                    MessageBox.Show("A key must be set", "Missing key", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    e.Cancel = true;
                    return;
                }

                if (radioButtonBase32.Checked && !Regex.IsMatch(this.textBoxKey.Text, @"^[A-Z2-7=]+$"))
                {
                    MessageBox.Show("The key includes illegal characters.\n\nAllowed characters:\nABCDEFGHIJKLMNOPQRSTUVWXYZ234567=\n\nRegex:\n^[A-Z2-7=]+$", "Illegal character found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    e.Cancel = true;
                    return;
                }
                else if (radioButtonBase64.Checked && !Regex.IsMatch(this.textBoxKey.Text, @"^[a-zA-Z0-9\+/]*={0,2}$"))
                {
                    MessageBox.Show("The key includes illegal characters.\n\nAllowed characters:\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789+/=\n\nRegex:\n^[a-zA-Z0-9\\+/]*={0,2}$", "Illegal character found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    e.Cancel = true;
                    return;
                }
                else if (radioButtonHex.Checked && !Regex.IsMatch(this.textBoxKey.Text, @"^[a-fA-F0-9]+$"))
                {
                    MessageBox.Show("The key includes illegal characters.\n\nAllowed characters:\nabcdefABCDEF0123456789\n\nRegex:\n^[a-fA-F0-9]+$", "Illegal character found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    e.Cancel = true;
                    return;
                }

                // check Base32 format
                if (radioButtonBase32.Checked && (textBoxKeyLength % 8 == 2 || textBoxKeyLength % 8 == 4 || textBoxKeyLength % 8 == 5 || textBoxKeyLength % 8 == 7))
                {
                    this.textBoxKey.Text += new string('=', 8 - textBoxKeyLength % 8);
                }
                else if (radioButtonBase32.Checked && textBoxKeyLength % 8 != 0)
                {
                    MessageBox.Show("The given format of your key is illegal. If you want to check the format, please read the RFC 4648.\n\nLink:\nhttps://tools.ietf.org/html/rfc4648", "Illegal Base32 format!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    e.Cancel = true;
                    return;
                }

                // check Base64 format
                if (radioButtonBase64.Checked && (textBoxKeyLength % 4 == 2 || textBoxKeyLength % 4 == 3))
                {
                    this.textBoxKey.Text += new string('=', 4 - textBoxKeyLength % 4);
                }
                else if (radioButtonBase64.Checked && textBoxKeyLength % 8 != 0)
                {
                    MessageBox.Show("The given format of your key is illegal. If you want to check the format, please read the RFC 4648.\n\nLink:\nhttps://tools.ietf.org/html/rfc4648", "Illegal Base64 format!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    e.Cancel = true;
                    return;
                }

                // check Hex format
                if (radioButtonHex.Checked && textBoxKeyLength % 2 == 1)
                {
                    MessageBox.Show("The given format of your key is illegal. If you want to check the format, please read the RFC 4648.\n\nLink:\nhttps://tools.ietf.org/html/rfc4648", "Illegal Hex format!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    e.Cancel = true;
                    return;
                }

                if (this.Data == null)
                {
                    this.Data = new OtpAuthData();
                }

                int step = 30;
                if (int.TryParse(this.textBoxStep.Text, out step))
                {
                    if (step != 30)
                    {
                        if (step <= 0)
                        {
                            this.textBoxStep.Text = "30";
                            MessageBox.Show("The time step must be a non-zero positive integer. The standard value is 30.", "Invalid time step", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            e.Cancel = true;
                            return;
                        }
                        else if (MessageBox.Show("You have selected a non-standard time step. You should only proceed if you were specifically told to use this time step size.\nDefault Value: 30\n\nDo you wish to proceed?", "Non-standard time step size", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                        {
                            e.Cancel = true;
                            return;
                        }
                    }
                }
                else
                {
                    this.textBoxStep.Text = "30";
                    MessageBox.Show("The time step must be a non-zero positive integer. The standard value is 30.", "Invalid time step", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;
                    return;
                }

                // size
                if (this.radioButtonSix.Checked)
                {
                    this.Data.Size = 6;
                }
                else if (this.radioButtonEight.Checked)
                {
                    this.Data.Size = 8;
                }
                else
                {
                    this.Data.Size = 6; // default
                }
                // step
                this.Data.Step = Convert.ToInt32(this.textBoxStep.Text);

                // encoding
                if (this.radioButtonBase32.Checked)
                {
                    this.Data.Encoding = OtpSecretEncoding.Base32;
                }
                else if (this.radioButtonBase64.Checked)
                {
                    this.Data.Encoding = OtpSecretEncoding.Base64;
                }
                else if (this.radioButtonHex.Checked)
                {
                    this.Data.Encoding = OtpSecretEncoding.Hex;
                }
                else if (this.radioButtonUtf8.Checked)
                {
                    this.Data.Encoding = OtpSecretEncoding.UTF8;
                }
                else
                {
                    this.Data.Encoding = OtpSecretEncoding.Base32; // default
                }
                // hashmode
                if (this.radioButtonSha1.Checked)
                {
                    this.Data.OtpHashMode = OtpHashMode.Sha1;
                }
                else if (this.radioButtonSha256.Checked)
                {
                    this.Data.OtpHashMode = OtpHashMode.Sha256;
                }
                else if (this.radioButtonSha512.Checked)
                {
                    this.Data.OtpHashMode = OtpHashMode.Sha512;
                }
                else
                {
                    this.Data.OtpHashMode = OtpHashMode.Sha1; // default
                }
                this.Data.SetPlainSecret(this.textBoxKey.Text.Replace(" ", string.Empty).Replace("-", string.Empty));

                this.entry = OtpAuthUtils.purgeLoadedFields(this.Data, this.entry);

                if (checkboxOldKeeOtp.Checked)
                {
                    this.entry = OtpAuthUtils.migrateToKeeOtp1String(this.Data, this.entry);
                }
                else
                {
                    this.entry = OtpAuthUtils.migrateToBuiltInOtp(this.Data, this.entry);
                }
                this.entry.Touch(true);
                this.host.MainWindow.ActiveDatabase.Modified = true;
                this.host.MainWindow.UpdateUI(false, null, false, null, false, null, true);
            }
            catch
            {
                MessageBox.Show("There happened an error. Please check your entered key and your settings!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;
                return;
            }
        }
예제 #20
0
 public SingleItem(KeePassLib.PwEntry pe)
 {
     Entry = pe;
     ExtendDisplay();
 }
예제 #21
0
        private void OnManageAutoExportClicked(object sender, EventArgs e)
        {
            if (ReferenceEquals(_host, null) || ReferenceEquals(_host.Database, null) || !_host.Database.IsOpen)
            {
                return;
            }

            KeePassLib.Collections.PwObjectList <KeePassLib.PwEntry> entries = new KeePassLib.Collections.PwObjectList <KeePassLib.PwEntry>();
            _host.Database.RootGroup.FindEntriesByTag(Tag, entries, true);
            ExportManager exportManager = new ExportManager(entries.Select(ConvertToExportItem));

            exportManager.ShowDialog();

            //Remove deleted entry
            bool hasDelete = false;

            foreach (KeePassLib.PwEntry entry in entries)
            {
                string uuid = entry.Uuid.ToHexString();
                if (exportManager.Exports.Any(ei => !string.IsNullOrEmpty(ei.Uuid) && string.Equals(ei.Uuid, uuid, StringComparison.InvariantCultureIgnoreCase)))
                {
                    continue;
                }

                hasDelete = true;
                KeePassLib.PwDeletedObject deletedObject = new KeePassLib.PwDeletedObject(entry.Uuid, DateTime.Now);
                _host.Database.DeletedObjects.Add(deletedObject);
            }

            //Create new entry
            bool hasNew = false;

            KeePassLib.PwGroup savingGroup = FindOrCreatePluginGroup();
            foreach (ExportItem exportItem in exportManager.Exports)
            {
                if (!string.IsNullOrEmpty(exportItem.Uuid))
                {
                    continue;
                }

                hasNew = true;
                KeePassLib.PwEntry newExportEntry = new KeePassLib.PwEntry(true, true);
                newExportEntry.Strings.Set(KeePassLib.PwDefs.TitleField, new KeePassLib.Security.ProtectedString(false, Path.GetFileName(exportItem.Path.LocalPath)));
                newExportEntry.Strings.Set(KeePassLib.PwDefs.UrlField, new KeePassLib.Security.ProtectedString(false, exportItem.Path.ToString()));
                newExportEntry.IconId = KeePassLib.PwIcon.Disk;
                newExportEntry.Tags   = new List <string>()
                {
                    Tag
                };
                newExportEntry.Strings.Set(KeePassLib.PwDefs.PasswordField, exportItem.Password);
                savingGroup.AddEntry(newExportEntry, true);
            }

            if (hasDelete || hasNew) //Perform action on database
            {
                _host.Database.MergeIn(_host.Database, KeePassLib.PwMergeMethod.Synchronize);

                //Refresh GUI (Event is launched by main UI thread)
                _host.MainWindow.UpdateUI(false, null, true, savingGroup, true, null, true);
                _host.MainWindow.RefreshEntriesList();
            }
        }
예제 #22
0
        public string getData(string value, string kpColumn2Search = "Title", string kpColumn2Return = "Password")
        {
            string returnValue = string.Empty;
            var    ioconninfo  = new KeePassLib.Serialization.IOConnectionInfo();

            if (!(string.IsNullOrEmpty(KeepassDBFilePath)))
            {
                ioconninfo.Path = base64Decode(KeepassDBFilePath);
                KeePassLib.Keys.CompositeKey compkey = new KeePassLib.Keys.CompositeKey();
                if (string.IsNullOrEmpty(KeepassKeyFilePath) && string.IsNullOrEmpty(KeepassMasterPassword))
                {
                    throw new Exception("A Key file or Master Password has not been set!");
                }
                else
                {
                    if (!(string.IsNullOrEmpty(KeepassKeyFilePath)))
                    {
                        compkey.AddUserKey(new KeePassLib.Keys.KcpKeyFile(base64Decode(KeepassKeyFilePath)));
                    }
                    if (!(string.IsNullOrEmpty(KeepassMasterPassword)))
                    {
                        compkey.AddUserKey(new KeePassLib.Keys.KcpPassword(base64Decode(KeepassMasterPassword)));
                    }
                    var db = new KeePassLib.PwDatabase();

                    try
                    {
                        db.Open(ioconninfo, compkey, null);

                        KeePassLib.Collections.PwObjectList <KeePassLib.PwEntry> entries = db.RootGroup.GetEntries(true);
                        //var data =  from entry in db.rootgroup.getentries(true) where entry.strings.readsafe("title") == "tyler-u-client-id" select entry;

                        KeePassLib.PwEntry pw = entries.FirstOrDefault(i => i.Strings.ReadSafe(kpColumn2Search) == value);

                        if (pw != null)
                        {
                            returnValue = pw.Strings.ReadSafe(kpColumn2Return);
                        }
                        else
                        {
                            returnValue = string.Empty;
                        }

                        pw = null;
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        if (db.IsOpen)
                        {
                            db.Close();
                            db = null;
                        }
                    }
                }
            }
            else
            {
                throw new Exception("Keepass DB Path has not been set!");
            }

            return(returnValue);
        }
 public override StrengthReport.Measuring.PasswordQuality Evaluate(KeePassLib.PwEntry entry)
 {
     return(StrengthReport.Measuring.PasswordQuality.Better);
 }