Skip to content

Commit

Permalink
fall back to encrypted private key comment when available
Browse files Browse the repository at this point in the history
Fixes #375
  • Loading branch information
dlech committed Feb 4, 2023
1 parent e36f0b6 commit 77e7d30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions KeeAgent/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down

0 comments on commit 77e7d30

Please sign in to comment.