kentpeacock / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
Petr Šabata 81d24c
diff -up openssh-8.0p1/cipher-ctr.c.fips openssh-8.0p1/cipher-ctr.c
Petr Šabata 81d24c
--- openssh-8.0p1/cipher-ctr.c.fips	2019-07-23 14:55:45.326525641 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/cipher-ctr.c	2019-07-23 14:55:45.401526401 +0200
Petr Šabata 81d24c
@@ -179,7 +179,8 @@ evp_aes_128_ctr(void)
Petr Šabata 81d24c
 	aes_ctr.do_cipher = ssh_aes_ctr;
Petr Šabata 81d24c
 #ifndef SSH_OLD_EVP
Petr Šabata 81d24c
 	aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
Petr Šabata 81d24c
-	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
Petr Šabata 81d24c
+	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV |
Petr Šabata 81d24c
+	    EVP_CIPH_FLAG_FIPS;
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 	return (&aes_ctr);
Petr Šabata 81d24c
 }
Petr Šabata 81d24c
diff -up openssh-8.0p1/dh.c.fips openssh-8.0p1/dh.c
Petr Šabata 81d24c
--- openssh-8.0p1/dh.c.fips	2019-04-18 00:52:57.000000000 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/dh.c	2019-07-23 14:55:45.401526401 +0200
Petr Šabata 81d24c
@@ -152,6 +152,12 @@ choose_dh(int min, int wantbits, int max
Petr Šabata 81d24c
 	int best, bestcount, which, linenum;
Petr Šabata 81d24c
 	struct dhgroup dhg;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+	if (FIPS_mode()) {
Petr Šabata 81d24c
+		logit("Using arbitrary primes is not allowed in FIPS mode."
Petr Šabata 81d24c
+		    " Falling back to known groups.");
Petr Šabata 81d24c
+		return (dh_new_group_fallback(max));
Petr Šabata 81d24c
+	}
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 	if ((f = fopen(_PATH_DH_MODULI, "r")) == NULL) {
Petr Šabata 81d24c
 		logit("WARNING: could not open %s (%s), using fixed modulus",
Petr Šabata 81d24c
 		    _PATH_DH_MODULI, strerror(errno));
Petr Šabata 81d24c
@@ -489,4 +495,38 @@ dh_estimate(int bits)
Petr Šabata 81d24c
 	return 8192;
Petr Šabata 81d24c
 }
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+/*
Petr Šabata 81d24c
+ * Compares the received DH parameters with known-good groups,
Petr Šabata 81d24c
+ * which might be either from group14, group16 or group18.
Petr Šabata 81d24c
+ */
Petr Šabata 81d24c
+int
Petr Šabata 81d24c
+dh_is_known_group(const DH *dh)
Petr Šabata 81d24c
+{
Petr Šabata 81d24c
+	const BIGNUM *p, *g;
Petr Šabata 81d24c
+	const BIGNUM *known_p, *known_g;
Petr Šabata 81d24c
+	DH *known = NULL;
Petr Šabata 81d24c
+	int bits = 0, rv = 0;
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+	DH_get0_pqg(dh, &p, NULL, &g);
Petr Šabata 81d24c
+	bits = BN_num_bits(p);
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+	if (bits <= 3072) {
Petr Šabata 81d24c
+		known = dh_new_group14();
Petr Šabata 81d24c
+	} else if (bits <= 6144) {
Petr Šabata 81d24c
+		known = dh_new_group16();
Petr Šabata 81d24c
+	} else {
Petr Šabata 81d24c
+		known = dh_new_group18();
Petr Šabata 81d24c
+	}
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+	DH_get0_pqg(known, &known_p, NULL, &known_g);
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+	if (BN_cmp(g, known_g) == 0 &&
Petr Šabata 81d24c
+	    BN_cmp(p, known_p) == 0) {
Petr Šabata 81d24c
+		rv = 1;
Petr Šabata 81d24c
+	}
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+	DH_free(known);
Petr Šabata 81d24c
+	return rv;
Petr Šabata 81d24c
+}
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 #endif /* WITH_OPENSSL */
Petr Šabata 81d24c
diff -up openssh-8.0p1/dh.h.fips openssh-8.0p1/dh.h
Petr Šabata 81d24c
--- openssh-8.0p1/dh.h.fips	2019-04-18 00:52:57.000000000 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/dh.h	2019-07-23 14:55:45.401526401 +0200
Petr Šabata 81d24c
@@ -43,6 +43,7 @@ DH	*dh_new_group_fallback(int);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 int	 dh_gen_key(DH *, int);
Petr Šabata 81d24c
 int	 dh_pub_is_valid(const DH *, const BIGNUM *);
Petr Šabata 81d24c
+int	 dh_is_known_group(const DH *);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 u_int	 dh_estimate(int);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
diff -up openssh-8.0p1/kex.c.fips openssh-8.0p1/kex.c
Petr Šabata 81d24c
--- openssh-8.0p1/kex.c.fips	2019-07-23 14:55:45.395526340 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/kex.c	2019-07-23 14:55:45.402526411 +0200
Petr Šabata 81d24c
@@ -199,7 +199,10 @@ kex_names_valid(const char *names)
Petr Šabata 81d24c
 	for ((p = strsep(&cp, ",")); p && *p != '\0';
Petr Šabata 81d24c
 	    (p = strsep(&cp, ","))) {
Petr Šabata 81d24c
 		if (kex_alg_by_name(p) == NULL) {
Petr Šabata 81d24c
-			error("Unsupported KEX algorithm \"%.100s\"", p);
Petr Šabata 81d24c
+			if (FIPS_mode())
Petr Šabata 81d24c
+				error("\"%.100s\" is not allowed in FIPS mode", p);
Petr Šabata 81d24c
+			else
Petr Šabata 81d24c
+				error("Unsupported KEX algorithm \"%.100s\"", p);
Petr Šabata 81d24c
 			free(s);
Petr Šabata 81d24c
 			return 0;
Petr Šabata 81d24c
 		}
Petr Šabata 81d24c
diff -up openssh-8.0p1/kexgexc.c.fips openssh-8.0p1/kexgexc.c
Petr Šabata 81d24c
--- openssh-8.0p1/kexgexc.c.fips	2019-04-18 00:52:57.000000000 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/kexgexc.c	2019-07-23 14:55:45.402526411 +0200
Petr Šabata 81d24c
@@ -28,6 +28,7 @@
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 #ifdef WITH_OPENSSL
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+#include <openssl/crypto.h>
Petr Šabata 81d24c
 #include <sys/types.h>
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 #include <openssl/dh.h>
Petr Šabata 81d24c
@@ -113,6 +114,10 @@ input_kex_dh_gex_group(int type, u_int32
Petr Šabata 81d24c
 		r = SSH_ERR_ALLOC_FAIL;
Petr Šabata 81d24c
 		goto out;
Petr Šabata 81d24c
 	}
Petr Šabata 81d24c
+	if (FIPS_mode() && dh_is_known_group(kex->dh) == 0) {
Petr Šabata 81d24c
+		r = SSH_ERR_INVALID_ARGUMENT;
Petr Šabata 81d24c
+		goto out;
Petr Šabata 81d24c
+	}
Petr Šabata 81d24c
 	p = g = NULL; /* belong to kex->dh now */
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	/* generate and send 'e', client DH public key */
Petr Šabata 81d24c
diff -up openssh-8.0p1/myproposal.h.fips openssh-8.0p1/myproposal.h
Petr Šabata 81d24c
--- openssh-8.0p1/myproposal.h.fips	2019-04-18 00:52:57.000000000 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/myproposal.h	2019-07-23 14:55:45.402526411 +0200
Petr Šabata 81d24c
@@ -111,6 +111,20 @@
Petr Šabata 81d24c
 	"rsa-sha2-256," \
Petr Šabata 81d24c
 	"ssh-rsa"
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+#define	KEX_FIPS_PK_ALG	\
Petr Šabata 81d24c
+	"ecdsa-sha2-nistp256-cert-v01@openssh.com," \
Petr Šabata 81d24c
+	"ecdsa-sha2-nistp384-cert-v01@openssh.com," \
Petr Šabata 81d24c
+	"ecdsa-sha2-nistp521-cert-v01@openssh.com," \
Petr Šabata 81d24c
+	"rsa-sha2-512-cert-v01@openssh.com," \
Petr Šabata 81d24c
+	"rsa-sha2-256-cert-v01@openssh.com," \
Petr Šabata 81d24c
+	"ssh-rsa-cert-v01@openssh.com," \
Petr Šabata 81d24c
+	"ecdsa-sha2-nistp256," \
Petr Šabata 81d24c
+	"ecdsa-sha2-nistp384," \
Petr Šabata 81d24c
+	"ecdsa-sha2-nistp521," \
Petr Šabata 81d24c
+	"rsa-sha2-512," \
Petr Šabata 81d24c
+	"rsa-sha2-256," \
Petr Šabata 81d24c
+	"ssh-rsa"
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 #define	KEX_SERVER_ENCRYPT \
Petr Šabata 81d24c
 	"chacha20-poly1305@openssh.com," \
Petr Šabata 81d24c
 	"aes128-ctr,aes192-ctr,aes256-ctr," \
Petr Šabata 81d24c
@@ -134,6 +142,27 @@
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 #define KEX_CLIENT_MAC KEX_SERVER_MAC
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+#define	KEX_FIPS_ENCRYPT \
Petr Šabata 81d24c
+	"aes128-ctr,aes192-ctr,aes256-ctr," \
Petr Šabata 81d24c
+	"aes128-cbc,3des-cbc," \
Petr Šabata 81d24c
+	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se," \
Petr Šabata 81d24c
+	"aes128-gcm@openssh.com,aes256-gcm@openssh.com"
Petr Šabata 81d24c
+#define KEX_DEFAULT_KEX_FIPS		\
Petr Šabata 81d24c
+	"ecdh-sha2-nistp256," \
Petr Šabata 81d24c
+	"ecdh-sha2-nistp384," \
Petr Šabata 81d24c
+	"ecdh-sha2-nistp521," \
Petr Šabata 81d24c
+	"diffie-hellman-group-exchange-sha256," \
Petr Šabata 81d24c
+	"diffie-hellman-group16-sha512," \
Petr Šabata 81d24c
+	"diffie-hellman-group18-sha512," \
Petr Šabata 81d24c
+	"diffie-hellman-group14-sha256"
Petr Šabata 81d24c
+#define KEX_FIPS_MAC \
Petr Šabata 81d24c
+	"hmac-sha1," \
Petr Šabata 81d24c
+	"hmac-sha2-256," \
Petr Šabata 81d24c
+	"hmac-sha2-512," \
Petr Šabata 81d24c
+	"hmac-sha1-etm@openssh.com," \
Petr Šabata 81d24c
+	"hmac-sha2-256-etm@openssh.com," \
Petr Šabata 81d24c
+	"hmac-sha2-512-etm@openssh.com"
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 /* Not a KEX value, but here so all the algorithm defaults are together */
Petr Šabata 81d24c
 #define	SSH_ALLOWED_CA_SIGALGS	\
Petr Šabata 81d24c
 	"ecdsa-sha2-nistp256," \
Petr Šabata 81d24c
diff -up openssh-8.0p1/readconf.c.fips openssh-8.0p1/readconf.c
Petr Šabata 81d24c
--- openssh-8.0p1/readconf.c.fips	2019-07-23 14:55:45.334525723 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/readconf.c	2019-07-23 14:55:45.402526411 +0200
Petr Šabata 81d24c
@@ -2179,11 +2179,16 @@ fill_default_options(Options * options)
Petr Šabata 81d24c
 	all_key = sshkey_alg_list(0, 0, 1, ',');
Petr Šabata 81d24c
 	all_sig = sshkey_alg_list(0, 1, 1, ',');
Petr Šabata 81d24c
 	/* remove unsupported algos from default lists */
Petr Šabata 81d24c
-	def_cipher = match_filter_allowlist(KEX_CLIENT_ENCRYPT, all_cipher);
Petr Šabata 81d24c
-	def_mac = match_filter_allowlist(KEX_CLIENT_MAC, all_mac);
Petr Šabata 81d24c
-	def_kex = match_filter_allowlist(KEX_CLIENT_KEX, all_kex);
Petr Šabata 81d24c
-	def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
Petr Šabata 81d24c
-	def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
Petr Šabata 81d24c
+	def_cipher = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_FIPS_ENCRYPT : KEX_CLIENT_ENCRYPT), all_cipher);
Petr Šabata 81d24c
+	def_mac = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_FIPS_MAC : KEX_CLIENT_MAC), all_mac);
Petr Šabata 81d24c
+	def_kex = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_DEFAULT_KEX_FIPS : KEX_CLIENT_KEX), all_kex);
Petr Šabata 81d24c
+	def_key = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG), all_key);
Petr Šabata 81d24c
+	def_sig = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_FIPS_PK_ALG : SSH_ALLOWED_CA_SIGALGS), all_sig);
Petr Šabata 81d24c
 #define ASSEMBLE(what, defaults, all) \
Petr Šabata 81d24c
 	do { \
Petr Šabata 81d24c
 		if ((r = kex_assemble_names(&options->what, \
Petr Šabata 81d24c
diff -up openssh-8.0p1/sandbox-seccomp-filter.c.fips openssh-8.0p1/sandbox-seccomp-filter.c
Petr Šabata 81d24c
--- openssh-8.0p1/sandbox-seccomp-filter.c.fips	2019-07-23 14:55:45.373526117 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/sandbox-seccomp-filter.c	2019-07-23 14:55:45.402526411 +0200
Petr Šabata 81d24c
@@ -137,6 +137,9 @@ static const struct sock_filter preauth_
Petr Šabata 81d24c
 #ifdef __NR_open
Petr Šabata 81d24c
 	SC_DENY(__NR_open, EACCES),
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
+#ifdef __NR_socket
Petr Šabata 81d24c
+	SC_DENY(__NR_socket, EACCES),
Petr Šabata 81d24c
+#endif
Petr Šabata 81d24c
 #ifdef __NR_openat
Petr Šabata 81d24c
 	SC_DENY(__NR_openat, EACCES),
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
diff -up openssh-8.0p1/servconf.c.fips openssh-8.0p1/servconf.c
Petr Šabata 81d24c
--- openssh-8.0p1/servconf.c.fips	2019-07-23 14:55:45.361525996 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/servconf.c	2019-07-23 14:55:45.403526421 +0200
Petr Šabata 81d24c
@@ -208,11 +208,16 @@ assemble_algorithms(ServerOptions *o)
Petr Šabata 81d24c
 	all_key = sshkey_alg_list(0, 0, 1, ',');
Petr Šabata 81d24c
 	all_sig = sshkey_alg_list(0, 1, 1, ',');
Petr Šabata 81d24c
 	/* remove unsupported algos from default lists */
Petr Šabata 81d24c
-	def_cipher = match_filter_allowlist(KEX_SERVER_ENCRYPT, all_cipher);
Petr Šabata 81d24c
-	def_mac = match_filter_allowlist(KEX_SERVER_MAC, all_mac);
Petr Šabata 81d24c
-	def_kex = match_filter_allowlist(KEX_SERVER_KEX, all_kex);
Petr Šabata 81d24c
-	def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
Petr Šabata 81d24c
-	def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
Petr Šabata 81d24c
+	def_cipher = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_FIPS_ENCRYPT : KEX_SERVER_ENCRYPT), all_cipher);
Petr Šabata 81d24c
+	def_mac = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_FIPS_MAC : KEX_SERVER_MAC), all_mac);
Petr Šabata 81d24c
+	def_kex = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_DEFAULT_KEX_FIPS : KEX_SERVER_KEX), all_kex);
Petr Šabata 81d24c
+	def_key = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG), all_key);
Petr Šabata 81d24c
+	def_sig = match_filter_allowlist((FIPS_mode() ?
Petr Šabata 81d24c
+	    KEX_FIPS_PK_ALG : SSH_ALLOWED_CA_SIGALGS), all_sig);
Petr Šabata 81d24c
 #define ASSEMBLE(what, defaults, all) \
Petr Šabata 81d24c
 	do { \
Petr Šabata 81d24c
 		if ((r = kex_assemble_names(&o->what, defaults, all)) != 0) \
Petr Šabata 81d24c
diff -up openssh-8.0p1/ssh.c.fips openssh-8.0p1/ssh.c
Petr Šabata 81d24c
--- openssh-8.0p1/ssh.c.fips	2019-07-23 14:55:45.378526168 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/ssh.c	2019-07-23 14:55:45.403526421 +0200
Petr Šabata 81d24c
@@ -76,6 +76,7 @@
Petr Šabata 81d24c
 #include <openssl/evp.h>
Petr Šabata 81d24c
 #include <openssl/err.h>
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
+#include <openssl/crypto.h>
Petr Šabata 81d24c
 #include "openbsd-compat/openssl-compat.h"
Petr Šabata 81d24c
 #include "openbsd-compat/sys-queue.h"
Petr Šabata 81d24c
 
Petr Šabata 81d24c
@@ -614,6 +626,10 @@ main(int ac, char **av)
Petr Šabata 81d24c
 		dump_client_config(&options, host);
Petr Šabata 81d24c
 		exit(0);
Petr Šabata 81d24c
 	}
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+	if (FIPS_mode()) {
Petr Šabata 81d24c
+		debug("FIPS mode initialized");
Petr Šabata 81d24c
+	}
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	/* Expand SecurityKeyProvider if it refers to an environment variable */
Petr Šabata 81d24c
 	if (options.sk_provider != NULL && *options.sk_provider == '$' &&
Petr Šabata 81d24c
diff -up openssh-8.0p1/sshconnect2.c.fips openssh-8.0p1/sshconnect2.c
Petr Šabata 81d24c
--- openssh-8.0p1/sshconnect2.c.fips	2019-07-23 14:55:45.336525743 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/sshconnect2.c	2019-07-23 14:55:45.403526421 +0200
Petr Šabata 81d24c
@@ -44,6 +44,8 @@
Petr Šabata 81d24c
 #include <vis.h>
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+#include <openssl/crypto.h>
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 #include "openbsd-compat/sys-queue.h"
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 #include "xmalloc.h"
Petr Šabata 81d24c
@@ -198,36 +203,41 @@ ssh_kex2(struct ssh *ssh, char *host, st
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 #if defined(GSSAPI) && defined(WITH_OPENSSL)
Petr Šabata 81d24c
 	if (options.gss_keyex) {
Petr Šabata 81d24c
-		/* Add the GSSAPI mechanisms currently supported on this
Petr Šabata 81d24c
-		 * client to the key exchange algorithm proposal */
Petr Šabata 81d24c
-		orig = myproposal[PROPOSAL_KEX_ALGS];
Petr Šabata 81d24c
-
Petr Šabata 81d24c
-		if (options.gss_server_identity) {
Petr Šabata 81d24c
-			gss_host = xstrdup(options.gss_server_identity);
Petr Šabata 81d24c
-		} else if (options.gss_trust_dns) {
Petr Šabata 81d24c
-			gss_host = remote_hostname(ssh);
Petr Šabata 81d24c
-			/* Fall back to specified host if we are using proxy command
Petr Šabata 81d24c
-			 * and can not use DNS on that socket */
Petr Šabata 81d24c
-			if (strcmp(gss_host, "UNKNOWN") == 0) {
Petr Šabata 81d24c
-				free(gss_host);
Petr Šabata 81d24c
-				gss_host = xstrdup(host);
Petr Šabata 81d24c
-			}
Petr Šabata 81d24c
-		} else {
Petr Šabata 81d24c
-			gss_host = xstrdup(host);
Petr Šabata 81d24c
-		}
Petr Šabata 81d24c
-
Petr Šabata 81d24c
-		gss = ssh_gssapi_client_mechanisms(gss_host,
Petr Šabata 81d24c
-		    options.gss_client_identity, options.gss_kex_algorithms);
Petr Šabata 81d24c
-		if (gss) {
Petr Šabata 81d24c
-			debug("Offering GSSAPI proposal: %s", gss);
Petr Šabata 81d24c
-			xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
Petr Šabata 81d24c
-			    "%s,%s", gss, orig);
Petr Šabata 81d24c
-
Petr Šabata 81d24c
-			/* If we've got GSSAPI algorithms, then we also support the
Petr Šabata 81d24c
-			 * 'null' hostkey, as a last resort */
Petr Šabata 81d24c
-			orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
Petr Šabata 81d24c
-			xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
Petr Šabata 81d24c
-			    "%s,null", orig);
Petr Šabata 81d24c
+		if (FIPS_mode()) {
Petr Šabata 81d24c
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
Petr Šabata 81d24c
+			options.gss_keyex = 0;
Petr Šabata 81d24c
+		} else {
Petr Šabata 81d24c
+			/* Add the GSSAPI mechanisms currently supported on this
Petr Šabata 81d24c
+			 * client to the key exchange algorithm proposal */
Petr Šabata 81d24c
+			orig = myproposal[PROPOSAL_KEX_ALGS];
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+			if (options.gss_server_identity) {
Petr Šabata 81d24c
+				gss_host = xstrdup(options.gss_server_identity);
Petr Šabata 81d24c
+			} else if (options.gss_trust_dns) {
Petr Šabata 81d24c
+				gss_host = remote_hostname(ssh);
Petr Šabata 81d24c
+				/* Fall back to specified host if we are using proxy command
Petr Šabata 81d24c
+				 * and can not use DNS on that socket */
Petr Šabata 81d24c
+				if (strcmp(gss_host, "UNKNOWN") == 0) {
Petr Šabata 81d24c
+					free(gss_host);
Petr Šabata 81d24c
+					gss_host = xstrdup(host);
Petr Šabata 81d24c
+				}
Petr Šabata 81d24c
+			} else {
Petr Šabata 81d24c
+				gss_host = xstrdup(host);
Petr Šabata 81d24c
+			}
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+			gss = ssh_gssapi_client_mechanisms(gss_host,
Petr Šabata 81d24c
+			    options.gss_client_identity, options.gss_kex_algorithms);
Petr Šabata 81d24c
+			if (gss) {
Petr Šabata 81d24c
+				debug("Offering GSSAPI proposal: %s", gss);
Petr Šabata 81d24c
+				xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
Petr Šabata 81d24c
+				    "%s,%s", gss, orig);
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+				/* If we've got GSSAPI algorithms, then we also support the
Petr Šabata 81d24c
+				 * 'null' hostkey, as a last resort */
Petr Šabata 81d24c
+				orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
Petr Šabata 81d24c
+				xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
Petr Šabata 81d24c
+				    "%s,null", orig);
Petr Šabata 81d24c
+			}
Petr Šabata 81d24c
 		}
Petr Šabata 81d24c
 	}
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
diff -up openssh-8.0p1/sshd.c.fips openssh-8.0p1/sshd.c
Petr Šabata 81d24c
--- openssh-8.0p1/sshd.c.fips	2019-07-23 14:55:45.398526371 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/sshd.c	2019-07-23 14:55:45.403526421 +0200
Petr Šabata 81d24c
@@ -66,6 +66,7 @@
Petr Šabata 81d24c
 #include <grp.h>
Petr Šabata 81d24c
 #include <pwd.h>
Petr Šabata 81d24c
 #include <signal.h>
Petr Šabata 81d24c
+#include <syslog.h>
Petr Šabata 81d24c
 #include <stdarg.h>
Petr Šabata 81d24c
 #include <stdio.h>
Petr Šabata 81d24c
 #include <stdlib.h>
Petr Šabata 81d24c
@@ -77,6 +78,7 @@
Petr Šabata 81d24c
 #include <openssl/dh.h>
Petr Šabata 81d24c
 #include <openssl/bn.h>
Petr Šabata 81d24c
 #include <openssl/rand.h>
Petr Šabata 81d24c
+#include <openssl/crypto.h>
Petr Šabata 81d24c
 #include "openbsd-compat/openssl-compat.h"
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 
Petr Šabata 81d24c
@@ -1529,6 +1532,7 @@ main(int ac, char **av)
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 	__progname = ssh_get_progname(av[0]);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+	OpenSSL_add_all_algorithms();
Petr Šabata 81d24c
 	/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
Petr Šabata 81d24c
 	saved_argc = ac;
Petr Šabata 81d24c
 	rexec_argc = ac;
Petr Šabata 81d24c
@@ -1992,6 +2007,10 @@ main(int ac, char **av)
Petr Šabata 81d24c
 	/* Reinitialize the log (because of the fork above). */
Petr Šabata 81d24c
 	log_init(__progname, options.log_level, options.log_facility, log_stderr);
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+	if (FIPS_mode()) {
Petr Šabata 81d24c
+		debug("FIPS mode initialized");
Petr Šabata 81d24c
+	}
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 	/* Chdir to the root directory so that the current disk can be
Petr Šabata 81d24c
 	   unmounted if desired. */
Petr Šabata 81d24c
 	if (chdir("/") == -1)
Petr Šabata 81d24c
@@ -2382,10 +2401,14 @@ do_ssh2_kex(struct ssh *ssh)
Petr Šabata 81d24c
 	if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
Petr Šabata 81d24c
 		orig = NULL;
Petr Šabata 81d24c
 
Petr Šabata 81d24c
-	if (options.gss_keyex)
Petr Šabata 81d24c
-		gss = ssh_gssapi_server_mechanisms();
Petr Šabata 81d24c
-	else
Petr Šabata 81d24c
-		gss = NULL;
Petr Šabata 81d24c
+	if (options.gss_keyex) {
Petr Šabata 81d24c
+		if (FIPS_mode()) {
Petr Šabata 81d24c
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
Petr Šabata 81d24c
+			options.gss_keyex = 0;
Petr Šabata 81d24c
+		} else {
Petr Šabata 81d24c
+			gss = ssh_gssapi_server_mechanisms();
Petr Šabata 81d24c
+		}
Petr Šabata 81d24c
+	}
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 	if (gss && orig)
Petr Šabata 81d24c
 		xasprintf(&newstr, "%s,%s", gss, orig);
Petr Šabata 81d24c
diff -up openssh-8.0p1/sshkey.c.fips openssh-8.0p1/sshkey.c
Petr Šabata 81d24c
--- openssh-8.0p1/sshkey.c.fips	2019-07-23 14:55:45.398526371 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/sshkey.c	2019-07-23 14:55:45.404526431 +0200
Petr Šabata 81d24c
@@ -34,6 +34,7 @@
Petr Šabata 81d24c
 #include <openssl/evp.h>
Petr Šabata 81d24c
 #include <openssl/err.h>
Petr Šabata 81d24c
 #include <openssl/pem.h>
Petr Šabata 81d24c
+#include <openssl/crypto.h>
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 #include "crypto_api.h"
Petr Šabata 81d24c
@@ -57,6 +58,7 @@
Petr Šabata 81d24c
 #define SSHKEY_INTERNAL
Petr Šabata 81d24c
 #include "sshkey.h"
Petr Šabata 81d24c
 #include "match.h"
Petr Šabata 81d24c
+#include "log.h"
Petr Šabata 81d24c
 #include "ssh-sk.h"
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 #ifdef WITH_XMSS
Petr Šabata 81d24c
@@ -1591,6 +1593,8 @@ rsa_generate_private_key(u_int bits, RSA
Petr Šabata 81d24c
 	}
Petr Šabata 81d24c
 	if (!BN_set_word(f4, RSA_F4) ||
Petr Šabata 81d24c
 	    !RSA_generate_key_ex(private, bits, f4, NULL)) {
Petr Šabata 81d24c
+			if (FIPS_mode())
Petr Šabata 81d24c
+				logit("%s: the key length might be unsupported by FIPS mode approved key generation method", __func__);
Petr Šabata 81d24c
 		ret = SSH_ERR_LIBCRYPTO_ERROR;
Petr Šabata 81d24c
 		goto out;
Petr Šabata 81d24c
 	}
Petr Šabata 81d24c
diff -up openssh-8.0p1/ssh-keygen.c.fips openssh-8.0p1/ssh-keygen.c
Petr Šabata 81d24c
--- openssh-8.0p1/ssh-keygen.c.fips	2019-07-23 14:55:45.391526300 +0200
Petr Šabata 81d24c
+++ openssh-8.0p1/ssh-keygen.c	2019-07-23 14:57:54.118830056 +0200
Petr Šabata 81d24c
@@ -199,6 +199,12 @@ type_bits_valid(int type, const char *na
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 	}
Petr Šabata 81d24c
 #ifdef WITH_OPENSSL
Petr Šabata 81d24c
+	if (FIPS_mode()) {
Petr Šabata 81d24c
+		if (type == KEY_DSA)
Petr Šabata 81d24c
+			fatal("DSA keys are not allowed in FIPS mode");
Petr Šabata 81d24c
+		if (type == KEY_ED25519)
Petr Šabata 81d24c
+			fatal("ED25519 keys are not allowed in FIPS mode");
Petr Šabata 81d24c
+	}
Petr Šabata 81d24c
 	switch (type) {
Petr Šabata 81d24c
 	case KEY_DSA:
Petr Šabata 81d24c
 		if (*bitsp != 1024)
Petr Šabata 81d24c
@@ -1029,9 +1035,17 @@ do_gen_all_hostkeys(struct passwd *pw)
Petr Šabata 81d24c
 			first = 1;
Petr Šabata 81d24c
 			printf("%s: generating new host keys: ", __progname);
Petr Šabata 81d24c
 		}
Petr Šabata 81d24c
+		type = sshkey_type_from_name(key_types[i].key_type);
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+		/* Skip the keys that are not supported in FIPS mode */
Petr Šabata 81d24c
+		if (FIPS_mode() && (type == KEY_DSA || type == KEY_ED25519)) {
Petr Šabata 81d24c
+			logit("Skipping %s key in FIPS mode",
Petr Šabata 81d24c
+			    key_types[i].key_type_display);
Petr Šabata 81d24c
+			goto next;
Petr Šabata 81d24c
+		}
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 		printf("%s ", key_types[i].key_type_display);
Petr Šabata 81d24c
 		fflush(stdout);
Petr Šabata 81d24c
-		type = sshkey_type_from_name(key_types[i].key_type);
Petr Šabata 81d24c
 		if ((fd = mkstemp(prv_tmp)) == -1) {
Petr Šabata 81d24c
 			error("Could not save your private key in %s: %s",
Petr Šabata 81d24c
			    prv_tmp, strerror(errno));