masaeedu / win-sshfs

Fork of http://code.google.com/p/win-sshfs/
BSD 3-Clause "New" or "Revised" License
26 stars 9 forks source link

Keyboard Interactive Authentication Fails #23

Open byteoctopus opened 6 years ago

byteoctopus commented 6 years ago

When attempting to connect to a server which requires keyboard interactive authentication the following error occurs:

No SSH key file selected, using password auth instead.
Please enter password:
Failed to authenticate using password, falling back to next auth mechanism if available.

Unhandled Exception: System.ArgumentNullException: String reference not set to an instance of a String.
Parameter name: s
   at Renci.SshNet.KeyboardInteractiveAuthenticationMethod.Authenticate(Session session)
   at Renci.SshNet.AuthenticationMethod.Renci.SshNet.IAuthenticationMethod.Authenticate(ISession session)
   at Renci.SshNet.ClientAuthentication.TryAuthenticate(ISession session, AuthenticationState authenticationState, String[] allowedAuthenticationMethods, SshAuthenticationException& authenticationException)
   at Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
   at Renci.SshNet.ConnectionInfo.Authenticate(ISession session, IServiceFactory serviceFactory)
   at Renci.SshNet.Session.Connect()
   at Renci.SshNet.BaseClient.Connect()
   at SSHFS.CLI.Program.AttemptConnection(String authType, ConnectionInfo connInfo, String path) in C:\projects\win-sshfs\Sshfs\SSHFS.CLI\Program.cs:line 160
   at SSHFS.CLI.Program.<>c__DisplayClass1_0.<Start>b__0(ValueTuple`2 auth) in C:\projects\win-sshfs\Sshfs\SSHFS.CLI\Program.cs:line 79
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at SSHFS.CLI.Program.Start(Options options) in C:\projects\win-sshfs\Sshfs\SSHFS.CLI\Program.cs:line 78
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at SSHFS.CLI.Program.Main(String[] args) in C:\projects\win-sshfs\Sshfs\SSHFS.CLI\Program.cs:line 70
masaeedu commented 6 years ago

Hi there. What is your command line invocation?

byteoctopus commented 6 years ago

sshfs -d z -r /home/user -h domain.xyz -u user -x

masaeedu commented 6 years ago

So you entered the password manually, and it failed? Could you try echo "yourpass" | ...?

byteoctopus commented 6 years ago

Yes, I manually entered the password.

Using echo "password" | sshfs -d z -r /home/user -h domain.xyz -u user -x results in

Failed to authenticate using password, falling back to next auth mechanism if available.
Failed to authenticate using keyboard-interactive, falling back to next auth mechanism if available.

Unhandled Exception: System.InvalidOperationException: Could not connect to server with any known authentication mechanism
   at SSHFS.CLI.Program.Start(Options options) in C:\projects\win-sshfs\Sshfs\SSHFS.CLI\Program.cs:line 83
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at SSHFS.CLI.Program.Main(String[] args) in C:\projects\win-sshfs\Sshfs\SSHFS.CLI\Program.cs:line 70
masaeedu commented 6 years ago

It seems like authentication is failing, at least for the user you're attempting to log in as. Have you tried using regular ssh to log in with the same credentials?

byteoctopus commented 6 years ago

Yes, ssh logins work via linux/putty/cygwin. The server prompts the user for a two factor authentication option (phone, mobile app, etc.) and logs in once that gets approved.

masaeedu commented 6 years ago

@byteoctopus I see. That's probably the issue; right now the "keyboard interactive" login isn't actually interactive, the tool just reads a password and tries to use it for both interactive and non-interactive password login. I'll see about using the keyboard interactive login API to allow you to make it actually interactive (so that e.g. you can wait for 2-factor) on Monday. If you want to take a crack at it, the relevant code is in:

Instead of passing in a password read from stdin, we'd need to present an interactive REPL using the AuthenticationPrompt handler.

byteoctopus commented 6 years ago

Ah that makes sense. I'll give it a try. Thanks!