rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
674526
diff -up openssh-6.6p1/Makefile.in.fips openssh-6.6p1/Makefile.in
674526
--- openssh-6.6p1/Makefile.in.fips	2015-08-13 15:09:43.343350136 +0200
674526
+++ openssh-6.6p1/Makefile.in	2015-08-13 15:09:43.356350114 +0200
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)
674526
@@ -187,7 +187,7 @@ ctr-cavstest$(EXEEXT): $(LIBCOMPAT) libs
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)
674526
diff -up openssh-6.6p1/auth-rsa.c.fips openssh-6.6p1/auth-rsa.c
674526
--- openssh-6.6p1/auth-rsa.c.fips	2015-08-13 15:09:43.344350134 +0200
674526
+++ openssh-6.6p1/auth-rsa.c	2015-08-13 15:09:43.354350118 +0200
674526
@@ -244,7 +244,7 @@ rsa_key_allowed_in_file(struct passwd *p
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);
674526
diff -up openssh-6.6p1/auth2-pubkey.c.fips openssh-6.6p1/auth2-pubkey.c
674526
--- openssh-6.6p1/auth2-pubkey.c.fips	2015-08-13 15:09:43.345350133 +0200
674526
+++ openssh-6.6p1/auth2-pubkey.c	2015-08-13 15:09:43.353350119 +0200
674526
@@ -214,8 +214,7 @@ pubkey_auth_info(Authctxt *authctxt, con
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,
674526
@@ -223,7 +222,7 @@ pubkey_auth_info(Authctxt *authctxt, con
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);
674526
diff -up openssh-6.6p1/authfile.c.fips openssh-6.6p1/authfile.c
674526
--- openssh-6.6p1/authfile.c.fips	2015-08-13 15:09:43.213350355 +0200
674526
+++ openssh-6.6p1/authfile.c	2015-08-13 15:09:43.354350118 +0200
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"
674526
@@ -1008,7 +1009,10 @@ key_parse_private_type(Buffer *blob, int
674526
 
674526
 	switch (type) {
674526
 	case KEY_RSA1:
674526
-		return key_parse_private_rsa1(blob, passphrase, commentp);
674526
+		if (! FIPS_mode())
674526
+			return key_parse_private_rsa1(blob, passphrase, commentp);
674526
+		error("%s: cannot parse rsa1 key in FIPS mode", __func__);
674526
+		break;
674526
 	case KEY_DSA:
674526
 	case KEY_ECDSA:
674526
 	case KEY_RSA:
674526
@@ -1068,7 +1072,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);
674526
@@ -1080,9 +1084,10 @@ key_parse_private(Buffer *buffer, const
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
 }
674526
diff -up openssh-6.6p1/cipher-ctr.c.fips openssh-6.6p1/cipher-ctr.c
674526
--- openssh-6.6p1/cipher-ctr.c.fips	2015-08-13 15:09:43.254350286 +0200
674526
+++ openssh-6.6p1/cipher-ctr.c	2015-08-13 15:09:43.354350118 +0200
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
 }
674526
diff -up openssh-6.6p1/cipher.c.fips openssh-6.6p1/cipher.c
674526
--- openssh-6.6p1/cipher.c.fips	2015-08-13 15:09:43.345350133 +0200
674526
+++ openssh-6.6p1/cipher.c	2015-08-13 15:09:43.354350118 +0200
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;
674526
diff -up openssh-6.6p1/dh.h.fips openssh-6.6p1/dh.h
674526
--- openssh-6.6p1/dh.h.fips	2013-10-10 01:32:40.000000000 +0200
674526
+++ openssh-6.6p1/dh.h	2015-08-13 15:09:43.354350118 +0200
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
 /*
674526
diff -up openssh-6.6p1/entropy.c.fips openssh-6.6p1/entropy.c
674526
--- openssh-6.6p1/entropy.c.fips	2015-08-13 15:09:43.238350313 +0200
674526
+++ openssh-6.6p1/entropy.c	2015-08-13 15:09:43.355350116 +0200
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");
674526
diff -up openssh-6.6p1/kex.c.fips openssh-6.6p1/kex.c
674526
--- openssh-6.6p1/kex.c.fips	2015-08-13 15:09:43.350350124 +0200
674526
+++ openssh-6.6p1/kex.c	2015-08-13 15:09:43.355350116 +0200
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
 		}
674526
diff -up openssh-6.6p1/kexecdhc.c.fips openssh-6.6p1/kexecdhc.c
674526
--- openssh-6.6p1/kexecdhc.c.fips	2014-02-04 01:20:15.000000000 +0100
674526
+++ openssh-6.6p1/kexecdhc.c	2015-08-13 15:09:43.355350116 +0200
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 */
674526
diff -up openssh-6.6p1/kexecdhs.c.fips openssh-6.6p1/kexecdhs.c
674526
--- openssh-6.6p1/kexecdhs.c.fips	2014-02-04 01:20:15.000000000 +0100
674526
+++ openssh-6.6p1/kexecdhs.c	2015-08-13 15:09:43.355350116 +0200
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 */
674526
diff -up openssh-6.6p1/kexgexc.c.fips openssh-6.6p1/kexgexc.c
674526
--- openssh-6.6p1/kexgexc.c.fips	2014-02-04 01:20:15.000000000 +0100
674526
+++ openssh-6.6p1/kexgexc.c	2015-08-13 15:09:43.355350116 +0200
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);
674526
diff -up openssh-6.6p1/kexgexs.c.fips openssh-6.6p1/kexgexs.c
674526
--- openssh-6.6p1/kexgexs.c.fips	2014-02-04 01:20:15.000000000 +0100
674526
+++ openssh-6.6p1/kexgexs.c	2015-08-13 15:09:43.355350116 +0200
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:
674526
diff -up openssh-6.6p1/key.c.fips openssh-6.6p1/key.c
674526
--- openssh-6.6p1/key.c.fips	2015-08-13 15:09:43.345350133 +0200
674526
+++ openssh-6.6p1/key.c	2015-08-13 15:09:43.356350114 +0200
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
 }
674526
diff -up openssh-6.6p1/mac.c.fips openssh-6.6p1/mac.c
674526
--- openssh-6.6p1/mac.c.fips	2015-08-13 15:09:43.346350131 +0200
674526
+++ openssh-6.6p1/mac.c	2015-08-13 15:09:43.356350114 +0200
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) {
674526
diff -up openssh-6.6p1/myproposal.h.fips openssh-6.6p1/myproposal.h
674526
--- openssh-6.6p1/myproposal.h.fips	2013-12-07 01:24:02.000000000 +0100
674526
+++ openssh-6.6p1/myproposal.h	2015-08-13 15:10:30.288271102 +0200
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,
674526
diff -up openssh-6.6p1/ssh-keygen.c.fips openssh-6.6p1/ssh-keygen.c
674526
--- openssh-6.6p1/ssh-keygen.c.fips	2015-08-13 15:09:43.296350215 +0200
674526
+++ openssh-6.6p1/ssh-keygen.c	2015-08-13 15:09:43.360350107 +0200
674526
@@ -195,6 +195,12 @@ type_bits_valid(int type, u_int32_t *bit
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)
674526
diff -up openssh-6.6p1/ssh.c.fips openssh-6.6p1/ssh.c
674526
--- openssh-6.6p1/ssh.c.fips	2014-02-27 00:17:13.000000000 +0100
674526
+++ openssh-6.6p1/ssh.c	2015-08-13 15:09:43.357350112 +0200
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,
674526
diff -up openssh-6.6p1/sshconnect2.c.fips openssh-6.6p1/sshconnect2.c
674526
--- openssh-6.6p1/sshconnect2.c.fips	2015-08-13 15:09:43.342350138 +0200
674526
+++ openssh-6.6p1/sshconnect2.c	2015-08-13 15:09:43.357350112 +0200
674526
@@ -46,6 +46,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"
674526
@@ -170,21 +172,26 @@ ssh_kex2(char *host, struct sockaddr *ho
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
-
674526
-		gss = ssh_gssapi_client_mechanisms(gss_host,
674526
-		    options.gss_client_identity, options.gss_kex_algorithms);
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 {
674526
+			/* 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
+
674526
+			gss = ssh_gssapi_client_mechanisms(gss_host,
674526
+			    options.gss_client_identity, options.gss_kex_algorithms);
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
674526
@@ -196,6 +203,10 @@ ssh_kex2(char *host, struct sockaddr *ho
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]);
674526
@@ -211,7 +222,11 @@ ssh_kex2(char *host, struct sockaddr *ho
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);
674526
@@ -223,9 +238,11 @@ ssh_kex2(char *host, struct sockaddr *ho
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 */
674526
diff -up openssh-6.6p1/sshd.c.fips openssh-6.6p1/sshd.c
674526
--- openssh-6.6p1/sshd.c.fips	2015-08-13 15:09:43.352350121 +0200
674526
+++ openssh-6.6p1/sshd.c	2015-08-13 15:09:43.359350109 +0200
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
674526
@@ -1473,6 +1475,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;
674526
@@ -1624,8 +1638,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);
674526
@@ -1803,6 +1815,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;
674526
@@ -1966,6 +1982,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)
674526
@@ -2537,6 +2557,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]);
674526
@@ -2546,6 +2569,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] =
674526
@@ -2556,6 +2582,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]);
674526
@@ -2582,10 +2610,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);