From 77e7d30899cf695eab5f999e8f81a92744941107 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 4 Feb 2023 14:43:22 -0600 Subject: [PATCH] fall back to encrypted private key comment when available Fixes #375 --- KeeAgent/ExtensionMethods.cs | 13 ++++++++++--- SshAgentLib | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/KeeAgent/ExtensionMethods.cs b/KeeAgent/ExtensionMethods.cs index 8e3185a..63b2f9f 100644 --- a/KeeAgent/ExtensionMethods.cs +++ b/KeeAgent/ExtensionMethods.cs @@ -379,12 +379,13 @@ public static ISshKey GetSshKey(this PwEntry entry) var privateKey = settings.GetSshPrivateKey(entry.Binaries); AsymmetricKeyParameter parameter; + var comment = string.Empty; if (privateKey.HasKdf) { // if there is a key derivation function, decrypting could be slow, // so show a progress dialog var dialog = new DecryptProgressDialog(); - dialog.Start((p) => privateKey.Decrypt(() => entry.GetPassphrase(), p)); + dialog.Start((p) => privateKey.Decrypt(() => entry.GetPassphrase(), p, out comment)); dialog.ShowDialog(); if (dialog.DialogResult == DialogResult.Abort) { @@ -394,13 +395,19 @@ public static ISshKey GetSshKey(this PwEntry entry) parameter = (AsymmetricKeyParameter)dialog.Result; } else { - parameter = privateKey.Decrypt(() => entry.GetPassphrase()); + parameter = privateKey.Decrypt(() => entry.GetPassphrase(), null, out comment); + } + + // prefer public key comment if there is one, otherwise fall back to + // private key comment + if (!string.IsNullOrWhiteSpace(publicKey.Comment)) { + comment = publicKey.Comment; } var key = new SshKey( publicKey.Parameter, parameter, - publicKey.Comment, + comment, publicKey.Nonce, publicKey.Certificate); diff --git a/SshAgentLib b/SshAgentLib index 990f8b6..6809f3e 160000 --- a/SshAgentLib +++ b/SshAgentLib @@ -1 +1 @@ -Subproject commit 990f8b695f8d733b66e267d95ca9e1552041cb12 +Subproject commit 6809f3ebc37268b9a492a7299bc3dc697ccd4940