Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ecdsa-sha2-nistp521, ecdsa-sha2-nistp384 server keys. #176

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ Supported client key algorithms:
- rsa-sha2-256

Supported server key algorithms:
- ecdsa-sha2-nistp521
- ecdsa-sha2-nistp384
- ecdsa-sha2-nistp256
- rsa-sha2-512
- rsa-sha2-256
Expand Down
8 changes: 8 additions & 0 deletions src/Tmds.Ssh/AlgorithmNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ static class AlgorithmNames // TODO: rename to KnownNames
public static Name RsaSshSha2_512 => new Name(RsaSshSha2_512Bytes);
private static readonly byte[] EcdsaSha2Nistp256Bytes = "ecdsa-sha2-nistp256"u8.ToArray();
public static Name EcdsaSha2Nistp256 => new Name(EcdsaSha2Nistp256Bytes);
private static readonly byte[] EcdsaSha2Nistp384Bytes = "ecdsa-sha2-nistp384"u8.ToArray();
public static Name EcdsaSha2Nistp384 => new Name(EcdsaSha2Nistp384Bytes);
private static readonly byte[] EcdsaSha2Nistp521Bytes = "ecdsa-sha2-nistp521"u8.ToArray();
public static Name EcdsaSha2Nistp521 => new Name(EcdsaSha2Nistp521Bytes);

// Encryption algorithms.
private static readonly byte[] Aes128GcmBytes = "[email protected]"u8.ToArray();
Expand All @@ -43,6 +47,10 @@ static class AlgorithmNames // TODO: rename to KnownNames
// Curve names.
private static readonly byte[] Nistp265Bytes = "nistp256"u8.ToArray();
public static Name Nistp265 => new Name(Nistp265Bytes);
private static readonly byte[] Nistp384Bytes = "nistp384"u8.ToArray();
public static Name Nistp384 => new Name(Nistp384Bytes);
private static readonly byte[] Nistp521Bytes = "nistp521"u8.ToArray();
public static Name Nistp521 => new Name(Nistp521Bytes);

// These fields are initialized in order, so these list must be created after the names.
// Algorithms are in **order of preference**.
Expand Down
14 changes: 14 additions & 0 deletions src/Tmds.Ssh/ECDsaPublicKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ public static ECDsaPublicKey CreateFromSshKey(byte[] key)
reader.ReadEnd();
return new ECDsaPublicKey(AlgorithmNames.EcdsaSha2Nistp256, ECCurve.NamedCurves.nistP256, q, HashAlgorithmName.SHA256);
}
else if (name == AlgorithmNames.EcdsaSha2Nistp384)
{
reader.ReadName(AlgorithmNames.Nistp384);
ECPoint q = reader.ReadStringAsECPoint();
reader.ReadEnd();
return new ECDsaPublicKey(AlgorithmNames.EcdsaSha2Nistp384, ECCurve.NamedCurves.nistP384, q, HashAlgorithmName.SHA384);
}
else if (name == AlgorithmNames.EcdsaSha2Nistp521)
{
reader.ReadName(AlgorithmNames.Nistp521);
ECPoint q = reader.ReadStringAsECPoint();
reader.ReadEnd();
return new ECDsaPublicKey(AlgorithmNames.EcdsaSha2Nistp521, ECCurve.NamedCurves.nistP521, q, HashAlgorithmName.SHA512);
}
ThrowHelper.ThrowProtocolUnexpectedValue();
return null!;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tmds.Ssh/ManagedSshClientSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal ManagedSshClientSettings()
// Internal.
// Algorithms are in **order of preference**.
internal List<Name> KeyExchangeAlgorithms { get; } = new List<Name>() { AlgorithmNames.EcdhSha2Nistp256, AlgorithmNames.EcdhSha2Nistp384, AlgorithmNames.EcdhSha2Nistp521 };
internal List<Name> ServerHostKeyAlgorithms { get; } = new List<Name>() { AlgorithmNames.EcdsaSha2Nistp256, AlgorithmNames.RsaSshSha2_512, AlgorithmNames.RsaSshSha2_256 };
internal List<Name> ServerHostKeyAlgorithms { get; } = new List<Name>() { AlgorithmNames.EcdsaSha2Nistp521, AlgorithmNames.EcdsaSha2Nistp384, AlgorithmNames.EcdsaSha2Nistp256, AlgorithmNames.RsaSshSha2_512, AlgorithmNames.RsaSshSha2_256 };
internal List<Name> EncryptionAlgorithmsClientToServer { get; } = new List<Name>() { AlgorithmNames.Aes256Gcm, AlgorithmNames.Aes128Gcm };
internal List<Name> EncryptionAlgorithmsServerToClient { get; } = new List<Name>() { AlgorithmNames.Aes256Gcm, AlgorithmNames.Aes128Gcm };
internal List<Name> MacAlgorithmsClientToServer { get; } = new List<Name>() { AlgorithmNames.HMacSha2_256 };
Expand Down
4 changes: 3 additions & 1 deletion src/Tmds.Ssh/PublicKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ abstract class PublicKey
public static PublicKey CreateFromSshKey(HostKey key)
{
Name name = new Name(key.Type);
if (name == AlgorithmNames.EcdsaSha2Nistp256)
if (name == AlgorithmNames.EcdsaSha2Nistp256 ||
name == AlgorithmNames.EcdsaSha2Nistp384 ||
name == AlgorithmNames.EcdsaSha2Nistp521)
{
return ECDsaPublicKey.CreateFromSshKey(key.RawKey);
}
Expand Down
Loading