Git Product home page Git Product logo

libssh2's Introduction

libssh2's People

Contributors

agebert avatar alamaison avatar bagder avatar biot avatar castaglia avatar craigberry avatar dfandrich avatar dottedmag avatar doublex avatar gitpeut avatar gknauf avatar jakob avatar jas4711 avatar kdudka avatar mback2k avatar michaelbuckley avatar monnerat avatar pipo avatar rmsh1216 avatar salva avatar sbredahl avatar tsengjun avatar ueno avatar vszakats avatar wez avatar willco007 avatar wootpthomas avatar xieepp avatar yodaldevoid avatar zenju avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libssh2's Issues

compilation fails with visual studio 2015

I get the following compile error:
3>...\src\libssh2_config.h(92): error C2375: 'snprintf': redefinition; different linkage
3> C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt\stdio.h(1932): note: see declaration of 'snprintf'
3> global.c

Seems like msvc 2015 started providing snprintf.

Clarify status of hmac-sha2-256 support

According to your website, libssh2 supports hmac-sha2-256 but this seems only to hold for the current development version, not for the latest released version.

One way to fix that would be to update the website. But it would of course be even nicer if there actually was a release supporting hmac-sha2-256. I had a look at your mailing list archive, and saw that in the past two months, there were at least two discussions on making a release, but both seem to have faded away again with no action.

As it is, libssh2 is one of the few remaining popular SSH2 implementations which does not support hmac-sha2-256 -- you can see that nicely on the comparision page I made at http://ssh-comparison.quendi.de/comparison.html

More specifically, there are seven implementations not supporting hmac-sha2-256 of these, three are based on libssh2 (in addition to libssh2 itself), and two are inactive, and one has unknown status.

fails: SFTP with 1GB files on Windows using Tectia Server

We recently having a problem with uploading a large file (around 1 GB) to Tectia Server using a libssh2 client. The file transfer is hanging, expecting few bytes which never arrives in the client side. We strongly believe this issue is due to a protocol mismatch between the client and the server. Going through the logs, we found that libsh2 client is expecting a packet type 101 and while the server is keep on sending packet type 200.

Error building against OpenSSL 1.1.0-pre1

gcc -fno-ident -O2 -DNDEBUG -DLIBSSH2_WIN32  -fno-builtin -fno-strict-aliasing -Wall  -m32 -DLIBSSH2_OPENSSL -I../win32 -I../include -I"../../openssl/include" -c ../src/hostkey.c -o release/hostkey.o
../src/hostkey.c: In function 'hostkey_method_ssh_rsa_signv':
../src/hostkey.c:206:22: error: storage size of 'ctx' isn't known
     libssh2_sha1_ctx ctx;
                      ^
../src/hostkey.c:206:22: warning: unused variable 'ctx' [-Wunused-variable]
../src/hostkey.c: In function 'hostkey_method_ssh_dss_signv':
../src/hostkey.c:425:22: error: storage size of 'ctx' isn't known
     libssh2_sha1_ctx ctx;
                      ^
../src/hostkey.c:425:22: warning: unused variable 'ctx' [-Wunused-variable]

Complete log:
https://ci.appveyor.com/project/vsz/harbour-deps/build/1.0.215#L1901

Problem with `libssh2_knownhost_check`

I've just discovered an issue with libssh2_knownhost_check.

The problem is that the typemask parameter is poorly documented.

To search for RSA or DSS keys, you need to provide either LIBSSH2_KNOWNHOST_KEY_SSHRSA or LIBSSH2_KNOWNHOST_KEY_SSHDSS. If you forget to provide one of these flags, libssh2 will compare any key types. This works if your known_hosts files contains the same key types you use, but fails if you use a different key type.

For example, many SSH servers now support elliptic curve cryptography. But libssh2 doesn't support EC. So if you connect to your server first with OpenSSH, it will put the EC host key into the known_hosts file. When you later try to connect with libssh2, it will fail, because it will compare the EC key to the RSA key, which of course fails.

Therefore it is necessary to always provide the correct typemask argument. If you forget the typemask argument, it is most likely an error.

I suggest that we change libssh2_knownhost_check to return an error when you don't provide a correct typemask parameter, as comparisons that don't take key type into account will lead to unexpected behaviour.

What do you think? If you think this is a good idea, I can volunteer to create a patch and send a pull request.

(Another note: I stumbled across this problem occurred because I provided the keytype value from libssh2_session_hostkey, which is a LIBSSH2_HOSTKEY_* constant, instead of providing a LIBSSH2_KNOWNHOST_* constant. It's confusing that there are different constants that mean similar things.)

Upload release tarball to Github

I'm still on a quest to find a way to download libssh2 sources over HTTPS.

Is it possible to upload the release tarball to Github? Github allows adding binaries to release pages. You could upload the tarball on this page: https://github.com/libssh2/libssh2/releases/tag/libssh2-1.5.0

This would allow me to download libbsh2 via HTTPS from Github.

Why is this important? I use a build script that can automatically download sources of dependencies. If that download is via HTTP, I have no automatic way to verify the sources have not been tampered with.

(Side effect: If bandwidth costs are a concern, you could point the download link on libssh2.org to Github and have them pay for bandwidth...)

Memleak in libssh2_session_init_ex and _libssh2_channel_open

hey buddy,

I am doing ssh_exec for my work so using the library. When my program is running it memory getting increased and when i am going to check the leak issue with valgrind it shows leak in the mentioned API's. I am giving a code snippet below. could you please tell me if i am doing any mistake while using API's or is this an issue.

thanks,
swapnil

include <unistd.h>

include <errno.h>

include <arpa/inet.h>

include <libssh2.h>

#include <stdlib.h>

LIBSSH2_CHANNEL channel;
LIBSSH2_SESSION *session;
void send_resp_obj(char
out_str, int status)
{
free(out_str);
libssh2_channel_send_eof(channel);
libssh2_channel_close(channel); //its blocking
libssh2_channel_free(channel);
libssh2_session_disconnect(session, "SESSION Shutdown");
libssh2_session_free(session);
return;
}
char* username = "admin";
char* password = "admin";
char commands = "man ls\r\n";
int main()
{
int ret, addrs_len, bytes_read, out_len;
struct sockaddr_in sock_addr;
char
out_str = NULL;
sock_addr.sin_family = AF_INET;
sock_addr.sin_port = htons(22);
sock_addr.sin_addr.s_addr = inet_addr("127.0.0.0");
int socket_fd;
socket_fd = socket(AF_INET, SOCK_STREAM, 0);
connect(socket_fd, (struct sockaddr_)&sock_addr, sizeof(struct sockaddr_in));
session = libssh2_session_init();
libssh2_session_handshake(session, socket_fd);
libssh2_userauth_password(session, username, password);
channel = libssh2_channel_open_session(session);
libssh2_channel_shell(channel);
libssh2_channel_set_blocking(channel, 0);
libssh2_channel_write(channel, commands, strlen(commands));
do {
if (NULL == out_str) {
out_len = 0;
out_str = (char_) malloc(4096);
if (NULL == out_str) {
send_resp_obj(out_str, 0);
}
bzero(out_str,4096);
}
errno = 0;
bytes_read = libssh2_channel_read(channel, out_str + out_len, 4095 - out_len);
if (bytes_read <= 0) {
if (LIBSSH2_ERROR_EAGAIN == bytes_read) {
continue;
} else {
send_resp_obj(out_str, -1);
return;
}
} else {
out_len += bytes_read;
if (4095 == out_len && EAGAIN == errno) {
send_resp_obj(out_str, 0);
}
}
} while( !libssh2_channel_eof(channel));
send_resp_obj(out_str, 0);
return;
}

Leveraging Security.framework on OSX

I found an old thread on this but it looks like not much came of it, so I was wondering if there are plans to not use OpenSSL on OSX and instead leverage Security.framework and other components?

Currently libssh2 doesn't compile on OSX 10.11 by default (as el capitan removed OpenSSL headers), but if Security.framework were used it should in theory work just fine!

libssh2_poll blocks forever if the remote system reboots

I know that libssh2_poll is deprecated but for some reason on my application standard poll does not work.
I found out that libssh2_poll blocks forever if the remote system reboots.
When this situation occurs, the netstat command shows that the corresponding socket is in CLOSE_WAIT. This happens because the remote system has sent a FIN but the local application has not yet closed the socket.

The reason is in the following block of code (session.c line 1671):

  case LIBSSH2_POLLFD_CHANNEL: 
                   if (sockets[i].events & POLLIN) { 
                       /* Spin session until no data available */ 
                       while (_libssh2_transport_read(fds[i].fd.channel->session) 
                              > 0); 
                   } 
                   if (sockets[i].revents & POLLHUP) { 
                       fds[i].revents |= 
                           LIBSSH2_POLLFD_CHANNEL_CLOSED | 
                           LIBSSH2_POLLFD_SESSION_CLOSED; 
                   } 
                   sockets[i].revents = 0; 
                   break; 

If the remote system has rebooted _libssh2_transport_read returns LIBSSH2_ERROR_SOCKET_RECV.
This error should not be ignored.
One possible correction could be:

    case LIBSSH2_POLLFD_CHANNEL:
                if (sockets[i].events & POLLIN) {
                   int ret;

                    /* Spin session until no data available */
                    while ( (ret = _libssh2_transport_read(fds[i].fd.channel->session))
                           > 0);                        
                    if (LIBSSH2_ERROR_SOCKET_RECV == ret)
                    {
                      /* Connection has been closed */   
                       sockets[i].revents = POLLHUP;
                    }
                }
                if (sockets[i].revents & POLLHUP) {
                    fds[i].revents |=
                        LIBSSH2_POLLFD_CHANNEL_CLOSED |
                        LIBSSH2_POLLFD_SESSION_CLOSED;
                }

Probably there are more errors that should not be ignored.

have the old canonical repo redirect here

Up until today I had my libssh2 remote pointing to git://git.libssh2.org/libssh2.git but that doesn't appear to be updated anymore. It looks as though this is now the canonical repo. I changed my remote:

git remote set-url upstream https://github.com/libssh2/libssh2.git

but I could not cleanly update without a merge commit, I think because something in master in the old repo is missing from this one. So instead I reset my master branch and now everything is ok:

git reset --hard upstream/master

My suggestion is redirect to the new location if it's possible.

Possible bug with `session->api_timeout`

Other than init/get/set operations the api_timeout member of the session structure is only ever really used in _libssh2_wait_socket.

The documentation for libssh2_session_get_timeout and libssh2_session_set_timeout describe the timeout as being milliseconds but in this part of _libssh2_wait_socket it's being compared against a number of seconds, not milliseconds.

Is this a bug, or am I missing something somewhere?

Install to non-default location not working, CMAKE_INSTALL_PREFIX is not defined

libssh2-1.6.0
Windows 10

I'm able to successfully build libssh2 on Windows but I cannot install it. docs\INSTALL_MAKE indicates:

If you are not using CMake for your own project, install libssh2

cmake
cmake --build .
cmake --build . --target install
or
cmake --build . --target INSTALL

and then specify the install location to your project in the normal
way for your build environment. If you don't like the default install
location, add -DCMAKE_INSTALL_PREFIX=<chosen prefix> when initially
configuring the project.

however, when I run:
cmake -DCMAKE_INSTALL_PREFIX="myssh2\install\location" -DZLIB_LIBRARY="my\zlib\lib\location" -DZLIB_INCLUDE_DIR="my\zlib\include\location" -DENABLE_ZLIB_COMPRESSION=ON -DCRYPTO_BACKEND=OpenSSL -DOPENSSL_ROOT_DIR="my\openssl\root"

These two work:
cmake --build .
cmake --build . --target RUN_TESTS

However "myssh2\install\location" remains empty after running this:
cmake --build . --target INSTALL

I've searched all the files in both libssh2-1.6.0.tar.gz from libssh2.org and libssh2-libssh2-1.6.0.zip from github, but CMAKE_INSTALL_PREFIX seems to only appear in docs\INSTALL_MAKE.

Compiling using openssl-1.0.2d

When I want to compile this library using openssl-1.0.2d with VS 2015, it won't compile. These are the reported errors:

Error LNK2019 unresolved external symbol __imp__CertOpenStore@20 referenced in function _capi_open_store libssh2 Error LNK2019 unresolved external symbol __imp__CertCloseStore@8 referenced in function _capi_find_key libssh2 Error LNK2019 unresolved external symbol __imp__CertEnumCertificatesInStore@8 referenced in function _capi_find_cert libssh2 Error LNK2019 unresolved external symbol __imp__CertFindCertificateInStore@24 referenced in function _capi_find_cert libssh2 Error LNK2019 unresolved external symbol __imp__CertFreeCertificateContext@4 referenced in function _capi_rsa_free libssh2 Error LNK2019 unresolved external symbol __imp__CertDuplicateCertificateContext@4 referenced in function _capi_load_ssl_client_cert libssh2 Error LNK2019 unresolved external symbol __imp__CertGetCertificateContextProperty@16 referenced in function _capi_cert_get_fname libssh2

Adding crypt32.lib to the libs list of the project, fixed the issue.

libssh2_sftp_read() with maxlen of 8192 causes memory corruption

When calling libssh2_sftp_read() with a buffer size of 4096 my application works as expected. If I do nothing other than change the buffer size to 8192 the application begins crashing due to memory corruption within libssh2. I am using a blocking socket with libssh2 set to blocking mode. Problems start occurring when libssh2 arbitrarily skips ahead within the file. Sometimes it does it with the first read and sometimes it doesn't do it until after multiple successful reads:

NOTE: Requested size is always 8192

GetBuffer() [New] About to read from requested file position 0 and actual file position 0
GetBuffer() [New] Read completed: bytes read = 2768, totalByteRead = 2768, new actual file position = 10960
GetBuffer() [New] About to read from requested file position 0 and actual file position 10960
GetBuffer() [New] Read completed: bytes read = 5424, totalByteRead = 8192, new actual file position = 16384

If you look at the log output above you can see that the libssh2 file pointer position started at 0. 8192 bytes were requested, 2768 were returned (it's always this number once problems begin), and the new file pointer after read has somehow jumped to 10960.

I compiled libssh2 and all of its dependencies as 64-bit DLL's using Visual Studio 2013. It's linking to OpenSSL 1.0.2d and zlib 1.2.8. All of my testing was done with Windows 7 x64. My sequence of actions is:

  1. I set function callbacks with OpenSSL for creating and destroying locks
  2. Initialize winsock and libssh2
  3. Create a (blocking) socket
  4. Do the ssh handshake using a private key in memory
  5. Create the sftp session and open a file. When the sftp session is created I set function pointers to a custom set of memory allocation functions that just call malloc(), realloc(), and free()
  6. Begin reading from the file. Every call to libssh2_sftp_read() is preceded by libssh2_sftp_seek64() to explicitly set the file pointer

I can't provide a callstack because the memory corruption appears to be nuking it. All I get is an access violation at msvcr120.dll!000007fedea9c3f9() Unknown. If there's any additional information I can provide please let me know.

SSH Forward Agent getting -39 on libssh2_agent_connect function.

I am trying in mobile application to agent forward same like this way in link. http://www.libssh2.org/examples/ssh2_agent.html

I am getting agent too with this
agent = libssh2_agent_init(session)

But when I go on next statement
libssh2_agent_connect(agent), I am getting here error -39 (LIBSSH2_ERROR_BAD_USE).

I am trying on Mac Osx machine, I checked in mac terminal there is agent anf identity too with that agent.

Can any one suggest me that is there any issue in code or there can be issue with agent forward settings?

Thanks

Change sizes in the API to use a libssh2_size_t

Because it's already widely deployed, libssh2 can't just switch its APIs to use size_t and ssize_t without breaking binary compatibility. However, it could define a couple of new types (like libssh2_size_t and libssh2_ssize_t) and use them instead. Whether these are defined in a binary-compatible way or defined as covers for size_t and ssize_t could be a confiruration option.

The latter would be useful to those embedding libssh2 who don't have to worry about binary compatibility, it would also allow building it with the system size_t locally just to run tests, and finally it would allow new platforms that don't yet have binary compatibility restrictions to use the proper types.

Best value for MAX_SFTP_READ_SIZE

Hi,

I have an 1,5 MB/sec bandwidth internet connection. When using libssh2 out of the box I only get 600 kb/sec download speed. However when I set MAX_SFTP_READ_SIZE to 20.000 instead of only 2000, I get about 1,4 MB/sec download speed.

Now when I set MAX_SFTP_READ_SIZE to 200.000 I get corrupted downloads (but no error codes from libssh2 whatsoever). So it seems at some point correctness is broken.

What is the highest value for MAX_SFTP_READ_SIZE that I can set without breaking correctness?

Thanks, except for the speed issue everything else works fine, also the new 1.6.0 release!

PS: curiously if I use 2.000.000 for MAX_SFTP_READ_SIZE speed is down to 700 kb / sec, but the downloaded files are not corrupted anymore!

ENGINE_load_builtin_engines => Unnecessary memory leaks?

  1. The current OpenSSL-related libssh2 initialization/teardown is very confusing. Reading all kinds of documentation distributed all over the web does not help much. What's missing is official libssh2-specific documentation on how OpenSSL is supposed to be used with libssh2_crypto_init/libssh2_crypto_exit.
    Currently using a default libssh 1.7 installation leads to memory leaks, ignoring these leaks is not acceptable since it renders the leak checker unusable for other purposes while flooding the logs with OpenSSL-related leaks. => A libssh2 user has to change libssh2-sources (libssh2_crypto_init/libssh2_crypto_exit) to fix this which requires knowledge about which OpenSSL tear-down is needed. This libssh2-implementation-specific info is currently not available (and has to inferred/guessed, which is a very brittle solution).
  2. New with libssh 1.7 openssl.h has added two new ENGINE_* initialization calls:

define libssh2_crypto_init() \

OpenSSL_add_all_algorithms();
ENGINE_load_builtin_engines();
ENGINE_register_all_complete()

=> The call "ENGINE_register_all_complete" is redundant, since ENGINE_load_builtin_engines() internally calls ENGINE_register_all_complete.

=> I think(!) ENGINE_load_builtin_engines() is also redundant. I couldn't find a single "ENGINE" use in libssh2, so why init it?

=> using ENGINE_load_builtin_engines() leads to memory leaks since no corresponding "ENGINE_cleanup()" is available. I understand this is due http://trac.libssh2.org/ticket/298
but still the very least requirement when adding new initialization calls that create memory leaks if clean-up is misssing should be that this is documented somewhere (or have I just not found the page?) so that a developer can write the cleanup code himself with confidence.

libssh2_session_init_ex needs documentation saying it may not be thread-safe

Looking through the source code, libssh2_init() is documented as not being thread-safe, which is fine. However, if libssh2_session_init_ex (and libssh2_session_init by extension) is called without libssh2_init being called, it will call libssh2_init. If you have libssh2_session_init_ex in a threaded context, it is possible to call libssh2_init in an unsafe way without realizing.

The documentation does not make it clear that a function which is not thread-safe may be called from a function that is (presumably) thread-safe.

can't seem to link to nonstandard openssl

no matter what I do, it ends up linking to the system files:
libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f83a6248000)
libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f83a5e68000)

it should be linking to the ones in
ls /UCHC/HPC/Gooch/biotoolmodules/openssl/1.0.2a/lib/
engines libcrypto.a libcrypto.so libcrypto.so.1.0.0 libssl.a libssl.so libssl.so.1.0.0 pkgconfig

what do I need to tell the configure script to accomplish this?

Autoreconf error: required file 'example/libssh2_config.h.in' not found

With commit 6d553a7:
sudo autoreconf -i -v -f
autoreconf: Entering directory .
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in ..
libtoolize: copying file ./ltmain.sh
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, m4.
libtoolize: copying file m4/libtool.m4
libtoolize: copying file m4/ltoptions.m4
libtoolize: copying file m4/ltsugar.m4
libtoolize: copying file m4/ltversion.m4
libtoolize: copying file m4/lt~obsolete.m4
autoreconf: running: /usr/bin/autoconf --force
autoreconf: running: /usr/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:54: installing ./compile
configure.ac:28: installing ./config.guess
configure.ac:28: installing ./config.sub
configure.ac:20: installing ./install-sh
configure.ac:20: installing ./missing
configure.ac:5: error: required file example/libssh2_config.h.in not found
example/Makefile.am: installing ./depcomp
parallel-tests: installing ./test-driver
autoreconf: automake failed with exit status: 1

libssh2 removes unrecognized entries in known_hosts

I use this code to add an entry to known_hosts:
https://github.com/NMSSH/NMSSH/blob/master/NMSSH/NMSSHSession.m#L710

I received a report that entries using unrecognized algorithms are getting removed:
https://gitlab.com/gnachman/iterm2/issues/4250

I confirmed this by creating a known_hosts file like this (personal data removed):

foo.bar.com ssh-rsa *redacted*
example.com ecdsa-sha2-nistp256 *redacted*

I then added a new host, and the ecdsa-sha2-nistp256 entry was removed. Entries whose algorithm field is ssh-rsa do not get clobbered.

blocking forever in libssh2_channel_read

In blocking mode, when I use libssh2_channel_read(channel, buffer, 4), the 4 bytes are read from the socket, but libssh2_channel_read doesn't return.

void startup()
{
    session = libssh2_session_init();
    if(!session)
    {
        throw ConnectionError("libssh2_session_init failed");
    }
    try
    {
        connection = openConnection(std::move(serverAddress));
    }
    catch(...)
    {
        libssh2_session_free(session);
        throw;
    }
    int error = libssh2_session_handshake(session, connection);
    if(error != 0)
    {
        libssh2_session_free(session);
        closeConnection(connection);
        throw ConnectionError("libssh2_session_handshake failed: " +
                              getLibSSH2ErrorString(error));
    }
    libssh2_trace(session, ~0);
    libssh2_trace_sethandler(session, nullptr, [](LIBSSH2_SESSION *session, void *,
                                                  const char *data, std::size_t length)
                             {
                                 std::cerr << std::string(data, length) << std::endl;
                             });
#warning finish implementing known_hosts check
    const auto userName = "codepoint-db";
    error = libssh2_userauth_publickey_frommemory(
        session, userName, std::strlen(userName), sshPublicKey, std::strlen(sshPublicKey),
        sshPrivateKey, std::strlen(sshPrivateKey), nullptr);
    if(error != 0)
    {
        libssh2_session_disconnect_ex(session, SSH_DISCONNECT_AUTH_CANCELLED_BY_USER,
                                      "database error shutdown", "");
        libssh2_session_free(session);
        closeConnection(connection);
        throw ConnectionError("libssh2_knownhost_init failed: " + getLibSSH2ErrorString(error));
    }
    channel = libssh2_channel_open_session(session);
    if(channel == nullptr)
    {
        libssh2_session_disconnect(session, "database error shutdown");
        libssh2_session_free(session);
        closeConnection(connection);
        throw ConnectionError("libssh2_channel_open_session failed");
    }
    error = libssh2_channel_exec(channel, "codepoint-db");
    if(error != 0)
    {
        libssh2_channel_free(channel);
        libssh2_session_disconnect(session, "database error shutdown");
        libssh2_session_free(session);
        closeConnection(connection);
        throw ConnectionError("libssh2_channel_exec failed: " + getLibSSH2ErrorString(error));
    }
    try
    {
        bool isFlush = false;
        readPacket(isFlush);
        if(!isFlush)
            throw ConnectionError("reading initial flush failed");
    }
    catch(...)
    {
        libssh2_channel_free(channel);
        libssh2_session_disconnect(session, "database error shutdown");
        libssh2_session_free(session);
        closeConnection(connection);
        throw;
    }
}
std::string readBytes(std::size_t maxByteCount, bool canReadLess)
{
    if(maxByteCount == 0)
        return "";
    std::string retval;
    retval.resize(maxByteCount);
    char *bufPtr = &retval[0];
    std::size_t sizeLeft = maxByteCount;
    do
    {
        auto readRetval = libssh2_channel_read(channel, bufPtr, sizeLeft);
        if(readRetval < 0)
        {
            throw ConnectionError("libssh2_channel_read failed: " +
                                  getLibSSH2ErrorString(readRetval));
        }
        sizeLeft -= readRetval;
        bufPtr += readRetval;
    } while(sizeLeft > 0 && !canReadLess);
    retval.resize(maxByteCount - sizeLeft);
    return retval;
}
std::string readPacket(bool &isFlush)
{
    auto packetHeader = readBytes(4, false);
    for(char ch : packetHeader)
    {
        if(!std::isxdigit(ch))
            throw ConnectionError("bad packet header");
    }
    std::istringstream ss(packetHeader);
    ss >> std::hex;
    std::size_t packetLength;
    ss >> packetLength;
    if(packetLength == 0)
    {
        isFlush = true;
        return "";
    }
    if(packetLength < 4)
        throw ConnectionError("bad packet header");
    isFlush = false;
    return readBytes(packetLength - 4, false);
}

trace:
...
[libssh2] 0.263924 Transport: Packet type 52 received, length=1
[libssh2] 0.263936 Transport: Looking for packet of type: 52
[libssh2] 0.263946 Userauth: Publickey authentication successful
[libssh2] 2.716543 Conn: Allocated new channel ID#0
[libssh2] 2.716580 Conn: Opening Channel - win 2097152 pack 32768
=> libssh2_transport_write plain (24 bytes)

0000: 5A 00 00 00 07 73 65 73 73 69 6F 6E 00 00 00 00 : Z....session....

0010: 00 20 00 00 00 00 80 00 : . ......

[libssh2] 2.716721 Socket: Sent 80/80 bytes at 0x879f70
=> libssh2_transport_write send() (80 bytes)

0000: DB F0 C9 30 4D 2F C4 43 0F FA 27 DB 02 B5 64 5E : ...0M/.C..'...d^

0010: 85 B4 A2 7F 39 AA 6A 38 4B DB DF E7 66 05 9A 6C : ....9.j8K...f..l

0020: 75 04 CB 44 EA 96 68 54 22 36 C6 13 69 53 8B 1C : u..D..hT"6..iS..

0030: 16 BF 56 AD 53 59 15 9C F2 D0 1A B6 1A A9 56 5F : ..V.SY........V_

0040: C4 77 D0 DB 17 A3 FC C8 90 8E 1D 5B 4E 90 4C CA : .w.........[N.L.

[libssh2] 2.716786 Transport: Looking for packet of type: 91
[libssh2] 2.716796 Transport: Looking for packet of type: 92
[libssh2] 2.717301 Socket: Recved 64/16384 bytes to 0x875f30+0
=> libssh2_transport_read() raw (64 bytes)

0000: 5B 60 65 75 27 0C F9 BA 9F FC DE 64 E1 6D 1D 8A : [`eu'......d.m..

0010: C3 0F 21 10 62 C0 51 1E 9F EF F3 E2 96 61 82 48 : ..!.b.Q......a.H

0020: 33 62 42 D6 D2 55 7D 5B 13 68 2A 05 81 5A 68 54 : 3bB..U}[.h*..ZhT

0030: 57 6D 5E 9F 76 79 3F 14 15 4C E4 10 99 C5 3D C6 : Wm^.vy?..L....=.

=> libssh2_transport_read() plain (17 bytes)

0000: 5B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 : [...............

0010: 00 : .

[libssh2] 2.717413 Transport: Packet type 91 received, length=17
[libssh2] 2.717424 Transport: Looking for packet of type: 91
[libssh2] 2.717434 Conn: Connection Established - ID: 0/0 win: 0/2097152 pack: 32768/32768
[libssh2] 3.844098 Conn: starting request(exec) on channel 0/0, message=codepoint-db
=> libssh2_transport_write plain (18 bytes)

0000: 62 00 00 00 00 00 00 00 04 65 78 65 63 01 00 00 : b........exec...

0010: 00 0C : ..

=> libssh2_transport_write plain2 (12 bytes)

0000: 63 6F 64 65 70 6F 69 6E 74 2D 64 62 : codepoint-db

[libssh2] 3.844258 Socket: Sent 80/80 bytes at 0x879f70
=> libssh2_transport_write send() (80 bytes)

0000: 96 C2 4E 9F 32 1A 41 FA 3B AA 9A D5 F7 36 8A BC : ..N.2.A.;....6..

0010: 22 7A 15 28 15 4E 25 17 8B 84 01 E1 34 85 77 D6 : "z.(.N%.....4.w.

0020: 20 65 8A EE 8F EE 12 D1 C5 69 7A 60 9F 96 C0 1D : e.......iz`....

0030: F2 14 E3 4D 98 11 B7 18 EE EA 95 65 55 AA A1 2F : ...M.......eU../

0040: 2F 25 98 B2 5B 6E CE D8 14 B2 D6 B0 B0 E4 8F 37 : /%..[n.........7

[libssh2] 3.844320 Transport: Looking for packet of type: 99
[libssh2] 3.844329 Transport: Looking for packet of type: 100
[libssh2] 3.845355 Socket: Recved 112/16384 bytes to 0x875f30+0
=> libssh2_transport_read() raw (112 bytes)

0000: 64 43 D9 E2 47 69 53 71 AD 58 7A 62 7D F9 8B E9 : dC..GiSq.Xzb}...

0010: 1A 7E 25 E7 D6 8A 8B D7 61 AF 8D 65 7C 4E 9F 7D : .~%.....a..e|N.}

0020: 9B 0E D2 D2 71 F3 F1 BE 18 31 B9 E3 74 AC 66 6F : ....q....1..t.fo

0030: 8B 20 9B 05 B0 A1 92 D9 FC 42 E7 16 81 7B D2 1D : . .......B...{..

0040: 73 B4 58 69 CE 7E E3 00 77 78 7E C0 CE 26 7A 57 : s.Xi...wx..&zW

0050: AA DC C9 77 9F 9E 83 1E 1E 81 1E 70 BF B1 0B 57 : ...w.......p...W

0060: 2A CD D6 53 A8 C0 62 A5 63 ED C2 D5 49 E0 8C 96 : *..S..b.c...I...

=> libssh2_transport_read() plain (9 bytes)

0000: 5D 00 00 00 00 00 20 00 00 : ]..... ..

[libssh2] 3.845461 Transport: Packet type 93 received, length=9
[libssh2] 3.845469 Conn: Window adjust for channel 0/0, adding 2097152 bytes, new window_size=2097152
=> libssh2_transport_read() plain (5 bytes)

0000: 63 00 00 00 00 : c....

[libssh2] 3.845498 Transport: Packet type 99 received, length=5
[libssh2] 3.845506 Transport: Looking for packet of type: 99
[libssh2] 52.163502 Conn: channel_read() wants 4 bytes from channel 0/0 stream #0
[libssh2] 109.702121 Socket: Recved 64/16384 bytes to 0x875f30+0
=> libssh2_transport_read() raw (64 bytes)

0000: AA 65 79 71 DB 76 BC 0D AD F4 CF A8 F1 99 FA 25 : .eyq.v.........%

0010: F2 E2 7C 3A 30 04 85 73 7C 2C 0D 22 C2 B6 F0 79 : ..|:0..s|,."...y

0020: 2B 1F 92 CF 73 CF 00 85 01 8F 9E 52 CF A1 F9 D1 : +...s......R....

0030: 60 86 C5 E5 A1 4D 07 B9 1C 54 28 6A A6 BB 8F A6 : `....M...T(j....

=> libssh2_transport_read() plain (13 bytes)

0000: 5E 00 00 00 00 00 00 00 04 30 30 30 30 : ^........0000

[libssh2] 193.860262 Transport: Packet type 94 received, length=13
[libssh2] 193.860309 Conn: 4 bytes packet_add() for 0/0/0
[libssh2] 193.860322 Conn: increasing read_avail by 4 bytes to 4/2097152
------------------ blocks here ---------------------------

makefile:

.PHONY: all clean distclean

SOURCES := $(wildcard src/.cpp) $(wildcard src//.cpp)
HEADERS := $(wildcard src/
.h) $(wildcard src//.h)
OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES))
PROGRAM := codepoint-v2-generator
OPENSSL := openssl-1.0.2g

all: codepoint-v2-generator

$(OPENSSL)/libcrypto.a:
tar -xzf $(OPENSSL).tar.gz
+cd $(OPENSSL) &amp;&amp; ./config no-shared no-ssl2 no-ssl3 no-comp &amp;&amp; $(MAKE) depend && $(MAKE)

$(OPENSSL)/libssl.a: $(OPENSSL)/libcrypto.a

libssh2_build/src/libssh2.a: $(OPENSSL)/libssl.a $(OPENSSL)/libcrypto.a
tar -xzf libssh2-1.7.0.tar.gz
mkdir -p libssh2_build
cd libssh2_build && cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DCRYPTO_BACKEND=OpenSSL -DOPENSSL_CRYPTO_LIBRARY=$(OPENSSL)/libcrypto.a -DOPENSSL_SSL_LIBRARY=$(OPENSSL)/libssl.a -DOPENSSL_INCLUDE_DIR=$(OPENSSL)/include -DENABLE_DEBUG_LOGGING=ON ../libssh2-1.7.0
cd libssh2_build && $(MAKE) libssh2

codepoint-v2-generator: $(OBJECTS) libssh2_build/src/libssh2.a
g++ -g -o codepoint-v2-generator $(OBJECTS) -Llibssh2_build/src -L$(OPENSSL) -lssh2 -lssl -lcrypto -ldl

%.o: %.cpp $(HEADERS)
g++ -std=c++11 -Wall -g -c -Ilibssh2-1.7.0/include -o "$(@)" "$(<)"

distclean: clean
rm -rf libssh2_build $(OPENSSL)

clean:
rm -rf codepoint-v2-generator $(OBJECTS)

NMakefile not producing static library in Windows

I am trying to compile libssh2 under Windows 10 environment with NMake. It is compiling with no issues but is only producing a DLL rather then a LIB file. I've gone through your documentation and have not seen anything regarding static libraries for Windows.

difftime in session.c

I guess the order of parameters in difftime function is wrong? It results negative value ...

if (session->api_timeout > 0 &&
(seconds_to_next == 0 ||
seconds_to_next > session->api_timeout)) {
time_t now = time (NULL);
elapsed_ms = (long)(1000*difftime(start_time, now));
if (elapsed_ms > session->api_timeout) {
session->err_code = LIBSSH2_ERROR_TIMEOUT;
return LIBSSH2_ERROR_TIMEOUT;
}
ms_to_next = (session->api_timeout - elapsed_ms);
has_timeout = 1;
}
else if (ms_to_next > 0) {
has_timeout = 1;
}
else
has_timeout = 0;

Request: Build static libs on windows using nmake

Hello, is that possible to build static libs on windows? I didn't found how to do that. I tried to compile with an option /DENABLE_STATIC, but with no luck.
Could you please add somewhere description of the compilation process under windows?

Thanks.

Docs: On SSH Windows Known hosts file

Refer My Question on SO, it seems Windows does not have a standardized path for the known host file.
I suggest you guys to put a note of suggestion of where should the file go. That will help to provide a semi-standard at least for libcurl users.

I suggest whatever Curl is using now be put forth as suggested path
Thanks!

linker error with Borland

I've got several linker errors by linking the libssh2 with the Embarcadero ( Borland/ bcc32 ) compiler.

The version 1.6.0 works fine.

The makefile was created via cmake - Borland makefiles with "CRYPTO_BACKEND" = OpenSSL.

But it seems that the the crypt32.lib is needed even though I want to use the OpenSSL crypto backend.

[Linker Error] Unresolved external 'CertGetCertificateContextProperty' referenced from C:\PROJECTS\IOPENSSL\OUT32\LIBEAY32.LIB|e_capi
[Linker Error] Unresolved external 'CertOpenStore' referenced from C:\PROJECTS\OPENSSL\OUT32\LIBEAY32.LIB|e_capi
[Linker Error] Unresolved external 'CertFindCertificateInStore' referenced from C:\PROJECTS\OPENSSL\OUT32\LIBEAY32.LIB|e_capi
[Linker Error] Unresolved external 'CertEnumCertificatesInStore' referenced from C:\PROJECTS\OPENSSL\OUT32\LIBEAY32.LIB|e_capi
[Linker Error] Unresolved external 'CertDuplicateCertificateContext' referenced from C:\PROJECTS\OPENSSL\OUT32\LIBEAY32.LIB|e_capi
[Linker Error] Unresolved external 'CertFreeCertificateContext' referenced from C:\PROJECTS\OPENSSL\OUT32\LIBEAY32.LIB|e_capi
[Linker Error] Unresolved external 'CertCloseStore' referenced from C:\PROJECTS\OPENSSL\OUT32\LIBEAY32.LIB|e_capi

Get rid of warnings in 64-bit

Hi,

it would be great if I could compile libssh2 without warnings on 64-bit:

  1. Currently I see lots of:
    warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data

Which is caused by the macros using "strlen" returning size_t but the _ex functions taking "unsigned int", e.g.

define libssh2_sftp_rmdir(sftp, path) \

libssh2_sftp_rmdir_ex((sftp), (path), strlen(path))

libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path,
unsigned int path_len)

In general it seems that the "unsigned int" should be replaced by size_t since this is also what std::string::length() returns.

  1. Here's another warning that's more serious, although we still have 23 years to go:
    warning C4244: '=' : conversion from 'int64_t' to 'unsigned long', possible loss of data

    std::int64_t mTime = ...;
    LIBSSH2_SFTP_ATTRIBUTES attribNew = {};
    attribNew.mtime = mTime; //32-bit target! loss of data!
    
  2. There are more warnings in the implementation files that are shown when compiling libssh2 with Visual Studio 2013 in 64 bit.

Compiling with VS 2015

When I want to compile this solution with Visual Studio 2015, it reports this error:

Error C1189 #error: Macro definition of snprintf conflicts with Standard Library function declaration libssh2 c:\program files (x86)\windows kits\10\include\10.0.10150.0\ucrt\stdio.h 1927

Removing this line in libssh2_config.h file, fixed the issue:
#defineย snprintfย _snprintf

_MSC_VER here is 1900.

Crash at libssh2!channel_send_eof

I am developing an application using libssh2 1.4.3 on Windows.
The application works fine on most of the Windows environment but it started crashing on some Windows 2012 Server R2 systems. From the crash dump I found following stack trace.

025dac44 76ee05bf 025dac5c 025dacac 025dac5c ntdll!ZwWow64CallFunction64+0x1fd3
025dafe4 003953a4 00000000 025db000 00000005 ntdll!KiUserExceptionDispatcher+0xf
025db014 00395619 0219e7f8 025db02c 00000000 libssh2!channel_send_eof+0x64 [c:\libssh2-1.4.3\src\channel.c @ 2129]
025db02c 003957dc 0219e7f8 56e6ebdc 00000000 libssh2!_libssh2_channel_close+0x49 [c:\libssh2-1.4.3\src\channel.c @ 2264]
025db048 00aeee35 0219e7f8 716fbc81 01b243d0 libssh2!libssh2_channel_close+0x2c [c:\libssh2-1.4.3\src\channel.c @ 2335]

Any suggestion will be helpful.

~Manoj

Maximize SFTP performance

Hi,

I'm trying to optimize read/write performance for large file transfers and found a few issues:

  1. The documentation for libssh2_sftp_write (http://www.libssh2.org/libssh2_sftp_write.html) recommends to "try to always pass in at least 32K of data". However when inpecting the source it seems packages are sent out in sizes of MAX_SFTP_OUTGOING_SIZE(30000). So if one would pass a buffer of 32K to libssh2_sftp_write this would create two packages, one 30K and one only 2K, thereby not effectively using the bandwidth in the second case, correct? I made a few tests and using a 60000 bytes buffer gave a 20% speedup compared to 65536 for me. So it seems the recommendation should be "use a multiple of MAX_SFTP_OUTGOING_SIZE for buffer size", right?
  2. https://www.libssh2.org/libssh2_sftp_read.html currently doesn't give any hint about buffer size, but similarly it seems it should be a multiple of MAX_SFTP_READ_SIZE.
  3. According to 1 and 2, the next thing that is needed for an libssh2 user is to get at the values MAX_SFTP_READ_SIZE and MAX_SFTP_OUTGOING_SIZE which are not exposed via libssh2_sftp.h.
    => put them into libssh2_sftp.h instead of src/sftp.h?
    => or alternatively expose them via two functions in libssh2_sftp.h, e.g.
    size_t get_sftp_read_packet_size();
    size_t get_sftp_write_packet_size();
  4. libssh2_sftp_read internally uses a prefetch buffer of "buffer_size*4", while at the same time sending out packages of size MAX_SFTP_READ_SIZE. What is the benefit of doing this internally compared to the API user just passing in 4 times the buffer size? If there is no advantage this magic number should be removed so that the API user can decide for himself how many packages he wants to send out (= buffer size / MAX_SFTP_READ_SIZE) without having to worry that the number will be increased internally. This would mirror the behavior of libssh2_sftp_write which sends "buffer size / MAX_SFTP_OUTGOING_SIZE" number of packets.
  5. Is there other official documentation about maximizing perf with libssh2?

Best regards, Zenju

Add support for ECDH key exchange

ECDH key exchange is faster than regular Diffie-Hellman with equivalent levels of security. It's been supported for some time in OpenSSH. It also uses longer session hashes, resulting in harder-to-guess key material. It would be nice if libssh2 supported this as well.

The NIST curves can probably be trivially implemented with OpenSSL and libgcrypt, but using [email protected] would probably require custom code in libssh2.

aes ctr supported or not?

The list of supported ciphers on http://www.libssh2.org/ does not list aes256-ctr, aes128-ctr, aes192-ctr. But they do seem to be present in the source code, and a quick test seems to indicate they work.

So, is this just an omission on the website?

SSH_MSG_DISCONNECT causes infinite loop in channel_wait_eof

when the server sends a SSH_MSG_DISCONNECT the _libssh2_packet_add() function sets session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; (packet.c:504). The channel_wait_eof() function has a while loop that calls _libssh2_transport_read() that returns LIBSSH2_ERROR_NONE (transport.c:329). The loop (channel.c:2255-2268) has no '0' handler so loops forever.

Changing transport.c:~330 from:
if (session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) {
return LIBSSH2_ERROR_NONE;
}
to:
if (session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) {
return LIBSSH2_ERROR_SOCKET_DISCONNECT;
}
seems a simple fix.

I went farther in my local code and changed the loop in the channel_wait_eof() (6 lines marked with //new) which cleaned up some error returns but I'm not sure it's the best way or place to handle it:

do {
    if (channel->remote.eof) {
        break;
    }
    rc = _libssh2_transport_read(session);
    if (rc == LIBSSH2_ERROR_EAGAIN) {
        return rc;
    }
    else if (rc < 0) {
        channel->wait_eof_state = libssh2_NB_state_idle;
        if (rc == LIBSSH2_ERROR_SOCKET_DISCONNECT) { //new
          // when we're disconnected we can't do much, set some flags and return 'ok' //new
          channel->remote.eof = 1; //new
          channel->remote.close = 1; //new
          return 0; //new
        }//new
        return _libssh2_error(session, rc,
                              "_libssh2_transport_read() bailed out!");
    }
} while (1);

Memory leaks in wincng.c, kex.c, session.c

Hi,

I've found the following memory leaks originating from the cryptography code:

  1. file wincng.c, function _libssh2_wincng_cipher_init() allocates variable "ctx->pbIV":
    if (type.dwUseIV) {
        pbIV = malloc(dwBlockLength);
        if (!pbIV) {
            BCryptDestroyKey(hKey);
            free(pbKeyObject);
            return -1;
        }
        dwIV = dwBlockLength;
        memcpy(pbIV, iv, dwIV);
    } else {
        pbIV = NULL;
        dwIV = 0;
    }

But there is no corresponding clean up in function _libssh2_wincng_cipher_dtor()

  1. In file kex.c an md5 checksum is generated as follows:
#if LIBSSH2_MD5
        {
            libssh2_md5_ctx fingerprint_ctx;

            if (libssh2_md5_init(&fingerprint_ctx)) {
                libssh2_md5_update(fingerprint_ctx, session->server_hostkey,
                                   session->server_hostkey_len);
                libssh2_md5_final(fingerprint_ctx, session->server_hostkey_md5);
                session->server_hostkey_md5_valid = TRUE;
            }
            else {
                session->server_hostkey_md5_valid = FALSE;
            }
        }

The check "if (libssh2_md5_init(&fingerprint_ctx))" seems to be incorrect and should probably be "if (libssh2_md5_init(&fingerprint_ctx) == 0)"

What happens is that "_libssh2_wincng_hash_init" internally allocs memory, which is never freed:

    pbHashObject = malloc(dwHashObject);
    if (!pbHashObject) {
        return -1;
    }
  1. wincng.c, function _libssh2_wincng_hash.
    Leak if _libssh2_wincng_hash_update fails:
int
_libssh2_wincng_hash(unsigned char *data, unsigned long datalen,
                     BCRYPT_ALG_HANDLE hAlg,
                     unsigned char *hash, unsigned long hashlen)
{
    _libssh2_wincng_hash_ctx ctx;

    if (!_libssh2_wincng_hash_init(&ctx, hAlg, hashlen, NULL, 0)) {
        if (!_libssh2_wincng_hash_update(&ctx, data, datalen)) {
            if (!_libssh2_wincng_hash_final(&ctx, hash)) {
                return 0;
            }
        }
    }

    return -1;
}
  1. file session.c, function session_free

This function cleans up cryptography only in case of LIBSSH2_STATE_NEWKEYS, but this is insufficient:

    if (session->state & LIBSSH2_STATE_NEWKEYS) {
        /* hostkey */
        if (session->hostkey && session->hostkey->dtor) {
            session->hostkey->dtor(session, &session->server_hostkey_abstract);
        }

It's possible that "session->state == 0", and but "session->hostkey->init" was run so that _libssh2_wincng_rsa_new internally allocated resources. Thous a "session->hostkey->dtor" is needed, but due to "if (session->state & LIBSSH2_STATE_NEWKEYS)" never called, therefore leaking memory.

How can "session->state == 0" while "session->hostkey->init" was run?
When libssh2_session_handshake() calls _libssh2_kex_exchange, which calls diffie_hellman_sha1, which runs

        if (session->hostkey->init(session, session->server_hostkey,
                                   session->server_hostkey_len,
                                   &session->server_hostkey_abstract)) {
            ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT,
                                 "Unable to initialize hostkey importer");
            goto clean_exit;
        }

if any of the subsequent failure conditions occur, e.g.

        exchange_state->k_value =
            LIBSSH2_ALLOC(session, exchange_state->k_value_len);
        if (!exchange_state->k_value) {
            ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
                                 "Unable to allocate buffer for K");
            goto clean_exit;
        }

then memory is leaked. There are probably more circumstances where this leak occurs, so it seems as if the session_free() function is to blame for not cleaning up thorougly.

PS: all these leaks occur in my libssh2 use, none of them is only theoretical.

Regards, Zenju

fail connected, error LIBSSH2_ERROR_SOCKET_RECV

libssh2-1.6.0
fail connected to the Extreme Networks network switches equipment
Putty is connected successful

----- debug -----

[libssh2] 0.545758 Transport: session_startup for socket 668
[libssh2] 0.853758 Transport: Sending Banner: SSH-2.0-libssh2_1.6.0
[libssh2] 0.865758 Socket: Sent 23/23 bytes at 6eb3c729+0
[libssh2] 0.874758 Socket: Recved 1 bytes banner
........
[libssh2] 1.254758 Socket: Recved 1 bytes banner
[libssh2] 1.264758 Transport: Received Banner: SSH-2.0-4.1.2 SSH Secure Shell Toolkit
[libssh2] 1.890758 Key Ex: Sent KEX: diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
[libssh2] 1.900758 Key Ex: Sent HOSTKEY: ssh-rsa,ssh-dss
[libssh2] 1.909758 Key Ex: Sent CRYPT_CS: aes128-ctr,aes192-ctr,aes256-ctr,aes256-cbc,[email protected],aes192-cbc,aes128-cbc,blowfish-cbc,arcfour128,arcfour,cast128-cbc,3des-cbc
[libssh2] 1.918758 Key Ex: Sent CRYPT_SC: aes128-ctr,aes192-ctr,aes256-ctr,aes256-cbc,[email protected],aes192-cbc,aes128-cbc,blowfish-cbc,arcfour128,arcfour,cast128-cbc,3des-cbc
[libssh2] 1.927758 Key Ex: Sent MAC_CS: hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96,hmac-ripemd160,[email protected]
[libssh2] 1.936758 Key Ex: Sent MAC_SC: hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96,hmac-ripemd160,[email protected]
[libssh2] 1.945758 Key Ex: Sent COMP_CS: none
[libssh2] 1.954758 Key Ex: Sent COMP_SC: none
[libssh2] 1.964758 Key Ex: Sent LANG_CS: 
[libssh2] 1.973758 Key Ex: Sent LANG_SC: => libssh2_transport_write plain (636 bytes)
0000: 14 9D 98 DB 65 67 66 4C  E2 56 29 FC 6F 69 9B 5E : ....egfL.V).oi.^
0010: 21 00 00 00 59 64 69 66  66 69 65 2D 68 65 6C 6C : !...Ydiffie-hell
0020: 6D 61 6E 2D 67 72 6F 75  70 31 34 2D 73 68 61 31 : man-group14-sha1
0030: 2C 64 69 66 66 69 65 2D  68 65 6C 6C 6D 61 6E 2D : ,diffie-hellman-
0040: 67 72 6F 75 70 2D 65 78  63 68 61 6E 67 65 2D 73 : group-exchange-s
0050: 68 61 31 2C 64 69 66 66  69 65 2D 68 65 6C 6C 6D : ha1,diffie-hellm
0060: 61 6E 2D 67 72 6F 75 70  31 2D 73 68 61 31 00 00 : an-group1-sha1..
0070: 00 0F 73 73 68 2D 72 73  61 2C 73 73 68 2D 64 73 : ..ssh-rsa,ssh-ds
0080: 73 00 00 00 92 61 65 73  31 32 38 2D 63 74 72 2C : s....aes128-ctr,
0090: 61 65 73 31 39 32 2D 63  74 72 2C 61 65 73 32 35 : aes192-ctr,aes25
00a0: 36 2D 63 74 72 2C 61 65  73 32 35 36 2D 63 62 63 : 6-ctr,aes256-cbc
00b0: 2C 72 69 6A 6E 64 61 65  6C 2D 63 62 63 40 6C 79 : ,rijndael-cbc@ly
00c0: 73 61 74 6F 72 2E 6C 69  75 2E 73 65 2C 61 65 73 : sator.liu.se,aes
00d0: 31 39 32 2D 63 62 63 2C  61 65 73 31 32 38 2D 63 : 192-cbc,aes128-c
00e0: 62 63 2C 62 6C 6F 77 66  69 73 68 2D 63 62 63 2C : bc,blowfish-cbc,
00f0: 61 72 63 66 6F 75 72 31  32 38 2C 61 72 63 66 6F : arcfour128,arcfo
0100: 75 72 2C 63 61 73 74 31  32 38 2D 63 62 63 2C 33 : ur,cast128-cbc,3
0110: 64 65 73 2D 63 62 63 00  00 00 92 61 65 73 31 32 : des-cbc....aes12
0120: 38 2D 63 74 72 2C 61 65  73 31 39 32 2D 63 74 72 : 8-ctr,aes192-ctr
0130: 2C 61 65 73 32 35 36 2D  63 74 72 2C 61 65 73 32 : ,aes256-ctr,aes2
0140: 35 36 2D 63 62 63 2C 72  69 6A 6E 64 61 65 6C 2D : 56-cbc,rijndael-
0150: 63 62 63 40 6C 79 73 61  74 6F 72 2E 6C 69 75 2E : [email protected].
0160: 73 65 2C 61 65 73 31 39  32 2D 63 62 63 2C 61 65 : se,aes192-cbc,ae
0170: 73 31 32 38 2D 63 62 63  2C 62 6C 6F 77 66 69 73 : s128-cbc,blowfis
0180: 68 2D 63 62 63 2C 61 72  63 66 6F 75 72 31 32 38 : h-cbc,arcfour128
0190: 2C 61 72 63 66 6F 75 72  2C 63 61 73 74 31 32 38 : ,arcfour,cast128
01a0: 2D 63 62 63 2C 33 64 65  73 2D 63 62 63 00 00 00 : -cbc,3des-cbc...
01b0: 55 68 6D 61 63 2D 73 68  61 31 2C 68 6D 61 63 2D : Uhmac-sha1,hmac-
01c0: 73 68 61 31 2D 39 36 2C  68 6D 61 63 2D 6D 64 35 : sha1-96,hmac-md5
01d0: 2C 68 6D 61 63 2D 6D 64  35 2D 39 36 2C 68 6D 61 : ,hmac-md5-96,hma
01e0: 63 2D 72 69 70 65 6D 64  31 36 30 2C 68 6D 61 63 : c-ripemd160,hmac
01f0: 2D 72 69 70 65 6D 64 31  36 30 40 6F 70 65 6E 73 : -ripemd160@opens
0200: 73 68 2E 63 6F 6D 00 00  00 55 68 6D 61 63 2D 73 : sh.com...Uhmac-s
0210: 68 61 31 2C 68 6D 61 63  2D 73 68 61 31 2D 39 36 : ha1,hmac-sha1-96
0220: 2C 68 6D 61 63 2D 6D 64  35 2C 68 6D 61 63 2D 6D : ,hmac-md5,hmac-m
0230: 64 35 2D 39 36 2C 68 6D  61 63 2D 72 69 70 65 6D : d5-96,hmac-ripem
0240: 64 31 36 30 2C 68 6D 61  63 2D 72 69 70 65 6D 64 : d160,hmac-ripemd
0250: 31 36 30 40 6F 70 65 6E  73 73 68 2E 63 6F 6D 00 : [email protected].
0260: 00 00 04 6E 6F 6E 65 00  00 00 04 6E 6F 6E 65 00 : ...none....none.
0270: 00 00 00 00 00 00 00 00  00 00 00 00             : ............

[libssh2] 2.394758 Socket: Sent 648/648 bytes at 03e841a8=> libssh2_transport_write send() (648 bytes)
0000: 00 00 02 84 07 14 9D 98  DB 65 67 66 4C E2 56 29 : .........egfL.V)
0010: FC 6F 69 9B 5E 21 00 00  00 59 64 69 66 66 69 65 : .oi.^!...Ydiffie
0020: 2D 68 65 6C 6C 6D 61 6E  2D 67 72 6F 75 70 31 34 : -hellman-group14
0030: 2D 73 68 61 31 2C 64 69  66 66 69 65 2D 68 65 6C : -sha1,diffie-hel
0040: 6C 6D 61 6E 2D 67 72 6F  75 70 2D 65 78 63 68 61 : lman-group-excha
0050: 6E 67 65 2D 73 68 61 31  2C 64 69 66 66 69 65 2D : nge-sha1,diffie-
0060: 68 65 6C 6C 6D 61 6E 2D  67 72 6F 75 70 31 2D 73 : hellman-group1-s
0070: 68 61 31 00 00 00 0F 73  73 68 2D 72 73 61 2C 73 : ha1....ssh-rsa,s
0080: 73 68 2D 64 73 73 00 00  00 92 61 65 73 31 32 38 : sh-dss....aes128
0090: 2D 63 74 72 2C 61 65 73  31 39 32 2D 63 74 72 2C : -ctr,aes192-ctr,
00a0: 61 65 73 32 35 36 2D 63  74 72 2C 61 65 73 32 35 : aes256-ctr,aes25
00b0: 36 2D 63 62 63 2C 72 69  6A 6E 64 61 65 6C 2D 63 : 6-cbc,rijndael-c
00c0: 62 63 40 6C 79 73 61 74  6F 72 2E 6C 69 75 2E 73 : [email protected]
00d0: 65 2C 61 65 73 31 39 32  2D 63 62 63 2C 61 65 73 : e,aes192-cbc,aes
00e0: 31 32 38 2D 63 62 63 2C  62 6C 6F 77 66 69 73 68 : 128-cbc,blowfish
00f0: 2D 63 62 63 2C 61 72 63  66 6F 75 72 31 32 38 2C : -cbc,arcfour128,
0100: 61 72 63 66 6F 75 72 2C  63 61 73 74 31 32 38 2D : arcfour,cast128-
0110: 63 62 63 2C 33 64 65 73  2D 63 62 63 00 00 00 92 : cbc,3des-cbc....
0120: 61 65 73 31 32 38 2D 63  74 72 2C 61 65 73 31 39 : aes128-ctr,aes19
0130: 32 2D 63 74 72 2C 61 65  73 32 35 36 2D 63 74 72 : 2-ctr,aes256-ctr
0140: 2C 61 65 73 32 35 36 2D  63 62 63 2C 72 69 6A 6E : ,aes256-cbc,rijn
0150: 64 61 65 6C 2D 63 62 63  40 6C 79 73 61 74 6F 72 : dael-cbc@lysator
0160: 2E 6C 69 75 2E 73 65 2C  61 65 73 31 39 32 2D 63 : .liu.se,aes192-c
0170: 62 63 2C 61 65 73 31 32  38 2D 63 62 63 2C 62 6C : bc,aes128-cbc,bl
0180: 6F 77 66 69 73 68 2D 63  62 63 2C 61 72 63 66 6F : owfish-cbc,arcfo
0190: 75 72 31 32 38 2C 61 72  63 66 6F 75 72 2C 63 61 : ur128,arcfour,ca
01a0: 73 74 31 32 38 2D 63 62  63 2C 33 64 65 73 2D 63 : st128-cbc,3des-c
01b0: 62 63 00 00 00 55 68 6D  61 63 2D 73 68 61 31 2C : bc...Uhmac-sha1,
01c0: 68 6D 61 63 2D 73 68 61  31 2D 39 36 2C 68 6D 61 : hmac-sha1-96,hma
01d0: 63 2D 6D 64 35 2C 68 6D  61 63 2D 6D 64 35 2D 39 : c-md5,hmac-md5-9
01e0: 36 2C 68 6D 61 63 2D 72  69 70 65 6D 64 31 36 30 : 6,hmac-ripemd160
01f0: 2C 68 6D 61 63 2D 72 69  70 65 6D 64 31 36 30 40 : ,hmac-ripemd160@
0200: 6F 70 65 6E 73 73 68 2E  63 6F 6D 00 00 00 55 68 : openssh.com...Uh
0210: 6D 61 63 2D 73 68 61 31  2C 68 6D 61 63 2D 73 68 : mac-sha1,hmac-sh
0220: 61 31 2D 39 36 2C 68 6D  61 63 2D 6D 64 35 2C 68 : a1-96,hmac-md5,h
0230: 6D 61 63 2D 6D 64 35 2D  39 36 2C 68 6D 61 63 2D : mac-md5-96,hmac-
0240: 72 69 70 65 6D 64 31 36  30 2C 68 6D 61 63 2D 72 : ripemd160,hmac-r
0250: 69 70 65 6D 64 31 36 30  40 6F 70 65 6E 73 73 68 : ipemd160@openssh
0260: 2E 63 6F 6D 00 00 00 04  6E 6F 6E 65 00 00 00 04 : .com....none....
0270: 6E 6F 6E 65 00 00 00 00  00 00 00 00 00 00 00 00 : none............
0280: 00 21 3A 8C F1 05 29 59                          : .!:...)Y

[libssh2] 2.817758 Transport: Looking for packet of type: 20
[libssh2] 2.826758 Socket: Recved 424/16384 bytes to 03e80180+0=> libssh2_transport_read() raw (424 bytes)
0000: 00 00 01 A4 08 14 81 8E  64 F9 56 D1 AE AB 7D 25 : ........d.V...}%
0010: 99 2E D5 A5 53 34 00 00  00 1A 64 69 66 66 69 65 : ....S4....diffie
0020: 2D 68 65 6C 6C 6D 61 6E  2D 67 72 6F 75 70 31 2D : -hellman-group1-
0030: 73 68 61 31 00 00 00 07  73 73 68 2D 64 73 73 00 : sha1....ssh-dss.
0040: 00 00 6F 61 65 73 32 35  36 2D 63 62 63 2C 61 65 : ..oaes256-cbc,ae
0050: 73 31 39 32 2D 63 62 63  2C 61 65 73 31 32 38 2D : s192-cbc,aes128-
0060: 63 62 63 2C 74 77 6F 66  69 73 68 32 35 36 2D 63 : cbc,twofish256-c
0070: 62 63 2C 74 77 6F 66 69  73 68 2D 63 62 63 2C 74 : bc,twofish-cbc,t
0080: 77 6F 66 69 73 68 31 39  32 2D 63 62 63 2C 74 77 : wofish192-cbc,tw
0090: 6F 66 69 73 68 31 32 38  2D 63 62 63 2C 62 6C 6F : ofish128-cbc,blo
00a0: 77 66 69 73 68 2D 63 62  63 2C 33 64 65 73 2D 63 : wfish-cbc,3des-c
00b0: 62 63 00 00 00 6F 61 65  73 32 35 36 2D 63 62 63 : bc...oaes256-cbc
00c0: 2C 61 65 73 31 39 32 2D  63 62 63 2C 61 65 73 31 : ,aes192-cbc,aes1
00d0: 32 38 2D 63 62 63 2C 74  77 6F 66 69 73 68 32 35 : 28-cbc,twofish25
00e0: 36 2D 63 62 63 2C 74 77  6F 66 69 73 68 2D 63 62 : 6-cbc,twofish-cb
00f0: 63 2C 74 77 6F 66 69 73  68 31 39 32 2D 63 62 63 : c,twofish192-cbc
0100: 2C 74 77 6F 66 69 73 68  31 32 38 2D 63 62 63 2C : ,twofish128-cbc,
0110: 62 6C 6F 77 66 69 73 68  2D 63 62 63 2C 33 64 65 : blowfish-cbc,3de
0120: 73 2D 63 62 63 00 00 00  2B 68 6D 61 63 2D 73 68 : s-cbc...+hmac-sh
0130: 61 31 2C 68 6D 61 63 2D  6D 64 35 2C 68 6D 61 63 : a1,hmac-md5,hmac
0140: 2D 73 68 61 31 2D 39 36  2C 68 6D 61 63 2D 6D 64 : -sha1-96,hmac-md
0150: 35 2D 39 36 00 00 00 2B  68 6D 61 63 2D 73 68 61 : 5-96...+hmac-sha
0160: 31 2C 68 6D 61 63 2D 6D  64 35 2C 68 6D 61 63 2D : 1,hmac-md5,hmac-
0170: 73 68 61 31 2D 39 36 2C  68 6D 61 63 2D 6D 64 35 : sha1-96,hmac-md5
0180: 2D 39 36 00 00 00 04 6E  6F 6E 65 00 00 00 04 6E : -96....none....n
0190: 6F 6E 65 00 00 00 00 00  00 00 00 00 00 00 00 00 : one.............
01a0: 9D 78 91 2F 14 4E 14 D7                          : .x./.N..
=> libssh2_transport_read() plain (411 bytes)
0000: 14 81 8E 64 F9 56 D1 AE  AB 7D 25 99 2E D5 A5 53 : ...d.V...}%....S
0010: 34 00 00 00 1A 64 69 66  66 69 65 2D 68 65 6C 6C : 4....diffie-hell
0020: 6D 61 6E 2D 67 72 6F 75  70 31 2D 73 68 61 31 00 : man-group1-sha1.
0030: 00 00 07 73 73 68 2D 64  73 73 00 00 00 6F 61 65 : ...ssh-dss...oae
0040: 73 32 35 36 2D 63 62 63  2C 61 65 73 31 39 32 2D : s256-cbc,aes192-
0050: 63 62 63 2C 61 65 73 31  32 38 2D 63 62 63 2C 74 : cbc,aes128-cbc,t
0060: 77 6F 66 69 73 68 32 35  36 2D 63 62 63 2C 74 77 : wofish256-cbc,tw
0070: 6F 66 69 73 68 2D 63 62  63 2C 74 77 6F 66 69 73 : ofish-cbc,twofis
0080: 68 31 39 32 2D 63 62 63  2C 74 77 6F 66 69 73 68 : h192-cbc,twofish
0090: 31 32 38 2D 63 62 63 2C  62 6C 6F 77 66 69 73 68 : 128-cbc,blowfish
00a0: 2D 63 62 63 2C 33 64 65  73 2D 63 62 63 00 00 00 : -cbc,3des-cbc...
00b0: 6F 61 65 73 32 35 36 2D  63 62 63 2C 61 65 73 31 : oaes256-cbc,aes1
00c0: 39 32 2D 63 62 63 2C 61  65 73 31 32 38 2D 63 62 : 92-cbc,aes128-cb
00d0: 63 2C 74 77 6F 66 69 73  68 32 35 36 2D 63 62 63 : c,twofish256-cbc
00e0: 2C 74 77 6F 66 69 73 68  2D 63 62 63 2C 74 77 6F : ,twofish-cbc,two
00f0: 66 69 73 68 31 39 32 2D  63 62 63 2C 74 77 6F 66 : fish192-cbc,twof
0100: 69 73 68 31 32 38 2D 63  62 63 2C 62 6C 6F 77 66 : ish128-cbc,blowf
0110: 69 73 68 2D 63 62 63 2C  33 64 65 73 2D 63 62 63 : ish-cbc,3des-cbc
0120: 00 00 00 2B 68 6D 61 63  2D 73 68 61 31 2C 68 6D : ...+hmac-sha1,hm
0130: 61 63 2D 6D 64 35 2C 68  6D 61 63 2D 73 68 61 31 : ac-md5,hmac-sha1
0140: 2D 39 36 2C 68 6D 61 63  2D 6D 64 35 2D 39 36 00 : -96,hmac-md5-96.
0150: 00 00 2B 68 6D 61 63 2D  73 68 61 31 2C 68 6D 61 : ..+hmac-sha1,hma
0160: 63 2D 6D 64 35 2C 68 6D  61 63 2D 73 68 61 31 2D : c-md5,hmac-sha1-
0170: 39 36 2C 68 6D 61 63 2D  6D 64 35 2D 39 36 00 00 : 96,hmac-md5-96..
0180: 00 04 6E 6F 6E 65 00 00  00 04 6E 6F 6E 65 00 00 : ..none....none..
0190: 00 00 00 00 00 00 00 00  00 00 00                : ...........

[libssh2] 3.382758 Transport: Packet type 20 received, length=411
[libssh2] 3.391758 Transport: Looking for packet of type: 20
[libssh2] 3.401758 Key Ex: Agreed on KEX method: diffie-hellman-group1-sha1
[libssh2] 3.411758 Key Ex: Agreed on HOSTKEY method: ssh-dss
[libssh2] 3.420758 Key Ex: Agreed on CRYPT_CS method: aes256-cbc
[libssh2] 3.430758 Key Ex: Agreed on CRYPT_SC method: aes256-cbc
[libssh2] 3.441758 Key Ex: Agreed on MAC_CS method: hmac-sha1
[libssh2] 3.458758 Key Ex: Agreed on MAC_SC method: hmac-sha1
[libssh2] 3.468758 Key Ex: Agreed on COMP_CS method: none
[libssh2] 3.478758 Key Ex: Agreed on COMP_SC method: none
[libssh2] 3.487758 Key Ex: Initiating Diffie-Hellman Group1 Key Exchange
[libssh2] 3.498758 Key Ex: Sending KEX packet 30=> libssh2_transport_write plain (134 bytes)
0000: 1E 00 00 00 81 00 F1 0A  F2 58 B4 3C 6B 90 65 DB : .........X.<k.e.
0010: 08 F9 EF BB 83 F5 65 5E  E4 AC 4D 74 BB A3 9D 98 : ......e^..Mt....
0020: 90 C0 08 B7 1F C6 94 2B  58 F3 CB FA 61 C0 D9 E0 : .......+X...a...
0030: CC A8 09 34 62 57 2D C7  AB CE A6 4E 66 3B D0 E8 : ...4bW-....Nf;..
0040: CC BD 55 26 71 C2 FE F3  7D 96 5F 3B 45 84 D3 E2 : ..U&q...}._;E...
0050: D6 17 E6 8A A4 D8 E3 26  43 08 0C 87 FD B4 8C A7 : .......&C.......
0060: A3 62 A6 AD 63 58 D1 5C  B2 D5 10 FB CA D2 9F 26 : .b..cX.\.......&
0070: 2C EF 9E 90 70 0E BB 87  D7 C2 AD 6A DD A6 90 FA : ,...p......j....
0080: B4 C0 81 87 57 A4                                : ....W.

[libssh2] 3.605758 Socket: Sent 144/144 bytes at 03e841a8=> libssh2_transport_write send() (144 bytes)
0000: 00 00 00 8C 05 1E 00 00  00 81 00 F1 0A F2 58 B4 : ..............X.
0010: 3C 6B 90 65 DB 08 F9 EF  BB 83 F5 65 5E E4 AC 4D : <k.e.......e^..M
0020: 74 BB A3 9D 98 90 C0 08  B7 1F C6 94 2B 58 F3 CB : t...........+X..
0030: FA 61 C0 D9 E0 CC A8 09  34 62 57 2D C7 AB CE A6 : .a......4bW-....
0040: 4E 66 3B D0 E8 CC BD 55  26 71 C2 FE F3 7D 96 5F : Nf;....U&q...}._
0050: 3B 45 84 D3 E2 D6 17 E6  8A A4 D8 E3 26 43 08 0C : ;E..........&C..
0060: 87 FD B4 8C A7 A3 62 A6  AD 63 58 D1 5C B2 D5 10 : ......b..cX.\...
0070: FB CA D2 9F 26 2C EF 9E  90 70 0E BB 87 D7 C2 AD : ....&,...p......
0080: 6A DD A6 90 FA B4 C0 81  87 57 A4 4B ED EC 64 FF : j........W.K..d.

[libssh2] 3.712758 Transport: Looking for packet of type: 31
[libssh2] 3.722758 Failure Event: -37 - Unable to exchange encryption keys
[libssh2] 3.849758 Socket: Recved 1040/16384 bytes to 03e80180+0=> libssh2_transport_read() raw (1040 bytes)
0000: 00 00 03 FC 05 1F 00 00  03 32 00 00 00 07 73 73 : .........2....ss
0010: 68 2D 64 73 73 00 00 01  01 00 F4 F2 B5 BC DA 42 : h-dss..........B
0020: FE C5 A0 C4 B7 1E 4C 36  08 E2 C1 D8 35 9A 3D ED : ......L6....5.=.
0030: 1D BC 69 2E 96 A2 AD AD  DF E2 29 A1 94 2C F0 A1 : ..i.......)..,..
0040: 0A D5 D7 FD 6D 81 A3 A4  62 90 91 96 42 39 06 30 : ....m...b...B9.0
0050: DC 09 B3 27 9E B7 5F 5D  F0 F4 3F 48 36 EF B1 CB : ...'.._]..?H6...
0060: DE 00 C7 2A E5 D6 26 53  6E 89 E9 57 BB 05 25 0C : ...*..&Sn..W..%.
0070: 34 8D 29 BD 63 9B EA 8E  7D 44 61 17 F4 03 A9 0F : 4.).c...}Da.....
0080: BC EB 70 53 02 B4 A2 F5  D6 7D 17 87 25 A8 F8 78 : ..pS.....}..%..x
0090: 03 FF 0E BD 38 CD FE D3  D1 96 05 F3 F7 15 AF 10 : ....8...........
00a0: 33 B6 66 2D 3F E3 08 9C  55 99 E2 6A C2 6A 36 D6 : 3.f-?...U..j.j6.
00b0: 85 06 4D 7F 53 94 4C 02  BB ED 9C 81 8C A1 14 73 : ..M.S.L........s
00c0: D2 88 D5 55 0F D4 D5 75  F2 F6 3B 8C E6 D9 F5 FE : ...U...u..;.....
00d0: 00 C6 9A 41 3D 25 DA EF  03 0C 1F 0F D2 0E 9A 19 : ...A=%..........
00e0: 46 3F E8 4C EB C4 A1 66  66 94 0D 87 2D EC 89 0A : F?.L...ff...-...
00f0: 1C D7 23 38 BC E5 E0 D8  75 41 B6 FB F6 C7 DF 1F : ..#8....uA......
0100: 21 0F 5D 81 C2 F2 97 AA  2A BF 2B 4D 20 D6 A6 3A : !.].....*.+M ..:
0110: B2 1C 13 33 1D E8 25 4F  8C 0B 00 00 00 15 00 B0 : ...3..%O........
0120: FD 96 55 46 5E 4A 94 68  38 A8 14 BC 19 77 AE 6A : ..UF^J.h8....w.j
0130: D6 3E FD 00 00 01 01 00  91 35 EC A7 FF 48 67 0D : .>.......5...Hg.
0140: 54 46 09 05 7F A0 7E 87  BA B3 EB 2B 78 A5 AC 1E : TF....~....+x...
0150: 93 FB 13 B4 AD 54 A1 B4  00 97 F0 5B 04 6A 01 F0 : .....T.....[.j..
0160: 53 BF A6 33 FE 8A 9F 38  89 BE F0 3C F8 20 92 E5 : S..3...8...<. ..
0170: A3 F2 F1 07 C5 28 1D C7  BC 0C F6 12 59 F8 BC 34 : .....(......Y..4
0180: C9 9D 81 8F FE 05 E8 35  26 04 B6 7C 1D 46 BB 4E : .......5&..|.F.N
0190: BD 22 91 92 40 AE 4B AD  3C A4 37 30 AD CC 50 08 : ."[email protected].<.70..P.
01a0: C5 CD A2 84 75 BA 3A 31  A8 F8 B4 E5 57 0F D0 34 : ....u.:1....W..4
01b0: 1A 96 BE 39 27 DC AF 17  CE 30 3E 7E 59 81 B6 FA : ...9'....0>~Y...
01c0: A4 C3 AB 01 56 41 BB B5  B2 E5 8D 10 8C A7 39 7D : ....VA........9}
01d0: 3B 30 DA 47 78 E7 7C B5  80 1D 25 FC 4E 62 3C CB : ;0.Gx.|...%.Nb<.
01e0: 6B 15 95 D4 13 B1 7D B8  16 59 FF 60 C1 2D 35 7B : k.....}..Y.`.-5{
01f0: B9 2D 3E 04 28 E4 F9 71  17 82 63 3D FB 57 8E 7D : .->.(..q..c=.W.}
0200: 7C 20 04 D6 28 05 CB 67  EA AA 6E ED A0 2A E2 08 : | ..(..g..n..*..
0210: B6 6A DD 96 17 B2 21 58  CF 68 FD 81 D0 36 D6 68 : .j....!X.h...6.h
0220: 97 E4 54 9E CB A4 47 0C  9F 29 BC 8A BD 19 C5 8E : ..T...G..)......
0230: 0D 01 1C 53 8D 5D E7 A1  00 00 01 00 2B DA F0 31 : ...S.]......+..1
0240: F3 64 08 21 63 EE 46 7F  C6 35 78 7B DA 66 0F 26 : .d.!c.F..5x{.f.&
0250: 64 8D 2E 4C 05 BF 68 77  D5 33 AA 44 E1 48 30 7A : d..L..hw.3.D.H0z
0260: 67 DC 21 54 3A 81 06 E6  14 4E C8 84 41 3F E8 F7 : g.!T:....N..A?..
0270: EC 8E 11 B0 25 81 E1 98  04 53 BD 57 66 84 89 F8 : ....%....S.Wf...
0280: 96 84 C8 1F A1 22 A0 0F  D8 FD 4C 2C 34 05 E4 B1 : ....."....L,4...
0290: D1 F0 2F F1 7C 07 46 B2  DB B2 A5 9A 55 CD 95 38 : ../.|.F.....U..8
02a0: B3 BD 57 EE B2 F0 D6 65  58 0E 57 CD 37 3F 01 D9 : ..W....eX.W.7?..
02b0: E1 69 12 A5 74 56 BE 0E  50 2F 4F 97 A7 3D 0E 6B : .i..tV..P/O..=.k
02c0: CA F1 36 59 0D 5F 93 A9  A5 FD 58 FD A8 7A 16 E3 : ..6Y._....X..z..
02d0: DD 8C 4B D0 8E E7 A0 0F  A9 26 C0 3F 00 F8 6E E6 : ..K......&.?..n.
02e0: C4 82 85 A1 64 A3 51 D8  96 8B C3 DB 2B 3F 69 13 : ....d.Q.....+?i.
02f0: 22 15 3D 6E 6C 44 9E E8  72 65 E7 2F D3 D1 EB 03 : ".=nlD..re./....
0300: B9 28 49 C8 3D A9 EC 28  BC 54 40 DB 2C 80 F6 E2 : .(I.=..(.T@.,...
0310: 42 4E E3 5E 57 D2 36 5B  21 B9 38 85 CD B1 38 21 : BN.^W.6[!.8...8!
0320: CC 7A 38 A5 C6 8E 9D 56  C4 4B D1 1F 63 41 92 5B : .z8....V.K..cA.[
0330: 02 D3 05 EB 2D 42 4D 8E  D8 9F 13 B1 00 00 00 80 : ....-BM.........
0340: 7F 3A 7F C4 59 BF 53 74  7B 4E D5 CD C6 73 53 E4 : .:..Y.St{N...sS.
0350: ED DF F4 4F 26 FA B7 D3  47 1F 99 E2 66 00 3D 38 : ...O&...G...f.=8
0360: 81 5B 92 93 01 B8 BD D4  29 38 AB 22 77 2F 88 E6 : .[......)8."w/..
0370: 2B F7 40 87 31 6E 63 E7  69 88 40 C9 BC 1B 54 9F : [email protected][email protected].
0380: 83 7D DD 86 D1 9D 6C D4  A5 DA B1 89 0A 18 5C 72 : .}....l.......\r
0390: 8E C0 FF 96 69 4D 78 09  22 AD 67 BD 99 AE C2 EC : ....iMx.".g.....
03a0: B8 44 D8 3A 69 F3 3F E6  90 6F F1 C1 95 1A C2 C7 : .D.:i.?..o......
03b0: 98 59 22 51 0C 2D E3 BA  4E 94 72 17 18 3B 6B 60 : .Y"Q.-..N.r..;k`
03c0: 00 00 00 37 00 00 00 07  73 73 68 2D 64 73 73 00 : ...7....ssh-dss.
03d0: 00 00 28 54 E5 55 1C 82  DC 1B 1C 8A 17 E5 A8 FD : ..(T.U..........
03e0: DC E3 37 3C A6 4B 94 5B  EA 15 DB 66 C1 12 07 20 : ..7<.K.[...f... 
03f0: 07 88 6D 8E A4 57 A9 D0  A7 DE 61 49 6D 66 BB 98 : ..m..W....aImf..
0400: 00 00 00 0C 0A 15 4A 1C  13 F7 3B C4 F6 D9 80 A0 : ......J...;.....
=> libssh2_transport_read() plain (1014 bytes)
0000: 1F 00 00 03 32 00 00 00  07 73 73 68 2D 64 73 73 : ....2....ssh-dss
0010: 00 00 01 01 00 F4 F2 B5  BC DA 42 FE C5 A0 C4 B7 : ..........B.....
0020: 1E 4C 36 08 E2 C1 D8 35  9A 3D ED 1D BC 69 2E 96 : .L6....5.=...i..
0030: A2 AD AD DF E2 29 A1 94  2C F0 A1 0A D5 D7 FD 6D : .....)..,......m
0040: 81 A3 A4 62 90 91 96 42  39 06 30 DC 09 B3 27 9E : ...b...B9.0...'.
0050: B7 5F 5D F0 F4 3F 48 36  EF B1 CB DE 00 C7 2A E5 : ._]..?H6......*.
0060: D6 26 53 6E 89 E9 57 BB  05 25 0C 34 8D 29 BD 63 : .&Sn..W..%.4.).c
0070: 9B EA 8E 7D 44 61 17 F4  03 A9 0F BC EB 70 53 02 : ...}Da.......pS.
0080: B4 A2 F5 D6 7D 17 87 25  A8 F8 78 03 FF 0E BD 38 : ....}..%..x....8
0090: CD FE D3 D1 96 05 F3 F7  15 AF 10 33 B6 66 2D 3F : ...........3.f-?
00a0: E3 08 9C 55 99 E2 6A C2  6A 36 D6 85 06 4D 7F 53 : ...U..j.j6...M.S
00b0: 94 4C 02 BB ED 9C 81 8C  A1 14 73 D2 88 D5 55 0F : .L........s...U.
00c0: D4 D5 75 F2 F6 3B 8C E6  D9 F5 FE 00 C6 9A 41 3D : ..u..;........A=
00d0: 25 DA EF 03 0C 1F 0F D2  0E 9A 19 46 3F E8 4C EB : %..........F?.L.
00e0: C4 A1 66 66 94 0D 87 2D  EC 89 0A 1C D7 23 38 BC : ..ff...-.....#8.
00f0: E5 E0 D8 75 41 B6 FB F6  C7 DF 1F 21 0F 5D 81 C2 : ...uA......!.]..
0100: F2 97 AA 2A BF 2B 4D 20  D6 A6 3A B2 1C 13 33 1D : ...*.+M ..:...3.
0110: E8 25 4F 8C 0B 00 00 00  15 00 B0 FD 96 55 46 5E : .%O..........UF^
0120: 4A 94 68 38 A8 14 BC 19  77 AE 6A D6 3E FD 00 00 : J.h8....w.j.>...
0130: 01 01 00 91 35 EC A7 FF  48 67 0D 54 46 09 05 7F : ....5...Hg.TF...
0140: A0 7E 87 BA B3 EB 2B 78  A5 AC 1E 93 FB 13 B4 AD : .~....+x........
0150: 54 A1 B4 00 97 F0 5B 04  6A 01 F0 53 BF A6 33 FE : T.....[.j..S..3.
0160: 8A 9F 38 89 BE F0 3C F8  20 92 E5 A3 F2 F1 07 C5 : ..8...<. .......
0170: 28 1D C7 BC 0C F6 12 59  F8 BC 34 C9 9D 81 8F FE : (......Y..4.....
0180: 05 E8 35 26 04 B6 7C 1D  46 BB 4E BD 22 91 92 40 : ..5&..|.F.N."..@
0190: AE 4B AD 3C A4 37 30 AD  CC 50 08 C5 CD A2 84 75 : .K.<.70..P.....u
01a0: BA 3A 31 A8 F8 B4 E5 57  0F D0 34 1A 96 BE 39 27 : .:1....W..4...9'
01b0: DC AF 17 CE 30 3E 7E 59  81 B6 FA A4 C3 AB 01 56 : ....0>~Y.......V
01c0: 41 BB B5 B2 E5 8D 10 8C  A7 39 7D 3B 30 DA 47 78 : A........9};0.Gx
01d0: E7 7C B5 80 1D 25 FC 4E  62 3C CB 6B 15 95 D4 13 : .|...%.Nb<.k....
01e0: B1 7D B8 16 59 FF 60 C1  2D 35 7B B9 2D 3E 04 28 : .}..Y.`.-5{.->.(
01f0: E4 F9 71 17 82 63 3D FB  57 8E 7D 7C 20 04 D6 28 : ..q..c=.W.}| ..(
0200: 05 CB 67 EA AA 6E ED A0  2A E2 08 B6 6A DD 96 17 : ..g..n..*...j...
0210: B2 21 58 CF 68 FD 81 D0  36 D6 68 97 E4 54 9E CB : .!X.h...6.h..T..
0220: A4 47 0C 9F 29 BC 8A BD  19 C5 8E 0D 01 1C 53 8D : .G..).........S.
0230: 5D E7 A1 00 00 01 00 2B  DA F0 31 F3 64 08 21 63 : ]......+..1.d.!c
0240: EE 46 7F C6 35 78 7B DA  66 0F 26 64 8D 2E 4C 05 : .F..5x{.f.&d..L.
0250: BF 68 77 D5 33 AA 44 E1  48 30 7A 67 DC 21 54 3A : .hw.3.D.H0zg.!T:
0260: 81 06 E6 14 4E C8 84 41  3F E8 F7 EC 8E 11 B0 25 : ....N..A?......%
0270: 81 E1 98 04 53 BD 57 66  84 89 F8 96 84 C8 1F A1 : ....S.Wf........
0280: 22 A0 0F D8 FD 4C 2C 34  05 E4 B1 D1 F0 2F F1 7C : "....L,4...../.|
0290: 07 46 B2 DB B2 A5 9A 55  CD 95 38 B3 BD 57 EE B2 : .F.....U..8..W..
02a0: F0 D6 65 58 0E 57 CD 37  3F 01 D9 E1 69 12 A5 74 : ..eX.W.7?...i..t
02b0: 56 BE 0E 50 2F 4F 97 A7  3D 0E 6B CA F1 36 59 0D : V..P/O..=.k..6Y.
02c0: 5F 93 A9 A5 FD 58 FD A8  7A 16 E3 DD 8C 4B D0 8E : _....X..z....K..
02d0: E7 A0 0F A9 26 C0 3F 00  F8 6E E6 C4 82 85 A1 64 : ....&.?..n.....d
02e0: A3 51 D8 96 8B C3 DB 2B  3F 69 13 22 15 3D 6E 6C : .Q.....+?i.".=nl
02f0: 44 9E E8 72 65 E7 2F D3  D1 EB 03 B9 28 49 C8 3D : D..re./.....(I.=
0300: A9 EC 28 BC 54 40 DB 2C  80 F6 E2 42 4E E3 5E 57 : ..(.T@.,...BN.^W
0310: D2 36 5B 21 B9 38 85 CD  B1 38 21 CC 7A 38 A5 C6 : .6[!.8...8!.z8..
0320: 8E 9D 56 C4 4B D1 1F 63  41 92 5B 02 D3 05 EB 2D : ..V.K..cA.[....-
0330: 42 4D 8E D8 9F 13 B1 00  00 00 80 7F 3A 7F C4 59 : BM..........:..Y
0340: BF 53 74 7B 4E D5 CD C6  73 53 E4 ED DF F4 4F 26 : .St{N...sS....O&
0350: FA B7 D3 47 1F 99 E2 66  00 3D 38 81 5B 92 93 01 : ...G...f.=8.[...
0360: B8 BD D4 29 38 AB 22 77  2F 88 E6 2B F7 40 87 31 : ...)8."w/[email protected]
0370: 6E 63 E7 69 88 40 C9 BC  1B 54 9F 83 7D DD 86 D1 : [email protected]..}...
0380: 9D 6C D4 A5 DA B1 89 0A  18 5C 72 8E C0 FF 96 69 : .l.......\r....i
0390: 4D 78 09 22 AD 67 BD 99  AE C2 EC B8 44 D8 3A 69 : Mx.".g......D.:i
03a0: F3 3F E6 90 6F F1 C1 95  1A C2 C7 98 59 22 51 0C : .?..o.......Y"Q.
03b0: 2D E3 BA 4E 94 72 17 18  3B 6B 60 00 00 00 37 00 : -..N.r..;k`...7.
03c0: 00 00 07 73 73 68 2D 64  73 73 00 00 00 28 54 E5 : ...ssh-dss...(T.
03d0: 55 1C 82 DC 1B 1C 8A 17  E5 A8 FD DC E3 37 3C A6 : U............7<.
03e0: 4B 94 5B EA 15 DB 66 C1  12 07 20 07 88 6D 8E A4 : K.[...f... ..m..
03f0: 57 A9 D0 A7 DE 61                                : W....a

[libssh2] 5.150758 Transport: Packet type 31 received, length=1014
[libssh2] 5.159758 Transport: Looking for packet of type: 31
[libssh2] 5.169758 Key Ex: Server's MD5 Fingerprint: ec:f8:c7:8f:41:4b:e7:78:fb:3b:76:df:67:a7:6e:ad
[libssh2] 5.178758 Key Ex: Server's SHA1 Fingerprint: 5b:53:0d:7d:20:71:4e:94:c4:80:3e:10:73:a4:72:b1:e6:e8:7b:b9
[libssh2] 5.214758 Key Ex: Sending NEWKEYS message=> libssh2_transport_write plain (1 bytes)
0000: 15                                               : .

[libssh2] 5.242758 Socket: Sent 16/16 bytes at 03e841a8=> libssh2_transport_write send() (16 bytes)
0000: 00 00 00 0C 0A 15 00 6A  98 B6 2E 30 E0 D1 D9 56 : .......j...0...V

[libssh2] 5.271758 Transport: Looking for packet of type: 21=> libssh2_transport_read() plain (1 bytes)
0000: 15                                               : .

[libssh2] 5.299758 Transport: Packet type 21 received, length=1
[libssh2] 5.308758 Transport: Looking for packet of type: 21
[libssh2] 5.317758 Key Ex: Received NEWKEYS message
[libssh2] 5.327758 Key Ex: session_id calculated
[libssh2] 5.337758 Key Ex: Client to Server IV and Key calculated
[libssh2] 5.346758 Key Ex: Server to Client IV and Key calculated
[libssh2] 5.356758 Key Ex: Client to Server HMAC Key calculated
[libssh2] 5.372758 Key Ex: Server to Client HMAC Key calculated
[libssh2] 5.382758 Key Ex: Client to Server compression initialized
[libssh2] 5.392758 Key Ex: Server to Client compression initialized
[libssh2] 5.401758 Transport: Requesting userauth service=> libssh2_transport_write plain (17 bytes)
0000: 05 00 00 00 0C 73 73 68  2D 75 73 65 72 61 75 74 : .....ssh-useraut
0010: 68                                               : h

[libssh2] 5.446758 Socket: Sent 52/52 bytes at 03e841a8=> libssh2_transport_write send() (52 bytes)
0000: 57 5D 88 D8 CB 2E 5A 43  3E 99 53 BD 51 45 84 7D : W]....ZC>.S.QE.}
0010: 20 2B CF 47 2F F7 BF 93  2C 8F 01 D5 01 18 98 94 :  +.G/...,.......
0020: C3 5D 43 3C B8 E5 C7 55  E4 A2 4C DD D7 6F B3 7E : .]C<...U..L..o.~
0030: 30 10 7F B0                                      : 0...

[libssh2] 5.507758 Transport: Looking for packet of type: 6
[libssh2] 5.516758 Socket: Error recving 16384 bytes (got 0) ```

latest libssh2 library fails to authenticate with public key (RSA) libssh2_userauth_publickey_fromfile

The same issue with number #309 I have wrote in the libssh2.org [old bug tracker], but I realized I have to put the issues here at github.

libssh2 library was build against MinGW Makefiles and using OpenSSL.
Target OS Windows 7.
public/private key pair was generated using OpenSSL, without passphrase.
I am using freeSSHd Server application, where I set a user "testuser" and authentication SSH public key only.

My Code look like this:

// authenticate by public key.
int iResult = libssh2_userauth_publickey_fromfile( mySession,
                "testuser", "public.pem", "private.pem", NULL );

iResult always returns LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED.
what am I doing wrong?
I really can't help myself and I couldn't find out what I am doing wrong.

By the way libssh2_userauth_password works fine, but I need public key authentication

Could you please help me.

Mohi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.