diff --git a/src/pki.c b/src/pki.c index 0fbfc115..a65e8a48 100644 --- a/src/pki.c +++ b/src/pki.c @@ -320,9 +320,24 @@ int ssh_key_algorithm_allowed(ssh_session session, const char *type) { const char *allowed_list; - allowed_list = session->opts.pubkey_accepted_types; - if (allowed_list == NULL) { - allowed_list = ssh_kex_get_default_methods(SSH_HOSTKEYS); + if (session->client) { + allowed_list = session->opts.pubkey_accepted_types; + if (allowed_list == NULL) { + allowed_list = ssh_kex_get_default_methods(SSH_HOSTKEYS); + } + } +#ifdef WITH_SERVER + else if (session->server) { + allowed_list = session->opts.wanted_methods[SSH_HOSTKEYS]; + if (allowed_list == NULL) { + SSH_LOG(SSH_LOG_WARN, "Session invalid: no host key available"); + return 0; + } + } +#endif + else { + SSH_LOG(SSH_LOG_WARN, "Session invalid: not set as client nor server"); + return 0; } SSH_LOG(SSH_LOG_DEBUG, "Checking %s with list <%s>", type, allowed_list); diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c index ea45aa32..48120013 100644 --- a/tests/unittests/torture_options.c +++ b/tests/unittests/torture_options.c @@ -36,6 +36,8 @@ static int setup(void **state) verbosity = torture_libssh_verbosity(); ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); + session->client = 1; + *state = session; return 0;