Skip to content

Commit

Permalink
charpier
Browse files Browse the repository at this point in the history
  • Loading branch information
dlech committed Jun 26, 2023
1 parent 6114528 commit c720b56
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
8 changes: 2 additions & 6 deletions SshAgentLib/AgentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,7 @@ BlobBuilder CreatePrivateKeyBlob(ISshKey key)
var ed448PublicKeyBytes = ed448PublicKeyParameters.GetEncoded();
builder.AddBlob(ed448PublicKeyBytes);
builder.AddBlob(
ed448PrivateKeyParameters
.GetEncoded()
.Concat(ed448PublicKeyBytes)
.ToArray()
ed448PrivateKeyParameters.GetEncoded().Concat(ed448PublicKeyBytes).ToArray()
);
break;
case PublicKeyAlgorithm.SshEd448CertV1:
Expand All @@ -448,8 +445,7 @@ BlobBuilder CreatePrivateKeyBlob(ISshKey key)

builder.AddBlob(key.GetPublicKeyBlob());

var ed448Public =
key.GetPublicKeyParameters() as Ed448PublicKeyParameters;
var ed448Public = key.GetPublicKeyParameters() as Ed448PublicKeyParameters;
var ed448Private =
key.GetPrivateKeyParameters() as Ed448PrivateKeyParameters;
var ed448PublicBytes = ed448Public.GetEncoded();
Expand Down
6 changes: 1 addition & 5 deletions SshAgentLib/BlobParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,7 @@ public AsymmetricKeyParameter ReadSsh2KeyData(AsymmetricKeyParameter publicKeyPa
// the first 57 bytes are the private key, the last 57 bytes
// are the public key

if (
!ed448Signature
.Skip(57)
.SequenceEqual(ed448PublicKeyParameters.GetEncoded())
)
if (!ed448Signature.Skip(57).SequenceEqual(ed448PublicKeyParameters.GetEncoded()))
{
throw new FormatException("public and private keys to not match");
}
Expand Down
6 changes: 5 additions & 1 deletion SshAgentLib/ISshKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ public static byte[] FormatSignature(this ISshKey key, byte[] signature)
}
return formattedSignature.GetBlob();
}
else if (publicKey is RsaKeyParameters || publicKey is Ed25519PublicKeyParameters || publicKey is Ed448PublicKeyParameters)
else if (
publicKey is RsaKeyParameters
|| publicKey is Ed25519PublicKeyParameters
|| publicKey is Ed448PublicKeyParameters
)
{
return signature;
}
Expand Down
5 changes: 1 addition & 4 deletions SshAgentLibTests/AgentClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ static AgentClientTest()
PublicKeyAlgorithm.SshEd25519CertV1,
"SSH2 Ed25519 test key + cert"
);
ed448Key = KeyGenerator.CreateKey(
PublicKeyAlgorithm.SshEd25519,
"SSH2 Ed448 test key"
);
ed448Key = KeyGenerator.CreateKey(PublicKeyAlgorithm.SshEd25519, "SSH2 Ed448 test key");
ed448Cert = KeyGenerator.CreateKey(
PublicKeyAlgorithm.SshEd25519CertV1,
"SSH2 Ed448 test key + cert"
Expand Down
5 changes: 1 addition & 4 deletions SshAgentLibTests/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ static AgentTest()
PublicKeyAlgorithm.SshEd25519,
"SSH2 ED25519 test key"
);
ed448Key = KeyGenerator.CreateKey(
PublicKeyAlgorithm.SshEd448,
"SSH2 ED448 test key"
);
ed448Key = KeyGenerator.CreateKey(PublicKeyAlgorithm.SshEd448, "SSH2 ED448 test key");

allKeys = new List<ISshKey>
{
Expand Down
16 changes: 14 additions & 2 deletions SshAgentLibTests/KeyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,26 @@ public static SshKey CreateKey(PublicKeyAlgorithm algorithm, string comment = ""
case PublicKeyAlgorithm.SshEd25519CertV1:
var ed25519PrivateKey = new Ed25519PrivateKeyParameters(secureRandom);
var ed25519PublicKey = ed25519PrivateKey.GeneratePublicKey();
var ed25519Key = new SshKey(ed25519PublicKey, ed25519PrivateKey, comment, nonce, certificate);
var ed25519Key = new SshKey(
ed25519PublicKey,
ed25519PrivateKey,
comment,
nonce,
certificate
);
return ed25519Key;

case PublicKeyAlgorithm.SshEd448:
case PublicKeyAlgorithm.SshEd448CertV1:
var ed448PrivateKey = new Ed448PrivateKeyParameters(secureRandom);
var ed448PublicKey = ed448PrivateKey.GeneratePublicKey();
var ed448Key = new SshKey(ed448PublicKey, ed448PrivateKey, comment, nonce, certificate);
var ed448Key = new SshKey(
ed448PublicKey,
ed448PrivateKey,
comment,
nonce,
certificate
);
return ed448Key;

default:
Expand Down

0 comments on commit c720b56

Please sign in to comment.