Subject: Re: [libssh2] meaning of -37 "Failed getting banner" / "Unable to exchange encryption keys" /

Re: [libssh2] meaning of -37 "Failed getting banner" / "Unable to exchange encryption keys" /

From: Nick Rudnick <nick.rudnick_at_googlemail.com>
Date: Sat, 28 Apr 2012 13:17:50 +0200

Hi TJ,

to be honest, I did not understand you completely, as there is no other
code left to emit a signal, neither in Haskell, nor the C code – you told
an interference can't come from other sources, didn't you?

Meanwhile, I extended libssh2 by a new function with roughly the
functionality of examples/ssh2.c libssh2_test():

LIBSSH2_API void libssh2_test(void){
  struct sockaddr_in sin;
  LIBSSH2_SESSION *session;
  const char *fingerprint;
  LIBSSH2_CHANNEL *channel;
  const unsigned long hostaddr= htonl(0x7F000001);
  const char *username= "i";
  const char *keyfile1="/home/i/.ssh/id_rsa.pub";
  const char *keyfile2="/home/i/.ssh/id_rsa";
  const char *password= "D0r1nha23";
  int got= 0;
  int sock= socket(AF_INET, SOCK_STREAM, 0);
  sin.sin_family= AF_INET;
  sin.sin_port= htons(22);
  sin.sin_addr.s_addr= hostaddr;
  if(connect( sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)
            ) != 0 ) {
    fprintf(stderr, "failed to connect!\n");
    return;
  }
  session= libssh2_session_init();
  libssh2_trace(session,~0);
  if(libssh2_session_handshake(session, sock)) {
    _libssh2_debug(session, LIBSSH2_TRACE_TRANS
                  , "Failure establishing SSH session" );
    return;
  }
  fingerprint= libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
  libssh2_userauth_list(session, username, strlen(username)); // ??
  if(libssh2_userauth_publickey_fromfile( session
                                        , username
                                        , keyfile1
                                        , keyfile2
                                        , password )) {
    _libssh2_debug(session, LIBSSH2_TRACE_TRANS
                  , "\tAuthentication by public key failed!" );
    return;
  } else {
    _libssh2_debug( session, LIBSSH2_TRACE_TRANS
                  , "\tAuthentication by public key succeeded." );
    if(!(channel= libssh2_channel_open_session(session))) {
      _libssh2_debug( session, LIBSSH2_TRACE_TRANS
                    , "Unable to open a session" );
      return;
    } else {
      libssh2_channel_setenv(channel, "FOO", "bar");
      if(libssh2_channel_request_pty(channel, "vanilla")) {
        _libssh2_debug( session, LIBSSH2_TRACE_TRANS
                      , "Failed requesting pty" );
      } else {
        if(libssh2_channel_shell(channel)) {
          _libssh2_debug( session, LIBSSH2_TRACE_TRANS
                        , "Unable to request shell on allocated pty" );
        } else {
          if(channel){
            libssh2_channel_free(channel);
            channel= NULL;
          }
        }
      }
    }
  }
  libssh2_session_disconnect( session
                            , "Normal Shutdown, Thank you for playing" );
  libssh2_session_free(session);
  close(sock);
  libssh2_exit();
  return;
}

A call to libssh2_test() runs flawless from C, while from Haskell, using
two different approaches, without any other Haskell statements, leads to
EINTR. I sent a question to a Haskell mailing list in how far, such a
signal might have its origin in the Haskell foreign function interface.

Thanks for your support, and a nice weekend, Nick

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-04-28