Replies: 3 comments
-
Passing |
Beta Was this translation helpful? Give feedback.
0 replies
-
@vszakats so maybe something like this instead? LIBSSH2_API int
libssh2_knownhost_frommemory(LIBSSH2_KNOWNHOSTS *hosts,
const char *knownhostsdata,
size_t knownhostsdata_len,
int type)
{
FILE *file;
int num = 0;
char buf[4092];
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unsupported type of known-host information "
"store");
file = fmemopen(knownhostsdata, knownhostsdata_len, FOPEN_READTEXT);
if(file) {
while(fgets(buf, sizeof(buf), file)) {
if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type)) {
num = _libssh2_error(hosts->session, LIBSSH2_ERROR_KNOWN_HOSTS,
"Failed to parse known hosts data");
break;
}
num++;
}
fclose(file);
}
else
return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
"Failed to open known hosts data");
return num;
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently the only way to read a set of known host keys is to read it from a file using
libssh2_knownhost_readfile
.But what if the set of known host keys is already in memory (e.g. our database of known host keys in our application returns it as string that looks like typical contents of
~/.ssh/known_hosts
)?We could remix
libssh2_knownhost_readstream
fromlibssh2_knownhost_readfile
like this:If
libssh2_knownhost_readstream
existed, thenlibssh2_knownhost_readfile
can be implemented in terms of it.And any application that has known hosts in memory, could use
fmemopen
and then calllibssh2_knownhost_readstream
.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions