diff --git a/KeeAgent/KeeAgentExt.cs b/KeeAgent/KeeAgentExt.cs
index 0e64ea6..58d33a0 100644
--- a/KeeAgent/KeeAgentExt.cs
+++ b/KeeAgent/KeeAgentExt.cs
@@ -64,6 +64,7 @@ public sealed partial class KeeAgentExt : Plugin
pluginNamespace + ".UserPicksKeyOnRequestIdentities";
const string ignoreMissingExternalKeyFilesName = pluginNamespace + ".IgnoreMissingExternalKeyFilesName";
const string disableKeyDecryptionProgressBarName = pluginNamespace + ".DisableKeyDecryptionProgressBar";
+ const string useSourceInConfirmationDialog = pluginNamespace + ".UseSourceInConfirmationDialog";
const string keyFilePathSprPlaceholder = @"{KEEAGENT:KEYFILEPATH}";
const string identFileOptSprPlaceholder = @"{KEEAGENT:IDENTFILEOPT}";
const string groupMenuItemName = "KeeAgentGroupMenuItem";
@@ -71,6 +72,18 @@ public sealed partial class KeeAgentExt : Plugin
const string entryMenuLoadSubmenuItemName = "KeeAgentEntryMenuLoadSubmenuItem";
const string entryMenuUrlSubmenuItemName = "KeeAgentEntryMenuUrlSubmenuItem";
+
+ /**
+ * Ripped from: https://github.com/dlech/SshAgentLib/blob/6114528e9652457f0064099e6e39769fe6aaa39e/Ui/WinForms/Default.cs
+ * In order to implement https://github.com/dlech/KeeAgent/pull/355
+ *
+ * MessageBox options for topmost and focus from:
+ * https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx
+ */
+ const MessageBoxOptions TopMost = (MessageBoxOptions)0x00040000;
+ const MessageBoxOptions SetForeground = (MessageBoxOptions)0x00010000;
+ const MessageBoxOptions SystemModal = (MessageBoxOptions)0x00001000;
+
class KeyFileInfo
{
public KeyFileInfo(string path, bool isTemporary)
@@ -125,7 +138,7 @@ public override bool Initialize(IPluginHost host)
pagent.ConfirmUserPermissionCallback = ConfirmUserPermissionCallback;
} else {
pagent.FilterKeyListCallback = FilterKeyListMono;
- pagent.ConfirmUserPermissionCallback = Default.ConfirmCallback;
+ pagent.ConfirmUserPermissionCallback = ConfirmCallback;
}
agent = pagent;
if (Options.UseCygwinSocket) {
@@ -164,7 +177,7 @@ public override bool Initialize(IPluginHost host)
unixAgent.ConfirmUserPermissionCallback = ConfirmUserPermissionCallback;
} else {
unixAgent.FilterKeyListCallback = FilterKeyListMono;
- unixAgent.ConfirmUserPermissionCallback = Default.ConfirmCallback;
+ unixAgent.ConfirmUserPermissionCallback = ConfirmCallback;
}
agent = unixAgent;
if (Options.UnixSocketPath == null) {
@@ -227,10 +240,60 @@ private bool ConfirmUserPermissionCallback(ISshKey key, Process process, string
string toHost)
{
var result = false;
- _uiThread.Invoke(() => result = Default.ConfirmCallback(key, process, user, fromHost, toHost));
+ _uiThread.Invoke(() => result = ConfirmCallback(key, process, user, fromHost, toHost));
return result;
}
+
+
+ ///
+ /// Ripped from: https://github.com/dlech/SshAgentLib/blob/6114528e9652457f0064099e6e39769fe6aaa39e/Ui/WinForms/Default.cs
+ /// In order to implement https://github.com/dlech/KeeAgent/pull/355
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool ConfirmCallback(
+ ISshKey key,
+ Process process,
+ string user,
+ string fromHost,
+ string toHost
+ )
+ {
+ var programName = Strings.askConfirmKeyUnknownProcess;
+
+ if (process != null)
+ {
+ programName = string.Format(
+ "{0} ({1})",
+ process.MainWindowTitle,
+ process.ProcessName
+ );
+ }
+
+ // TODO: add user/host info to message
+
+ var result = MessageBox.Show(
+ string.Format(
+ Strings.askConfirmKey,
+ programName,
+ Options.UseSourceInConfirmationDialog ? key.Source : key.Comment,
+ key.GetMD5Fingerprint().ToHexString()
+ ),
+ Util.AssemblyTitle,
+ MessageBoxButtons.YesNo,
+ MessageBoxIcon.Question,
+ MessageBoxDefaultButton.Button2,
+ TopMost | SetForeground | SystemModal
+ );
+
+ return result == DialogResult.Yes;
+ }
+
public override void Terminate()
{
GlobalWindowManager.WindowAdded -= WindowAddedHandler;
@@ -649,6 +712,7 @@ internal void SaveGlobalOptions()
Options.UserPicksKeyOnRequestIdentities);
config.SetBool(ignoreMissingExternalKeyFilesName, Options.IgnoreMissingExternalKeyFiles);
config.SetBool(disableKeyDecryptionProgressBarName, Options.DisableKeyDecryptionProgressBar);
+ config.SetBool(useSourceInConfirmationDialog, Options.UseSourceInConfirmationDialog);
}
private void LoadOptions()
@@ -672,6 +736,7 @@ private void LoadOptions()
config.GetBool(userPicksKeyOnRequestIdentitiesOptionName, false);
Options.IgnoreMissingExternalKeyFiles = config.GetBool(ignoreMissingExternalKeyFilesName, false);
Options.DisableKeyDecryptionProgressBar = config.GetBool(disableKeyDecryptionProgressBarName, false);
+ Options.UseSourceInConfirmationDialog = config.GetBool(useSourceInConfirmationDialog, false);
string defaultLogFileNameValue = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
diff --git a/KeeAgent/Options.cs b/KeeAgent/Options.cs
index 814780d..4f0f9cd 100644
--- a/KeeAgent/Options.cs
+++ b/KeeAgent/Options.cs
@@ -112,5 +112,10 @@ public Options()
/// When true, we will not display a progress bar during SSH key decryption.
///
public bool DisableKeyDecryptionProgressBar { get; set; }
+
+ ///
+ /// When true, use the entry's source instead of comment for the confirmation dialog.
+ ///
+ public static bool UseSourceInConfirmationDialog { get; set; }
}
}
diff --git a/KeeAgent/Translatable.Designer.cs b/KeeAgent/Translatable.Designer.cs
index 6c99420..835d6c4 100644
--- a/KeeAgent/Translatable.Designer.cs
+++ b/KeeAgent/Translatable.Designer.cs
@@ -302,6 +302,15 @@ internal static string OptionUserPicksKeyOnRequestIdentities {
}
}
+ ///
+ /// Looks up a localized string similar to Use key source instead of key comment in confirmation dialog.
+ ///
+ internal static string OptionUseSourceInConfirmationDialog {
+ get {
+ return ResourceManager.GetString("OptionUseSourceInConfirmationDialog", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Enable agent for Windows OpenSSH.
///
diff --git a/KeeAgent/Translatable.resx b/KeeAgent/Translatable.resx
index 602c2fd..cbbefeb 100644
--- a/KeeAgent/Translatable.resx
+++ b/KeeAgent/Translatable.resx
@@ -221,4 +221,7 @@
Enable agent for Windows OpenSSH
+
+ Use key source instead of key comment in confirmation dialog
+
diff --git a/KeeAgent/UI/OptionsPanel.cs b/KeeAgent/UI/OptionsPanel.cs
index 536be9e..2601078 100644
--- a/KeeAgent/UI/OptionsPanel.cs
+++ b/KeeAgent/UI/OptionsPanel.cs
@@ -65,6 +65,9 @@ public OptionsPanel(KeeAgentExt ext)
optionsList.CreateItem(ext.Options, "DisableKeyDecryptionProgressBar",
optionsGroup, Translatable.OptionDisableKeyDecryptionProgressBar);
+ optionsList.CreateItem(ext.Options, "UseSourceInConfirmationDialog",
+ optionsGroup, Translatable.OptionUseSourceInConfirmationDialog);
+
var agentModeOptionsGroup = new ListViewGroup("agentMode",
"Agent Mode Options (no effect in Client Mode)");
customListViewEx.Groups.Add(agentModeOptionsGroup);