Пример #1
0
        internal static int DeleteFiles(params string[] files)
        {
            // 0 = success
            // -1 = aborted by user
            // other value = error

            string from = string.Empty;

            foreach (string file in files)
            {
                from += file + "\0";
            }
            from += "\0";

            SHFILEOPSTRUCT lpFileOp = new SHFILEOPSTRUCT();

            lpFileOp.hwnd   = IntPtr.Zero;
            lpFileOp.wFunc  = FILE_OP_TYPE.FO_DELETE;
            lpFileOp.pFrom  = from;
            lpFileOp.pTo    = "\0\0";
            lpFileOp.fFlags = FILE_OP_FLAGS.FOF_NOCONFIRMATION | FILE_OP_FLAGS.FOF_ALLOWUNDO;
            lpFileOp.fAnyOperationsAborted = false;
            lpFileOp.hNameMappings         = IntPtr.Zero;
            lpFileOp.lpszProgressTitle     = string.Empty;

            int result = SHFileOperation(ref lpFileOp);

            if (result == 0 && lpFileOp.fAnyOperationsAborted)
            {
                result = -1;
            }
            PluginDebug.AddInfo("Delete in UAC mode: " + result.ToString());
            return(result);
        }
 private void OnFocusChangeRequired(object sender, EventArgs e)
 {
     PluginDebug.AddInfo(Name + " Check for focus change");
     if (UseSystemPasswordChar)
     {
         return;
     }
     if (!ReadOnly)
     {
         return;
     }
     if (TabStop)
     {
         return;
     }
     if (m_text == null)
     {
         return;
     }
     //UIUtil.SetFocus(m_text, GetForm(m_text), true); //Only availabe as of KeePass 2.42
     UIUtil.SetFocus(m_text, GetForm(m_text));
     if (m_text.CanFocus)
     {
         m_text.Focus();
     }
     PluginDebug.AddInfo(Name + " Focus changed");
 }
Пример #3
0
        private void bDBSettings_Click(object sender, EventArgs e)
        {
            PwDatabase db = m_dDB.ElementAt(lbDB.SelectedIndex).Key;

            RefreshHandler(db);
            if (!m_handler.OTPDB_Opened)
            {
                return;
            }
            PwDatabase kpotpdb = m_handler.OTPDB;

            if (kpotpdb == null)
            {
                return;
            }

            DatabaseSettingsForm dsf = new DatabaseSettingsForm();

            dsf.InitEx(false, kpotpdb);
            dsf.Shown += DBSettings_Shown;
            if (UIUtil.ShowDialogAndDestroy(dsf) == DialogResult.OK)
            {
                m_handler.FlagChanged(true);
                m_handler.FlagChanged(false);
                PluginDebug.AddInfo("Changed OTP Db settings", 0);
                //KeePass.Program.MainForm.RefreshEntriesList(); // History items might have been deleted
            }
        }
Пример #4
0
 private void SprEngine_FilterCompile(object sender, SprEventArgs e)
 {
     if ((e.Context.Flags & SprCompileFlags.ExtActive) != SprCompileFlags.ExtActive)
     {
         return;
     }
     if (e.Text.IndexOf(Config.Placeholder, StringComparison.InvariantCultureIgnoreCase) >= 0)
     {
         OTPDAO.EnsureOTPUsagePossible(e.Context.Entry);
         KPOTP myOTP = OTPDAO.GetOTP(e.Context.Entry);
         if (!myOTP.Valid)
         {
             PluginDebug.AddError("Auto-Type OTP failed", 0, "Uuid: " + e.Context.Entry.Uuid.ToHexString());
         }
         else
         {
             PluginDebug.AddInfo("Auto-Type OTP success", 0, "Uuid: " + e.Context.Entry.Uuid.ToHexString());
         }
         e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, Config.Placeholder, myOTP.GetOTP(false, true));
         if (myOTP.Valid && (myOTP.Type == KPOTPType.HOTP))
         {
             var newOTP = myOTP.Clone();
             newOTP.HOTPCounter++;
             OTPDAO.SaveOTP(newOTP, e.Context.Entry);
         }
     }
 }
Пример #5
0
 private void WindowAdded(object sender, GwmWindowEventArgs e)
 {
     if (!PluginConfig.Active)
     {
         return;
     }
     PluginDebug.AddInfo("Form added", 0, e.Form.Name, e.Form.GetType().FullName, DebugPrint);
     if (e.Form is UpdateCheckForm)
     {
         if (m_CheckProgress != null && !m_CheckProgress.IsDisposed && !m_CheckProgress.Disposing)
         {
             if (!KeePassLib.Native.NativeLib.IsUnix())
             {
                 m_CheckProgress.Hide();                                                            //Makes KeePass freeze sometimes... How I love randomness in development...
             }
             lock (m_lock) { m_UpdateCheckStatus = UpdateCheckStatus.Checked; }
         }
         if (PluginConfig.OneClickUpdate)
         {
             PluginDebug.AddInfo("OneClickUpdate 1", 0, DebugPrint);
             e.Form.Shown += OnUpdateCheckFormShown;
             PluginDebug.AddInfo("OneClickUpdate 2", 0, DebugPrint);
         }
         return;
     }
     if (e.Form is KeyPromptForm)
     {
         KeyPromptFormAdded();
     }
     if (e.Form is LanguageForm)
     {
         e.Form.Shown += LanguageFormAdded;
     }
 }
Пример #6
0
        public static PEDCalcValue GetPEDCValue(PwEntry pe, bool recursion)
        {
            if (!m_dPEDValues.ContainsKey(pe))
            {
                string         days_string = pe.ReadPEDCString();
                PEDCValueEntry pve         = new PEDCValueEntry();
                pve.value = PEDCalcValue.ConvertFromString(days_string);

                if (pve.value.Inherit && (pe.ParentGroup != null))
                {
                    pve.valueinherit = pe.ParentGroup.GetPEDValue(true);
                }
                else
                {
                    pve.valueinherit = new PEDCalcValue(PEDC.Off);
                }
                m_dPEDValues[pe] = pve;
                PluginDebug.AddInfo("Add PEDCValues to buffer", 0,
                                    "Entry: " + pe.Uuid.ToHexString() + " / " + pe.Strings.ReadSafe(PwDefs.TitleField),
                                    "Value: " + pve.value.ToString(),
                                    "Value inherited: " + pve.valueinherit.ToString());
            }
            if (recursion && m_dPEDValues[pe].value.Inherit)
            {
                return(m_dPEDValues[pe].valueinherit);
            }
            return(m_dPEDValues[pe].value);
        }
Пример #7
0
 /* Ensure the internal RichTextBox m_text has the same parent
  * as the SecureTextBoxEx
  * Adjust TabIndex as well
  */
 protected override void OnParentChanged(EventArgs e)
 {
     PluginDebug.AddInfo(Name + " Adjust parent control");
     base.OnParentChanged(e);
     if (m_text == null)
     {
         return;
     }
     if (m_text.Parent != null)
     {
         m_text.Parent.Controls.Remove(m_text);
     }
     if (Parent == null)
     {
         return;
     }
     Parent.SuspendLayout();
     Parent.Controls.Add(m_text);
     m_text.Parent = Parent;
     foreach (Control c in Parent.Controls)
     {
         if (c.TabIndex > TabIndex)
         {
             c.TabIndex++;
         }
     }
     m_text.TabStop  = true;
     m_text.TabIndex = TabIndex + 1;
     Parent.ResumeLayout();
     Parent.PerformLayout();
 }
Пример #8
0
        private void OnButtonClick(object sender, EventArgs e)
        {
            if (ItemOrButtonClick != null)
            {
                PEDCalcValue pcv;
                PEDC         unit = PEDC.Days;
                PEDCListItem i    = m_cbUnit.Items[m_cbUnit.SelectedIndex] as PEDCListItem;
                unit = i.Unit;
                int dummy = -1;
                if (!int.TryParse(m_tbValue.Text, out dummy) || (dummy == -1))
                {
                    pcv = new PEDCalcValue(PEDC.Inherit);
                    PluginDebug.AddInfo("Converted expiry value", 0, "Given: " + m_tbValue.Text, "Converted: " + pcv.unit.ToString());
                }
                else if (dummy <= 0)
                {
                    pcv = new PEDCalcValue(PEDC.Off);
                    PluginDebug.AddInfo("Converted expiry value", 0, "Given: " + m_tbValue.Text, "Converted: " + pcv.unit.ToString());
                }
                else
                {
                    pcv = new PEDCalcValue(unit, dummy);
                }

                QuickActionEventArgs qe = new QuickActionEventArgs(pcv);
                ItemOrButtonClick(this, qe);
            }
        }
Пример #9
0
        public static bool CopyFiles(string from, string to)
        {
            bool success = false;

            from += "*\0\0";
            to   += "\0\0";

            SHFILEOPSTRUCT lpFileOp = new SHFILEOPSTRUCT();

            lpFileOp.hwnd   = IntPtr.Zero;
            lpFileOp.wFunc  = FILE_OP_TYPE.FO_COPY;
            lpFileOp.pFrom  = from;
            lpFileOp.pTo    = to;
            lpFileOp.fFlags = FILE_OP_FLAGS.FOF_NOCONFIRMATION;
            lpFileOp.fAnyOperationsAborted = false;
            lpFileOp.hNameMappings         = IntPtr.Zero;
            lpFileOp.lpszProgressTitle     = string.Empty;

            int result = SHFileOperation(ref lpFileOp);

            if (result == 0)
            {
                success = !lpFileOp.fAnyOperationsAborted;
            }
            PluginDebug.AddInfo("Copy in UAC mode: " + success.ToString());
            return(success);
        }
        public override void PerformCellAction(string strColumnName, PwEntry pe)
        {
            //Copy OTP to clipboard
            if (strColumnName == null)
            {
                return;
            }
            if (KeePassOTPExt.CopyOTP(pe) || OTPDAO.OTPDefined(pe) != OTPDAO.OTPDefinition.None)
            {
                return;
            }

            //Show 2FA setup instructions if available
            if (!Config.CheckTFA)
            {
                return;
            }
            string url    = pe.Strings.ReadSafe(PwDefs.UrlField);
            string target = TFASites.GetTFAUrl(url);

            PluginDebug.AddInfo("Show 2FA instructions", 0, "URL: " + target);
            try
            {
                System.Diagnostics.Process.Start(target);
            }
            catch { }
        }
Пример #11
0
        static Config()
        {
            if (KeePassLib.Native.NativeLib.IsUnix())
            {
                KPAutoTypePWPossible = false;
                return;
            }
            if (!Program.Config.CustomConfig.GetBool("AlternateAutoType.UseAutoTypePasswordHotKey", true))
            {
                return;
            }
            KPAutoTypePWPossible = Tools.KeePassVersion >= new Version(2, 41);
            if (!KPAutoTypePWPossible)
            {
                return;
            }
            m_piHotKeyGlobalAutoTypePassword = Program.Config.Integration.GetType().GetProperty("HotKeyGlobalAutoTypePassword");

            if (KPAutoTypePWPossible && (m_piHotKeyGlobalAutoTypePassword != null))
            {
                PluginDebug.AddInfo("Hooking Program.Config.Integration.HotKeyGlobalAutoTypePassword successful");
            }
            else
            {
                PluginDebug.AddError("Hooking Program.Config.Integration.HotKeyGlobalAutoTypePassword failed");
                KPAutoTypePWPossible = false;
            }
        }
Пример #12
0
        private void OnWindowRemoved(object sender, GwmWindowEventArgs e)
        {
            if (m_AT == null)
            {
                return;
            }
            if (!(e.Form is AutoTypeCtxForm))
            {
                return;
            }
            PluginDebug.AddInfo("Auto-Type entry selection window removed", 0);
            m_AT.Shown -= OnAutoTypeFormShown;
            ListView lv = Tools.GetControl("m_lvItems", m_AT) as ListView;

            lv.ColumnWidthChanged -= HandleColumns;
            lv.Columns.RemoveByKey(Config.DBColumn);
            lv.Columns.RemoveByKey(Config.PWColumn);
            UIUtil.ResizeColumns(lv, true);
            string ColumnWidths = UIUtil.GetColumnWidths(lv);

            if (ColumnWidths.Length > 0)
            {
                KeePass.Program.Config.UI.AutoTypeCtxColumnWidths = ColumnWidths;
            }
            m_AT              = null;
            m_SortColumn      = null;
            m_SortOrder       = SortOrder.Ascending;
            m_DBColumnVisible = false;
        }
Пример #13
0
        internal static bool DeleteFiles(params string[] files)
        {
            bool success = false;

            string from = string.Empty;

            foreach (string file in files)
            {
                from += file + "\0";
            }
            from += "\0";

            SHFILEOPSTRUCT lpFileOp = new SHFILEOPSTRUCT();

            lpFileOp.hwnd   = IntPtr.Zero;
            lpFileOp.wFunc  = FILE_OP_TYPE.FO_DELETE;
            lpFileOp.pFrom  = from;
            lpFileOp.pTo    = "\0\0";
            lpFileOp.fFlags = FILE_OP_FLAGS.FOF_NOCONFIRMATION | FILE_OP_FLAGS.FOF_ALLOWUNDO;
            lpFileOp.fAnyOperationsAborted = false;
            lpFileOp.hNameMappings         = IntPtr.Zero;
            lpFileOp.lpszProgressTitle     = string.Empty;

            int result = SHFileOperation(ref lpFileOp);

            if (result == 0)
            {
                success = !lpFileOp.fAnyOperationsAborted;
            }
            PluginDebug.AddInfo("Delete in UAC mode: " + success.ToString());
            return(success);
        }
Пример #14
0
        internal static bool RecalcRequired(this PwEntry pe)
        {
            if (pe.History.UCount < 1)
            {
                return(false);                // no history exists, this is a new entry and not a password change: nothing to do
            }
            byte[] pw_now  = pe.Strings.GetSafe(PwDefs.PasswordField).ReadUtf8();
            byte[] pw_prev = pe.History.GetAt(pe.History.UCount - 1).Strings.GetSafe(PwDefs.PasswordField).ReadUtf8();

            string days_string      = ReadPEDCString(pe);
            string days_string_prev = ReadPEDCString(pe.History.GetAt(pe.History.UCount - 1));

            DateTime expiry_now  = pe.ExpiryTime;
            DateTime expiry_prev = pe.History.GetAt(pe.History.UCount - 1).ExpiryTime;

            //check whether recalculation is required
            bool bNoRecalc = ((expiry_now != expiry_prev) ||         //expiry time has been changed manually
                              ((days_string == days_string_prev) &&  //	PEDCalc password lifetime value is the same as before
                               MemUtil.ArraysEqual(pw_now, pw_prev)));     //	Passwords are the same

            if (bNoRecalc)
            {
                PluginDebug.AddInfo("Recalc expiry date", pe.Uuid.ToString(), "Recalc not required");
            }
            else
            {
                PluginDebug.AddInfo("Recalc expiry date", pe.Uuid.ToString(), "Recalc required");
            }
            return(!bNoRecalc);
        }
Пример #15
0
        internal static void RecalcExpiry(this PwEntry pe, bool forceRecalculation)
        {
            if (!pe.Expires)
            {
                return;                 //password does not expire: nothing to do
            }
            if (!forceRecalculation && !RecalcRequired(pe))
            {
                return;
            }

            PEDCalcValue days = GetPEDValue(pe, true);

            PluginDebug.AddInfo("Recalc expiry date", pe.Uuid.ToString(), "Force: " + forceRecalculation.ToString(), "Old: " + pe.ExpiryTime.ToString("YYYYMMddTHHmmssZ"),
                                "New: " + days.NewExpiryDateUtc.ToString("yyyyMMddTHHmmssZ"),
                                "Recalc required: " + (days.Specific && (pe.ExpiryTime != days.NewExpiryDateUtc)).ToString());
            if (!days.Specific)
            {
                return;
            }

            if (days.NewExpiryDateUtc == pe.ExpiryTime)
            {
                return;
            }
            pe.ExpiryTime = days.NewExpiryDateUtc;
            pe.Touch(true, false);
            Tools.RefreshEntriesList(true);
        }
Пример #16
0
        private void Lv_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            AceColumn colPw = KeePass.Program.Config.MainWindow.FindColumn(AceColumnType.Password);
            string    m     = string.Empty;

            if (((colPw == null) || colPw.HideWithAsterisks) && !SinglePwDisplay.PasswordShown(e.Item))
            {
                //Let the OS draw in case no other handlers exist
                //If other handlers exist, we pass their value for DrawDefault
                e.DrawDefault = true;
                if (colPw == null)
                {
                    m = "Password column not found";
                }
                else
                {
                    m = "Password column found, password hidden";
                }
                List <string> lCol = new List <string>();
                foreach (var c in KeePass.Program.Config.MainWindow.EntryListColumns)
                {
                    lCol.Add(c.GetDisplayName());
                }
                PluginDebug.AddInfo(m, 0, lCol.ToArray());
                return;
            }
            e.DrawDefault = false;
            m             = "Password column found, password shown";
            PluginDebug.AddSuccess(m, 0);

            if ((e.State & ListViewItemStates.Selected) != 0)
            {
                e.DrawFocusRectangle();
            }
        }
Пример #17
0
        private void RestoreFormLoadPostHandlers(object sender, EventArgs e)
        {
            Thread t = new Thread(() =>
            {
                Thread.Sleep(PluginConfig.RestoreMutexThreshold);
                if (KeePass.Program.MainForm == null || KeePass.Program.MainForm.Disposing || KeePass.Program.MainForm.IsDisposed)
                {
                    PluginDebug.AddInfo("Restore MainForm.FormLoadPost handlers not done");
                    return;
                }
                EventHelper.RestoreFormLoadPostEventHandlers(m_lFormLoadPostHandlers);
                PluginDebug.AddInfo("Restore MainForm.FormLoadPost handlers done");
                foreach (var del in m_lFormLoadPostHandlers)
                {
                    if (KeePass.Program.MainForm != null && !KeePass.Program.MainForm.Disposing && !KeePass.Program.MainForm.IsDisposed)
                    {
                        del.DynamicInvoke(new object[] { sender, e });
                    }
                }
                PluginDebug.AddInfo("MainForm.FormLoadPost handlers executed");
            });

            t.IsBackground = true;
            t.Start();
        }
Пример #18
0
        private void MainWindow_FormLoadPost(object sender, EventArgs e)
        {
            //Can be null if restart after upgrade is in progress
            //In this case, EarlyUpdateCheckExt.Terminate() might have been called already
            //RemoveAndBackupFormLoadPostHandlers and RestoreFormLoadPostHandlers should work around that, but you never know...
            if (m_host == null || m_host.MainWindow == null)
            {
                return;
            }
            if (m_host.MainWindow.IsDisposed || m_host.MainWindow.Disposing)
            {
                return;
            }

            m_host.MainWindow.FormLoadPost -= MainWindow_FormLoadPost;

            //Load plugins and check check for new translations if not already done
            if (PluginUpdateHandler.CheckTranslations && !m_bRestartInvoke)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(CheckPluginLanguages));
            }
            else if (!m_bRestartInvoke)
            {
                //Only load plugins, do NOT check for new translations
                ThreadPool.QueueUserWorkItem(new WaitCallback((object o) => { PluginUpdateHandler.LoadPlugins(false); }));
            }
            PluginDebug.AddInfo("All plugins loaded", 0, DebugPrint);
            m_bRestartInvoke = false;
        }
Пример #19
0
        /// Calculate time offset for all relevant entries
        /// Do NOT use Task.Run as this requires .NET 4.5 which will cause issues on Mono
        /// Mono reports .NET 4.0.3 being installed despite higher versions can be used
        /// This results in KeePass refusing to compile the plgx
        public static /*async*/ void GetTimingsAsync(KeePassLib.PwDatabase db)
        {
            //Don't use TraverseTree as db content might change during processing
            //and this will result in an exception since TraverseTree uses 'foreach'

            //await - Don't use, see comment above method definition
            System.Threading.Tasks.Task.Factory.StartNew(() =>
                                                         //System.Threading.Tasks.Task.Run(() =>
            {
                DateTime dtStart          = DateTime.Now;
                IEnumerable <string> lURL = db.RootGroup.GetEntries(true).
                                            Where(e => OTPDAO.OTPDefined(e) != OTPDAO.OTPDefinition.None).          //We're not interested in sites without OTP being set up
                                            Select(e => e.Strings.ReadSafe(KeePassLib.PwDefs.UrlField)).Distinct(); //We're not interested in duplicate URLs
                foreach (string url in lURL)
                {
                    if (m_timeCorrectionUrls.ContainsKey(url))
                    {
                        continue;
                    }
                    GetTimeCorrection(url);
                    System.Threading.Thread.Sleep(100);
                }
                ;
                DateTime dtEnd = DateTime.Now;
                PluginDebug.AddInfo("Calculated OTP time corrections", 0, "Start: " + dtStart.ToLongTimeString(), "End: " + dtEnd.ToLongTimeString());
            }
                                                         );
        }
Пример #20
0
            private EntryOTP EnsureEntry()
            {
                EntryOTP otp;

                if (m_dEntryOTPData.TryGetValue(m_pe, out otp) && !IgnoreBuffer)
                {
                    return(otp);
                }
                otp.db          = DB;
                otp.OTPDefined  = OTPDefined(m_pe);
                otp.Loaded      = OTPDB_Opened;
                otp.ReadableOTP = otp.OTPDefined == OTPDefinition.Partial ? "???" : string.Empty;
                otp.ValidTo     = otp.OTPDefined != OTPDefinition.None ? KPOTP.UnixStartUTC : DateTime.MaxValue;
                if (otp.OTPDefined != OTPDefinition.Complete)
                {
                    otp.ReadableOTP = otp.OTPDefined == OTPDefinition.Partial ? "???" : string.Empty;
                    otp.ValidTo     = DateTime.MaxValue;
                    otp.kpotp       = new KPOTP();
                    InitIssuerLabel(otp.kpotp, m_pe);
                }
                else
                {
                    otp.kpotp   = GetSettings();
                    otp.ValidTo = KPOTP.UnixStartUTC;
                }
                UpdateOTPBuffer(m_pe, otp);
                PluginDebug.AddInfo("Fill OTP buffer", 0,
                                    "Entry uuid: " + m_pe.Uuid.ToHexString(),
                                    "OTP db exists: " + OTPDB_Exists.ToString(),
                                    "OTP db loaded: " + otp.Loaded.ToString(),
                                    "OTP defined: " + otp.OTPDefined.ToString(),
                                    "OTP setup valid: " + otp.kpotp.Valid.ToString());
                return(otp);
            }
Пример #21
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;
            }
Пример #22
0
            private void GetOTPEntry(bool bCreate, out bool Created)
            {
                Created = false;
                m_peOTP = null;
                if (!OTPDB_Opened)
                {
                    return;
                }
                string uuid = m_pe.Uuid.ToHexString();

                m_peOTP = OTPDB.RootGroup.GetEntries(true).Where(x => x.Strings.ReadSafe(UUID) == uuid).FirstOrDefault();
                if (m_peOTP != null)
                {
                    string s = "Found OTP entry for main entry " + m_pe.Uuid.ToHexString();
                    if (!PluginDebug.HasMessage(PluginDebug.LogLevelFlags.Info, s))
                    {
                        PluginDebug.AddInfo(s);
                    }
                }
                if ((m_peOTP != null) || !bCreate)
                {
                    return;
                }
                m_peOTP = new PwEntry(true, true);
                OTPDB.RootGroup.AddEntry(m_peOTP, true);
                m_peOTP.Strings.Set(UUID, new ProtectedString(false, uuid));
                UpdateString(PwDefs.TitleField);
                UpdateString(PwDefs.UserNameField);
                UpdateString(PwDefs.UrlField);
                Created = true;
                if (m_peOTP != null)
                {
                    PluginDebug.AddInfo("Created OTP entry for main entry " + m_pe.Uuid.ToHexString());
                }
            }
Пример #23
0
            public void OTPDB_Open()
            {
                if (m_bOpening)
                {
                    return;
                }
                m_bOpening = true;

                if (OTPDB_Opened)
                {
                    PluginDebug.AddInfo("OTP DB already opened");
                    UpdateDBHeader();
                    m_bOpening = false;
                    return;
                }
                if (!OTPDB_Exists)
                {
                    PluginDebug.AddError("OTP DB not available");
                    m_bOpening = false;
                    return;
                }

                OTPDB_Load();
                if (OTPDB_Opened)
                {
                    OTPDB.Modified = false;
                }
                m_bOpening = false;
            }
Пример #24
0
        private void OptionsFormClosed(object sender, Tools.OptionsFormsEventArgs e)
        {
            if (e.form.DialogResult != DialogResult.OK)
            {
                return;
            }
            bool    shown   = false;
            Options options = (Options)Tools.GetPluginFromOptions(this, out shown);

            if (!shown)
            {
                return;
            }
            Program.Config.Application.ExpirySoonDays = options.Days;
            Config.AlreadyExpiredIcon   = options.expiredIcon;
            Config.SoonExpiredIcon      = options.expiringIcon;
            Config.AlreadyExpiredColor  = options.expiredColor;
            Config.SoonExpiredColor     = options.expiringColor;
            Config.IgnoreTimeFraction   = options.ignoreTimeFraction;
            Config.ToggleKey            = options.hkcToggle.HotKey;
            Config.SoonExpiredActive    = options.cgExpiring.Checked;
            Config.AlreadyExpiredActive = options.cgExpired.Checked;
            m_tsbToggle.Enabled         = Config.AlreadyExpiredActive;
            if ((Config.HideExpired != options.hideExpired))
            {
                if (m_tsbToggle != null)
                {
                    m_tsbToggle.Checked = options.hideExpired;
                }
                Config.HideExpired = options.hideExpired;
                PluginDebug.AddInfo("Display of expired entries: " + (Config.HideExpired ? "Hide" : "Show"), 1);
            }
            m_host.MainWindow.UpdateUI(false, null, false, null, true, null, false);
        }
Пример #25
0
        private void MainWindow_FormLoadPost(object sender, EventArgs e)
        {
            HookOtherTimers(false);

            m_OtherTimers.Clear();
            if (m_lTimers.Contains("None"))
            {
                PluginDebug.AddInfo("Hooking other timers disabled", 0);
            }
            else
            {
                foreach (string sTimer in m_lTimers)
                {
                    string[] timer = sTimer.Split(new char[] { '.' }, 2);
                    if (timer.Length != 2)
                    {
                        PluginDebug.AddError("Invalid timer format", 0, "Expected: PluginNamespace.NameOfTimerVariable", "Found: " + sTimer);
                        continue;
                    }
                    AddTimerIfExists(timer[0], timer[1]);
                }
            }

            HookOtherTimers(true);
        }
Пример #26
0
        private void OnAutoTypeFormShown(object sender, EventArgs e)
        {
            AutoTypeCtxForm f  = sender as AutoTypeCtxForm;
            ListView        lv = Tools.GetControl("m_lvItems", f) as ListView;

            PluginDebug.AddInfo("Auto-Type entry selection window shown", 0);
            if ((lv != null) && (lv.Items.Count == 0) && !Program.Config.Integration.AutoTypeAlwaysShowSelDialog)
            {
                PluginDebug.AddInfo("Auto-Type Entry Selection window closed", 0, "Reason: No entries to display");
                f.Close();
                return;
            }
            if ((lv != null) && (lv.Items.Count == 1) && !Program.Config.Integration.AutoTypeAlwaysShowSelDialog)
            {
                lv.Items[0].Selected = true;
                try
                {
                    MethodInfo miPIS = f.GetType().GetMethod("ProcessItemSelection", BindingFlags.NonPublic | BindingFlags.Instance);
                    miPIS.Invoke(f, null);
                    PluginDebug.AddInfo("Auto-Type Entry Selection window closed", 0, "Reason: Only one entry to be shown");
                }
                catch (Exception ex)
                {
                    PluginDebug.AddError("Auto-Type Entry Selection window NOT closed", 0, "Reason: Could not process entry", "Details: " + ex.Message);
                }
                return;
            }
        }
Пример #27
0
        /// Calculate time offset for all relevant entries
        /// Do NOT use Task.Run as this requires .NET 4.5 which will cause issues on Mono
        /// Mono reports .NET 4.0.3 being installed despite higher versions can be used
        /// This results in KeePass refusing to compile the plgx
        public static /*async*/ void GetTimingsAsync(KeePassLib.PwDatabase db)
        {
            //Don't use TraverseTree as db content might change during processing
            //and this will result in an exception since TraverseTree uses 'foreach'

            //Don't use Task at all (https://github.com/Rookiestyle/KeePassOTP/issues/31)
            KeePassLib.Delegates.GAction <object> act = new KeePassLib.Delegates.GAction <object>((object o) =>
            {
                DateTime dtStart          = DateTime.Now;
                IEnumerable <string> lURL = db.RootGroup.GetEntries(true).
                                            Where(e => OTPDAO.OTPDefined(e) != OTPDAO.OTPDefinition.None).          //We're not interested in sites without OTP being set up
                                            Select(e => e.Strings.ReadSafe(KeePassLib.PwDefs.UrlField)).Distinct(); //We're not interested in duplicate URLs
                foreach (string url in lURL)
                {
                    if (m_timeCorrectionUrls.ContainsKey(url))
                    {
                        continue;
                    }
                    GetTimeCorrection(url);
                    System.Threading.Thread.Sleep(100);
                }
                ;
                DateTime dtEnd = DateTime.Now;
                PluginDebug.AddInfo("Calculated OTP time corrections", 0, "Start: " + dtStart.ToLongTimeString(), "End: " + dtEnd.ToLongTimeString());
            });
            System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(act));
        }
Пример #28
0
        public static KeePass_Update.KeePassInstallType VerifyKeePassInstallType()
        {
            //By default, KeePass-Setup.exe installs to Program Files\KeePass Password Safe 2 / Program Files (x86)\KeePass Password Safe 2
            //By default, KeePass.msi installs to Program Files\KeePass2x / Program Files (x86)\KeePass2x

            var    lSpecialFolders = new System.Collections.Generic.List <string>();
            string sFolder         = Environment.GetEnvironmentVariable("ProgramFiles(x86)");

            if (!string.IsNullOrEmpty(sFolder))
            {
                lSpecialFolders.Add(sFolder);
            }

            try
            {
                //Environment.SpecialFolder.ProgramFilesX86
                sFolder = Environment.GetFolderPath((Environment.SpecialFolder) 42);
                if (!string.IsNullOrEmpty(sFolder))
                {
                    lSpecialFolders.Add(sFolder);
                }
            }
            catch { }

            sFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
            if (!string.IsNullOrEmpty(sFolder))
            {
                lSpecialFolders.Add(sFolder);
            }

            sFolder = KeePassLib.Utility.UrlUtil.GetFileDirectory(KeePass.Util.WinUtil.GetExecutable(), true, true);

            var lMsg = new System.Collections.Generic.List <string>();

            lMsg.AddRange(lSpecialFolders);
            lMsg.Add("KeePass path: " + sFolder);
            sFolder = sFolder.ToLowerInvariant();

            var result = KeePass_Update.KeePassInstallType.Portable;

            if (string.IsNullOrEmpty(lSpecialFolders.Find(x => sFolder.StartsWith(x.ToLowerInvariant()))))
            {
                result = KeePass_Update.KeePassInstallType.Portable;
            }
            else if (sFolder.Contains("keepass password safe 2"))
            {
                result = KeePass_Update.KeePassInstallType.Setup;
            }
            else if (sFolder.Contains("keepass2x"))
            {
                result = KeePass_Update.KeePassInstallType.MSI;
            }

            lMsg.Add(result.ToString());

            PluginDebug.AddInfo("Verify KeePass install type", 0, lMsg.ToArray());

            return(result);
        }
Пример #29
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);
            }
        private void PrepareEntryForm()
        {
            m_pweForm.PasswordGeneratorContextMenu.Opening     += ProfilesOpening;
            m_pweForm.PasswordGeneratorContextMenu.ItemClicked += ProfileClicked;
            m_pweForm.FormClosed += OnFormClosed;
            m_pwgForm             = null;
            LoadDBProfiles();

            //try to get the edit mode
            var spb = DoShowPCAButton();

            if (spb == ShowPCAButton.Error)
            {
                m_pweForm.Shown += OnEntryFormShown;                                         //Reading the edit mode failed, try this as fallback
            }
            else if (spb == ShowPCAButton.NoShowMultiple)
            {
                PluginDebug.AddInfo("Multiple entries selected - No PCA button added", 0);
                return;
            }
            else if (spb == ShowPCAButton.NoShowOthers)
            {
                PluginDebug.AddInfo("Neither CREATE nor EDIT mode - No PCA button added", 0);
                return;
            }
            SaveOldPassword();

            m_pweForm.Resize += OnEntryFormResize;

            //create plugin button right below the button for generating a new password
            CreatePCAButton();

            #region add context menu to plugin button
            ContextMenuStrip  cmsPCA   = new ContextMenuStrip();
            ToolStripMenuItem menuitem = new ToolStripMenuItem(PluginTranslate.OldPWCopy, m_btnPCA.Image, PasswordCopyClick);
            menuitem.Name = PluginTranslate.PluginName + "OldCopy";
            cmsPCA.Items.Add(menuitem);
            menuitem      = new ToolStripMenuItem(PluginTranslate.OldPWType, m_btnPCA.Image, PasswordTypeClick);
            menuitem.Name = PluginTranslate.PluginName + "OldType";
            cmsPCA.Items.Add(menuitem);
            menuitem      = new ToolStripMenuItem(PluginTranslate.NewPWCopy, m_btnPCA.Image, PasswordCopyClick);
            menuitem.Name = PluginTranslate.PluginName + "NewCopy";
            cmsPCA.Items.Add(menuitem);
            menuitem      = new ToolStripMenuItem(PluginTranslate.NewPWType, m_btnPCA.Image, PasswordTypeClick);
            menuitem.Name = PluginTranslate.PluginName + "NewType";
            cmsPCA.Items.Add(menuitem);
            cmsPCA.Items.Add(new ToolStripSeparator());
            menuitem      = new ToolStripMenuItem(PluginTranslate.PluginName + "...", m_btnPCA.Image, ShowPCAFormFromEntry);
            menuitem.Name = PluginTranslate.PluginName + "ShowPCAFormFromEntry";
            cmsPCA.Items.Add(menuitem);
            m_btnPCA.ContextMenuStrip = cmsPCA;
            cmsPCA.Opening           += cmsPCAOpening;
            m_btnPCA.Click           += (o, x) => m_btnPCA.ContextMenuStrip.Show(m_btnPCA, 0, m_btnPCA.Height);
            #endregion

            //finally add the button to the form
            m_btnPCA.BringToFront();
        }