How to print the SSH host key as a client

Ján Osuský jan.osusky at iblsoft.com
Wed Feb 9 11:11:53 CET 2022


Hi Jente,
we use libssh2 for a client implementation too and we use both the 
fingerprint (with libssh2_hostkey_hash) and the host key itself.

Function "libssh2_session_hostkey" returns pointer to the key as expected, 
and also sets the key length and type.

In our code (that is not new anymore) we still use libssh2_session_startup 
instead of libssh2_session_handshake but I don't think that should be a 
problem.




Best regards,




JanO





On Wednesday 9. February 2022, 10:17:05 (+01:00), Jente Hidskes via 
libssh2-devel wrote:

 > Hey folks,
 >
 > I am working on a small SFTP client using libssh2. I would like for
 > this client to persist the host key of the server it is connecting to,
 > but I seem to be unable to get a hold of it.
 >
 > After initialising libssh2 and calling libssh2_session_handshake, I am
 > able to print the host key fingerprint through libssh2_hostkey_hash as
 > in the example programs. I assumed I would be able to print the actual
 > host key rather than the fingerprint with libssh2_session_hostkey, but
 > that returns an empty string.
 >
 > I suspect that libssh2_session_hostkey only returns the local host key
 > when operating as a server (given this[1] source code comment), but
 > the docs[2] are unclear about this: they just state "get the remote
 > key" and "returns a pointer to the current host key".
 >
 > Am I doing something wrong, or is it indeed impossible right now to
 > print the host key when operating as a client?
 >
 > Kind regards,
 >
 > Jente
 >
 > [1] 
https://github.com/libssh2/libssh2/blob/2a2aaed3b6c3c1dc25e35e11afcfb23f88a18510/src/libssh2_priv.h#L628
 
> [2] https://www.libssh2.org/libssh2_session_hostkey.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.haxx.se/pipermail/libssh2-devel/attachments/20220209/6e202760/attachment.htm>


More information about the libssh2-devel mailing list