<html><head></head><body><h4>Hi Jente,</h4><div>we use libssh2 for a client
implementation too and we use both the fingerprint (with <font
face="monospace">libssh2_hostkey_hash</font><span style="background-color:
var(--colorBgIntense); color: var(--colorFgIntense);">) and the host key
itself.</span></div><div><p style="margin-top: 0px; margin-bottom:
0px;">Function "<font face="monospace">libssh2_session_hostkey</font>"
returns pointer to the key as expected, and also sets the key length and
type.</p><p style="margin-top: 0px; margin-bottom: 0px;">In our code (that
is not new anymore) we still use <font
face="monospace">libssh2_session_startup</font> instead of <font
face="monospace">libssh2_session_handshake</font> but I don't think that
should be a problem.</p><p style="margin-top: 0px; margin-bottom:
0px;"><br></p><p style="margin-top: 0px; margin-bottom: 0px;">Best
regards,</p><p style="margin-top: 0px; margin-bottom: 0px;"><br></p><p
style="margin-top: 0px; margin-bottom: 0px;">JanO</p><p style="margin-top:
0px; margin-bottom: 0px;"><br></p><br>On
Wednesday 9. February 2022, 10:17:05 (+01:00), Jente
Hidskes via libssh2-devel wrote:<br><br>> Hey folks,<br>> <br>> I
am working on a small SFTP client using libssh2. I would like for<br>>
this client to persist the host key of the server it is connecting
to,<br>> but I seem to be unable to get a hold of it.<br>> <br>>
After initialising libssh2 and calling libssh2_session_handshake, I
am<br>> able to print the host key fingerprint through
libssh2_hostkey_hash as<br>> in the example programs. I assumed I would
be able to print the actual<br>> host key rather than the fingerprint
with libssh2_session_hostkey, but<br>> that returns an empty
string.<br>> <br>> I suspect that libssh2_session_hostkey only
returns the local host key<br>> when operating as a server (given
this[1] source code comment), but<br>> the docs[2] are unclear about
this: they just state "get the remote<br>> key" and "returns a pointer
to the current host key".<br>> <br>> Am I doing something wrong, or
is it indeed impossible right now to<br>> print the host key when
operating as a client?<br>> <br>> Kind regards,<br>> <br>>
Jente<br>> <br>> [1]
https://github.com/libssh2/libssh2/blob/2a2aaed3b6c3c1dc25e35e11afcfb23f88a18510/src/libssh2_priv.h#L628<br>>
[2]
https://www.libssh2.org/libssh2_session_hostkey.html<br><br></div></body></html>