Explorar o código

Add IPAddress as parameter to ForwardedPortRemote
Allow all projects to generate xml documentation files
Add GetIPAddress method and other minor refactoring

olegkap_cp %!s(int64=12) %!d(string=hai) anos
pai
achega
19802b6553
Modificáronse 24 ficheiros con 607 adicións e 98 borrados
  1. 0 24
      Renci.SshClient/Renci.SshNet.NET35/Common/Extensions.NET35.cs
  2. 16 0
      Renci.SshClient/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj
  3. 10 0
      Renci.SshClient/Renci.SshNet.Silverlight/Common/Extensions.SilverlightShared.cs
  4. 11 1
      Renci.SshClient/Renci.SshNet.Silverlight/Renci.SshNet.Silverlight.csproj
  5. 10 0
      Renci.SshClient/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj
  6. 1 1
      Renci.SshClient/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest.cs
  7. 2 2
      Renci.SshClient/Renci.SshNet.Tests/Properties/Resources.Designer.cs
  8. 1 1
      Renci.SshClient/Renci.SshNet.Tests/Properties/Resources.resx
  9. 11 1
      Renci.SshClient/Renci.SshNet.WindowsPhone/Renci.SshNet.WindowsPhone.csproj
  10. 11 1
      Renci.SshClient/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj
  11. 16 0
      Renci.SshClient/Renci.SshNet.sln
  12. 2 2
      Renci.SshClient/Renci.SshNet/Channels/ChannelForwardedTcpip.NET40.cs
  13. 2 2
      Renci.SshClient/Renci.SshNet/Channels/ChannelForwardedTcpip.cs
  14. 48 0
      Renci.SshClient/Renci.SshNet/Common/Extensions.NET.cs
  15. 1 2
      Renci.SshClient/Renci.SshNet/ForwardedPortDynamic.NET.cs
  16. 1 4
      Renci.SshClient/Renci.SshNet/ForwardedPortLocal.NET.cs
  17. 37 0
      Renci.SshClient/Renci.SshNet/ForwardedPortRemote.NET.cs
  18. 35 31
      Renci.SshClient/Renci.SshNet/ForwardedPortRemote.cs
  19. 50 0
      Renci.SshClient/Renci.SshNet/Messages/Transport/KeyExchangeEcdhInitMessage.cs
  20. 50 0
      Renci.SshClient/Renci.SshNet/Messages/Transport/KeyExchangeEcdhReplyMessage.cs
  21. 5 3
      Renci.SshClient/Renci.SshNet/Renci.SshNet.csproj
  22. 284 0
      Renci.SshClient/Renci.SshNet/Security/KeyExchangeEllipticCurveDiffieHellman.cs
  23. 1 3
      Renci.SshClient/Renci.SshNet/Session.NET.cs
  24. 2 20
      Renci.SshClient/Renci.SshNet/Session.cs

+ 0 - 24
Renci.SshClient/Renci.SshNet.NET35/Common/Extensions.NET35.cs

@@ -14,20 +14,6 @@ namespace Renci.SshNet
     /// </summary>
     public static partial class Extensions
     {
-        /// <summary>
-        /// Determines whether [is null or white space] [the specified value].
-        /// </summary>
-        /// <param name="value">The value.</param>
-        /// <returns>
-        ///   <c>true</c> if [is null or white space] [the specified value]; otherwise, <c>false</c>.
-        /// </returns>
-        internal static bool IsNullOrWhiteSpace(this string value)
-        {
-            if (string.IsNullOrEmpty(value)) return true;
-
-            return value.All(char.IsWhiteSpace);
-        }
-
         /// <summary>
         /// Disposes the specified socket.
         /// </summary>
@@ -78,15 +64,5 @@ namespace Renci.SshNet
             value.Length = 0;
             value.Capacity = 16;
         }
-
-        internal static bool CanRead(this Socket socket)
-        {
-            return socket.Connected && socket.Poll(-1, SelectMode.SelectRead) && socket.Available > 0;
-        }
-
-        internal static bool CanWrite(this Socket socket)
-        {
-            return socket.Connected && socket.Poll(-1, SelectMode.SelectWrite);
-        }
     }
 }

+ 16 - 0
Renci.SshClient/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj

@@ -29,6 +29,7 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <DocumentationFile>bin\Release\Renci.SshNet.XML</DocumentationFile>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
@@ -117,6 +118,9 @@
     <Compile Include="..\Renci.SshNet\Common\Extensions.cs">
       <Link>Common\Extensions.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Common\Extensions.NET.cs">
+      <Link>Common\Extensions.NET.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Common\HostKeyEventArgs.cs">
       <Link>Common\HostKeyEventArgs.cs</Link>
     </Compile>
@@ -246,6 +250,9 @@
     <Compile Include="..\Renci.SshNet\ForwardedPortRemote.cs">
       <Link>ForwardedPortRemote.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\ForwardedPortRemote.NET.cs">
+      <Link>ForwardedPortRemote.NET.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\HashInfo.cs">
       <Link>HashInfo.cs</Link>
     </Compile>
@@ -450,6 +457,12 @@
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeDhReplyMessage.cs">
       <Link>Messages\Transport\KeyExchangeDhReplyMessage.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhInitMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhInitMessage.cs</Link>
+    </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhReplyMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhReplyMessage.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeInitMessage.cs">
       <Link>Messages\Transport\KeyExchangeInitMessage.cs</Link>
     </Compile>
@@ -639,6 +652,9 @@
     <Compile Include="..\Renci.SshNet\Security\KeyExchangeDiffieHellmanGroupSha1.cs">
       <Link>Security\KeyExchangeDiffieHellmanGroupSha1.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Security\KeyExchangeEllipticCurveDiffieHellman.cs">
+      <Link>Security\KeyExchangeEllipticCurveDiffieHellman.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Security\KeyHostAlgorithm.cs">
       <Link>Security\KeyHostAlgorithm.cs</Link>
     </Compile>

+ 10 - 0
Renci.SshClient/Renci.SshNet.Silverlight/Common/Extensions.SilverlightShared.cs

@@ -6,6 +6,7 @@ using System.Net.Sockets;
 using System.Threading;
 using System.Security.Cryptography;
 using System.Diagnostics;
+using System.Net;
 
 namespace Renci.SshNet.Common
 {
@@ -77,5 +78,14 @@ namespace Renci.SshNet.Common
             return socket.Connected;
         }
 
+        internal static IPAddress GetIPAddress(this string host)
+        {
+            IPAddress ipAddress;
+            if (!IPAddress.TryParse(host, out ipAddress))
+            {
+                throw new ProxyException("Silverlight supports only IP addresses.");
+            }
+            return ipAddress;
+        }
     }
 }

+ 11 - 1
Renci.SshClient/Renci.SshNet.Silverlight/Renci.SshNet.Silverlight.csproj

@@ -49,6 +49,7 @@
     <NoConfig>true</NoConfig>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <DocumentationFile>Bin\Release\Renci.SshNet.Silverlight.XML</DocumentationFile>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
@@ -433,6 +434,12 @@
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeDhReplyMessage.cs">
       <Link>Messages\Transport\KeyExchangeDhReplyMessage.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhInitMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhInitMessage.cs</Link>
+    </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhReplyMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhReplyMessage.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeInitMessage.cs">
       <Link>Messages\Transport\KeyExchangeInitMessage.cs</Link>
     </Compile>
@@ -613,6 +620,9 @@
     <Compile Include="..\Renci.SshNet\Security\KeyExchangeDiffieHellmanGroupSha1.cs">
       <Link>Security\KeyExchangeDiffieHellmanGroupSha1.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Security\KeyExchangeEllipticCurveDiffieHellman.cs">
+      <Link>Security\KeyExchangeEllipticCurveDiffieHellman.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Security\KeyHostAlgorithm.cs">
       <Link>Security\KeyHostAlgorithm.cs</Link>
     </Compile>
@@ -813,7 +823,7 @@
       <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
         <SilverlightProjectProperties />
       </FlavorProperties>
-      <UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
+      <UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
     </VisualStudio>
   </ProjectExtensions>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 10 - 0
Renci.SshClient/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj

@@ -52,6 +52,7 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <Prefer32Bit>false</Prefer32Bit>
+    <DocumentationFile>Bin\Release\Renci.SshNet.Silverlight.XML</DocumentationFile>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="Microsoft.CSharp, Version=5.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -442,6 +443,12 @@
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeDhReplyMessage.cs">
       <Link>Messages\Transport\KeyExchangeDhReplyMessage.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhInitMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhInitMessage.cs</Link>
+    </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhReplyMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhReplyMessage.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeInitMessage.cs">
       <Link>Messages\Transport\KeyExchangeInitMessage.cs</Link>
     </Compile>
@@ -622,6 +629,9 @@
     <Compile Include="..\Renci.SshNet\Security\KeyExchangeDiffieHellmanGroupSha1.cs">
       <Link>Security\KeyExchangeDiffieHellmanGroupSha1.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Security\KeyExchangeEllipticCurveDiffieHellman.cs">
+      <Link>Security\KeyExchangeEllipticCurveDiffieHellman.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Security\KeyHostAlgorithm.cs">
       <Link>Security\KeyHostAlgorithm.cs</Link>
     </Compile>

+ 1 - 1
Renci.SshClient/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest.cs

@@ -22,7 +22,7 @@ namespace Renci.SshNet.Tests.Classes
             using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
             {
                 client.Connect();
-                var port1 = new ForwardedPortRemote(null, 8080, null, 80);
+                var port1 = new ForwardedPortRemote((string)null, 8080, (string)null, 80);
                 client.AddForwardedPort(port1);
                 client.Disconnect();
             }

+ 2 - 2
Renci.SshClient/Renci.SshNet.Tests/Properties/Resources.Designer.cs

@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.18010
+//     Runtime Version:4.0.30319.18033
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -97,7 +97,7 @@ namespace Renci.SshNet.Tests.Properties {
         }
         
         /// <summary>
-        ///   Looks up a localized string similar to oleg-centos.edc.renci.org.
+        ///   Looks up a localized string similar to 192.168.10.192.
         /// </summary>
         internal static string HOST {
             get {

+ 1 - 1
Renci.SshClient/Renci.SshNet.Tests/Properties/Resources.resx

@@ -149,7 +149,7 @@ D8DHbFwAT2mUv1QxRXYJO1y4pENboEzT6LUqxJgE+ae/F/29g2RD9DhtwqKqWjhM
 -----END DSA PRIVATE KEY-----</value>
   </data>
   <data name="HOST" xml:space="preserve">
-    <value>oleg-centos.edc.renci.org</value>
+    <value>192.168.10.192</value>
   </data>
   <data name="INVALID_KEY" xml:space="preserve">
     <value>-----BEGIN DSA PRIVATE KEY-----

+ 11 - 1
Renci.SshClient/Renci.SshNet.WindowsPhone/Renci.SshNet.WindowsPhone.csproj

@@ -40,6 +40,7 @@
     <NoConfig>true</NoConfig>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <DocumentationFile>Bin\Release\Renci.SshNet.WindowsPhone.XML</DocumentationFile>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System.Windows" />
@@ -428,6 +429,12 @@
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeDhReplyMessage.cs">
       <Link>Messages\Transport\KeyExchangeDhReplyMessage.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhInitMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhInitMessage.cs</Link>
+    </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhReplyMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhReplyMessage.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeInitMessage.cs">
       <Link>Messages\Transport\KeyExchangeInitMessage.cs</Link>
     </Compile>
@@ -611,6 +618,9 @@
     <Compile Include="..\Renci.SshNet\Security\KeyExchangeDiffieHellmanGroupSha1.cs">
       <Link>Security\KeyExchangeDiffieHellmanGroupSha1.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Security\KeyExchangeEllipticCurveDiffieHellman.cs">
+      <Link>Security\KeyExchangeEllipticCurveDiffieHellman.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Security\KeyHostAlgorithm.cs">
       <Link>Security\KeyHostAlgorithm.cs</Link>
     </Compile>
@@ -813,7 +823,7 @@
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
   <ProjectExtensions>
     <VisualStudio>
-      <UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
+      <UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
     </VisualStudio>
   </ProjectExtensions>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 11 - 1
Renci.SshClient/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj

@@ -45,6 +45,7 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <Prefer32Bit>false</Prefer32Bit>
+    <DocumentationFile>Bin\Release\Renci.SshNet.WindowsPhone.XML</DocumentationFile>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
     <DebugSymbols>true</DebugSymbols>
@@ -471,6 +472,12 @@
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeDhReplyMessage.cs">
       <Link>Messages\Transport\KeyExchangeDhReplyMessage.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhInitMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhInitMessage.cs</Link>
+    </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeEcdhReplyMessage.cs">
+      <Link>Messages\Transport\KeyExchangeEcdhReplyMessage.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Messages\Transport\KeyExchangeInitMessage.cs">
       <Link>Messages\Transport\KeyExchangeInitMessage.cs</Link>
     </Compile>
@@ -654,6 +661,9 @@
     <Compile Include="..\Renci.SshNet\Security\KeyExchangeDiffieHellmanGroupSha1.cs">
       <Link>Security\KeyExchangeDiffieHellmanGroupSha1.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Security\KeyExchangeEllipticCurveDiffieHellman.cs">
+      <Link>Security\KeyExchangeEllipticCurveDiffieHellman.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Security\KeyHostAlgorithm.cs">
       <Link>Security\KeyHostAlgorithm.cs</Link>
     </Compile>
@@ -856,7 +866,7 @@
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
   <ProjectExtensions>
     <VisualStudio>
-      <UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
+      <UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
     </VisualStudio>
   </ProjectExtensions>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 16 - 0
Renci.SshClient/Renci.SshNet.sln

@@ -24,6 +24,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.Silverlight5",
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.WindowsPhone8", "Renci.SshNet.WindowsPhone8\Renci.SshNet.WindowsPhone8.csproj", "{4A6CA785-1C8A-47FE-98C0-30C675A9328B}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{EFAF2072-A01F-4970-878A-AAD40326AFD2}"
+EndProject
 Global
 	GlobalSection(TestCaseManagementSettings) = postSolution
 		CategoryFile = Renci.SshNet1.vsmdi
@@ -153,6 +155,20 @@ Global
 		{4A6CA785-1C8A-47FE-98C0-30C675A9328B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
 		{4A6CA785-1C8A-47FE-98C0-30C675A9328B}.Release|x64.ActiveCfg = Release|Any CPU
 		{4A6CA785-1C8A-47FE-98C0-30C675A9328B}.Release|x86.ActiveCfg = Release|Any CPU
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|Any CPU.ActiveCfg = Debug|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|ARM.ActiveCfg = Debug|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|Mixed Platforms.Build.0 = Debug|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|x64.ActiveCfg = Debug|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|x86.ActiveCfg = Debug|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Debug|x86.Build.0 = Debug|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|Any CPU.ActiveCfg = Release|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|ARM.ActiveCfg = Release|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|Mixed Platforms.ActiveCfg = Release|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|Mixed Platforms.Build.0 = Release|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|x64.ActiveCfg = Release|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|x86.ActiveCfg = Release|x86
+		{EFAF2072-A01F-4970-878A-AAD40326AFD2}.Release|x86.Build.0 = Release|x86
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 2 - 2
Renci.SshClient/Renci.SshNet/Channels/ChannelForwardedTcpip.NET40.cs

@@ -13,9 +13,9 @@ namespace Renci.SshNet.Channels
     /// </summary>
     internal partial class ChannelForwardedTcpip : Channel
     {
-        partial void OpenSocket(string connectedHost, uint connectedPort)
+        partial void OpenSocket(IPAddress connectedHost, uint connectedPort)
         {
-            var ep = new IPEndPoint(Dns.GetHostEntry(connectedHost).AddressList[0], (int)connectedPort);
+            var ep = new IPEndPoint(connectedHost, (int)connectedPort);
             this._socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
             this._socket.Connect(ep);
             this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);

+ 2 - 2
Renci.SshClient/Renci.SshNet/Channels/ChannelForwardedTcpip.cs

@@ -40,7 +40,7 @@ namespace Renci.SshNet.Channels
         /// </summary>
         /// <param name="connectedHost">The connected host.</param>
         /// <param name="connectedPort">The connected port.</param>
-        public void Bind(string connectedHost, uint connectedPort)
+        public void Bind(IPAddress connectedHost, uint connectedPort)
         {
             byte[] buffer = null;
 
@@ -109,7 +109,7 @@ namespace Renci.SshNet.Channels
             this.Close();
         }
 
-        partial void OpenSocket(string connectedHost, uint connectedPort);
+        partial void OpenSocket(IPAddress connectedHost, uint connectedPort);
 
         public override void Close()
         {

+ 48 - 0
Renci.SshClient/Renci.SshNet/Common/Extensions.NET.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+
+namespace Renci.SshNet
+{
+    /// <summary>
+    /// Collection of different extension method specific for .NET 4.0
+    /// </summary>
+    public static partial class Extensions
+    {
+        /// <summary>
+        /// Determines whether [is null or white space] [the specified value].
+        /// </summary>
+        /// <param name="value">The value.</param>
+        /// <returns>
+        ///   <c>true</c> if [is null or white space] [the specified value]; otherwise, <c>false</c>.
+        /// </returns>
+        internal static bool IsNullOrWhiteSpace(this string value)
+        {
+            if (string.IsNullOrEmpty(value)) return true;
+
+            return value.All(char.IsWhiteSpace);
+        }
+        
+        internal static bool CanRead(this Socket socket)
+        {
+            return socket.Connected && socket.Poll(-1, SelectMode.SelectRead) && socket.Available > 0;
+        }
+
+        internal static bool CanWrite(this Socket socket)
+        {
+            return socket.Connected && socket.Poll(-1, SelectMode.SelectWrite);
+        }
+
+        internal static IPAddress GetIPAddress(this string host)
+        {
+            IPAddress ipAddress;
+            if (!IPAddress.TryParse(host, out ipAddress))
+                ipAddress = Dns.GetHostAddresses(host).First();
+
+            return ipAddress;
+        }
+    }
+}

+ 1 - 2
Renci.SshClient/Renci.SshNet/ForwardedPortDynamic.NET.cs

@@ -24,8 +24,7 @@ namespace Renci.SshNet
             var ip = IPAddress.Any;
             if (!string.IsNullOrEmpty(this.BoundHost))
             {
-                if (IPAddress.TryParse(this.BoundHost, out ip) == false)
-                    ip = Dns.GetHostAddresses(this.BoundHost)[0];
+                ip = this.BoundHost.GetIPAddress();
             }
 
             var ep = new IPEndPoint(ip, (int)this.BoundPort);

+ 1 - 4
Renci.SshClient/Renci.SshNet/ForwardedPortLocal.NET.cs

@@ -21,10 +21,7 @@ namespace Renci.SshNet
             if (this.IsStarted)
                 return;
 
-            IPAddress addr;
-            if (!IPAddress.TryParse(this.BoundHost, out addr))
-                addr = Dns.GetHostAddresses(this.BoundHost).First();
-
+            IPAddress addr = this.BoundHost.GetIPAddress();
             var ep = new IPEndPoint(addr, (int)this.BoundPort); 
 
             this._listener = new TcpListener(ep);

+ 37 - 0
Renci.SshClient/Renci.SshNet/ForwardedPortRemote.NET.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Net;
+
+namespace Renci.SshNet
+{
+    /// <summary>
+    /// Provides functionality for remote port forwarding
+    /// </summary>
+    public partial class ForwardedPortRemote
+    {
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ForwardedPortRemote"/> class.
+        /// </summary>
+        /// <param name="boundPort">The bound port.</param>
+        /// <param name="host">The host.</param>
+        /// <param name="port">The port.</param>
+        /// <example>
+        ///     <code source="..\..\Renci.SshNet.Tests\Classes\ForwardedPortRemoteTest.cs" region="Example SshClient AddForwardedPort Start Stop ForwardedPortRemote" language="C#" title="Remote port forwarding" />
+        /// </example>
+        public ForwardedPortRemote(uint boundPort, string host, uint port)
+            : this(string.Empty, boundPort, host, port)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ForwardedPortRemote"/> class.
+        /// </summary>
+        /// <param name="boundHost">The bound host.</param>
+        /// <param name="boundPort">The bound port.</param>
+        /// <param name="host">The host.</param>
+        /// <param name="port">The port.</param>
+        public ForwardedPortRemote(string boundHost, uint boundPort, string host, uint port)
+            : this(Dns.GetHostEntry(boundHost).AddressList[0], boundPort, Dns.GetHostEntry(host).AddressList[0], port)
+        {
+        }
+    }
+}

+ 35 - 31
Renci.SshClient/Renci.SshNet/ForwardedPortRemote.cs

@@ -5,6 +5,7 @@ using Renci.SshNet.Messages.Connection;
 using Renci.SshNet.Common;
 using System.Diagnostics;
 using System.Globalization;
+using System.Net;
 
 namespace Renci.SshNet
 {
@@ -20,7 +21,18 @@ namespace Renci.SshNet
         /// <summary>
         /// Gets the bound host.
         /// </summary>
-        public string BoundHost { get; protected set; }
+        public IPAddress BoundHostAddress { get; protected set; }
+
+        /// <summary>
+        /// Gets the bound host.
+        /// </summary>
+        public string BoundHost
+        {
+            get
+            {
+                return this.BoundHostAddress.ToString();
+            }
+        }
 
         /// <summary>
         /// Gets the bound port.
@@ -30,61 +42,53 @@ namespace Renci.SshNet
         /// <summary>
         /// Gets the forwarded host.
         /// </summary>
-        public string Host { get; protected set; }
+        public IPAddress HostAddress { get; protected set; }
 
         /// <summary>
-        /// Gets the forwarded port.
+        /// Gets the forwarded host.
         /// </summary>
-        public uint Port { get; protected set; }
+        public string Host
+        {
+            get
+            {
+                return this.HostAddress.ToString();
+            }
+        }
 
         /// <summary>
-        /// Initializes a new instance of the <see cref="ForwardedPortRemote"/> class.
+        /// Gets the forwarded port.
         /// </summary>
-        /// <param name="boundPort">The bound port.</param>
-        /// <param name="host">The host.</param>
-        /// <param name="port">The port.</param>
-        /// <example>
-        ///     <code source="..\..\Renci.SshNet.Tests\Classes\ForwardedPortRemoteTest.cs" region="Example SshClient AddForwardedPort Start Stop ForwardedPortRemote" language="C#" title="Remote port forwarding" />
-        /// </example>
-        public ForwardedPortRemote(uint boundPort, string host, uint port)
-            : this(string.Empty, boundPort, host, port)
-        {
-        }
+        public uint Port { get; protected set; }
 
         /// <summary>
-        /// Initializes a new instance of the <see cref="ForwardedPortRemote"/> class.
+        /// Initializes a new instance of the <see cref="ForwardedPortRemote" /> class.
         /// </summary>
-        /// <param name="boundHost">The bound host.</param>
+        /// <param name="boundHostAddress">The bound host address.</param>
         /// <param name="boundPort">The bound port.</param>
-        /// <param name="host">The host.</param>
+        /// <param name="hostAddress">The host address.</param>
         /// <param name="port">The port.</param>
-        public ForwardedPortRemote(string boundHost, uint boundPort, string host, uint port)
+        /// <exception cref="System.ArgumentNullException">boundHost</exception>
+        /// <exception cref="System.ArgumentOutOfRangeException">boundPort</exception>
+        public ForwardedPortRemote(IPAddress boundHostAddress, uint boundPort, IPAddress hostAddress, uint port)
         {
-            if (boundHost == null)
+            if (boundHostAddress == null)
                 throw new ArgumentNullException("boundHost");
 
-            if (host == null)
+            if (hostAddress == null)
                 throw new ArgumentNullException("host");
 
-            if (!boundHost.IsValidHost())
-                throw new ArgumentException("boundHost");
-
             if (!boundPort.IsValidPort())
                 throw new ArgumentOutOfRangeException("boundPort");
 
-            if (!host.IsValidHost())
-                throw new ArgumentException("host");
-
             if (!port.IsValidPort())
                 throw new ArgumentOutOfRangeException("port");
 
-            this.BoundHost = boundHost;
+            this.BoundHostAddress = boundHostAddress;
             this.BoundPort = boundPort;
-            this.Host = host;
+            this.HostAddress = hostAddress;
             this.Port = port;
         }
 
-
         /// <summary>
         /// Starts remote port forwarding.
         /// </summary>
@@ -160,7 +164,7 @@ namespace Renci.SshNet
                             this.RaiseRequestReceived(info.OriginatorAddress, info.OriginatorPort);
 
                             var channel = this.Session.CreateChannel<ChannelForwardedTcpip>(e.Message.LocalChannelNumber, e.Message.InitialWindowSize, e.Message.MaximumPacketSize);
-                            channel.Bind(this.Host, this.Port);
+                            channel.Bind(this.HostAddress, this.Port);
                         }
                         catch (Exception exp)
                         {

+ 50 - 0
Renci.SshClient/Renci.SshNet/Messages/Transport/KeyExchangeEcdhInitMessage.cs

@@ -0,0 +1,50 @@
+using Renci.SshNet.Common;
+using System.Linq;
+using System.Collections.Generic;
+
+namespace Renci.SshNet.Messages.Transport
+{
+    /// <summary>
+    /// Represents SSH_MSG_KEXECDH_INIT message.
+    /// </summary>
+    [Message("SSH_MSG_KEXECDH_INIT", 30)]
+    internal class KeyExchangeEcdhInitMessage : Message, IKeyExchangedAllowed
+    {
+        /// <summary>
+        /// Gets the client's ephemeral contribution to the ECDH exchange, encoded as an octet string
+        /// </summary>
+        public byte[] QC { get; private set; }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="KeyExchangeEcdhInitMessage"/> class.
+        /// </summary>
+        /// <param name="clientExchangeValue">The client exchange value.</param>
+        public KeyExchangeEcdhInitMessage(BigInteger d, BigInteger Q)
+        {
+            var a = d.ToByteArray().Reverse();
+            var b = Q.ToByteArray().Reverse();
+            var data = new List<byte>();
+            data.Add(0x04);
+            data.AddRange(d.ToByteArray().Reverse());
+            data.AddRange(Q.ToByteArray().Reverse());
+            this.QC = data.ToArray();
+        }
+
+        /// <summary>
+        /// Called when type specific data need to be loaded.
+        /// </summary>
+        protected override void LoadData()
+        {
+            this.ResetReader();
+            this.QC = this.ReadBinaryString();
+        }
+
+        /// <summary>
+        /// Called when type specific data need to be saved.
+        /// </summary>
+        protected override void SaveData()
+        {
+            this.WriteBinaryString(this.QC);
+        }
+    }
+}

+ 50 - 0
Renci.SshClient/Renci.SshNet/Messages/Transport/KeyExchangeEcdhReplyMessage.cs

@@ -0,0 +1,50 @@
+using System;
+using Renci.SshNet.Common;
+
+namespace Renci.SshNet.Messages.Transport
+{
+    /// <summary>
+    /// Represents SSH_MSG_KEXECDH_REPLY message.
+    /// </summary>
+    [Message("SSH_MSG_KEXECDH_REPLY", 31)]
+    public class KeyExchangeEcdhReplyMessage : Message
+    {
+        /// <summary>
+        /// Gets a string encoding an X.509v3 certificate containing the server's ECDSA public host key
+        /// </summary>
+        /// <value>The host key.</value>
+        public byte[] KS { get; private set; }
+
+        /// <summary>
+        /// Gets the the server's ephemeral contribution to the ECDH exchange, encoded as an octet string.
+        /// </summary>
+        public byte[] QS { get; private set; }
+
+        /// <summary>
+        /// Gets the an octet string containing the server's signature of the newly established exchange hash value.
+        /// </summary>
+        /// <value>The signature.</value>
+        public byte[] Signature { get; private set; }
+
+        /// <summary>
+        /// Called when type specific data need to be loaded.
+        /// </summary>
+        protected override void LoadData()
+        {
+            this.ResetReader();
+            this.KS = this.ReadBinaryString();
+            this.QS = this.ReadBinaryString();
+            this.Signature = this.ReadBinaryString();
+        }
+
+        /// <summary>
+        /// Called when type specific data need to be saved.
+        /// </summary>
+        protected override void SaveData()
+        {
+            this.WriteBinaryString(this.KS);
+            this.WriteBinaryString(this.QS);
+            this.WriteBinaryString(this.Signature);
+        }
+    }
+}

+ 5 - 3
Renci.SshClient/Renci.SshNet/Renci.SshNet.csproj

@@ -69,6 +69,7 @@
     <Compile Include="Common\ChannelEventArgs.cs" />
     <Compile Include="Common\ChannelOpenFailedEventArgs.cs" />
     <Compile Include="Common\ChannelRequestEventArgs.cs" />
+    <Compile Include="Common\Extensions.NET.cs" />
     <Compile Include="Common\ProxyException.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -80,9 +81,6 @@
     <Compile Include="Common\Extensions.cs">
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="Common\Extensions.NET40.cs">
-      <SubType>Code</SubType>
-    </Compile>
     <Compile Include="Common\NetConfServerException.cs" />
     <Compile Include="Common\ObjectIdentifier.cs" />
     <Compile Include="Common\PipeStream.cs" />
@@ -131,9 +129,12 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="ConnectionInfo.cs" />
+    <Compile Include="ForwardedPortRemote.NET.cs" />
     <Compile Include="HashInfo.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Messages\Transport\KeyExchangeEcdhInitMessage.cs" />
+    <Compile Include="Messages\Transport\KeyExchangeEcdhReplyMessage.cs" />
     <Compile Include="Security\Cryptography\Hashes\RIPEMD160Hash.cs" />
     <Compile Include="Security\Cryptography\Hashes\SHA2HashBase.cs">
       <SubType>Code</SubType>
@@ -144,6 +145,7 @@
     <Compile Include="Security\Cryptography\Hashes\SHA512Hash.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Security\KeyExchangeEllipticCurveDiffieHellman.cs" />
     <Compile Include="ShellStream.NET40.cs" />
     <Compile Include="ExpectAsyncResult.cs" />
     <Compile Include="Security\KeyExchangeDiffieHellmanGroupSha1.cs" />

+ 284 - 0
Renci.SshClient/Renci.SshNet/Security/KeyExchangeEllipticCurveDiffieHellman.cs

@@ -0,0 +1,284 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Security.Cryptography;
+using Renci.SshNet.Messages.Transport;
+using System.Diagnostics;
+using Renci.SshNet.Messages;
+using Renci.SshNet.Common;
+using Renci.SshNet.Security.Cryptography;
+using System.Globalization;
+
+namespace Renci.SshNet.Security
+{
+    /// <summary>
+    /// Represents base class for Diffie Hellman key exchange algorithm
+    /// </summary>
+    public class KeyExchangeEllipticCurveDiffieHellman : KeyExchange
+    {
+        /// <summary>
+        /// Specifies client payload
+        /// </summary>
+        protected byte[] _clientPayload;
+
+        /// <summary>
+        /// Specifies server payload
+        /// </summary>
+        protected byte[] _serverPayload;
+
+        /// <summary>
+        /// Specifies client exchange number.
+        /// </summary>
+        protected BigInteger _clientExchangeValue;
+
+        /// <summary>
+        /// Specifies server exchange number.
+        /// </summary>
+        protected BigInteger _serverExchangeValue;
+
+        /// <summary>
+        /// Specifies random generated number.
+        /// </summary>
+        protected BigInteger _randomValue;
+
+        /// <summary>
+        /// Specifies host key data.
+        /// </summary>
+        protected byte[] _hostKey;
+
+        /// <summary>
+        /// Specifies signature data.
+        /// </summary>
+        protected byte[] _signature;
+
+        ////  256
+        //p = FFFFFFFF 00000001 00000000 00000000 00000000 FFFFFFFF FFFFFFFF FFFFFFFF
+        //a = FFFFFFFF 00000001 00000000 00000000 00000000 FFFFFFFF FFFFFFFF FFFFFFFC
+        //b = 5AC635D8 AA3A93E7 B3EBBD55 769886BC 651D06B0 CC53B0F6 3BCE3C3E 27D2604B
+        //S = C49D3608 86E70493 6A6678E1 139D26B7 819F7E90
+        //The base point G in compressed form is:
+        //G = 03 6B17D1F2 E12C4247 F8BCE6E5 63A440F2 77037D81 2DEB33A0 F4A13945 D898C296
+        //and in uncompressed form is:
+        //G = 04 6B17D1F2 E12C4247 F8BCE6E5 63A440F2 77037D81 2DEB33A0 F4A13945 D898C296 4FE342E2 FE1A7F9B 8EE7EB4A 7C0F9E16 2BCE3357 6B315ECE CBB64068 37BF51F5
+        //n = FFFFFFFF 00000000 FFFFFFFF FFFFFFFF BCE6FAAD A7179E84 F3B9CAC2 FC632551
+        //h = 01
+
+        ////  384
+        //p = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFFFF 00000000 00000000 FFFFFFFF
+        //a = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFFFF 00000000 00000000 FFFFFFFC
+        //b = B3312FA7 E23EE7E4 988E056B E3F82D19 181D9C6E FE814112 0314088F 5013875A C656398D 8A2ED19D 2A85C8ED D3EC2AEF
+        //S = A335926A A319A27A 1D00896A 6773A482 7ACDAC73
+        //The base point G in compressed form is:
+        //G = 03 AA87CA22 BE8B0537 8EB1C71E F320AD74 6E1D3B62 8BA79B98 59F741E0 82542A38 5502F25D BF55296C 3A545E38 72760AB7
+        //and in uncompressed form is:
+        //G = 04 AA87CA22 BE8B0537 8EB1C71E F320AD74 6E1D3B62 8BA79B98 59F741E0 82542A38 5502F25D BF55296C 3A545E38 72760AB7 3617DE4A 96262C6F 5D9E98BF 9292DC29 F8F41DBD 289A147C E9DA3113 B5F0B8C0 0A60B1CE 1D7E819D 7A431D7C 90EA0E5F
+        //n = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF C7634D81 F4372DDF 581A0DB2 48B0A77A ECEC196A CCC52973
+        //h = 01
+
+        public override string Name
+        {
+            get { return "ecdh-sha2-nistp256"; }
+        }
+
+        /// <summary>
+        /// Starts key exchange algorithm
+        /// </summary>
+        /// <param name="session">The session.</param>
+        /// <param name="message">Key exchange init message.</param>
+        public override void Start(Session session, KeyExchangeInitMessage message)
+        {
+            base.Start(session, message);
+
+            this._serverPayload = message.GetBytes().ToArray();
+            this._clientPayload = this.Session.ClientInitMessage.GetBytes().ToArray();
+
+            this.Session.RegisterMessage("SSH_MSG_KEXECDH_REPLY");
+
+            this.Session.MessageReceived += Session_MessageReceived;
+
+            //3.2.1 Elliptic Curve Key Pair Generation Primitive
+            //Elliptic curve key pairs should be generated as follows:
+            //Input: Valid elliptic curve domain parameters T = (p, a, b, G, n, h) or (m, f(x), a, b,G, n, h).
+            //Output: An elliptic curve key pair (d,Q) associated with T.
+            //Actions: Generate an elliptic curve key pair as follows:
+            //1. Randomly or pseudorandomly select an integer d in the interval [1, n − 1].
+            //2. Compute Q = dG.
+            //3. Output (d,Q).
+            
+            BigInteger p;
+            BigInteger.TryParse("00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, out p);
+
+
+
+            BigInteger n;
+            BigInteger.TryParse("00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, out n);
+            BigInteger G;
+            BigInteger.TryParse("00036B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, out G);
+
+            BigInteger d;
+
+            do
+            {
+                d = BigInteger.Random(n.BitLength);
+            } while (d < 1 || d > n);
+
+            var Q = d * G;
+
+
+            this.SendMessage(new KeyExchangeEcdhInitMessage(d, Q));
+
+        }
+
+        private void Session_MessageReceived(object sender, MessageEventArgs<Message> e)
+        {
+            var message = e.Message as KeyExchangeEcdhReplyMessage;
+            if (message != null)
+            {
+                //  Unregister message once received
+                this.Session.UnRegisterMessage("SSH_MSG_KEXECDH_REPLY");
+
+                this.HandleServerEcdhReply();
+
+                //  When SSH_MSG_KEXDH_REPLY received key exchange is completed
+                this.Finish();
+            }
+        }
+
+        /// <summary>
+        /// Validates the exchange hash.
+        /// </summary>
+        /// <returns>
+        /// true if exchange hash is valid; otherwise false.
+        /// </returns>
+        protected override bool ValidateExchangeHash()
+        {
+            //var exchangeHash = this.CalculateHash();
+
+            //var length = (uint)(this._hostKey[0] << 24 | this._hostKey[1] << 16 | this._hostKey[2] << 8 | this._hostKey[3]);
+
+            //var algorithmName = Encoding.UTF8.GetString(this._hostKey, 4, (int)length);
+
+            //var key = this.Session.ConnectionInfo.HostKeyAlgorithms[algorithmName](this._hostKey);
+
+            //this.Session.ConnectionInfo.CurrentHostKeyAlgorithm = algorithmName;
+
+            //if (this.CanTrustHostKey(key))
+            //{
+
+            //    return key.VerifySignature(exchangeHash, this._signature);
+            //}
+            //else
+            //{
+            //    return false;
+            //}
+
+            return false;
+        }
+
+        /// <summary>
+        /// Populates the client exchange value.
+        /// </summary>
+        //protected void PopulateClientExchangeValue()
+        //{
+        //    if (this._group.IsZero)
+        //        throw new ArgumentNullException("_group");
+
+        //    if (this._prime.IsZero)
+        //        throw new ArgumentNullException("_prime");
+
+        //    var bitLength = this._prime.BitLength;
+
+        //    do
+        //    {
+        //        this._randomValue = BigInteger.Random(bitLength);
+
+        //        this._clientExchangeValue = BigInteger.ModPow(this._group, this._randomValue, this._prime);
+
+        //    } while (this._clientExchangeValue < 1 || this._clientExchangeValue > ((this._prime - 1)));
+        //}
+
+        protected virtual void HandleServerEcdhReply()
+        {
+            //this._serverExchangeValue = serverExchangeValue;
+            //this._hostKey = hostKey;
+            //this.SharedKey = BigInteger.ModPow(serverExchangeValue, this._randomValue, this._prime);
+            //this._signature = signature;
+        }
+
+        protected override byte[] CalculateHash()
+        {
+            var hashData = new _ExchangeHashData
+            {
+                ClientVersion = this.Session.ClientVersion,
+                ServerVersion = this.Session.ServerVersion,
+                ClientPayload = this._clientPayload,
+                ServerPayload = this._serverPayload,
+                HostKey = this._hostKey,
+                SharedKey = this.SharedKey,
+            }.GetBytes();
+
+            //string   V_C, client's identification string (CR and LF excluded)
+            //string   V_S, server's identification string (CR and LF excluded)
+            //string   I_C, payload of the client's SSH_MSG_KEXINIT
+            //string   I_S, payload of the server's SSH_MSG_KEXINIT
+            //string   K_S, server's public host key
+            //string   Q_C, client's ephemeral public key octet string
+            //string   Q_S, server's ephemeral public key octet string
+            //mpint    K,   shared secret
+            return this.Hash(hashData);
+        }
+
+        private class _ExchangeHashData : SshData
+        {
+            public string ServerVersion { get; set; }
+
+            public string ClientVersion { get; set; }
+
+            public byte[] ClientPayload { get; set; }
+
+            public byte[] ServerPayload { get; set; }
+
+            public byte[] HostKey { get; set; }
+
+            public UInt32 MinimumGroupSize { get; set; }
+
+            public UInt32 PreferredGroupSize { get; set; }
+
+            public UInt32 MaximumGroupSize { get; set; }
+
+            public BigInteger Prime { get; set; }
+
+            public BigInteger SubGroup { get; set; }
+
+            public BigInteger ClientExchangeValue { get; set; }
+
+            public BigInteger ServerExchangeValue { get; set; }
+
+            public BigInteger SharedKey { get; set; }
+
+            protected override void LoadData()
+            {
+                throw new System.NotImplementedException();
+            }
+
+            protected override void SaveData()
+            {
+                this.Write(this.ClientVersion);
+                this.Write(this.ServerVersion);
+                this.WriteBinaryString(this.ClientPayload);
+                this.WriteBinaryString(this.ServerPayload);
+                this.WriteBinaryString(this.HostKey);
+                this.Write(this.MinimumGroupSize);
+                this.Write(this.PreferredGroupSize);
+                this.Write(this.MaximumGroupSize);
+                this.Write(this.Prime);
+                this.Write(this.SubGroup);
+                this.Write(this.ClientExchangeValue);
+                this.Write(this.ServerExchangeValue);
+                this.Write(this.SharedKey);
+            }
+        }
+
+    }
+}

+ 1 - 3
Renci.SshClient/Renci.SshNet/Session.NET.cs

@@ -30,9 +30,7 @@ namespace Renci.SshNet
 
         partial void SocketConnect(string host, int port)
         {
-            IPAddress addr;
-            if (!IPAddress.TryParse(host, out addr))
-                addr = Dns.GetHostAddresses(host).First();
+            IPAddress addr = host.GetIPAddress();
 
             var ep = new IPEndPoint(addr, port);
             this._socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

+ 2 - 20
Renci.SshClient/Renci.SshNet/Session.cs

@@ -1625,16 +1625,7 @@ namespace Renci.SshNet
             this.SocketWriteByte((byte)(this.ConnectionInfo.Port % 0xFF));
 
             //  Send IP
-            IPAddress ipAddress;
-#if SILVERLIGHT
-            if (!IPAddress.TryParse(this.ConnectionInfo.Host, out ipAddress))
-            {
-                throw new ProxyException("SOCKS4: Silverlight supports only IP addresses.");
-            }
-#else
-            if (!IPAddress.TryParse(this.ConnectionInfo.Host, out ipAddress))
-                ipAddress = Dns.GetHostAddresses(this.ConnectionInfo.Host).First();
-#endif
+            IPAddress ipAddress = this.ConnectionInfo.Host.GetIPAddress();
             this.SocketWrite(ipAddress.GetAddressBytes());
 
             //  Send username
@@ -1749,16 +1740,7 @@ namespace Renci.SshNet
             //  Send reserved, must be 0x00
             this.SocketWriteByte(0x00);
 
-            IPAddress ip;
-#if SILVERLIGHT
-            if (!IPAddress.TryParse(this.ConnectionInfo.Host, out ip))
-            {
-                throw new ProxyException("SOCKS4: Silverlight supports only IP addresses.");
-            }
-#else
-            if (!IPAddress.TryParse(this.ConnectionInfo.Host, out ip))
-                ip = Dns.GetHostAddresses(this.ConnectionInfo.Host).First();
-#endif
+            IPAddress ip = this.ConnectionInfo.Host.GetIPAddress();
 
             //  Send address type and address
             if (ip.AddressFamily == AddressFamily.InterNetwork)