예제 #1
0
        private void FieldAction(ToolStripMenuItem Item, string FieldName, FIELD_ACTION action)
        {
            if (Item == null)
            {
                return;
            }

            PwEntry Entry = (PwEntry)Item.Tag;

            if (Entry == null)
            {
                return;
            }
            SetLastOne(Item);
            if (FieldName == PwDefs.PasswordField && PwDefs.IsTanEntry(Entry))
            {
                Entry.ExpiryTime = DateTime.Now;
                Entry.Expires    = true;
                Host.MainWindow.RefreshEntriesList();
                Host.MainWindow.UpdateUI(false, null, false, null, false, null, true);
            }

            if (action == FIELD_ACTION.CLIPBOARD_COPY)
            {
                ClipboardUtil.CopyAndMinimize(Entry.Strings.GetSafe(FieldName),
                                              true, Program.Config.MainWindow.MinimizeAfterClipboardCopy ?
                                              Host.MainWindow : null, Entry, Host.MainWindow.DocumentManager.ActiveDatabase);
                Host.MainWindow.StartClipboardCountdown();
            }
            else if (action == FIELD_ACTION.DRAG_DROP)
            {
                Item.DoDragDrop(Entry.Strings.ReadSafe(FieldName), DragDropEffects.Copy);
            }
        }
예제 #2
0
        /// <summary>
        /// Test whether an entry is a TAN entry and if so, expire it, provided
        /// that the option for expiring TANs on use is enabled.
        /// </summary>
        /// <param name="pe">Entry.</param>
        /// <returns>If the entry has been modified, the return value is
        /// <c>true</c>, otherwise <c>false</c>.</returns>
        public static bool ExpireTanEntryIfOption(PwEntry pe, PwDatabase pdContext)
        {
            if (pe == null)
            {
                throw new ArgumentNullException("pe");
            }
            // pdContext may be null
            if (!PwDefs.IsTanEntry(pe))
            {
                return(false);                                   // No assert
            }
            if (Program.Config.Defaults.TanExpiresOnUse)
            {
                pe.ExpiryTime = DateTime.Now;
                pe.Expires    = true;
                pe.Touch(true);
                if (pdContext != null)
                {
                    pdContext.Modified = true;
                }
                return(true);
            }

            return(false);
        }
예제 #3
0
        public int CompareEntries(PwEntry x, PwEntry y)
        {
            String nameX = x.Strings.ReadSafe(PwDefs.TitleField);
            String nameY = y.Strings.ReadSafe(PwDefs.TitleField);

            if (nameX.ToLower() != nameY.ToLower())
            {
                return(String.Compare(nameX, nameY, StringComparison.CurrentCultureIgnoreCase));
            }
            else
            {
                if (PwDefs.IsTanEntry(x) && PwDefs.IsTanEntry(y))
                {
                    //compare the user name fields (=TAN index)
                    String userX = x.Strings.ReadSafe(PwDefs.UserNameField);
                    String userY = y.Strings.ReadSafe(PwDefs.UserNameField);
                    if (userX != userY)
                    {
                        try
                        {
                            return(int.Parse(userX).CompareTo(int.Parse(userY)));
                        }
                        catch (Exception)
                        {
                            //ignore
                        }
                        return(String.Compare(userX, userY, StringComparison.CurrentCultureIgnoreCase));
                    }
                }

                //use creation time for non-tan entries:

                return(x.CreationTime.CompareTo(y.CreationTime));
            }
        }
        public static string CreateSummaryList(PwGroup pgSubGroups, PwEntry[] vEntries)
        {
            int    nMaxEntries = 10;
            string strSummary  = string.Empty;

            if (pgSubGroups != null)
            {
                PwObjectList <PwGroup> vGroups = pgSubGroups.GetGroups(true);
                if (vGroups.UCount > 0)
                {
                    StringBuilder sbGroups = new StringBuilder();
                    sbGroups.Append("- ");
                    uint uToList = Math.Min(3U, vGroups.UCount);
                    for (uint u = 0; u < uToList; ++u)
                    {
                        if (sbGroups.Length > 2)
                        {
                            sbGroups.Append(", ");
                        }
                        sbGroups.Append(vGroups.GetAt(u).Name);
                    }
                    if (uToList < vGroups.UCount)
                    {
                        sbGroups.Append(", ...");
                    }
                    strSummary += sbGroups.ToString();                     // New line below

                    nMaxEntries -= 2;
                }
            }

            int nSummaryShow = Math.Min(nMaxEntries, vEntries.Length);

            if (nSummaryShow == (vEntries.Length - 1))
            {
                --nSummaryShow;                                                   // Plural msg
            }
            for (int iSumEnum = 0; iSumEnum < nSummaryShow; ++iSumEnum)
            {
                if (strSummary.Length > 0)
                {
                    strSummary += MessageService.NewLine;
                }

                PwEntry pe = vEntries[iSumEnum];
                strSummary += ("- " + StrUtil.CompactString3Dots(
                                   pe.Strings.ReadSafe(PwDefs.TitleField), 39));
                if (PwDefs.IsTanEntry(pe))
                {
                    string strTanIdx = pe.Strings.ReadSafe(PwDefs.UserNameField);
                    if (!string.IsNullOrEmpty(strTanIdx))
                    {
                        strSummary += (@" (#" + strTanIdx + @")");
                    }
                }
            }

            return(strSummary);
        }
예제 #5
0
        public static void ExpireTanEntry(PwEntry pe)
        {
            if (pe == null)
            {
                throw new ArgumentNullException("pe");
            }
            Debug.Assert(PwDefs.IsTanEntry(pe));

            if (Program.Config.Defaults.TanExpiresOnUse)
            {
                pe.ExpiryTime = DateTime.Now;
                pe.Expires    = true;
                pe.Touch(true);
            }
        }
예제 #6
0
            // Ported from KeePass because it is private
            private static bool ListContainsOnlyTans(PwObjectList <PwEntry> vEntries)
            {
                if (vEntries == null)
                {
                    Debug.Assert(false); return(true);
                }

                foreach (PwEntry pe in vEntries)
                {
                    if (!PwDefs.IsTanEntry(pe))
                    {
                        return(false);
                    }
                }

                return(true);
            }
예제 #7
0
        /// <summary>
        /// Test whether an entry is a TAN entry and if so, expire it, provided
        /// that the option for expiring TANs on use is enabled.
        /// </summary>
        /// <param name="pe">Entry.</param>
        /// <returns>If the entry has been modified, the return value is
        /// <c>true</c>, otherwise <c>false</c>.</returns>
        public static bool ExpireTanEntryIfOption(PwEntry pe)
        {
            if (pe == null)
            {
                throw new ArgumentNullException("pe");
            }
            if (!PwDefs.IsTanEntry(pe))
            {
                return(false);                                   // No assert
            }
            if (Program.Config.Defaults.TanExpiresOnUse)
            {
                pe.ExpiryTime = DateTime.Now;
                pe.Expires    = true;
                pe.Touch(true);
                return(true);
            }

            return(false);
        }
예제 #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);

            long usageCount = prefs.GetLong(GetString(Resource.String.UsageCount_key), 0);

            ISharedPreferencesEditor edit = prefs.Edit();

            edit.PutLong(GetString(Resource.String.UsageCount_key), usageCount + 1);
            edit.Commit();

            _showPassword =
                !prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default));

            RequestWindowFeature(WindowFeatures.IndeterminateProgress);

            _activityDesign.ApplyTheme();
            base.OnCreate(savedInstanceState);



            SetEntryView();

            Database db = App.Kp2a.GetDb();

            // Likely the app has been killed exit the activity
            if (!db.Loaded || (App.Kp2a.QuickLocked))
            {
                Finish();
                return;
            }

            SetResult(KeePass.ExitNormal);

            Intent i    = Intent;
            PwUuid uuid = new PwUuid(MemUtil.HexStringToByteArray(i.GetStringExtra(KeyEntry)));

            _pos = i.GetIntExtra(KeyRefreshPos, -1);

            _appTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);

            Entry = db.Entries[uuid];

            // Refresh Menu contents in case onCreateMenuOptions was called before Entry was set
            ActivityCompat.InvalidateOptionsMenu(this);

            // Update last access time.
            Entry.Touch(false);

            if (PwDefs.IsTanEntry(Entry) && prefs.GetBoolean(GetString(Resource.String.TanExpiresOnUse_key), Resources.GetBoolean(Resource.Boolean.TanExpiresOnUse_default)) && ((Entry.Expires == false) || Entry.ExpiryTime > DateTime.Now))
            {
                PwEntry backupEntry = Entry.CloneDeep();
                Entry.ExpiryTime = DateTime.Now;
                Entry.Expires    = true;
                Entry.Touch(true);
                RequiresRefresh();
                UpdateEntry  update = new UpdateEntry(this, App.Kp2a, backupEntry, Entry, null);
                ProgressTask pt     = new ProgressTask(App.Kp2a, this, update);
                pt.Run();
            }
            FillData();

            SetupEditButtons();

            App.Kp2a.GetDb().LastOpenedEntry = new PwEntryOutput(Entry, App.Kp2a.GetDb().KpDatabase);

            _pluginActionReceiver = new PluginActionReceiver(this);
            RegisterReceiver(_pluginActionReceiver, new IntentFilter(Strings.ActionAddEntryAction));
            _pluginFieldReceiver = new PluginFieldReceiver(this);
            RegisterReceiver(_pluginFieldReceiver, new IntentFilter(Strings.ActionSetEntryField));

            new Thread(NotifyPluginsOnOpen).Start();

            //the rest of the things to do depends on the current app task:
            _appTask.CompleteOnCreateEntryActivity(this);
        }
예제 #9
0
        private static string GetSequenceForWindow(PwEntry pwe, string strWindow, bool bRequireDefinedWindow)
        {
            Debug.Assert(strWindow != null); if (strWindow == null)
            {
                return(null);
            }
            Debug.Assert(pwe != null); if (pwe == null)
            {
                return(null);
            }

            if (pwe.AutoType.Enabled == false)
            {
                return(null);
            }

            string strSeq = null;

            foreach (KeyValuePair <string, string> kvp in pwe.AutoType.WindowSequencePairs)
            {
                if (MatchWindows(kvp.Key, strWindow))
                {
                    strSeq = kvp.Value;
                    break;
                }
            }

            string strTitle = pwe.Strings.ReadSafe(PwDefs.TitleField);

            if (((strSeq == null) || (strSeq.Length == 0)) &&
                (strTitle.Length > 0) &&
                (strWindow.IndexOf(strTitle, StrCaseIgnoreCmp) >= 0))
            {
                strSeq = pwe.AutoType.DefaultSequence;
                Debug.Assert(strSeq != null);
            }

            if ((strSeq == null) && bRequireDefinedWindow)
            {
                return(null);
            }

            // Assume default sequence now
            if ((strSeq == null) || (strSeq.Length == 0))
            {
                strSeq = pwe.AutoType.DefaultSequence;
            }

            PwGroup pg = pwe.ParentGroup;

            while (pg != null)
            {
                if (strSeq.Length != 0)
                {
                    break;
                }

                strSeq = pg.DefaultAutoTypeSequence;
                pg     = pg.ParentGroup;
            }

            if (strSeq.Length != 0)
            {
                return(strSeq);
            }

            if (PwDefs.IsTanEntry(pwe))
            {
                return(PwDefs.DefaultAutoTypeSequenceTan);
            }
            return(PwDefs.DefaultAutoTypeSequence);
        }
예제 #10
0
        internal static List <object> FindExpired(PwDatabase db, IStatusLogger sl, out Action <ListView> fInit, bool bOnlyExpired, int iExpDays, int iExpMonths)
        {
            List <object> l = new List <object>();

            fInit = PrepareListView();

            PwGroup pg = new PwGroup(true, true, string.Empty, PwIcon.Expired);

            pg.IsVirtual = true;

            bool bExpInP = bOnlyExpired;               // Past
            bool bExpInF = (iExpDays == int.MaxValue); // Future
            bool bExpInI = !bExpInP && !bExpInF;       // Interval

            DateTime dtNow   = DateTime.UtcNow;
            DateTime dtLimit = dtNow;

            if (bExpInI)
            {
                if (iExpDays > 0)
                {
                    dtLimit = dtNow.AddDays(iExpDays);
                }
                else if (iExpMonths > 0)
                {
                    dtLimit = dtNow.AddMonths(iExpMonths);
                }

                dtLimit = KeePassLib.Utility.TimeUtil.ToLocal(dtLimit, false);
                dtLimit = dtLimit.Date.Add(new TimeSpan(23, 59, 59));
                dtLimit = KeePassLib.Utility.TimeUtil.ToUtc(dtLimit, false);
            }

            KeePassLib.Delegates.EntryHandler eh = delegate(PwEntry pe)
            {
                if (!pe.Expires)
                {
                    return(true);
                }
                if (!pe.GetSearchingEnabled())
                {
                    return(true);
                }
                if (PwDefs.IsTanEntry(pe))
                {
                    return(true);                                       // Exclude TANs
                }
                int iRelNow = pe.ExpiryTime.CompareTo(dtNow);

                if ((bExpInP && (iRelNow <= 0)) ||
                    (bExpInI && (pe.ExpiryTime <= dtLimit) && (iRelNow > 0)) ||
                    (bExpInF && (iRelNow > 0)))
                {
                    pg.AddEntry(pe, false, false);
                }
                return(true);
            };

            db.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);

            if (pg.Entries.UCount == 0)
            {
                return(l);
            }

            l = MapResults(pg);
            return(l);
        }