Blame openssh-8.7p1-negotiate-supported-algs.patch

Zoltan Fridrich e8622f
diff --color -rup a/regress/hostkey-agent.sh b/regress/hostkey-agent.sh
Zoltan Fridrich e8622f
--- a/regress/hostkey-agent.sh	2021-08-20 06:03:49.000000000 +0200
Zoltan Fridrich e8622f
+++ b/regress/hostkey-agent.sh	2022-07-14 11:58:12.172786060 +0200
Zoltan Fridrich e8622f
@@ -13,8 +13,12 @@ r=$?
Zoltan Fridrich e8622f
 grep -vi 'hostkey' $OBJ/sshd_proxy > $OBJ/sshd_proxy.orig
Zoltan Fridrich e8622f
 echo "HostKeyAgent $SSH_AUTH_SOCK" >> $OBJ/sshd_proxy.orig
Zoltan Fridrich e8622f
 
Zoltan Fridrich e8622f
+PUBKEY_ACCEPTED_ALGOS=`$SSH -G "example.com" | \
Zoltan Fridrich e8622f
+    grep -i "PubkeyAcceptedAlgorithms" | cut -d ' ' -f2- | tr "," "|"`
Zoltan Fridrich e8622f
+SSH_ACCEPTED_KEYTYPES=`echo "$SSH_KEYTYPES" | egrep "$PUBKEY_ACCEPTED_ALGOS"`
Zoltan Fridrich e8622f
+
Zoltan Fridrich e8622f
 trace "load hostkeys"
Zoltan Fridrich e8622f
-for k in $SSH_KEYTYPES ; do
Zoltan Fridrich e8622f
+for k in $SSH_ACCEPTED_KEYTYPES ; do
Zoltan Fridrich e8622f
 	${SSHKEYGEN} -qt $k -f $OBJ/agent-key.$k -N '' || fatal "ssh-keygen $k"
Zoltan Fridrich e8622f
 	(
Zoltan Fridrich e8622f
 		printf 'localhost-with-alias,127.0.0.1,::1 '
Zoltan Fridrich e8622f
@@ -31,7 +35,7 @@ cp $OBJ/known_hosts.orig $OBJ/known_host
Zoltan Fridrich e8622f
 unset SSH_AUTH_SOCK
Zoltan Fridrich e8622f
 
Zoltan Fridrich e8622f
 for ps in yes; do
Zoltan Fridrich e8622f
-	for k in $SSH_KEYTYPES ; do
Zoltan Fridrich e8622f
+	for k in $SSH_ACCEPTED_KEYTYPES ; do
Zoltan Fridrich e8622f
 		verbose "key type $k privsep=$ps"
Zoltan Fridrich e8622f
 		cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy
Zoltan Fridrich e8622f
 		echo "UsePrivilegeSeparation $ps" >> $OBJ/sshd_proxy
Zoltan Fridrich e8622f
diff --color -rup a/sshconnect2.c b/sshconnect2.c
Zoltan Fridrich e8622f
--- a/sshconnect2.c	2022-07-14 10:10:07.262975710 +0200
Zoltan Fridrich e8622f
+++ b/sshconnect2.c	2022-07-14 10:10:32.068452067 +0200
Zoltan Fridrich e8622f
@@ -222,6 +222,7 @@ ssh_kex2(struct ssh *ssh, char *host, st
Zoltan Fridrich e8622f
 {
Zoltan Fridrich e8622f
 	char *myproposal[PROPOSAL_MAX] = { KEX_CLIENT };
Zoltan Fridrich e8622f
 	char *s, *all_key;
Zoltan Fridrich e8622f
+	char *hostkeyalgs = NULL, *pkalg = NULL;
Zoltan Fridrich e8622f
 	char *prop_kex = NULL, *prop_enc = NULL, *prop_hostkey = NULL;
Zoltan Fridrich e8622f
 	int r, use_known_hosts_order = 0;
Zoltan Fridrich e8622f
 
Zoltan Fridrich e8622f
@@ -264,14 +265,19 @@ ssh_kex2(struct ssh *ssh, char *host, st
Zoltan Fridrich e8622f
 	    myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
Zoltan Fridrich e8622f
 	if (use_known_hosts_order) {
Zoltan Fridrich e8622f
 		/* Query known_hosts and prefer algorithms that appear there */
Zoltan Fridrich e8622f
-		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = prop_hostkey =
Zoltan Fridrich e8622f
-		    compat_pkalg_proposal(ssh,
Zoltan Fridrich e8622f
-		    order_hostkeyalgs(host, hostaddr, port, cinfo));
Zoltan Fridrich e8622f
+		if ((hostkeyalgs = order_hostkeyalgs(host, hostaddr, port, cinfo)) == NULL)
Zoltan Fridrich e8622f
+			fatal_f("order_hostkeyalgs");
Zoltan Fridrich e8622f
+		pkalg = match_filter_allowlist(hostkeyalgs, options.pubkey_accepted_algos);
Zoltan Fridrich e8622f
+		free(hostkeyalgs);
Zoltan Fridrich e8622f
 	} else {
Zoltan Fridrich e8622f
-		/* Use specified HostkeyAlgorithms exactly */
Zoltan Fridrich e8622f
-		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = prop_hostkey =
Zoltan Fridrich e8622f
-		    compat_pkalg_proposal(ssh, options.hostkeyalgorithms);
Zoltan Fridrich e8622f
+		/* Use specified HostkeyAlgorithms */
Zoltan Fridrich e8622f
+		pkalg = match_filter_allowlist(options.hostkeyalgorithms, options.pubkey_accepted_algos);
Zoltan Fridrich e8622f
 	}
Zoltan Fridrich e8622f
+	if (pkalg == NULL)
Zoltan Fridrich e8622f
+		fatal_f("match_filter_allowlist");
Zoltan Fridrich e8622f
+	myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = prop_hostkey =
Zoltan Fridrich e8622f
+	    compat_pkalg_proposal(ssh, pkalg);
Zoltan Fridrich e8622f
+	free(pkalg);
Zoltan Fridrich e8622f
 
Zoltan Fridrich e8622f
 #if defined(GSSAPI) && defined(WITH_OPENSSL)
Zoltan Fridrich e8622f
 	if (options.gss_keyex) {