Ejemplo n.º 1
0
        /// <summary>
        /// Propagates possible changes of a rootNode to all of his proxyNodes
        /// </summary>
        /// <param name="root">The rootNode we want to propagate</param>
        /// <returns>True if the function has made changes to the database.</returns>
        private Changes UpdateProxyInformation(PwEntry root)
        {
            Changes changeFlag = Changes.None;
            //get all relevant proxies
            //copy new information from root to proxies
            PwObjectList <PwEntry> allProxies = m_database.GetAllProxyNodes();

            foreach (PwEntry proxy in allProxies)
            {
                //check if the proxy matches to the root and has changes! if not we are done here
                if (proxy.IsProxyOf(root) && !proxy.IsSimilarTo(root, true))
                {
                    PwGroup parent  = proxy.ParentGroup;
                    bool    success = parent.Entries.Remove(proxy);
                    Debug.Assert(success);
                    PwEntry duplicate = root.CloneDeep();
                    duplicate.Uuid = proxy.Uuid;
                    //if the rootNode was a userRoot, the StringFiledUidLink is set automatically in a clone
                    //but if not we have to set it manually
                    if (!root.IsUserRootNode())
                    {
                        duplicate.MakeToProxyOf(root);
                    }
                    duplicate.SetParent(parent);
                    changeFlag |= Changes.EntryCreated;
                }
            }
            return(changeFlag);
        }
Ejemplo n.º 2
0
        private void CreateNewFromStandardTemplate(PwEntry templateEntry)
        {
            var newEntry = templateEntry.CloneDeep();

            newEntry.SetUuid(new PwUuid(true), true);             // Create new UUID
            newEntry.CreationTime = newEntry.LastModificationTime = newEntry.LastAccessTime = DateTime.Now;
            State.EntryInDatabase = newEntry;
        }
        private static PwEntry CreateCopy(PwEntry entry, IKp2aApp app)
        {
            var newEntry = entry.CloneDeep();

            newEntry.SetUuid(new PwUuid(true), true);             // Create new UUID
            string strTitle = newEntry.Strings.ReadSafe(PwDefs.TitleField);

            newEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(
                                     false, strTitle + " - " + app.GetResourceString(UiStringKey.DuplicateTitle)));

            return(newEntry);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The function checks if thelast made change has to be propageted to
        /// some referenced PwEntries
        /// </summary>
        /// <returns>True if the function has made changes to the database.</returns>
        private Changes CheckReferences()
        {
            PwEntry lastModifiedEntry = GetLastModifiedEntry();

            //if there are no changes, then we have nothing to do
            if (lastModifiedEntry == null)
            {
                return(Changes.None);
            }
            //was it a proxy or not?
            Changes changeFlag = Changes.None;

            if (lastModifiedEntry.IsProxyNode())
            {
                //lets update the root so we later can update all proxies
                PwEntry root = m_database.GetProxyTargetFor(lastModifiedEntry);
                //check if there are real changes! if not we are done here
                if (lastModifiedEntry.IsSimilarTo(root, true))
                {
                    return(Changes.None);
                }
                PwGroup parent = root.ParentGroup;

                root.CreateBackup(m_database); //rootNode_X should save all modifications in history
                parent.Entries.Remove(root);

                PwEntry updatedRoot = lastModifiedEntry.CloneDeep();
                updatedRoot.Uuid = root.Uuid;
                updatedRoot.SetParent(parent);
                //special handling for userRootNodes because they have a homefolder
                if (root.IsUserRootNode())
                {
                    //maybe the oldUserName has changed to => the homefolder should have the new name also
                    //we also want to have the same icons everywhere
                    parent.Name   = updatedRoot.GetTitle();
                    parent.IconId = updatedRoot.IconId;
                }
                else
                {
                    updatedRoot.Strings.Remove(KeeShare.UuidLinkField);
                }
                changeFlag |= UpdateProxyInformation(updatedRoot);
                changeFlag |= Changes.GroupDeleted;
            }
            else
            {
                changeFlag |= UpdateProxyInformation(lastModifiedEntry);
            }
            pe_lastModedEntry = GetLastModifiedEntry();
            return(changeFlag);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// creates a new ProxyNode for the specified user. This Proxy can be used to mark a
        /// PwGroup as "shared" to this user.
        /// </summary>
        /// <param name="name">oldUserName you want to have a proxyNode of</param>
        /// <returns>PwEntry ProxyNode of the specified user</returns>
        public static PwEntry CreateProxyNode(PwEntry rootNode)
        {
            Debug.Assert(rootNode != null, "CreateProxy got rootNode==null!");

            string uuid = rootNode.Strings.Exists(KeeShare.UuidLinkField) ? rootNode.Strings.ReadSafe(KeeShare.UuidLinkField) : rootNode.Uuid.ToHexString();
            PwEntry proxy = rootNode.CloneDeep();
            proxy.SetUuid(new PwUuid(true), false);

            Debug.Assert(KeeShare.UuidLinkField != "", "CreateProxy has an empty linkIdentifier!");

            proxy.Strings.Set(KeeShare.UuidLinkField, new ProtectedString(true, uuid));

            Debug.Assert(proxy != null, "CreateProxy would return null!");

            return proxy;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// creates a new ProxyNode for the specified user. This Proxy can be used to mark a
        /// PwGroup as "shared" to this user.
        /// </summary>
        /// <param name="name">oldUserName you want to have a proxyNode of</param>
        /// <returns>PwEntry ProxyNode of the specified user</returns>
        public static PwEntry CreateProxyNode(this PwEntry entry)
        {
            Debug.Assert(entry != null, "CreateProxy got rootNode==null!");

            string  uuid  = entry.Strings.Exists(KeeShare.UuidLinkField) ? entry.Strings.ReadSafe(KeeShare.UuidLinkField) : entry.Uuid.ToHexString();
            PwEntry proxy = entry.CloneDeep();

            proxy.SetUuid(new PwUuid(true), false);

            Debug.Assert(KeeShare.UuidLinkField != "", "CreateProxy has an empty linkIdentifier!");

            proxy.Strings.Set(KeeShare.UuidLinkField, new ProtectedString(true, uuid));

            Debug.Assert(proxy != null, "CreateProxy would return null!");

            return(proxy);
        }
Ejemplo n.º 7
0
            private bool SaveEntryStatus(ListViewItem Item, PwIcon icon, string text)
            {
                PwListItem pli = (((ListViewItem)Item).Tag as PwListItem);

                if (pli == null)
                {
                    Debug.Assert(false); return(false);
                }
                PwEntry pe = pli.Entry;

                pe = m_host.Database.RootGroup.FindEntry(pe.Uuid, true);

                var protString = pe.Strings.Get(PwDefs.PasswordField);

                if (protString != null && !protString.IsEmpty)
                {
                    return(false);
                }

                PwEntry peInit = pe.CloneDeep();

                pe.CreateBackup(null);
                pe.Touch(true, false); // Touch *after* backup


                pe.IconId       = icon;
                Item.ImageIndex = (int)icon;

                pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, text));
                Item.SubItems[getSubitemOfField(KeePass.App.Configuration.AceColumnType.UserName)].Text = text;

                PwCompareOptions cmpOpt = (PwCompareOptions.IgnoreLastMod | PwCompareOptions.IgnoreLastAccess | PwCompareOptions.IgnoreLastBackup);

                if (pe.EqualsEntry(peInit, cmpOpt, MemProtCmpMode.None))
                {
                    pe.LastModificationTime = peInit.LastModificationTime;

                    pe.History.Remove(pe.History.GetAt(pe.History.UCount - 1)); // Undo backup

                    return(false);
                }
                else
                {
                    return(true);
                }
            }
Ejemplo n.º 8
0
            private void txtNotes_TextChanged(object sender, EventArgs e)
            {
                PwDatabase pwStorage = m_host.Database;
                PwEntry    pe        = m_host.MainWindow.GetSelectedEntry(true);

                if (txtNotes.Tag == null)
                {
                    // Text has just started changing, backup the original entry and save it in Tag property, which we'll use later do determine whether the entry is modified or not
                    pe.CreateBackup(null);
                    pe.Touch(true, false);                     // Touch *after* backup

                    txtNotes.Tag = pe.CloneDeep();
                }

                pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pwStorage.MemoryProtection.ProtectNotes, txtNotes.Text));
                Util.UpdateSaveState();                 // Make save icon enabled
            }
Ejemplo n.º 9
0
        internal void AddUrlToEntry(string url, Action finishAction)
        {
            PwEntry initialEntry = Entry.CloneDeep();

            PwEntry newEntry = Entry;

            newEntry.History = newEntry.History.CloneDeep();
            newEntry.CreateBackup(null);

            newEntry.Touch(true, false);             // Touch *after* backup

            //if there is no URL in the entry, set that field. If it's already in use, use an additional (not existing) field
            if (String.IsNullOrEmpty(newEntry.Strings.ReadSafe(PwDefs.UrlField)))
            {
                newEntry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, url));
            }
            else
            {
                int c = 1;
                while (newEntry.Strings.Get("KP2A_URL_" + c) != null)
                {
                    c++;
                }

                newEntry.Strings.Set("KP2A_URL_" + c, new ProtectedString(false, url));
            }

            //save the entry:

            ActionOnFinish closeOrShowError = new ActionOnFinish((success, message) =>
            {
                OnFinish.DisplayMessage(this, message);
                finishAction();
            });


            RunnableOnFinish runnable = new UpdateEntry(this, App.Kp2a, initialEntry, newEntry, closeOrShowError);

            ProgressTask pt = new ProgressTask(App.Kp2a, this, runnable);

            pt.Run();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// The function compares two PwEntries in every scope except the Uuid
        /// </summary>
        /// <param name="entry">the first entry</param>
        /// <param name="otherEntry">the second entry</param>
        /// <param name="bIgnoreKeeShareFields">Should the KeeShare-specific fields be ignored?</param>
        /// <returns>True if both entries are equal in all field, accordingly to the parametersettings</returns>
        public static bool IsSimilarTo(this PwEntry entry, PwEntry otherEntry, bool bIgnoreKeeShareFields)
        {
            //if both are null they are equal
            if (entry == null && otherEntry == null)
            {
                return(true);
            }
            //if only one of them is null we could not clone it => they are not equal
            if (entry == null || otherEntry == null)
            {
                return(false);
            }

            // only clone both entries if we need to
            PwEntry myCopy    = entry.CloneDeep();
            PwEntry otherCopy = otherEntry;

            if (bIgnoreKeeShareFields)
            {
                myCopy.Strings.Remove(KeeShare.UuidLinkField);
                otherCopy = otherEntry.CloneDeep();
                otherCopy.Strings.Remove(KeeShare.UuidLinkField);
            }

            //we have to make the Uuids and creation times equal, because PwEntry.EqualsEntry compares these too
            //and returns false if they are not equal!!
            myCopy.SetUuid(otherCopy.Uuid, false);
            myCopy.CreationTime = otherCopy.CreationTime;

            PwCompareOptions opts = PwCompareOptions.IgnoreHistory
                                    | PwCompareOptions.IgnoreLastAccess
                                    | PwCompareOptions.IgnoreLastBackup
                                    | PwCompareOptions.IgnoreLastMod
                                    | PwCompareOptions.IgnoreParentGroup
                                    | PwCompareOptions.IgnoreTimes;

            return(myCopy.EqualsEntry(otherCopy, opts, MemProtCmpMode.Full));
        }
Ejemplo n.º 11
0
#pragma warning restore IDE1006

        public void CreateHistoryEntries(PwEntry pwEntry, PwDatabase pwDatabase, UserPrefs userPrefs)
        {
            if (this.passwordHistory != null)
            {
                List <PwEntry> historyEntries = new List <PwEntry>();

                foreach (PasswordHistory passwordHistory in this.passwordHistory)
                {
                    PwEntry historyEntry = pwEntry.CloneDeep();

                    historyEntry.CreationTime         = passwordHistory.time;
                    historyEntry.LastModificationTime = passwordHistory.time;

                    historyEntry.Strings.Set(PwDefs.PasswordField, new ProtectedString(pwDatabase.MemoryProtection.ProtectPassword, passwordHistory.value));

                    historyEntries.Add(historyEntry);
                }

                foreach (PwEntry historyEntry in historyEntries)
                {
                    pwEntry.History.Add(historyEntry);
                }
            }
        }
Ejemplo n.º 12
0
        private static void CreateEntry(PwEntry peTemplate)
        {
            if (peTemplate == null)
            {
                Debug.Assert(false); return;
            }

            PwDatabase pd = Program.MainForm.ActiveDatabase;

            if (pd == null)
            {
                Debug.Assert(false); return;
            }
            if (pd.IsOpen == false)
            {
                Debug.Assert(false); return;
            }

            PwGroup pgContainer = Program.MainForm.GetSelectedGroup();

            if (pgContainer == null)
            {
                pgContainer = pd.RootGroup;
            }

            PwEntry pe = peTemplate.Duplicate();

            pe.History.Clear();

            if (EntryTemplates.EntryCreating != null)
            {
                EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
                                                 peTemplate.CloneDeep(), pe));
            }

            PwEntryForm pef = new PwEntryForm();

            pef.InitEx(pe, PwEditMode.AddNewEntry, pd, Program.MainForm.ClientIcons,
                       false, true);

            if (UIUtil.ShowDialogAndDestroy(pef) == DialogResult.OK)
            {
                pgContainer.AddEntry(pe, true, true);

                MainForm mf = Program.MainForm;
                if (mf != null)
                {
                    mf.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                                true, null, true);

                    PwObjectList <PwEntry> vSelect = new PwObjectList <PwEntry>();
                    vSelect.Add(pe);
                    mf.SelectEntries(vSelect, true, true);

                    mf.EnsureVisibleEntry(pe.Uuid);
                    mf.UpdateUI(false, null, false, null, false, null, false);
                }
                else
                {
                    Debug.Assert(false);
                }

                if (EntryTemplates.EntryCreated != null)
                {
                    EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
                                                    peTemplate.CloneDeep(), pe));
                }
            }
            else
            {
                Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                                          pd.UINeedsIconUpdate, null, false);
            }
        }
Ejemplo n.º 13
0
            /*
             * // Get all user defined strings
             * internal static Dictionary<string, string> GetDictEntriesUserStrings(PwGroup pwg)
             * {
             *  Dictionary<string, string> strd = new Dictionary<string, string>();
             *  //SortedDictionary<string, string> strd = new SortedDictionary<string, string>();
             *
             *  // Add all known pwentry strings
             *  foreach (PwEntry pe in pwg.GetEntries(true))
             *  {
             *      foreach (KeyValuePair<string, ProtectedString> pstr in pe.Strings)
             *      {
             *          if (!strd.ContainsKey(pstr.Key))
             *          {
             *              if (!PwDefs.IsStandardField(pstr.Key))
             *              {
             *                  strd.Add(pstr.Key, pstr.Value.ReadString());
             *              }
             *          }
             *      }
             *  }
             *
             *  return strd;
             * }*/

            // Ported from KeePass Entry Dialog SaveEntry() and UpdateEntryStrings(...)
            internal static bool SaveEntry(PwDatabase pwStorage, ListViewItem Item, int SubItem, string Text)
            {
                PwListItem pli = (((ListViewItem)Item).Tag as PwListItem);

                if (pli == null)
                {
                    Debug.Assert(false); return(false);
                }
                PwEntry pe = pli.Entry;

                pe = pwStorage.RootGroup.FindEntry(pe.Uuid, true);

                PwEntry peInit = pe.CloneDeep();

                pe.CreateBackup(null);
                pe.Touch(true, false); // Touch *after* backup

                int           colID   = SubItem;
                AceColumn     col     = GetAceColumn(colID);
                AceColumnType colType = col.Type;

                switch (colType)
                {
                case AceColumnType.Title:
                    //if(PwDefs.IsTanEntry(pe))
                    //TODO tan list	 TanTitle ???		    pe.Strings.Set(PwDefs.TanTitle, new ProtectedString(false, Text));
                    //else
                    pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pwStorage.MemoryProtection.ProtectTitle, Text));
                    break;

                case AceColumnType.UserName:
                    pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pwStorage.MemoryProtection.ProtectUserName, Text));
                    break;

                case AceColumnType.Password:
                    //byte[] pb = Text.ToUtf8();
                    //pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pwStorage.MemoryProtection.ProtectPassword, pb));
                    //MemUtil.ZeroByteArray(pb);
                    pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pwStorage.MemoryProtection.ProtectPassword, Text));
                    break;

                case AceColumnType.Url:
                    pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pwStorage.MemoryProtection.ProtectUrl, Text));
                    break;

                case AceColumnType.Notes:
                    pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pwStorage.MemoryProtection.ProtectNotes, Text));
                    break;

                case AceColumnType.OverrideUrl:
                    pe.OverrideUrl = Text;
                    break;

                case AceColumnType.Tags:
                    List <string> vNewTags = StrUtil.StringToTags(Text);
                    pe.Tags.Clear();
                    foreach (string strTag in vNewTags)
                    {
                        pe.AddTag(strTag);
                    }
                    break;

                case AceColumnType.CustomString:
                    pe.Strings.Set(col.CustomName, new ProtectedString(pe.Strings.GetSafe(col.CustomName).IsProtected, Text));
                    break;

                default:
                    // Nothing todo
                    break;
                }

                PwCompareOptions cmpOpt = (PwCompareOptions.IgnoreLastMod | PwCompareOptions.IgnoreLastAccess | PwCompareOptions.IgnoreLastBackup);

                if (pe.EqualsEntry(peInit, cmpOpt, MemProtCmpMode.None))
                {
                    pe.LastModificationTime = peInit.LastModificationTime;

                    pe.History.Remove(pe.History.GetAt(pe.History.UCount - 1)); // Undo backup

                    return(false);
                }
                else
                {
                    return(true);
                }
            }
Ejemplo n.º 14
0
        /// <summary>
        /// The function compares two PwEntries in every scope except the Uuid
        /// </summary>
        /// <param name="entry1">the first entry</param>
        /// <param name="entry2">the second entry</param>
        /// <param name="bIgnoreKeeShareFields">Should the KeeShare-specific fields be ignored?</param>
        /// <returns>True if both entries are equal in all field, accordingly to the parametersettings</returns>
        public static bool IsSimilarTo(this PwEntry entry1, PwEntry entry2, bool bIgnoreKeeShareFields)
        {
            //if both are null they are equal
            if (entry1 == null && entry2 == null)
            {
                return true;
            }
            //if only one of them is null we could not clone it => they are not equal
            if (entry1 == null || entry2 == null)
            {
                return false;
            }

            PwEntry copy1 = entry1.CloneDeep();
            PwEntry copy2 = entry2.CloneDeep();
            if (bIgnoreKeeShareFields)
            {
                copy1.Strings.Remove(KeeShare.UuidLinkField);
                copy2.Strings.Remove(KeeShare.UuidLinkField);
            }

            //we have to make the Uuids and creation times equal, because PwEntry.EqualsEntry compares these too
            //and returns false if they are not equal!!
            copy1.SetUuid(copy2.Uuid, false);
            copy1.CreationTime = copy2.CreationTime;

            PwCompareOptions opts = PwCompareOptions.IgnoreHistory
                | PwCompareOptions.IgnoreLastAccess
                | PwCompareOptions.IgnoreLastBackup
                | PwCompareOptions.IgnoreLastMod
                | PwCompareOptions.IgnoreParentGroup
                | PwCompareOptions.IgnoreTimes;
            return copy1.EqualsEntry(copy2, opts, MemProtCmpMode.Full);
        }
Ejemplo n.º 15
0
        private static void OnMenuExecute(object sender, EventArgs e)
        {
            ToolStripMenuItem tsmi = (sender as ToolStripMenuItem);

            if (tsmi == null)
            {
                Debug.Assert(false); return;
            }

            PwEntry peTemplate = (tsmi.Tag as PwEntry);

            if (peTemplate == null)
            {
                Debug.Assert(false); return;
            }

            MainForm mf = Program.MainForm;

            if (mf == null)
            {
                Debug.Assert(false); return;
            }

            PwDatabase pd = mf.ActiveDatabase;

            if ((pd == null) || !pd.IsOpen)
            {
                Debug.Assert(false); return;
            }

            // Ensure that the correct database is still active
            if (pd != mf.DocumentManager.FindContainerOf(peTemplate))
            {
                return;
            }

            GFunc <PwEntry> fNewEntry = delegate()
            {
                PwEntry pe = peTemplate.Duplicate();
                pe.History.Clear();
                return(pe);
            };

            Action <PwEntry> fAddPre = delegate(PwEntry pe)
            {
                if (EntryTemplates.EntryCreating != null)
                {
                    EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
                                                     peTemplate.CloneDeep(), pe));
                }
            };

            Action <PwEntry> fAddPost = delegate(PwEntry pe)
            {
                if (EntryTemplates.EntryCreated != null)
                {
                    EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
                                                    peTemplate.CloneDeep(), pe));
                }
            };

            mf.AddEntryEx(null, fNewEntry, fAddPre, fAddPost);
        }
Ejemplo n.º 16
0
        private static void CreateEntry(PwEntry peTemplate)
        {
            if(peTemplate == null) { Debug.Assert(false); return; }

            PwDatabase pd = Program.MainForm.ActiveDatabase;
            if(pd == null) { Debug.Assert(false); return; }
            if(pd.IsOpen == false) { Debug.Assert(false); return; }

            PwGroup pgContainer = Program.MainForm.GetSelectedGroup();
            if(pgContainer == null) pgContainer = pd.RootGroup;

            PwEntry pe = peTemplate.CloneDeep();
            pe.SetUuid(new PwUuid(true), true);
            pe.CreationTime = pe.LastModificationTime = pe.LastAccessTime = DateTime.Now;

            if(EntryTemplates.EntryCreating != null)
                EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
                    peTemplate.CloneDeep(), pe));

            PwEntryForm pef = new PwEntryForm();
            pef.InitEx(pe, PwEditMode.AddNewEntry, pd, Program.MainForm.ClientIcons,
                false, true);

            if(UIUtil.ShowDialogAndDestroy(pef) == DialogResult.OK)
            {
                pgContainer.AddEntry(pe, true, true);

                if(EntryTemplates.EntryCreated != null)
                    EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
                        peTemplate.CloneDeep(), pe));

                // Program.MainForm.UpdateEntryList(null, true);
                // Program.MainForm.UpdateUIState(true);
                Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                    true, null, true);
            }
            else Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                pd.UINeedsIconUpdate, null, false);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        private static void CreateEntry(PwEntry peTemplate)
        {
            if (peTemplate == null)
            {
                Debug.Assert(false); return;
            }

            PwDatabase pd = Program.MainForm.ActiveDatabase;

            if (pd == null)
            {
                Debug.Assert(false); return;
            }
            if (pd.IsOpen == false)
            {
                Debug.Assert(false); return;
            }

            PwGroup pgContainer = Program.MainForm.GetSelectedGroup();

            if (pgContainer == null)
            {
                pgContainer = pd.RootGroup;
            }

            PwEntry pe = peTemplate.CloneDeep();

            pe.Uuid         = new PwUuid(true);
            pe.CreationTime = pe.LastModificationTime = pe.LastAccessTime = DateTime.Now;

            if (EntryTemplates.EntryCreating != null)
            {
                EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
                                                 peTemplate.CloneDeep(), pe));
            }

            PwEntryForm pef = new PwEntryForm();

            pef.InitEx(pe, PwEditMode.AddNewEntry, pd, Program.MainForm.ClientIcons,
                       false, true);

            if (pef.ShowDialog() == DialogResult.OK)
            {
                pgContainer.AddEntry(pe, true, true);

                if (EntryTemplates.EntryCreated != null)
                {
                    EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
                                                    peTemplate.CloneDeep(), pe));
                }

                // Program.MainForm.UpdateEntryList(null, true);
                // Program.MainForm.UpdateUIState(true);
                Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                                          true, null, true);
            }
            else
            {
                Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                                          pd.UINeedsIconUpdate, null, false);
            }
        }
Ejemplo n.º 19
0
        private static void CreateEntry(PwEntry peTemplate)
        {
            if(peTemplate == null) { Debug.Assert(false); return; }

            PwDatabase pd = Program.MainForm.ActiveDatabase;
            if(pd == null) { Debug.Assert(false); return; }
            if(pd.IsOpen == false) { Debug.Assert(false); return; }

            PwGroup pgContainer = Program.MainForm.GetSelectedGroup();
            if(pgContainer == null) pgContainer = pd.RootGroup;

            PwEntry pe = peTemplate.Duplicate();

            if(EntryTemplates.EntryCreating != null)
                EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
                    peTemplate.CloneDeep(), pe));

            PwEntryForm pef = new PwEntryForm();
            pef.InitEx(pe, PwEditMode.AddNewEntry, pd, Program.MainForm.ClientIcons,
                false, true);

            if(UIUtil.ShowDialogAndDestroy(pef) == DialogResult.OK)
            {
                pgContainer.AddEntry(pe, true, true);

                MainForm mf = Program.MainForm;
                if(mf != null)
                {
                    mf.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                        true, null, true);

                    PwObjectList<PwEntry> vSelect = new PwObjectList<PwEntry>();
                    vSelect.Add(pe);
                    mf.SelectEntries(vSelect, true, true);

                    mf.EnsureVisibleEntry(pe.Uuid);
                    mf.UpdateUI(false, null, false, null, false, null, false);
                }
                else { Debug.Assert(false); }

                if(EntryTemplates.EntryCreated != null)
                    EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
                        peTemplate.CloneDeep(), pe));
            }
            else Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                pd.UINeedsIconUpdate, null, false);
        }
Ejemplo n.º 20
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));

            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.IndeterminateProgress);

            new ActivityDesign(this).ApplyTheme();

            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];
            Android.Util.Log.Debug("KP2A", "Notes: " + Entry.Strings.ReadSafe(PwDefs.NotesField));

            // 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();
            SetupMoveButtons ();

            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);
        }