bmh10 / rpms / openssh

Forked from rpms/openssh 2 days ago
Clone

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

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