Пример #1
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));
        }
        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 { }
        }
Пример #3
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());
            }
                                                         );
        }
Пример #4
0
 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 System.Threading.Tasks.Task.Run(() =>
     {
         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);
         }
         ;
     }
                                           );
 }
Пример #5
0
        private void GlobalWindowManager_WindowAdded(object sender, GwmWindowEventArgs e)
        {
            if (!m_bOTPHotkeyPressed)
            {
                return;
            }
            if (!(e.Form is AutoTypeCtxForm))
            {
                return;
            }

            PluginDebug.AddInfo("Auto-Type entry selection window added", 0);

            List <AutoTypeCtx> lCtx = (List <AutoTypeCtx>)Tools.GetField("m_lCtxs", e.Form);

            if (lCtx == null)
            {
                return;
            }

            //Adjust sequence to show correct auto-type sequence
            //Remove lines that don't have KPOTP defined
            int PrevCount = lCtx.Count;

            lCtx.RemoveAll(x => OTPDAO.OTPDefined(x.Entry) == OTPDAO.OTPDefinition.None);
            PluginDebug.AddInfo("Removed sequences without valid OTP settings", 0,
                                "Before: " + PrevCount.ToString(),
                                "After: " + lCtx.Count.ToString());

            //If now 0 or 1 entries remain, we need to hook the Shown event
            //simply to close it
            //We do not want to display an entry selection form with less then 2 entries
            if (lCtx.Count < 2)
            {
                e.Form.Shown += OnAutoTypeFormShown;
            }
        }
 private void OnTimerTick(object sender, EventArgs e)
 {
     if (m_bUpdateInProgress)
     {
         return;
     }
     m_bUpdateInProgress = true;
     //Trigger refresh of entry list if at least one relevant entry is shown
     //Relevant = Entry has OTP settings defined
     try
     {
         if (KeePass.Program.MainForm.UIIsInteractionBlocked())
         {
             return;
         }
         if (!KeePass.Program.MainForm.Visible)
         {
             return;
         }
         if (!KeePass.Program.MainForm.ActiveDatabase.IsOpen)
         {
             return;
         }
         if (KeePass.Program.Config.MainWindow.EntryListColumns.Find(x => x.CustomName == KPOTPColumnName) == null)
         {
             return;
         }
         PwGroup pg = KeePass.Program.MainForm.GetSelectedGroup();
         if (pg == null)
         {
             return;
         }
         bool bRefresh = pg.GetEntries(KeePass.Program.Config.MainWindow.ShowEntriesOfSubGroups).FirstOrDefault(x => OTPDAO.OTPDefined(x) == OTPDAO.OTPDefinition.Complete) != null;
         if (!bRefresh && !ForceUpdate)
         {
             return;                                            //Update entry list if OTP DB was closed / deleted
         }
         if (ForceUpdate)
         {
             ForceUpdate = false;
         }
         bool LVPossible = LV_DirectUpdate();
         if (!LVPossible)
         {
             KeePass.Program.MainForm.RefreshEntriesList();
         }
     }
     finally { m_bUpdateInProgress = false; }
 }