HMacTest.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Renci.SshNet.Abstractions;
  2. using Renci.SshNet.IntegrationTests.Common;
  3. namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
  4. {
  5. [TestClass]
  6. public class HMacTest : IntegrationTestBase
  7. {
  8. private IConnectionInfoFactory _adminConnectionInfoFactory;
  9. private RemoteSshdConfig _remoteSshdConfig;
  10. [TestInitialize]
  11. public void SetUp()
  12. {
  13. _adminConnectionInfoFactory = new LinuxAdminConnectionFactory(SshServerHostName, SshServerPort);
  14. _remoteSshdConfig = new RemoteSshd(_adminConnectionInfoFactory).OpenConfig();
  15. }
  16. [TestCleanup]
  17. public void TearDown()
  18. {
  19. _remoteSshdConfig?.Reset();
  20. }
  21. [TestMethod]
  22. public void Test_HMac_Sha1_Connection()
  23. {
  24. var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password);
  25. connectionInfo.HmacAlgorithms.Clear();
  26. connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, CryptoAbstraction.CreateHMACSHA1));
  27. using (var client = new SshClient(connectionInfo))
  28. {
  29. client.Connect();
  30. client.Disconnect();
  31. }
  32. }
  33. [TestMethod]
  34. public void Test_HMac_Sha256_Connection()
  35. {
  36. var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password);
  37. connectionInfo.HmacAlgorithms.Clear();
  38. connectionInfo.HmacAlgorithms.Add("hmac-sha2-256", new HashInfo(32 * 8, CryptoAbstraction.CreateHMACSHA256));
  39. using (var client = new SshClient(connectionInfo))
  40. {
  41. client.Connect();
  42. client.Disconnect();
  43. }
  44. }
  45. [TestMethod]
  46. public void Test_HMac_Sha2_512_Connection()
  47. {
  48. var connectionInfo = new PasswordConnectionInfo(SshServerHostName, SshServerPort, User.UserName, User.Password);
  49. connectionInfo.HmacAlgorithms.Clear();
  50. connectionInfo.HmacAlgorithms.Add("hmac-sha2-512", new HashInfo(64 * 8, CryptoAbstraction.CreateHMACSHA512));
  51. using (var client = new SshClient(connectionInfo))
  52. {
  53. client.Connect();
  54. client.Disconnect();
  55. }
  56. }
  57. }
  58. }