vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jakub Jelen 132f8f
diff -up openssh-6.8p1/Makefile.in.fips openssh-6.8p1/Makefile.in
Jakub Jelen 132f8f
--- openssh-6.8p1/Makefile.in.fips	2015-03-19 13:14:22.221212174 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/Makefile.in	2015-03-19 13:14:22.230212157 +0100
Jakub Jelen 132f8f
@@ -168,25 +168,25 @@ libssh.a: $(LIBSSH_OBJS)
Petr Lautrbach 802815
 	$(RANLIB) $@
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHOBJS)
Petr Lautrbach 802815
-	$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHLIBS) $(LIBS) $(GSSLIBS)
Petr Lautrbach 802815
+	$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(SSHLIBS) $(LIBS) $(GSSLIBS)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 sshd$(EXEEXT): libssh.a	$(LIBCOMPAT) $(SSHDOBJS)
Petr Lautrbach 802815
-	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS) $(GSSLIBS) $(K5LIBS)
Petr Lautrbach 802815
+	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(SSHDLIBS) $(LIBS) $(GSSLIBS) $(K5LIBS)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o
Petr Lautrbach 802815
 	$(LD) -o $@ scp.o progressmeter.o bufaux.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o
Petr Lautrbach 802815
-	$(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Petr Lautrbach 802815
+	$(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 ssh-agent$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-agent.o ssh-pkcs11-client.o
Petr Lautrbach 802815
-	$(LD) -o $@ ssh-agent.o ssh-pkcs11-client.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Petr Lautrbach 802815
+	$(LD) -o $@ ssh-agent.o ssh-pkcs11-client.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 ssh-keygen$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keygen.o
Petr Lautrbach 802815
-	$(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Petr Lautrbach 802815
+	$(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 ssh-keysign$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keysign.o roaming_dummy.o readconf.o
Petr Lautrbach 802815
-	$(LD) -o $@ ssh-keysign.o readconf.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Petr Lautrbach 802815
+	$(LD) -o $@ ssh-keysign.o readconf.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 ssh-pkcs11-helper$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-pkcs11-helper.o ssh-pkcs11.o
Petr Lautrbach 802815
 	$(LD) -o $@ ssh-pkcs11-helper.o ssh-pkcs11.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lopenbsd-compat $(LIBS)
Jakub Jelen 132f8f
@@ -204,7 +204,7 @@ ssh-cavs$(EXEEXT): $(LIBCOMPAT) libssh.a
Jakub Jelen bb3e88
 	$(LD) -o $@ ssh-cavs.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o roaming_dummy.o
Petr Lautrbach 802815
-	$(LD) -o $@ ssh-keyscan.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh $(LIBS)
Petr Lautrbach 802815
+	$(LD) -o $@ ssh-keyscan.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(LIBS)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o sftp-server-main.o
Petr Lautrbach 802815
 	$(LD) -o $@ sftp-server.o sftp-common.o sftp-server-main.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Jakub Jelen 132f8f
diff -up openssh-6.8p1/cipher-ctr.c.fips openssh-6.8p1/cipher-ctr.c
Jakub Jelen 132f8f
--- openssh-6.8p1/cipher-ctr.c.fips	2015-03-19 13:14:22.155212302 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/cipher-ctr.c	2015-03-19 13:14:22.230212157 +0100
Petr Lautrbach 802815
@@ -179,7 +179,8 @@ evp_aes_128_ctr(void)
Petr Lautrbach 802815
 	aes_ctr.do_cipher = ssh_aes_ctr;
Petr Lautrbach 802815
 #ifndef SSH_OLD_EVP
Petr Lautrbach 802815
 	aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
Petr Lautrbach 802815
-	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
Petr Lautrbach 802815
+	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV |
Petr Lautrbach 802815
+	    EVP_CIPH_FLAG_FIPS;
Petr Lautrbach 802815
 #endif
Petr Lautrbach 802815
 	return (&aes_ctr);
Petr Lautrbach 802815
 }
Jakub Jelen 132f8f
diff -up openssh-6.8p1/cipher.c.fips openssh-6.8p1/cipher.c
Jakub Jelen 132f8f
--- openssh-6.8p1/cipher.c.fips	2015-03-19 13:14:22.224212169 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/cipher.c	2015-03-19 13:14:22.230212157 +0100
Petr Lautrbach 802815
@@ -39,6 +39,8 @@
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 #include <sys/types.h>
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+#include <openssl/fips.h>
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 #include <string.h>
Petr Lautrbach 802815
 #include <stdarg.h>
Petr Lautrbach 802815
 #include <stdio.h>
Jakub Jelen 132f8f
@@ -99,6 +101,26 @@ static const struct sshcipher ciphers[]
Petr Lautrbach 802815
 	{ NULL,		SSH_CIPHER_INVALID, 0, 0, 0, 0, 0, 0, NULL }
Petr Lautrbach 802815
 };
Petr Lautrbach 802815
 
Petr Lautrbach 190035
+static const struct sshcipher fips_ciphers[] = {
Petr Lautrbach 802815
+	{ "none",	SSH_CIPHER_NONE, 8, 0, 0, 0, 0, 0, EVP_enc_null },
Petr Lautrbach 802815
+	{ "3des-cbc",	SSH_CIPHER_SSH2, 8, 24, 0, 0, 0, 1, EVP_des_ede3_cbc },
Petr Lautrbach 802815
+	{ "aes128-cbc",	SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, 1, EVP_aes_128_cbc },
Petr Lautrbach 802815
+	{ "aes192-cbc",	SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, 1, EVP_aes_192_cbc },
Petr Lautrbach 802815
+	{ "aes256-cbc",	SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, 1, EVP_aes_256_cbc },
Petr Lautrbach 802815
+	{ "rijndael-cbc@lysator.liu.se",
Petr Lautrbach 802815
+			SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, 1, EVP_aes_256_cbc },
Petr Lautrbach 802815
+	{ "aes128-ctr",	SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, 0, EVP_aes_128_ctr },
Petr Lautrbach 802815
+	{ "aes192-ctr",	SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, 0, EVP_aes_192_ctr },
Petr Lautrbach 802815
+	{ "aes256-ctr",	SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, 0, EVP_aes_256_ctr },
Petr Lautrbach 802815
+#ifdef OPENSSL_HAVE_EVPGCM
Petr Lautrbach 802815
+	{ "aes128-gcm@openssh.com",
Petr Lautrbach 802815
+			SSH_CIPHER_SSH2, 16, 16, 12, 16, 0, 0, EVP_aes_128_gcm },
Petr Lautrbach 802815
+	{ "aes256-gcm@openssh.com",
Petr Lautrbach 802815
+			SSH_CIPHER_SSH2, 16, 32, 12, 16, 0, 0, EVP_aes_256_gcm },
Petr Lautrbach 802815
+#endif
Petr Lautrbach 802815
+	{ NULL,		SSH_CIPHER_INVALID, 0, 0, 0, 0, 0, 0, NULL }
Petr Lautrbach 802815
+};
Petr Lautrbach 190035
+
Petr Lautrbach 802815
 /*--*/
Petr Lautrbach 802815
 
Petr Lautrbach 190035
 /* Returns a comma-separated list of supported ciphers. */
Petr Lautrbach 190035
@@ -109,7 +131,7 @@ cipher_alg_list(char sep, int auth_only)
Petr Lautrbach 802815
 	size_t nlen, rlen = 0;
Petr Lautrbach 190035
 	const struct sshcipher *c;
Petr Lautrbach 802815
 
Petr Lautrbach 802815
-	for (c = ciphers; c->name != NULL; c++) {
Petr Lautrbach 802815
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++) {
Petr Lautrbach 802815
 		if (c->number != SSH_CIPHER_SSH2)
Petr Lautrbach 802815
 			continue;
Petr Lautrbach 802815
 		if (auth_only && c->auth_len == 0)
Petr Lautrbach 190035
@@ -193,7 +215,7 @@ const struct sshcipher *
Petr Lautrbach 802815
 cipher_by_name(const char *name)
Petr Lautrbach 802815
 {
Petr Lautrbach 190035
 	const struct sshcipher *c;
Petr Lautrbach 802815
-	for (c = ciphers; c->name != NULL; c++)
Petr Lautrbach 802815
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
Petr Lautrbach 802815
 		if (strcmp(c->name, name) == 0)
Petr Lautrbach 802815
 			return c;
Petr Lautrbach 802815
 	return NULL;
Petr Lautrbach 190035
@@ -203,7 +225,7 @@ const struct sshcipher *
Petr Lautrbach 802815
 cipher_by_number(int id)
Petr Lautrbach 802815
 {
Petr Lautrbach 190035
 	const struct sshcipher *c;
Petr Lautrbach 802815
-	for (c = ciphers; c->name != NULL; c++)
Petr Lautrbach 802815
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
Petr Lautrbach 802815
 		if (c->number == id)
Petr Lautrbach 802815
 			return c;
Petr Lautrbach 802815
 	return NULL;
Petr Lautrbach 190035
@@ -244,7 +266,7 @@ cipher_number(const char *name)
Petr Lautrbach 190035
 	const struct sshcipher *c;
Petr Lautrbach 802815
 	if (name == NULL)
Petr Lautrbach 802815
 		return -1;
Petr Lautrbach 802815
-	for (c = ciphers; c->name != NULL; c++)
Petr Lautrbach 802815
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
Petr Lautrbach 802815
 		if (strcasecmp(c->name, name) == 0)
Petr Lautrbach 802815
 			return c->number;
Petr Lautrbach 802815
 	return -1;
Jakub Jelen 132f8f
diff -up openssh-6.8p1/dh.h.fips openssh-6.8p1/dh.h
Jakub Jelen 132f8f
--- openssh-6.8p1/dh.h.fips	2015-03-17 06:49:20.000000000 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/dh.h	2015-03-19 13:14:22.230212157 +0100
Jakub Jelen 132f8f
@@ -45,6 +45,7 @@ u_int	 dh_estimate(int);
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 /* Min and max values from RFC4419. */
Petr Lautrbach 802815
 #define DH_GRP_MIN	1024
Petr Lautrbach 802815
+#define DH_GRP_MIN_FIPS	2048
Petr Lautrbach 802815
 #define DH_GRP_MAX	8192
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 /*
Jakub Jelen 132f8f
diff -up openssh-6.8p1/entropy.c.fips openssh-6.8p1/entropy.c
Jakub Jelen 132f8f
--- openssh-6.8p1/entropy.c.fips	2015-03-19 13:14:22.147212317 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/entropy.c	2015-03-19 13:14:22.230212157 +0100
Jakub Jelen 132f8f
@@ -217,6 +217,9 @@ seed_rng(void)
Petr Lautrbach 802815
 		fatal("OpenSSL version mismatch. Built against %lx, you "
Petr Lautrbach 802815
 		    "have %lx", (u_long)OPENSSL_VERSION_NUMBER, SSLeay());
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+	/* clean the PRNG status when exiting the program */
Petr Lautrbach 802815
+	atexit(RAND_cleanup);
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 #ifndef OPENSSL_PRNG_ONLY
Petr Lautrbach 802815
 	if (RAND_status() == 1) {
Petr Lautrbach 802815
 		debug3("RNG is ready, skipping seeding");
Jakub Jelen 132f8f
diff -up openssh-6.8p1/kex.c.fips openssh-6.8p1/kex.c
Jakub Jelen 132f8f
--- openssh-6.8p1/kex.c.fips	2015-03-19 13:14:22.165212282 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/kex.c	2015-03-19 13:14:22.230212157 +0100
Petr Lautrbach 190035
@@ -35,6 +35,7 @@
Petr Lautrbach 802815
 
Petr Lautrbach 190035
 #ifdef WITH_OPENSSL
Petr Lautrbach 802815
 #include <openssl/crypto.h>
Petr Lautrbach 802815
+#include <openssl/fips.h>
Petr Lautrbach 190035
 #endif
Petr Lautrbach 802815
 
Jakub Jelen 132f8f
 #include "ssh2.h"
Petr Lautrbach 190035
@@ -107,6 +108,25 @@ static const struct kexalg kexalgs[] = {
Petr Lautrbach 802815
 	{ NULL, -1, -1, -1},
Petr Lautrbach 802815
 };
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+static const struct kexalg kexalgs_fips[] = {
Petr Lautrbach 802815
+	{ KEX_DH14, KEX_DH_GRP14_SHA1, 0, SSH_DIGEST_SHA1 },
Petr Lautrbach 802815
+	{ KEX_DHGEX_SHA1, KEX_DH_GEX_SHA1, 0, SSH_DIGEST_SHA1 },
Petr Lautrbach 802815
+#ifdef HAVE_EVP_SHA256
Petr Lautrbach 802815
+	{ KEX_DHGEX_SHA256, KEX_DH_GEX_SHA256, 0, SSH_DIGEST_SHA256 },
Petr Lautrbach 802815
+#endif
Petr Lautrbach 802815
+#ifdef OPENSSL_HAS_ECC
Petr Lautrbach 802815
+	{ KEX_ECDH_SHA2_NISTP256, KEX_ECDH_SHA2,
Petr Lautrbach 802815
+	    NID_X9_62_prime256v1, SSH_DIGEST_SHA256 },
Petr Lautrbach 802815
+	{ KEX_ECDH_SHA2_NISTP384, KEX_ECDH_SHA2, NID_secp384r1,
Petr Lautrbach 802815
+	    SSH_DIGEST_SHA384 },
Petr Lautrbach 802815
+# ifdef OPENSSL_HAS_NISTP521
Petr Lautrbach 802815
+	{ KEX_ECDH_SHA2_NISTP521, KEX_ECDH_SHA2, NID_secp521r1,
Petr Lautrbach 802815
+	    SSH_DIGEST_SHA512 },
Petr Lautrbach 802815
+# endif
Petr Lautrbach 802815
+#endif
Jakub Jelen 580f98
+	{ NULL, -1, -1, -1},
Petr Lautrbach 802815
+};
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 char *
Petr Lautrbach 802815
 kex_alg_list(char sep)
Petr Lautrbach 802815
 {
Jakub Jelen 132f8f
@@ -134,7 +154,7 @@ kex_alg_by_name(const char *name)
Petr Lautrbach 802815
 {
Petr Lautrbach 802815
 	const struct kexalg *k;
Petr Lautrbach 802815
 
Petr Lautrbach 802815
-	for (k = kexalgs; k->name != NULL; k++) {
Petr Lautrbach 802815
+	for (k = (FIPS_mode() ? kexalgs_fips : kexalgs); k->name != NULL; k++) {
Petr Lautrbach 802815
 		if (strcmp(k->name, name) == 0)
Petr Lautrbach 802815
 			return k;
Petr Lautrbach 802815
 #ifdef GSSAPI
Jakub Jelen 132f8f
@@ -160,7 +180,10 @@ kex_names_valid(const char *names)
Petr Lautrbach 802815
 	for ((p = strsep(&cp, ",")); p && *p != '\0';
Petr Lautrbach 802815
 	    (p = strsep(&cp, ","))) {
Petr Lautrbach 802815
 		if (kex_alg_by_name(p) == NULL) {
Petr Lautrbach 802815
-			error("Unsupported KEX algorithm \"%.100s\"", p);
Petr Lautrbach 802815
+			if (FIPS_mode())
Petr Lautrbach 802815
+				error("\"%.100s\" is not allowed in FIPS mode", p);
Petr Lautrbach 802815
+			else
Petr Lautrbach 802815
+				error("Unsupported KEX algorithm \"%.100s\"", p);
Petr Lautrbach 802815
 			free(s);
Petr Lautrbach 802815
 			return 0;
Petr Lautrbach 802815
 		}
Jakub Jelen 132f8f
diff -up openssh-6.8p1/kexgexc.c.fips openssh-6.8p1/kexgexc.c
Jakub Jelen 132f8f
--- openssh-6.8p1/kexgexc.c.fips	2015-03-19 13:14:22.196212223 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/kexgexc.c	2015-03-19 13:15:11.462117016 +0100
Jakub Jelen 132f8f
@@ -28,6 +28,8 @@
Petr Lautrbach 802815
 
Jakub Jelen 132f8f
 #ifdef WITH_OPENSSL
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+#include <openssl/fips.h>
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 #include <sys/types.h>
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 #include <openssl/dh.h>
Jakub Jelen 132f8f
@@ -62,7 +64,7 @@ kexgex_client(struct ssh *ssh)
Jakub Jelen 132f8f
 
Jakub Jelen 132f8f
 	nbits = dh_estimate(kex->dh_need * 8);
Petr Lautrbach 08fe9e
 
Jakub Jelen 132f8f
-	kex->min = DH_GRP_MIN;
Jakub Jelen 132f8f
+	kex->min = FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN;
Jakub Jelen 132f8f
 	kex->max = DH_GRP_MAX;
Petr Lautrbach 08fe9e
 
Petr Lautrbach 08fe9e
 	/* Servers with MAX4096DH need a preferred size (nbits) <= 4096.
Jakub Jelen 132f8f
diff -up openssh-6.8p1/kexgexs.c.fips openssh-6.8p1/kexgexs.c
Jakub Jelen 132f8f
--- openssh-6.8p1/kexgexs.c.fips	2015-03-17 06:49:20.000000000 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/kexgexs.c	2015-03-19 13:14:22.231212155 +0100
Jakub Jelen 132f8f
@@ -87,9 +87,9 @@ input_kex_dh_gex_request(int type, u_int
Jakub Jelen 132f8f
 		kex->nbits = nbits;
Jakub Jelen 132f8f
 		kex->min = min;
Jakub Jelen 132f8f
 		kex->max = max;
Petr Lautrbach 802815
-		min = MAX(DH_GRP_MIN, min);
Petr Lautrbach 802815
+		min = MAX(FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN, min);
Petr Lautrbach 802815
 		max = MIN(DH_GRP_MAX, max);
Petr Lautrbach 802815
-		nbits = MAX(DH_GRP_MIN, nbits);
Petr Lautrbach 802815
+		nbits = MAX(FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN, nbits);
Petr Lautrbach 802815
 		nbits = MIN(DH_GRP_MAX, nbits);
Petr Lautrbach 802815
 		break;
Petr Lautrbach 802815
 	case SSH2_MSG_KEX_DH_GEX_REQUEST_OLD:
Jakub Jelen 132f8f
@@ -99,7 +99,7 @@ input_kex_dh_gex_request(int type, u_int
Jakub Jelen 132f8f
 			goto out;
Jakub Jelen 132f8f
 		kex->nbits = nbits;
Petr Lautrbach 802815
 		/* unused for old GEX */
Jakub Jelen 132f8f
-		kex->min = min = DH_GRP_MIN;
Jakub Jelen 132f8f
+		kex->min = min = FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN;
Jakub Jelen 132f8f
 		kex->max = max = DH_GRP_MAX;
Petr Lautrbach 802815
 		break;
Petr Lautrbach 802815
 	default:
Jakub Jelen 132f8f
diff -up openssh-6.8p1/mac.c.fips openssh-6.8p1/mac.c
Jakub Jelen 132f8f
--- openssh-6.8p1/mac.c.fips	2015-03-19 13:14:22.224212169 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/mac.c	2015-03-19 13:14:22.231212155 +0100
Petr Lautrbach 802815
@@ -27,6 +27,8 @@
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 #include <sys/types.h>
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+#include <openssl/fips.h>
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 #include <string.h>
Jakub Jelen 132f8f
 #include <stdio.h>
Jakub Jelen 132f8f
 
Jakub Jelen 132f8f
@@ -54,7 +56,7 @@ struct macalg {
Petr Lautrbach 802815
 	int		etm;		/* Encrypt-then-MAC */
Petr Lautrbach 802815
 };
Petr Lautrbach 802815
 
Petr Lautrbach 802815
-static const struct macalg macs[] = {
Petr Lautrbach 802815
+static const struct macalg all_macs[] = {
Petr Lautrbach 802815
 	/* Encrypt-and-MAC (encrypt-and-authenticate) variants */
Petr Lautrbach 802815
 	{ "hmac-sha1",				SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 0 },
Petr Lautrbach 802815
 	{ "hmac-sha1-96",			SSH_DIGEST, SSH_DIGEST_SHA1, 96, 0, 0, 0 },
Jakub Jelen 132f8f
@@ -85,6 +87,24 @@ static const struct macalg macs[] = {
Petr Lautrbach 802815
 	{ NULL,					0, 0, 0, 0, 0, 0 }
Petr Lautrbach 802815
 };
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+static const struct macalg fips_macs[] = {
Petr Lautrbach 802815
+	/* Encrypt-and-MAC (encrypt-and-authenticate) variants */
Petr Lautrbach 802815
+	{ "hmac-sha1",				SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 0 },
Petr Lautrbach 802815
+#ifdef HAVE_EVP_SHA256
Petr Lautrbach 802815
+	{ "hmac-sha2-256",			SSH_DIGEST, SSH_DIGEST_SHA256, 0, 0, 0, 0 },
Petr Lautrbach 802815
+	{ "hmac-sha2-512",			SSH_DIGEST, SSH_DIGEST_SHA512, 0, 0, 0, 0 },
Petr Lautrbach 802815
+#endif
Petr Lautrbach 802815
+
Petr Lautrbach 802815
+	/* Encrypt-then-MAC variants */
Petr Lautrbach 802815
+	{ "hmac-sha1-etm@openssh.com",		SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 1 },
Petr Lautrbach 802815
+#ifdef HAVE_EVP_SHA256
Petr Lautrbach 802815
+	{ "hmac-sha2-256-etm@openssh.com",	SSH_DIGEST, SSH_DIGEST_SHA256, 0, 0, 0, 1 },
Petr Lautrbach 802815
+	{ "hmac-sha2-512-etm@openssh.com",	SSH_DIGEST, SSH_DIGEST_SHA512, 0, 0, 0, 1 },
Petr Lautrbach 802815
+#endif
Petr Lautrbach 802815
+
Petr Lautrbach 802815
+	{ NULL,					0, 0, 0, 0, 0, 0 }
Petr Lautrbach 802815
+};
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 /* Returns a list of supported MACs separated by the specified char. */
Petr Lautrbach 802815
 char *
Petr Lautrbach 802815
 mac_alg_list(char sep)
Jakub Jelen 132f8f
@@ -93,7 +113,7 @@ mac_alg_list(char sep)
Petr Lautrbach 802815
 	size_t nlen, rlen = 0;
Petr Lautrbach 802815
 	const struct macalg *m;
Petr Lautrbach 802815
 
Petr Lautrbach 802815
-	for (m = macs; m->name != NULL; m++) {
Petr Lautrbach 802815
+	for (m = FIPS_mode() ? fips_macs : all_macs; m->name != NULL; m++) {
Petr Lautrbach 802815
 		if (ret != NULL)
Petr Lautrbach 802815
 			ret[rlen++] = sep;
Petr Lautrbach 802815
 		nlen = strlen(m->name);
Jakub Jelen 132f8f
@@ -132,7 +152,7 @@ mac_setup(struct sshmac *mac, char *name
Petr Lautrbach 802815
 {
Petr Lautrbach 802815
 	const struct macalg *m;
Petr Lautrbach 802815
 
Petr Lautrbach 802815
-	for (m = macs; m->name != NULL; m++) {
Petr Lautrbach 802815
+	for (m = FIPS_mode() ? fips_macs : all_macs; m->name != NULL; m++) {
Petr Lautrbach 802815
 		if (strcmp(name, m->name) != 0)
Petr Lautrbach 802815
 			continue;
Jakub Jelen 132f8f
 		if (mac != NULL)
Jakub Jelen 132f8f
diff -up openssh-6.8p1/myproposal.h.fips openssh-6.8p1/myproposal.h
Jakub Jelen 132f8f
--- openssh-6.8p1/myproposal.h.fips	2015-03-17 06:49:20.000000000 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/myproposal.h	2015-03-19 13:14:22.231212155 +0100
Petr Lautrbach 190035
@@ -140,6 +140,28 @@
Petr Lautrbach 190035
 	"hmac-sha1-96," \
Petr Lautrbach 190035
 	"hmac-md5-96"
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+#define KEX_DEFAULT_KEX_FIPS		\
Petr Lautrbach 802815
+	KEX_ECDH_METHODS \
Petr Lautrbach 802815
+	KEX_SHA256_METHODS \
Petr Lautrbach 802815
+	"diffie-hellman-group-exchange-sha1," \
Petr Lautrbach 802815
+	"diffie-hellman-group14-sha1"
Petr Lautrbach 802815
+#define	KEX_FIPS_ENCRYPT \
Petr Lautrbach 802815
+	"aes128-ctr,aes192-ctr,aes256-ctr," \
Petr Lautrbach 802815
+	"aes128-cbc,3des-cbc," \
Petr Lautrbach 802815
+	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se"
Petr Lautrbach 802815
+#ifdef HAVE_EVP_SHA256
Petr Lautrbach 802815
+#define	KEX_FIPS_MAC \
Petr Lautrbach 802815
+	"hmac-sha1," \
Petr Lautrbach 802815
+	"hmac-sha2-256," \
Petr Lautrbach 802815
+	"hmac-sha2-512," \
Petr Lautrbach 802815
+	"hmac-sha1-etm@openssh.com," \
Petr Lautrbach 802815
+	"hmac-sha2-256-etm@openssh.com," \
Petr Lautrbach 802815
+	"hmac-sha2-512-etm@openssh.com"
Petr Lautrbach 802815
+#else
Petr Lautrbach 802815
+#define        KEX_FIPS_MAC \
Petr Lautrbach 802815
+       "hmac-sha1"
Petr Lautrbach 802815
+#endif
Petr Lautrbach 190035
+
Petr Lautrbach 190035
 #else
Petr Lautrbach 802815
 
Petr Lautrbach 190035
 #define KEX_SERVER_KEX		\
Jakub Jelen 132f8f
diff -up openssh-6.8p1/ssh.c.fips openssh-6.8p1/ssh.c
Jakub Jelen 132f8f
--- openssh-6.8p1/ssh.c.fips	2015-03-17 06:49:20.000000000 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/ssh.c	2015-03-19 13:14:22.232212153 +0100
Petr Lautrbach 190035
@@ -75,6 +75,8 @@
Petr Lautrbach 802815
 #include <openssl/evp.h>
Petr Lautrbach 802815
 #include <openssl/err.h>
Petr Lautrbach 190035
 #endif
Petr Lautrbach 802815
+#include <openssl/fips.h>
Petr Lautrbach 802815
+#include <fipscheck.h>
Petr Lautrbach 802815
 #include "openbsd-compat/openssl-compat.h"
Petr Lautrbach 802815
 #include "openbsd-compat/sys-queue.h"
Petr Lautrbach 802815
 
Jakub Jelen 132f8f
@@ -523,6 +525,14 @@ main(int ac, char **av)
Petr Lautrbach 802815
 	sanitise_stdfd();
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 	__progname = ssh_get_progname(av[0]);
Petr Lautrbach 802815
+        SSLeay_add_all_algorithms();
Petr Lautrbach 802815
+	if (access("/etc/system-fips", F_OK) == 0)
Jakub Jelen 580f98
+		if (! FIPSCHECK_verify(NULL, NULL)){
Petr Lautrbach 802815
+			if (FIPS_mode())
Petr Lautrbach 802815
+				fatal("FIPS integrity verification test failed.");
Petr Lautrbach 802815
+			else
Petr Lautrbach 802815
+				logit("FIPS integrity verification test failed.");
Jakub Jelen 580f98
+	}
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 #ifndef HAVE_SETPROCTITLE
Petr Lautrbach 802815
 	/* Prepare for later setproctitle emulation */
Jakub Jelen 132f8f
@@ -600,6 +610,9 @@ main(int ac, char **av)
Jakub Jelen 132f8f
 	    "ACD:E:F:GI:KL:MNO:PQ:R:S:TVw:W:XYy")) != -1) {
Petr Lautrbach 802815
 		switch (opt) {
Petr Lautrbach 802815
 		case '1':
Petr Lautrbach 802815
+			if (FIPS_mode()) {
Petr Lautrbach 802815
+				fatal("Protocol 1 not allowed in the FIPS mode.");
Petr Lautrbach 802815
+			}
Petr Lautrbach 802815
 			options.protocol = SSH_PROTO_1;
Petr Lautrbach 802815
 			break;
Petr Lautrbach 802815
 		case '2':
Jakub Jelen 132f8f
@@ -941,7 +954,6 @@ main(int ac, char **av)
Petr Lautrbach 802815
 	host_arg = xstrdup(host);
Petr Lautrbach 802815
 
Petr Lautrbach 190035
 #ifdef WITH_OPENSSL
Petr Lautrbach 802815
-	OpenSSL_add_all_algorithms();
Petr Lautrbach 802815
 	ERR_load_crypto_strings();
Petr Lautrbach 190035
 #endif
Petr Lautrbach 802815
 
Jakub Jelen 132f8f
@@ -1115,6 +1127,10 @@ main(int ac, char **av)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 	seed_rng();
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+	if (FIPS_mode()) {
Petr Lautrbach 802815
+		logit("FIPS mode initialized");
Petr Lautrbach 802815
+	}
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 	if (options.user == NULL)
Petr Lautrbach 802815
 		options.user = xstrdup(pw->pw_name);
Petr Lautrbach 802815
 
Jakub Jelen 132f8f
@@ -1192,6 +1208,12 @@ main(int ac, char **av)
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 	timeout_ms = options.connection_timeout * 1000;
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+	if (FIPS_mode()) {
Petr Lautrbach 802815
+		options.protocol &= SSH_PROTO_2;
Petr Lautrbach 802815
+		if (options.protocol == 0)
Petr Lautrbach 802815
+			fatal("Protocol 2 disabled by configuration but required in the FIPS mode.");
Petr Lautrbach 802815
+	}
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 	/* Open a connection to the remote host. */
Petr Lautrbach 802815
 	if (ssh_connect(host, addrs, &hostaddr, options.port,
Petr Lautrbach 802815
 	    options.address_family, options.connection_attempts,
Jakub Jelen 132f8f
diff -up openssh-6.8p1/sshconnect2.c.fips openssh-6.8p1/sshconnect2.c
Jakub Jelen 132f8f
--- openssh-6.8p1/sshconnect2.c.fips	2015-03-19 13:14:22.188212238 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/sshconnect2.c	2015-03-19 13:14:22.232212153 +0100
Petr Lautrbach 190035
@@ -46,6 +46,8 @@
Petr Lautrbach 802815
 #include <vis.h>
Petr Lautrbach 802815
 #endif
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+#include <openssl/fips.h>
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 #include "openbsd-compat/sys-queue.h"
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 #include "xmalloc.h"
Jakub Jelen 132f8f
@@ -172,20 +174,25 @@ ssh_kex2(char *host, struct sockaddr *ho
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 #ifdef GSSAPI
Petr Lautrbach 802815
 	if (options.gss_keyex) {
Petr Lautrbach 802815
-		/* Add the GSSAPI mechanisms currently supported on this 
Petr Lautrbach 802815
-		 * client to the key exchange algorithm proposal */
Petr Lautrbach 802815
-		orig = myproposal[PROPOSAL_KEX_ALGS];
Jakub Jelen 132f8f
-
Jakub Jelen 132f8f
-		if (options.gss_trust_dns)
Jakub Jelen 132f8f
-			gss_host = (char *)get_canonical_hostname(1);
Jakub Jelen 132f8f
-		else
Jakub Jelen 132f8f
-			gss_host = host;
Jakub Jelen 132f8f
-
Jakub Jelen 132f8f
-		gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
Jakub Jelen 132f8f
-		if (gss) {
Jakub Jelen 132f8f
-			debug("Offering GSSAPI proposal: %s", gss);
Jakub Jelen 132f8f
-			xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
Jakub Jelen 132f8f
-			    "%s,%s", gss, orig);
Petr Lautrbach 802815
+		if (FIPS_mode()) {
Petr Lautrbach 802815
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
Petr Lautrbach 802815
+			options.gss_keyex = 0;
Petr Lautrbach 802815
+		} else {
Petr Lautrbach 802815
+			/* Add the GSSAPI mechanisms currently supported on this
Petr Lautrbach 802815
+			 * client to the key exchange algorithm proposal */
Petr Lautrbach 802815
+			orig = myproposal[PROPOSAL_KEX_ALGS];
Jakub Jelen 132f8f
+
Petr Lautrbach 802815
+			if (options.gss_trust_dns)
Petr Lautrbach 802815
+				gss_host = (char *)get_canonical_hostname(1);
Petr Lautrbach 802815
+			else
Petr Lautrbach 802815
+				gss_host = host;
Jakub Jelen 132f8f
+
Petr Lautrbach 802815
+			gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
Petr Lautrbach 802815
+			if (gss) {
Petr Lautrbach 802815
+				debug("Offering GSSAPI proposal: %s", gss);
Petr Lautrbach 802815
+				xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
Petr Lautrbach 802815
+				    "%s,%s", gss, orig);
Petr Lautrbach 802815
+			}
Petr Lautrbach 802815
 		}
Petr Lautrbach 802815
 	}
Petr Lautrbach 802815
 #endif
Jakub Jelen 132f8f
@@ -197,6 +204,10 @@ ssh_kex2(char *host, struct sockaddr *ho
Petr Lautrbach 802815
 	if (options.ciphers != NULL) {
Petr Lautrbach 802815
 		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Petr Lautrbach 802815
 		myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
Petr Lautrbach 802815
+	} else if (FIPS_mode()) {
Petr Lautrbach 802815
+		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Petr Lautrbach 802815
+		myproposal[PROPOSAL_ENC_ALGS_STOC] = KEX_FIPS_ENCRYPT;
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 	}
Petr Lautrbach 802815
 	myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Petr Lautrbach 802815
 	    compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
Jakub Jelen 132f8f
@@ -212,7 +223,11 @@ ssh_kex2(char *host, struct sockaddr *ho
Petr Lautrbach 802815
 	if (options.macs != NULL) {
Petr Lautrbach 802815
 		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
Petr Lautrbach 802815
 		myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
Petr Lautrbach 802815
+	} else if (FIPS_mode()) {
Petr Lautrbach 802815
+		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
Petr Lautrbach 802815
+		myproposal[PROPOSAL_MAC_ALGS_STOC] = KEX_FIPS_MAC;
Petr Lautrbach 802815
 	}
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 	if (options.hostkeyalgorithms != NULL)
Petr Lautrbach 802815
 		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
Petr Lautrbach 802815
 		    compat_pkalg_proposal(options.hostkeyalgorithms);
Jakub Jelen 132f8f
@@ -224,9 +239,11 @@ ssh_kex2(char *host, struct sockaddr *ho
Petr Lautrbach 802815
 	}
Petr Lautrbach 802815
 	if (options.kex_algorithms != NULL)
Petr Lautrbach 802815
 		myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
Petr Lautrbach 802815
+	else if (FIPS_mode())
Petr Lautrbach 802815
+		myproposal[PROPOSAL_KEX_ALGS] = KEX_DEFAULT_KEX_FIPS;
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 	myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(
Petr Lautrbach 802815
 	    myproposal[PROPOSAL_KEX_ALGS]);
Petr Lautrbach 802815
-
Petr Lautrbach 802815
 #ifdef GSSAPI
Petr Lautrbach 802815
 	/* If we've got GSSAPI algorithms, then we also support the
Petr Lautrbach 802815
 	 * 'null' hostkey, as a last resort */
Jakub Jelen 132f8f
diff -up openssh-6.8p1/sshd.c.fips openssh-6.8p1/sshd.c
Jakub Jelen 132f8f
--- openssh-6.8p1/sshd.c.fips	2015-03-19 13:14:22.226212165 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/sshd.c	2015-03-19 13:14:22.232212153 +0100
Petr Lautrbach 190035
@@ -66,6 +66,7 @@
Petr Lautrbach 190035
 #include <grp.h>
Petr Lautrbach 190035
 #include <pwd.h>
Petr Lautrbach 190035
 #include <signal.h>
Petr Lautrbach 190035
+#include <syslog.h>
Petr Lautrbach 190035
 #include <stdarg.h>
Petr Lautrbach 190035
 #include <stdio.h>
Petr Lautrbach 190035
 #include <stdlib.h>
Jakub Jelen 132f8f
@@ -77,6 +78,8 @@
Petr Lautrbach 802815
 #include <openssl/dh.h>
Petr Lautrbach 802815
 #include <openssl/bn.h>
Petr Lautrbach 802815
 #include <openssl/rand.h>
Petr Lautrbach 802815
+#include <openssl/fips.h>
Petr Lautrbach 802815
+#include <fipscheck.h>
Petr Lautrbach 802815
 #include "openbsd-compat/openssl-compat.h"
Petr Lautrbach 190035
 #endif
Petr Lautrbach 802815
 
Jakub Jelen 132f8f
@@ -1543,6 +1546,18 @@ main(int ac, char **av)
Petr Lautrbach 802815
 #endif
Petr Lautrbach 802815
 	__progname = ssh_get_progname(av[0]);
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+        SSLeay_add_all_algorithms();
Petr Lautrbach 802815
+	if (access("/etc/system-fips", F_OK) == 0)
Petr Lautrbach 802815
+		if (! FIPSCHECK_verify(NULL, NULL)) {
Petr Lautrbach 802815
+			openlog(__progname, LOG_PID, LOG_AUTHPRIV);
Petr Lautrbach 802815
+			if (FIPS_mode()) {
Petr Lautrbach 802815
+				syslog(LOG_CRIT, "FIPS integrity verification test failed.");
Petr Lautrbach 802815
+				cleanup_exit(255);
Petr Lautrbach 802815
+			}
Petr Lautrbach 802815
+			else
Petr Lautrbach 802815
+				syslog(LOG_INFO, "FIPS integrity verification test failed.");
Petr Lautrbach 802815
+			closelog();
Petr Lautrbach 802815
+		}
Petr Lautrbach 802815
 	/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
Petr Lautrbach 802815
 	saved_argc = ac;
Petr Lautrbach 802815
 	rexec_argc = ac;
Jakub Jelen 132f8f
@@ -1694,7 +1709,7 @@ main(int ac, char **av)
Petr Lautrbach 802815
 	else
Petr Lautrbach 802815
 		closefrom(REEXEC_DEVCRYPTO_RESERVED_FD);
Petr Lautrbach 802815
 
Petr Lautrbach 190035
-#ifdef WITH_OPENSSL
Petr Lautrbach 190035
+#if 0 /* FIPS */
Petr Lautrbach 190035
 	OpenSSL_add_all_algorithms();
Petr Lautrbach 190035
 #endif
Petr Lautrbach 190035
 
Jakub Jelen 132f8f
@@ -1890,6 +1905,10 @@ main(int ac, char **av)
Jakub Jelen 132f8f
 		    sshkey_type(pubkey) : sshkey_ssh_name(pubkey), fp);
Jakub Jelen 132f8f
 		free(fp);
Petr Lautrbach 802815
 	}
Petr Lautrbach 802815
+	if ((options.protocol & SSH_PROTO_1) && FIPS_mode()) {
Petr Lautrbach 802815
+		logit("Disabling protocol version 1. Not allowed in the FIPS mode.");
Petr Lautrbach 802815
+		options.protocol &= ~SSH_PROTO_1;
Petr Lautrbach 802815
+	}
Petr Lautrbach 802815
 	if ((options.protocol & SSH_PROTO_1) && !sensitive_data.have_ssh1_key) {
Petr Lautrbach 802815
 		logit("Disabling protocol version 1. Could not load host key");
Petr Lautrbach 802815
 		options.protocol &= ~SSH_PROTO_1;
Jakub Jelen 132f8f
@@ -2058,6 +2077,10 @@ main(int ac, char **av)
Petr Lautrbach 802815
 	/* Reinitialize the log (because of the fork above). */
Petr Lautrbach 802815
 	log_init(__progname, options.log_level, options.log_facility, log_stderr);
Petr Lautrbach 802815
 
Petr Lautrbach 802815
+	if (FIPS_mode()) {
Petr Lautrbach 802815
+		logit("FIPS mode initialized");
Petr Lautrbach 802815
+	}
Petr Lautrbach 802815
+
Petr Lautrbach 802815
 	/* Chdir to the root directory so that the current disk can be
Petr Lautrbach 802815
 	   unmounted if desired. */
Petr Lautrbach 802815
 	if (chdir("/") == -1)
Jakub Jelen 132f8f
@@ -2642,6 +2665,9 @@ do_ssh2_kex(void)
Petr Lautrbach 802815
 	if (options.ciphers != NULL) {
Petr Lautrbach 802815
 		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Petr Lautrbach 802815
 		myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
Petr Lautrbach 802815
+	} else if (FIPS_mode()) {
Petr Lautrbach 802815
+		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Petr Lautrbach 802815
+		myproposal[PROPOSAL_ENC_ALGS_STOC] = KEX_FIPS_ENCRYPT;
Petr Lautrbach 802815
 	}
Petr Lautrbach 802815
 	myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Petr Lautrbach 802815
 	    compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
Jakub Jelen 132f8f
@@ -2651,6 +2677,9 @@ do_ssh2_kex(void)
Petr Lautrbach 802815
 	if (options.macs != NULL) {
Petr Lautrbach 802815
 		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
Petr Lautrbach 802815
 		myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
Petr Lautrbach 802815
+	} else if (FIPS_mode()) {
Petr Lautrbach 802815
+		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
Petr Lautrbach 802815
+		myproposal[PROPOSAL_MAC_ALGS_STOC] = KEX_FIPS_MAC;
Petr Lautrbach 802815
 	}
Petr Lautrbach 802815
 	if (options.compression == COMP_NONE) {
Petr Lautrbach 802815
 		myproposal[PROPOSAL_COMP_ALGS_CTOS] =
Jakub Jelen 132f8f
@@ -2661,6 +2690,8 @@ do_ssh2_kex(void)
Petr Lautrbach 802815
 	}
Petr Lautrbach 802815
 	if (options.kex_algorithms != NULL)
Petr Lautrbach 802815
 		myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
Petr Lautrbach 802815
+	else if (FIPS_mode())
Petr Lautrbach 802815
+		myproposal[PROPOSAL_KEX_ALGS] = KEX_DEFAULT_KEX_FIPS;
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 	myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(
Petr Lautrbach 802815
 	    myproposal[PROPOSAL_KEX_ALGS]);
Jakub Jelen 132f8f
@@ -2687,10 +2718,14 @@ do_ssh2_kex(void)
Petr Lautrbach 802815
 	if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
Petr Lautrbach 802815
 		orig = NULL;
Petr Lautrbach 802815
 
Petr Lautrbach 802815
-	if (options.gss_keyex)
Petr Lautrbach 802815
-		gss = ssh_gssapi_server_mechanisms();
Petr Lautrbach 802815
-	else
Petr Lautrbach 802815
-		gss = NULL;
Petr Lautrbach 802815
+	if (options.gss_keyex) {
Petr Lautrbach 802815
+		if (FIPS_mode()) {
Petr Lautrbach 802815
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
Petr Lautrbach 802815
+			options.gss_keyex = 0;
Petr Lautrbach 802815
+		} else {
Petr Lautrbach 802815
+			gss = ssh_gssapi_server_mechanisms();
Petr Lautrbach 802815
+		}
Petr Lautrbach 802815
+	}
Petr Lautrbach 802815
 
Petr Lautrbach 802815
 	if (gss && orig)
Petr Lautrbach 802815
 		xasprintf(&newstr, "%s,%s", gss, orig);
Jakub Jelen 132f8f
diff -up openssh-6.8p1/sshkey.c.fips openssh-6.8p1/sshkey.c
Jakub Jelen 132f8f
--- openssh-6.8p1/sshkey.c.fips	2015-03-19 13:14:22.227212163 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/sshkey.c	2015-03-19 13:14:22.233212151 +0100
Jakub Jelen 132f8f
@@ -35,6 +35,7 @@
Petr Lautrbach 190035
 #include <openssl/evp.h>
Petr Lautrbach 190035
 #include <openssl/err.h>
Petr Lautrbach 190035
 #include <openssl/pem.h>
Petr Lautrbach 190035
+#include <openssl/fips.h>
Jakub Jelen 132f8f
 #endif
Petr Lautrbach 190035
 
Petr Lautrbach 190035
 #include "crypto_api.h"
Jakub Jelen 132f8f
@@ -1562,6 +1563,8 @@ rsa_generate_private_key(u_int bits, RSA
Petr Lautrbach 190035
 	}
Petr Lautrbach 190035
 	if (!BN_set_word(f4, RSA_F4) ||
Petr Lautrbach 190035
 	    !RSA_generate_key_ex(private, bits, f4, NULL)) {
Petr Lautrbach 190035
+			if (FIPS_mode())
Petr Lautrbach 190035
+				logit("%s: the key length might be unsupported by FIPS mode approved key generation method", __func__);
Petr Lautrbach 190035
 		ret = SSH_ERR_LIBCRYPTO_ERROR;
Petr Lautrbach 190035
 		goto out;
Petr Lautrbach 190035
 	}
Jakub Jelen 132f8f
diff -up openssh-6.8p1/servconf.c.fips openssh-6.8p1/servconf.c
Jakub Jelen 132f8f
--- openssh-6.8p1/servconf.c.fips	2015-03-19 13:14:22.210212196 +0100
Jakub Jelen 132f8f
+++ openssh-6.8p1/servconf.c	2015-03-19 13:14:22.233212151 +0100
Jakub Jelen 132f8f
@@ -2226,8 +2226,10 @@ dump_config(ServerOptions *o)
Jakub Jelen b552eb
 	/* string arguments */
Jakub Jelen b552eb
 	dump_cfg_string(sPidFile, o->pid_file);
Jakub Jelen b552eb
 	dump_cfg_string(sXAuthLocation, o->xauth_location);
Jakub Jelen b552eb
-	dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : KEX_SERVER_ENCRYPT);
Jakub Jelen b552eb
-	dump_cfg_string(sMacs, o->macs ? o->macs : KEX_SERVER_MAC);
Jakub Jelen b552eb
+	dump_cfg_string(sCiphers, o->ciphers ? o->ciphers : FIPS_mode()
Jakub Jelen b552eb
+		? KEX_FIPS_ENCRYPT : KEX_SERVER_ENCRYPT);
Jakub Jelen b552eb
+	dump_cfg_string(sMacs, o->macs ? o->macs : FIPS_mode()
Jakub Jelen b552eb
+		? KEX_FIPS_MAC : KEX_SERVER_MAC);
Jakub Jelen 0a076e
 	dump_cfg_string(sBanner, o->banner != NULL ? o->banner : "none");
Jakub Jelen b552eb
 	dump_cfg_string(sForceCommand, o->adm_forced_command);
Jakub Jelen b552eb
 	dump_cfg_string(sChrootDirectory, o->chroot_directory);
Jakub Jelen 132f8f
@@ -2240,8 +2242,8 @@ dump_config(ServerOptions *o)
Jakub Jelen 132f8f
 	dump_cfg_string(sAuthorizedKeysCommand, o->authorized_keys_command);
Jakub Jelen b552eb
 	dump_cfg_string(sAuthorizedKeysCommandUser, o->authorized_keys_command_user);
Jakub Jelen b552eb
 	dump_cfg_string(sHostKeyAgent, o->host_key_agent);
Jakub Jelen 132f8f
-	dump_cfg_string(sKexAlgorithms,
Jakub Jelen 132f8f
-	    o->kex_algorithms ? o->kex_algorithms : KEX_SERVER_KEX);
Jakub Jelen 132f8f
+ 	dump_cfg_string(sKexAlgorithms, o->kex_algorithms ? o->kex_algorithms :
Jakub Jelen b552eb
+		FIPS_mode() ? KEX_DEFAULT_KEX_FIPS : KEX_SERVER_KEX);
Jakub Jelen 132f8f
 	dump_cfg_string(sHostbasedAcceptedKeyTypes, o->hostbased_key_types ?
Jakub Jelen 132f8f
 	    o->hostbased_key_types : KEX_DEFAULT_PK_ALG);
Jakub Jelen 132f8f
 	dump_cfg_string(sPubkeyAcceptedKeyTypes, o->pubkey_key_types ?