Skip to content

Commit

Permalink
fix IAgentExt.AddKeyFromFile when no cert file
Browse files Browse the repository at this point in the history
This was getting a null reference error when no certificate public key file was present.

Fixes dlech/KeeAgent#358
  • Loading branch information
dlech committed Sep 25, 2022
1 parent c96e6d0 commit f017165
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions SshAgentLib/IAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ public static ISshKey AddKeyFromFile(

try
{
publicKey = SshPublicKey.Read(File.OpenRead($"{fileName}-cert.pub"));
var certificateKey = SshPublicKey.Read(File.OpenRead($"{fileName}-cert.pub"));

if (certificateKey != null)
{
privateKey = privateKey.WithPublicKey(certificateKey);
}
}
catch
{
Expand All @@ -109,9 +114,9 @@ public static ISshKey AddKeyFromFile(
privateKey.PublicKey.Parameter,
privateKey.Decrypt(getPassPhraseCallback, progress),
privateKey.PublicKey.Comment,
publicKey.Nonce,
publicKey.Certificate,
publicKey.Application
privateKey.PublicKey.Nonce,
privateKey.PublicKey.Certificate,
privateKey.PublicKey.Application
);

if (constraints != null)
Expand Down

0 comments on commit f017165

Please sign in to comment.