kentpeacock / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
943807
diff -up openssh-8.6p1/cipher-ctr.c.fips openssh-8.6p1/cipher-ctr.c
943807
--- openssh-8.6p1/cipher-ctr.c.fips	2021-05-06 12:08:36.423926297 +0200
943807
+++ openssh-8.6p1/cipher-ctr.c	2021-05-06 12:08:36.497926869 +0200
943807
@@ -179,7 +179,8 @@ evp_aes_128_ctr(void)
943807
 	aes_ctr.do_cipher = ssh_aes_ctr;
943807
 #ifndef SSH_OLD_EVP
943807
 	aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
943807
-	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
943807
+	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV |
943807
+	    EVP_CIPH_FLAG_FIPS;
943807
 #endif
943807
 	return (&aes_ctr);
943807
 }
943807
diff -up openssh-8.6p1/dh.c.fips openssh-8.6p1/dh.c
943807
--- openssh-8.6p1/dh.c.fips	2021-04-16 05:55:25.000000000 +0200
943807
+++ openssh-8.6p1/dh.c	2021-05-06 12:12:10.107634472 +0200
943807
@@ -164,6 +164,12 @@ choose_dh(int min, int wantbits, int max
943807
 	int best, bestcount, which, linenum;
943807
 	struct dhgroup dhg;
943807
 
943807
+	if (FIPS_mode()) {
943807
+		logit("Using arbitrary primes is not allowed in FIPS mode."
943807
+		    " Falling back to known groups.");
943807
+		return (dh_new_group_fallback(max));
943807
+	}
943807
+
943807
 	if ((f = fopen(get_moduli_filename(), "r")) == NULL) {
943807
 		logit("WARNING: could not open %s (%s), using fixed modulus",
943807
 		    get_moduli_filename(), strerror(errno));
943807
@@ -502,4 +508,38 @@ dh_estimate(int bits)
943807
 	return 8192;
943807
 }
943807
 
943807
+/*
943807
+ * Compares the received DH parameters with known-good groups,
943807
+ * which might be either from group14, group16 or group18.
943807
+ */
943807
+int
943807
+dh_is_known_group(const DH *dh)
943807
+{
943807
+	const BIGNUM *p, *g;
943807
+	const BIGNUM *known_p, *known_g;
943807
+	DH *known = NULL;
943807
+	int bits = 0, rv = 0;
943807
+
943807
+	DH_get0_pqg(dh, &p, NULL, &g);
943807
+	bits = BN_num_bits(p);
943807
+
943807
+	if (bits <= 3072) {
943807
+		known = dh_new_group14();
943807
+	} else if (bits <= 6144) {
943807
+		known = dh_new_group16();
943807
+	} else {
943807
+		known = dh_new_group18();
943807
+	}
943807
+
943807
+	DH_get0_pqg(known, &known_p, NULL, &known_g);
943807
+
943807
+	if (BN_cmp(g, known_g) == 0 &&
943807
+	    BN_cmp(p, known_p) == 0) {
943807
+		rv = 1;
943807
+	}
943807
+
943807
+	DH_free(known);
943807
+	return rv;
943807
+}
943807
+
943807
 #endif /* WITH_OPENSSL */
943807
diff -up openssh-8.6p1/dh.h.fips openssh-8.6p1/dh.h
943807
--- openssh-8.6p1/dh.h.fips	2021-05-06 12:08:36.498926877 +0200
943807
+++ openssh-8.6p1/dh.h	2021-05-06 12:11:28.393298005 +0200
943807
@@ -45,6 +45,7 @@ DH	*dh_new_group_fallback(int);
943807
 
943807
 int	 dh_gen_key(DH *, int);
943807
 int	 dh_pub_is_valid(const DH *, const BIGNUM *);
943807
+int	 dh_is_known_group(const DH *);
943807
 
943807
 u_int	 dh_estimate(int);
943807
 void	 dh_set_moduli_file(const char *);
943807
diff -up openssh-8.6p1/kex.c.fips openssh-8.6p1/kex.c
943807
--- openssh-8.6p1/kex.c.fips	2021-05-06 12:08:36.489926807 +0200
943807
+++ openssh-8.6p1/kex.c	2021-05-06 12:08:36.498926877 +0200
943807
@@ -203,7 +203,10 @@ kex_names_valid(const char *names)
943807
 	for ((p = strsep(&cp, ",")); p && *p != '\0';
943807
 	    (p = strsep(&cp, ","))) {
943807
 		if (kex_alg_by_name(p) == NULL) {
943807
-			error("Unsupported KEX algorithm \"%.100s\"", p);
943807
+			if (FIPS_mode())
943807
+				error("\"%.100s\" is not allowed in FIPS mode", p);
943807
+			else
943807
+				error("Unsupported KEX algorithm \"%.100s\"", p);
943807
 			free(s);
943807
 			return 0;
943807
 		}
943807
diff -up openssh-8.6p1/kexgexc.c.fips openssh-8.6p1/kexgexc.c
943807
--- openssh-8.6p1/kexgexc.c.fips	2021-04-16 05:55:25.000000000 +0200
943807
+++ openssh-8.6p1/kexgexc.c	2021-05-06 12:08:36.498926877 +0200
943807
@@ -28,6 +28,7 @@
943807
 
943807
 #ifdef WITH_OPENSSL
943807
 
943807
+#include <openssl/crypto.h>
943807
 #include <sys/types.h>
943807
 
943807
 #include <openssl/dh.h>
943807
@@ -115,6 +116,10 @@ input_kex_dh_gex_group(int type, u_int32
943807
 		r = SSH_ERR_ALLOC_FAIL;
943807
 		goto out;
943807
 	}
943807
+	if (FIPS_mode() && dh_is_known_group(kex->dh) == 0) {
943807
+		r = SSH_ERR_INVALID_ARGUMENT;
943807
+		goto out;
943807
+	}
943807
 	p = g = NULL; /* belong to kex->dh now */
943807
 
943807
 	/* generate and send 'e', client DH public key */
943807
diff -up openssh-8.6p1/myproposal.h.fips openssh-8.6p1/myproposal.h
943807
--- openssh-8.6p1/myproposal.h.fips	2021-04-16 05:55:25.000000000 +0200
943807
+++ openssh-8.6p1/myproposal.h	2021-05-06 12:08:36.498926877 +0200
943807
@@ -57,6 +57,20 @@
943807
 	"rsa-sha2-256," \
943807
 	"ssh-rsa"
943807
 
943807
+#define	KEX_FIPS_PK_ALG	\
943807
+	"ecdsa-sha2-nistp256-cert-v01@openssh.com," \
943807
+	"ecdsa-sha2-nistp384-cert-v01@openssh.com," \
943807
+	"ecdsa-sha2-nistp521-cert-v01@openssh.com," \
943807
+	"rsa-sha2-512-cert-v01@openssh.com," \
943807
+	"rsa-sha2-256-cert-v01@openssh.com," \
943807
+	"ssh-rsa-cert-v01@openssh.com," \
943807
+	"ecdsa-sha2-nistp256," \
943807
+	"ecdsa-sha2-nistp384," \
943807
+	"ecdsa-sha2-nistp521," \
943807
+	"rsa-sha2-512," \
943807
+	"rsa-sha2-256," \
943807
+	"ssh-rsa"
943807
+
943807
 #define	KEX_SERVER_ENCRYPT \
943807
 	"chacha20-poly1305@openssh.com," \
943807
 	"aes128-ctr,aes192-ctr,aes256-ctr," \
943807
@@ -78,6 +92,27 @@
943807
 
943807
 #define KEX_CLIENT_MAC KEX_SERVER_MAC
943807
 
943807
+#define	KEX_FIPS_ENCRYPT \
943807
+	"aes128-ctr,aes192-ctr,aes256-ctr," \
943807
+	"aes128-cbc,3des-cbc," \
943807
+	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se," \
943807
+	"aes128-gcm@openssh.com,aes256-gcm@openssh.com"
943807
+#define KEX_DEFAULT_KEX_FIPS		\
943807
+	"ecdh-sha2-nistp256," \
943807
+	"ecdh-sha2-nistp384," \
943807
+	"ecdh-sha2-nistp521," \
943807
+	"diffie-hellman-group-exchange-sha256," \
943807
+	"diffie-hellman-group16-sha512," \
943807
+	"diffie-hellman-group18-sha512," \
943807
+	"diffie-hellman-group14-sha256"
943807
+#define KEX_FIPS_MAC \
943807
+	"hmac-sha1," \
943807
+	"hmac-sha2-256," \
943807
+	"hmac-sha2-512," \
943807
+	"hmac-sha1-etm@openssh.com," \
943807
+	"hmac-sha2-256-etm@openssh.com," \
943807
+	"hmac-sha2-512-etm@openssh.com"
943807
+
943807
 /* Not a KEX value, but here so all the algorithm defaults are together */
943807
 #define	SSH_ALLOWED_CA_SIGALGS	\
943807
 	"ssh-ed25519," \
943807
diff -up openssh-8.6p1/readconf.c.fips openssh-8.6p1/readconf.c
943807
--- openssh-8.6p1/readconf.c.fips	2021-05-06 12:08:36.428926336 +0200
943807
+++ openssh-8.6p1/readconf.c	2021-05-06 12:08:36.499926885 +0200
943807
@@ -2538,11 +2538,16 @@ fill_default_options(Options * options)
943807
 	all_key = sshkey_alg_list(0, 0, 1, ',');
943807
 	all_sig = sshkey_alg_list(0, 1, 1, ',');
943807
 	/* remove unsupported algos from default lists */
943807
-	def_cipher = match_filter_allowlist(KEX_CLIENT_ENCRYPT, all_cipher);
943807
-	def_mac = match_filter_allowlist(KEX_CLIENT_MAC, all_mac);
943807
-	def_kex = match_filter_allowlist(KEX_CLIENT_KEX, all_kex);
943807
-	def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
943807
-	def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
943807
+	def_cipher = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_FIPS_ENCRYPT : KEX_CLIENT_ENCRYPT), all_cipher);
943807
+	def_mac = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_FIPS_MAC : KEX_CLIENT_MAC), all_mac);
943807
+	def_kex = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_DEFAULT_KEX_FIPS : KEX_CLIENT_KEX), all_kex);
943807
+	def_key = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG), all_key);
943807
+	def_sig = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_FIPS_PK_ALG : SSH_ALLOWED_CA_SIGALGS), all_sig);
943807
 #define ASSEMBLE(what, defaults, all) \
943807
 	do { \
943807
 		if ((r = kex_assemble_names(&options->what, \
943807
diff -up openssh-8.6p1/sandbox-seccomp-filter.c.fips openssh-8.6p1/sandbox-seccomp-filter.c
943807
--- openssh-8.6p1/sandbox-seccomp-filter.c.fips	2021-05-06 12:08:36.463926606 +0200
943807
+++ openssh-8.6p1/sandbox-seccomp-filter.c	2021-05-06 12:08:36.499926885 +0200
943807
@@ -160,6 +160,9 @@ static const struct sock_filter preauth_
943807
 #ifdef __NR_open
943807
 	SC_DENY(__NR_open, EACCES),
943807
 #endif
943807
+#ifdef __NR_socket
943807
+	SC_DENY(__NR_socket, EACCES),
943807
+#endif
943807
 #ifdef __NR_openat
943807
 	SC_DENY(__NR_openat, EACCES),
943807
 #endif
943807
diff -up openssh-8.6p1/servconf.c.fips openssh-8.6p1/servconf.c
943807
--- openssh-8.6p1/servconf.c.fips	2021-05-06 12:08:36.455926545 +0200
943807
+++ openssh-8.6p1/servconf.c	2021-05-06 12:08:36.500926893 +0200
943807
@@ -226,11 +226,16 @@ assemble_algorithms(ServerOptions *o)
943807
 	all_key = sshkey_alg_list(0, 0, 1, ',');
943807
 	all_sig = sshkey_alg_list(0, 1, 1, ',');
943807
 	/* remove unsupported algos from default lists */
943807
-	def_cipher = match_filter_allowlist(KEX_SERVER_ENCRYPT, all_cipher);
943807
-	def_mac = match_filter_allowlist(KEX_SERVER_MAC, all_mac);
943807
-	def_kex = match_filter_allowlist(KEX_SERVER_KEX, all_kex);
943807
-	def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
943807
-	def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
943807
+	def_cipher = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_FIPS_ENCRYPT : KEX_SERVER_ENCRYPT), all_cipher);
943807
+	def_mac = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_FIPS_MAC : KEX_SERVER_MAC), all_mac);
943807
+	def_kex = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_DEFAULT_KEX_FIPS : KEX_SERVER_KEX), all_kex);
943807
+	def_key = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG), all_key);
943807
+	def_sig = match_filter_allowlist((FIPS_mode() ?
943807
+	    KEX_FIPS_PK_ALG : SSH_ALLOWED_CA_SIGALGS), all_sig);
943807
 #define ASSEMBLE(what, defaults, all) \
943807
 	do { \
943807
 		if ((r = kex_assemble_names(&o->what, defaults, all)) != 0) \
943807
diff -up openssh-8.6p1/ssh.c.fips openssh-8.6p1/ssh.c
943807
--- openssh-8.6p1/ssh.c.fips	2021-05-06 12:08:36.467926637 +0200
943807
+++ openssh-8.6p1/ssh.c	2021-05-06 12:08:36.500926893 +0200
943807
@@ -77,6 +77,7 @@
943807
 #include <openssl/evp.h>
943807
 #include <openssl/err.h>
943807
 #endif
943807
+#include <openssl/crypto.h>
943807
 #include "openbsd-compat/openssl-compat.h"
943807
 #include "openbsd-compat/sys-queue.h"
943807
 
943807
@@ -1516,6 +1517,10 @@ main(int ac, char **av)
943807
 		exit(0);
943807
 	}
943807
 
943807
+	if (FIPS_mode()) {
943807
+		debug("FIPS mode initialized");
943807
+	}
943807
+
943807
 	/* Expand SecurityKeyProvider if it refers to an environment variable */
943807
 	if (options.sk_provider != NULL && *options.sk_provider == '$' &&
943807
 	    strlen(options.sk_provider) > 1) {
943807
diff -up openssh-8.6p1/sshconnect2.c.fips openssh-8.6p1/sshconnect2.c
943807
--- openssh-8.6p1/sshconnect2.c.fips	2021-05-06 12:08:36.485926777 +0200
943807
+++ openssh-8.6p1/sshconnect2.c	2021-05-06 12:08:36.501926900 +0200
943807
@@ -45,6 +45,8 @@
943807
 #include <vis.h>
943807
 #endif
943807
 
943807
+#include <openssl/crypto.h>
943807
+
943807
 #include "openbsd-compat/sys-queue.h"
943807
 
943807
 #include "xmalloc.h"
943807
@@ -269,36 +271,41 @@ ssh_kex2(struct ssh *ssh, char *host, st
943807
 
943807
 #if defined(GSSAPI) && defined(WITH_OPENSSL)
943807
 	if (options.gss_keyex) {
943807
-		/* Add the GSSAPI mechanisms currently supported on this
943807
-		 * client to the key exchange algorithm proposal */
943807
-		orig = myproposal[PROPOSAL_KEX_ALGS];
943807
-
943807
-		if (options.gss_server_identity) {
943807
-			gss_host = xstrdup(options.gss_server_identity);
943807
-		} else if (options.gss_trust_dns) {
943807
-			gss_host = remote_hostname(ssh);
943807
-			/* Fall back to specified host if we are using proxy command
943807
-			 * and can not use DNS on that socket */
943807
-			if (strcmp(gss_host, "UNKNOWN") == 0) {
943807
-				free(gss_host);
943807
+		if (FIPS_mode()) {
943807
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
943807
+			options.gss_keyex = 0;
943807
+		} else {
943807
+			/* Add the GSSAPI mechanisms currently supported on this
943807
+			 * client to the key exchange algorithm proposal */
943807
+			orig = myproposal[PROPOSAL_KEX_ALGS];
943807
+
943807
+			if (options.gss_server_identity) {
943807
+				gss_host = xstrdup(options.gss_server_identity);
943807
+			} else if (options.gss_trust_dns) {
943807
+				gss_host = remote_hostname(ssh);
943807
+				/* Fall back to specified host if we are using proxy command
943807
+				 * and can not use DNS on that socket */
943807
+				if (strcmp(gss_host, "UNKNOWN") == 0) {
943807
+					free(gss_host);
943807
+					gss_host = xstrdup(host);
943807
+				}
943807
+			} else {
943807
 				gss_host = xstrdup(host);
943807
 			}
943807
-		} else {
943807
-			gss_host = xstrdup(host);
943807
-		}
943807
 
943807
-		gss = ssh_gssapi_client_mechanisms(gss_host,
943807
-		    options.gss_client_identity, options.gss_kex_algorithms);
943807
-		if (gss) {
943807
-			debug("Offering GSSAPI proposal: %s", gss);
943807
-			xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
943807
-			    "%s,%s", gss, orig);
943807
-
943807
-			/* If we've got GSSAPI algorithms, then we also support the
943807
-			 * 'null' hostkey, as a last resort */
943807
-			orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
943807
-			xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
943807
-			    "%s,null", orig);
943807
+			gss = ssh_gssapi_client_mechanisms(gss_host,
943807
+			    options.gss_client_identity, options.gss_kex_algorithms);
943807
+			if (gss) {
943807
+				debug("Offering GSSAPI proposal: %s", gss);
943807
+				xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
943807
+				    "%s,%s", gss, orig);
943807
+
943807
+				/* If we've got GSSAPI algorithms, then we also support the
943807
+				 * 'null' hostkey, as a last resort */
943807
+				orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
943807
+				xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
943807
+				    "%s,null", orig);
943807
+			}
943807
 		}
943807
 	}
943807
 #endif
943807
diff -up openssh-8.6p1/sshd.c.fips openssh-8.6p1/sshd.c
943807
--- openssh-8.6p1/sshd.c.fips	2021-05-06 12:08:36.493926838 +0200
943807
+++ openssh-8.6p1/sshd.c	2021-05-06 12:13:56.501492639 +0200
943807
@@ -66,6 +66,7 @@
943807
 #include <grp.h>
943807
 #include <pwd.h>
943807
 #include <signal.h>
943807
+#include <syslog.h>
943807
 #include <stdarg.h>
943807
 #include <stdio.h>
943807
 #include <stdlib.h>
943807
@@ -77,6 +78,7 @@
943807
 #include <openssl/dh.h>
943807
 #include <openssl/bn.h>
943807
 #include <openssl/rand.h>
943807
+#include <openssl/crypto.h>
943807
 #include "openbsd-compat/openssl-compat.h"
943807
 #endif
943807
 
943807
@@ -1619,6 +1621,7 @@ main(int ac, char **av)
943807
 #endif
943807
 	__progname = ssh_get_progname(av[0]);
943807
 
943807
+	OpenSSL_add_all_algorithms();
943807
 	/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
943807
 	saved_argc = ac;
943807
 	rexec_argc = ac;
943807
@@ -2110,6 +2113,10 @@ main(int ac, char **av)
943807
 	/* Reinitialize the log (because of the fork above). */
943807
 	log_init(__progname, options.log_level, options.log_facility, log_stderr);
943807
 
943807
+	if (FIPS_mode()) {
943807
+		debug("FIPS mode initialized");
943807
+	}
943807
+
943807
 	/*
943807
 	 * Chdir to the root directory so that the current disk can be
943807
 	 * unmounted if desired.
943807
@@ -2494,10 +2501,14 @@ do_ssh2_kex(struct ssh *ssh)
943807
 	if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
943807
 		orig = NULL;
943807
 
943807
-	if (options.gss_keyex)
943807
-		gss = ssh_gssapi_server_mechanisms();
943807
-	else
943807
-		gss = NULL;
943807
+	if (options.gss_keyex) {
943807
+		if (FIPS_mode()) {
943807
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
943807
+			options.gss_keyex = 0;
943807
+		} else {
943807
+			gss = ssh_gssapi_server_mechanisms();
943807
+		}
943807
+	}
943807
 
943807
 	if (gss && orig)
943807
 		xasprintf(&newstr, "%s,%s", gss, orig);
943807
diff -up openssh-8.6p1/sshkey.c.fips openssh-8.6p1/sshkey.c
943807
--- openssh-8.6p1/sshkey.c.fips	2021-05-06 12:08:36.493926838 +0200
943807
+++ openssh-8.6p1/sshkey.c	2021-05-06 12:08:36.502926908 +0200
943807
@@ -34,6 +34,7 @@
943807
 #include <openssl/evp.h>
943807
 #include <openssl/err.h>
943807
 #include <openssl/pem.h>
943807
+#include <openssl/crypto.h>
943807
 #endif
943807
 
943807
 #include "crypto_api.h"
943807
@@ -57,6 +58,7 @@
943807
 #define SSHKEY_INTERNAL
943807
 #include "sshkey.h"
943807
 #include "match.h"
943807
+#include "log.h"
943807
 #include "ssh-sk.h"
943807
 
943807
 #ifdef WITH_XMSS
943807
@@ -1705,6 +1707,8 @@ rsa_generate_private_key(u_int bits, RSA
943807
 	}
943807
 	if (!BN_set_word(f4, RSA_F4) ||
943807
 	    !RSA_generate_key_ex(private, bits, f4, NULL)) {
943807
+			if (FIPS_mode())
943807
+				logit_f("the key length might be unsupported by FIPS mode approved key generation method");
943807
 		ret = SSH_ERR_LIBCRYPTO_ERROR;
943807
 		goto out;
943807
 	}
943807
diff -up openssh-8.6p1/ssh-keygen.c.fips openssh-8.6p1/ssh-keygen.c
943807
--- openssh-8.6p1/ssh-keygen.c.fips	2021-05-06 12:08:36.467926637 +0200
943807
+++ openssh-8.6p1/ssh-keygen.c	2021-05-06 12:08:36.503926916 +0200
943807
@@ -205,6 +205,12 @@ type_bits_valid(int type, const char *na
943807
 #endif
943807
 	}
943807
 #ifdef WITH_OPENSSL
943807
+	if (FIPS_mode()) {
943807
+		if (type == KEY_DSA)
943807
+			fatal("DSA keys are not allowed in FIPS mode");
943807
+		if (type == KEY_ED25519)
943807
+			fatal("ED25519 keys are not allowed in FIPS mode");
943807
+	}
943807
 	switch (type) {
943807
 	case KEY_DSA:
943807
 		if (*bitsp != 1024)
943807
@@ -1098,9 +1104,17 @@ do_gen_all_hostkeys(struct passwd *pw)
943807
 			first = 1;
943807
 			printf("%s: generating new host keys: ", __progname);
943807
 		}
943807
+		type = sshkey_type_from_name(key_types[i].key_type);
943807
+
943807
+		/* Skip the keys that are not supported in FIPS mode */
943807
+		if (FIPS_mode() && (type == KEY_DSA || type == KEY_ED25519)) {
943807
+			logit("Skipping %s key in FIPS mode",
943807
+			    key_types[i].key_type_display);
943807
+			goto next;
943807
+		}
943807
+
943807
 		printf("%s ", key_types[i].key_type_display);
943807
 		fflush(stdout);
943807
-		type = sshkey_type_from_name(key_types[i].key_type);
943807
 		if ((fd = mkstemp(prv_tmp)) == -1) {
943807
 			error("Could not save your private key in %s: %s",
943807
 			    prv_tmp, strerror(errno));