2
0

SessionTest_Connecting_ServerIdentificationReceived.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Connection;
  3. namespace Renci.SshNet.Tests.Classes
  4. {
  5. [TestClass]
  6. public class SessionTest_Connecting_ServerIdentificationReceived : SessionTest_ConnectingBase
  7. {
  8. protected override void SetupData()
  9. {
  10. base.SetupData();
  11. Session.ServerIdentificationReceived += (s, e) =>
  12. {
  13. if ((e.SshIdentification.SoftwareVersion.StartsWith("OpenSSH_6.5", System.StringComparison.Ordinal) || e.SshIdentification.SoftwareVersion.StartsWith("OpenSSH_6.6", System.StringComparison.Ordinal))
  14. && !e.SshIdentification.SoftwareVersion.StartsWith("OpenSSH_6.6.1", System.StringComparison.Ordinal))
  15. {
  16. _ = ConnectionInfo.KeyExchangeAlgorithms.Remove("curve25519-sha256");
  17. _ = ConnectionInfo.KeyExchangeAlgorithms.Remove("curve25519-sha256@libssh.org");
  18. }
  19. };
  20. }
  21. [TestMethod]
  22. [DataRow("OpenSSH_6.5")]
  23. [DataRow("OpenSSH_6.5p1")]
  24. [DataRow("OpenSSH_6.5 PKIX")]
  25. [DataRow("OpenSSH_6.6")]
  26. [DataRow("OpenSSH_6.6p1")]
  27. [DataRow("OpenSSH_6.6 PKIX")]
  28. public void ShouldExcludeCurve25519KexWhenServerIs(string softwareVersion)
  29. {
  30. ServerIdentification = new SshIdentification("2.0", softwareVersion);
  31. Session.Connect();
  32. Assert.IsFalse(ConnectionInfo.KeyExchangeAlgorithms.ContainsKey("curve25519-sha256"));
  33. Assert.IsFalse(ConnectionInfo.KeyExchangeAlgorithms.ContainsKey("curve25519-sha256@libssh.org"));
  34. }
  35. [TestMethod]
  36. [DataRow("OpenSSH_6.6.1")]
  37. [DataRow("OpenSSH_6.6.1p1")]
  38. [DataRow("OpenSSH_6.6.1 PKIX")]
  39. [DataRow("OpenSSH_6.7")]
  40. [DataRow("OpenSSH_6.7p1")]
  41. [DataRow("OpenSSH_6.7 PKIX")]
  42. public void ShouldIncludeCurve25519KexWhenServerIs(string softwareVersion)
  43. {
  44. ServerIdentification = new SshIdentification("2.0", softwareVersion);
  45. Session.Connect();
  46. Assert.IsTrue(ConnectionInfo.KeyExchangeAlgorithms.ContainsKey("curve25519-sha256"));
  47. Assert.IsTrue(ConnectionInfo.KeyExchangeAlgorithms.ContainsKey("curve25519-sha256@libssh.org"));
  48. }
  49. }
  50. }