Subject: Re: Fwd: libssh2_knownhost_check key format

Re: Fwd: libssh2_knownhost_check key format

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sat, 6 Mar 2010 22:30:27 +0100 (CET)

On Sat, 6 Mar 2010, Alexander Lamaison wrote:

First, let me just say that it was a while since I did these things so I'm not
completely up to speed with them. But I did write both the libssh2 side and
the libcurl code using it so whatever mistakes are there, I made them! ;-)

>      keycheck = libssh2_knownhost_check(sshc->kh,
>                                         conn->host.name,
>                                         remotekey, keylen,
>                                         LIBSSH2_KNOWNHOST_TYPE_PLAIN|
>                                         LIBSSH2_KNOWNHOST_KEYENC_RAW|
>                                         keybit,
>                                         &host);
>
> The key held by 'host' here should be in binary format because
> LIBSSH2_KNOWNHOST_KEYENC_RAW was used.

I believe the 'typemask' as is set by the function above is for the key passed
in to the function. That's the 'remotekey' argument. It doesn't specify what
format the info about the existing known host key is using.

'host' is a pointer to a struct that gets returned by
libssh2_knownhost_check() and that returns a 'struct libssh2_knownhost' which
in the public libssh2.h header has its 'key' field documented as "key in
base64/printable format".

> As the key will always start with '\0' this would lead to no key showing up
> in the final string.

I'd say this is a bug on the libssh2 side. It is documented and intended to
only "export" the key as base64-encoded or an otherwise prinatable format,
which should be fine to print as zero-terminated. I see how that the
knownhost_to_external() function makes no effort to make sure that is the
case, and that seems wrong.

Or maybe the problem is earlier. How does it end up kept in memory raw in the
first place? Iirc, the code keeps the data base64-encoded in memory.

(FYI: I'll be away the upcoming week so I'll be slower to respond to mails.)

-- 
  / daniel.haxx.se

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-03-06