rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone

Blame SOURCES/openssh-7.4p1-show-more-fingerprints.patch

b58e57
diff -up openssh-7.4p1/clientloop.c.fingerprint openssh-7.4p1/clientloop.c
b58e57
--- openssh-7.4p1/clientloop.c.fingerprint	2016-12-23 15:38:50.520432387 +0100
b58e57
+++ openssh-7.4p1/clientloop.c	2016-12-23 15:38:50.564432394 +0100
b58e57
@@ -2279,7 +2279,7 @@ update_known_hosts(struct hostkeys_updat
b58e57
 		if (ctx->keys_seen[i] != 2)
b58e57
 			continue;
b58e57
 		if ((fp = sshkey_fingerprint(ctx->keys[i],
b58e57
-		    options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL)
b58e57
+		    options.fingerprint_hash[0], SSH_FP_DEFAULT)) == NULL)
b58e57
 			fatal("%s: sshkey_fingerprint failed", __func__);
b58e57
 		do_log2(loglevel, "Learned new hostkey: %s %s",
b58e57
 		    sshkey_type(ctx->keys[i]), fp);
b58e57
@@ -2287,7 +2287,7 @@ update_known_hosts(struct hostkeys_updat
b58e57
 	}
b58e57
 	for (i = 0; i < ctx->nold; i++) {
b58e57
 		if ((fp = sshkey_fingerprint(ctx->old_keys[i],
b58e57
-		    options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL)
b58e57
+		    options.fingerprint_hash[0], SSH_FP_DEFAULT)) == NULL)
b58e57
 			fatal("%s: sshkey_fingerprint failed", __func__);
b58e57
 		do_log2(loglevel, "Deprecating obsolete hostkey: %s %s",
b58e57
 		    sshkey_type(ctx->old_keys[i]), fp);
b58e57
@@ -2330,7 +2330,7 @@ update_known_hosts(struct hostkeys_updat
b58e57
 	    (r = hostfile_replace_entries(options.user_hostfiles[0],
b58e57
 	    ctx->host_str, ctx->ip_str, ctx->keys, ctx->nkeys,
b58e57
 	    options.hash_known_hosts, 0,
b58e57
-	    options.fingerprint_hash)) != 0)
b58e57
+	    options.fingerprint_hash[0])) != 0)
b58e57
 		error("%s: hostfile_replace_entries failed: %s",
b58e57
 		    __func__, ssh_err(r));
b58e57
 }
b58e57
@@ -2443,7 +2443,7 @@ client_input_hostkeys(void)
b58e57
 			error("%s: parse key: %s", __func__, ssh_err(r));
b58e57
 			goto out;
b58e57
 		}
b58e57
-		fp = sshkey_fingerprint(key, options.fingerprint_hash,
b58e57
+		fp = sshkey_fingerprint(key, options.fingerprint_hash[0],
b58e57
 		    SSH_FP_DEFAULT);
b58e57
 		debug3("%s: received %s key %s", __func__,
b58e57
 		    sshkey_type(key), fp);
b58e57
diff -up openssh-7.4p1/readconf.c.fingerprint openssh-7.4p1/readconf.c
b58e57
--- openssh-7.4p1/readconf.c.fingerprint	2016-12-23 15:38:50.559432393 +0100
b58e57
+++ openssh-7.4p1/readconf.c	2016-12-23 15:38:50.565432394 +0100
b58e57
@@ -1668,16 +1668,18 @@ parse_keytypes:
b58e57
 		goto parse_string;
b58e57
 
b58e57
 	case oFingerprintHash:
b58e57
-		intptr = &options->fingerprint_hash;
b58e57
-		arg = strdelim(&s);
b58e57
-		if (!arg || *arg == '\0')
b58e57
-			fatal("%.200s line %d: Missing argument.",
b58e57
-			    filename, linenum);
b58e57
-		if ((value = ssh_digest_alg_by_name(arg)) == -1)
b58e57
-			fatal("%.200s line %d: Invalid hash algorithm \"%s\".",
b58e57
-			    filename, linenum, arg);
b58e57
-		if (*activep && *intptr == -1)
b58e57
-			*intptr = value;
b58e57
+		if (*activep && options->num_fingerprint_hash == 0)
b58e57
+			while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
b58e57
+				value = ssh_digest_alg_by_name(arg);
b58e57
+				if (value == -1)
b58e57
+					fatal("%s line %d: unknown fingerprints algorithm specs: %s.",
b58e57
+						filename, linenum, arg);
b58e57
+				if (options->num_fingerprint_hash >= SSH_DIGEST_MAX)
b58e57
+					fatal("%s line %d: too many fingerprints algorithm specs.",
b58e57
+						filename, linenum);
b58e57
+				options->fingerprint_hash[
b58e57
+					options->num_fingerprint_hash++] = value;
b58e57
+			}
b58e57
 		break;
b58e57
 
b58e57
 	case oUpdateHostkeys:
b58e57
@@ -1905,7 +1907,7 @@ initialize_options(Options * options)
b58e57
 	options->canonicalize_fallback_local = -1;
b58e57
 	options->canonicalize_hostname = -1;
b58e57
 	options->revoked_host_keys = NULL;
b58e57
-	options->fingerprint_hash = -1;
b58e57
+	options->num_fingerprint_hash = 0;
b58e57
 	options->update_hostkeys = -1;
b58e57
 	options->hostbased_key_types = NULL;
b58e57
 	options->pubkey_key_types = NULL;
b58e57
@@ -2102,8 +2104,10 @@ fill_default_options(Options * options)
b58e57
 		options->canonicalize_fallback_local = 1;
b58e57
 	if (options->canonicalize_hostname == -1)
b58e57
 		options->canonicalize_hostname = SSH_CANONICALISE_NO;
b58e57
-	if (options->fingerprint_hash == -1)
b58e57
-		options->fingerprint_hash = SSH_FP_HASH_DEFAULT;
b58e57
+	if (options->num_fingerprint_hash == 0) {
b58e57
+		options->fingerprint_hash[options->num_fingerprint_hash++] = SSH_DIGEST_SHA256;
b58e57
+		options->fingerprint_hash[options->num_fingerprint_hash++] = (FIPS_mode() ? SSH_DIGEST_SHA1 : SSH_DIGEST_MD5);
b58e57
+	}
b58e57
 	if (options->update_hostkeys == -1)
b58e57
 		options->update_hostkeys = 0;
b58e57
 	if (kex_assemble_names(KEX_CLIENT_ENCRYPT, &options->ciphers) != 0 ||
b58e57
@@ -2489,6 +2493,17 @@ dump_cfg_strarray(OpCodes code, u_int co
b58e57
 }
b58e57
 
b58e57
 static void
b58e57
+dump_cfg_fmtarray(OpCodes code, u_int count, int *vals)
b58e57
+{
b58e57
+	u_int i;
b58e57
+
b58e57
+	printf("%s", lookup_opcode_name(code));
b58e57
+	for (i = 0; i < count; i++)
b58e57
+		printf(" %s", fmt_intarg(code, vals[i]));
b58e57
+	printf("\n");
b58e57
+}
b58e57
+
b58e57
+static void
b58e57
 dump_cfg_strarray_oneline(OpCodes code, u_int count, char **vals)
b58e57
 {
b58e57
 	u_int i;
b58e57
@@ -2564,7 +2579,6 @@ dump_client_config(Options *o, const cha
b58e57
 	dump_cfg_fmtint(oEnableSSHKeysign, o->enable_ssh_keysign);
b58e57
 	dump_cfg_fmtint(oClearAllForwardings, o->clear_forwardings);
b58e57
 	dump_cfg_fmtint(oExitOnForwardFailure, o->exit_on_forward_failure);
b58e57
-	dump_cfg_fmtint(oFingerprintHash, o->fingerprint_hash);
b58e57
 	dump_cfg_fmtint(oForwardAgent, o->forward_agent);
b58e57
 	dump_cfg_fmtint(oForwardX11, o->forward_x11);
b58e57
 	dump_cfg_fmtint(oForwardX11Trusted, o->forward_x11_trusted);
b58e57
@@ -2634,6 +2648,7 @@ dump_client_config(Options *o, const cha
b58e57
 	dump_cfg_strarray_oneline(oGlobalKnownHostsFile, o->num_system_hostfiles, o->system_hostfiles);
b58e57
 	dump_cfg_strarray_oneline(oUserKnownHostsFile, o->num_user_hostfiles, o->user_hostfiles);
b58e57
 	dump_cfg_strarray(oSendEnv, o->num_send_env, o->send_env);
b58e57
+	dump_cfg_fmtarray(oFingerprintHash, o->num_fingerprint_hash, o->fingerprint_hash);
b58e57
 
b58e57
 	/* Special cases */
b58e57
 
b58e57
diff -up openssh-7.4p1/readconf.h.fingerprint openssh-7.4p1/readconf.h
b58e57
--- openssh-7.4p1/readconf.h.fingerprint	2016-12-23 15:38:50.559432393 +0100
b58e57
+++ openssh-7.4p1/readconf.h	2016-12-23 15:38:50.565432394 +0100
b58e57
@@ -21,6 +21,7 @@
b58e57
 #define MAX_SEND_ENV		256
b58e57
 #define SSH_MAX_HOSTS_FILES	32
b58e57
 #define MAX_CANON_DOMAINS	32
b58e57
+#define MAX_SSH_DIGESTS	8
b58e57
 #define PATH_MAX_SUN		(sizeof((struct sockaddr_un *)0)->sun_path)
b58e57
 
b58e57
 struct allowed_cname {
b58e57
@@ -162,7 +163,8 @@ typedef struct {
b58e57
 
b58e57
 	char	*revoked_host_keys;
b58e57
 
b58e57
-	int	 fingerprint_hash;
b58e57
+	int num_fingerprint_hash;
b58e57
+	int 	fingerprint_hash[MAX_SSH_DIGESTS];
b58e57
 
b58e57
 	int	 update_hostkeys; /* one of SSH_UPDATE_HOSTKEYS_* */
b58e57
 
b58e57
diff -up openssh-7.4p1/ssh_config.5.fingerprint openssh-7.4p1/ssh_config.5
b58e57
--- openssh-7.4p1/ssh_config.5.fingerprint	2016-12-23 15:38:50.565432394 +0100
b58e57
+++ openssh-7.4p1/ssh_config.5	2016-12-23 15:40:03.754444166 +0100
b58e57
@@ -652,12 +652,13 @@ or
b58e57
 .Cm no
b58e57
 (the default).
b58e57
 .It Cm FingerprintHash
b58e57
-Specifies the hash algorithm used when displaying key fingerprints.
b58e57
+Specifies the hash algorithms used when displaying key fingerprints.
b58e57
 Valid options are:
b58e57
 .Cm md5
b58e57
 and
b58e57
-.Cm sha256
b58e57
-(the default).
b58e57
+.Cm sha256 .
b58e57
+The default is
b58e57
+.Cm "sha256 md5".
b58e57
 .It Cm ForwardAgent
b58e57
 Specifies whether the connection to the authentication agent (if any)
b58e57
 will be forwarded to the remote machine.
b58e57
diff -up openssh-7.4p1/sshconnect2.c.fingerprint openssh-7.4p1/sshconnect2.c
b58e57
--- openssh-7.4p1/sshconnect2.c.fingerprint	2016-12-23 15:38:50.561432394 +0100
b58e57
+++ openssh-7.4p1/sshconnect2.c	2016-12-23 15:38:50.566432394 +0100
b58e57
@@ -677,7 +677,7 @@ input_userauth_pk_ok(int type, u_int32_t
b58e57
 		    key->type, pktype);
b58e57
 		goto done;
b58e57
 	}
b58e57
-	if ((fp = sshkey_fingerprint(key, options.fingerprint_hash,
b58e57
+	if ((fp = sshkey_fingerprint(key, options.fingerprint_hash[0],
b58e57
 	    SSH_FP_DEFAULT)) == NULL)
b58e57
 		goto done;
b58e57
 	debug2("input_userauth_pk_ok: fp %s", fp);
b58e57
@@ -1172,7 +1172,7 @@ sign_and_send_pubkey(Authctxt *authctxt,
b58e57
 	int matched, ret = -1, have_sig = 1;
b58e57
 	char *fp;
b58e57
 
b58e57
-	if ((fp = sshkey_fingerprint(id->key, options.fingerprint_hash,
b58e57
+	if ((fp = sshkey_fingerprint(id->key, options.fingerprint_hash[0],
b58e57
 	    SSH_FP_DEFAULT)) == NULL)
b58e57
 		return 0;
b58e57
 	debug3("%s: %s %s", __func__, key_type(id->key), fp);
b58e57
@@ -1864,7 +1864,7 @@ userauth_hostbased(Authctxt *authctxt)
b58e57
 		goto out;
b58e57
 	}
b58e57
 
b58e57
-	if ((fp = sshkey_fingerprint(private, options.fingerprint_hash,
b58e57
+	if ((fp = sshkey_fingerprint(private, options.fingerprint_hash[0],
b58e57
 	    SSH_FP_DEFAULT)) == NULL) {
b58e57
 		error("%s: sshkey_fingerprint failed", __func__);
b58e57
 		goto out;
b58e57
diff -up openssh-7.4p1/sshconnect.c.fingerprint openssh-7.4p1/sshconnect.c
b58e57
--- openssh-7.4p1/sshconnect.c.fingerprint	2016-12-19 05:59:41.000000000 +0100
b58e57
+++ openssh-7.4p1/sshconnect.c	2016-12-23 15:38:50.566432394 +0100
b58e57
@@ -922,9 +922,9 @@ check_host_key(char *hostname, struct so
b58e57
 				    "of known hosts.", type, ip);
b58e57
 		} else if (options.visual_host_key) {
b58e57
 			fp = sshkey_fingerprint(host_key,
b58e57
-			    options.fingerprint_hash, SSH_FP_DEFAULT);
b58e57
+			    options.fingerprint_hash[0], SSH_FP_DEFAULT);
b58e57
 			ra = sshkey_fingerprint(host_key,
b58e57
-			    options.fingerprint_hash, SSH_FP_RANDOMART);
b58e57
+			    options.fingerprint_hash[0], SSH_FP_RANDOMART);
b58e57
 			if (fp == NULL || ra == NULL)
b58e57
 				fatal("%s: sshkey_fingerprint fail", __func__);
b58e57
 			logit("Host key fingerprint is %s\n%s", fp, ra);
b58e57
@@ -966,12 +966,6 @@ check_host_key(char *hostname, struct so
b58e57
 			else
b58e57
 				snprintf(msg1, sizeof(msg1), ".");
b58e57
 			/* The default */
b58e57
-			fp = sshkey_fingerprint(host_key,
b58e57
-			    options.fingerprint_hash, SSH_FP_DEFAULT);
b58e57
-			ra = sshkey_fingerprint(host_key,
b58e57
-			    options.fingerprint_hash, SSH_FP_RANDOMART);
b58e57
-			if (fp == NULL || ra == NULL)
b58e57
-				fatal("%s: sshkey_fingerprint fail", __func__);
b58e57
 			msg2[0] = '\0';
b58e57
 			if (options.verify_host_key_dns) {
b58e57
 				if (matching_host_key_dns)
b58e57
@@ -985,16 +979,28 @@ check_host_key(char *hostname, struct so
b58e57
 			}
b58e57
 			snprintf(msg, sizeof(msg),
b58e57
 			    "The authenticity of host '%.200s (%s)' can't be "
b58e57
-			    "established%s\n"
b58e57
-			    "%s key fingerprint is %s.%s%s\n%s"
b58e57
+			    "established%s\n", host, ip, msg1);
b58e57
+			for (i = 0; i < (u_int) options.num_fingerprint_hash; i++) {
b58e57
+				fp = sshkey_fingerprint(host_key,
b58e57
+				    options.fingerprint_hash[i], SSH_FP_DEFAULT);
b58e57
+				ra = sshkey_fingerprint(host_key,
b58e57
+				    options.fingerprint_hash[i], SSH_FP_RANDOMART);
b58e57
+				if (fp == NULL || ra == NULL)
b58e57
+					fatal("%s: sshkey_fingerprint fail", __func__);
b58e57
+				len = strlen(msg);
b58e57
+				snprintf(msg+len, sizeof(msg)-len,
b58e57
+				    "%s key fingerprint is %s.%s%s\n%s",
b58e57
+				    type, fp,
b58e57
+				    options.visual_host_key ? "\n" : "",
b58e57
+				    options.visual_host_key ? ra : "",
b58e57
+				    msg2);
b58e57
+				free(ra);
b58e57
+				free(fp);
b58e57
+			}
b58e57
+			len = strlen(msg);
b58e57
+			snprintf(msg+len, sizeof(msg)-len,
b58e57
 			    "Are you sure you want to continue connecting "
b58e57
-			    "(yes/no)? ",
b58e57
-			    host, ip, msg1, type, fp,
b58e57
-			    options.visual_host_key ? "\n" : "",
b58e57
-			    options.visual_host_key ? ra : "",
b58e57
-			    msg2);
b58e57
-			free(ra);
b58e57
-			free(fp);
b58e57
+			    "(yes/no)? ");
b58e57
 			if (!confirm(msg))
b58e57
 				goto fail;
b58e57
 			hostkey_trusted = 1; /* user explicitly confirmed */
b58e57
@@ -1244,7 +1250,7 @@ verify_host_key(char *host, struct socka
b58e57
 	struct sshkey *plain = NULL;
b58e57
 
b58e57
 	if ((fp = sshkey_fingerprint(host_key,
b58e57
-	    options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL) {
b58e57
+	    options.fingerprint_hash[0], SSH_FP_DEFAULT)) == NULL) {
b58e57
 		error("%s: fingerprint host key: %s", __func__, ssh_err(r));
b58e57
 		r = -1;
b58e57
 		goto out;
b58e57
@@ -1252,7 +1258,7 @@ verify_host_key(char *host, struct socka
b58e57
 
b58e57
 	if (sshkey_is_cert(host_key)) {
b58e57
 		if ((cafp = sshkey_fingerprint(host_key->cert->signature_key,
b58e57
-		    options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL) {
b58e57
+		    options.fingerprint_hash[0], SSH_FP_DEFAULT)) == NULL) {
b58e57
 			error("%s: fingerprint CA key: %s",
b58e57
 			    __func__, ssh_err(r));
b58e57
 			r = -1;
b58e57
@@ -1432,9 +1438,9 @@ show_other_keys(struct hostkeys *hostkey
b58e57
 		if (!lookup_key_in_hostkeys_by_type(hostkeys, type[i], &found))
b58e57
 			continue;
b58e57
 		fp = sshkey_fingerprint(found->key,
b58e57
-		    options.fingerprint_hash, SSH_FP_DEFAULT);
b58e57
+		    options.fingerprint_hash[0], SSH_FP_DEFAULT);
b58e57
 		ra = sshkey_fingerprint(found->key,
b58e57
-		    options.fingerprint_hash, SSH_FP_RANDOMART);
b58e57
+		    options.fingerprint_hash[0], SSH_FP_RANDOMART);
b58e57
 		if (fp == NULL || ra == NULL)
b58e57
 			fatal("%s: sshkey_fingerprint fail", __func__);
b58e57
 		logit("WARNING: %s key found for host %s\n"
b58e57
@@ -1457,7 +1463,7 @@ warn_changed_key(Key *host_key)
b58e57
 {
b58e57
 	char *fp;
b58e57
 
b58e57
-	fp = sshkey_fingerprint(host_key, options.fingerprint_hash,
b58e57
+	fp = sshkey_fingerprint(host_key, options.fingerprint_hash[0],
b58e57
 	    SSH_FP_DEFAULT);
b58e57
 	if (fp == NULL)
b58e57
 		fatal("%s: sshkey_fingerprint fail", __func__);
b58e57
diff -up openssh-7.4p1/ssh-keysign.c.fingerprint openssh-7.4p1/ssh-keysign.c
b58e57
--- openssh-7.4p1/ssh-keysign.c.fingerprint	2016-12-19 05:59:41.000000000 +0100
b58e57
+++ openssh-7.4p1/ssh-keysign.c	2016-12-23 15:38:50.566432394 +0100
b58e57
@@ -285,7 +285,7 @@ main(int argc, char **argv)
b58e57
 		}
b58e57
 	}
b58e57
 	if (!found) {
b58e57
-		if ((fp = sshkey_fingerprint(key, options.fingerprint_hash,
b58e57
+		if ((fp = sshkey_fingerprint(key, options.fingerprint_hash[0],
b58e57
 		    SSH_FP_DEFAULT)) == NULL)
b58e57
 			fatal("%s: sshkey_fingerprint failed", __progname);
b58e57
 		fatal("no matching hostkey found for key %s %s",