CipherTests.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Renci.SshNet.IntegrationTests.Common;
  2. using Renci.SshNet.TestTools.OpenSSH;
  3. namespace Renci.SshNet.IntegrationTests
  4. {
  5. [TestClass]
  6. public class CipherTests : IntegrationTestBase
  7. {
  8. private IConnectionInfoFactory _connectionInfoFactory;
  9. private RemoteSshdConfig _remoteSshdConfig;
  10. [TestInitialize]
  11. public void SetUp()
  12. {
  13. _connectionInfoFactory = new LinuxVMConnectionFactory(SshServerHostName, SshServerPort);
  14. _remoteSshdConfig = new RemoteSshd(new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort)).OpenConfig();
  15. }
  16. [TestCleanup]
  17. public void TearDown()
  18. {
  19. _remoteSshdConfig?.Reset();
  20. }
  21. [TestMethod]
  22. public void TripledesCbc()
  23. {
  24. DoTest(Cipher.TripledesCbc);
  25. }
  26. [TestMethod]
  27. public void Aes128Cbc()
  28. {
  29. DoTest(Cipher.Aes128Cbc);
  30. }
  31. [TestMethod]
  32. public void Aes192Cbc()
  33. {
  34. DoTest(Cipher.Aes192Cbc);
  35. }
  36. [TestMethod]
  37. public void Aes256Cbc()
  38. {
  39. DoTest(Cipher.Aes256Cbc);
  40. }
  41. [TestMethod]
  42. public void Aes128Ctr()
  43. {
  44. DoTest(Cipher.Aes128Ctr);
  45. }
  46. [TestMethod]
  47. public void Aes192Ctr()
  48. {
  49. DoTest(Cipher.Aes192Ctr);
  50. }
  51. [TestMethod]
  52. public void Aes256Ctr()
  53. {
  54. DoTest(Cipher.Aes256Ctr);
  55. }
  56. #if NET6_0_OR_GREATER
  57. [TestMethod]
  58. public void Aes128Gcm()
  59. {
  60. DoTest(Cipher.Aes128Gcm);
  61. }
  62. [TestMethod]
  63. public void Aes256Gcm()
  64. {
  65. DoTest(Cipher.Aes256Gcm);
  66. }
  67. #endif
  68. private void DoTest(Cipher cipher)
  69. {
  70. _remoteSshdConfig.ClearCiphers()
  71. .AddCipher(cipher)
  72. .Update()
  73. .Restart();
  74. using (var client = new SshClient(_connectionInfoFactory.Create()))
  75. {
  76. client.Connect();
  77. client.Disconnect();
  78. }
  79. }
  80. }
  81. }