Beispiel #1
0
        public void WriteXml(XmlWriter writer)
        {
            List <UpdateInfoExtern> l = this as List <UpdateInfoExtern>;

            foreach (UpdateInfoExtern uie in l)
            {
                writer.WriteStartElement("UpdateInfoExtern");

                writer.WriteStartElement("PluginName");
                writer.WriteString(uie.PluginTitle);
                writer.WriteEndElement();

                writer.WriteStartElement("PluginURL");
                writer.WriteString(uie.PluginURL);
                writer.WriteEndElement();

                writer.WriteStartElement("PluginUpdateURL");
                writer.WriteString(uie.PluginUpdateURL);
                writer.WriteEndElement();

                writer.WriteStartElement("UpdateMode");
                writer.WriteString(uie.UpdateMode.ToString());
                writer.WriteEndElement();

                writer.WriteStartElement("AllowVersionStripping");
                writer.WriteString(StrUtil.BoolToString(uie.AllowVersionStripping));
                writer.WriteEndElement();

                writer.WriteEndElement();
            }
        }
Beispiel #2
0
            public void OTPDB_Create()
            {
                if (m_bOpening)
                {
                    return;
                }
                m_bOpening = true;
                OTPDB_Init(true);
                if (!OTPDB_ChangePassword(false))
                {
                    PluginDebug.AddInfo("OTP DB - Creation cancelled");
                    OTPDB_Exists = OTPDB_Opened = false;
                    OTPDB        = null;
                    m_bOpening   = false;
                    return;
                }

                DB.CustomData.Set(Config.DBUsage, StrUtil.BoolToString(true));
                DB.CustomData.Set(Config.DBPreload, StrUtil.BoolToString(true));
                FlagChanged(false);

                OTPDB_Save();
                PluginDebug.AddInfo("OTP DB - Creation successful");
                m_bOpening = false;
            }
        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);
        }
Beispiel #4
0
            public override void SaveOTP(KPOTP myOTP, PwEntry pe)
            {
                if (!SetEntry(pe, true))
                {
                    return;
                }

                //string otpSettings = myOTP.Settings;
                KPOTP prev = GetOTP(pe);
                bool  OnlyCounterChanged = false;

                if (!SettingsChanged(pe, prev, myOTP, out OnlyCounterChanged))
                {
                    return;
                }

                PluginDebug.AddInfo("Update OTP data",
                                    "Entry uuid: " + pe.Uuid.ToHexString(),
                                    "Only change of HOTP counter: " + OnlyCounterChanged.ToString());

                bool bCreated = false;

                GetOTPEntry(true, out bCreated);
                if (!OnlyCounterChanged)
                {
                    //Create backup if something else than only the HOTP counter was changed
                    if (!bCreated)
                    {
                        m_peOTP.CreateBackup(OTPDB);
                    }
                }
                m_peOTP.Strings.Set(Config.OTPFIELD, myOTP.OTPAuthString);
                if (myOTP.TimeCorrectionUrlOwn)
                {
                    m_peOTP.Strings.Set(Config.TIMECORRECTION, new ProtectedString(false, "OWNURL"));
                }
                else if (string.IsNullOrEmpty(myOTP.TimeCorrectionUrl) || (myOTP.TimeCorrectionUrl == "OFF"))
                {
                    m_peOTP.Strings.Remove(Config.TIMECORRECTION);
                }
                else
                {
                    m_peOTP.Strings.Set(Config.TIMECORRECTION, new ProtectedString(false, myOTP.TimeCorrectionUrl));
                }

                Touch(m_peOTP);
                if (myOTP.OTPSeed.IsEmpty)
                {
                    m_pe.Strings.Remove(DBNAME);
                }
                else
                {
                    m_pe.Strings.Set(DBNAME, new ProtectedString(false, StrUtil.BoolToString(true)));
                }
                FlagChanged(false);
                FlagChanged(true);

                m_pe.Touch(true);
            }
        internal static void PreloadOTPDB(this PwDatabase db, bool value)
        {
            if (db == null)
            {
                return;
            }
            if (value == db.PreloadOTPDB())
            {
                return;
            }

            db.CustomData.Set(DBPreload, StrUtil.BoolToString(value));
            db.Modified        = true;
            db.SettingsChanged = DateTime.UtcNow;
            Program.MainForm.UpdateUI(false, null, false, null, false, null, Program.MainForm.ActiveDatabase == db);
        }
Beispiel #6
0
            public int MigrateOTP2DB()
            {
                if (!Valid || !OTPDB_Exists || !OTPDB_Opened)
                {
                    return(-1);
                }
                int moved = 0;
                //process all entries having OTP settings
                PwEntry peBackup     = m_pe;
                PwEntry pe_OTPBackup = m_peOTP;

                foreach (PwEntry pe in DB.RootGroup.GetEntries(true).Where(x => x.Strings.Exists(Config.OTPFIELD)))
                {
                    m_pe = pe;
                    ProtectedString otpfield       = m_pe.Strings.GetSafe(Config.OTPFIELD);
                    ProtectedString timecorrection = m_pe.Strings.GetSafe(Config.TIMECORRECTION);
                    if (otpfield.IsEmpty)
                    {
                        continue;
                    }
                    bool bCreated = false;
                    GetOTPEntry(true, out bCreated);
                    m_peOTP.Strings.Set(Config.OTPFIELD, otpfield);
                    if (!timecorrection.IsEmpty)
                    {
                        m_peOTP.Strings.Set(Config.TIMECORRECTION, timecorrection);
                    }
                    else
                    {
                        m_peOTP.Strings.Remove(Config.TIMECORRECTION);
                    }
                    //Seed has been added to OTP db, increase moved-counter
                    moved++;
                    m_pe.Strings.Remove(Config.OTPFIELD);
                    m_pe.Strings.Remove(Config.TIMECORRECTION);
                    m_pe.Strings.Set(DBNAME, new ProtectedString(false, StrUtil.BoolToString(true)));
                    m_pe.Touch(true);
                    FlagChanged(false);
                }
                m_pe    = peBackup;
                m_peOTP = pe_OTPBackup;
                if (moved > 0)
                {
                    OTPDB_Save();
                }
                return(moved);
            }
Beispiel #7
0
 /// <summary>
 /// Set a configuration item's value.
 /// </summary>
 /// <param name="strID">ID of the configuration item. This identifier
 /// should consist only of English characters (a-z, A-Z, 0-9, '.',
 /// ',', '-', '_') and should be unique -- for example (without quotes):
 /// "PluginName.YourConfigGroupName.ItemName". Use upper camel
 /// case as naming convention.</param>
 /// <param name="bValue">New value of the configuration item.</param>
 public void SetBool(string strID, bool bValue)
 {
     SetString(strID, StrUtil.BoolToString(bValue));
 }
Beispiel #8
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);
        }