rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone

Blame SOURCES/openssh-6.4p1-FIPS-mode-SP800-131A.patch

770374
diff --git a/dh.h b/dh.h
770374
index 48f7b68..9ff39f4 100644
770374
--- a/dh.h
770374
+++ b/dh.h
770374
@@ -45,6 +45,7 @@ int	 dh_estimate(int);
770374
 
770374
 /* Min and max values from RFC4419. */
770374
 #define DH_GRP_MIN	1024
770374
+#define DH_GRP_MIN_FIPS	2048
770374
 #define DH_GRP_MAX	8192
770374
 
770374
 /*
770374
diff --git a/kex.c b/kex.c
770374
index a468805..3a0eb16 100644
770374
--- a/kex.c
770374
+++ b/kex.c
770374
@@ -34,6 +34,7 @@
770374
 #include <string.h>
770374
 
770374
 #include <openssl/crypto.h>
770374
+#include <openssl/fips.h>
770374
 
770374
 #include "xmalloc.h"
770374
 #include "ssh2.h"
770374
@@ -93,6 +94,20 @@ static const struct kexalg kexalgs[] = {
770374
 	{ NULL, -1, -1, NULL},
770374
 };
770374
 
770374
+static const struct kexalg kexalgs_fips[] = {
770374
+	{ KEX_DH14, KEX_DH_GRP14_SHA1, 0, EVP_sha1 },
770374
+	{ KEX_DHGEX_SHA1, KEX_DH_GEX_SHA1, 0, EVP_sha1 },
770374
+#ifdef HAVE_EVP_SHA256
770374
+	{ KEX_DHGEX_SHA256, KEX_DH_GEX_SHA256, 0, EVP_sha256 },
770374
+#endif
770374
+#ifdef OPENSSL_HAS_ECC
770374
+	{ KEX_ECDH_SHA2_NISTP256, KEX_ECDH_SHA2, NID_X9_62_prime256v1, EVP_sha256 },
770374
+	{ KEX_ECDH_SHA2_NISTP384, KEX_ECDH_SHA2, NID_secp384r1, EVP_sha384 },
770374
+	{ KEX_ECDH_SHA2_NISTP521, KEX_ECDH_SHA2, NID_secp521r1, EVP_sha512 },
770374
+#endif
770374
+	{ NULL, -1, -1, NULL},
770374
+};
770374
+
770374
 char *
770374
 kex_alg_list(void)
770374
 {
770374
@@ -116,7 +131,7 @@ kex_alg_by_name(const char *name)
770374
 {
770374
 	const struct kexalg *k;
770374
 
770374
-	for (k = kexalgs; k->name != NULL; k++) {
770374
+	for (k = (FIPS_mode() ? kexalgs_fips : kexalgs); k->name != NULL; k++) {
770374
 		if (strcmp(k->name, name) == 0)
770374
 			return k;
770374
 #ifdef GSSAPI
770374
@@ -141,7 +156,10 @@ kex_names_valid(const char *names)
770374
 	for ((p = strsep(&cp, ",")); p && *p != '\0';
770374
 	    (p = strsep(&cp, ","))) {
770374
 		if (kex_alg_by_name(p) == NULL) {
770374
-			error("Unsupported KEX algorithm \"%.100s\"", p);
770374
+			if (FIPS_mode())
770374
+				error("\"%.100s\" is not allowed in FIPS mode", p);
770374
+			else
770374
+				error("Unsupported KEX algorithm \"%.100s\"", p);
770374
 			free(s);
770374
 			return 0;
770374
 		}
770374
diff --git a/kexecdhc.c b/kexecdhc.c
770374
index 6193836..d435f1f 100644
770374
--- a/kexecdhc.c
770374
+++ b/kexecdhc.c
770374
@@ -154,6 +154,7 @@ kexecdh_client(Kex *kex)
770374
 
770374
 	kex_derive_keys(kex, hash, hashlen, shared_secret);
770374
 	BN_clear_free(shared_secret);
770374
+	memset(hash, 0, hashlen);
770374
 	kex_finish(kex);
770374
 }
770374
 #else /* OPENSSL_HAS_ECC */
770374
diff --git a/kexecdhs.c b/kexecdhs.c
770374
index 3a580aa..9a06905 100644
770374
--- a/kexecdhs.c
770374
+++ b/kexecdhs.c
770374
@@ -155,6 +155,7 @@ kexecdh_server(Kex *kex)
770374
 
770374
 	kex_derive_keys(kex, hash, hashlen, shared_secret);
770374
 	BN_clear_free(shared_secret);
770374
+	memset(hash, 0, hashlen);
770374
 	kex_finish(kex);
770374
 }
770374
 #else /* OPENSSL_HAS_ECC */
770374
diff --git a/kexgexc.c b/kexgexc.c
770374
index 5a3be20..a931b6e 100644
770374
--- a/kexgexc.c
770374
+++ b/kexgexc.c
770374
@@ -26,6 +26,8 @@
770374
 
770374
 #include "includes.h"
770374
 
770374
+#include <openssl/fips.h>
770374
+
770374
 #include <sys/types.h>
770374
 
770374
 #include <openssl/dh.h>
770374
@@ -64,13 +66,13 @@ kexgex_client(Kex *kex)
770374
 		/* Old GEX request */
770374
 		packet_start(SSH2_MSG_KEX_DH_GEX_REQUEST_OLD);
770374
 		packet_put_int(nbits);
770374
-		min = DH_GRP_MIN;
770374
+		min = FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN;
770374
 		max = DH_GRP_MAX;
770374
 
770374
 		debug("SSH2_MSG_KEX_DH_GEX_REQUEST_OLD(%u) sent", nbits);
770374
 	} else {
770374
 		/* New GEX request */
770374
-		min = DH_GRP_MIN;
770374
+		min = FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN;
770374
 		max = DH_GRP_MAX;
770374
 		packet_start(SSH2_MSG_KEX_DH_GEX_REQUEST);
770374
 		packet_put_int(min);
770374
diff --git a/kexgexs.c b/kexgexs.c
770374
index 4e473fc..2ed49bd 100644
770374
--- a/kexgexs.c
770374
+++ b/kexgexs.c
770374
@@ -76,16 +76,16 @@ kexgex_server(Kex *kex)
770374
 		omin = min = packet_get_int();
770374
 		onbits = nbits = packet_get_int();
770374
 		omax = max = packet_get_int();
770374
-		min = MAX(DH_GRP_MIN, min);
770374
+		min = MAX(FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN, min);
770374
 		max = MIN(DH_GRP_MAX, max);
770374
-		nbits = MAX(DH_GRP_MIN, nbits);
770374
+		nbits = MAX(FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN, nbits);
770374
 		nbits = MIN(DH_GRP_MAX, nbits);
770374
 		break;
770374
 	case SSH2_MSG_KEX_DH_GEX_REQUEST_OLD:
770374
 		debug("SSH2_MSG_KEX_DH_GEX_REQUEST_OLD received");
770374
 		onbits = nbits = packet_get_int();
770374
 		/* unused for old GEX */
770374
-		omin = min = DH_GRP_MIN;
770374
+		omin = min = FIPS_mode() ? DH_GRP_MIN_FIPS : DH_GRP_MIN;
770374
 		omax = max = DH_GRP_MAX;
770374
 		break;
770374
 	default:
770374
diff --git a/myproposal.h b/myproposal.h
770374
index ee69ea2..1b68c5b 100644
770374
--- a/myproposal.h
770374
+++ b/myproposal.h
770374
@@ -72,6 +72,12 @@
770374
 	"diffie-hellman-group14-sha1," \
770374
 	"diffie-hellman-group1-sha1"
770374
 
770374
+#define KEX_DEFAULT_KEX_FIPS		\
770374
+	KEX_ECDH_METHODS \
770374
+	KEX_SHA256_METHODS \
770374
+	"diffie-hellman-group-exchange-sha1," \
770374
+	"diffie-hellman-group14-sha1"
770374
+
770374
 #define	KEX_DEFAULT_PK_ALG	\
770374
 	HOSTKEY_ECDSA_CERT_METHODS \
770374
 	"ssh-rsa-cert-v01@openssh.com," \
770374
diff --git a/ssh-keygen.c b/ssh-keygen.c
770374
index cac6762..2569016 100644
770374
--- a/ssh-keygen.c
770374
+++ b/ssh-keygen.c
770374
@@ -183,8 +183,14 @@ type_bits_valid(int type, u_int32_t *bitsp)
770374
 		fprintf(stderr, "key bits exceeds maximum %d\n", maxbits);
770374
 		exit(1);
770374
 	}
770374
-	if (type == KEY_DSA && *bitsp != 1024)
770374
+	if (type == KEY_DSA && FIPS_mode())
770374
+		fatal("DSA keys are not allowed in FIPS mode");
770374
+	else if (type == KEY_DSA && *bitsp != 1024)
770374
 		fatal("DSA keys must be 1024 bits");
770374
+	else if (type == KEY_RSA && bits < DEFAULT_BITS && FIPS_mode()) {
770374
+		fprintf(stderr, "RSA keys must be at least %d bits in FIPS mode\n", DEFAULT_BITS);
770374
+		exit(1);
770374
+	}
770374
 	else if (type != KEY_ECDSA && *bitsp < 768)
770374
 		fatal("Key must at least be 768 bits");
770374
 	else if (type == KEY_ECDSA && key_ecdsa_bits_to_nid(*bitsp) == -1)
770374
diff --git a/sshconnect2.c b/sshconnect2.c
770374
index 7e48880..3179d82 100644
770374
--- a/sshconnect2.c
770374
+++ b/sshconnect2.c
770374
@@ -231,6 +231,8 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
770374
 	}
770374
 	if (options.kex_algorithms != NULL)
770374
 		myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
770374
+	else if (FIPS_mode())
770374
+		myproposal[PROPOSAL_KEX_ALGS] = KEX_DEFAULT_KEX_FIPS;
770374
 
770374
 #ifdef GSSAPI
770374
 	/* If we've got GSSAPI algorithms, then we also support the
770374
diff --git a/sshd.c b/sshd.c
770374
index 11adbf6..f5e98bc 100644
770374
--- a/sshd.c
770374
+++ b/sshd.c
770374
@@ -2605,6 +2605,8 @@ do_ssh2_kex(void)
770374
 	}
770374
 	if (options.kex_algorithms != NULL)
770374
 		myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
770374
+	else if (FIPS_mode())
770374
+		myproposal[PROPOSAL_KEX_ALGS] = KEX_DEFAULT_KEX_FIPS;
770374
 
770374
 	if (options.rekey_limit || options.rekey_interval)
770374
 		packet_set_rekey_limits((u_int32_t)options.rekey_limit,