From d19ba936f26d0bd05e15d43d808110115b1ecf01 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Jul 26 2019 07:27:52 +0000 Subject: Do not attempt to generate DSA and ED25519 keys in FIPS mode --- diff --git a/openssh-7.7p1-fips.patch b/openssh-7.7p1-fips.patch index f28b943..333a9a2 100644 --- a/openssh-7.7p1-fips.patch +++ b/openssh-7.7p1-fips.patch @@ -1,6 +1,6 @@ -diff -up openssh-7.9p1/cipher-ctr.c.fips openssh-7.9p1/cipher-ctr.c ---- openssh-7.9p1/cipher-ctr.c.fips 2019-03-11 17:06:37.519877082 +0100 -+++ openssh-7.9p1/cipher-ctr.c 2019-03-11 17:06:37.620878031 +0100 +diff -up openssh-8.0p1/cipher-ctr.c.fips openssh-8.0p1/cipher-ctr.c +--- openssh-8.0p1/cipher-ctr.c.fips 2019-07-23 14:55:45.326525641 +0200 ++++ openssh-8.0p1/cipher-ctr.c 2019-07-23 14:55:45.401526401 +0200 @@ -179,7 +179,8 @@ evp_aes_128_ctr(void) aes_ctr.do_cipher = ssh_aes_ctr; #ifndef SSH_OLD_EVP @@ -11,10 +11,10 @@ diff -up openssh-7.9p1/cipher-ctr.c.fips openssh-7.9p1/cipher-ctr.c #endif return (&aes_ctr); } -diff -up openssh-7.9p1/clientloop.c.fips openssh-7.9p1/clientloop.c ---- openssh-7.9p1/clientloop.c.fips 2019-03-11 17:06:37.523877120 +0100 -+++ openssh-7.9p1/clientloop.c 2019-03-11 17:06:37.620878031 +0100 -@@ -2014,7 +2014,8 @@ key_accepted_by_hostkeyalgs(const struct +diff -up openssh-8.0p1/clientloop.c.fips openssh-8.0p1/clientloop.c +--- openssh-8.0p1/clientloop.c.fips 2019-07-23 14:55:45.331525692 +0200 ++++ openssh-8.0p1/clientloop.c 2019-07-23 14:55:45.401526401 +0200 +@@ -2049,7 +2049,8 @@ key_accepted_by_hostkeyalgs(const struct { const char *ktype = sshkey_ssh_name(key); const char *hostkeyalgs = options.hostkeyalgorithms != NULL ? @@ -24,9 +24,9 @@ diff -up openssh-7.9p1/clientloop.c.fips openssh-7.9p1/clientloop.c if (key == NULL || key->type == KEY_UNSPEC) return 0; -diff -up openssh-7.9p1/dh.c.fips openssh-7.9p1/dh.c ---- openssh-7.9p1/dh.c.fips 2018-10-17 02:01:20.000000000 +0200 -+++ openssh-7.9p1/dh.c 2019-03-11 17:08:11.769763057 +0100 +diff -up openssh-8.0p1/dh.c.fips openssh-8.0p1/dh.c +--- openssh-8.0p1/dh.c.fips 2019-04-18 00:52:57.000000000 +0200 ++++ openssh-8.0p1/dh.c 2019-07-23 14:55:45.401526401 +0200 @@ -152,6 +152,12 @@ choose_dh(int min, int wantbits, int max int best, bestcount, which, linenum; struct dhgroup dhg; @@ -79,9 +79,9 @@ diff -up openssh-7.9p1/dh.c.fips openssh-7.9p1/dh.c +} + #endif /* WITH_OPENSSL */ -diff -up openssh-7.9p1/dh.h.fips openssh-7.9p1/dh.h ---- openssh-7.9p1/dh.h.fips 2018-10-17 02:01:20.000000000 +0200 -+++ openssh-7.9p1/dh.h 2019-03-11 17:08:18.718828381 +0100 +diff -up openssh-8.0p1/dh.h.fips openssh-8.0p1/dh.h +--- openssh-8.0p1/dh.h.fips 2019-04-18 00:52:57.000000000 +0200 ++++ openssh-8.0p1/dh.h 2019-07-23 14:55:45.401526401 +0200 @@ -43,6 +43,7 @@ DH *dh_new_group_fallback(int); int dh_gen_key(DH *, int); @@ -90,10 +90,10 @@ diff -up openssh-7.9p1/dh.h.fips openssh-7.9p1/dh.h u_int dh_estimate(int); -diff -up openssh-7.9p1/kex.c.fips openssh-7.9p1/kex.c ---- openssh-7.9p1/kex.c.fips 2019-03-11 17:06:37.614877975 +0100 -+++ openssh-7.9p1/kex.c 2019-03-11 17:06:37.621878041 +0100 -@@ -175,7 +196,10 @@ kex_names_valid(const char *names) +diff -up openssh-8.0p1/kex.c.fips openssh-8.0p1/kex.c +--- openssh-8.0p1/kex.c.fips 2019-07-23 14:55:45.395526340 +0200 ++++ openssh-8.0p1/kex.c 2019-07-23 14:55:45.402526411 +0200 +@@ -199,7 +199,10 @@ kex_names_valid(const char *names) for ((p = strsep(&cp, ",")); p && *p != '\0'; (p = strsep(&cp, ","))) { if (kex_alg_by_name(p) == NULL) { @@ -105,9 +105,9 @@ diff -up openssh-7.9p1/kex.c.fips openssh-7.9p1/kex.c free(s); return 0; } -diff -up openssh-7.9p1/kexgexc.c.fips openssh-7.9p1/kexgexc.c ---- openssh-7.9p1/kexgexc.c.fips 2018-10-17 02:01:20.000000000 +0200 -+++ openssh-7.9p1/kexgexc.c 2019-03-11 17:06:37.621878041 +0100 +diff -up openssh-8.0p1/kexgexc.c.fips openssh-8.0p1/kexgexc.c +--- openssh-8.0p1/kexgexc.c.fips 2019-04-18 00:52:57.000000000 +0200 ++++ openssh-8.0p1/kexgexc.c 2019-07-23 14:55:45.402526411 +0200 @@ -28,6 +28,7 @@ #ifdef WITH_OPENSSL @@ -116,7 +116,7 @@ diff -up openssh-7.9p1/kexgexc.c.fips openssh-7.9p1/kexgexc.c #include #include -@@ -118,6 +119,10 @@ input_kex_dh_gex_group(int type, u_int32 +@@ -113,6 +114,10 @@ input_kex_dh_gex_group(int type, u_int32 r = SSH_ERR_ALLOC_FAIL; goto out; } @@ -127,10 +127,10 @@ diff -up openssh-7.9p1/kexgexc.c.fips openssh-7.9p1/kexgexc.c p = g = NULL; /* belong to kex->dh now */ /* generate and send 'e', client DH public key */ -diff -up openssh-7.9p1/Makefile.in.fips openssh-7.9p1/Makefile.in ---- openssh-7.9p1/Makefile.in.fips 2019-03-11 17:06:37.615877984 +0100 -+++ openssh-7.9p1/Makefile.in 2019-03-11 17:06:37.621878041 +0100 -@@ -179,25 +179,25 @@ libssh.a: $(LIBSSH_OBJS) +diff -up openssh-8.0p1/Makefile.in.fips openssh-8.0p1/Makefile.in +--- openssh-8.0p1/Makefile.in.fips 2019-07-23 14:55:45.396526350 +0200 ++++ openssh-8.0p1/Makefile.in 2019-07-23 14:55:45.402526411 +0200 +@@ -180,25 +180,25 @@ libssh.a: $(LIBSSH_OBJS) $(RANLIB) $@ ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHOBJS) @@ -162,7 +162,7 @@ diff -up openssh-7.9p1/Makefile.in.fips openssh-7.9p1/Makefile.in ssh-pkcs11-helper$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-pkcs11-helper.o ssh-pkcs11.o $(LD) -o $@ ssh-pkcs11-helper.o ssh-pkcs11.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lopenbsd-compat $(LIBS) -@@ -215,7 +215,7 @@ ssh-cavs$(EXEEXT): $(LIBCOMPAT) libssh.a +@@ -216,7 +216,7 @@ ssh-cavs$(EXEEXT): $(LIBCOMPAT) libssh.a $(LD) -o $@ ssh-cavs.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o @@ -171,10 +171,10 @@ diff -up openssh-7.9p1/Makefile.in.fips openssh-7.9p1/Makefile.in sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o sftp-server-main.o $(LD) -o $@ sftp-server.o sftp-common.o sftp-server-main.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) -diff -up openssh-7.9p1/myproposal.h.fips openssh-7.9p1/myproposal.h ---- openssh-7.9p1/myproposal.h.fips 2018-10-17 02:01:20.000000000 +0200 -+++ openssh-7.9p1/myproposal.h 2019-03-11 17:06:37.621878041 +0100 -@@ -116,6 +116,14 @@ +diff -up openssh-8.0p1/myproposal.h.fips openssh-8.0p1/myproposal.h +--- openssh-8.0p1/myproposal.h.fips 2019-04-18 00:52:57.000000000 +0200 ++++ openssh-8.0p1/myproposal.h 2019-07-23 14:55:45.402526411 +0200 +@@ -111,6 +111,14 @@ "rsa-sha2-256," \ "ssh-rsa" @@ -189,7 +189,7 @@ diff -up openssh-7.9p1/myproposal.h.fips openssh-7.9p1/myproposal.h /* the actual algorithms */ #define KEX_SERVER_ENCRYPT \ -@@ -139,6 +147,38 @@ +@@ -134,6 +142,38 @@ #define KEX_CLIENT_MAC KEX_SERVER_MAC @@ -228,10 +228,10 @@ diff -up openssh-7.9p1/myproposal.h.fips openssh-7.9p1/myproposal.h /* Not a KEX value, but here so all the algorithm defaults are together */ #define SSH_ALLOWED_CA_SIGALGS \ "ecdsa-sha2-nistp256," \ -diff -up openssh-7.9p1/readconf.c.fips openssh-7.9p1/readconf.c ---- openssh-7.9p1/readconf.c.fips 2019-03-11 17:06:37.601877853 +0100 -+++ openssh-7.9p1/readconf.c 2019-03-11 17:06:37.622878050 +0100 -@@ -2178,18 +2178,19 @@ fill_default_options(Options * options) +diff -up openssh-8.0p1/readconf.c.fips openssh-8.0p1/readconf.c +--- openssh-8.0p1/readconf.c.fips 2019-07-23 14:55:45.334525723 +0200 ++++ openssh-8.0p1/readconf.c 2019-07-23 14:55:45.402526411 +0200 +@@ -2179,18 +2179,19 @@ fill_default_options(Options * options) all_kex = kex_alg_list(','); all_key = sshkey_alg_list(0, 0, 1, ','); all_sig = sshkey_alg_list(0, 1, 1, ','); @@ -259,9 +259,9 @@ diff -up openssh-7.9p1/readconf.c.fips openssh-7.9p1/readconf.c #undef ASSEMBLE free(all_cipher); free(all_mac); -diff -up openssh-7.9p1/sandbox-seccomp-filter.c.fips openssh-7.9p1/sandbox-seccomp-filter.c ---- openssh-7.9p1/sandbox-seccomp-filter.c.fips 2019-03-11 17:06:37.586877712 +0100 -+++ openssh-7.9p1/sandbox-seccomp-filter.c 2019-03-11 17:06:37.622878050 +0100 +diff -up openssh-8.0p1/sandbox-seccomp-filter.c.fips openssh-8.0p1/sandbox-seccomp-filter.c +--- openssh-8.0p1/sandbox-seccomp-filter.c.fips 2019-07-23 14:55:45.373526117 +0200 ++++ openssh-8.0p1/sandbox-seccomp-filter.c 2019-07-23 14:55:45.402526411 +0200 @@ -137,6 +137,9 @@ static const struct sock_filter preauth_ #ifdef __NR_open SC_DENY(__NR_open, EACCES), @@ -272,10 +272,10 @@ diff -up openssh-7.9p1/sandbox-seccomp-filter.c.fips openssh-7.9p1/sandbox-secco #ifdef __NR_openat SC_DENY(__NR_openat, EACCES), #endif -diff -up openssh-7.9p1/servconf.c.fips openssh-7.9p1/servconf.c ---- openssh-7.9p1/servconf.c.fips 2019-03-11 17:06:37.568877543 +0100 -+++ openssh-7.9p1/servconf.c 2019-03-11 17:06:37.622878050 +0100 -@@ -209,18 +209,19 @@ assemble_algorithms(ServerOptions *o) +diff -up openssh-8.0p1/servconf.c.fips openssh-8.0p1/servconf.c +--- openssh-8.0p1/servconf.c.fips 2019-07-23 14:55:45.361525996 +0200 ++++ openssh-8.0p1/servconf.c 2019-07-23 14:55:45.403526421 +0200 +@@ -208,18 +208,19 @@ assemble_algorithms(ServerOptions *o) all_kex = kex_alg_list(','); all_key = sshkey_alg_list(0, 0, 1, ','); all_sig = sshkey_alg_list(0, 1, 1, ','); @@ -304,9 +304,9 @@ diff -up openssh-7.9p1/servconf.c.fips openssh-7.9p1/servconf.c #undef ASSEMBLE free(all_cipher); free(all_mac); -diff -up openssh-7.9p1/ssh.c.fips openssh-7.9p1/ssh.c ---- openssh-7.9p1/ssh.c.fips 2019-03-11 17:06:37.602877862 +0100 -+++ openssh-7.9p1/ssh.c 2019-03-11 17:06:37.623878060 +0100 +diff -up openssh-8.0p1/ssh.c.fips openssh-8.0p1/ssh.c +--- openssh-8.0p1/ssh.c.fips 2019-07-23 14:55:45.378526168 +0200 ++++ openssh-8.0p1/ssh.c 2019-07-23 14:55:45.403526421 +0200 @@ -76,6 +76,8 @@ #include #include @@ -333,7 +333,7 @@ diff -up openssh-7.9p1/ssh.c.fips openssh-7.9p1/ssh.c #ifndef HAVE_SETPROCTITLE /* Prepare for later setproctitle emulation */ -@@ -1283,6 +1294,10 @@ main(int ac, char **av) +@@ -614,6 +626,10 @@ main(int ac, char **av) seed_rng(); @@ -344,9 +344,9 @@ diff -up openssh-7.9p1/ssh.c.fips openssh-7.9p1/ssh.c /* * Discard other fds that are hanging around. These can cause problem * with backgrounded ssh processes started by ControlPersist. -diff -up openssh-7.9p1/sshconnect2.c.fips openssh-7.9p1/sshconnect2.c ---- openssh-7.9p1/sshconnect2.c.fips 2019-03-11 17:06:37.580877655 +0100 -+++ openssh-7.9p1/sshconnect2.c 2019-03-11 17:06:37.623878060 +0100 +diff -up openssh-8.0p1/sshconnect2.c.fips openssh-8.0p1/sshconnect2.c +--- openssh-8.0p1/sshconnect2.c.fips 2019-07-23 14:55:45.336525743 +0200 ++++ openssh-8.0p1/sshconnect2.c 2019-07-23 14:55:45.403526421 +0200 @@ -44,6 +44,8 @@ #include #endif @@ -356,7 +356,7 @@ diff -up openssh-7.9p1/sshconnect2.c.fips openssh-7.9p1/sshconnect2.c #include "openbsd-compat/sys-queue.h" #include "xmalloc.h" -@@ -117,7 +117,8 @@ order_hostkeyalgs(char *host, struct soc +@@ -115,7 +117,8 @@ order_hostkeyalgs(char *host, struct soc for (i = 0; i < options.num_system_hostfiles; i++) load_hostkeys(hostkeys, hostname, options.system_hostfiles[i]); @@ -366,7 +366,7 @@ diff -up openssh-7.9p1/sshconnect2.c.fips openssh-7.9p1/sshconnect2.c maxlen = strlen(avail) + 1; first = xmalloc(maxlen); last = xmalloc(maxlen); -@@ -185,14 +185,16 @@ ssh_kex2(char *host, struct sockaddr *ho +@@ -182,14 +185,16 @@ ssh_kex2(struct ssh *ssh, char *host, st if (options.hostkeyalgorithms != NULL) { all_key = sshkey_alg_list(0, 0, 1, ','); if (kex_assemble_names(&options.hostkeyalgorithms, @@ -385,7 +385,7 @@ diff -up openssh-7.9p1/sshconnect2.c.fips openssh-7.9p1/sshconnect2.c /* Prefer algorithms that we already have keys for */ myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal( -@@ -201,29 +201,34 @@ ssh_kex2(char *host, struct sockaddr *ho +@@ -198,29 +203,34 @@ ssh_kex2(struct ssh *ssh, char *host, st #if defined(GSSAPI) && defined(WITH_OPENSSL) if (options.gss_keyex) { @@ -443,9 +443,9 @@ diff -up openssh-7.9p1/sshconnect2.c.fips openssh-7.9p1/sshconnect2.c } } #endif -diff -up openssh-7.9p1/sshd.c.fips openssh-7.9p1/sshd.c ---- openssh-7.9p1/sshd.c.fips 2019-03-11 17:06:37.617878003 +0100 -+++ openssh-7.9p1/sshd.c 2019-03-11 17:06:37.624878069 +0100 +diff -up openssh-8.0p1/sshd.c.fips openssh-8.0p1/sshd.c +--- openssh-8.0p1/sshd.c.fips 2019-07-23 14:55:45.398526371 +0200 ++++ openssh-8.0p1/sshd.c 2019-07-23 14:55:45.403526421 +0200 @@ -66,6 +66,7 @@ #include #include @@ -463,7 +463,7 @@ diff -up openssh-7.9p1/sshd.c.fips openssh-7.9p1/sshd.c #include "openbsd-compat/openssl-compat.h" #endif -@@ -1581,6 +1584,18 @@ main(int ac, char **av) +@@ -1529,6 +1532,18 @@ main(int ac, char **av) #endif __progname = ssh_get_progname(av[0]); @@ -482,7 +482,7 @@ diff -up openssh-7.9p1/sshd.c.fips openssh-7.9p1/sshd.c /* Save argv. Duplicate so setproctitle emulation doesn't clobber it */ saved_argc = ac; rexec_argc = ac; -@@ -2036,6 +2051,10 @@ main(int ac, char **av) +@@ -1992,6 +2007,10 @@ main(int ac, char **av) /* Reinitialize the log (because of the fork above). */ log_init(__progname, options.log_level, options.log_facility, log_stderr); @@ -493,7 +493,7 @@ diff -up openssh-7.9p1/sshd.c.fips openssh-7.9p1/sshd.c /* Chdir to the root directory so that the current disk can be unmounted if desired. */ if (chdir("/") == -1) -@@ -2412,10 +2431,14 @@ do_ssh2_kex(void) +@@ -2382,10 +2401,14 @@ do_ssh2_kex(struct ssh *ssh) if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0) orig = NULL; @@ -512,9 +512,9 @@ diff -up openssh-7.9p1/sshd.c.fips openssh-7.9p1/sshd.c if (gss && orig) xasprintf(&newstr, "%s,%s", gss, orig); -diff -up openssh-7.9p1/sshkey.c.fips openssh-7.9p1/sshkey.c ---- openssh-7.9p1/sshkey.c.fips 2019-03-11 17:06:37.617878003 +0100 -+++ openssh-7.9p1/sshkey.c 2019-03-11 17:06:37.624878069 +0100 +diff -up openssh-8.0p1/sshkey.c.fips openssh-8.0p1/sshkey.c +--- openssh-8.0p1/sshkey.c.fips 2019-07-23 14:55:45.398526371 +0200 ++++ openssh-8.0p1/sshkey.c 2019-07-23 14:55:45.404526431 +0200 @@ -34,6 +34,7 @@ #include #include @@ -531,7 +531,7 @@ diff -up openssh-7.9p1/sshkey.c.fips openssh-7.9p1/sshkey.c #include "xmss_fast.h" -@@ -1514,6 +1516,8 @@ rsa_generate_private_key(u_int bits, RSA +@@ -1591,6 +1593,8 @@ rsa_generate_private_key(u_int bits, RSA } if (!BN_set_word(f4, RSA_F4) || !RSA_generate_key_ex(private, bits, f4, NULL)) { @@ -540,10 +540,10 @@ diff -up openssh-7.9p1/sshkey.c.fips openssh-7.9p1/sshkey.c ret = SSH_ERR_LIBCRYPTO_ERROR; goto out; } -diff -up openssh-7.9p1/ssh-keygen.c.fips openssh-7.9p1/ssh-keygen.c ---- openssh-7.9p1/ssh-keygen.c.fips 2019-03-11 17:06:37.590877750 +0100 -+++ openssh-7.9p1/ssh-keygen.c 2019-03-11 17:06:37.625878079 +0100 -@@ -230,6 +230,12 @@ type_bits_valid(int type, const char *na +diff -up openssh-8.0p1/ssh-keygen.c.fips openssh-8.0p1/ssh-keygen.c +--- openssh-8.0p1/ssh-keygen.c.fips 2019-07-23 14:55:45.391526300 +0200 ++++ openssh-8.0p1/ssh-keygen.c 2019-07-23 14:57:54.118830056 +0200 +@@ -199,6 +199,12 @@ type_bits_valid(int type, const char *na OPENSSL_DSA_MAX_MODULUS_BITS : OPENSSL_RSA_MAX_MODULUS_BITS; if (*bitsp > maxbits) fatal("key bits exceeds maximum %d", maxbits); @@ -556,3 +556,22 @@ diff -up openssh-7.9p1/ssh-keygen.c.fips openssh-7.9p1/ssh-keygen.c switch (type) { case KEY_DSA: if (*bitsp != 1024) +@@ -1029,9 +1035,17 @@ do_gen_all_hostkeys(struct passwd *pw) + first = 1; + printf("%s: generating new host keys: ", __progname); + } ++ type = sshkey_type_from_name(key_types[i].key_type); ++ ++ /* Skip the keys that are not supported in FIPS mode */ ++ if (FIPS_mode() && (type == KEY_DSA || type == KEY_ED25519)) { ++ logit("Skipping %s key in FIPS mode", ++ key_types[i].key_type_display); ++ goto next; ++ } ++ + printf("%s ", key_types[i].key_type_display); + fflush(stdout); +- type = sshkey_type_from_name(key_types[i].key_type); + if ((fd = mkstemp(prv_tmp)) == -1) { + error("Could not save your public key in %s: %s", + prv_tmp, strerror(errno));