0

Even though I can authenticate with various methods on my servers, using the libssh library, no authentication methods are detected. Here's a sample of code:

 #include <libssh/libssh.h>
 #include <stdio.h>

 int main(int,char**)
 {
   ssh_session session = ssh_new();
   unsigned short port = 22;
   int verbosity = SSH_LOG_PROTOCOL;

   ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
   ssh_options_set(session, SSH_OPTIONS_PORT, &port);
   ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
   ssh_connect(session);

   int supported_authentication_methods = ssh_userauth_list(session, NULL);

   printf("Supported methods: %d\n", supported_authentication_methods);
   return (0);
 }

And here's the output it produces:

[2015/04/16 19:30:34.367528, 1] ssh_connect:  libssh 0.6.4 (c) 2003-2014 Aris Adamantiadis, Andreas Schneider, and libssh contributors. Distributed under the LGPL, please refer to COPYING file for information about your rights, using threading threads_noop
[2015/04/16 19:30:34.368626, 2] ssh_socket_connect:  Nonblocking connection socket: 5
[2015/04/16 19:30:34.368643, 2] ssh_connect:  Socket connecting, now waiting for the callbacks to work
[2015/04/16 19:30:34.368675, 1] socket_callback_connected:  Socket connection callback: 1 (0)
[2015/04/16 19:30:34.400420, 1] ssh_client_connection_callback:  SSH server banner: SSH-2.0-OpenSSH_6.2
[2015/04/16 19:30:34.400445, 1] ssh_analyze_banner:  Analyzing banner: SSH-2.0-OpenSSH_6.2
[2015/04/16 19:30:34.400456, 1] ssh_analyze_banner:  We are talking to an OpenSSH client version: 6.2 (60200)
[2015/04/16 19:30:34.426885, 2] ssh_packet_dh_reply:  Received SSH_KEXDH_REPLY
[2015/04/16 19:30:34.427292, 2] ssh_client_dh_reply:  SSH_MSG_NEWKEYS sent
[2015/04/16 19:30:34.427311, 2] ssh_packet_newkeys:  Received SSH_MSG_NEWKEYS
[2015/04/16 19:30:34.427908, 2] ssh_packet_newkeys:  Signature verified and valid
Supported methods: 0

As the output shows, no method of authentication are detected... and that's weird, because I can definitely log in to localhost, with passwords, with keys... what's up with that ?

user3387633
  • 121
  • 11

1 Answers1

2

Per the docs:

This requires the function ssh_userauth_none() to be called before the methods are available.

So call ssh_userauth_none() first. The server responds with the list of available options, which is how ssh_userauth_list() knows what to return.

(void)ssh_userauth_none(session, NULL);
int supported_authentication_methods = ssh_userauth_list(session, NULL);
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
  • Good god... and I *saw* it, I just didn't understand *why* it was there, decided not to use it, and spent the last 1h30 going left and right to fix this... thanks ! – user3387633 Apr 16 '15 at 17:41
  • Hm... I tried to implement this properly in my program... the thing is, the documentation seems to say that `ssh_userauth_none` should return `SSH_AUTH_SUCCESS`... the fact is, despite the fact that it *does* work, that function does not return `SSH_AUTH_SUCCESS` for me... that's tricky. – user3387633 Apr 16 '15 at 17:56
  • I don't read the docs that way at all. Unless completely anonymous access is allowed by your server, I'd expect SSH_AUTH_DENIED or SSH_AUTH_PARTIAL – Paul Roub Apr 16 '15 at 17:58
  • Oh. Alright, I didn't see it that way. Also... the `ssh_userauth_list` keeps telling me that I cannot log in using the login/password method (though it does accept public keys and other methods)... but all the servers I tried with do accept that method when I use the ssh client...any idea why that would happen ? – user3387633 Apr 16 '15 at 18:02
  • Sorry, no idea there. – Paul Roub Apr 16 '15 at 18:05