sync with OpenBSD -current

This commit is contained in:
purplerain 2024-05-03 17:35:01 +00:00
parent 7768d1f254
commit c9341f2e4a
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
65 changed files with 2158 additions and 1228 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: sshconnect.c,v 1.367 2024/04/23 13:34:50 jsg Exp $ */
/* $OpenBSD: sshconnect.c,v 1.368 2024/04/30 02:10:49 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -45,6 +45,7 @@
#include "sshconnect.h"
#include "hostfile.h"
#include "log.h"
#include "match.h"
#include "misc.h"
#include "readconf.h"
#include "atomicio.h"
@ -679,6 +680,29 @@ try_tilde_unexpand(const char *path)
return ret;
}
/*
* Returns non-zero if the key is accepted by HostkeyAlgorithms.
* Made slightly less trivial by the multiple RSA signature algorithm names.
*/
int
hostkey_accepted_by_hostkeyalgs(const struct sshkey *key)
{
const char *ktype = sshkey_ssh_name(key);
const char *hostkeyalgs = options.hostkeyalgorithms;
if (key->type == KEY_UNSPEC)
return 0;
if (key->type == KEY_RSA &&
(match_pattern_list("rsa-sha2-256", hostkeyalgs, 0) == 1 ||
match_pattern_list("rsa-sha2-512", hostkeyalgs, 0) == 1))
return 1;
if (key->type == KEY_RSA_CERT &&
(match_pattern_list("rsa-sha2-512-cert-v01@openssh.com", hostkeyalgs, 0) == 1 ||
match_pattern_list("rsa-sha2-256-cert-v01@openssh.com", hostkeyalgs, 0) == 1))
return 1;
return match_pattern_list(ktype, hostkeyalgs, 0) == 1;
}
static int
hostkeys_find_by_key_cb(struct hostkey_foreach_line *l, void *_ctx)
{
@ -979,6 +1003,12 @@ check_host_key(char *hostname, const struct ssh_conn_info *cinfo,
}
retry:
if (!hostkey_accepted_by_hostkeyalgs(host_key)) {
error("host key %s not permitted by HostkeyAlgorithms",
sshkey_ssh_name(host_key));
goto fail;
}
/* Reload these as they may have changed on cert->key downgrade */
want_cert = sshkey_is_cert(host_key);
type = sshkey_type(host_key);