internal static void UseDBForOTPSeeds(this PwDatabase db, bool value)
        {
            if (db == null)
            {
                return;
            }
            bool bUse = true;             //default

            if (db.CustomData.Exists(DBUsage))
            {
                bUse = StrUtil.StringToBool(db.CustomData.Get(DBUsage));
            }

            //Explicitly set value, even if it's the default value
            db.CustomData.Set(DBUsage, StrUtil.BoolToString(value));

            if (bUse == value)
            {
                return;
            }
            db.Modified        = true;
            db.SettingsChanged = DateTime.UtcNow;
            Program.MainForm.UpdateUI(false, null, false, null, false, null, Program.MainForm.ActiveDatabase == db);
            OTPDAO.InitEntries(db);
            OTPDAO.RemoveHandler(db.IOConnectionInfo.Path, true);
        }
Exemple #2
0
        private void bCreateOpen_Click(object sender, EventArgs e)
        {
            cbUseDBForSeeds.Checked = true;
            PwDatabase db = m_dDB.ElementAt(lbDB.SelectedIndex).Key;

            RefreshHandler(db);
            DBAction dba = cbDBAction.SelectedItem as DBAction;

            if (dba == null)
            {
                return;
            }
            if ((dba.Action == ACTION_CREATE) || !m_handler.OTPDB_Exists)
            {
                m_handler.OTPDB_Create();
                if (m_handler.OTPDB_Exists)
                {
                    bDBSettings_Click(sender, e);
                }
            }
            else if (dba.Action == ACTION_OPEN)
            {
                m_handler.SetDB(db, true);
            }
            else if (dba.Action == ACTION_CLOSE)
            {
                m_handler.OTPDB_Close();
                OTPDAO.RemoveHandler(db.IOConnectionInfo.Path, true);
                OTPDAO.GetOTPHandler(db);
                OTPDAO.InitEntries(db);
                KeePassOTPColumnProvider.ForceUpdate = true;
            }
            else if (dba.Action == ACTION_DELETE)
            {
                m_handler.OTPDB_Remove();
                OTPDAO.RemoveHandler(db.IOConnectionInfo.Path, true);
                OTPDAO.InitEntries(db);
                KeePassOTPColumnProvider.ForceUpdate = true;
            }

            if (m_handler.OTPDB_Opened)
            {
                cbUseDBForSeeds.Checked = true;
                Config.UseDBForOTPSeeds(db, true);
                OTPDAO.GetOTPHandler(db);
                OTPDAO.InitEntries(db);
            }
            lbDB_SelectedIndexChanged(sender, e);
        }
Exemple #3
0
        private void cbUseDBForSeeds_CheckedChanged(object sender, EventArgs e)
        {
            PwDatabase db = m_dDB.ElementAt(lbDB.SelectedIndex).Key;

            if (!cbUseDBForSeeds.Checked)
            {
                OTPDAO.OTPHandler_DB h = OTPDAO.GetOTPHandler(db);
                if ((h != null) && h.OTPDB_Exists)
                {
                    DialogResult dr = DialogResult.None;
                    if (!h.HasEntries())
                    {
                        dr = DialogResult.Yes;
                    }
                    else
                    {
                        dr = MessageBox.Show(string.Format(PluginTranslate.ConfirmOTPDBDelete, DialogResult.Yes.ToString(), DialogResult.No.ToString()),
                                             PluginTranslate.PluginName,
                                             MessageBoxButtons.YesNoCancel,
                                             MessageBoxIcon.Question,
                                             MessageBoxDefaultButton.Button2);
                    }
                    if (dr == DialogResult.Cancel)
                    {
                        cbUseDBForSeeds.CheckedChanged -= cbUseDBForSeeds_CheckedChanged;
                        cbUseDBForSeeds.Checked         = true;
                        cbUseDBForSeeds.CheckedChanged += cbUseDBForSeeds_CheckedChanged;
                        return;
                    }
                    if (dr == DialogResult.Yes)
                    {
                        h.OTPDB_Remove();
                        OTPDAO.RemoveHandler(db.IOConnectionInfo.Path, true);
                        OTPDAO.InitEntries(db);
                    }
                    else if (dr == DialogResult.No)
                    {
                        h.OTPDB_Close();
                        OTPDAO.RemoveHandler(db.IOConnectionInfo.Path, true);
                        OTPDAO.InitEntries(db);
                    }
                }
            }
            m_dDB[db].UseOTPDB   = cbUseDBForSeeds.Checked;
            cbPreloadOTP.Enabled = cbUseDBForSeeds.Checked;
            DBAction_Init(db);
        }
Exemple #4
0
        public static void MigrateToCustomdata(PwDatabase db, PwEntry pe)
        {
            bool bPreload = !pe.Strings.Exists(Config.DBPreload) || StrUtil.StringToBool(pe.Strings.ReadSafe(Config.DBPreload));

            db.CustomData.Set(Config.DBPreload, StrUtil.BoolToString(bPreload));

            bool bUseDB = !pe.Strings.Exists(Config.DBUsage) || StrUtil.StringToBool(pe.Strings.ReadSafe(Config.DBUsage));

            db.CustomData.Set(Config.DBUsage, StrUtil.BoolToString(bUseDB));

            db.CustomData.Remove(Config.DBKeySources);
            string k = pe.Strings.ReadSafe("KPOTP.KeySources");

            if (!string.IsNullOrEmpty(k))
            {
                db.CustomData.Set(Config.DBKeySources, k);
            }

            if (pe.Binaries.Get(OTPDAO.OTPHandler_DB.DBNAME + ".kdbx") != null)
            {
                ProtectedBinary pbOTPDB = pe.Binaries.Get(OTPDAO.OTPHandler_DB.DBNAME + ".kdbx");
                string          otpdb   = OTPDAO.OTPHandler_DB.ConvertToCustomData(pbOTPDB.ReadData());
                db.CustomData.Set(OTPDAO.OTPHandler_DB.DBNAME, otpdb);
            }

            bool bDeleted = false;

            if (db.RecycleBinEnabled)
            {
                PwGroup pgRecycleBin = db.RootGroup.FindGroup(db.RecycleBinUuid, true);
                if (pgRecycleBin == null)
                {
                    MethodInfo miEnsureRecycleBin = Program.MainForm.GetType().GetMethod("EnsureRecycleBin", BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
                    if (miEnsureRecycleBin != null)
                    {
                        object[] p = new object[] { null, db, null };
                        try
                        {
                            miEnsureRecycleBin.Invoke(null, p);
                            pgRecycleBin = p[0] as PwGroup;
                        }
                        catch { }
                    }
                }
                if (pgRecycleBin != null)
                {
                    pe.ParentGroup.Entries.Remove(pe);
                    pgRecycleBin.AddEntry(pe, true);
                    bDeleted = true;
                }
            }
            else if (!db.RecycleBinEnabled && !bUseDB)
            {
                pe.ParentGroup.Entries.Remove(pe);
                bDeleted = true;
            }
            if (!bDeleted)
            {
                pe.Strings.Remove(Config.DBPreload);
                pe.Strings.Remove(Config.DBUsage);
                pe.Strings.Remove(Config.DBKeySources);
                pe.Binaries.Remove(OTPDAO.OTPHandler_DB.DBNAME + ".kdbx");
                pe.Touch(true);
            }

            db.Modified        = true;
            db.SettingsChanged = DateTime.UtcNow;
            System.Threading.Thread tUpdate = new System.Threading.Thread(UpdateUI);
            tUpdate.Start(new object[] { bDeleted, db });
            OTPDAO.InitEntries(db);
            OTPDAO.RemoveHandler(db.IOConnectionInfo.Path, true);
        }