예제 #1
0
        private void setTags(PwEntry pwe, string url = null)
        {
            pwe.AddTag("keebook_bookmark");

            if (!string.IsNullOrEmpty(url))
            {
                if (url.Contains("https://"))
                {
                    pwe.AddTag("keebook_secure_url");
                }
            }

            if (pwe.IconId != PwIcon.Star)
            {
                pwe.AddTag("keebook_custom_icon");
            }
        }
예제 #2
0
        private static void ImportEntry(JsonObject jo, Dictionary <string, PwGroup> dGroups,
                                        PwDatabase pd)
        {
            PwEntry pe = new PwEntry(true, true);

            PwGroup pg;
            string  strGroupID = (jo.GetValue <string>("folderId") ?? string.Empty);

            dGroups.TryGetValue(strGroupID, out pg);
            if (pg == null)
            {
                Debug.Assert(false); pg = dGroups[string.Empty];
            }
            pg.AddEntry(pe, true);

            ImportString(jo, "name", pe, PwDefs.TitleField, pd);
            ImportString(jo, "notes", pe, PwDefs.NotesField, pd);

            bool bFav = jo.GetValue <bool>("favorite", false);

            if (bFav)
            {
                pe.AddTag(PwDefs.FavoriteTag);
            }

            JsonObject joSub = jo.GetValue <JsonObject>("login");

            if (joSub != null)
            {
                ImportLogin(joSub, pe, pd);
            }

            joSub = jo.GetValue <JsonObject>("card");
            if (joSub != null)
            {
                ImportCard(joSub, pe, pd);
            }

            JsonObject[] v = jo.GetValueArray <JsonObject>("fields");
            if (v != null)
            {
                ImportFields(v, pe, pd);
            }

            joSub = jo.GetValue <JsonObject>("identity");
            if (joSub != null)
            {
                ImportIdentity(joSub, pe, pd);
            }
        }
        /// <summary>
        /// Adds breach tag to entry
        /// </summary>
        /// <param name="pwEntry"></param>
        /// <param name="breachCount"></param>
        /// <returns><c>true</c>, if breach tag has been newly added, otherwise <c>false</c></returns>
        private bool UpdateEntryWithBreachInformation(PwEntry pwEntry, int breachCount)
        {
            if (!pwEntry.Tags.Contains(BreachedTag))
            {
                pwEntry.AddTag(BreachedTag);

                if (breachCount > 0)
                {
                    pwEntry.CustomData.Set(BreachCountCustomDataName, breachCount.ToString());
                }

                return(true);
            }

            return(false);
        }
예제 #4
0
        private PwEntry CreateUserNode(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("name cannot be null or empty");
            }
            // TODO: Remove magic strings - these are propably defined in KeePass
            PwEntry entry = new PwEntry(true, true);

            entry.AddTag("user");
            entry.Strings.Set(KeeShare.TitleField, new ProtectedString(true, name));
            //the rootNode links against itself
            entry.Strings.Set(KeeShare.UuidLinkField, new ProtectedString(true, entry.Uuid.ToHexString()));
            //create the key which will be used to encrypt the delta-containers
            entry.Strings.Set(KeeShare.PasswordField, CreatePassword());
            entry.IconId = PwIcon.UserKey;
            return(entry);
        }
예제 #5
0
        private static void ProcessCsvLine(string[] vLine, PwDatabase pwStorage,
                                           SortedDictionary <string, PwGroup> dictGroups)
        {
            string strType = ParseCsvWord(vLine[0]);

            string strGroupName = ParseCsvWord(vLine[12]);             // + " - " + strType;

            if (strGroupName.Length == 0)
            {
                strGroupName = strType;
            }

            SplashIdMapping mp = null;

            foreach (SplashIdMapping mpFind in SplashIdCsv402.SplashIdMappings)
            {
                if (mpFind.TypeName == strType)
                {
                    mp = mpFind;
                    break;
                }
            }

            PwIcon pwIcon = ((mp != null) ? mp.Icon : PwIcon.Key);

            PwGroup pg = null;

            if (dictGroups.ContainsKey(strGroupName))
            {
                pg = dictGroups[strGroupName];
            }
            else
            {
                // PwIcon pwGroupIcon = ((pwIcon == PwIcon.Key) ?
                //	PwIcon.FolderOpen : pwIcon);
                // pg = new PwGroup(true, true, strGroupName, pwGroupIcon);

                pg      = new PwGroup(true, true);
                pg.Name = strGroupName;

                pwStorage.RootGroup.AddGroup(pg, true);
                dictGroups[strGroupName] = pg;
            }

            PwEntry pe = new PwEntry(true, true);

            pg.AddEntry(pe, true);

            pe.IconId = pwIcon;

            List <string> vTags = StrUtil.StringToTags(strType);

            foreach (string strTag in vTags)
            {
                pe.AddTag(strTag);
            }

            for (int iField = 0; iField < 9; ++iField)
            {
                string strData = ParseCsvWord(vLine[iField + 1]);
                if (strData.Length == 0)
                {
                    continue;
                }

                string strLookup = ((mp != null) ? mp.FieldNames[iField] :
                                    null);
                string strField = (strLookup ?? ("Field " + (iField + 1).ToString()));

                string strSep = ((strField != PwDefs.NotesField) ? ", " : "\r\n");
                ImportUtil.AppendToField(pe, strField, strData, pwStorage, strSep, false);
            }

            ImportUtil.AppendToField(pe, PwDefs.NotesField, ParseCsvWord(vLine[11]),
                                     pwStorage, "\r\n", false);

            DateTime?odt = TimeUtil.ParseUSTextDate(ParseCsvWord(vLine[10]),
                                                    DateTimeKind.Local);

            if (odt.HasValue)
            {
                DateTime dt = TimeUtil.ToUtc(odt.Value, false);
                pe.LastAccessTime       = dt;
                pe.LastModificationTime = dt;
            }
        }
예제 #6
0
        private static void AddEntry(string[] vLine, PwDatabase pd)
        {
            Debug.Assert((vLine.Length == 0) || (vLine.Length == 7));
            if (vLine.Length < 5)
            {
                return;
            }

            // Skip header line
            if ((vLine[1] == "username") && (vLine[2] == "password") &&
                (vLine[3] == "extra") && (vLine[4] == "name"))
            {
                return;
            }

            PwEntry pe = new PwEntry(true, true);

            PwGroup pg = pd.RootGroup;

            if (vLine.Length >= 6)
            {
                string strGroup = vLine[5];
                if (strGroup.Length > 0)
                {
                    pg = pg.FindCreateSubTree(strGroup, new string[1] {
                        "\\"
                    }, true);
                }
            }
            pg.AddEntry(pe, true);

            ImportUtil.AppendToField(pe, PwDefs.TitleField, vLine[4], pd);
            ImportUtil.AppendToField(pe, PwDefs.UserNameField, vLine[1], pd);
            ImportUtil.AppendToField(pe, PwDefs.PasswordField, vLine[2], pd);

            string strNotes   = vLine[3];
            bool   bIsSecNote = vLine[0].Equals("http://sn", StrUtil.CaseIgnoreCmp);

            if (bIsSecNote)
            {
                if (strNotes.StartsWith("NoteType:", StrUtil.CaseIgnoreCmp))
                {
                    AddNoteFields(pe, strNotes, pd);
                }
                else
                {
                    ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
                }
            }
            else             // Standard entry, no secure note
            {
                ImportUtil.AppendToField(pe, PwDefs.UrlField, vLine[0], pd);

                Debug.Assert(!strNotes.StartsWith("NoteType:"));
                ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
            }

            if (vLine.Length >= 7)
            {
                if (StrUtil.StringToBool(vLine[6]))
                {
                    pe.AddTag("Favorite");
                }
            }
        }
예제 #7
0
        private static void AddEntry(string[] vLine, PwDatabase pd,
			IDictionary<string, PwGroup> dGroups)
        {
            Debug.Assert((vLine.Length == 0) || (vLine.Length == 7));
            if(vLine.Length < 5) return;

            // Skip header line
            if((vLine[1] == "username") && (vLine[2] == "password") &&
                (vLine[3] == "extra") && (vLine[4] == "name"))
                return;

            PwEntry pe = new PwEntry(true, true);

            PwGroup pg = dGroups[string.Empty];
            if(vLine.Length >= 6)
            {
                string strGroup = vLine[5];
                if(!dGroups.TryGetValue(strGroup, out pg))
                {
                    pg = new PwGroup(true, true, strGroup, PwIcon.Folder);
                    pd.RootGroup.AddGroup(pg, true, true);
                    dGroups[strGroup] = pg;
                }
            }
            pg.AddEntry(pe, true, true);

            ImportUtil.AppendToField(pe, PwDefs.TitleField, vLine[4], pd);
            ImportUtil.AppendToField(pe, PwDefs.UserNameField, vLine[1], pd);
            ImportUtil.AppendToField(pe, PwDefs.PasswordField, vLine[2], pd);

            string strNotes = vLine[3];
            bool bIsSecNote = vLine[0].Equals("http://sn", StrUtil.CaseIgnoreCmp);
            if(bIsSecNote)
            {
                if(strNotes.StartsWith("NoteType:", StrUtil.CaseIgnoreCmp))
                    AddNoteFields(pe, strNotes, pd);
                else ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
            }
            else // Standard entry, no secure note
            {
                ImportUtil.AppendToField(pe, PwDefs.UrlField, vLine[0], pd);

                Debug.Assert(!strNotes.StartsWith("NoteType:"));
                ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
            }

            if(vLine.Length >= 7)
            {
                if(StrUtil.StringToBool(vLine[6]))
                    pe.AddTag("Favorite");
            }
        }
예제 #8
0
		private static void ProcessCsvLine(string[] vLine, PwDatabase pwStorage,
			SortedDictionary<string, PwGroup> dictGroups)
		{
			string strType = ParseCsvWord(vLine[0]);

			string strGroupName = ParseCsvWord(vLine[12]); // + " - " + strType;
			if(strGroupName.Length == 0) strGroupName = strType;

			SplashIdMapping mp = null;
			foreach(SplashIdMapping mpFind in SplashIdCsv402.SplashIdMappings)
			{
				if(mpFind.TypeName == strType)
				{
					mp = mpFind;
					break;
				}
			}

			PwIcon pwIcon = ((mp != null) ? mp.Icon : PwIcon.Key);

			PwGroup pg = null;
			if(dictGroups.ContainsKey(strGroupName))
				pg = dictGroups[strGroupName];
			else
			{
				// PwIcon pwGroupIcon = ((pwIcon == PwIcon.Key) ?
				//	PwIcon.FolderOpen : pwIcon);
				// pg = new PwGroup(true, true, strGroupName, pwGroupIcon);

				pg = new PwGroup(true, true);
				pg.Name = strGroupName;

				pwStorage.RootGroup.AddGroup(pg, true);
				dictGroups[strGroupName] = pg;
			}

			PwEntry pe = new PwEntry(true, true);
			pg.AddEntry(pe, true);

			pe.IconId = pwIcon;

			List<string> vTags = StrUtil.StringToTags(strType);
			foreach(string strTag in vTags) { pe.AddTag(strTag); }

			for(int iField = 0; iField < 9; ++iField)
			{
				string strData = ParseCsvWord(vLine[iField + 1]);
				if(strData.Length == 0) continue;

				string strLookup = ((mp != null) ? mp.FieldNames[iField] :
					null);
				string strField = (strLookup ?? ("Field " + (iField + 1).ToString()));

				string strSep = ((strField != PwDefs.NotesField) ? ", " : "\r\n");
				ImportUtil.AppendToField(pe, strField, strData, pwStorage, strSep, false);
			}

			ImportUtil.AppendToField(pe, PwDefs.NotesField, ParseCsvWord(vLine[11]),
				pwStorage, "\r\n", false);

			DateTime? odt = TimeUtil.ParseUSTextDate(ParseCsvWord(vLine[10]),
				DateTimeKind.Local);
			if(odt.HasValue)
			{
				DateTime dt = TimeUtil.ToUtc(odt.Value, false);
				pe.LastAccessTime = dt;
				pe.LastModificationTime = dt;
			}
		}
예제 #9
0
        private void PerformImport(PwGroup pgStorage, bool bCreatePreview)
        {
            List<CsvFieldInfo> lFields = GetCsvFieldInfos();

            if(bCreatePreview)
            {
                int dx = m_lvImportPreview.ClientRectangle.Width; // Before clearing

                m_lvImportPreview.Items.Clear();
                m_lvImportPreview.Columns.Clear();

                foreach(CsvFieldInfo cfi in lFields)
                {
                    string strCol = CsvFieldToString(cfi.Type);
                    if(cfi.Type == CsvFieldType.CustomString)
                        strCol = (cfi.Name ?? string.Empty);
                    m_lvImportPreview.Columns.Add(strCol, dx / lFields.Count);
                }
            }

            CsvOptions opt = GetCsvOptions();
            if(opt == null) { Debug.Assert(bCreatePreview); return; }

            string strData = GetDecodedText();
            CsvStreamReaderEx csr = new CsvStreamReaderEx(strData, opt);

            Dictionary<string, PwGroup> dGroups = new Dictionary<string, PwGroup>();
            dGroups[string.Empty] = pgStorage;

            if(bCreatePreview) m_lvImportPreview.BeginUpdate();

            DateTime dtNow = DateTime.Now;
            DateTime dtNoExpire = KdbTime.NeverExpireTime.ToDateTime();
            bool bIgnoreFirstRow = m_cbIgnoreFirst.Checked;
            bool bIsFirstRow = true;
            bool bMergeGroups = m_cbMergeGroups.Checked;

            while(true)
            {
                string[] v = csr.ReadLine();
                if(v == null) break;
                if(v.Length == 0) continue;
                if((v.Length == 1) && (v[0].Length == 0)) continue;

                if(bIsFirstRow && bIgnoreFirstRow)
                {
                    bIsFirstRow = false;
                    continue;
                }
                bIsFirstRow = false;

                PwGroup pg = pgStorage;
                PwEntry pe = new PwEntry(true, true);

                ListViewItem lvi = null;
                for(int i = 0; i < Math.Min(v.Length, lFields.Count); ++i)
                {
                    string strField = v[i];
                    CsvFieldInfo cfi = lFields[i];

                    if(cfi.Type == CsvFieldType.Ignore) { }
                    else if(cfi.Type == CsvFieldType.Group)
                        pg = FindCreateGroup(strField, pgStorage, dGroups,
                            cfi.Format, opt, bMergeGroups);
                    else if(cfi.Type == CsvFieldType.Title)
                        ImportUtil.AppendToField(pe, PwDefs.TitleField,
                            strField, m_pwDatabase);
                    else if(cfi.Type == CsvFieldType.UserName)
                        ImportUtil.AppendToField(pe, PwDefs.UserNameField,
                            strField, m_pwDatabase);
                    else if(cfi.Type == CsvFieldType.Password)
                        ImportUtil.AppendToField(pe, PwDefs.PasswordField,
                            strField, m_pwDatabase);
                    else if(cfi.Type == CsvFieldType.Url)
                        ImportUtil.AppendToField(pe, PwDefs.UrlField,
                            strField, m_pwDatabase);
                    else if(cfi.Type == CsvFieldType.Notes)
                        ImportUtil.AppendToField(pe, PwDefs.NotesField,
                            strField, m_pwDatabase);
                    else if(cfi.Type == CsvFieldType.CustomString)
                        ImportUtil.AppendToField(pe, (string.IsNullOrEmpty(cfi.Name) ?
                            PwDefs.NotesField : cfi.Name), strField, m_pwDatabase);
                    else if(cfi.Type == CsvFieldType.CreationTime)
                        pe.CreationTime = ParseDateTime(ref strField, cfi, dtNow);
                    // else if(cfi.Type == CsvFieldType.LastAccessTime)
                    //	pe.LastAccessTime = ParseDateTime(ref strField, cfi, dtNow);
                    else if(cfi.Type == CsvFieldType.LastModTime)
                        pe.LastModificationTime = ParseDateTime(ref strField, cfi, dtNow);
                    else if(cfi.Type == CsvFieldType.ExpiryTime)
                    {
                        bool bParseSuccess;
                        pe.ExpiryTime = ParseDateTime(ref strField, cfi, dtNow,
                            out bParseSuccess);
                        pe.Expires = (bParseSuccess && (pe.ExpiryTime != dtNoExpire));
                    }
                    else if(cfi.Type == CsvFieldType.Tags)
                    {
                        List<string> lTags = StrUtil.StringToTags(strField);
                        foreach(string strTag in lTags)
                            pe.AddTag(strTag);
                    }
                    else { Debug.Assert(false); }

                    if(bCreatePreview)
                    {
                        strField = StrUtil.MultiToSingleLine(strField);

                        if(lvi != null) lvi.SubItems.Add(strField);
                        else lvi = m_lvImportPreview.Items.Add(strField);
                    }
                }

                if(bCreatePreview)
                {
                    // Create remaining subitems
                    for(int r = v.Length; r < lFields.Count; ++r)
                    {
                        if(lvi != null) lvi.SubItems.Add(string.Empty);
                        else lvi = m_lvImportPreview.Items.Add(string.Empty);
                    }
                }

                pg.AddEntry(pe, true);
            }

            if(bCreatePreview)
            {
                m_lvImportPreview.EndUpdate();
                ProcessResize();
            }
        }
예제 #10
0
        private void PerformImport(PwGroup pgStorage, bool bCreatePreview)
        {
            List <CsvFieldInfo> lFields = GetCsvFieldInfos();

            if (bCreatePreview)
            {
                int dx = m_lvImportPreview.ClientRectangle.Width;                 // Before clearing

                m_lvImportPreview.Items.Clear();
                m_lvImportPreview.Columns.Clear();

                foreach (CsvFieldInfo cfi in lFields)
                {
                    string strCol = CsvFieldToString(cfi.Type);
                    if (cfi.Type == CsvFieldType.CustomString)
                    {
                        strCol = (cfi.Name ?? string.Empty);
                    }
                    m_lvImportPreview.Columns.Add(strCol, dx / lFields.Count);
                }
            }

            CsvOptions opt = GetCsvOptions();

            if (opt == null)
            {
                Debug.Assert(bCreatePreview); return;
            }

            string            strData = GetDecodedText();
            CsvStreamReaderEx csr     = new CsvStreamReaderEx(strData, opt);

            Dictionary <string, PwGroup> dGroups = new Dictionary <string, PwGroup>();

            dGroups[string.Empty] = pgStorage;

            if (bCreatePreview)
            {
                m_lvImportPreview.BeginUpdate();
            }

            DateTime dtNow           = DateTime.Now;
            DateTime dtNoExpire      = KdbTime.NeverExpireTime.ToDateTime();
            bool     bIgnoreFirstRow = m_cbIgnoreFirst.Checked;
            bool     bIsFirstRow     = true;
            bool     bMergeGroups    = m_cbMergeGroups.Checked;

            while (true)
            {
                string[] v = csr.ReadLine();
                if (v == null)
                {
                    break;
                }
                if (v.Length == 0)
                {
                    continue;
                }
                if ((v.Length == 1) && (v[0].Length == 0))
                {
                    continue;
                }

                if (bIsFirstRow && bIgnoreFirstRow)
                {
                    bIsFirstRow = false;
                    continue;
                }
                bIsFirstRow = false;

                PwGroup pg = pgStorage;
                PwEntry pe = new PwEntry(true, true);

                ListViewItem lvi = null;
                for (int i = 0; i < Math.Min(v.Length, lFields.Count); ++i)
                {
                    string       strField = v[i];
                    CsvFieldInfo cfi      = lFields[i];

                    if (cfi.Type == CsvFieldType.Ignore)
                    {
                    }
                    else if (cfi.Type == CsvFieldType.Group)
                    {
                        pg = FindCreateGroup(strField, pgStorage, dGroups,
                                             cfi.Format, opt, bMergeGroups);
                    }
                    else if (cfi.Type == CsvFieldType.Title)
                    {
                        ImportUtil.AppendToField(pe, PwDefs.TitleField,
                                                 strField, m_pwDatabase);
                    }
                    else if (cfi.Type == CsvFieldType.UserName)
                    {
                        ImportUtil.AppendToField(pe, PwDefs.UserNameField,
                                                 strField, m_pwDatabase);
                    }
                    else if (cfi.Type == CsvFieldType.Password)
                    {
                        ImportUtil.AppendToField(pe, PwDefs.PasswordField,
                                                 strField, m_pwDatabase);
                    }
                    else if (cfi.Type == CsvFieldType.Url)
                    {
                        ImportUtil.AppendToField(pe, PwDefs.UrlField,
                                                 strField, m_pwDatabase);
                    }
                    else if (cfi.Type == CsvFieldType.Notes)
                    {
                        ImportUtil.AppendToField(pe, PwDefs.NotesField,
                                                 strField, m_pwDatabase);
                    }
                    else if (cfi.Type == CsvFieldType.CustomString)
                    {
                        ImportUtil.AppendToField(pe, (string.IsNullOrEmpty(cfi.Name) ?
                                                      PwDefs.NotesField : cfi.Name), strField, m_pwDatabase);
                    }
                    else if (cfi.Type == CsvFieldType.CreationTime)
                    {
                        pe.CreationTime = ParseDateTime(ref strField, cfi, dtNow);
                    }
                    // else if(cfi.Type == CsvFieldType.LastAccessTime)
                    //	pe.LastAccessTime = ParseDateTime(ref strField, cfi, dtNow);
                    else if (cfi.Type == CsvFieldType.LastModTime)
                    {
                        pe.LastModificationTime = ParseDateTime(ref strField, cfi, dtNow);
                    }
                    else if (cfi.Type == CsvFieldType.ExpiryTime)
                    {
                        bool bParseSuccess;
                        pe.ExpiryTime = ParseDateTime(ref strField, cfi, dtNow,
                                                      out bParseSuccess);
                        pe.Expires = (bParseSuccess && (pe.ExpiryTime != dtNoExpire));
                    }
                    else if (cfi.Type == CsvFieldType.Tags)
                    {
                        List <string> lTags = StrUtil.StringToTags(strField);
                        foreach (string strTag in lTags)
                        {
                            pe.AddTag(strTag);
                        }
                    }
                    else
                    {
                        Debug.Assert(false);
                    }

                    if (bCreatePreview)
                    {
                        strField = StrUtil.MultiToSingleLine(strField);

                        if (lvi != null)
                        {
                            lvi.SubItems.Add(strField);
                        }
                        else
                        {
                            lvi = m_lvImportPreview.Items.Add(strField);
                        }
                    }
                }

                if (bCreatePreview)
                {
                    // Create remaining subitems
                    for (int r = v.Length; r < lFields.Count; ++r)
                    {
                        if (lvi != null)
                        {
                            lvi.SubItems.Add(string.Empty);
                        }
                        else
                        {
                            lvi = m_lvImportPreview.Items.Add(string.Empty);
                        }
                    }
                }

                pg.AddEntry(pe, true);
            }

            if (bCreatePreview)
            {
                m_lvImportPreview.EndUpdate();
                ProcessResize();
            }
        }
예제 #11
0
        void UpdateEntryFromUi(PwEntry entry)
        {
            Database          db  = App.Kp2a.GetDb();
            EntryEditActivity act = this;

            entry.Strings.Set(PwDefs.TitleField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectTitle,
                                                                     Util.GetEditText(act, Resource.Id.entry_title)));
            entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUserName,
                                                                        Util.GetEditText(act, Resource.Id.entry_user_name)));

            String pass = Util.GetEditText(act, Resource.Id.entry_password);

            byte[] password = StrUtil.Utf8.GetBytes(pass);
            entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectPassword,
                                                                        password));
            MemUtil.ZeroByteArray(password);

            entry.Strings.Set(PwDefs.UrlField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUrl,
                                                                   Util.GetEditText(act, Resource.Id.entry_url)));
            entry.Strings.Set(PwDefs.NotesField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectNotes,
                                                                     Util.GetEditText(act, Resource.Id.entry_comment)));

            // Validate expiry date
            DateTime newExpiry = new DateTime();

            if ((State.Entry.Expires) && (!DateTime.TryParse(Util.GetEditText(this, Resource.Id.entry_expires), out newExpiry)))
            {
                //ignore here
            }
            else
            {
                State.Entry.ExpiryTime = newExpiry;
            }

            // Delete all non standard strings
            var keys = entry.Strings.GetKeys();

            foreach (String key in keys)
            {
                if (PwDefs.IsStandardField(key) == false)
                {
                    entry.Strings.Remove(key);
                }
            }

            LinearLayout container = (LinearLayout)FindViewById(Resource.Id.advanced_container);

            for (int index = 0; index < container.ChildCount; index++)
            {
                View view = container.GetChildAt(index);

                TextView keyView = (TextView)view.FindViewById(Resource.Id.title);
                String   key     = keyView.Text;

                if (String.IsNullOrEmpty(key))
                {
                    continue;
                }

                TextView valueView = (TextView)view.FindViewById(Resource.Id.value);
                String   value     = valueView.Text;


                bool protect = ((CheckBox)view.FindViewById(Resource.Id.protection)).Checked;
                entry.Strings.Set(key, new ProtectedString(protect, value));
            }


            entry.OverrideUrl = Util.GetEditText(this, Resource.Id.entry_override_url);

            List <string> vNewTags = StrUtil.StringToTags(Util.GetEditText(this, Resource.Id.entry_tags));

            entry.Tags.Clear();
            foreach (string strTag in vNewTags)
            {
                entry.AddTag(strTag);
            }

            /*KPDesktop
             *
             *
             *      m_atConfig.Enabled = m_cbAutoTypeEnabled.Checked;
             *      m_atConfig.ObfuscationOptions = (m_cbAutoTypeObfuscation.Checked ?
             *                                       AutoTypeObfuscationOptions.UseClipboard :
             *                                       AutoTypeObfuscationOptions.None);
             *
             *      SaveDefaultSeq();
             *
             *      newEntry.AutoType = m_atConfig;
             */
        }
예제 #12
0
        private static void ReadEntry(XmlNode xmlNode, PwGroup pgParent, PwDatabase pwStorage)
        {
            PwEntry pe = new PwEntry(true, true);
            pgParent.AddEntry(pe, true);

            DateTime? odtExpiry = null;

            foreach(XmlNode xmlChild in xmlNode)
            {
                string strValue = XmlUtil.SafeInnerText(xmlChild);

                if(xmlChild.NodeType == XmlNodeType.Text)
                    ImportUtil.AppendToField(pe, PwDefs.TitleField, (xmlChild.Value ??
                        string.Empty).Trim(), pwStorage, " ", false);
                else if(xmlChild.Name == ElemEntryUser)
                    pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                        pwStorage.MemoryProtection.ProtectUserName, strValue));
                else if(xmlChild.Name == ElemEntryPassword)
                    pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
                        pwStorage.MemoryProtection.ProtectPassword, strValue));
                else if(xmlChild.Name == ElemEntryPassword2)
                {
                    if(strValue.Length > 0) // Prevent empty item
                        pe.Strings.Set(Password2Key, new ProtectedString(
                            pwStorage.MemoryProtection.ProtectPassword, strValue));
                }
                else if(xmlChild.Name == ElemEntryUrl)
                    pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
                        pwStorage.MemoryProtection.ProtectUrl, strValue));
                else if(xmlChild.Name == ElemEntryNotes)
                    pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
                        pwStorage.MemoryProtection.ProtectNotes, strValue));
                else if(xmlChild.Name == ElemTags)
                {
                    string strTags = strValue.Replace(' ', ';');
                    List<string> vTags = StrUtil.StringToTags(strTags);
                    foreach(string strTag in vTags) { pe.AddTag(strTag); }
                }
                else if(xmlChild.Name == ElemEntryExpires)
                    pe.Expires = StrUtil.StringToBool(strValue);
                else if(xmlChild.Name == ElemEntryExpiryTime)
                {
                    DateTime dt = TimeUtil.FromDisplayString(strValue);
                    if(dt != DateTime.Now) odtExpiry = dt;
                    else { Debug.Assert(false); }
                }
                else if(xmlChild.Name == ElemAutoType)
                    ReadAutoType(xmlChild, pe);
                else if(xmlChild.Name == ElemEntryUnsupp0) { }
                else if(xmlChild.Name == ElemEntryUnsupp1) { }
                else { Debug.Assert(false); }
            }

            if(odtExpiry.HasValue) pe.ExpiryTime = odtExpiry.Value;
            else pe.Expires = false;
        }
예제 #13
0
        private void setTags(PwEntry pwe, string url = null)
        {
            pwe.AddTag("keebook_bookmark");

            if (!string.IsNullOrEmpty(url))
            {
                if (url.Contains("https://"))
                {
                    pwe.AddTag("keebook_secure_url");
                }
            }

            if (pwe.IconId != PwIcon.Star)
            {
                pwe.AddTag("keebook_custom_icon");
            }
        }
예제 #14
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
                                    IStatusLogger slLogger)
        {
            StreamReader sr      = new StreamReader(sInput, StrUtil.Utf8, true);
            string       strData = sr.ReadToEnd();

            sr.Close();

            CsvOptions opt = new CsvOptions();

            opt.BackslashIsEscape = false;
            opt.TrimFields        = true;

            CsvStreamReaderEx csv = new CsvStreamReaderEx(strData, opt);

            string[] vNames = csv.ReadLine();
            if ((vNames == null) || (vNames.Length == 0))
            {
                Debug.Assert(false); return;
            }

            for (int i = 0; i < vNames.Length; ++i)
            {
                vNames[i] = (vNames[i] ?? string.Empty).ToLowerInvariant();
            }

            while (true)
            {
                string[] v = csv.ReadLine();
                if (v == null)
                {
                    break;
                }
                if (v.Length == 0)
                {
                    continue;
                }

                PwEntry pe = new PwEntry(true, true);
                pwStorage.RootGroup.AddEntry(pe, true);

                Debug.Assert(v.Length == vNames.Length);
                int m = Math.Min(v.Length, vNames.Length);

                for (int i = 0; i < m; ++i)
                {
                    string strValue = v[i];
                    if (string.IsNullOrEmpty(strValue))
                    {
                        continue;
                    }

                    string   strName = vNames[i];
                    string   strTo   = null;
                    DateTime?odt;

                    switch (strName)
                    {
                    case "autologin":
                    case "protectedwithpassword":
                    case "subdomainonly":
                    case "type":
                    case "tk_export_version":
                        break;                                 // Ignore

                    case "kind":
                        if (strValue.Equals("note", StrUtil.CaseIgnoreCmp))
                        {
                            pe.IconId = PwIcon.Note;
                        }
                        else if (strValue.Equals("identity", StrUtil.CaseIgnoreCmp) ||
                                 strValue.Equals("drivers", StrUtil.CaseIgnoreCmp) ||
                                 strValue.Equals("passport", StrUtil.CaseIgnoreCmp) ||
                                 strValue.Equals("ssn", StrUtil.CaseIgnoreCmp))
                        {
                            pe.IconId = PwIcon.Identity;
                        }
                        else if (strValue.Equals("cc", StrUtil.CaseIgnoreCmp))
                        {
                            pe.IconId = PwIcon.Money;
                        }
                        else if (strValue.Equals("membership", StrUtil.CaseIgnoreCmp))
                        {
                            pe.IconId = PwIcon.UserKey;
                        }
                        break;

                    case "name":
                    case "title":
                        strTo = PwDefs.TitleField;
                        break;

                    case "cardholder":
                    case "email":
                    case "login":
                        strTo = PwDefs.UserNameField;
                        break;

                    case "password":
                        strTo = PwDefs.PasswordField;
                        break;

                    case "url":
                    case "website":
                        strTo = PwDefs.UrlField;
                        break;

                    case "document_content":
                    case "memo":
                    case "note":
                        strTo = PwDefs.NotesField;
                        break;

                    case "city":
                    case "company":
                    case "country":
                    case "number":
                    case "state":
                    case "street":
                    case "telephone":
                        strTo = (new string(char.ToUpperInvariant(strName[0]), 1)) +
                                strName.Substring(1);
                        break;

                    case "deliveryplace":
                        strTo = "Delivery Place";
                        break;

                    case "firstname":
                        strTo = "First Name";
                        break;

                    case "lastname":
                        strTo = "Last Name";
                        break;

                    case "memberid":
                        strTo = "Member ID";
                        break;

                    case "phonenumber":
                        strTo = "Phone Number";
                        break;

                    case "streetnumber":
                        strTo = "Street Number";
                        break;

                    case "zipcode":
                        strTo = "ZIP Code";
                        break;

                    case "dateofbirth":
                        strTo    = "Date of Birth";
                        strValue = DateToString(strValue);
                        break;

                    case "expirationdate":
                    case "expirydate":
                        odt = ParseTime(strValue);
                        if (odt.HasValue)
                        {
                            pe.Expires    = true;
                            pe.ExpiryTime = odt.Value;
                        }
                        break;

                    case "favorite":
                        if (StrUtil.StringToBoolEx(strValue).GetValueOrDefault(false))
                        {
                            pe.AddTag("Favorite");
                        }
                        break;

                    case "gender":
                        if ((strValue == "0") || (strValue == "1"))
                        {
                            strTo    = "Gender";
                            strValue = ((strValue == "0") ? "Male" : "Female");
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                        break;

                    case "hexcolor":
                        if ((strValue.Length == 6) && StrUtil.IsHexString(strValue, true))
                        {
                            Color c = Color.FromArgb(unchecked ((int)(0xFF000000U |
                                                                      Convert.ToUInt32(strValue, 16))));

                            Color cG = UIUtil.ColorToGrayscale(c);
                            if (cG.B < 128)
                            {
                                c = UIUtil.LightenColor(c, 0.5);
                            }

                            pe.BackgroundColor = c;
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                        break;

                    case "issuedate":
                    case "issueddate":
                        strTo    = "Issue Date";
                        strValue = DateToString(strValue);
                        break;

                    case "membersince":
                        strTo    = "Member Since";
                        strValue = DateToString(strValue);
                        break;

                    default:
                        Debug.Assert(false);                                 // Unknown field
                        break;
                    }

                    if (!string.IsNullOrEmpty(strTo))
                    {
                        ImportUtil.AppendToField(pe, strTo, strValue, pwStorage);
                    }
                }
            }
        }
예제 #15
0
        private static void AddObject(PwGroup pgStorage, JsonObject jo,
                                      PwDatabase pwContext, bool bCreateSubGroups,
                                      Dictionary <string, List <string> > dTags, List <PwEntry> lCreatedEntries)
        {
            string strRoot = jo.GetValue <string>("root");

            if (string.Equals(strRoot, "tagsFolder", StrUtil.CaseIgnoreCmp))
            {
                ImportTags(jo, dTags);
                return;
            }

            JsonObject[] v = jo.GetValueArray <JsonObject>("children");
            if (v != null)
            {
                PwGroup pgNew;
                if (bCreateSubGroups)
                {
                    pgNew      = new PwGroup(true, true);
                    pgNew.Name = (jo.GetValue <string>("title") ?? string.Empty);

                    pgStorage.AddGroup(pgNew, true);
                }
                else
                {
                    pgNew = pgStorage;
                }

                foreach (JsonObject joSub in v)
                {
                    if (joSub == null)
                    {
                        Debug.Assert(false); continue;
                    }

                    AddObject(pgNew, joSub, pwContext, true, dTags, lCreatedEntries);
                }

                return;
            }

            PwEntry pe = new PwEntry(true, true);

            // SetString(pe, "Index", false, jo, "index");
            SetString(pe, PwDefs.TitleField, pwContext.MemoryProtection.ProtectTitle,
                      jo, "title");
            // SetString(pe, "ID", false, jo, "id");
            SetString(pe, PwDefs.UrlField, pwContext.MemoryProtection.ProtectUrl,
                      jo, "uri");
            // SetString(pe, "CharSet", false, jo, "charset");

            v = jo.GetValueArray <JsonObject>("annos");
            if (v != null)
            {
                foreach (JsonObject joAnno in v)
                {
                    if (joAnno == null)
                    {
                        Debug.Assert(false); continue;
                    }

                    string strName  = joAnno.GetValue <string>("name");
                    string strValue = joAnno.GetValue <string>("value");

                    if ((strName == "bookmarkProperties/description") &&
                        !string.IsNullOrEmpty(strValue))
                    {
                        pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
                                           pwContext.MemoryProtection.ProtectNotes, strValue));
                    }
                }
            }

            // Tags support (new versions)
            string strTags = jo.GetValue <string>("tags");

            if (!string.IsNullOrEmpty(strTags))
            {
                string[] vTags = strTags.Split(',');
                foreach (string strTag in vTags)
                {
                    string str = strTag.Trim();
                    if (str.Length != 0)
                    {
                        pe.AddTag(str);
                    }
                }
            }

            string strKeyword = jo.GetValue <string>("keyword");

            if (!string.IsNullOrEmpty(strKeyword))
            {
                ImportUtil.AppendToField(pe, "Keyword", strKeyword, pwContext);
            }

            if ((pe.Strings.ReadSafe(PwDefs.TitleField).Length != 0) ||
                (pe.Strings.ReadSafe(PwDefs.UrlField).Length != 0))
            {
                pgStorage.AddEntry(pe, true);
                lCreatedEntries.Add(pe);
            }
        }
예제 #16
0
        private static void AddEntry(string[] vLine, PwDatabase pd)
        {
            Debug.Assert((vLine.Length == 0) || (vLine.Length == 7));
            if(vLine.Length < 5) return;

            // Skip header line
            if((vLine[1] == "username") && (vLine[2] == "password") &&
                (vLine[3] == "extra") && (vLine[4] == "name"))
                return;

            PwEntry pe = new PwEntry(true, true);

            PwGroup pg = pd.RootGroup;
            if(vLine.Length >= 6)
            {
                string strGroup = vLine[5];
                if(strGroup.Length > 0)
                    pg = pg.FindCreateSubTree(strGroup, new string[1]{ "\\" }, true);
            }
            pg.AddEntry(pe, true);

            ImportUtil.AppendToField(pe, PwDefs.TitleField, vLine[4], pd);
            ImportUtil.AppendToField(pe, PwDefs.UserNameField, vLine[1], pd);
            ImportUtil.AppendToField(pe, PwDefs.PasswordField, vLine[2], pd);

            string strNotes = vLine[3];
            bool bIsSecNote = vLine[0].Equals("http://sn", StrUtil.CaseIgnoreCmp);
            if(bIsSecNote)
            {
                if(strNotes.StartsWith("NoteType:", StrUtil.CaseIgnoreCmp))
                    AddNoteFields(pe, strNotes, pd);
                else ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
            }
            else // Standard entry, no secure note
            {
                ImportUtil.AppendToField(pe, PwDefs.UrlField, vLine[0], pd);

                Debug.Assert(!strNotes.StartsWith("NoteType:"));
                ImportUtil.AppendToField(pe, PwDefs.NotesField, strNotes, pd);
            }

            if(vLine.Length >= 7)
            {
                if(StrUtil.StringToBool(vLine[6]))
                    pe.AddTag("Favorite");
            }
        }
예제 #17
0
        private bool SaveEntry(PwEntry peTarget, bool bValidate)
        {
            if(m_pwEditMode == PwEditMode.ViewReadOnlyEntry) return true;

            if(bValidate && !m_icgPassword.ValidateData(true)) return false;

            if(this.EntrySaving != null)
            {
                CancellableOperationEventArgs eaCancel = new CancellableOperationEventArgs();
                this.EntrySaving(this, eaCancel);
                if(eaCancel.Cancel) return false;
            }

            peTarget.History = m_vHistory; // Must be called before CreateBackup()
            bool bCreateBackup = (m_pwEditMode != PwEditMode.AddNewEntry);
            if(bCreateBackup) peTarget.CreateBackup(null);

            peTarget.IconId = m_pwEntryIcon;
            peTarget.CustomIconUuid = m_pwCustomIconID;

            if(m_cbCustomForegroundColor.Checked)
                peTarget.ForegroundColor = m_clrForeground;
            else peTarget.ForegroundColor = Color.Empty;
            if(m_cbCustomBackgroundColor.Checked)
                peTarget.BackgroundColor = m_clrBackground;
            else peTarget.BackgroundColor = Color.Empty;

            peTarget.OverrideUrl = m_cmbOverrideUrl.Text;

            List<string> vNewTags = StrUtil.StringToTags(m_tbTags.Text);
            peTarget.Tags.Clear();
            foreach(string strTag in vNewTags) peTarget.AddTag(strTag);

            peTarget.Expires = m_cgExpiry.Checked;
            if(peTarget.Expires) peTarget.ExpiryTime = m_cgExpiry.Value;

            UpdateEntryStrings(true, false, false);

            peTarget.Strings = m_vStrings;
            peTarget.Binaries = m_vBinaries;

            m_atConfig.Enabled = m_cbAutoTypeEnabled.Checked;
            m_atConfig.ObfuscationOptions = (m_cbAutoTypeObfuscation.Checked ?
                AutoTypeObfuscationOptions.UseClipboard :
                AutoTypeObfuscationOptions.None);

            SaveDefaultSeq();

            peTarget.AutoType = m_atConfig;

            peTarget.Touch(true, false); // Touch *after* backup
            if(object.ReferenceEquals(peTarget, m_pwEntry)) m_bTouchedOnce = true;

            StrUtil.NormalizeNewLines(peTarget.Strings, true);

            bool bUndoBackup = false;
            PwCompareOptions cmpOpt = m_cmpOpt;
            if(bCreateBackup) cmpOpt |= PwCompareOptions.IgnoreLastBackup;
            if(peTarget.EqualsEntry(m_pwInitialEntry, cmpOpt, MemProtCmpMode.CustomOnly))
            {
                // No modifications at all => restore last mod time and undo backup
                peTarget.LastModificationTime = m_pwInitialEntry.LastModificationTime;
                bUndoBackup = bCreateBackup;
            }
            else if(bCreateBackup)
            {
                // If only history items have been modified (deleted) => undo
                // backup, but without restoring the last mod time
                PwCompareOptions cmpOptNH = (m_cmpOpt | PwCompareOptions.IgnoreHistory);
                if(peTarget.EqualsEntry(m_pwInitialEntry, cmpOptNH, MemProtCmpMode.CustomOnly))
                    bUndoBackup = true;
            }
            if(bUndoBackup) peTarget.History.RemoveAt(peTarget.History.UCount - 1);

            peTarget.MaintainBackups(m_pwDatabase);

            if(this.EntrySaved != null) this.EntrySaved(this, EventArgs.Empty);

            return true;
        }
예제 #18
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
                                    IStatusLogger slLogger)
        {
            StreamReader sr      = new StreamReader(sInput, StrUtil.Utf8, true);
            string       strData = sr.ReadToEnd();

            sr.Close();

            CsvOptions opt = new CsvOptions();

            opt.BackslashIsEscape = false;
            opt.TextQualifier     = char.MinValue;
            opt.TrimFields        = true;

            CsvStreamReaderEx csv = new CsvStreamReaderEx(strData, opt);

            string strMapIgnore  = Guid.NewGuid().ToString();
            string strMapGroup   = Guid.NewGuid().ToString();
            string strMapTags    = Guid.NewGuid().ToString();
            string strMapLastMod = Guid.NewGuid().ToString();
            string strMapEMail   = Guid.NewGuid().ToString();

            Dictionary <string, string> dMaps = new Dictionary <string, string>(
                StrUtil.CaseIgnoreComparer);

            dMaps["title"]                  = PwDefs.TitleField;
            dMaps["type"]                   = strMapIgnore;
            dMaps["username_field"]         = strMapIgnore;
            dMaps["username"]               = PwDefs.UserNameField;
            dMaps["password_field"]         = strMapIgnore;
            dMaps["password"]               = PwDefs.PasswordField;
            dMaps["url"]                    = PwDefs.UrlField;
            dMaps["category"]               = strMapGroup;
            dMaps["note"]                   = PwDefs.NotesField;
            dMaps["autofill"]               = strMapIgnore;
            dMaps["autofillenabled"]        = strMapIgnore;
            dMaps["last_password_change"]   = strMapIgnore;
            dMaps["lastmodified"]           = strMapLastMod;
            dMaps["iban"]                   = PwDefs.UserNameField;
            dMaps["bic"]                    = "BIC";
            dMaps["banking_pin"]            = PwDefs.PasswordField;
            dMaps["card_number"]            = PwDefs.UserNameField;
            dMaps["card_holder"]            = "Card Holder";
            dMaps["card_pin"]               = PwDefs.PasswordField;
            dMaps["card_verification_code"] = "Verification Code";
            dMaps["valid_from"]             = "Valid From";
            dMaps["valid_thru"]             = "Valid To";
            dMaps["name"]                   = PwDefs.UserNameField;
            dMaps["firstname"]              = PwDefs.UserNameField;
            dMaps["street"]                 = PwDefs.NotesField;
            dMaps["houseno"]                = PwDefs.NotesField;
            dMaps["zip"]                    = PwDefs.NotesField;
            dMaps["city"]                   = PwDefs.NotesField;
            dMaps["mobile_phone"]           = PwDefs.NotesField;
            dMaps["phone"]                  = PwDefs.NotesField;
            dMaps["email"]                  = strMapEMail;
            dMaps["birthday"]               = "Birthday";
            dMaps["tags"]                   = strMapTags;
            dMaps["keyword"]                = strMapTags;

            string[] vNames = csv.ReadLine();
            if ((vNames == null) || (vNames.Length == 0))
            {
                Debug.Assert(false); return;
            }

            for (int i = 0; i < vNames.Length; ++i)
            {
                string str = vNames[i];

                if (string.IsNullOrEmpty(str))
                {
                    Debug.Assert(false); str = strMapIgnore;
                }
                else
                {
                    string strMapped = null;
                    dMaps.TryGetValue(str, out strMapped);

                    if (string.IsNullOrEmpty(strMapped))
                    {
                        Debug.Assert(false);
                        strMapped = ImportUtil.MapNameToStandardField(str, true);
                        if (string.IsNullOrEmpty(strMapped))
                        {
                            strMapped = PwDefs.NotesField;
                        }
                    }

                    str = strMapped;
                }

                vNames[i] = str;
            }

            Dictionary <string, PwGroup> dGroups = new Dictionary <string, PwGroup>();

            while (true)
            {
                string[] v = csv.ReadLine();
                if (v == null)
                {
                    break;
                }
                if (v.Length == 0)
                {
                    continue;
                }

                PwEntry pe = new PwEntry(true, true);
                PwGroup pg = pwStorage.RootGroup;

                for (int i = 0; i < v.Length; ++i)
                {
                    string strValue = v[i];
                    if (string.IsNullOrEmpty(strValue))
                    {
                        continue;
                    }

                    strValue = strValue.Replace(@"<COMMA>", ",");
                    strValue = strValue.Replace(@"<-N/L-/>", "\n");

                    strValue = StrUtil.NormalizeNewLines(strValue, true);

                    string strName = ((i < vNames.Length) ? vNames[i] : PwDefs.NotesField);

                    if (strName == strMapIgnore)
                    {
                    }
                    else if (strName == strMapGroup)
                    {
                        dGroups.TryGetValue(strValue, out pg);
                        if (pg == null)
                        {
                            pg      = new PwGroup(true, true);
                            pg.Name = strValue;

                            pwStorage.RootGroup.AddGroup(pg, true);
                            dGroups[strValue] = pg;
                        }
                    }
                    else if (strName == strMapTags)
                    {
                        List <string> lTags = StrUtil.StringToTags(strValue);
                        foreach (string strTag in lTags)
                        {
                            pe.AddTag(strTag);
                        }
                    }
                    else if (strName == strMapLastMod)
                    {
                        double dUnix;
                        if (double.TryParse(strValue, out dUnix))
                        {
                            pe.LastModificationTime = TimeUtil.ConvertUnixTime(dUnix);
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                    }
                    else if (strName == strMapEMail)
                    {
                        ImportUtil.AppendToField(pe, PwDefs.UrlField,
                                                 "mailto:" + strValue, pwStorage);
                    }
                    else
                    {
                        ImportUtil.AppendToField(pe, strName, strValue, pwStorage);
                    }
                }

                pg.AddEntry(pe, true);
            }
        }
예제 #19
0
        public static void UpdateKeePassEntry(PwEntry entry,
            string username = "",
            string title = "",
            string url = "",
            string notes = "",
            string password = "",
            string[] attachments = null,
            string[] tags = null)
        {
            UpdateValue(entry, "UserName", username);
            UpdateValue(entry, "Title", title);
            UpdateValue(entry, "URL", url);
            UpdateValue(entry, "Notes", notes);
            UpdateValue(entry, "Password", password);

            if(tags != null)
            {
                var tagsCopy = entry.Tags.ToArray();
                foreach(var tag in tagsCopy)
                    entry.RemoveTag(tag);

                foreach (var tag in tags)
                    entry.AddTag(tag);
            }

            if (attachments != null)
            {
                var fileNames = attachments.Select(o => Path.GetFileName(o)).ToList();
                var binaries = entry.Binaries.CloneDeep();
                var filesToAdd = new List<string>();

                foreach(var binary in binaries)
                {
                    entry.Binaries.Remove(binary.Key);
                }

                foreach(var attachment in attachments)
                {
                    var fileName = Path.GetFileName(attachment);

                    var bytes = File.ReadAllBytes(attachment);
                    if(bytes != null)
                    {
                        var protectedBytes = new ProtectedBinary(true, bytes);
                        entry.Binaries.Set(fileName, protectedBytes);
                    }
                }
            }
        }
예제 #20
0
        private static void ImportGroup(XmlNode xmlNode, PwDatabase pwStorage,
                                        PwGroup pg)
        {
            PwGroup pgSub = pg;
            PwEntry pe    = null;

            foreach (XmlNode xmlChild in xmlNode)
            {
                if (xmlChild.Name == "A")
                {
                    pe = new PwEntry(true, true);
                    pg.AddEntry(pe, true);

                    pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
                                       pwStorage.MemoryProtection.ProtectTitle,
                                       XmlUtil.SafeInnerText(xmlChild)));

                    XmlNode xnUrl = xmlChild.Attributes.GetNamedItem("HREF");
                    if ((xnUrl != null) && (xnUrl.Value != null))
                    {
                        pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
                                           pwStorage.MemoryProtection.ProtectUrl, xnUrl.Value));
                    }
                    else
                    {
                        Debug.Assert(false);
                    }

                    // pe.Strings.Set("RDF_ID", new ProtectedString(
                    //	false, xmlChild.Attributes.GetNamedItem("ID").Value));

                    ImportIcon(xmlChild, pe, pwStorage);

                    XmlNode xnTags = xmlChild.Attributes.GetNamedItem("TAGS");
                    if ((xnTags != null) && (xnTags.Value != null))
                    {
                        string[] vTags = xnTags.Value.Split(',');
                        foreach (string strTag in vTags)
                        {
                            if (string.IsNullOrEmpty(strTag))
                            {
                                continue;
                            }
                            pe.AddTag(strTag);
                        }
                    }
                }
                else if (xmlChild.Name == "DD")
                {
                    if (pe != null)
                    {
                        ImportUtil.AppendToField(pe, PwDefs.NotesField,
                                                 XmlUtil.SafeInnerText(xmlChild).Trim(), pwStorage);
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
                else if (xmlChild.Name == "H3")
                {
                    string strGroup = XmlUtil.SafeInnerText(xmlChild);
                    if (strGroup.Length == 0)
                    {
                        Debug.Assert(false); pgSub = pg;
                    }
                    else
                    {
                        pgSub = new PwGroup(true, true, strGroup, PwIcon.Folder);
                        pg.AddGroup(pgSub, true);
                    }
                }
                else if (xmlChild.Name == "DL")
                {
                    ImportGroup(xmlChild, pwStorage, pgSub);
                }
                else
                {
                    Debug.Assert(false);
                }
            }
        }
예제 #21
0
        private static void ReadEntry(XmlNode xmlNode, PwGroup pgParent, PwDatabase pwStorage)
        {
            PwEntry pe = new PwEntry(true, true);

            pgParent.AddEntry(pe, true);

            DateTime?odtExpiry = null;

            foreach (XmlNode xmlChild in xmlNode)
            {
                string strValue = XmlUtil.SafeInnerText(xmlChild);

                if (xmlChild.NodeType == XmlNodeType.Text)
                {
                    ImportUtil.AppendToField(pe, PwDefs.TitleField, (xmlChild.Value ??
                                                                     string.Empty).Trim(), pwStorage, " ", false);
                }
                else if (xmlChild.Name == ElemEntryUser)
                {
                    pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                                       pwStorage.MemoryProtection.ProtectUserName, strValue));
                }
                else if (xmlChild.Name == ElemEntryPassword)
                {
                    pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
                                       pwStorage.MemoryProtection.ProtectPassword, strValue));
                }
                else if (xmlChild.Name == ElemEntryPassword2)
                {
                    if (strValue.Length > 0)                    // Prevent empty item
                    {
                        pe.Strings.Set(Password2Key, new ProtectedString(
                                           pwStorage.MemoryProtection.ProtectPassword, strValue));
                    }
                }
                else if (xmlChild.Name == ElemEntryUrl)
                {
                    pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
                                       pwStorage.MemoryProtection.ProtectUrl, strValue));
                }
                else if (xmlChild.Name == ElemEntryNotes)
                {
                    pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
                                       pwStorage.MemoryProtection.ProtectNotes, strValue));
                }
                else if (xmlChild.Name == ElemTags)
                {
                    string        strTags = strValue.Replace(' ', ';');
                    List <string> vTags   = StrUtil.StringToTags(strTags);
                    foreach (string strTag in vTags)
                    {
                        pe.AddTag(strTag);
                    }
                }
                else if (xmlChild.Name == ElemEntryExpires)
                {
                    pe.Expires = StrUtil.StringToBool(strValue);
                }
                else if (xmlChild.Name == ElemEntryExpiryTime)
                {
                    DateTime dt;
                    if (TimeUtil.FromDisplayStringEx(strValue, out dt))
                    {
                        odtExpiry = TimeUtil.ToUtc(dt, false);
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
                else if (xmlChild.Name == ElemAutoType)
                {
                    ReadAutoType(xmlChild, pe);
                }
                else if (xmlChild.Name == ElemEntryUnsupp0)
                {
                }
                else if (xmlChild.Name == ElemEntryUnsupp1)
                {
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            if (odtExpiry.HasValue)
            {
                pe.ExpiryTime = odtExpiry.Value;
            }
            else
            {
                pe.Expires = false;
            }
        }
예제 #22
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);
                }
            }
예제 #23
0
        private static void ImportGroup(XmlNode xmlNode, PwDatabase pwStorage,
			PwGroup pg)
        {
            PwGroup pgSub = pg;
            PwEntry pe = null;

            foreach(XmlNode xmlChild in xmlNode)
            {
                if(xmlChild.Name == "A")
                {
                    pe = new PwEntry(true, true);
                    pg.AddEntry(pe, true);

                    pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
                        pwStorage.MemoryProtection.ProtectTitle,
                        XmlUtil.SafeInnerText(xmlChild)));

                    XmlNode xnUrl = xmlChild.Attributes.GetNamedItem("HREF");
                    if((xnUrl != null) && (xnUrl.Value != null))
                        pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
                            pwStorage.MemoryProtection.ProtectUrl, xnUrl.Value));
                    else { Debug.Assert(false); }

                    // pe.Strings.Set("RDF_ID", new ProtectedString(
                    //	false, xmlChild.Attributes.GetNamedItem("ID").Value));

                    ImportIcon(xmlChild, pe, pwStorage);

                    XmlNode xnTags = xmlChild.Attributes.GetNamedItem("TAGS");
                    if((xnTags != null) && (xnTags.Value != null))
                    {
                        string[] vTags = xnTags.Value.Split(',');
                        foreach(string strTag in vTags)
                        {
                            if(string.IsNullOrEmpty(strTag)) continue;
                            pe.AddTag(strTag);
                        }
                    }
                }
                else if(xmlChild.Name == "DD")
                {
                    if(pe != null)
                        ImportUtil.AppendToField(pe, PwDefs.NotesField,
                            XmlUtil.SafeInnerText(xmlChild).Trim(), pwStorage,
                            "\r\n", false);
                    else { Debug.Assert(false); }
                }
                else if(xmlChild.Name == "H3")
                {
                    string strGroup = XmlUtil.SafeInnerText(xmlChild);
                    if(strGroup.Length == 0) { Debug.Assert(false); pgSub = pg; }
                    else
                    {
                        pgSub = new PwGroup(true, true, strGroup, PwIcon.Folder);
                        pg.AddGroup(pgSub, true);
                    }
                }
                else if(xmlChild.Name == "DL")
                    ImportGroup(xmlChild, pwStorage, pgSub);
                else { Debug.Assert(false); }
            }
        }
예제 #24
0
        void UpdateEntryFromUi(PwEntry entry)
        {
            Database db = App.Kp2a.GetDb();
            EntryEditActivity act = this;

            entry.Strings.Set(PwDefs.TitleField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectTitle,
                                                                        Util.GetEditText(act, Resource.Id.entry_title)));
            entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUserName,
                                                                           Util.GetEditText(act, Resource.Id.entry_user_name)));

            String pass = Util.GetEditText(act, Resource.Id.entry_password);
            byte[] password = StrUtil.Utf8.GetBytes(pass);
            entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectPassword,
                                                                           password));
            MemUtil.ZeroByteArray(password);

            entry.Strings.Set(PwDefs.UrlField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUrl,
                                                                      Util.GetEditText(act, Resource.Id.entry_url)));
            entry.Strings.Set(PwDefs.NotesField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectNotes,
                                                                        Util.GetEditText(act, Resource.Id.entry_comment)));

            // Validate expiry date
            DateTime newExpiry = new DateTime();
            if ((State.Entry.Expires) && (!DateTime.TryParse( Util.GetEditText(this,Resource.Id.entry_expires), out newExpiry)))
            {
                //ignore here
            }
            else
            {
                State.Entry.ExpiryTime = newExpiry;
            }

            // Delete all non standard strings
            var keys = entry.Strings.GetKeys();
            foreach (String key in keys)
                if (PwDefs.IsStandardField(key) == false)
                    entry.Strings.Remove(key);

            LinearLayout container = (LinearLayout) FindViewById(Resource.Id.advanced_container);

            for (int index = 0; index < container.ChildCount; index++) {
                View view = container.GetChildAt(index);

                TextView keyView = (TextView)view.FindViewById(Resource.Id.title);
                String key = keyView.Text;

                if (String.IsNullOrEmpty(key))
                    continue;

                TextView valueView = (TextView)view.FindViewById(Resource.Id.value);
                String value = valueView.Text;

                bool protect = ((CheckBox) view.FindViewById(Resource.Id.protection)).Checked;
                entry.Strings.Set(key, new ProtectedString(protect, value));
            }

            entry.OverrideUrl = Util.GetEditText(this,Resource.Id.entry_override_url);

            List<string> vNewTags = StrUtil.StringToTags(Util.GetEditText(this,Resource.Id.entry_tags));
            entry.Tags.Clear();
            foreach(string strTag in vNewTags) entry.AddTag(strTag);

            /*KPDesktop

                m_atConfig.Enabled = m_cbAutoTypeEnabled.Checked;
                m_atConfig.ObfuscationOptions = (m_cbAutoTypeObfuscation.Checked ?
                                                 AutoTypeObfuscationOptions.UseClipboard :
                                                 AutoTypeObfuscationOptions.None);

                SaveDefaultSeq();

                newEntry.AutoType = m_atConfig;
                */
        }