aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-05-16 17:07:57 +0200
committerAndreas Schneider <asn@cryptomilk.org>2019-06-12 10:17:54 +0200
commitb0ff64bf1b177f3272cb0d4858e59f66629fa739 (patch)
tree2629b367f69b6dbb6978d1c9ec5549024c26276a /src
parentd013a94f378e98f638fc5cc1b7bd72a4d1411820 (diff)
downloadlibssh-b0ff64bf1b177f3272cb0d4858e59f66629fa739.tar.gz
libssh-b0ff64bf1b177f3272cb0d4858e59f66629fa739.tar.xz
libssh-b0ff64bf1b177f3272cb0d4858e59f66629fa739.zip
pki: Check if the key is allowed against right list
Previously when generating the signature in server side the key was checked against the wrong list, potentially making the server to select the wrong algorithm to sign (e.g. rsa-sha2-512 instead of rsa-sha2-256). Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/pki.c21
1 files changed, 18 insertions, 3 deletions
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);