HmacTests.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using Renci.SshNet.IntegrationTests.Common;
  2. using Renci.SshNet.TestTools.OpenSSH;
  3. namespace Renci.SshNet.IntegrationTests
  4. {
  5. [TestClass]
  6. public class HmacTests : 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 HmacSha1()
  23. {
  24. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1);
  25. }
  26. [TestMethod]
  27. public void HmacSha2_256()
  28. {
  29. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_256);
  30. }
  31. [TestMethod]
  32. public void HmacSha2_512()
  33. {
  34. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_512);
  35. }
  36. [TestMethod]
  37. public void HmacSha2_512_ShortKexOutput()
  38. {
  39. _remoteSshdConfig.ClearMessageAuthenticationCodeAlgorithms()
  40. .AddMessageAuthenticationCodeAlgorithm(MessageAuthenticationCodeAlgorithm.HmacSha2_512)
  41. .ClearKeyExchangeAlgorithms()
  42. .AddKeyExchangeAlgorithm(KeyExchangeAlgorithm.DiffieHellmanGroupExchangeSha1)
  43. .Update()
  44. .Restart();
  45. using (var client = new SshClient(_connectionInfoFactory.Create()))
  46. {
  47. client.Connect();
  48. client.Disconnect();
  49. }
  50. }
  51. [TestMethod]
  52. public void HmacSha1_Etm()
  53. {
  54. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha1Etm);
  55. }
  56. [TestMethod]
  57. public void HmacSha2_256_Etm()
  58. {
  59. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_256_Etm);
  60. }
  61. [TestMethod]
  62. public void HmacSha2_512_Etm()
  63. {
  64. DoTest(MessageAuthenticationCodeAlgorithm.HmacSha2_512_Etm);
  65. }
  66. private void DoTest(MessageAuthenticationCodeAlgorithm macAlgorithm)
  67. {
  68. _remoteSshdConfig.ClearMessageAuthenticationCodeAlgorithms()
  69. .AddMessageAuthenticationCodeAlgorithm(macAlgorithm)
  70. .Update()
  71. .Restart();
  72. using (var client = new SshClient(_connectionInfoFactory.Create()))
  73. {
  74. client.Connect();
  75. client.Disconnect();
  76. }
  77. }
  78. }
  79. }