jonathancammack / rpms / openssh

Forked from rpms/openssh 8 months ago
Clone
017ff1
diff --git a/Makefile.in b/Makefile.in
017ff1
index 3bb7f00..294bef5 100644
017ff1
--- a/Makefile.in
017ff1
+++ b/Makefile.in
017ff1
@@ -154,25 +154,25 @@ libssh.a: $(LIBSSH_OBJS)
017ff1
 	$(RANLIB) $@
017ff1
 
017ff1
 ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHOBJS)
017ff1
-	$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHLIBS) $(LIBS) $(GSSLIBS)
017ff1
+	$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(SSHLIBS) $(LIBS) $(GSSLIBS)
017ff1
 
017ff1
 sshd$(EXEEXT): libssh.a	$(LIBCOMPAT) $(SSHDOBJS)
017ff1
-	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS) $(GSSLIBS) $(K5LIBS)
017ff1
+	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(SSHDLIBS) $(LIBS) $(GSSLIBS) $(K5LIBS)
017ff1
 
017ff1
 scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o
017ff1
 	$(LD) -o $@ scp.o progressmeter.o bufaux.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
017ff1
 
017ff1
 ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o
017ff1
-	$(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
017ff1
+	$(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
017ff1
 
017ff1
 ssh-agent$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-agent.o ssh-pkcs11-client.o
017ff1
-	$(LD) -o $@ ssh-agent.o ssh-pkcs11-client.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
017ff1
+	$(LD) -o $@ ssh-agent.o ssh-pkcs11-client.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
017ff1
 
017ff1
 ssh-keygen$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keygen.o
017ff1
-	$(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
017ff1
+	$(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
017ff1
 
017ff1
 ssh-keysign$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keysign.o roaming_dummy.o readconf.o
017ff1
-	$(LD) -o $@ ssh-keysign.o readconf.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
017ff1
+	$(LD) -o $@ ssh-keysign.o readconf.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
017ff1
 
017ff1
 ssh-pkcs11-helper$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-pkcs11-helper.o ssh-pkcs11.o
017ff1
 	$(LD) -o $@ ssh-pkcs11-helper.o ssh-pkcs11.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lopenbsd-compat $(LIBS)
017ff1
@@ -187,7 +187,7 @@ ctr-cavstest$(EXEEXT): $(LIBCOMPAT) libssh.a ctr-cavstest.o
017ff1
 	$(LD) -o $@ ctr-cavstest.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(LIBS)
017ff1
 
017ff1
 ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o roaming_dummy.o
017ff1
-	$(LD) -o $@ ssh-keyscan.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh $(LIBS)
017ff1
+	$(LD) -o $@ ssh-keyscan.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(LIBS)
017ff1
 
017ff1
 sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o sftp-server-main.o
017ff1
 	$(LD) -o $@ sftp-server.o sftp-common.o sftp-server-main.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
017ff1
diff --git a/auth-rsa.c b/auth-rsa.c
017ff1
index f225b0b..8bafcd6 100644
017ff1
--- a/auth-rsa.c
017ff1
+++ b/auth-rsa.c
017ff1
@@ -244,7 +244,7 @@ rsa_key_allowed_in_file(struct passwd *pw, char *file,
017ff1
 			    "actual %d vs. announced %d.",
017ff1
 			    file, linenum, BN_num_bits(key->rsa->n), bits);
017ff1
 
017ff1
-		fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
017ff1
+		fp = key_selected_fingerprint(key, SSH_FP_HEX);
017ff1
 		debug("matching key found: file %s, line %lu %s %s",
017ff1
 		    file, linenum, key_type(key), fp);
017ff1
 		free(fp);
017ff1
diff --git a/auth2-pubkey.c b/auth2-pubkey.c
017ff1
index 6d1c872..3808ec8 100644
017ff1
--- a/auth2-pubkey.c
017ff1
+++ b/auth2-pubkey.c
017ff1
@@ -214,8 +214,7 @@ pubkey_auth_info(Authctxt *authctxt, const Key *key, const char *fmt, ...)
017ff1
 	}
017ff1
 
017ff1
 	if (key_is_cert(key)) {
017ff1
-		fp = key_fingerprint(key->cert->signature_key,
017ff1
-		    SSH_FP_MD5, SSH_FP_HEX);
017ff1
+		fp = key_selected_fingerprint(key->cert->signature_key, SSH_FP_HEX);
017ff1
 		auth_info(authctxt, "%s ID %s (serial %llu) CA %s %s%s%s", 
017ff1
 		    key_type(key), key->cert->key_id,
017ff1
 		    (unsigned long long)key->cert->serial,
017ff1
@@ -223,7 +222,7 @@ pubkey_auth_info(Authctxt *authctxt, const Key *key, const char *fmt, ...)
017ff1
 		    extra == NULL ? "" : ", ", extra == NULL ? "" : extra);
017ff1
 		free(fp);
017ff1
 	} else {
017ff1
-		fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
017ff1
+		fp = key_selected_fingerprint(key, SSH_FP_HEX);
017ff1
 		auth_info(authctxt, "%s %s%s%s", key_type(key), fp,
017ff1
 		    extra == NULL ? "" : ", ", extra == NULL ? "" : extra);
017ff1
 		free(fp);
017ff1
diff --git a/authfile.c b/authfile.c
017ff1
index ec4f4ff..2b3d650 100644
017ff1
--- a/authfile.c
017ff1
+++ b/authfile.c
017ff1
@@ -46,6 +46,7 @@
017ff1
 #include <openssl/err.h>
017ff1
 #include <openssl/evp.h>
017ff1
 #include <openssl/pem.h>
017ff1
+#include <openssl/fips.h>
017ff1
 
017ff1
 /* compatibility with old or broken OpenSSL versions */
017ff1
 #include "openbsd-compat/openssl-compat.h"
017ff1
@@ -1068,7 +1069,7 @@ Key *
017ff1
 key_parse_private(Buffer *buffer, const char *filename,
017ff1
     const char *passphrase, char **commentp)
017ff1
 {
017ff1
-	Key *pub, *prv;
017ff1
+	Key *pub, *prv = NULL;
017ff1
 
017ff1
 	/* it's a SSH v1 key if the public key part is readable */
017ff1
 	pub = key_parse_public_rsa1(buffer, commentp);
017ff1
@@ -1080,9 +1081,10 @@ key_parse_private(Buffer *buffer, const char *filename,
017ff1
 			*commentp = xstrdup(filename);
017ff1
 	} else {
017ff1
 		key_free(pub);
017ff1
-		/* key_parse_public_rsa1() has already loaded the comment */
017ff1
-		prv = key_parse_private_type(buffer, KEY_RSA1, passphrase,
017ff1
-		    NULL);
017ff1
+		if (! FIPS_mode())
017ff1
+			/* key_parse_public_rsa1() has already loaded the comment */
017ff1
+			prv = key_parse_private_type(buffer, KEY_RSA1, passphrase,
017ff1
+			    NULL);
017ff1
 	}
017ff1
 	return prv;
017ff1
 }
017ff1
diff --git a/cipher-ctr.c b/cipher-ctr.c
017ff1
index 73e9c7c..40ee395 100644
017ff1
--- a/cipher-ctr.c
017ff1
+++ b/cipher-ctr.c
017ff1
@@ -179,7 +179,8 @@ evp_aes_128_ctr(void)
017ff1
 	aes_ctr.do_cipher = ssh_aes_ctr;
017ff1
 #ifndef SSH_OLD_EVP
017ff1
 	aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
017ff1
-	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
017ff1
+	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV |
017ff1
+	    EVP_CIPH_FLAG_FIPS;
017ff1
 #endif
017ff1
 	return (&aes_ctr);
017ff1
 }
017ff1
diff --git a/cipher.c b/cipher.c
017ff1
index 226e56d..b19443c 100644
017ff1
--- a/cipher.c
017ff1
+++ b/cipher.c
017ff1
@@ -39,6 +39,8 @@
017ff1
 
017ff1
 #include <sys/types.h>
017ff1
 
017ff1
+#include <openssl/fips.h>
017ff1
+
017ff1
 #include <string.h>
017ff1
 #include <stdarg.h>
017ff1
 #include <stdio.h>
017ff1
@@ -90,6 +92,25 @@ static const struct Cipher ciphers[] = {
017ff1
 	{ NULL,		SSH_CIPHER_INVALID, 0, 0, 0, 0, 0, 0, NULL }
017ff1
 };
017ff1
 
017ff1
+static const struct Cipher fips_ciphers[] = {
017ff1
+	{ "none",	SSH_CIPHER_NONE, 8, 0, 0, 0, 0, 0, EVP_enc_null },
017ff1
+	{ "3des-cbc",	SSH_CIPHER_SSH2, 8, 24, 0, 0, 0, 1, EVP_des_ede3_cbc },
017ff1
+	{ "aes128-cbc",	SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, 1, EVP_aes_128_cbc },
017ff1
+	{ "aes192-cbc",	SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, 1, EVP_aes_192_cbc },
017ff1
+	{ "aes256-cbc",	SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, 1, EVP_aes_256_cbc },
017ff1
+	{ "rijndael-cbc@lysator.liu.se",
017ff1
+			SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, 1, EVP_aes_256_cbc },
017ff1
+	{ "aes128-ctr",	SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, 0, EVP_aes_128_ctr },
017ff1
+	{ "aes192-ctr",	SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, 0, EVP_aes_192_ctr },
017ff1
+	{ "aes256-ctr",	SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, 0, EVP_aes_256_ctr },
017ff1
+#ifdef OPENSSL_HAVE_EVPGCM
017ff1
+	{ "aes128-gcm@openssh.com",
017ff1
+			SSH_CIPHER_SSH2, 16, 16, 12, 16, 0, 0, EVP_aes_128_gcm },
017ff1
+	{ "aes256-gcm@openssh.com",
017ff1
+			SSH_CIPHER_SSH2, 16, 32, 12, 16, 0, 0, EVP_aes_256_gcm },
017ff1
+#endif
017ff1
+	{ NULL,		SSH_CIPHER_INVALID, 0, 0, 0, 0, 0, 0, NULL }
017ff1
+};
017ff1
 /*--*/
017ff1
 
017ff1
 /* Returns a list of supported ciphers separated by the specified char. */
017ff1
@@ -100,7 +121,7 @@ cipher_alg_list(char sep, int auth_only)
017ff1
 	size_t nlen, rlen = 0;
017ff1
 	const Cipher *c;
017ff1
 
017ff1
-	for (c = ciphers; c->name != NULL; c++) {
017ff1
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++) {
017ff1
 		if (c->number != SSH_CIPHER_SSH2)
017ff1
 			continue;
017ff1
 		if (auth_only && c->auth_len == 0)
017ff1
@@ -180,7 +201,7 @@ const Cipher *
017ff1
 cipher_by_name(const char *name)
017ff1
 {
017ff1
 	const Cipher *c;
017ff1
-	for (c = ciphers; c->name != NULL; c++)
017ff1
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
017ff1
 		if (strcmp(c->name, name) == 0)
017ff1
 			return c;
017ff1
 	return NULL;
017ff1
@@ -190,7 +211,7 @@ const Cipher *
017ff1
 cipher_by_number(int id)
017ff1
 {
017ff1
 	const Cipher *c;
017ff1
-	for (c = ciphers; c->name != NULL; c++)
017ff1
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
017ff1
 		if (c->number == id)
017ff1
 			return c;
017ff1
 	return NULL;
017ff1
@@ -232,7 +253,7 @@ cipher_number(const char *name)
017ff1
 	const Cipher *c;
017ff1
 	if (name == NULL)
017ff1
 		return -1;
017ff1
-	for (c = ciphers; c->name != NULL; c++)
017ff1
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
017ff1
 		if (strcasecmp(c->name, name) == 0)
017ff1
 			return c->number;
017ff1
 	return -1;
017ff1
diff --git a/dh.h b/dh.h
017ff1
index 48f7b68..9ff39f4 100644
017ff1
--- a/dh.h
017ff1
+++ b/dh.h
017ff1
@@ -45,6 +45,7 @@ int	 dh_estimate(int);
017ff1
 
017ff1
 /* Min and max values from RFC4419. */
017ff1
 #define DH_GRP_MIN	1024
017ff1
+#define DH_GRP_MIN_FIPS	2048
017ff1
 #define DH_GRP_MAX	8192
017ff1
 
017ff1
 /*
017ff1
diff --git a/entropy.c b/entropy.c
017ff1
index b361a04..5616643 100644
017ff1
--- a/entropy.c
017ff1
+++ b/entropy.c
017ff1
@@ -222,6 +222,9 @@ seed_rng(void)
017ff1
 		fatal("OpenSSL version mismatch. Built against %lx, you "
017ff1
 		    "have %lx", (u_long)OPENSSL_VERSION_NUMBER, SSLeay());
017ff1
 
017ff1
+	/* clean the PRNG status when exiting the program */
017ff1
+	atexit(RAND_cleanup);
017ff1
+
017ff1
 #ifndef OPENSSL_PRNG_ONLY
017ff1
 	if (RAND_status() == 1) {
017ff1
 		debug3("RNG is ready, skipping seeding");
017ff1
diff --git a/kex.c b/kex.c
017ff1
index bc3e53e..ede7b67 100644
017ff1
--- a/kex.c
017ff1
+++ b/kex.c
017ff1
@@ -34,6 +34,7 @@
017ff1
 #include <string.h>
017ff1
 
017ff1
 #include <openssl/crypto.h>
017ff1
+#include <openssl/fips.h>
017ff1
 
017ff1
 #include "xmalloc.h"
017ff1
 #include "ssh2.h"
017ff1
@@ -103,6 +104,25 @@ static const struct kexalg kexalgs[] = {
017ff1
 	{ NULL, -1, -1, -1},
017ff1
 };
017ff1
 
017ff1
+static const struct kexalg kexalgs_fips[] = {
017ff1
+	{ KEX_DH14, KEX_DH_GRP14_SHA1, 0, SSH_DIGEST_SHA1 },
017ff1
+	{ KEX_DHGEX_SHA1, KEX_DH_GEX_SHA1, 0, SSH_DIGEST_SHA1 },
017ff1
+#ifdef HAVE_EVP_SHA256
017ff1
+	{ KEX_DHGEX_SHA256, KEX_DH_GEX_SHA256, 0, SSH_DIGEST_SHA256 },
017ff1
+#endif
017ff1
+#ifdef OPENSSL_HAS_ECC
017ff1
+	{ KEX_ECDH_SHA2_NISTP256, KEX_ECDH_SHA2,
017ff1
+	    NID_X9_62_prime256v1, SSH_DIGEST_SHA256 },
017ff1
+	{ KEX_ECDH_SHA2_NISTP384, KEX_ECDH_SHA2, NID_secp384r1,
017ff1
+	    SSH_DIGEST_SHA384 },
017ff1
+# ifdef OPENSSL_HAS_NISTP521
017ff1
+	{ KEX_ECDH_SHA2_NISTP521, KEX_ECDH_SHA2, NID_secp521r1,
017ff1
+	    SSH_DIGEST_SHA512 },
017ff1
+# endif
017ff1
+#endif
017ff1
+	{ NULL, -1, -1, NULL},
017ff1
+};
017ff1
+
017ff1
 char *
017ff1
 kex_alg_list(char sep)
017ff1
 {
017ff1
@@ -126,7 +146,7 @@ kex_alg_by_name(const char *name)
017ff1
 {
017ff1
 	const struct kexalg *k;
017ff1
 
017ff1
-	for (k = kexalgs; k->name != NULL; k++) {
017ff1
+	for (k = (FIPS_mode() ? kexalgs_fips : kexalgs); k->name != NULL; k++) {
017ff1
 		if (strcmp(k->name, name) == 0)
017ff1
 			return k;
017ff1
 #ifdef GSSAPI
017ff1
@@ -151,7 +171,10 @@ kex_names_valid(const char *names)
017ff1
 	for ((p = strsep(&cp, ",")); p && *p != '\0';
017ff1
 	    (p = strsep(&cp, ","))) {
017ff1
 		if (kex_alg_by_name(p) == NULL) {
017ff1
-			error("Unsupported KEX algorithm \"%.100s\"", p);
017ff1
+			if (FIPS_mode())
017ff1
+				error("\"%.100s\" is not allowed in FIPS mode", p);
017ff1
+			else
017ff1
+				error("Unsupported KEX algorithm \"%.100s\"", p);
017ff1
 			free(s);
017ff1
 			return 0;
017ff1
 		}
017ff1
diff --git a/kexecdhc.c b/kexecdhc.c
017ff1
index 2f7629c..20c9946 100644
017ff1
--- a/kexecdhc.c
017ff1
+++ b/kexecdhc.c
017ff1
@@ -154,6 +154,7 @@ kexecdh_client(Kex *kex)
017ff1
 
017ff1
 	kex_derive_keys_bn(kex, hash, hashlen, shared_secret);
017ff1
 	BN_clear_free(shared_secret);
017ff1
+	memset(hash, 0, hashlen);
017ff1
 	kex_finish(kex);
017ff1
 }
017ff1
 #else /* OPENSSL_HAS_ECC */
017ff1
diff --git a/kexecdhs.c b/kexecdhs.c
017ff1
index 2700b72..0820894 100644
017ff1
--- a/kexecdhs.c
017ff1
+++ b/kexecdhs.c
017ff1
@@ -150,6 +150,7 @@ kexecdh_server(Kex *kex)
017ff1
 
017ff1
 	kex_derive_keys_bn(kex, hash, hashlen, shared_secret);
017ff1
 	BN_clear_free(shared_secret);
017ff1
+	memset(hash, 0, hashlen);
017ff1
 	kex_finish(kex);
017ff1
 }
017ff1
 #else /* OPENSSL_HAS_ECC */
017ff1
diff --git a/kexgexc.c b/kexgexc.c
017ff1
index 355b7ba..427e11f 100644
017ff1
--- a/kexgexc.c
017ff1
+++ b/kexgexc.c
017ff1
@@ -26,6 +26,8 @@
017ff1
 
017ff1
 #include "includes.h"
017ff1
 
017ff1
+#include <openssl/fips.h>
017ff1
+
017ff1
 #include <sys/types.h>
017ff1
 
017ff1
 #include <openssl/dh.h>
017ff1
@@ -64,13 +66,13 @@ kexgex_client(Kex *kex)
017ff1
 		/* Old GEX request */
017ff1
 		packet_start(SSH2_MSG_KEX_DH_GEX_REQUEST_OLD);
017ff1
 		packet_put_int(nbits);
017ff1
-		min = DH_GRP_MIN;
017ff1
+		min = FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN;
017ff1
 		max = DH_GRP_MAX;
017ff1
 
017ff1
 		debug("SSH2_MSG_KEX_DH_GEX_REQUEST_OLD(%u) sent", nbits);
017ff1
 	} else {
017ff1
 		/* New GEX request */
017ff1
-		min = DH_GRP_MIN;
017ff1
+		min = FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN;
017ff1
 		max = DH_GRP_MAX;
017ff1
 		packet_start(SSH2_MSG_KEX_DH_GEX_REQUEST);
017ff1
 		packet_put_int(min);
017ff1
diff --git a/kexgexs.c b/kexgexs.c
017ff1
index 770ad28..9d4fc6d 100644
017ff1
--- a/kexgexs.c
017ff1
+++ b/kexgexs.c
017ff1
@@ -76,16 +76,16 @@ kexgex_server(Kex *kex)
017ff1
 		omin = min = packet_get_int();
017ff1
 		onbits = nbits = packet_get_int();
017ff1
 		omax = max = packet_get_int();
017ff1
-		min = MAX(DH_GRP_MIN, min);
017ff1
+		min = MAX(FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN, min);
017ff1
 		max = MIN(DH_GRP_MAX, max);
017ff1
-		nbits = MAX(DH_GRP_MIN, nbits);
017ff1
+		nbits = MAX(FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN, nbits);
017ff1
 		nbits = MIN(DH_GRP_MAX, nbits);
017ff1
 		break;
017ff1
 	case SSH2_MSG_KEX_DH_GEX_REQUEST_OLD:
017ff1
 		debug("SSH2_MSG_KEX_DH_GEX_REQUEST_OLD received");
017ff1
 		onbits = nbits = packet_get_int();
017ff1
 		/* unused for old GEX */
017ff1
-		omin = min = DH_GRP_MIN;
017ff1
+		omin = min = FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN;
017ff1
 		omax = max = DH_GRP_MAX;
017ff1
 		break;
017ff1
 	default:
017ff1
diff --git a/key.c b/key.c
017ff1
index 62f3edb..a2050f6 100644
017ff1
--- a/key.c
017ff1
+++ b/key.c
017ff1
@@ -42,6 +42,7 @@
017ff1
 #include "crypto_api.h"
017ff1
 
017ff1
 #include <openssl/evp.h>
017ff1
+#include <openssl/fips.h>
017ff1
 #include <openbsd-compat/openssl-compat.h>
017ff1
 
017ff1
 #include <stdarg.h>
017ff1
@@ -636,9 +637,13 @@ key_fingerprint_selection(void)
017ff1
 	char *env;
017ff1
 
017ff1
 	if (!rv_defined) {
017ff1
-		env = getenv("SSH_FINGERPRINT_TYPE");
017ff1
-		rv = (env && !strcmp (env, "sha")) ?
017ff1
-			SSH_FP_SHA1 : SSH_FP_MD5;
017ff1
+		if (FIPS_mode())
017ff1
+			rv = SSH_FP_SHA1;
017ff1
+		else {
017ff1
+			env = getenv("SSH_FINGERPRINT_TYPE");
017ff1
+			rv = (env && !strcmp (env, "sha")) ?
017ff1
+				SSH_FP_SHA1 : SSH_FP_MD5;
017ff1
+		}
017ff1
 		rv_defined = 1;
017ff1
 	}
017ff1
 	return rv;
017ff1
@@ -1168,8 +1173,11 @@ rsa_generate_private_key(u_int bits)
017ff1
 		fatal("%s: BN_new failed", __func__);
017ff1
 	if (!BN_set_word(f4, RSA_F4))
017ff1
 		fatal("%s: BN_new failed", __func__);
017ff1
-	if (!RSA_generate_key_ex(private, bits, f4, NULL))
017ff1
+	if (!RSA_generate_key_ex(private, bits, f4, NULL)) {
017ff1
+		if (FIPS_mode())
017ff1
+			logit("%s: the key length might be unsupported by FIPS mode approved key generation method", __func__);
017ff1
 		fatal("%s: key generation failed.", __func__);
017ff1
+	}
017ff1
 	BN_free(f4);
017ff1
 	return private;
017ff1
 }
017ff1
diff --git a/mac.c b/mac.c
017ff1
index 9388af4..cd7b034 100644
017ff1
--- a/mac.c
017ff1
+++ b/mac.c
017ff1
@@ -27,6 +27,8 @@
017ff1
 
017ff1
 #include <sys/types.h>
017ff1
 
017ff1
+#include <openssl/fips.h>
017ff1
+
017ff1
 #include <stdarg.h>
017ff1
 #include <string.h>
017ff1
 #include <signal.h>
017ff1
@@ -60,7 +62,7 @@ struct macalg {
017ff1
 	int		etm;		/* Encrypt-then-MAC */
017ff1
 };
017ff1
 
017ff1
-static const struct macalg macs[] = {
017ff1
+static const struct macalg all_macs[] = {
017ff1
 	/* Encrypt-and-MAC (encrypt-and-authenticate) variants */
017ff1
 	{ "hmac-sha1",				SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 0 },
017ff1
 	{ "hmac-sha1-96",			SSH_DIGEST, SSH_DIGEST_SHA1, 96, 0, 0, 0 },
017ff1
@@ -91,6 +93,24 @@ static const struct macalg macs[] = {
017ff1
 	{ NULL,					0, 0, 0, 0, 0, 0 }
017ff1
 };
017ff1
 
017ff1
+static const struct macalg fips_macs[] = {
017ff1
+	/* Encrypt-and-MAC (encrypt-and-authenticate) variants */
017ff1
+	{ "hmac-sha1",				SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 0 },
017ff1
+#ifdef HAVE_EVP_SHA256
017ff1
+	{ "hmac-sha2-256",			SSH_DIGEST, SSH_DIGEST_SHA256, 0, 0, 0, 0 },
017ff1
+	{ "hmac-sha2-512",			SSH_DIGEST, SSH_DIGEST_SHA512, 0, 0, 0, 0 },
017ff1
+#endif
017ff1
+
017ff1
+	/* Encrypt-then-MAC variants */
017ff1
+	{ "hmac-sha1-etm@openssh.com",		SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 1 },
017ff1
+#ifdef HAVE_EVP_SHA256
017ff1
+	{ "hmac-sha2-256-etm@openssh.com",	SSH_DIGEST, SSH_DIGEST_SHA256, 0, 0, 0, 1 },
017ff1
+	{ "hmac-sha2-512-etm@openssh.com",	SSH_DIGEST, SSH_DIGEST_SHA512, 0, 0, 0, 1 },
017ff1
+#endif
017ff1
+
017ff1
+	{ NULL,					0, 0, 0, 0, 0, 0 }
017ff1
+};
017ff1
+
017ff1
 /* Returns a list of supported MACs separated by the specified char. */
017ff1
 char *
017ff1
 mac_alg_list(char sep)
017ff1
@@ -99,7 +119,7 @@ mac_alg_list(char sep)
017ff1
 	size_t nlen, rlen = 0;
017ff1
 	const struct macalg *m;
017ff1
 
017ff1
-	for (m = macs; m->name != NULL; m++) {
017ff1
+	for (m = FIPS_mode() ? fips_macs : all_macs; m->name != NULL; m++) {
017ff1
 		if (ret != NULL)
017ff1
 			ret[rlen++] = sep;
017ff1
 		nlen = strlen(m->name);
017ff1
@@ -133,7 +153,7 @@ mac_setup(Mac *mac, char *name)
017ff1
 {
017ff1
 	const struct macalg *m;
017ff1
 
017ff1
-	for (m = macs; m->name != NULL; m++) {
017ff1
+	for (m = FIPS_mode() ? fips_macs : all_macs; m->name != NULL; m++) {
017ff1
 		if (strcmp(name, m->name) != 0)
017ff1
 			continue;
017ff1
 		if (mac != NULL) {
017ff1
diff --git a/myproposal.h b/myproposal.h
017ff1
index 3a0f5ae..4f35a44 100644
017ff1
--- a/myproposal.h
017ff1
+++ b/myproposal.h
017ff1
@@ -88,6 +88,12 @@
017ff1
 	"diffie-hellman-group14-sha1," \
017ff1
 	"diffie-hellman-group1-sha1"
017ff1
 
017ff1
+#define KEX_DEFAULT_KEX_FIPS		\
017ff1
+	KEX_ECDH_METHODS \
017ff1
+	KEX_SHA256_METHODS \
017ff1
+	"diffie-hellman-group-exchange-sha1," \
017ff1
+	"diffie-hellman-group14-sha1"
017ff1
+
017ff1
 #define	KEX_DEFAULT_PK_ALG	\
017ff1
 	HOSTKEY_ECDSA_CERT_METHODS \
017ff1
 	"ssh-ed25519-cert-v01@openssh.com," \
017ff1
@@ -133,6 +139,22 @@
017ff1
 #define	KEX_DEFAULT_COMP	"none,zlib@openssh.com,zlib"
017ff1
 #define	KEX_DEFAULT_LANG	""
017ff1
 
017ff1
+#define	KEX_FIPS_ENCRYPT \
017ff1
+	"aes128-ctr,aes192-ctr,aes256-ctr," \
017ff1
+	"aes128-cbc,3des-cbc," \
017ff1
+	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se"
017ff1
+#ifdef HAVE_EVP_SHA256
017ff1
+#define	KEX_FIPS_MAC \
017ff1
+	"hmac-sha1," \
017ff1
+	"hmac-sha2-256," \
017ff1
+	"hmac-sha2-512," \
017ff1
+	"hmac-sha1-etm@openssh.com," \
017ff1
+	"hmac-sha2-256-etm@openssh.com," \
017ff1
+	"hmac-sha2-512-etm@openssh.com"
017ff1
+#else
017ff1
+#define        KEX_FIPS_MAC \
017ff1
+       "hmac-sha1"
017ff1
+#endif
017ff1
 
017ff1
 static char *myproposal[PROPOSAL_MAX] = {
017ff1
 	KEX_DEFAULT_KEX,
017ff1
diff --git a/ssh-keygen.c b/ssh-keygen.c
017ff1
index 66198e6..ccf22c8 100644
017ff1
--- a/ssh-keygen.c
017ff1
+++ b/ssh-keygen.c
017ff1
@@ -195,6 +195,12 @@ type_bits_valid(int type, u_int32_t *bitsp)
017ff1
 		fprintf(stderr, "key bits exceeds maximum %d\n", maxbits);
017ff1
 		exit(1);
017ff1
 	}
017ff1
+	if (FIPS_mode()) {
017ff1
+		if (type == KEY_DSA)
017ff1
+			fatal("DSA keys are not allowed in FIPS mode");
017ff1
+		if (type == KEY_ED25519)
017ff1
+			fatal("ED25519 keys are not allowed in FIPS mode");
017ff1
+	}
017ff1
 	if (type == KEY_DSA && *bitsp != 1024)
017ff1
 		fatal("DSA keys must be 1024 bits");
017ff1
 	else if (type != KEY_ECDSA && type != KEY_ED25519 && *bitsp < 768)
017ff1
@@ -746,7 +752,7 @@ do_download(struct passwd *pw)
017ff1
 	enum fp_type fptype;
017ff1
 	char *fp, *ra;
017ff1
 
017ff1
-	fptype = print_bubblebabble ? SSH_FP_SHA1 : SSH_FP_MD5;
017ff1
+	fptype = print_bubblebabble ? SSH_FP_SHA1 : key_fingerprint_selection();
017ff1
 	rep =    print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_HEX;
017ff1
 
017ff1
 	pkcs11_init(0);
017ff1
@@ -756,8 +762,7 @@ do_download(struct passwd *pw)
017ff1
 	for (i = 0; i < nkeys; i++) {
017ff1
 		if (print_fingerprint) {
017ff1
 			fp = key_fingerprint(keys[i], fptype, rep);
017ff1
-			ra = key_fingerprint(keys[i], SSH_FP_MD5,
017ff1
-			    SSH_FP_RANDOMART);
017ff1
+			ra = key_selected_fingerprint(keys[i], SSH_FP_RANDOMART);
017ff1
 			printf("%u %s %s (PKCS11 key)\n", key_size(keys[i]),
017ff1
 			    fp, key_type(keys[i]));
017ff1
 			if (log_level >= SYSLOG_LEVEL_VERBOSE)
017ff1
diff --git a/ssh.c b/ssh.c
017ff1
index 1e6cb90..ea9193f 100644
017ff1
--- a/ssh.c
017ff1
+++ b/ssh.c
017ff1
@@ -73,6 +73,8 @@
017ff1
 
017ff1
 #include <openssl/evp.h>
017ff1
 #include <openssl/err.h>
017ff1
+#include <openssl/fips.h>
017ff1
+#include <fipscheck.h>
017ff1
 #include "openbsd-compat/openssl-compat.h"
017ff1
 #include "openbsd-compat/sys-queue.h"
017ff1
 
017ff1
@@ -427,6 +429,13 @@ main(int ac, char **av)
017ff1
 	sanitise_stdfd();
017ff1
 
017ff1
 	__progname = ssh_get_progname(av[0]);
017ff1
+        SSLeay_add_all_algorithms();
017ff1
+	if (access("/etc/system-fips", F_OK) == 0)
017ff1
+		if (! FIPSCHECK_verify(NULL, NULL))
017ff1
+			if (FIPS_mode())
017ff1
+				fatal("FIPS integrity verification test failed.");
017ff1
+			else
017ff1
+				logit("FIPS integrity verification test failed.");
017ff1
 
017ff1
 #ifndef HAVE_SETPROCTITLE
017ff1
 	/* Prepare for later setproctitle emulation */
017ff1
@@ -504,6 +513,9 @@ main(int ac, char **av)
017ff1
 	    "ACD:E:F:I:KL:MNO:PQ:R:S:TVw:W:XYy")) != -1) {
017ff1
 		switch (opt) {
017ff1
 		case '1':
017ff1
+			if (FIPS_mode()) {
017ff1
+				fatal("Protocol 1 not allowed in the FIPS mode.");
017ff1
+			}
017ff1
 			options.protocol = SSH_PROTO_1;
017ff1
 			break;
017ff1
 		case '2':
017ff1
@@ -828,7 +840,6 @@ main(int ac, char **av)
017ff1
 
017ff1
 	host_arg = xstrdup(host);
017ff1
 
017ff1
-	OpenSSL_add_all_algorithms();
017ff1
 	ERR_load_crypto_strings();
017ff1
 
017ff1
 	/* Initialize the command to execute on remote host. */
017ff1
@@ -973,6 +984,10 @@ main(int ac, char **av)
017ff1
 
017ff1
 	seed_rng();
017ff1
 
017ff1
+	if (FIPS_mode()) {
017ff1
+		logit("FIPS mode initialized");
017ff1
+	}
017ff1
+
017ff1
 	if (options.user == NULL)
017ff1
 		options.user = xstrdup(pw->pw_name);
017ff1
 
017ff1
@@ -1020,6 +1035,12 @@ main(int ac, char **av)
017ff1
 
017ff1
 	timeout_ms = options.connection_timeout * 1000;
017ff1
 
017ff1
+	if (FIPS_mode()) {
017ff1
+		options.protocol &= SSH_PROTO_2;
017ff1
+		if (options.protocol == 0)
017ff1
+			fatal("Protocol 2 disabled by configuration but required in the FIPS mode.");
017ff1
+	}
017ff1
+
017ff1
 	/* Open a connection to the remote host. */
017ff1
 	if (ssh_connect(host, addrs, &hostaddr, options.port,
017ff1
 	    options.address_family, options.connection_attempts,
017ff1
diff --git a/sshconnect2.c b/sshconnect2.c
017ff1
index b00658b..6a1562c 100644
017ff1
--- a/sshconnect2.c
017ff1
+++ b/sshconnect2.c
017ff1
@@ -44,6 +44,8 @@
017ff1
 #include <vis.h>
017ff1
 #endif
017ff1
 
017ff1
+#include <openssl/fips.h>
017ff1
+
017ff1
 #include "openbsd-compat/sys-queue.h"
017ff1
 
017ff1
 #include "xmalloc.h"
017ff1
@@ -168,20 +170,25 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
017ff1
 
017ff1
 #ifdef GSSAPI
017ff1
 	if (options.gss_keyex) {
017ff1
-		/* Add the GSSAPI mechanisms currently supported on this 
017ff1
-		 * client to the key exchange algorithm proposal */
017ff1
-		orig = myproposal[PROPOSAL_KEX_ALGS];
017ff1
-
017ff1
-		if (options.gss_trust_dns)
017ff1
-			gss_host = (char *)get_canonical_hostname(1);
017ff1
-		else
017ff1
-			gss_host = host;
017ff1
-
017ff1
-		gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
017ff1
-		if (gss) {
017ff1
-			debug("Offering GSSAPI proposal: %s", gss);
017ff1
-			xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
017ff1
-			    "%s,%s", gss, orig);
017ff1
+		if (FIPS_mode()) {
017ff1
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
017ff1
+			options.gss_keyex = 0;
017ff1
+		} else {
017ff1
+			/* Add the GSSAPI mechanisms currently supported on this
017ff1
+			 * client to the key exchange algorithm proposal */
017ff1
+			orig = myproposal[PROPOSAL_KEX_ALGS];
017ff1
+
017ff1
+			if (options.gss_trust_dns)
017ff1
+				gss_host = (char *)get_canonical_hostname(1);
017ff1
+			else
017ff1
+				gss_host = host;
017ff1
+
017ff1
+			gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
017ff1
+			if (gss) {
017ff1
+				debug("Offering GSSAPI proposal: %s", gss);
017ff1
+				xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
017ff1
+				    "%s,%s", gss, orig);
017ff1
+			}
017ff1
 		}
017ff1
 	}
017ff1
 #endif
017ff1
@@ -193,6 +200,10 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
017ff1
 	if (options.ciphers != NULL) {
017ff1
 		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
017ff1
 		myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
017ff1
+	} else if (FIPS_mode()) {
017ff1
+		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
017ff1
+		myproposal[PROPOSAL_ENC_ALGS_STOC] = KEX_FIPS_ENCRYPT;
017ff1
+
017ff1
 	}
017ff1
 	myproposal[PROPOSAL_ENC_ALGS_CTOS] =
017ff1
 	    compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
017ff1
@@ -208,7 +219,11 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
017ff1
 	if (options.macs != NULL) {
017ff1
 		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
017ff1
 		myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
017ff1
+	} else if (FIPS_mode()) {
017ff1
+		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
017ff1
+		myproposal[PROPOSAL_MAC_ALGS_STOC] = KEX_FIPS_MAC;
017ff1
 	}
017ff1
+
017ff1
 	if (options.hostkeyalgorithms != NULL)
017ff1
 		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
017ff1
 		    compat_pkalg_proposal(options.hostkeyalgorithms);
017ff1
@@ -220,9 +235,11 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
017ff1
 	}
017ff1
 	if (options.kex_algorithms != NULL)
017ff1
 		myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
017ff1
+	else if (FIPS_mode())
017ff1
+		myproposal[PROPOSAL_KEX_ALGS] = KEX_DEFAULT_KEX_FIPS;
017ff1
+
017ff1
 	myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(
017ff1
 	    myproposal[PROPOSAL_KEX_ALGS]);
017ff1
-
017ff1
 #ifdef GSSAPI
017ff1
 	/* If we've got GSSAPI algorithms, then we also support the
017ff1
 	 * 'null' hostkey, as a last resort */
017ff1
diff --git a/sshd.c b/sshd.c
017ff1
index b561ec8..e977de3 100644
017ff1
--- a/sshd.c
017ff1
+++ b/sshd.c
017ff1
@@ -75,6 +75,8 @@
017ff1
 #include <openssl/dh.h>
017ff1
 #include <openssl/bn.h>
017ff1
 #include <openssl/rand.h>
017ff1
+#include <openssl/fips.h>
017ff1
+#include <fipscheck.h>
017ff1
 #include "openbsd-compat/openssl-compat.h"
017ff1
 
017ff1
 #ifdef HAVE_SECUREWARE
017ff1
@@ -1468,6 +1470,18 @@ main(int ac, char **av)
017ff1
 #endif
017ff1
 	__progname = ssh_get_progname(av[0]);
017ff1
 
017ff1
+        SSLeay_add_all_algorithms();
017ff1
+	if (access("/etc/system-fips", F_OK) == 0)
017ff1
+		if (! FIPSCHECK_verify(NULL, NULL)) {
017ff1
+			openlog(__progname, LOG_PID, LOG_AUTHPRIV);
017ff1
+			if (FIPS_mode()) {
017ff1
+				syslog(LOG_CRIT, "FIPS integrity verification test failed.");
017ff1
+				cleanup_exit(255);
017ff1
+			}
017ff1
+			else
017ff1
+				syslog(LOG_INFO, "FIPS integrity verification test failed.");
017ff1
+			closelog();
017ff1
+		}
017ff1
 	/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
017ff1
 	saved_argc = ac;
017ff1
 	rexec_argc = ac;
017ff1
@@ -1619,8 +1633,6 @@ main(int ac, char **av)
017ff1
 	else
017ff1
 		closefrom(REEXEC_DEVCRYPTO_RESERVED_FD);
017ff1
 
017ff1
-	OpenSSL_add_all_algorithms();
017ff1
-
017ff1
 	/* If requested, redirect the logs to the specified logfile. */
017ff1
 	if (logfile != NULL) {
017ff1
 		log_redirect_stderr_to(logfile);
017ff1
@@ -1798,6 +1810,10 @@ main(int ac, char **av)
017ff1
 		debug("private host key: #%d type %d %s", i, keytype,
017ff1
 		    key_type(key ? key : pubkey));
017ff1
 	}
017ff1
+	if ((options.protocol & SSH_PROTO_1) && FIPS_mode()) {
017ff1
+		logit("Disabling protocol version 1. Not allowed in the FIPS mode.");
017ff1
+		options.protocol &= ~SSH_PROTO_1;
017ff1
+	}
017ff1
 	if ((options.protocol & SSH_PROTO_1) && !sensitive_data.have_ssh1_key) {
017ff1
 		logit("Disabling protocol version 1. Could not load host key");
017ff1
 		options.protocol &= ~SSH_PROTO_1;
017ff1
@@ -1961,6 +1977,10 @@ main(int ac, char **av)
017ff1
 	/* Reinitialize the log (because of the fork above). */
017ff1
 	log_init(__progname, options.log_level, options.log_facility, log_stderr);
017ff1
 
017ff1
+	if (FIPS_mode()) {
017ff1
+		logit("FIPS mode initialized");
017ff1
+	}
017ff1
+
017ff1
 	/* Chdir to the root directory so that the current disk can be
017ff1
 	   unmounted if desired. */
017ff1
 	if (chdir("/") == -1)
017ff1
@@ -2530,6 +2550,9 @@ do_ssh2_kex(void)
017ff1
 	if (options.ciphers != NULL) {
017ff1
 		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
017ff1
 		myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
017ff1
+	} else if (FIPS_mode()) {
017ff1
+		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
017ff1
+		myproposal[PROPOSAL_ENC_ALGS_STOC] = KEX_FIPS_ENCRYPT;
017ff1
 	}
017ff1
 	myproposal[PROPOSAL_ENC_ALGS_CTOS] =
017ff1
 	    compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
017ff1
@@ -2539,6 +2562,9 @@ do_ssh2_kex(void)
017ff1
 	if (options.macs != NULL) {
017ff1
 		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
017ff1
 		myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
017ff1
+	} else if (FIPS_mode()) {
017ff1
+		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
017ff1
+		myproposal[PROPOSAL_MAC_ALGS_STOC] = KEX_FIPS_MAC;
017ff1
 	}
017ff1
 	if (options.compression == COMP_NONE) {
017ff1
 		myproposal[PROPOSAL_COMP_ALGS_CTOS] =
017ff1
@@ -2549,6 +2575,8 @@ do_ssh2_kex(void)
017ff1
 	}
017ff1
 	if (options.kex_algorithms != NULL)
017ff1
 		myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
017ff1
+	else if (FIPS_mode())
017ff1
+		myproposal[PROPOSAL_KEX_ALGS] = KEX_DEFAULT_KEX_FIPS;
017ff1
 
017ff1
 	myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(
017ff1
 	    myproposal[PROPOSAL_KEX_ALGS]);
017ff1
@@ -2575,10 +2603,14 @@ do_ssh2_kex(void)
017ff1
 	if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
017ff1
 		orig = NULL;
017ff1
 
017ff1
-	if (options.gss_keyex)
017ff1
-		gss = ssh_gssapi_server_mechanisms();
017ff1
-	else
017ff1
-		gss = NULL;
017ff1
+	if (options.gss_keyex) {
017ff1
+		if (FIPS_mode()) {
017ff1
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
017ff1
+			options.gss_keyex = 0;
017ff1
+		} else {
017ff1
+			gss = ssh_gssapi_server_mechanisms();
017ff1
+		}
017ff1
+	}
017ff1
 
017ff1
 	if (gss && orig)
017ff1
 		xasprintf(&newstr, "%s,%s", gss, orig);