rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
aedd00
diff -up openssh-7.9p1/cipher-ctr.c.fips openssh-7.9p1/cipher-ctr.c
aedd00
--- openssh-7.9p1/cipher-ctr.c.fips	2019-03-11 17:06:37.519877082 +0100
aedd00
+++ openssh-7.9p1/cipher-ctr.c	2019-03-11 17:06:37.620878031 +0100
aedd00
@@ -179,7 +179,8 @@ evp_aes_128_ctr(void)
aedd00
 	aes_ctr.do_cipher = ssh_aes_ctr;
aedd00
 #ifndef SSH_OLD_EVP
aedd00
 	aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
aedd00
-	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
aedd00
+	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV |
aedd00
+	    EVP_CIPH_FLAG_FIPS;
aedd00
 #endif
aedd00
 	return (&aes_ctr);
aedd00
 }
aedd00
diff -up openssh-7.9p1/clientloop.c.fips openssh-7.9p1/clientloop.c
aedd00
--- openssh-7.9p1/clientloop.c.fips	2019-03-11 17:06:37.523877120 +0100
aedd00
+++ openssh-7.9p1/clientloop.c	2019-03-11 17:06:37.620878031 +0100
aedd00
@@ -2014,7 +2014,8 @@ key_accepted_by_hostkeyalgs(const struct
aedd00
 {
aedd00
 	const char *ktype = sshkey_ssh_name(key);
aedd00
 	const char *hostkeyalgs = options.hostkeyalgorithms != NULL ?
aedd00
-	    options.hostkeyalgorithms : KEX_DEFAULT_PK_ALG;
aedd00
+	    options.hostkeyalgorithms : (FIPS_mode() ?
aedd00
+	    KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG);
aedd00
 
aedd00
 	if (key == NULL || key->type == KEY_UNSPEC)
aedd00
 		return 0;
aedd00
diff -up openssh-7.9p1/dh.c.fips openssh-7.9p1/dh.c
aedd00
--- openssh-7.9p1/dh.c.fips	2018-10-17 02:01:20.000000000 +0200
aedd00
+++ openssh-7.9p1/dh.c	2019-03-11 17:08:11.769763057 +0100
aedd00
@@ -152,6 +152,12 @@ choose_dh(int min, int wantbits, int max
aedd00
 	int best, bestcount, which, linenum;
aedd00
 	struct dhgroup dhg;
aedd00
 
aedd00
+	if (FIPS_mode()) {
aedd00
+		logit("Using arbitrary primes is not allowed in FIPS mode."
aedd00
+		    " Falling back to known groups.");
aedd00
+		return (dh_new_group_fallback(max));
aedd00
+	}
aedd00
+
aedd00
 	if ((f = fopen(_PATH_DH_MODULI, "r")) == NULL) {
aedd00
 		logit("WARNING: could not open %s (%s), using fixed modulus",
aedd00
 		    _PATH_DH_MODULI, strerror(errno));
aedd00
@@ -489,4 +495,38 @@ dh_estimate(int bits)
aedd00
 	return 8192;
aedd00
 }
aedd00
 
aedd00
+/*
aedd00
+ * Compares the received DH parameters with known-good groups,
aedd00
+ * which might be either from group14, group16 or group18.
aedd00
+ */
aedd00
+int
aedd00
+dh_is_known_group(const DH *dh)
aedd00
+{
aedd00
+	const BIGNUM *p, *g;
aedd00
+	const BIGNUM *known_p, *known_g;
aedd00
+	DH *known = NULL;
aedd00
+	int bits = 0, rv = 0;
aedd00
+
aedd00
+	DH_get0_pqg(dh, &p, NULL, &g);
aedd00
+	bits = BN_num_bits(p);
aedd00
+
aedd00
+	if (bits <= 3072) {
aedd00
+		known = dh_new_group14();
aedd00
+	} else if (bits <= 6144) {
aedd00
+		known = dh_new_group16();
aedd00
+	} else {
aedd00
+		known = dh_new_group18();
aedd00
+	}
aedd00
+
aedd00
+	DH_get0_pqg(known, &known_p, NULL, &known_g);
aedd00
+
aedd00
+	if (BN_cmp(g, known_g) == 0 &&
aedd00
+	    BN_cmp(p, known_p) == 0) {
aedd00
+		rv = 1;
aedd00
+	}
aedd00
+
aedd00
+	DH_free(known);
aedd00
+	return rv;
aedd00
+}
aedd00
+
aedd00
 #endif /* WITH_OPENSSL */
aedd00
diff -up openssh-7.9p1/dh.h.fips openssh-7.9p1/dh.h
aedd00
--- openssh-7.9p1/dh.h.fips	2018-10-17 02:01:20.000000000 +0200
aedd00
+++ openssh-7.9p1/dh.h	2019-03-11 17:08:18.718828381 +0100
aedd00
@@ -43,6 +43,7 @@ DH	*dh_new_group_fallback(int);
aedd00
 
aedd00
 int	 dh_gen_key(DH *, int);
aedd00
 int	 dh_pub_is_valid(const DH *, const BIGNUM *);
aedd00
+int	 dh_is_known_group(const DH *);
aedd00
 
aedd00
 u_int	 dh_estimate(int);
aedd00
 
aedd00
diff -up openssh-7.9p1/kex.c.fips openssh-7.9p1/kex.c
aedd00
--- openssh-7.9p1/kex.c.fips	2019-03-11 17:06:37.614877975 +0100
aedd00
+++ openssh-7.9p1/kex.c	2019-03-11 17:06:37.621878041 +0100
aedd00
@@ -175,7 +196,10 @@ kex_names_valid(const char *names)
aedd00
 	for ((p = strsep(&cp, ",")); p && *p != '\0';
aedd00
 	    (p = strsep(&cp, ","))) {
aedd00
 		if (kex_alg_by_name(p) == NULL) {
aedd00
-			error("Unsupported KEX algorithm \"%.100s\"", p);
aedd00
+			if (FIPS_mode())
aedd00
+				error("\"%.100s\" is not allowed in FIPS mode", p);
aedd00
+			else
aedd00
+				error("Unsupported KEX algorithm \"%.100s\"", p);
aedd00
 			free(s);
aedd00
 			return 0;
aedd00
 		}
aedd00
diff -up openssh-7.9p1/kexgexc.c.fips openssh-7.9p1/kexgexc.c
aedd00
--- openssh-7.9p1/kexgexc.c.fips	2018-10-17 02:01:20.000000000 +0200
aedd00
+++ openssh-7.9p1/kexgexc.c	2019-03-11 17:06:37.621878041 +0100
aedd00
@@ -28,6 +28,7 @@
aedd00
 
aedd00
 #ifdef WITH_OPENSSL
aedd00
 
aedd00
+#include <openssl/crypto.h>
aedd00
 #include <sys/types.h>
aedd00
 
aedd00
 #include <openssl/dh.h>
aedd00
@@ -118,6 +119,10 @@ input_kex_dh_gex_group(int type, u_int32
aedd00
 		r = SSH_ERR_ALLOC_FAIL;
aedd00
 		goto out;
aedd00
 	}
aedd00
+	if (FIPS_mode() && dh_is_known_group(kex->dh) == 0) {
aedd00
+		r = SSH_ERR_INVALID_ARGUMENT;
aedd00
+		goto out;
aedd00
+	}
aedd00
 	p = g = NULL; /* belong to kex->dh now */
aedd00
 
aedd00
 	/* generate and send 'e', client DH public key */
aedd00
diff -up openssh-7.9p1/myproposal.h.fips openssh-7.9p1/myproposal.h
aedd00
--- openssh-7.9p1/myproposal.h.fips	2018-10-17 02:01:20.000000000 +0200
aedd00
+++ openssh-7.9p1/myproposal.h	2019-03-11 17:06:37.621878041 +0100
aedd00
@@ -116,6 +116,16 @@
aedd00
 	"rsa-sha2-256," \
aedd00
 	"ssh-rsa"
aedd00
 
aedd00
+#define	KEX_FIPS_PK_ALG	\
aedd00
+	HOSTKEY_ECDSA_CERT_METHODS \
aedd00
+	"rsa-sha2-512-cert-v01@openssh.com," \
aedd00
+	"rsa-sha2-256-cert-v01@openssh.com," \
aedd00
+	"ssh-rsa-cert-v01@openssh.com," \
aedd00
+	HOSTKEY_ECDSA_METHODS \
aedd00
+	"rsa-sha2-512," \
aedd00
+	"rsa-sha2-256," \
aedd00
+	"ssh-rsa"
aedd00
+
aedd00
 /* the actual algorithms */
aedd00
 
aedd00
 #define KEX_SERVER_ENCRYPT \
aedd00
@@ -139,6 +147,38 @@
aedd00
 
aedd00
 #define KEX_CLIENT_MAC KEX_SERVER_MAC
aedd00
 
aedd00
+#define	KEX_FIPS_ENCRYPT \
aedd00
+	"aes128-ctr,aes192-ctr,aes256-ctr," \
aedd00
+	"aes128-cbc,3des-cbc," \
aedd00
+	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se" \
aedd00
+	AESGCM_CIPHER_MODES
aedd00
+#ifdef HAVE_EVP_SHA256
aedd00
+# define KEX_DEFAULT_KEX_FIPS		\
aedd00
+	KEX_ECDH_METHODS \
aedd00
+	KEX_SHA2_METHODS \
aedd00
+	"diffie-hellman-group14-sha256"
aedd00
+# define KEX_FIPS_MAC \
aedd00
+	"hmac-sha1," \
aedd00
+	"hmac-sha2-256," \
aedd00
+	"hmac-sha2-512," \
aedd00
+	"hmac-sha1-etm@openssh.com," \
aedd00
+	"hmac-sha2-256-etm@openssh.com," \
aedd00
+	"hmac-sha2-512-etm@openssh.com"
aedd00
+#else
aedd00
+# ifdef OPENSSL_HAS_NISTP521
aedd00
+#  define KEX_DEFAULT_KEX_FIPS		\
aedd00
+	"ecdh-sha2-nistp256," \
aedd00
+	"ecdh-sha2-nistp384," \
aedd00
+	"ecdh-sha2-nistp521"
aedd00
+# else
aedd00
+#  define KEX_DEFAULT_KEX_FIPS		\
aedd00
+	"ecdh-sha2-nistp256," \
aedd00
+	"ecdh-sha2-nistp384"
aedd00
+# endif
aedd00
+#define        KEX_FIPS_MAC \
aedd00
+       "hmac-sha1"
aedd00
+#endif
aedd00
+
aedd00
 /* Not a KEX value, but here so all the algorithm defaults are together */
aedd00
 #define	SSH_ALLOWED_CA_SIGALGS	\
aedd00
 	"ecdsa-sha2-nistp256," \
aedd00
diff -up openssh-7.9p1/readconf.c.fips openssh-7.9p1/readconf.c
aedd00
--- openssh-7.9p1/readconf.c.fips	2019-03-11 17:06:37.601877853 +0100
aedd00
+++ openssh-7.9p1/readconf.c	2019-03-11 17:06:37.622878050 +0100
aedd00
@@ -2178,18 +2178,19 @@ fill_default_options(Options * options)
aedd00
 	all_kex = kex_alg_list(',');
aedd00
 	all_key = sshkey_alg_list(0, 0, 1, ',');
aedd00
 	all_sig = sshkey_alg_list(0, 1, 1, ',');
aedd00
-#define ASSEMBLE(what, defaults, all) \
aedd00
+#define ASSEMBLE(what, defaults, fips_defaults, all) \
aedd00
 	do { \
aedd00
 		if ((r = kex_assemble_names(&options->what, \
aedd00
-		    defaults, all)) != 0) \
aedd00
+		    (FIPS_mode() ? fips_defaults : defaults), \
aedd00
+		    all)) != 0) \
aedd00
 			fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \
aedd00
 	} while (0)
aedd00
-	ASSEMBLE(ciphers, KEX_CLIENT_ENCRYPT, all_cipher);
aedd00
-	ASSEMBLE(macs, KEX_CLIENT_MAC, all_mac);
aedd00
-	ASSEMBLE(kex_algorithms, KEX_CLIENT_KEX, all_kex);
aedd00
-	ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key);
aedd00
-	ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, all_key);
aedd00
-	ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, all_sig);
aedd00
+	ASSEMBLE(ciphers, KEX_CLIENT_ENCRYPT, KEX_FIPS_ENCRYPT, all_cipher);
aedd00
+	ASSEMBLE(macs, KEX_CLIENT_MAC, KEX_FIPS_MAC, all_mac);
aedd00
+	ASSEMBLE(kex_algorithms, KEX_CLIENT_KEX, KEX_DEFAULT_KEX_FIPS, all_kex);
aedd00
+	ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, KEX_FIPS_PK_ALG, all_key);
aedd00
+	ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, KEX_FIPS_PK_ALG, all_key);
aedd00
+	ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, KEX_FIPS_PK_ALG, all_sig);
aedd00
 #undef ASSEMBLE
aedd00
 	free(all_cipher);
aedd00
 	free(all_mac);
aedd00
diff -up openssh-7.9p1/sandbox-seccomp-filter.c.fips openssh-7.9p1/sandbox-seccomp-filter.c
aedd00
--- openssh-7.9p1/sandbox-seccomp-filter.c.fips	2019-03-11 17:06:37.586877712 +0100
aedd00
+++ openssh-7.9p1/sandbox-seccomp-filter.c	2019-03-11 17:06:37.622878050 +0100
aedd00
@@ -137,6 +137,9 @@ static const struct sock_filter preauth_
aedd00
 #ifdef __NR_open
aedd00
 	SC_DENY(__NR_open, EACCES),
aedd00
 #endif
aedd00
+#ifdef __NR_socket
aedd00
+	SC_DENY(__NR_socket, EACCES),
aedd00
+#endif
aedd00
 #ifdef __NR_openat
aedd00
 	SC_DENY(__NR_openat, EACCES),
aedd00
 #endif
aedd00
diff -up openssh-7.9p1/servconf.c.fips openssh-7.9p1/servconf.c
aedd00
--- openssh-7.9p1/servconf.c.fips	2019-03-11 17:06:37.568877543 +0100
aedd00
+++ openssh-7.9p1/servconf.c	2019-03-11 17:06:37.622878050 +0100
aedd00
@@ -209,18 +209,19 @@ assemble_algorithms(ServerOptions *o)
aedd00
 	all_kex = kex_alg_list(',');
aedd00
 	all_key = sshkey_alg_list(0, 0, 1, ',');
aedd00
 	all_sig = sshkey_alg_list(0, 1, 1, ',');
aedd00
-#define ASSEMBLE(what, defaults, all) \
aedd00
+#define ASSEMBLE(what, defaults, fips_defaults, all) \
aedd00
 	do { \
aedd00
-		if ((r = kex_assemble_names(&o->what, defaults, all)) != 0) \
aedd00
+		if ((r = kex_assemble_names(&o->what, (FIPS_mode() \
aedd00
+		    ? fips_defaults : defaults), all)) != 0) \
aedd00
 			fatal("%s: %s: %s", __func__, #what, ssh_err(r)); \
aedd00
 	} while (0)
aedd00
-	ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, all_cipher);
aedd00
-	ASSEMBLE(macs, KEX_SERVER_MAC, all_mac);
aedd00
-	ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, all_kex);
aedd00
-	ASSEMBLE(hostkeyalgorithms, KEX_DEFAULT_PK_ALG, all_key);
aedd00
-	ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, all_key);
aedd00
-	ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, all_key);
aedd00
-	ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, all_sig);
aedd00
+	ASSEMBLE(ciphers, KEX_SERVER_ENCRYPT, KEX_FIPS_ENCRYPT, all_cipher);
aedd00
+	ASSEMBLE(macs, KEX_SERVER_MAC, KEX_FIPS_MAC, all_mac);
aedd00
+	ASSEMBLE(kex_algorithms, KEX_SERVER_KEX, KEX_DEFAULT_KEX_FIPS, all_kex);
aedd00
+	ASSEMBLE(hostkeyalgorithms, KEX_DEFAULT_PK_ALG, KEX_FIPS_PK_ALG, all_key);
aedd00
+	ASSEMBLE(hostbased_key_types, KEX_DEFAULT_PK_ALG, KEX_FIPS_PK_ALG, all_key);
aedd00
+	ASSEMBLE(pubkey_key_types, KEX_DEFAULT_PK_ALG, KEX_FIPS_PK_ALG, all_key);
aedd00
+	ASSEMBLE(ca_sign_algorithms, SSH_ALLOWED_CA_SIGALGS, KEX_FIPS_PK_ALG, all_sig);
aedd00
 #undef ASSEMBLE
aedd00
 	free(all_cipher);
aedd00
 	free(all_mac);
aedd00
diff -up openssh-7.9p1/ssh.c.fips openssh-7.9p1/ssh.c
aedd00
--- openssh-7.9p1/ssh.c.fips	2019-03-11 17:06:37.602877862 +0100
aedd00
+++ openssh-7.9p1/ssh.c	2019-03-11 17:06:37.623878060 +0100
aedd00
@@ -76,6 +76,7 @@
aedd00
 #include <openssl/evp.h>
aedd00
 #include <openssl/err.h>
aedd00
 #endif
aedd00
+#include <openssl/crypto.h>
aedd00
 #include "openbsd-compat/openssl-compat.h"
aedd00
 #include "openbsd-compat/sys-queue.h"
aedd00
 
aedd00
@@ -1283,6 +1294,10 @@ main(int ac, char **av)
aedd00
 		dump_client_config(&options, host);
aedd00
 		exit(0);
aedd00
 	}
aedd00
+
aedd00
+	if (FIPS_mode()) {
aedd00
+		debug("FIPS mode initialized");
aedd00
+	}
aedd00
 
aedd00
 	if (muxclient_command != 0 && options.control_path == NULL)
aedd00
 		fatal("No ControlPath specified for \"-O\" command");
aedd00
diff -up openssh-7.9p1/sshconnect2.c.fips openssh-7.9p1/sshconnect2.c
aedd00
--- openssh-7.9p1/sshconnect2.c.fips	2019-03-11 17:06:37.580877655 +0100
aedd00
+++ openssh-7.9p1/sshconnect2.c	2019-03-11 17:06:37.623878060 +0100
aedd00
@@ -44,6 +44,8 @@
aedd00
 #include <vis.h>
aedd00
 #endif
aedd00
 
aedd00
+#include <openssl/crypto.h>
aedd00
+
aedd00
 #include "openbsd-compat/sys-queue.h"
aedd00
 
aedd00
 #include "xmalloc.h"
f806d6
@@ -148,7 +150,8 @@ order_hostkeyalgs(char *host, struct soc
f806d6
 	 * Otherwise, prefer the host key algorithms that match known keys
f806d6
 	 * while keeping the ordering of HostkeyAlgorithms as much as possible.
f806d6
 	 */
aedd00
-	oavail = avail = xstrdup(KEX_DEFAULT_PK_ALG);
aedd00
+	oavail = avail = xstrdup((FIPS_mode()
aedd00
+	    ? KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG));
aedd00
 	maxlen = strlen(avail) + 1;
aedd00
 	first = xmalloc(maxlen);
aedd00
 	last = xmalloc(maxlen);
f806d6
@@ -229,14 +232,16 @@ ssh_kex2(struct ssh *ssh, char *host, st
aedd00
 	if (options.hostkeyalgorithms != NULL) {
aedd00
 		all_key = sshkey_alg_list(0, 0, 1, ',');
aedd00
 		if (kex_assemble_names(&options.hostkeyalgorithms,
aedd00
-		    KEX_DEFAULT_PK_ALG, all_key) != 0)
aedd00
+		    (FIPS_mode() ? KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG),
aedd00
+		    all_key) != 0)
aedd00
 			fatal("%s: kex_assemble_namelist", __func__);
aedd00
 		free(all_key);
aedd00
 		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
aedd00
 		    compat_pkalg_proposal(options.hostkeyalgorithms);
aedd00
 	} else {
aedd00
 		/* Enforce default */
aedd00
-		options.hostkeyalgorithms = xstrdup(KEX_DEFAULT_PK_ALG);
aedd00
+		options.hostkeyalgorithms = xstrdup((FIPS_mode()
aedd00
+		    ? KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG));
aedd00
 		/* Prefer algorithms that we already have keys for */
aedd00
 		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
aedd00
 		    compat_pkalg_proposal(
aedd00
@@ -201,35 +201,40 @@ ssh_kex2(char *host, struct sockaddr *ho
aedd00
 
aedd00
 #if defined(GSSAPI) && defined(WITH_OPENSSL)
aedd00
 	if (options.gss_keyex) {
aedd00
-		/* Add the GSSAPI mechanisms currently supported on this
aedd00
-		 * client to the key exchange algorithm proposal */
aedd00
-		orig = myproposal[PROPOSAL_KEX_ALGS];
aedd00
-
aedd00
-		if (options.gss_server_identity) {
aedd00
-			gss_host = xstrdup(options.gss_server_identity);
aedd00
-		} else if (options.gss_trust_dns) {
aedd00
-			gss_host = remote_hostname(ssh);
aedd00
-			/* Fall back to specified host if we are using proxy command
aedd00
-			 * and can not use DNS on that socket */
aedd00
-			if (strcmp(gss_host, "UNKNOWN") == 0) {
aedd00
-				gss_host = xstrdup(host);
aedd00
-			}
aedd00
-		} else {
aedd00
-			gss_host = xstrdup(host);
aedd00
-		}
aedd00
-
aedd00
-		gss = ssh_gssapi_client_mechanisms(gss_host,
aedd00
-		    options.gss_client_identity, options.gss_kex_algorithms);
aedd00
-		if (gss) {
aedd00
-			debug("Offering GSSAPI proposal: %s", gss);
aedd00
-			xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
aedd00
-			    "%s,%s", gss, orig);
aedd00
-
aedd00
-			/* If we've got GSSAPI algorithms, then we also support the
aedd00
-			 * 'null' hostkey, as a last resort */
aedd00
-			orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
aedd00
-			xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
aedd00
-			    "%s,null", orig);
aedd00
+		if (FIPS_mode()) {
aedd00
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
aedd00
+			options.gss_keyex = 0;
aedd00
+		} else {
aedd00
+			/* Add the GSSAPI mechanisms currently supported on this
aedd00
+			 * client to the key exchange algorithm proposal */
aedd00
+			orig = myproposal[PROPOSAL_KEX_ALGS];
aedd00
+
aedd00
+			if (options.gss_server_identity) {
aedd00
+				gss_host = xstrdup(options.gss_server_identity);
aedd00
+			} else if (options.gss_trust_dns) {
aedd00
+				gss_host = remote_hostname(ssh);
aedd00
+				/* Fall back to specified host if we are using proxy command
aedd00
+				 * and can not use DNS on that socket */
aedd00
+				if (strcmp(gss_host, "UNKNOWN") == 0) {
aedd00
+					gss_host = xstrdup(host);
aedd00
+				}
aedd00
+			} else {
aedd00
+				gss_host = xstrdup(host);
aedd00
+			}
aedd00
+
aedd00
+			gss = ssh_gssapi_client_mechanisms(gss_host,
aedd00
+			    options.gss_client_identity, options.gss_kex_algorithms);
aedd00
+			if (gss) {
aedd00
+				debug("Offering GSSAPI proposal: %s", gss);
aedd00
+				xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
aedd00
+				    "%s,%s", gss, orig);
aedd00
+
aedd00
+				/* If we've got GSSAPI algorithms, then we also support the
aedd00
+				 * 'null' hostkey, as a last resort */
aedd00
+				orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
aedd00
+				xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
aedd00
+				    "%s,null", orig);
aedd00
+			}
aedd00
 		}
aedd00
 	}
aedd00
 #endif
aedd00
diff -up openssh-7.9p1/sshd.c.fips openssh-7.9p1/sshd.c
aedd00
--- openssh-7.9p1/sshd.c.fips	2019-03-11 17:06:37.617878003 +0100
aedd00
+++ openssh-7.9p1/sshd.c	2019-03-11 17:06:37.624878069 +0100
aedd00
@@ -66,6 +66,7 @@
aedd00
 #include <grp.h>
aedd00
 #include <pwd.h>
aedd00
 #include <signal.h>
aedd00
+#include <syslog.h>
aedd00
 #include <stdarg.h>
aedd00
 #include <stdio.h>
aedd00
 #include <stdlib.h>
aedd00
@@ -77,6 +78,7 @@
aedd00
 #include <openssl/dh.h>
aedd00
 #include <openssl/bn.h>
aedd00
 #include <openssl/rand.h>
aedd00
+#include <openssl/crypto.h>
aedd00
 #include "openbsd-compat/openssl-compat.h"
aedd00
 #endif
aedd00
 
aedd00
@@ -1581,6 +1584,7 @@ main(int ac, char **av)
aedd00
 #endif
aedd00
 	__progname = ssh_get_progname(av[0]);
aedd00
 
aedd00
+	OpenSSL_add_all_algorithms();
aedd00
 	/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
aedd00
 	saved_argc = ac;
aedd00
 	rexec_argc = ac;
aedd00
@@ -2036,6 +2051,10 @@ main(int ac, char **av)
aedd00
 	/* Reinitialize the log (because of the fork above). */
aedd00
 	log_init(__progname, options.log_level, options.log_facility, log_stderr);
aedd00
 
aedd00
+	if (FIPS_mode()) {
aedd00
+		debug("FIPS mode initialized");
aedd00
+	}
aedd00
+
aedd00
 	/* Chdir to the root directory so that the current disk can be
aedd00
 	   unmounted if desired. */
aedd00
 	if (chdir("/") == -1)
aedd00
@@ -2412,10 +2431,14 @@ do_ssh2_kex(void)
aedd00
 	if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
aedd00
 		orig = NULL;
aedd00
 
aedd00
-	if (options.gss_keyex)
aedd00
-		gss = ssh_gssapi_server_mechanisms();
aedd00
-	else
aedd00
-		gss = NULL;
aedd00
+	if (options.gss_keyex) {
aedd00
+		if (FIPS_mode()) {
aedd00
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
aedd00
+			options.gss_keyex = 0;
aedd00
+		} else {
aedd00
+			gss = ssh_gssapi_server_mechanisms();
aedd00
+		}
aedd00
+	}
aedd00
 
aedd00
 	if (gss && orig)
aedd00
 		xasprintf(&newstr, "%s,%s", gss, orig);
aedd00
diff -up openssh-7.9p1/sshkey.c.fips openssh-7.9p1/sshkey.c
aedd00
--- openssh-7.9p1/sshkey.c.fips	2019-03-11 17:06:37.617878003 +0100
aedd00
+++ openssh-7.9p1/sshkey.c	2019-03-11 17:06:37.624878069 +0100
aedd00
@@ -34,6 +34,7 @@
aedd00
 #include <openssl/evp.h>
aedd00
 #include <openssl/err.h>
aedd00
 #include <openssl/pem.h>
aedd00
+#include <openssl/crypto.h>
aedd00
 #endif
aedd00
 
aedd00
 #include "crypto_api.h"
aedd00
@@ -57,6 +58,7 @@
aedd00
 #include "sshkey.h"
aedd00
 #include "sshkey-xmss.h"
aedd00
 #include "match.h"
aedd00
+#include "log.h"
aedd00
 
aedd00
 #include "xmss_fast.h"
aedd00
 
aedd00
@@ -1514,6 +1516,8 @@ rsa_generate_private_key(u_int bits, RSA
aedd00
 	}
aedd00
 	if (!BN_set_word(f4, RSA_F4) ||
aedd00
 	    !RSA_generate_key_ex(private, bits, f4, NULL)) {
aedd00
+			if (FIPS_mode())
aedd00
+				logit("%s: the key length might be unsupported by FIPS mode approved key generation method", __func__);
aedd00
 		ret = SSH_ERR_LIBCRYPTO_ERROR;
aedd00
 		goto out;
aedd00
 	}
aedd00
diff -up openssh-7.9p1/ssh-keygen.c.fips openssh-7.9p1/ssh-keygen.c
aedd00
--- openssh-7.9p1/ssh-keygen.c.fips	2019-03-11 17:06:37.590877750 +0100
aedd00
+++ openssh-7.9p1/ssh-keygen.c	2019-03-11 17:06:37.625878079 +0100
aedd00
@@ -230,6 +230,12 @@ type_bits_valid(int type, const char *na
aedd00
 	    OPENSSL_DSA_MAX_MODULUS_BITS : OPENSSL_RSA_MAX_MODULUS_BITS;
aedd00
 	if (*bitsp > maxbits)
aedd00
 		fatal("key bits exceeds maximum %d", maxbits);
aedd00
+	if (FIPS_mode()) {
aedd00
+		if (type == KEY_DSA)
aedd00
+			fatal("DSA keys are not allowed in FIPS mode");
aedd00
+		if (type == KEY_ED25519)
aedd00
+			fatal("ED25519 keys are not allowed in FIPS mode");
aedd00
+	}
aedd00
 	switch (type) {
aedd00
 	case KEY_DSA:
aedd00
 		if (*bitsp != 1024)
aedd00
@@ -1029,9 +1035,17 @@ do_gen_all_hostkeys(struct passwd *pw)
aedd00
 			first = 1;
aedd00
 			printf("%s: generating new host keys: ", __progname);
aedd00
 		}
aedd00
+		type = sshkey_type_from_name(key_types[i].key_type);
aedd00
+
aedd00
+		/* Skip the keys that are not supported in FIPS mode */
aedd00
+		if (FIPS_mode() && (type == KEY_DSA || type == KEY_ED25519)) {
aedd00
+			logit("Skipping %s key in FIPS mode",
aedd00
+			    key_types[i].key_type_display);
aedd00
+			goto next;
aedd00
+		}
aedd00
+
aedd00
 		printf("%s ", key_types[i].key_type_display);
aedd00
 		fflush(stdout);
aedd00
-		type = sshkey_type_from_name(key_types[i].key_type);
aedd00
 		if ((fd = mkstemp(prv_tmp)) == -1) {
aedd00
 			error("Could not save your public key in %s: %s",
aedd00
 			    prv_tmp, strerror(errno));