diff --git a/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs b/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs index 5fc1cd832..2d95c8d5e 100644 --- a/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs @@ -343,5 +343,74 @@ public void AuthenticateShouldThrowArgumentNullExceptionWhenServiceFactoryIsNull Assert.AreEqual("serviceFactory", ex.ParamName); } } - } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentExceptionWhenUsingNoProxyAndNotResolvingHostLocally() + { + try + { + new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, + ProxyTypes.None, null, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, + HostResolutionMode.ResolvedByProxy, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + Assert.Fail(); + } + catch (ArgumentException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("hostResolutionMode", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentExceptionWhenUsingHttproxyAndResolvingHostOnProxy() + { + try + { + new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, + ProxyTypes.Http, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, + HostResolutionMode.ResolvedByProxy, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + Assert.Fail(); + } + catch (ArgumentException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("hostResolutionMode", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentExceptionWhenUsingSocks4ProxyAndResolvingHostOnProxy() + { + try + { + new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, + ProxyTypes.Socks4, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, + HostResolutionMode.ResolvedByProxy, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + Assert.Fail(); + } + catch (ArgumentException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("hostResolutionMode", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldNotThrowArgumentExceptionWhenUsingSocks5ProxyAndResolvingHostOnProxy() + { + var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, + ProxyTypes.Socks5, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, + HostResolutionMode.ResolvedByProxy, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + + Assert.AreEqual(HostResolutionMode.ResolvedByProxy, connectionInfo.HostResolutionMode); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet/Connection/Socks5Connector.cs b/src/Renci.SshNet/Connection/Socks5Connector.cs index e1b6859dc..642e00511 100644 --- a/src/Renci.SshNet/Connection/Socks5Connector.cs +++ b/src/Renci.SshNet/Connection/Socks5Connector.cs @@ -65,7 +65,7 @@ protected override void HandleProxyConnect(IConnectionInfo connectionInfo, Socke throw new ProxyException("SOCKS5: No acceptable authentication methods were offered."); } - var connectionRequest = CreateSocks5ConnectionRequest(connectionInfo.Host, (ushort) connectionInfo.Port); + var connectionRequest = CreateSocks5ConnectionRequest(connectionInfo.Host, (ushort) connectionInfo.Port, connectionInfo.HostResolutionMode); SocketAbstraction.Send(socket, connectionRequest); // Read Server SOCKS5 version @@ -173,10 +173,10 @@ private static byte[] CreateSocks5UserNameAndPasswordAuthenticationRequest(strin return authenticationRequest; } - private static byte[] CreateSocks5ConnectionRequest(string hostname, ushort port) + private static byte[] CreateSocks5ConnectionRequest(string hostname, ushort port, HostResolutionMode hostResolutionMode) { byte addressType; - var addressBytes = GetSocks5DestinationAddress(hostname, out addressType); + var addressBytes = GetSocks5DestinationAddress(hostname, hostResolutionMode, out addressType); var connectionRequest = new byte [ @@ -188,6 +188,8 @@ private static byte[] CreateSocks5ConnectionRequest(string hostname, ushort port 1 + // Address type 1 + + // Address Length if type == 0x03 + (addressType == 0x03 ? 1 : 0) + // Address addressBytes.Length + // Port number @@ -208,6 +210,10 @@ private static byte[] CreateSocks5ConnectionRequest(string hostname, ushort port // Address type connectionRequest[index++] = addressType; + // Address Length + if (addressType == 0x03) + connectionRequest[index++] = (byte)addressBytes.Length; + // Address Buffer.BlockCopy(addressBytes, 0, connectionRequest, index, addressBytes.Length); index += addressBytes.Length; @@ -218,24 +224,33 @@ private static byte[] CreateSocks5ConnectionRequest(string hostname, ushort port return connectionRequest; } - private static byte[] GetSocks5DestinationAddress(string hostname, out byte addressType) + private static byte[] GetSocks5DestinationAddress(string hostname, HostResolutionMode hostResolutionMode, out byte addressType) { - var ip = DnsAbstraction.GetHostAddresses(hostname)[0]; - byte[] address; - switch (ip.AddressFamily) + switch (hostResolutionMode) { - case AddressFamily.InterNetwork: - addressType = 0x01; // IPv4 - address = ip.GetAddressBytes(); - break; - case AddressFamily.InterNetworkV6: - addressType = 0x04; // IPv6 - address = ip.GetAddressBytes(); + case HostResolutionMode.ResolvedByProxy: + addressType = 0x03; // Host Name + address = SshData.Ascii.GetBytes(hostname); break; default: - throw new ProxyException(string.Format("SOCKS5: IP address '{0}' is not supported.", ip)); + var ip = DnsAbstraction.GetHostAddresses(hostname)[0]; + + switch (ip.AddressFamily) + { + case AddressFamily.InterNetwork: + addressType = 0x01; // IPv4 + address = ip.GetAddressBytes(); + break; + case AddressFamily.InterNetworkV6: + addressType = 0x04; // IPv6 + address = ip.GetAddressBytes(); + break; + default: + throw new ProxyException(string.Format("SOCKS5: IP address '{0}' is not supported.", ip)); + } + break; } return address; diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs index af8e1ca5c..2e63a0425 100644 --- a/src/Renci.SshNet/ConnectionInfo.cs +++ b/src/Renci.SshNet/ConnectionInfo.cs @@ -134,6 +134,11 @@ public class ConnectionInfo : IConnectionInfoInternal /// public string ProxyPassword { get; private set; } + /// + /// Resolve host locally or by a socks5 proxy + /// + public HostResolutionMode HostResolutionMode { get; private set; } + /// /// Gets or sets connection timeout. /// @@ -294,6 +299,31 @@ public ConnectionInfo(string host, int port, string username, params Authenticat /// is null. /// No specified. public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params AuthenticationMethod[] authenticationMethods) + : this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, HostResolutionMode.ResolvedLocally, authenticationMethods) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Connection host. + /// Connection port. + /// Connection username. + /// Type of the proxy. + /// The proxy host. + /// The proxy port. + /// The proxy username. + /// The proxy password. + /// The resolution mode of addresses, for SOCKS5 proxy + /// The authentication methods. + /// is null. + /// is null, a zero-length string or contains only whitespace characters. + /// is not within and . + /// is not and is null. + /// is not and is not within and . + /// is null. + /// No specified. + public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, HostResolutionMode hostResolutionMode, params AuthenticationMethod[] authenticationMethods) { if (host == null) throw new ArgumentNullException("host"); @@ -310,6 +340,17 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy throw new ArgumentNullException("proxyHost"); proxyPort.ValidatePort("proxyPort"); } + else + { + if (hostResolutionMode != HostResolutionMode.ResolvedLocally) + throw new ArgumentException("HostResolutionMode.ResolvedLocally is the only supported value when using no proxy", "hostResolutionMode"); + } + + if (hostResolutionMode == HostResolutionMode.ResolvedByProxy) + { + if (proxyType != ProxyTypes.Socks5) + throw new ArgumentException("HostResolutionMode.ResolvedByProxy is only supported by SOCKS5 proxies", "hostResolutionMode"); + } if (authenticationMethods == null) throw new ArgumentNullException("authenticationMethods"); @@ -431,6 +472,8 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy ProxyUsername = proxyUsername; ProxyPassword = proxyPassword; + HostResolutionMode = hostResolutionMode; + AuthenticationMethods = authenticationMethods; } diff --git a/src/Renci.SshNet/HostResolutionMode.cs b/src/Renci.SshNet/HostResolutionMode.cs new file mode 100644 index 000000000..05d7cffc6 --- /dev/null +++ b/src/Renci.SshNet/HostResolutionMode.cs @@ -0,0 +1,14 @@ +namespace Renci.SshNet +{ + /// + /// Specifies the way host names will be resolved when conecting through a proxy. + /// + public enum HostResolutionMode + { + /// The host name is resolved by the client and the host IP is sent to the proxy. + ResolvedLocally, + + /// The host name is sent to the proxy and resolved later. + ResolvedByProxy + } +} \ No newline at end of file diff --git a/src/Renci.SshNet/IConnectionInfo.cs b/src/Renci.SshNet/IConnectionInfo.cs index 22abefda2..20420f58c 100644 --- a/src/Renci.SshNet/IConnectionInfo.cs +++ b/src/Renci.SshNet/IConnectionInfo.cs @@ -112,6 +112,11 @@ internal interface IConnectionInfo /// string ProxyPassword { get; } + /// + /// Resolve host locally or by a socks5 proxy + /// + HostResolutionMode HostResolutionMode { get; } + /// /// Gets the number of retry attempts when session channel creation failed. /// diff --git a/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs b/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs index d8780caa7..d9396d2a1 100644 --- a/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs +++ b/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs @@ -27,7 +27,7 @@ public class KeyboardInteractiveConnectionInfo : ConnectionInfo, IDisposable /// The host. /// The username. public KeyboardInteractiveConnectionInfo(string host, string username) - : this(host, DefaultPort, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty) + : this(host, DefaultPort, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -39,7 +39,7 @@ public KeyboardInteractiveConnectionInfo(string host, string username) /// The port. /// The username. public KeyboardInteractiveConnectionInfo(string host, int port, string username) - : this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty) + : this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -54,7 +54,7 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username) /// The proxy host. /// The proxy port. public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort) - : this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty) + : this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -69,7 +69,7 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username, /// The proxy port. /// The proxy username. public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername) - : this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty) + : this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -82,7 +82,7 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username, /// The proxy host. /// The proxy port. public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort) - : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty) + : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -96,7 +96,7 @@ public KeyboardInteractiveConnectionInfo(string host, string username, ProxyType /// The proxy port. /// The proxy username. public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername) - : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty) + : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -111,7 +111,7 @@ public KeyboardInteractiveConnectionInfo(string host, string username, ProxyType /// The proxy username. /// The proxy password. public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword) - : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword) + : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, HostResolutionMode.ResolvedLocally) { } @@ -127,7 +127,24 @@ public KeyboardInteractiveConnectionInfo(string host, string username, ProxyType /// The proxy username. /// The proxy password. public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword) - : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new KeyboardInteractiveAuthenticationMethod(username)) + : this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, HostResolutionMode.ResolvedLocally) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Connection host. + /// Connection port. + /// Connection username. + /// Type of the proxy. + /// The proxy host. + /// The proxy port. + /// The proxy username. + /// The proxy password. + /// The resolution mode of addresses, for SOCKS5 proxy + public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, HostResolutionMode hostResolutionMode) + : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, hostResolutionMode, new KeyboardInteractiveAuthenticationMethod(username)) { foreach (var authenticationMethod in AuthenticationMethods) { diff --git a/src/Renci.SshNet/PasswordConnectionInfo.cs b/src/Renci.SshNet/PasswordConnectionInfo.cs index d42ff5094..0b89c73fa 100644 --- a/src/Renci.SshNet/PasswordConnectionInfo.cs +++ b/src/Renci.SshNet/PasswordConnectionInfo.cs @@ -50,7 +50,7 @@ public PasswordConnectionInfo(string host, string username, string password) /// is invalid, or is null or contains only whitespace characters. /// is not within and . public PasswordConnectionInfo(string host, int port, string username, string password) - : this(host, port, username, Encoding.UTF8.GetBytes(password), ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty) + : this(host, port, username, Encoding.UTF8.GetBytes(password), ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -65,7 +65,7 @@ public PasswordConnectionInfo(string host, int port, string username, string pas /// The proxy host. /// The proxy port. public PasswordConnectionInfo(string host, int port, string username, string password, ProxyTypes proxyType, string proxyHost, int proxyPort) - : this(host, port, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, string.Empty, string.Empty) + : this(host, port, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -81,7 +81,7 @@ public PasswordConnectionInfo(string host, int port, string username, string pas /// The proxy port. /// The proxy username. public PasswordConnectionInfo(string host, int port, string username, string password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername) - : this(host, port, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, proxyUsername, string.Empty) + : this(host, port, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -95,7 +95,7 @@ public PasswordConnectionInfo(string host, int port, string username, string pas /// The proxy host. /// The proxy port. public PasswordConnectionInfo(string host, string username, string password, ProxyTypes proxyType, string proxyHost, int proxyPort) - : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, string.Empty, string.Empty) + : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -110,7 +110,7 @@ public PasswordConnectionInfo(string host, string username, string password, Pro /// The proxy port. /// The proxy username. public PasswordConnectionInfo(string host, string username, string password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername) - : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, proxyUsername, string.Empty) + : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -126,7 +126,7 @@ public PasswordConnectionInfo(string host, string username, string password, Pro /// The proxy username. /// The proxy password. public PasswordConnectionInfo(string host, string username, string password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword) - : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword) + : this(host, DefaultPort, username, Encoding.UTF8.GetBytes(password), proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, HostResolutionMode.ResolvedLocally) { } @@ -152,7 +152,7 @@ public PasswordConnectionInfo(string host, string username, byte[] password) /// is invalid, or is null or contains only whitespace characters. /// is not within and . public PasswordConnectionInfo(string host, int port, string username, byte[] password) - : this(host, port, username, password, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty) + : this(host, port, username, password, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -167,7 +167,7 @@ public PasswordConnectionInfo(string host, int port, string username, byte[] pas /// The proxy host. /// The proxy port. public PasswordConnectionInfo(string host, int port, string username, byte[] password, ProxyTypes proxyType, string proxyHost, int proxyPort) - : this(host, port, username, password, proxyType, proxyHost, proxyPort, string.Empty, string.Empty) + : this(host, port, username, password, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -183,7 +183,7 @@ public PasswordConnectionInfo(string host, int port, string username, byte[] pas /// The proxy port. /// The proxy username. public PasswordConnectionInfo(string host, int port, string username, byte[] password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername) - : this(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty) + : this(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -197,7 +197,7 @@ public PasswordConnectionInfo(string host, int port, string username, byte[] pas /// The proxy host. /// The proxy port. public PasswordConnectionInfo(string host, string username, byte[] password, ProxyTypes proxyType, string proxyHost, int proxyPort) - : this(host, DefaultPort, username, password, proxyType, proxyHost, proxyPort, string.Empty, string.Empty) + : this(host, DefaultPort, username, password, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -212,7 +212,7 @@ public PasswordConnectionInfo(string host, string username, byte[] password, Pro /// The proxy port. /// The proxy username. public PasswordConnectionInfo(string host, string username, byte[] password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername) - : this(host, DefaultPort, username, password, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty) + : this(host, DefaultPort, username, password, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, HostResolutionMode.ResolvedLocally) { } @@ -228,7 +228,7 @@ public PasswordConnectionInfo(string host, string username, byte[] password, Pro /// The proxy username. /// The proxy password. public PasswordConnectionInfo(string host, string username, byte[] password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword) - : this(host, DefaultPort, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword) + : this(host, DefaultPort, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, HostResolutionMode.ResolvedLocally) { } @@ -245,7 +245,25 @@ public PasswordConnectionInfo(string host, string username, byte[] password, Pro /// The proxy username. /// The proxy password. public PasswordConnectionInfo(string host, int port, string username, byte[] password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword) - : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PasswordAuthenticationMethod(username, password)) + : this(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, HostResolutionMode.ResolvedLocally) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Connection host. + /// The port. + /// Connection username. + /// Connection password. + /// Type of the proxy. + /// The proxy host. + /// The proxy port. + /// The proxy username. + /// The proxy password. + /// The resolution mode of addresses, for SOCKS5 proxy + public PasswordConnectionInfo(string host, int port, string username, byte[] password, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, HostResolutionMode hostResolutionMode) + : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, hostResolutionMode, new PasswordAuthenticationMethod(username, password)) { foreach (var authenticationMethod in AuthenticationMethods) { diff --git a/src/Renci.SshNet/PrivateKeyConnectionInfo.cs b/src/Renci.SshNet/PrivateKeyConnectionInfo.cs index 7f0c4f658..2d00899fc 100644 --- a/src/Renci.SshNet/PrivateKeyConnectionInfo.cs +++ b/src/Renci.SshNet/PrivateKeyConnectionInfo.cs @@ -28,7 +28,7 @@ public class PrivateKeyConnectionInfo : ConnectionInfo, IDisposable /// /// public PrivateKeyConnectionInfo(string host, string username, params PrivateKeyFile[] keyFiles) - : this(host, DefaultPort, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, keyFiles) + : this(host, DefaultPort, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally, keyFiles) { } @@ -41,7 +41,7 @@ public PrivateKeyConnectionInfo(string host, string username, params PrivateKeyF /// Connection username. /// Connection key files. public PrivateKeyConnectionInfo(string host, int port, string username, params PrivateKeyFile[] keyFiles) - : this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, keyFiles) + : this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally, keyFiles) { } @@ -56,7 +56,7 @@ public PrivateKeyConnectionInfo(string host, int port, string username, params P /// The proxy port. /// The key files. public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params PrivateKeyFile[] keyFiles) - : this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, keyFiles) + : this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally, keyFiles) { } @@ -72,7 +72,7 @@ public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTyp /// The proxy username. /// The key files. public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params PrivateKeyFile[] keyFiles) - : this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, keyFiles) + : this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, HostResolutionMode.ResolvedLocally, keyFiles) { } @@ -86,7 +86,7 @@ public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTyp /// The proxy port. /// The key files. public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params PrivateKeyFile[] keyFiles) - : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, keyFiles) + : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, HostResolutionMode.ResolvedLocally, keyFiles) { } @@ -101,7 +101,7 @@ public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyTy /// The proxy username. /// The key files. public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params PrivateKeyFile[] keyFiles) - : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, keyFiles) + : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, HostResolutionMode.ResolvedLocally, keyFiles) { } @@ -117,7 +117,7 @@ public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyTy /// The proxy password. /// The key files. public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params PrivateKeyFile[] keyFiles) - : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles) + : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, HostResolutionMode.ResolvedLocally, keyFiles) { } @@ -134,7 +134,25 @@ public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyTy /// The proxy password. /// The key files. public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params PrivateKeyFile[] keyFiles) - : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PrivateKeyAuthenticationMethod(username, keyFiles)) + : this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, HostResolutionMode.ResolvedLocally, keyFiles) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Connection host. + /// The port. + /// Connection username. + /// Type of the proxy. + /// The proxy host. + /// The proxy port. + /// The proxy username. + /// The proxy password. + /// The key files. + /// The resolution mode of addresses, for SOCKS5 proxy + public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, HostResolutionMode hostResolutionMode, params PrivateKeyFile[] keyFiles) + : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, hostResolutionMode, new PrivateKeyAuthenticationMethod(username, keyFiles)) { KeyFiles = new Collection(keyFiles); }