kentpeacock / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
2c68b3
diff -up openssh-8.7p1/kex.c.minsha1 openssh-8.7p1/kex.c
2c68b3
--- openssh-8.7p1/kex.c.minsha1	2021-12-20 17:38:51.438294309 +0100
2c68b3
+++ openssh-8.7p1/kex.c	2021-12-21 11:02:48.379991319 +0100
2c68b3
@@ -994,6 +994,35 @@ kex_choose_conf(struct ssh *ssh)
2c68b3
 		free(ext);
2c68b3
 	}
2c68b3
 
2c68b3
+	/* Check whether client supports rsa-sha2 algorithms */
2c68b3
+	if (kex->server && (kex->flags & KEX_INITIAL)) {
2c68b3
+		char *ext;
2c68b3
+
2c68b3
+		ext = match_list("rsa-sha2-256", peer[PROPOSAL_SERVER_HOST_KEY_ALGS], NULL);
2c68b3
+		if (ext) {
2c68b3
+			kex->flags |= KEX_RSA_SHA2_256_SUPPORTED;
2c68b3
+			free(ext);
2c68b3
+		}
2c68b3
+
2c68b3
+		ext = match_list("rsa-sha2-512", peer[PROPOSAL_SERVER_HOST_KEY_ALGS], NULL);
2c68b3
+		if (ext) {
2c68b3
+			kex->flags |= KEX_RSA_SHA2_512_SUPPORTED;
2c68b3
+			free(ext);
2c68b3
+		}
2c68b3
+
2c68b3
+		ext = match_list("rsa-sha2-256-cert-v01@openssh.com", peer[PROPOSAL_SERVER_HOST_KEY_ALGS], NULL);
2c68b3
+		if (ext) {
2c68b3
+			kex->flags |= KEX_RSA_SHA2_256_SUPPORTED;
2c68b3
+			free(ext);
2c68b3
+		}
2c68b3
+
2c68b3
+		ext = match_list("rsa-sha2-512-cert-v01@openssh.com", peer[PROPOSAL_SERVER_HOST_KEY_ALGS], NULL);
2c68b3
+		if (ext) {
2c68b3
+			kex->flags |= KEX_RSA_SHA2_512_SUPPORTED;
2c68b3
+			free(ext);
2c68b3
+		}
2c68b3
+	}
2c68b3
+
2c68b3
 	/* Algorithm Negotiation */
2c68b3
 	if ((r = choose_kex(kex, cprop[PROPOSAL_KEX_ALGS],
2c68b3
 	    sprop[PROPOSAL_KEX_ALGS])) != 0) {
2c68b3
diff -up openssh-8.7p1/kex.h.minsha1 openssh-8.7p1/kex.h
2c68b3
--- openssh-8.7p1/kex.h.minsha1	2021-12-20 17:38:51.430294240 +0100
2c68b3
+++ openssh-8.7p1/kex.h	2021-12-21 10:56:29.066735608 +0100
2c68b3
@@ -116,6 +116,8 @@ enum kex_exchange {
2c68b3
 
2c68b3
 #define KEX_INIT_SENT	0x0001
2c68b3
 #define KEX_INITIAL	0x0002
2c68b3
+#define KEX_RSA_SHA2_256_SUPPORTED 0x0004
2c68b3
+#define KEX_RSA_SHA2_512_SUPPORTED 0x0008
2c68b3
 
2c68b3
 struct sshenc {
2c68b3
 	char	*name;
2c68b3
diff -up openssh-8.7p1/serverloop.c.minsha1 openssh-8.7p1/serverloop.c
2c68b3
--- openssh-8.7p1/serverloop.c.minsha1	2021-08-20 06:03:49.000000000 +0200
2c68b3
+++ openssh-8.7p1/serverloop.c	2021-12-21 11:01:00.594047538 +0100
2c68b3
@@ -684,7 +685,7 @@ server_input_hostkeys_prove(struct ssh *
2c68b3
 	struct sshbuf *resp = NULL;
2c68b3
 	struct sshbuf *sigbuf = NULL;
2c68b3
 	struct sshkey *key = NULL, *key_pub = NULL, *key_prv = NULL;
2c68b3
-	int r, ndx, kexsigtype, use_kexsigtype, success = 0;
2c68b3
+	int r, ndx, success = 0;
2c68b3
 	const u_char *blob;
2c68b3
 	u_char *sig = 0;
2c68b3
 	size_t blen, slen;
2c68b3
@@ -692,9 +693,11 @@ server_input_hostkeys_prove(struct ssh *
2c68b3
 	if ((resp = sshbuf_new()) == NULL || (sigbuf = sshbuf_new()) == NULL)
2c68b3
 		fatal_f("sshbuf_new");
2c68b3
 
2c68b3
-	kexsigtype = sshkey_type_plain(
2c68b3
-	    sshkey_type_from_name(ssh->kex->hostkey_alg));
2c68b3
 	while (ssh_packet_remaining(ssh) > 0) {
2c68b3
+		const char *pkexstr = NULL;
2c68b3
+		const char *rsa_sha2_256 = "rsa-sha2-256";
2c68b3
+		const char *rsa_sha2_512 = "rsa-sha2-512";
2c68b3
+
2c68b3
 		sshkey_free(key);
2c68b3
 		key = NULL;
2c68b3
 		if ((r = sshpkt_get_string_direct(ssh, &blob, &blen)) != 0 ||
2c68b3
@@ -726,8 +729,13 @@ server_input_hostkeys_prove(struct ssh *
2c68b3
 		 * For RSA keys, prefer to use the signature type negotiated
2c68b3
 		 * during KEX to the default (SHA1).
2c68b3
 		 */
2c68b3
-		use_kexsigtype = kexsigtype == KEY_RSA &&
2c68b3
-		    sshkey_type_plain(key->type) == KEY_RSA;
2c68b3
+		if (sshkey_type_plain(key->type) == KEY_RSA) {
2c68b3
+		    if (ssh->kex->flags & KEX_RSA_SHA2_512_SUPPORTED)
2c68b3
+			pkexstr = rsa_sha2_512;
2c68b3
+		    else if (ssh->kex->flags & KEX_RSA_SHA2_256_SUPPORTED)
2c68b3
+			pkexstr = rsa_sha2_256;
2c68b3
+		}
2c68b3
+
2c68b3
 		if ((r = sshbuf_put_cstring(sigbuf,
2c68b3
 		    "hostkeys-prove-00@openssh.com")) != 0 ||
2c68b3
 		    (r = sshbuf_put_stringb(sigbuf,
2c68b3
@@ -735,7 +743,7 @@ server_input_hostkeys_prove(struct ssh *
2c68b3
 		    (r = sshkey_puts(key, sigbuf)) != 0 ||
2c68b3
 		    (r = ssh->kex->sign(ssh, key_prv, key_pub, &sig, &slen,
2c68b3
 		    sshbuf_ptr(sigbuf), sshbuf_len(sigbuf),
2c68b3
-		    use_kexsigtype ? ssh->kex->hostkey_alg : NULL)) != 0 ||
2c68b3
+		    pkexstr)) != 0 ||
2c68b3
 		    (r = sshbuf_put_string(resp, sig, slen)) != 0) {
2c68b3
 			error_fr(r, "assemble signature");
2c68b3
 			goto out;