Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions KeeAgent/KeeAgentExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,26 @@ 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";
const string entryMenuItemName = "KeeAgentEntryMenuItem";
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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}



/// <summary>
/// Ripped from: https://github.com/dlech/SshAgentLib/blob/6114528e9652457f0064099e6e39769fe6aaa39e/Ui/WinForms/Default.cs
/// In order to implement https://github.com/dlech/KeeAgent/pull/355
/// </summary>
/// <param name="key"></param>
/// <param name="process"></param>
/// <param name="user"></param>
/// <param name="fromHost"></param>
/// <param name="toHost"></param>
/// <returns></returns>
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;
Expand Down Expand Up @@ -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()
Expand All @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions KeeAgent/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,10 @@ public Options()
/// When <c>true</c>, we will not display a progress bar during SSH key decryption.
/// </summary>
public bool DisableKeyDecryptionProgressBar { get; set; }

/// <summary>
/// When <c>true</c>, use the entry's source instead of comment for the confirmation dialog.
/// </summary>
public static bool UseSourceInConfirmationDialog { get; set; }
}
}
9 changes: 9 additions & 0 deletions KeeAgent/Translatable.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions KeeAgent/Translatable.resx
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,7 @@
<data name="OptionUseWindowsOpenSshPipe" xml:space="preserve">
<value>Enable agent for Windows OpenSSH</value>
</data>
<data name="OptionUseSourceInConfirmationDialog" xml:space="preserve">
<value>Use key source instead of key comment in confirmation dialog</value>
</data>
</root>
3 changes: 3 additions & 0 deletions KeeAgent/UI/OptionsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down