diff --git a/KeePassNatMsg/KeePassNatMsg.csproj b/KeePassNatMsg/KeePassNatMsg.csproj
index cd020fe..c1e3c6b 100644
--- a/KeePassNatMsg/KeePassNatMsg.csproj
+++ b/KeePassNatMsg/KeePassNatMsg.csproj
@@ -66,6 +66,7 @@
+
Form
diff --git a/KeePassNatMsg/Options/DatabaseKeyItem.cs b/KeePassNatMsg/Options/DatabaseKeyItem.cs
new file mode 100644
index 0000000..c9ba5bf
--- /dev/null
+++ b/KeePassNatMsg/Options/DatabaseKeyItem.cs
@@ -0,0 +1,8 @@
+namespace KeePassNatMsg.Options
+{
+ class DatabaseKeyItem
+ {
+ public string Name { get; set; }
+ public string Key { get; set; }
+ }
+}
diff --git a/KeePassNatMsg/Options/OptionsForm.Designer.cs b/KeePassNatMsg/Options/OptionsForm.Designer.cs
index ff5835d..a6f2815 100644
--- a/KeePassNatMsg/Options/OptionsForm.Designer.cs
+++ b/KeePassNatMsg/Options/OptionsForm.Designer.cs
@@ -40,7 +40,6 @@ private void InitializeComponent()
this.matchSchemesCheckbox = new System.Windows.Forms.CheckBox();
this.removePermissionsButton = new System.Windows.Forms.Button();
this.unlockDatabaseCheckbox = new System.Windows.Forms.CheckBox();
- this.removeButton = new System.Windows.Forms.Button();
this.credMatchingCheckbox = new System.Windows.Forms.CheckBox();
this.credNotifyCheckbox = new System.Windows.Forms.CheckBox();
this.tabPage2 = new System.Windows.Forms.TabPage();
@@ -58,14 +57,28 @@ private void InitializeComponent()
this.label1 = new System.Windows.Forms.Label();
this.credAllowUpdatesCheckbox = new System.Windows.Forms.CheckBox();
this.credAllowAccessCheckbox = new System.Windows.Forms.CheckBox();
+ this.tabPage3 = new System.Windows.Forms.TabPage();
+ this.scKeysMain = new System.Windows.Forms.SplitContainer();
+ this.dgvKeys = new System.Windows.Forms.DataGridView();
+ this.colName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.colKey = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.btnRemoveAllKeys = new System.Windows.Forms.Button();
+ this.btnRemoveSelectedKeys = new System.Windows.Forms.Button();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
+ this.tabPage3.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.scKeysMain)).BeginInit();
+ this.scKeysMain.Panel1.SuspendLayout();
+ this.scKeysMain.Panel2.SuspendLayout();
+ this.scKeysMain.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dgvKeys)).BeginInit();
this.SuspendLayout();
//
// cancelButton
//
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(313, 470);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(88, 28);
@@ -93,11 +106,13 @@ private void InitializeComponent()
| System.Windows.Forms.AnchorStyles.Right)));
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
+ this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Location = new System.Drawing.Point(1, 3);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(410, 460);
this.tabControl1.TabIndex = 3;
+ this.tabControl1.Selected += new System.Windows.Forms.TabControlEventHandler(this.tabControl1_Selected);
//
// tabPage1
//
@@ -109,7 +124,6 @@ private void InitializeComponent()
this.tabPage1.Controls.Add(this.matchSchemesCheckbox);
this.tabPage1.Controls.Add(this.removePermissionsButton);
this.tabPage1.Controls.Add(this.unlockDatabaseCheckbox);
- this.tabPage1.Controls.Add(this.removeButton);
this.tabPage1.Controls.Add(this.credMatchingCheckbox);
this.tabPage1.Controls.Add(this.credNotifyCheckbox);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
@@ -122,9 +136,9 @@ private void InitializeComponent()
//
// lblProxyVersion
//
- this.lblProxyVersion.Location = new System.Drawing.Point(14, 270);
+ this.lblProxyVersion.Location = new System.Drawing.Point(14, 236);
this.lblProxyVersion.Name = "lblProxyVersion";
- this.lblProxyVersion.Size = new System.Drawing.Size(372, 95);
+ this.lblProxyVersion.Size = new System.Drawing.Size(372, 129);
this.lblProxyVersion.TabIndex = 22;
this.lblProxyVersion.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
//
@@ -188,7 +202,7 @@ private void InitializeComponent()
this.removePermissionsButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.removePermissionsButton.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
- this.removePermissionsButton.Location = new System.Drawing.Point(14, 239);
+ this.removePermissionsButton.Location = new System.Drawing.Point(14, 205);
this.removePermissionsButton.Name = "removePermissionsButton";
this.removePermissionsButton.Size = new System.Drawing.Size(372, 28);
this.removePermissionsButton.TabIndex = 16;
@@ -206,18 +220,6 @@ private void InitializeComponent()
this.unlockDatabaseCheckbox.Text = "Re&quest for unlocking the database if it is locked";
this.unlockDatabaseCheckbox.UseVisualStyleBackColor = true;
//
- // removeButton
- //
- this.removeButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.removeButton.Location = new System.Drawing.Point(14, 205);
- this.removeButton.Name = "removeButton";
- this.removeButton.Size = new System.Drawing.Size(372, 28);
- this.removeButton.TabIndex = 11;
- this.removeButton.Text = "R&emove all shared encryption-keys from active database";
- this.removeButton.UseVisualStyleBackColor = true;
- this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
- //
// credMatchingCheckbox
//
this.credMatchingCheckbox.AutoSize = true;
@@ -402,6 +404,89 @@ private void InitializeComponent()
this.credAllowAccessCheckbox.Text = "Always allow &access to entries";
this.credAllowAccessCheckbox.UseVisualStyleBackColor = true;
//
+ // tabPage3
+ //
+ this.tabPage3.Controls.Add(this.scKeysMain);
+ this.tabPage3.Location = new System.Drawing.Point(4, 22);
+ this.tabPage3.Name = "tabPage3";
+ this.tabPage3.Size = new System.Drawing.Size(402, 434);
+ this.tabPage3.TabIndex = 2;
+ this.tabPage3.Text = "Keys";
+ this.tabPage3.UseVisualStyleBackColor = true;
+ //
+ // scKeysMain
+ //
+ this.scKeysMain.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.scKeysMain.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
+ this.scKeysMain.Location = new System.Drawing.Point(0, 0);
+ this.scKeysMain.Name = "scKeysMain";
+ this.scKeysMain.Orientation = System.Windows.Forms.Orientation.Horizontal;
+ //
+ // scKeysMain.Panel1
+ //
+ this.scKeysMain.Panel1.Controls.Add(this.dgvKeys);
+ //
+ // scKeysMain.Panel2
+ //
+ this.scKeysMain.Panel2.Controls.Add(this.btnRemoveAllKeys);
+ this.scKeysMain.Panel2.Controls.Add(this.btnRemoveSelectedKeys);
+ this.scKeysMain.Size = new System.Drawing.Size(402, 434);
+ this.scKeysMain.SplitterDistance = 396;
+ this.scKeysMain.TabIndex = 0;
+ //
+ // dgvKeys
+ //
+ this.dgvKeys.AllowUserToAddRows = false;
+ this.dgvKeys.AllowUserToDeleteRows = false;
+ this.dgvKeys.AllowUserToResizeRows = false;
+ this.dgvKeys.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
+ this.dgvKeys.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dgvKeys.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.colName,
+ this.colKey});
+ this.dgvKeys.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.dgvKeys.Location = new System.Drawing.Point(0, 0);
+ this.dgvKeys.Name = "dgvKeys";
+ this.dgvKeys.ReadOnly = true;
+ this.dgvKeys.RowHeadersVisible = false;
+ this.dgvKeys.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.dgvKeys.Size = new System.Drawing.Size(402, 396);
+ this.dgvKeys.TabIndex = 0;
+ //
+ // colName
+ //
+ this.colName.DataPropertyName = "Name";
+ this.colName.HeaderText = "Name";
+ this.colName.Name = "colName";
+ this.colName.ReadOnly = true;
+ //
+ // colKey
+ //
+ this.colKey.DataPropertyName = "Key";
+ this.colKey.HeaderText = "Key";
+ this.colKey.Name = "colKey";
+ this.colKey.ReadOnly = true;
+ //
+ // btnRemoveAllKeys
+ //
+ this.btnRemoveAllKeys.Location = new System.Drawing.Point(205, 3);
+ this.btnRemoveAllKeys.Name = "btnRemoveAllKeys";
+ this.btnRemoveAllKeys.Size = new System.Drawing.Size(150, 23);
+ this.btnRemoveAllKeys.TabIndex = 1;
+ this.btnRemoveAllKeys.Text = "Remove All Keys";
+ this.btnRemoveAllKeys.UseVisualStyleBackColor = true;
+ this.btnRemoveAllKeys.Click += new System.EventHandler(this.btnRemoveAllKeys_Click);
+ //
+ // btnRemoveSelectedKeys
+ //
+ this.btnRemoveSelectedKeys.Location = new System.Drawing.Point(49, 3);
+ this.btnRemoveSelectedKeys.Name = "btnRemoveSelectedKeys";
+ this.btnRemoveSelectedKeys.Size = new System.Drawing.Size(150, 23);
+ this.btnRemoveSelectedKeys.TabIndex = 0;
+ this.btnRemoveSelectedKeys.Text = "Remove Selected Keys";
+ this.btnRemoveSelectedKeys.UseVisualStyleBackColor = true;
+ this.btnRemoveSelectedKeys.Click += new System.EventHandler(this.btnRemoveSelectedKeys_Click);
+ //
// OptionsForm
//
this.AcceptButton = this.okButton;
@@ -426,6 +511,12 @@ private void InitializeComponent()
this.tabPage1.PerformLayout();
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
+ this.tabPage3.ResumeLayout(false);
+ this.scKeysMain.Panel1.ResumeLayout(false);
+ this.scKeysMain.Panel2.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.scKeysMain)).EndInit();
+ this.scKeysMain.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dgvKeys)).EndInit();
this.ResumeLayout(false);
}
@@ -440,7 +531,6 @@ private void InitializeComponent()
private System.Windows.Forms.CheckBox matchSchemesCheckbox;
private System.Windows.Forms.Button removePermissionsButton;
private System.Windows.Forms.CheckBox unlockDatabaseCheckbox;
- private System.Windows.Forms.Button removeButton;
private System.Windows.Forms.CheckBox credMatchingCheckbox;
private System.Windows.Forms.CheckBox credNotifyCheckbox;
private System.Windows.Forms.TabPage tabPage2;
@@ -459,8 +549,15 @@ private void InitializeComponent()
private System.Windows.Forms.Label lblProxyVersion;
private System.Windows.Forms.TextBox txtKPXCVerOverride;
private System.Windows.Forms.Label label5;
- private System.Windows.Forms.ComboBox comboBoxDatabases;
- private System.Windows.Forms.Label label6;
- private System.Windows.Forms.CheckBox chkSearchUrls;
- }
+ private System.Windows.Forms.ComboBox comboBoxDatabases;
+ private System.Windows.Forms.Label label6;
+ private System.Windows.Forms.CheckBox chkSearchUrls;
+ private System.Windows.Forms.TabPage tabPage3;
+ private System.Windows.Forms.SplitContainer scKeysMain;
+ private System.Windows.Forms.DataGridView dgvKeys;
+ private System.Windows.Forms.DataGridViewTextBoxColumn colName;
+ private System.Windows.Forms.DataGridViewTextBoxColumn colKey;
+ private System.Windows.Forms.Button btnRemoveAllKeys;
+ private System.Windows.Forms.Button btnRemoveSelectedKeys;
+ }
}
\ No newline at end of file
diff --git a/KeePassNatMsg/Options/OptionsForm.cs b/KeePassNatMsg/Options/OptionsForm.cs
index 1084369..90081ca 100644
--- a/KeePassNatMsg/Options/OptionsForm.cs
+++ b/KeePassNatMsg/Options/OptionsForm.cs
@@ -89,51 +89,6 @@ private void cancelButton_Click(object sender, EventArgs e)
Close();
}
- private void removeButton_Click(object sender, EventArgs e)
- {
- if (KeePass.Program.MainForm.DocumentManager.ActiveDatabase.IsOpen)
- {
- PwDatabase db = KeePass.Program.MainForm.DocumentManager.ActiveDatabase;
- List deleteKeys = new List();
-
- foreach (var cd in db.CustomData)
- {
- if (cd.Key.StartsWith(KeePassNatMsgExt.KeePassNatMsgConfig))
- {
- deleteKeys.Add(cd.Key);
- }
- }
-
- if (deleteKeys.Count > 0)
- {
- foreach (var key in deleteKeys)
- {
- db.CustomData.Remove(key);
- }
-
- KeePass.Program.MainForm.UpdateUI(false, null, true, db.RootGroup, true, null, true);
- MessageBox.Show(
- String.Format("Successfully removed {0} encryption-key{1} from KeePassNatMsg Settings.", deleteKeys.Count.ToString(), deleteKeys.Count == 1 ? "" : "s"),
- String.Format("Removed {0} key{1} from database", deleteKeys.Count.ToString(), deleteKeys.Count == 1 ? "" : "s"),
- MessageBoxButtons.OK,
- MessageBoxIcon.Information
- );
- }
- else
- {
- MessageBox.Show(
- "No shared encryption-keys found in KeePassNatMsg Settings.", "No keys found",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information
- );
- }
- }
- else
- {
- MessageBox.Show("The active database is locked!\nPlease unlock the selected database or choose another one which is unlocked.", "Database locked!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
private void removePermissionsButton_Click(object sender, EventArgs e)
{
if (KeePass.Program.MainForm.DocumentManager.ActiveDatabase.IsOpen)
@@ -317,5 +272,102 @@ private void InitDatabasesDropdown()
comboBoxDatabases.Items.Add(new DatabaseItem { Id = dbIdentifier, DbHash = KeePassNatMsgExt.ExtInstance.GetDbHash(item.Database) });
}
}
+
+ private void LoadDatabaseKeys()
+ {
+ LoadDatabaseKeys(KeePass.Program.MainForm.DocumentManager.ActiveDatabase);
+ }
+
+ private void LoadDatabaseKeys(PwDatabase db)
+ {
+ if (db.IsOpen)
+ {
+ var keys = new List();
+
+ foreach (var cd in db.CustomData)
+ {
+ if (cd.Key.StartsWith(KeePassNatMsgExt.KeePassNatMsgConfig))
+ {
+ var keyName = cd.Key.Substring(KeePassNatMsgExt.KeePassNatMsgConfig.Length);
+ keys.Add(new DatabaseKeyItem { Name = keyName, Key = cd.Value });
+ }
+ }
+
+ dgvKeys.DataSource = keys;
+ }
+ }
+
+ private void tabControl1_Selected(object sender, TabControlEventArgs e)
+ {
+ if (e.TabPage == tabPage3)
+ {
+ LoadDatabaseKeys();
+ }
+ }
+
+ private void btnRemoveSelectedKeys_Click(object sender, EventArgs e)
+ {
+ var db = KeePass.Program.MainForm.DocumentManager.ActiveDatabase;
+
+ if (db.IsOpen)
+ {
+ var items = dgvKeys.SelectedRows
+ .OfType()
+ .Select(x => KeePassNatMsgExt.KeePassNatMsgConfig + (x.DataBoundItem as DatabaseKeyItem)?.Name);
+
+ var deleteKeys = db.CustomData
+ .Where(x => items.Contains(x.Key))
+ .Select(x => x.Key).ToList();
+
+ RemoveKeys(deleteKeys, db);
+ }
+ }
+
+ private void btnRemoveAllKeys_Click(object sender, EventArgs e)
+ {
+ var db = KeePass.Program.MainForm.DocumentManager.ActiveDatabase;
+
+ if (db.IsOpen)
+ {
+ var deleteKeys = db.CustomData
+ .Where(x => x.Key.StartsWith(KeePassNatMsgExt.KeePassNatMsgConfig))
+ .Select(x => x.Key).ToList();
+
+ RemoveKeys(deleteKeys, db);
+ }
+ else
+ {
+ MessageBox.Show("The active database is locked!\nPlease unlock the selected database or choose another one which is unlocked.", "Database locked!", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void RemoveKeys(List keys, PwDatabase db)
+ {
+ if (keys.Count > 0)
+ {
+ foreach (var key in keys)
+ {
+ db.CustomData.Remove(key);
+ }
+
+ LoadDatabaseKeys(db);
+
+ KeePass.Program.MainForm.UpdateUI(false, null, true, db.RootGroup, true, null, true);
+ MessageBox.Show(
+ $"Successfully removed {keys.Count} encryption-key{(keys.Count == 1 ? "" : "s")} from KeePassNatMsg Settings.",
+ $"Removed {keys.Count} key{(keys.Count == 1 ? "" : "s")} from database",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Information
+ );
+ }
+ else
+ {
+ MessageBox.Show(
+ "No shared encryption-keys found in KeePassNatMsg Settings.", "No keys found",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Information
+ );
+ }
+ }
}
}
diff --git a/KeePassNatMsg/Options/OptionsForm.resx b/KeePassNatMsg/Options/OptionsForm.resx
index 1af7de1..f881651 100644
--- a/KeePassNatMsg/Options/OptionsForm.resx
+++ b/KeePassNatMsg/Options/OptionsForm.resx
@@ -117,4 +117,10 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ True
+
+
+ True
+
\ No newline at end of file