Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@
<Compile Include="..\Renci.SshNet\HashInfo.cs">
<Link>HashInfo.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\HostResolutionMode.cs">
<Link>HostResolutionMode.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\IAuthenticationMethod.cs">
<Link>IAuthenticationMethod.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@
<Compile Include="..\Renci.SshNet\HashInfo.cs">
<Link>HashInfo.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\HostResolutionMode.cs">
<Link>HostResolutionMode.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\IAuthenticationMethod.cs">
<Link>IAuthenticationMethod.cs</Link>
</Compile>
Expand Down
71 changes: 70 additions & 1 deletion src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
3 changes: 3 additions & 0 deletions src/Renci.SshNet.UAP10/Renci.SshNet.UAP10.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@
<Compile Include="..\Renci.SshNet\HashInfo.cs">
<Link>HashInfo.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\HostResolutionMode.cs">
<Link>HostResolutionMode.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\IAuthenticationMethod.cs">
<Link>IAuthenticationMethod.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@
<Compile Include="..\Renci.SshNet\HashInfo.cs">
<Link>HashInfo.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\HostResolutionMode.cs">
<Link>HostResolutionMode.cs</Link>
</Compile>
<Compile Include="..\Renci.SshNet\IAuthenticationMethod.cs">
<Link>IAuthenticationMethod.cs</Link>
</Compile>
Expand Down
44 changes: 44 additions & 0 deletions src/Renci.SshNet/ConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public class ConnectionInfo : IConnectionInfoInternal
/// </summary>
public string ProxyPassword { get; private set; }

/// <summary>
/// Gets the host resolution mode.
/// </summary>
public HostResolutionMode? HostResolutionMode { get; private set; }

/// <summary>
/// Gets or sets connection timeout.
/// </summary>
Expand Down Expand Up @@ -263,6 +268,32 @@ public ConnectionInfo(string host, int port, string username, params Authenticat
/// <exception cref="ArgumentNullException"><paramref name="authenticationMethods"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">No <paramref name="authenticationMethods"/> specified.</exception>
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, SshNet.HostResolutionMode.ResolvedLocally, authenticationMethods)
{
}


/// <summary>
/// Initializes a new instance of the <see cref="ConnectionInfo" /> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="port">Connection port.</param>
/// <param name="username">Connection username.</param>
/// <param name="proxyType">Type of the proxy.</param>
/// <param name="proxyHost">The proxy host.</param>
/// <param name="proxyPort">The proxy port.</param>
/// <param name="proxyUsername">The proxy username.</param>
/// <param name="proxyPassword">The proxy password.</param>
/// <param name="hostResolutionMode">The host name resolution method when using the proxy.</param>
/// <param name="authenticationMethods">The authentication methods.</param>
/// <exception cref="ArgumentNullException"><paramref name="host"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="username" /> is <c>null</c>, a zero-length string or contains only whitespace characters.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port" /> is not within <see cref="F:System.Net.IPEndPoint.MinPort" /> and <see cref="F:System.Net.IPEndPoint.MaxPort" />.</exception>
/// <exception cref="ArgumentNullException"><paramref name="proxyType"/> is not <see cref="ProxyTypes.None"/> and <paramref name="proxyHost" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="proxyType"/> is not <see cref="ProxyTypes.None"/> and <paramref name="proxyPort" /> is not within <see cref="F:System.Net.IPEndPoint.MinPort" /> and <see cref="F:System.Net.IPEndPoint.MaxPort" />.</exception>
/// <exception cref="ArgumentNullException"><paramref name="authenticationMethods"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">No <paramref name="authenticationMethods"/> specified.</exception>
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");
Expand All @@ -279,6 +310,17 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy
throw new ArgumentNullException("proxyHost");
proxyPort.ValidatePort("proxyPort");
}
else
{
if (hostResolutionMode != SshNet.HostResolutionMode.ResolvedLocally)
throw new ArgumentException("HostResolutionMode.ResolvedLocally is the only supported value when using no proxy", "hostResolutionMode");
}

if (hostResolutionMode == SshNet.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");
Expand Down Expand Up @@ -393,6 +435,8 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy
ProxyUsername = proxyUsername;
ProxyPassword = proxyPassword;

HostResolutionMode = hostResolutionMode;

AuthenticationMethods = authenticationMethods;
}

Expand Down
14 changes: 14 additions & 0 deletions src/Renci.SshNet/HostResolutionMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Renci.SshNet
{
/// <summary>
/// Specifies the way host names will be resolved when conecting through a proxy.
/// </summary>
public enum HostResolutionMode
{
/// <summary>The host name is resolved by the client and the host IP is sent to the proxy.</summary>
ResolvedLocally,

/// <summary>The host name is sent to the proxy and resolved later.</summary>
ResolvedByProxy
}
}
100 changes: 98 additions & 2 deletions src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class KeyboardInteractiveConnectionInfo : ConnectionInfo, IDisposable
public KeyboardInteractiveConnectionInfo(string host, string username)
: this(host, DefaultPort, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty)
{

}

/// <summary>
Expand All @@ -42,7 +41,6 @@ public KeyboardInteractiveConnectionInfo(string host, string username)
public KeyboardInteractiveConnectionInfo(string host, int port, string username)
: this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty)
{

}

/// <summary>
Expand All @@ -59,6 +57,21 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username,
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="port">Connection port.</param>
/// <param name="username">Connection username.</param>
/// <param name="proxyType">Type of the proxy.</param>
/// <param name="proxyHost">The proxy host.</param>
/// <param name="proxyPort">The proxy port.</param>
/// <param name="hostResolutionMode">The host name resolution method when using the proxy.</param>
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, HostResolutionMode hostResolutionMode)
: this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, hostResolutionMode)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
Expand All @@ -74,6 +87,22 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username,
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="port">Connection port.</param>
/// <param name="username">Connection username.</param>
/// <param name="proxyType">Type of the proxy.</param>
/// <param name="proxyHost">The proxy host.</param>
/// <param name="proxyPort">The proxy port.</param>
/// <param name="proxyUsername">The proxy username.</param>
/// <param name="hostResolutionMode">The host name resolution method when using the proxy.</param>
public KeyboardInteractiveConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, HostResolutionMode hostResolutionMode)
: this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, hostResolutionMode)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
Expand All @@ -87,6 +116,20 @@ public KeyboardInteractiveConnectionInfo(string host, string username, ProxyType
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="username">Connection username.</param>
/// <param name="proxyType">Type of the proxy.</param>
/// <param name="proxyHost">The proxy host.</param>
/// <param name="proxyPort">The proxy port.</param>
/// <param name="hostResolutionMode">The host name resolution method when using the proxy.</param>
public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, HostResolutionMode hostResolutionMode)
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, hostResolutionMode)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
Expand All @@ -101,6 +144,21 @@ public KeyboardInteractiveConnectionInfo(string host, string username, ProxyType
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="username">Connection username.</param>
/// <param name="proxyType">Type of the proxy.</param>
/// <param name="proxyHost">The proxy host.</param>
/// <param name="proxyPort">The proxy port.</param>
/// <param name="proxyUsername">The proxy username.</param>
/// <param name="hostResolutionMode">The host name resolution method when using the proxy.</param>
public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, HostResolutionMode hostResolutionMode)
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, hostResolutionMode)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
Expand All @@ -116,6 +174,22 @@ public KeyboardInteractiveConnectionInfo(string host, string username, ProxyType
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="username">Connection username.</param>
/// <param name="proxyType">Type of the proxy.</param>
/// <param name="proxyHost">The proxy host.</param>
/// <param name="proxyPort">The proxy port.</param>
/// <param name="proxyUsername">The proxy username.</param>
/// <param name="proxyPassword">The proxy password.</param>
/// <param name="hostResolutionMode">The host name resolution method when using the proxy.</param>
public KeyboardInteractiveConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, HostResolutionMode hostResolutionMode)
: this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, hostResolutionMode)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
Expand All @@ -137,6 +211,28 @@ public KeyboardInteractiveConnectionInfo(string host, int port, string username,

}

/// <summary>
/// Initializes a new instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
/// </summary>
/// <param name="host">Connection host.</param>
/// <param name="port">Connection port.</param>
/// <param name="username">Connection username.</param>
/// <param name="proxyType">Type of the proxy.</param>
/// <param name="proxyHost">The proxy host.</param>
/// <param name="proxyPort">The proxy port.</param>
/// <param name="proxyUsername">The proxy username.</param>
/// <param name="proxyPassword">The proxy password.</param>
/// <param name="hostResolutionMode">The host name resolution method when using the proxy.</param>
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.OfType<KeyboardInteractiveAuthenticationMethod>())
{
authenticationMethod.AuthenticationPrompt += AuthenticationMethod_AuthenticationPrompt;
}

}

private void AuthenticationMethod_AuthenticationPrompt(object sender, AuthenticationPromptEventArgs e)
{
if (AuthenticationPrompt != null)
Expand Down
Loading