rutwa189 / rpms / openssh

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