diff --git a/src/Renci.SshNet.IntegrationTests/CipherTests.cs b/src/Renci.SshNet.IntegrationTests/CipherTests.cs new file mode 100644 index 000000000..1a11f9814 --- /dev/null +++ b/src/Renci.SshNet.IntegrationTests/CipherTests.cs @@ -0,0 +1,81 @@ +using Renci.SshNet.IntegrationTests.Common; +using Renci.SshNet.TestTools.OpenSSH; + +namespace Renci.SshNet.IntegrationTests +{ + [TestClass] + public class CipherTests : IntegrationTestBase + { + private IConnectionInfoFactory _connectionInfoFactory; + private RemoteSshdConfig _remoteSshdConfig; + + [TestInitialize] + public void SetUp() + { + _connectionInfoFactory = new LinuxVMConnectionFactory(SshServerHostName, SshServerPort); + _remoteSshdConfig = new RemoteSshd(new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort)).OpenConfig(); + } + + [TestCleanup] + public void TearDown() + { + _remoteSshdConfig?.Reset(); + } + + [TestMethod] + public void TripledesCbc() + { + DoTest(Cipher.TripledesCbc); + } + + [TestMethod] + public void Aes128Cbc() + { + DoTest(Cipher.Aes128Cbc); + } + + [TestMethod] + public void Aes192Cbc() + { + DoTest(Cipher.Aes192Cbc); + } + + [TestMethod] + public void Aes256Cbc() + { + DoTest(Cipher.Aes256Cbc); + } + + [TestMethod] + public void Aes128Ctr() + { + DoTest(Cipher.Aes128Ctr); + } + + [TestMethod] + public void Aes192Ctr() + { + DoTest(Cipher.Aes192Ctr); + } + + [TestMethod] + public void Aes256Ctr() + { + DoTest(Cipher.Aes256Ctr); + } + + private void DoTest(Cipher cipher) + { + _remoteSshdConfig.ClearCiphers() + .AddCipher(cipher) + .Update() + .Restart(); + + using (var client = new SshClient(_connectionInfoFactory.Create())) + { + client.Connect(); + client.Disconnect(); + } + } + } +} diff --git a/src/Renci.SshNet.IntegrationTests/Common/RemoteSshdConfigExtensions.cs b/src/Renci.SshNet.IntegrationTests/Common/RemoteSshdConfigExtensions.cs index af64ff62a..865154bfb 100644 --- a/src/Renci.SshNet.IntegrationTests/Common/RemoteSshdConfigExtensions.cs +++ b/src/Renci.SshNet.IntegrationTests/Common/RemoteSshdConfigExtensions.cs @@ -21,6 +21,7 @@ public static void Reset(this RemoteSshdConfig remoteSshdConfig) .ClearKeyExchangeAlgorithms() .ClearHostKeyAlgorithms() .ClearPublicKeyAcceptedAlgorithms() + .ClearMessageAuthenticationCodeAlgorithms() .WithUsePAM(true) .Update() .Restart(); diff --git a/src/Renci.SshNet.IntegrationTests/HmacTests.cs b/src/Renci.SshNet.IntegrationTests/HmacTests.cs new file mode 100644 index 000000000..993e5ec98 --- /dev/null +++ b/src/Renci.SshNet.IntegrationTests/HmacTests.cs @@ -0,0 +1,75 @@ +using Renci.SshNet.IntegrationTests.Common; +using Renci.SshNet.TestTools.OpenSSH; + +namespace Renci.SshNet.IntegrationTests +{ + [TestClass] + public class HmacTests : IntegrationTestBase + { + private IConnectionInfoFactory _connectionInfoFactory; + private RemoteSshdConfig _remoteSshdConfig; + + [TestInitialize] + public void SetUp() + { + _connectionInfoFactory = new LinuxVMConnectionFactory(SshServerHostName, SshServerPort); + _remoteSshdConfig = new RemoteSshd(new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort)).OpenConfig(); + } + + [TestCleanup] + public void TearDown() + { + _remoteSshdConfig?.Reset(); + } + + [TestMethod] + public void HmacMd5() + { + DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5); + } + + [TestMethod] + public void HmacMd5_96() + { + DoTest(MessageAuthenticationCodeAlgorithm.HmacMd5_96); + } + + [TestMethod] + public void HmacSha1() + { + DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1); + } + + [TestMethod] + public void HmacSha1_96() + { + DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1_96); + } + + [TestMethod] + public void HmacSha2_256() + { + DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_256); + } + + [TestMethod] + public void HmacSha2_512() + { + DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_512); + } + + private void DoTest(MessageAuthenticationCodeAlgorithm macAlgorithm) + { + _remoteSshdConfig.ClearMessageAuthenticationCodeAlgorithms() + .AddMessageAuthenticationCodeAlgorithm(macAlgorithm) + .Update() + .Restart(); + + using (var client = new SshClient(_connectionInfoFactory.Create())) + { + client.Connect(); + client.Disconnect(); + } + } + } +} diff --git a/src/Renci.SshNet.IntegrationTests/OldIntegrationTests/AesCipherTests.cs b/src/Renci.SshNet.IntegrationTests/OldIntegrationTests/AesCipherTests.cs deleted file mode 100644 index 7e9e97b01..000000000 --- a/src/Renci.SshNet.IntegrationTests/OldIntegrationTests/AesCipherTests.cs +++ /dev/null @@ -1,147 +0,0 @@ -using Renci.SshNet.IntegrationTests.Common; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.TestTools.OpenSSH; - -namespace Renci.SshNet.IntegrationTests.OldIntegrationTests -{ - [TestClass] - public class AesCipherTests : IntegrationTestBase - { - private IConnectionInfoFactory _adminConnectionInfoFactory; - private RemoteSshdConfig _remoteSshdConfig; - - [TestInitialize] - public void SetUp() - { - _adminConnectionInfoFactory = new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort); - _remoteSshdConfig = new RemoteSshd(_adminConnectionInfoFactory).OpenConfig(); - } - - [TestCleanup] - public void TearDown() - { - _remoteSshdConfig?.Reset(); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - public void Test_Cipher_AEes128CBC_Connection() - { - _remoteSshdConfig.AddCipher(Cipher.Aes128Cbc) - .Update() - .Restart(); - - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes128-cbc", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - public void Test_Cipher_Aes192CBC_Connection() - { - _remoteSshdConfig.AddCipher(Cipher.Aes192Cbc) - .Update() - .Restart(); - - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes192-cbc", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - public void Test_Cipher_Aes256CBC_Connection() - { - _remoteSshdConfig.AddCipher(Cipher.Aes256Cbc) - .Update() - .Restart(); - - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes256-cbc", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - public void Test_Cipher_Aes128CTR_Connection() - { - _remoteSshdConfig.AddCipher(Cipher.Aes128Ctr) - .Update() - .Restart(); - - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes128-ctr", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - public void Test_Cipher_Aes192CTR_Connection() - { - _remoteSshdConfig.AddCipher(Cipher.Aes192Ctr) - .Update() - .Restart(); - - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes192-ctr", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - public void Test_Cipher_Aes256CTR_Connection() - { - _remoteSshdConfig.AddCipher(Cipher.Aes256Ctr) - .Update() - .Restart(); - - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes256-ctr", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - } -} diff --git a/src/Renci.SshNet.IntegrationTests/OldIntegrationTests/HMacTest.cs b/src/Renci.SshNet.IntegrationTests/OldIntegrationTests/HMacTest.cs deleted file mode 100644 index c8df34e9d..000000000 --- a/src/Renci.SshNet.IntegrationTests/OldIntegrationTests/HMacTest.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Renci.SshNet.Abstractions; -using Renci.SshNet.IntegrationTests.Common; - -namespace Renci.SshNet.IntegrationTests.OldIntegrationTests -{ - [TestClass] - public class HMacTest : IntegrationTestBase - { - private IConnectionInfoFactory _adminConnectionInfoFactory; - private RemoteSshdConfig _remoteSshdConfig; - - [TestInitialize] - public void SetUp() - { - _adminConnectionInfoFactory = new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort); - _remoteSshdConfig = new RemoteSshd(_adminConnectionInfoFactory).OpenConfig(); - } - - [TestCleanup] - public void TearDown() - { - _remoteSshdConfig?.Reset(); - } - - [TestMethod] - public void Test_HMac_Sha1_Connection() - { - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, CryptoAbstraction.CreateHMACSHA1)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - public void Test_HMac_Sha256_Connection() - { - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha2-256", new HashInfo(32 * 8, CryptoAbstraction.CreateHMACSHA256)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - public void Test_HMac_Sha2_512_Connection() - { - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha2-512", new HashInfo(64 * 8, CryptoAbstraction.CreateHMACSHA512)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - } -} diff --git a/src/Renci.SshNet.IntegrationTests/OldIntegrationTests/TripleDesCipherTest.cs b/src/Renci.SshNet.IntegrationTests/OldIntegrationTests/TripleDesCipherTest.cs deleted file mode 100644 index a9195cf5e..000000000 --- a/src/Renci.SshNet.IntegrationTests/OldIntegrationTests/TripleDesCipherTest.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Renci.SshNet.IntegrationTests.Common; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.TestTools.OpenSSH; - -namespace Renci.SshNet.IntegrationTests.OldIntegrationTests -{ - /// - /// Implements 3DES cipher algorithm. - /// - [TestClass] - public class TripleDesCipherTest : IntegrationTestBase - { - private IConnectionInfoFactory _adminConnectionInfoFactory; - private RemoteSshdConfig _remoteSshdConfig; - - [TestInitialize] - public void SetUp() - { - _adminConnectionInfoFactory = new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort); - _remoteSshdConfig = new RemoteSshd(_adminConnectionInfoFactory).OpenConfig(); - } - - [TestCleanup] - public void TearDown() - { - _remoteSshdConfig?.Reset(); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - public void Test_Cipher_TripleDESCBC_Connection() - { - _remoteSshdConfig.AddCipher(Cipher.TripledesCbc) - .Update() - .Restart(); - - var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => { return new TripleDesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - } -} diff --git a/src/Renci.SshNet.IntegrationTests/PrivateKeyAuthenticationTests.cs b/src/Renci.SshNet.IntegrationTests/PrivateKeyAuthenticationTests.cs index 950079370..05b6c4787 100644 --- a/src/Renci.SshNet.IntegrationTests/PrivateKeyAuthenticationTests.cs +++ b/src/Renci.SshNet.IntegrationTests/PrivateKeyAuthenticationTests.cs @@ -73,7 +73,7 @@ public void Ed25519() private void DoTest(PublicKeyAlgorithm publicKeyAlgorithm, string keyResource) { _remoteSshdConfig.ClearPublicKeyAcceptedAlgorithms() - .AddPublicKeyAcceptedAlgorithms(publicKeyAlgorithm) + .AddPublicKeyAcceptedAlgorithm(publicKeyAlgorithm) .Update() .Restart(); diff --git a/src/Renci.SshNet.IntegrationTests/RemoteSshd.cs b/src/Renci.SshNet.IntegrationTests/RemoteSshd.cs index c81bf96f5..b9a32e67a 100644 --- a/src/Renci.SshNet.IntegrationTests/RemoteSshd.cs +++ b/src/Renci.SshNet.IntegrationTests/RemoteSshd.cs @@ -167,12 +167,24 @@ public RemoteSshdConfig ClearPublicKeyAcceptedAlgorithms() return this; } - public RemoteSshdConfig AddPublicKeyAcceptedAlgorithms(PublicKeyAlgorithm publicKeyAlgorithm) + public RemoteSshdConfig AddPublicKeyAcceptedAlgorithm(PublicKeyAlgorithm publicKeyAlgorithm) { _config.PublicKeyAcceptedAlgorithms.Add(publicKeyAlgorithm); return this; } + public RemoteSshdConfig ClearMessageAuthenticationCodeAlgorithms() + { + _config.MessageAuthenticationCodeAlgorithms.Clear(); + return this; + } + + public RemoteSshdConfig AddMessageAuthenticationCodeAlgorithm(MessageAuthenticationCodeAlgorithm messageAuthenticationCodeAlgorithm) + { + _config.MessageAuthenticationCodeAlgorithms.Add(messageAuthenticationCodeAlgorithm); + return this; + } + public RemoteSshdConfig ClearHostKeyAlgorithms() { _config.HostKeyAlgorithms.Clear();