private bool UpdateTemplate(Template template) { int foundEntries = 0; PwEntry singlePwEntry = null; foreach (var pwGroup in _allGroups) { foreach (var pwEntry in pwGroup.GetEntries(false)) { string ser = pwEntry.Strings.Get(PwDefs.NotesField).ReadString(); if (ser != null) { Template entryTemplate = (Template) SerializationDotNet2.Xml.Deserializer.DeserializeObjectFromString( EncodingEx.Base64.Decoder.DecodeString(Encoding.UTF8, ser), typeof(Template)); if (entryTemplate.UTID == template.UTID) { singlePwEntry = pwEntry; foundEntries++; } else if (entryTemplate.BoundUrl.Value.Value.Contains(template.BoundUrl.Value.Value) || template.BoundUrl.Value.Value.Contains(entryTemplate.BoundUrl.Value.Value)) { foundEntries++; } } } } if (singlePwEntry == null) { return(AddTemplate(template)); } if (foundEntries > 1) { RefreshUI(false); MessageBox.Show("There are too many templates that match on the bound URL or share the same UTID"); return(false); } string serializedEntry = SerializationDotNet2.Xml.Serializer.SerializeObjectToString(CleanTemplate(template), template.GetType()); string encodedEntry = EncodingEx.Base64.Encoder.EncodeString(Encoding.UTF8, serializedEntry); singlePwEntry.Strings.Set(PwDefs.NotesField, new ProtectedString(true, encodedEntry)); singlePwEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(true, template.Name + " Version " + template.TemplateVersion + " UTID: " + template.UTID)); singlePwEntry.Strings.Set(PwDefs.UrlField, new ProtectedString(true, template.BoundUrl.Value.Value)); KeePassPasswordChangerExt.RefreshUiEntry(singlePwEntry); //KeePassPasswordChangerExt.SaveCurrentDb(); RefreshUI(); return(true); }
private bool AddTemplate(Template template) { bool foundAnotherEntry = false; foreach (var pwGroup in _allGroups) { foreach (var pwEntry in pwGroup.GetEntries(false)) { string ser = pwEntry.Strings.Get(PwDefs.NotesField).ReadString(); if (ser != null) { Template entryTemplate = (Template) SerializationDotNet2.Xml.Deserializer.DeserializeObjectFromString( EncodingEx.Base64.Decoder.DecodeString(Encoding.UTF8, ser), typeof(Template)); if (entryTemplate.BoundUrl.Value.Value.Contains(template.BoundUrl.Value.Value) || template.BoundUrl.Value.Value.Contains(entryTemplate.BoundUrl.Value.Value)) { MessageBox.Show("Cannot add template '" + template.Name + "' (UTID: '" + template.UTID + "') because of the existing template '" + entryTemplate.Name + "' in the group '" + pwGroup.Name + "', which maps on this URI."); foundAnotherEntry = true; } if (entryTemplate.UTID == template.UTID) { MessageBox.Show("Cannot add template '" + template.Name + "' (UTID: '" + template.UTID + "') because of the existing template '" + entryTemplate.Name + "' in the group '" + pwGroup.Name + "', which has the same UTID"); foundAnotherEntry = true; } } } } if (foundAnotherEntry) { return(false); } string serializedEntry = SerializationDotNet2.Xml.Serializer.SerializeObjectToString(CleanTemplate(template), template.GetType()); string encodedEntry = EncodingEx.Base64.Encoder.EncodeString(Encoding.UTF8, serializedEntry); PwEntry entry = new PwEntry(true, true); entry.Strings.Set(PwDefs.NotesField, new ProtectedString(true, encodedEntry)); entry.Strings.Set(PwDefs.TitleField, new ProtectedString(true, template.Name + " Version " + template.TemplateVersion + " UTID: " + template.UTID)); entry.Strings.Set(PwDefs.UrlField, new ProtectedString(true, template.BoundUrl.Value.Value)); _editPwGroup.AddEntry(entry, true); KeePassPasswordChangerExt.RefreshUiEntry(entry); //KeePassPasswordChangerExt.SaveCurrentDb(); RefreshUI(); return(true); }
private void DeleteTemplate(Template template) { int foundEntries = 0; PwEntry singlePwEntry = null; foreach (var pwGroup in _allGroups) { foreach (var pwEntry in pwGroup.GetEntries(false)) { string ser = pwEntry.Strings.Get(PwDefs.NotesField).ReadString(); if (ser != null) { Template entryTemplate = (Template) SerializationDotNet2.Xml.Deserializer.DeserializeObjectFromString( EncodingEx.Base64.Decoder.DecodeString(Encoding.UTF8, ser), typeof(Template)); if (entryTemplate.UTID == template.UTID) { singlePwEntry = pwEntry; foundEntries++; } else if (entryTemplate.BoundUrl.Value.Value.Contains(template.BoundUrl.Value.Value) || template.BoundUrl.Value.Value.Contains(entryTemplate.BoundUrl.Value.Value)) { foundEntries++; } } } } if (singlePwEntry == null) { MessageBox.Show("Could not find any template to delete, sorry"); return; } if (foundEntries > 1) { MessageBox.Show("There are too many templates that match on the bound URL or share the same UTID"); return; } PwGroup pwgroup = singlePwEntry.ParentGroup; pwgroup.Entries.Remove(singlePwEntry); KeePassPasswordChangerExt.RefreshUiGroup(pwgroup); //KeePassPasswordChangerExt.SaveCurrentDb(); RefreshUI(); }
public Condition(string usedOperator, string firstOperand, string secondOperand) : this() { UsedOperator = usedOperator; FirstOperand = firstOperand; SecondOperand = secondOperand; HashingEx.Hashing.GetSha1Hash(DateTime.Now.ToString() + " " + firstOperand + secondOperand + usedOperator + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString()); }
public Condition() { UCID = HashingEx.Hashing.GetSha1Hash(DateTime.Now.ToString() + " " + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString()); }
public void TimerTemplateRunOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) { _timer.Stop(); Open cmd = new Open(HashingEx.Hashing.GetSha1Hash(DateTime.Now.ToString() + " " + counter++ + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString())); _cefControl.AddCefBrowserCommand(cmd); UID = cmd.UID; Thread.Sleep(1000); bool success = true; while (true) { Thread.Sleep(100); if (CefControl.BrowserCommandsCompleted.ContainsKey(cmd.UCID)) { break; } } if (TemplateElements.Count > 0) { foreach (var templateElement in TemplateElements) { if (!RunTemplate(templateElement, _cefControl)) { success = false; break; } } } if (AutomaticallyCloseWindowWhenOutOfCommands && CefControl.CefBrowserSessions.ContainsKey(UID) || !success && CefControl.CefBrowserSessions.ContainsKey(UID)) { Quit quit = new Quit(UID); _cefControl.AddCefBrowserCommand(quit); while (true) { Thread.Sleep(100); if (CefControl.BrowserCommandsCompleted.ContainsKey(cmd.UCID)) { break; } } } Completed = true; Successful = success; bool run = true; while (run) { try { TemplateManagement.LockTemplates.AcquireWriterLock(Options.LockTimeOut); if (TemplateManagement.TemplatesInTransit.ContainsKey(UTID)) { TemplateManagement.TemplatesCompleted.Add(UTID, TemplateManagement.TemplatesInTransit[UTID]); Template template = TemplateManagement.TemplatesInTransit[UTID]; ProtectedString oldPassword = null, newPassword = null; foreach (var templateAvailableResourceKeyValuePair in template.AvailableResources) { if ( BaseObject.ExtractSinglePlaceholderToString(templateAvailableResourceKeyValuePair.Key) == "" && (templateAvailableResourceKeyValuePair.Value).GetType().Name == "Text") { newPassword = ((Text)templateAvailableResourceKeyValuePair.Value).Value; } if ( BaseObject.ExtractSinglePlaceholderToString(templateAvailableResourceKeyValuePair.Key) == PwDefs.PasswordField && (templateAvailableResourceKeyValuePair.Value).GetType().Name == "Text") { oldPassword = ((Text)templateAvailableResourceKeyValuePair.Value).Value; } } if (template.SetNewPasswordWhenSuccess) { PwEntry entry = KeePassPasswordChangerExt._mHost.MainWindow.ActiveDatabase.RootGroup.FindEntry( new PwUuid(template.PwUidBytes), true); PwEntry newone = new PwEntry(true, true); if (Successful) { newone.Strings.Set(PwDefs.PasswordField, new ProtectedString(true, oldPassword.ReadString())); newone.Strings.Set(PwDefs.TitleField, new ProtectedString(true, "Old Password")); entry.History.Add(newone); if (newPassword != null) { entry.Strings.Set(PwDefs.PasswordField, newPassword); } } else { if (newPassword != null) { newone.Strings.Set(PwDefs.PasswordField, new ProtectedString(true, newPassword.ReadString())); newone.Strings.Set(PwDefs.TitleField, new ProtectedString(true, "Not applied new password")); entry.History.Add(newone); } } KeePassPasswordChangerExt._mHost.MainWindow.BeginInvoke((MethodInvoker) delegate() { entry.LastModificationTime = TimeUtil.ToUtc(DateTime.Now, false); KeePassPasswordChangerExt.RefreshUiEntry(entry); }); //KeePassPasswordChangerExt.SaveCurrentDb(); } TemplateManagement.TemplatesInTransit.Remove(UTID); } run = false; } catch (ApplicationException ex) { ExceptionHandling.Handling.GetException("ReaderWriterLock", ex); } finally { if (TemplateManagement.LockTemplates.IsWriterLockHeld) { TemplateManagement.LockTemplates.ReleaseWriterLock(); } } } //_timer.Start(); }
public void GenerateNewUtid(string additional) { UTID = HashingEx.Hashing.GetSha512Hash(DateTime.Now.ToString() + " " + counter++ + additional + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString()); }
private void GenerateNewUtid() { UTID = HashingEx.Hashing.GetSha512Hash(DateTime.Now.ToString() + " " + counter++ + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString()); }
private void Overview_FormClosing(object sender, FormClosingEventArgs e) { KeePassPasswordChangerExt.SaveCurrentDb(); }
private void buttonImportTemplates_Click(object sender, EventArgs e) { try { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); folderBrowserDialog.Description = "Select a destination folder for your " + (_isPrivateMode ? "private" : "public") + " templates to export to (subfolder will be created)"; folderBrowserDialog.ShowNewFolderButton = true; //folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyDocuments; folderBrowserDialog.SelectedPath = "Exported " + (_isPrivateMode ? "Private" : "Public") + " Templates"; int count = 0; if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { if (Directory.Exists(folderBrowserDialog.SelectedPath)) { foreach (var file in Directory.GetFiles(folderBrowserDialog.SelectedPath)) { if (!file.EndsWith(Options.ExportExtension)) { continue; } try { string content = File.ReadAllText(file, Encoding.UTF8); try { string decoded = EncodingEx.Base64.Decoder.DecodeString(Encoding.UTF8, content); try { Template template = (Template) SerializationDotNet2.Xml.Deserializer.DeserializeObjectFromString(decoded, typeof(Template)); bool foundAnotherEntry = false; PwEntry oldEntry = null; foreach (var pwGroup in _allGroups) { foreach (var pwEntry in pwGroup.GetEntries(false)) { string ser = pwEntry.Strings.Get(PwDefs.NotesField).ReadString(); if (ser != null) { Template entryTemplate = (Template) SerializationDotNet2.Xml.Deserializer .DeserializeObjectFromString( EncodingEx.Base64.Decoder.DecodeString(Encoding.UTF8, ser), typeof(Template)); if ( entryTemplate.BoundUrl.Value.Value.Contains( template.BoundUrl.Value.Value) || template.BoundUrl.Value.Value.Contains( entryTemplate.BoundUrl.Value.Value)) { if (entryTemplate.UTID == template.UTID) { if (template.TemplateVersion > entryTemplate.TemplateVersion) { oldEntry = pwEntry; continue; } } MessageBox.Show("Cannot add template '" + template.Name + "' (UTID: '" + template.UTID + "') because of the existing template '" + entryTemplate.Name + "' in the group '" + pwGroup.Name + "', which maps on this URI."); foundAnotherEntry = true; } if (entryTemplate.UTID == template.UTID) { if (template.TemplateVersion > entryTemplate.TemplateVersion) { oldEntry = pwEntry; continue; } MessageBox.Show("Cannot add template '" + template.Name + "' Version '" + template.TemplateVersion + "' (UTID: '" + template.UTID + ")' because of the existing template '" + entryTemplate.Name + "' has with Version '" + template.TemplateVersion + "' a higher^or equal number in the group '" + pwGroup.Name + "', which has the same UTID"); foundAnotherEntry = true; } } } } if (foundAnotherEntry) { continue; } if (_isPrivateMode) { DialogResult dialogResult = MessageBox.Show( "Do you want to export the template '" + template.Name + "' Version '" + template.TemplateVersion.ToString() + "'", "Export Template?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { continue; } if (dialogResult == DialogResult.Cancel) { break; } } PwEntry entry = new PwEntry(true, true); entry.Strings.Set(PwDefs.NotesField, new ProtectedString(true, content)); entry.Strings.Set(PwDefs.TitleField, new ProtectedString(true, template.Name + " Version " + template.TemplateVersion + " UTID: " + template.UTID)); entry.Strings.Set(PwDefs.UrlField, new ProtectedString(true, template.BoundUrl.Value.Value)); _editPwGroup.AddEntry(entry, true); KeePassPasswordChangerExt.RefreshUiEntry(entry); if (oldEntry != null) { PwGroup pwGroup = oldEntry.ParentGroup; pwGroup.Entries.Remove(oldEntry); KeePassPasswordChangerExt.RefreshUiGroup(pwGroup); } //KeePassPasswordChangerExt.SaveCurrentDb(); count++; } catch (Exception ex) { MessageBox.Show("Could not deserialize plaintext\n\n" + ex.Message + "\n\n" + ex.StackTrace); } } catch (Exception ex) { MessageBox.Show("Could not base 64 decode file\n\n" + ex.Message + "\n\n" + ex.StackTrace); } } catch (Exception ex) { MessageBox.Show("Could not read file\n\n" + ex.Message + "\n\n" + ex.StackTrace); } } } } MessageBox.Show("Completed importing " + count + " Templates", "Completed"); if (count > 0) { RefreshUI(); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace); } }