diff --git a/src/Renci.SshNet/AuthenticationMethod.cs b/src/Renci.SshNet/AuthenticationMethod.cs index f4afa4c2..294f5dbd 100644 --- a/src/Renci.SshNet/AuthenticationMethod.cs +++ b/src/Renci.SshNet/AuthenticationMethod.cs @@ -1,4 +1,5 @@ -using System; +using Renci.SshNet.Common; +using System; using System.Collections.Generic; namespace Renci.SshNet @@ -24,7 +25,7 @@ namespace Renci.SshNet /// /// Gets list of allowed authentications. /// - public IList AllowedAuthentications { get; protected set; } + public string[] AllowedAuthentications { get; protected set; } /// /// Initializes a new instance of the class. diff --git a/src/Renci.SshNet/ClientAuthentication.cs b/src/Renci.SshNet/ClientAuthentication.cs index 74103baf..24c462dc 100644 --- a/src/Renci.SshNet/ClientAuthentication.cs +++ b/src/Renci.SshNet/ClientAuthentication.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Renci.SshNet.Common; namespace Renci.SshNet @@ -48,10 +47,10 @@ namespace Renci.SshNet private static bool TryAuthenticate(ISession session, AuthenticationState authenticationState, - ICollection allowedAuthenticationMethods, + string[] allowedAuthenticationMethods, ref SshAuthenticationException authenticationException) { - if (allowedAuthenticationMethods.Count == 0) + if (allowedAuthenticationMethods.Length == 0) { authenticationException = new SshAuthenticationException("No authentication methods defined on SSH server."); return false; @@ -60,10 +59,10 @@ namespace Renci.SshNet // we want to try authentication methods in the order in which they were // passed in the ctor, not the order in which the SSH server returns // the allowed authentication methods - var matchingAuthenticationMethods = authenticationState.SupportedAuthenticationMethods.Where(a => allowedAuthenticationMethods.Contains(a.Name)).ToArray(); - if (matchingAuthenticationMethods.Length == 0) + var matchingAuthenticationMethods = GetAllowedAuthenticationMethodsThatAreSupported(authenticationState, allowedAuthenticationMethods); + if (matchingAuthenticationMethods.Count == 0) { - authenticationException = new SshAuthenticationException(string.Format("No suitable authentication method found to complete authentication ({0}).", string.Join(",", allowedAuthenticationMethods.ToArray()))); + authenticationException = new SshAuthenticationException(string.Format("No suitable authentication method found to complete authentication ({0}).", string.Join(",", allowedAuthenticationMethods))); return false; } @@ -108,11 +107,31 @@ namespace Renci.SshNet return false; } - private static IEnumerable GetOrderedAuthenticationMethods(AuthenticationState authenticationState, IAuthenticationMethod[] matchingAuthenticationMethods) + private static List GetAllowedAuthenticationMethodsThatAreSupported(AuthenticationState authenticationState, + string[] allowedAuthenticationMethods) + { + var result = new List(); + + foreach (var supportedAuthenticationMethod in authenticationState.SupportedAuthenticationMethods) + { + for (var i = 0; i < allowedAuthenticationMethods.Length; i++) + { + if (allowedAuthenticationMethods[i] == supportedAuthenticationMethod.Name) + { + result.Add(supportedAuthenticationMethod); + break; + } + } + } + + return result; + } + + private static IEnumerable GetOrderedAuthenticationMethods(AuthenticationState authenticationState, List matchingAuthenticationMethods) { var skippedAuthenticationMethods = new List(); - for (var i = 0; i < matchingAuthenticationMethods.Length; i++) + for (var i = 0; i < matchingAuthenticationMethods.Count; i++) { var authenticationMethod = matchingAuthenticationMethods[i]; @@ -162,7 +181,7 @@ namespace Renci.SshNet /// /// The list of supported authentication methods. /// - public IEnumerable SupportedAuthenticationMethods + public IList SupportedAuthenticationMethods { get { return _supportedAuthenticationMethods; } } diff --git a/src/Renci.SshNet/IAuthenticationMethod.cs b/src/Renci.SshNet/IAuthenticationMethod.cs index 548087e3..6f5551ec 100644 --- a/src/Renci.SshNet/IAuthenticationMethod.cs +++ b/src/Renci.SshNet/IAuthenticationMethod.cs @@ -22,7 +22,7 @@ namespace Renci.SshNet /// /// The list of allowed authentications. /// - IList AllowedAuthentications { get; } + string[] AllowedAuthentications { get; } /// /// Gets the name of the authentication method.