CipherTests.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. [TestMethod]
  57. public void Aes128Gcm()
  58. {
  59. DoTest(Cipher.Aes128Gcm);
  60. }
  61. [TestMethod]
  62. public void Aes256Gcm()
  63. {
  64. DoTest(Cipher.Aes256Gcm);
  65. }
  66. [TestMethod]
  67. public void ChaCha20Poly1305()
  68. {
  69. DoTest(Cipher.Chacha20Poly1305);
  70. }
  71. private void DoTest(Cipher cipher)
  72. {
  73. _remoteSshdConfig.ClearCiphers()
  74. .AddCipher(cipher)
  75. .Update()
  76. .Restart();
  77. using (var client = new SshClient(_connectionInfoFactory.Create()))
  78. {
  79. client.Connect();
  80. client.Disconnect();
  81. }
  82. }
  83. }
  84. }