Skip to content

Commit 4f1eac7

Browse files
authored
Merge branch 'develop' into develop
2 parents 35021cc + aade354 commit 4f1eac7

38 files changed

+747
-216
lines changed

src/Renci.SshNet.Benchmarks/Security/Cryptography/Ciphers/RsaCipherBenchmarks.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public RsaCipherBenchmarks()
2121

2222
using (var s = typeof(RsaCipherBenchmarks).Assembly.GetManifestResourceStream("Renci.SshNet.Benchmarks.Data.Key.RSA.txt"))
2323
{
24-
_privateKey = (RsaKey)((KeyHostAlgorithm) new PrivateKeyFile(s).HostKey).Key;
24+
25+
_privateKey = (RsaKey)new PrivateKeyFile(s).Key;
2526

2627
// The implementations of RsaCipher.Encrypt/Decrypt differ based on whether the supplied RsaKey has private key information
2728
// or only public. So we extract out the public key information to a separate variable.

src/Renci.SshNet.Benchmarks/Security/Cryptography/ED25519DigitalSignatureBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ED25519DigitalSignatureBenchmarks()
2121

2222
using (var s = typeof(ED25519DigitalSignatureBenchmarks).Assembly.GetManifestResourceStream("Renci.SshNet.Benchmarks.Data.Key.OPENSSH.ED25519.txt"))
2323
{
24-
_key = (ED25519Key) ((KeyHostAlgorithm) new PrivateKeyFile(s).HostKey).Key;
24+
_key = (ED25519Key) new PrivateKeyFile(s).Key;
2525
}
2626
_signature = new ED25519DigitalSignature(_key).Sign(_data);
2727
}

src/Renci.SshNet.IntegrationTests/Common/RemoteSshdConfigExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public static void Reset(this RemoteSshdConfig remoteSshdConfig)
2020
.ClearCiphers()
2121
.ClearKeyExchangeAlgorithms()
2222
.ClearHostKeyAlgorithms()
23-
.AddHostKeyAlgorithm(HostKeyAlgorithm.SshRsa)
2423
.ClearPublicKeyAcceptedAlgorithms()
25-
.AddPublicKeyAcceptedAlgorithms(PublicKeyAlgorithm.SshRsa)
2624
.WithUsePAM(true)
2725
.Update()
2826
.Restart();

src/Renci.SshNet.IntegrationTests/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ RUN apk update && apk upgrade --no-cache && \
1414
chmod 400 /etc/ssh/ssh*key && \
1515
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
1616
sed -i 's/#LogLevel\s*INFO/LogLevel DEBUG3/' /etc/ssh/sshd_config && \
17-
echo 'PubkeyAcceptedAlgorithms ssh-rsa' >> /etc/ssh/sshd_config && \
1817
chmod 646 /etc/ssh/sshd_config && \
1918
# install and configure sudo
2019
apk add --no-cache sudo && \

src/Renci.SshNet.IntegrationTests/HostKeyAlgorithmTests.cs

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,63 +22,46 @@ public void TearDown()
2222
{
2323
_remoteSshdConfig?.Reset();
2424
}
25-
25+
2626
[TestMethod]
2727
[Ignore] // No longer supported in recent versions of OpenSSH
28+
// TODO: We should be able to enable some legacy settings to make it work
29+
// https://www.openssh.com/legacy.html e.g. PubkeyAcceptedKeyTypes / HostbasedAcceptedKeyTypes ?
2830
public void SshDsa()
2931
{
30-
_remoteSshdConfig.ClearHostKeyAlgorithms()
31-
.AddHostKeyAlgorithm(HostKeyAlgorithm.SshDsa)
32-
.ClearHostKeyFiles()
33-
.AddHostKeyFile(HostKeyFile.Dsa.FilePath)
34-
.Update()
35-
.Restart();
36-
37-
HostKeyEventArgs hostKeyEventsArgs = null;
38-
39-
using (var client = new SshClient(_connectionInfoFactory.Create()))
40-
{
41-
client.HostKeyReceived += (sender, e) => hostKeyEventsArgs = e;
42-
client.Connect();
43-
client.Disconnect();
44-
}
45-
46-
Assert.IsNotNull(hostKeyEventsArgs);
47-
Assert.AreEqual(HostKeyFile.Dsa.KeyName, hostKeyEventsArgs.HostKeyName);
48-
Assert.AreEqual(1024, hostKeyEventsArgs.KeyLength);
49-
Assert.IsTrue(hostKeyEventsArgs.FingerPrint.SequenceEqual(HostKeyFile.Dsa.FingerPrint));
32+
DoTest(HostKeyAlgorithm.SshDsa, HostKeyFile.Dsa, 1024);
5033
}
5134

5235
[TestMethod]
5336
public void SshRsa()
5437
{
55-
_remoteSshdConfig.ClearHostKeyAlgorithms()
56-
.AddHostKeyAlgorithm(HostKeyAlgorithm.SshRsa)
57-
.Update()
58-
.Restart();
59-
60-
HostKeyEventArgs hostKeyEventsArgs = null;
38+
DoTest(HostKeyAlgorithm.SshRsa, HostKeyFile.Rsa, 3072);
39+
}
6140

62-
using (var client = new SshClient(_connectionInfoFactory.Create()))
63-
{
64-
client.HostKeyReceived += (sender, e) => hostKeyEventsArgs = e;
65-
client.Connect();
66-
client.Disconnect();
67-
}
41+
[TestMethod]
42+
public void SshRsaSha256()
43+
{
44+
DoTest(HostKeyAlgorithm.RsaSha2256, HostKeyFile.Rsa, 3072);
45+
}
6846

69-
Assert.IsNotNull(hostKeyEventsArgs);
70-
Assert.AreEqual(HostKeyFile.Rsa.KeyName, hostKeyEventsArgs.HostKeyName);
71-
Assert.AreEqual(3072, hostKeyEventsArgs.KeyLength);
72-
Assert.IsTrue(hostKeyEventsArgs.FingerPrint.SequenceEqual(HostKeyFile.Rsa.FingerPrint));
47+
[TestMethod]
48+
public void SshRsaSha512()
49+
{
50+
DoTest(HostKeyAlgorithm.RsaSha2512, HostKeyFile.Rsa, 3072);
7351
}
7452

7553
[TestMethod]
7654
public void SshEd25519()
55+
{
56+
DoTest(HostKeyAlgorithm.SshEd25519, HostKeyFile.Ed25519, 256);
57+
}
58+
59+
private void DoTest(HostKeyAlgorithm hostKeyAlgorithm, HostKeyFile hostKeyFile, int keyLength)
7760
{
7861
_remoteSshdConfig.ClearHostKeyAlgorithms()
79-
.AddHostKeyAlgorithm(HostKeyAlgorithm.SshEd25519)
62+
.AddHostKeyAlgorithm(hostKeyAlgorithm)
8063
.ClearHostKeyFiles()
81-
.AddHostKeyFile(HostKeyFile.Ed25519.FilePath)
64+
.AddHostKeyFile(hostKeyFile.FilePath)
8265
.Update()
8366
.Restart();
8467

@@ -92,14 +75,9 @@ public void SshEd25519()
9275
}
9376

9477
Assert.IsNotNull(hostKeyEventsArgs);
95-
Assert.AreEqual(HostKeyFile.Ed25519.KeyName, hostKeyEventsArgs.HostKeyName);
96-
Assert.AreEqual(256, hostKeyEventsArgs.KeyLength);
97-
Assert.IsTrue(hostKeyEventsArgs.FingerPrint.SequenceEqual(HostKeyFile.Ed25519.FingerPrint));
98-
}
99-
100-
private void Client_HostKeyReceived(object sender, HostKeyEventArgs e)
101-
{
102-
throw new NotImplementedException();
78+
Assert.AreEqual(hostKeyAlgorithm.Name, hostKeyEventsArgs.HostKeyName);
79+
Assert.AreEqual(keyLength, hostKeyEventsArgs.KeyLength);
80+
CollectionAssert.AreEqual(hostKeyFile.FingerPrint, hostKeyEventsArgs.FingerPrint);
10381
}
10482
}
10583
}

src/Renci.SshNet.IntegrationTests/PrivateKeyAuthenticationTests.cs

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Renci.SshNet.IntegrationTests
55
{
66
[TestClass]
77
public class PrivateKeyAuthenticationTests : TestBase
8-
{
8+
{
99
private IConnectionInfoFactory _connectionInfoFactory;
1010
private RemoteSshdConfig _remoteSshdConfig;
1111

@@ -23,43 +23,64 @@ public void TearDown()
2323
}
2424

2525
[TestMethod]
26-
public void Ecdsa256()
26+
[Ignore] // No longer supported in recent versions of OpenSSH
27+
// TODO: We should be able to enable some legacy settings to make it work
28+
// https://www.openssh.com/legacy.html e.g. PubkeyAcceptedKeyTypes / HostbasedAcceptedKeyTypes ?
29+
public void SshDsa()
2730
{
28-
_remoteSshdConfig.AddPublicKeyAcceptedAlgorithms(PublicKeyAlgorithm.EcdsaSha2Nistp256)
29-
.Update()
30-
.Restart();
31+
DoTest(PublicKeyAlgorithm.SshDss, "id_dsa");
32+
}
3133

32-
var connectionInfo = _connectionInfoFactory.Create(CreatePrivateKeyAuthenticationMethod("key_ecdsa_256_openssh"));
34+
[TestMethod]
35+
public void SshRsa()
36+
{
37+
DoTest(PublicKeyAlgorithm.SshRsa, "id_rsa");
38+
}
3339

34-
using (var client = new SshClient(connectionInfo))
35-
{
36-
client.Connect();
37-
}
40+
[TestMethod]
41+
public void SshRsaSha256()
42+
{
43+
DoTest(PublicKeyAlgorithm.RsaSha2256, "id_rsa");
3844
}
3945

4046
[TestMethod]
41-
public void Ecdsa384()
47+
public void SshRsaSha512()
4248
{
43-
_remoteSshdConfig.AddPublicKeyAcceptedAlgorithms(PublicKeyAlgorithm.EcdsaSha2Nistp384)
44-
.Update()
45-
.Restart();
49+
DoTest(PublicKeyAlgorithm.RsaSha2512, "id_rsa");
50+
}
4651

47-
var connectionInfo = _connectionInfoFactory.Create(CreatePrivateKeyAuthenticationMethod("key_ecdsa_384_openssh"));
52+
[TestMethod]
53+
public void Ecdsa256()
54+
{
55+
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp256, "key_ecdsa_256_openssh");
56+
}
4857

49-
using (var client = new SshClient(connectionInfo))
50-
{
51-
client.Connect();
52-
}
58+
[TestMethod]
59+
public void Ecdsa384()
60+
{
61+
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp384, "key_ecdsa_384_openssh");
5362
}
5463

5564
[TestMethod]
56-
public void EcdsaA521()
65+
public void Ecdsa521()
66+
{
67+
DoTest(PublicKeyAlgorithm.EcdsaSha2Nistp521, "key_ecdsa_521_openssh");
68+
}
69+
70+
[TestMethod]
71+
public void Ed25519()
72+
{
73+
DoTest(PublicKeyAlgorithm.SshEd25519, "key_ed25519_openssh");
74+
}
75+
76+
private void DoTest(PublicKeyAlgorithm publicKeyAlgorithm, string keyResource)
5777
{
58-
_remoteSshdConfig.AddPublicKeyAcceptedAlgorithms(PublicKeyAlgorithm.EcdsaSha2Nistp521)
78+
_remoteSshdConfig.ClearPublicKeyAcceptedAlgorithms()
79+
.AddPublicKeyAcceptedAlgorithms(publicKeyAlgorithm)
5980
.Update()
6081
.Restart();
6182

62-
var connectionInfo = _connectionInfoFactory.Create(CreatePrivateKeyAuthenticationMethod("key_ecdsa_521_openssh"));
83+
var connectionInfo = _connectionInfoFactory.Create(CreatePrivateKeyAuthenticationMethod(keyResource));
6384

6485
using (var client = new SshClient(connectionInfo))
6586
{

src/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<EmbeddedResource Include="resources\client\key_ecdsa_256_openssh" />
6161
<EmbeddedResource Include="resources\client\key_ecdsa_384_openssh" />
6262
<EmbeddedResource Include="resources\client\key_ecdsa_521_openssh" />
63+
<EmbeddedResource Include="resources\client\key_ed25519_openssh" />
6364
<EmbeddedResource Include="resources\issue #70.png" />
6465
</ItemGroup>
6566
</Project>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4N0T6VopnwPSYQUw0waQNhBjz0DYFQwvkv4OwWYSf//fJF3M6bH42Tn2J+IlQ+4/fCFnE3m99seV5T1myEj7fsupNteY2sKFGXENLGtAD/76FM0iBmXx76xlSTyZSSmNDIRU4xUR23cfc+al84F5mO2lEk+5Zr3Qn5JUpucBfis4vtu0sMDgZ4w1d0tcuXkT/MEJn2iX2cnxbSy5qNAPHu7b+LEfXBv2OrMDqPrx/X6QREgi3w5RxL5kz7bvitWsIwIvb3ST2ARAArBwb8pEyp2A/w5p22rkQtL+3ibZ8fkmpgn33f31AZPgtM++iJPBmPKFjArcWEJ9fIVB/6DAj
22
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPzzrPpItEjNG7tU0DpJJ4pkI01E9d6K61OKTVPdFQSyGCdMj9XdP93lC6sJA+9/ahvf5F3gWEKxUJL2CKUiFWw=
33
ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBLSsu/HNKiaALhQ26UDv+N0AFdMb26fMVrOKe866CGu6ajSf9HUOhJFdjhseihB2rTalMPr8MrcXNLufii4mL8u4l9fUQXFgwnM/ZpiVPSs6C+8i4u/ZDg7Nx2NXybNIgQ==
4-
ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBACB4WgRgGBRo6Uk+cRgg8tJPCbEtGURRWlUA7PDDerXR+P9O6mm3L99Etxsyh5XNYqXyaMNtH5c51ooMajrFwcayAHIhPPb8X3CsTwEfIUQ96aDyHQMotbRfnkn6uefeUTRrSNcqeAndUtVyAqBdqbsq2mgJYXHrz2NUKlPFYgauQi+WQ==
4+
ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBACB4WgRgGBRo6Uk+cRgg8tJPCbEtGURRWlUA7PDDerXR+P9O6mm3L99Etxsyh5XNYqXyaMNtH5c51ooMajrFwcayAHIhPPb8X3CsTwEfIUQ96aDyHQMotbRfnkn6uefeUTRrSNcqeAndUtVyAqBdqbsq2mgJYXHrz2NUKlPFYgauQi+WQ==
5+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAkNGPVOTuzuKTgGfHcve2MRj57yXhmZgkUyi9RpmJrl

src/Renci.SshNet.TestTools.OpenSSH/SshdConfig.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,11 @@ public void SaveTo(TextWriter writer)
211211
writer.WriteLine("MACs " + string.Join(",", MessageAuthenticationCodeAlgorithms.Select(c => c.Name).ToArray()));
212212
}
213213

214-
writer.WriteLine("PubkeyAcceptedAlgorithms " + string.Join(",", PublicKeyAcceptedAlgorithms.Select(c => c.Name).ToArray()));
215-
214+
if (PublicKeyAcceptedAlgorithms.Count > 0)
215+
{
216+
writer.WriteLine("PubkeyAcceptedAlgorithms " + string.Join(",", PublicKeyAcceptedAlgorithms.Select(c => c.Name).ToArray()));
217+
}
218+
216219
foreach (var match in Matches)
217220
{
218221
_matchFormatter.Format(match, writer);

src/Renci.SshNet.Tests/Classes/BaseClientTest_Connect_OnConnectedThrowsException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Reflection;
34
using System.Threading;
45
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -140,7 +141,7 @@ private static KeyHostAlgorithm GetKeyHostAlgorithm()
140141
using (var s = executingAssembly.GetManifestResourceStream(string.Format("Renci.SshNet.Tests.Data.{0}", "Key.RSA.txt")))
141142
{
142143
var privateKey = new PrivateKeyFile(s);
143-
return (KeyHostAlgorithm) privateKey.HostKey;
144+
return (KeyHostAlgorithm) privateKey.HostKeyAlgorithms.First();
144145
}
145146
}
146147

0 commit comments

Comments
 (0)