2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/dh.c.fips openssh-8.6p1/dh.c
|
|
|
|
--- openssh-8.6p1/dh.c.fips 2021-04-16 05:55:25.000000000 +0200
|
|
|
|
+++ openssh-8.6p1/dh.c 2021-05-06 12:12:10.107634472 +0200
|
2022-12-16 10:52:54 +00:00
|
|
|
@@ -36,6 +36,7 @@
|
|
|
|
|
|
|
|
#include <openssl/bn.h>
|
|
|
|
#include <openssl/dh.h>
|
|
|
|
+#include <openssl/fips.h>
|
|
|
|
|
|
|
|
#include "dh.h"
|
|
|
|
#include "pathnames.h"
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -164,6 +164,12 @@ choose_dh(int min, int wantbits, int max
|
2020-10-15 20:26:16 +00:00
|
|
|
int best, bestcount, which, linenum;
|
|
|
|
struct dhgroup dhg;
|
|
|
|
|
|
|
|
+ if (FIPS_mode()) {
|
2022-06-29 15:30:44 +00:00
|
|
|
+ verbose("Using arbitrary primes is not allowed in FIPS mode."
|
2020-10-15 20:26:16 +00:00
|
|
|
+ " Falling back to known groups.");
|
|
|
|
+ return (dh_new_group_fallback(max));
|
|
|
|
+ }
|
|
|
|
+
|
2021-05-06 12:51:30 +00:00
|
|
|
if ((f = fopen(get_moduli_filename(), "r")) == NULL) {
|
2020-10-15 20:26:16 +00:00
|
|
|
logit("WARNING: could not open %s (%s), using fixed modulus",
|
2021-05-06 12:51:30 +00:00
|
|
|
get_moduli_filename(), strerror(errno));
|
|
|
|
@@ -502,4 +508,38 @@ dh_estimate(int bits)
|
2020-10-15 20:26:16 +00:00
|
|
|
return 8192;
|
|
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * Compares the received DH parameters with known-good groups,
|
|
|
|
+ * which might be either from group14, group16 or group18.
|
|
|
|
+ */
|
|
|
|
+int
|
|
|
|
+dh_is_known_group(const DH *dh)
|
|
|
|
+{
|
|
|
|
+ const BIGNUM *p, *g;
|
|
|
|
+ const BIGNUM *known_p, *known_g;
|
|
|
|
+ DH *known = NULL;
|
|
|
|
+ int bits = 0, rv = 0;
|
|
|
|
+
|
|
|
|
+ DH_get0_pqg(dh, &p, NULL, &g);
|
|
|
|
+ bits = BN_num_bits(p);
|
|
|
|
+
|
|
|
|
+ if (bits <= 3072) {
|
|
|
|
+ known = dh_new_group14();
|
|
|
|
+ } else if (bits <= 6144) {
|
|
|
|
+ known = dh_new_group16();
|
|
|
|
+ } else {
|
|
|
|
+ known = dh_new_group18();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DH_get0_pqg(known, &known_p, NULL, &known_g);
|
|
|
|
+
|
|
|
|
+ if (BN_cmp(g, known_g) == 0 &&
|
|
|
|
+ BN_cmp(p, known_p) == 0) {
|
|
|
|
+ rv = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DH_free(known);
|
|
|
|
+ return rv;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
#endif /* WITH_OPENSSL */
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/dh.h.fips openssh-8.6p1/dh.h
|
|
|
|
--- openssh-8.6p1/dh.h.fips 2021-05-06 12:08:36.498926877 +0200
|
|
|
|
+++ openssh-8.6p1/dh.h 2021-05-06 12:11:28.393298005 +0200
|
|
|
|
@@ -45,6 +45,7 @@ DH *dh_new_group_fallback(int);
|
2020-10-15 20:26:16 +00:00
|
|
|
|
|
|
|
int dh_gen_key(DH *, int);
|
|
|
|
int dh_pub_is_valid(const DH *, const BIGNUM *);
|
|
|
|
+int dh_is_known_group(const DH *);
|
|
|
|
|
|
|
|
u_int dh_estimate(int);
|
2021-05-06 12:51:30 +00:00
|
|
|
void dh_set_moduli_file(const char *);
|
|
|
|
diff -up openssh-8.6p1/kex.c.fips openssh-8.6p1/kex.c
|
|
|
|
--- openssh-8.6p1/kex.c.fips 2021-05-06 12:08:36.489926807 +0200
|
|
|
|
+++ openssh-8.6p1/kex.c 2021-05-06 12:08:36.498926877 +0200
|
2022-12-16 10:52:54 +00:00
|
|
|
@@ -39,6 +39,7 @@
|
|
|
|
|
|
|
|
#ifdef WITH_OPENSSL
|
|
|
|
#include <openssl/crypto.h>
|
|
|
|
+#include <openssl/fips.h>
|
|
|
|
#include <openssl/dh.h>
|
|
|
|
# ifdef HAVE_EVP_KDF_CTX_NEW_ID
|
|
|
|
# include <openssl/kdf.h>
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -203,7 +203,10 @@ kex_names_valid(const char *names)
|
2020-10-15 20:26:16 +00:00
|
|
|
for ((p = strsep(&cp, ",")); p && *p != '\0';
|
|
|
|
(p = strsep(&cp, ","))) {
|
|
|
|
if (kex_alg_by_name(p) == NULL) {
|
|
|
|
- error("Unsupported KEX algorithm \"%.100s\"", p);
|
|
|
|
+ if (FIPS_mode())
|
|
|
|
+ error("\"%.100s\" is not allowed in FIPS mode", p);
|
|
|
|
+ else
|
|
|
|
+ error("Unsupported KEX algorithm \"%.100s\"", p);
|
|
|
|
free(s);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/kexgexc.c.fips openssh-8.6p1/kexgexc.c
|
|
|
|
--- openssh-8.6p1/kexgexc.c.fips 2021-04-16 05:55:25.000000000 +0200
|
|
|
|
+++ openssh-8.6p1/kexgexc.c 2021-05-06 12:08:36.498926877 +0200
|
2020-10-15 20:26:16 +00:00
|
|
|
@@ -28,6 +28,7 @@
|
|
|
|
|
|
|
|
#ifdef WITH_OPENSSL
|
|
|
|
|
2022-12-16 10:52:54 +00:00
|
|
|
+#include <openssl/fips.h>
|
2020-10-15 20:26:16 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <openssl/dh.h>
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -115,6 +116,10 @@ input_kex_dh_gex_group(int type, u_int32
|
2020-10-15 20:26:16 +00:00
|
|
|
r = SSH_ERR_ALLOC_FAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
+ if (FIPS_mode() && dh_is_known_group(kex->dh) == 0) {
|
|
|
|
+ r = SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
p = g = NULL; /* belong to kex->dh now */
|
|
|
|
|
|
|
|
/* generate and send 'e', client DH public key */
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/myproposal.h.fips openssh-8.6p1/myproposal.h
|
|
|
|
--- openssh-8.6p1/myproposal.h.fips 2021-04-16 05:55:25.000000000 +0200
|
|
|
|
+++ openssh-8.6p1/myproposal.h 2021-05-06 12:08:36.498926877 +0200
|
2022-07-11 13:45:56 +00:00
|
|
|
@@ -57,6 +57,18 @@
|
2020-10-15 20:26:16 +00:00
|
|
|
"rsa-sha2-256," \
|
|
|
|
"ssh-rsa"
|
|
|
|
|
|
|
|
+#define KEX_FIPS_PK_ALG \
|
|
|
|
+ "ecdsa-sha2-nistp256-cert-v01@openssh.com," \
|
|
|
|
+ "ecdsa-sha2-nistp384-cert-v01@openssh.com," \
|
|
|
|
+ "ecdsa-sha2-nistp521-cert-v01@openssh.com," \
|
|
|
|
+ "rsa-sha2-512-cert-v01@openssh.com," \
|
|
|
|
+ "rsa-sha2-256-cert-v01@openssh.com," \
|
|
|
|
+ "ecdsa-sha2-nistp256," \
|
|
|
|
+ "ecdsa-sha2-nistp384," \
|
|
|
|
+ "ecdsa-sha2-nistp521," \
|
|
|
|
+ "rsa-sha2-512," \
|
2022-07-11 13:45:56 +00:00
|
|
|
+ "rsa-sha2-256"
|
2020-10-15 20:26:16 +00:00
|
|
|
+
|
|
|
|
#define KEX_SERVER_ENCRYPT \
|
|
|
|
"chacha20-poly1305@openssh.com," \
|
|
|
|
"aes128-ctr,aes192-ctr,aes256-ctr," \
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -78,6 +92,27 @@
|
2020-10-15 20:26:16 +00:00
|
|
|
|
|
|
|
#define KEX_CLIENT_MAC KEX_SERVER_MAC
|
|
|
|
|
|
|
|
+#define KEX_FIPS_ENCRYPT \
|
|
|
|
+ "aes128-ctr,aes192-ctr,aes256-ctr," \
|
|
|
|
+ "aes128-cbc,3des-cbc," \
|
|
|
|
+ "aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se," \
|
|
|
|
+ "aes128-gcm@openssh.com,aes256-gcm@openssh.com"
|
|
|
|
+#define KEX_DEFAULT_KEX_FIPS \
|
|
|
|
+ "ecdh-sha2-nistp256," \
|
|
|
|
+ "ecdh-sha2-nistp384," \
|
|
|
|
+ "ecdh-sha2-nistp521," \
|
|
|
|
+ "diffie-hellman-group-exchange-sha256," \
|
|
|
|
+ "diffie-hellman-group16-sha512," \
|
|
|
|
+ "diffie-hellman-group18-sha512," \
|
|
|
|
+ "diffie-hellman-group14-sha256"
|
|
|
|
+#define KEX_FIPS_MAC \
|
|
|
|
+ "hmac-sha1," \
|
|
|
|
+ "hmac-sha2-256," \
|
|
|
|
+ "hmac-sha2-512," \
|
|
|
|
+ "hmac-sha1-etm@openssh.com," \
|
|
|
|
+ "hmac-sha2-256-etm@openssh.com," \
|
|
|
|
+ "hmac-sha2-512-etm@openssh.com"
|
|
|
|
+
|
|
|
|
/* Not a KEX value, but here so all the algorithm defaults are together */
|
|
|
|
#define SSH_ALLOWED_CA_SIGALGS \
|
2021-03-22 10:10:25 +00:00
|
|
|
"ssh-ed25519," \
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/readconf.c.fips openssh-8.6p1/readconf.c
|
|
|
|
--- openssh-8.6p1/readconf.c.fips 2021-05-06 12:08:36.428926336 +0200
|
|
|
|
+++ openssh-8.6p1/readconf.c 2021-05-06 12:08:36.499926885 +0200
|
2022-12-16 10:52:54 +00:00
|
|
|
@@ -39,6 +39,7 @@
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
+#include <openssl/fips.h>
|
|
|
|
#ifdef USE_SYSTEM_GLOB
|
|
|
|
# include <glob.h>
|
|
|
|
#else
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -2538,11 +2538,16 @@ fill_default_options(Options * options)
|
2020-10-15 20:26:16 +00:00
|
|
|
all_key = sshkey_alg_list(0, 0, 1, ',');
|
|
|
|
all_sig = sshkey_alg_list(0, 1, 1, ',');
|
|
|
|
/* remove unsupported algos from default lists */
|
|
|
|
- def_cipher = match_filter_allowlist(KEX_CLIENT_ENCRYPT, all_cipher);
|
|
|
|
- def_mac = match_filter_allowlist(KEX_CLIENT_MAC, all_mac);
|
|
|
|
- def_kex = match_filter_allowlist(KEX_CLIENT_KEX, all_kex);
|
|
|
|
- def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
|
|
|
|
- def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
|
|
|
|
+ def_cipher = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_FIPS_ENCRYPT : KEX_CLIENT_ENCRYPT), all_cipher);
|
|
|
|
+ def_mac = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_FIPS_MAC : KEX_CLIENT_MAC), all_mac);
|
|
|
|
+ def_kex = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_DEFAULT_KEX_FIPS : KEX_CLIENT_KEX), all_kex);
|
|
|
|
+ def_key = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG), all_key);
|
|
|
|
+ def_sig = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_FIPS_PK_ALG : SSH_ALLOWED_CA_SIGALGS), all_sig);
|
|
|
|
#define ASSEMBLE(what, defaults, all) \
|
|
|
|
do { \
|
|
|
|
if ((r = kex_assemble_names(&options->what, \
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/sandbox-seccomp-filter.c.fips openssh-8.6p1/sandbox-seccomp-filter.c
|
|
|
|
--- openssh-8.6p1/sandbox-seccomp-filter.c.fips 2021-05-06 12:08:36.463926606 +0200
|
|
|
|
+++ openssh-8.6p1/sandbox-seccomp-filter.c 2021-05-06 12:08:36.499926885 +0200
|
|
|
|
@@ -160,6 +160,9 @@ static const struct sock_filter preauth_
|
2020-10-15 20:26:16 +00:00
|
|
|
#ifdef __NR_open
|
|
|
|
SC_DENY(__NR_open, EACCES),
|
|
|
|
#endif
|
|
|
|
+#ifdef __NR_socket
|
|
|
|
+ SC_DENY(__NR_socket, EACCES),
|
|
|
|
+#endif
|
|
|
|
#ifdef __NR_openat
|
|
|
|
SC_DENY(__NR_openat, EACCES),
|
|
|
|
#endif
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/servconf.c.fips openssh-8.6p1/servconf.c
|
|
|
|
--- openssh-8.6p1/servconf.c.fips 2021-05-06 12:08:36.455926545 +0200
|
|
|
|
+++ openssh-8.6p1/servconf.c 2021-05-06 12:08:36.500926893 +0200
|
2022-12-16 10:52:54 +00:00
|
|
|
@@ -38,6 +38,7 @@
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <errno.h>
|
|
|
|
+#include <openssl/fips.h>
|
|
|
|
#ifdef HAVE_UTIL_H
|
|
|
|
#include <util.h>
|
|
|
|
#endif
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -226,11 +226,16 @@ assemble_algorithms(ServerOptions *o)
|
2020-10-15 20:26:16 +00:00
|
|
|
all_key = sshkey_alg_list(0, 0, 1, ',');
|
|
|
|
all_sig = sshkey_alg_list(0, 1, 1, ',');
|
|
|
|
/* remove unsupported algos from default lists */
|
|
|
|
- def_cipher = match_filter_allowlist(KEX_SERVER_ENCRYPT, all_cipher);
|
|
|
|
- def_mac = match_filter_allowlist(KEX_SERVER_MAC, all_mac);
|
|
|
|
- def_kex = match_filter_allowlist(KEX_SERVER_KEX, all_kex);
|
|
|
|
- def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
|
|
|
|
- def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
|
|
|
|
+ def_cipher = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_FIPS_ENCRYPT : KEX_SERVER_ENCRYPT), all_cipher);
|
|
|
|
+ def_mac = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_FIPS_MAC : KEX_SERVER_MAC), all_mac);
|
|
|
|
+ def_kex = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_DEFAULT_KEX_FIPS : KEX_SERVER_KEX), all_kex);
|
|
|
|
+ def_key = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG), all_key);
|
|
|
|
+ def_sig = match_filter_allowlist((FIPS_mode() ?
|
|
|
|
+ KEX_FIPS_PK_ALG : SSH_ALLOWED_CA_SIGALGS), all_sig);
|
|
|
|
#define ASSEMBLE(what, defaults, all) \
|
|
|
|
do { \
|
|
|
|
if ((r = kex_assemble_names(&o->what, defaults, all)) != 0) \
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/ssh.c.fips openssh-8.6p1/ssh.c
|
|
|
|
--- openssh-8.6p1/ssh.c.fips 2021-05-06 12:08:36.467926637 +0200
|
|
|
|
+++ openssh-8.6p1/ssh.c 2021-05-06 12:08:36.500926893 +0200
|
|
|
|
@@ -77,6 +77,7 @@
|
2020-10-15 20:26:16 +00:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#endif
|
2022-12-16 10:52:54 +00:00
|
|
|
+#include <openssl/fips.h>
|
2020-10-15 20:26:16 +00:00
|
|
|
#include "openbsd-compat/openssl-compat.h"
|
|
|
|
#include "openbsd-compat/sys-queue.h"
|
|
|
|
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -1516,6 +1517,10 @@ main(int ac, char **av)
|
2020-10-15 20:26:16 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2021-05-06 12:51:30 +00:00
|
|
|
|
2020-10-15 20:26:16 +00:00
|
|
|
+ if (FIPS_mode()) {
|
|
|
|
+ debug("FIPS mode initialized");
|
|
|
|
+ }
|
2021-05-06 12:51:30 +00:00
|
|
|
+
|
2020-10-15 20:26:16 +00:00
|
|
|
/* Expand SecurityKeyProvider if it refers to an environment variable */
|
|
|
|
if (options.sk_provider != NULL && *options.sk_provider == '$' &&
|
2021-05-06 12:51:30 +00:00
|
|
|
strlen(options.sk_provider) > 1) {
|
|
|
|
diff -up openssh-8.6p1/sshconnect2.c.fips openssh-8.6p1/sshconnect2.c
|
|
|
|
--- openssh-8.6p1/sshconnect2.c.fips 2021-05-06 12:08:36.485926777 +0200
|
|
|
|
+++ openssh-8.6p1/sshconnect2.c 2021-05-06 12:08:36.501926900 +0200
|
|
|
|
@@ -45,6 +45,8 @@
|
2020-10-15 20:26:16 +00:00
|
|
|
#include <vis.h>
|
|
|
|
#endif
|
|
|
|
|
2022-12-16 10:52:54 +00:00
|
|
|
+#include <openssl/fips.h>
|
2020-10-15 20:26:16 +00:00
|
|
|
+
|
|
|
|
#include "openbsd-compat/sys-queue.h"
|
|
|
|
|
|
|
|
#include "xmalloc.h"
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -269,36 +271,41 @@ ssh_kex2(struct ssh *ssh, char *host, st
|
2020-10-15 20:26:16 +00:00
|
|
|
|
|
|
|
#if defined(GSSAPI) && defined(WITH_OPENSSL)
|
|
|
|
if (options.gss_keyex) {
|
|
|
|
- /* Add the GSSAPI mechanisms currently supported on this
|
|
|
|
- * client to the key exchange algorithm proposal */
|
|
|
|
- orig = myproposal[PROPOSAL_KEX_ALGS];
|
|
|
|
-
|
|
|
|
- if (options.gss_server_identity) {
|
|
|
|
- gss_host = xstrdup(options.gss_server_identity);
|
|
|
|
- } else if (options.gss_trust_dns) {
|
|
|
|
- gss_host = remote_hostname(ssh);
|
|
|
|
- /* Fall back to specified host if we are using proxy command
|
|
|
|
- * and can not use DNS on that socket */
|
|
|
|
- if (strcmp(gss_host, "UNKNOWN") == 0) {
|
|
|
|
- free(gss_host);
|
|
|
|
+ if (FIPS_mode()) {
|
|
|
|
+ logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
|
|
|
|
+ options.gss_keyex = 0;
|
|
|
|
+ } else {
|
|
|
|
+ /* Add the GSSAPI mechanisms currently supported on this
|
|
|
|
+ * client to the key exchange algorithm proposal */
|
|
|
|
+ orig = myproposal[PROPOSAL_KEX_ALGS];
|
|
|
|
+
|
|
|
|
+ if (options.gss_server_identity) {
|
|
|
|
+ gss_host = xstrdup(options.gss_server_identity);
|
|
|
|
+ } else if (options.gss_trust_dns) {
|
|
|
|
+ gss_host = remote_hostname(ssh);
|
|
|
|
+ /* Fall back to specified host if we are using proxy command
|
|
|
|
+ * and can not use DNS on that socket */
|
|
|
|
+ if (strcmp(gss_host, "UNKNOWN") == 0) {
|
|
|
|
+ free(gss_host);
|
|
|
|
+ gss_host = xstrdup(host);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
2021-05-06 12:51:30 +00:00
|
|
|
gss_host = xstrdup(host);
|
|
|
|
}
|
|
|
|
- } else {
|
|
|
|
- gss_host = xstrdup(host);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- gss = ssh_gssapi_client_mechanisms(gss_host,
|
|
|
|
- options.gss_client_identity, options.gss_kex_algorithms);
|
|
|
|
- if (gss) {
|
|
|
|
- debug("Offering GSSAPI proposal: %s", gss);
|
|
|
|
- xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
|
|
|
|
- "%s,%s", gss, orig);
|
|
|
|
-
|
|
|
|
- /* If we've got GSSAPI algorithms, then we also support the
|
|
|
|
- * 'null' hostkey, as a last resort */
|
|
|
|
- orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
|
|
|
|
- xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
|
|
|
|
- "%s,null", orig);
|
2020-10-15 20:26:16 +00:00
|
|
|
+ gss = ssh_gssapi_client_mechanisms(gss_host,
|
|
|
|
+ options.gss_client_identity, options.gss_kex_algorithms);
|
|
|
|
+ if (gss) {
|
|
|
|
+ debug("Offering GSSAPI proposal: %s", gss);
|
|
|
|
+ xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
|
|
|
|
+ "%s,%s", gss, orig);
|
|
|
|
+
|
|
|
|
+ /* If we've got GSSAPI algorithms, then we also support the
|
|
|
|
+ * 'null' hostkey, as a last resort */
|
|
|
|
+ orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
|
|
|
|
+ xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
|
|
|
|
+ "%s,null", orig);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/sshd.c.fips openssh-8.6p1/sshd.c
|
|
|
|
--- openssh-8.6p1/sshd.c.fips 2021-05-06 12:08:36.493926838 +0200
|
|
|
|
+++ openssh-8.6p1/sshd.c 2021-05-06 12:13:56.501492639 +0200
|
2020-10-15 20:26:16 +00:00
|
|
|
@@ -66,6 +66,7 @@
|
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
+#include <syslog.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
@@ -77,6 +78,7 @@
|
|
|
|
#include <openssl/dh.h>
|
|
|
|
#include <openssl/bn.h>
|
|
|
|
#include <openssl/rand.h>
|
2022-12-16 10:52:54 +00:00
|
|
|
+#include <openssl/fips.h>
|
2020-10-15 20:26:16 +00:00
|
|
|
#include "openbsd-compat/openssl-compat.h"
|
|
|
|
#endif
|
|
|
|
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -1619,6 +1621,7 @@ main(int ac, char **av)
|
2020-10-15 20:26:16 +00:00
|
|
|
#endif
|
|
|
|
__progname = ssh_get_progname(av[0]);
|
|
|
|
|
|
|
|
+ OpenSSL_add_all_algorithms();
|
|
|
|
/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
|
|
|
|
saved_argc = ac;
|
|
|
|
rexec_argc = ac;
|
2022-07-13 14:19:53 +00:00
|
|
|
@@ -1931,6 +1931,13 @@ main(int ac, char **av)
|
|
|
|
&key, NULL)) != 0 && r != SSH_ERR_SYSTEM_ERROR)
|
|
|
|
do_log2_r(r, ll, "Unable to load host key \"%s\"",
|
|
|
|
options.host_key_files[i]);
|
2022-07-14 10:23:52 +00:00
|
|
|
+ if (FIPS_mode() && key != NULL && (sshkey_type_plain(key->type) == KEY_ED25519_SK
|
2022-07-13 14:19:53 +00:00
|
|
|
+ || sshkey_type_plain(key->type) == KEY_ED25519)) {
|
|
|
|
+ logit_f("sshd: Ed25519 keys are not allowed in FIPS mode, skipping %s", options.host_key_files[i]);
|
|
|
|
+ sshkey_free(key);
|
|
|
|
+ key = NULL;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
if (sshkey_is_sk(key) &&
|
|
|
|
key->sk_flags & SSH_SK_USER_PRESENCE_REQD) {
|
|
|
|
debug("host key %s requires user presence, ignoring",
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -2110,6 +2113,10 @@ main(int ac, char **av)
|
2020-10-15 20:26:16 +00:00
|
|
|
/* Reinitialize the log (because of the fork above). */
|
|
|
|
log_init(__progname, options.log_level, options.log_facility, log_stderr);
|
|
|
|
|
|
|
|
+ if (FIPS_mode()) {
|
|
|
|
+ debug("FIPS mode initialized");
|
|
|
|
+ }
|
|
|
|
+
|
2021-05-06 12:51:30 +00:00
|
|
|
/*
|
|
|
|
* Chdir to the root directory so that the current disk can be
|
|
|
|
* unmounted if desired.
|
|
|
|
@@ -2494,10 +2501,14 @@ do_ssh2_kex(struct ssh *ssh)
|
2020-10-15 20:26:16 +00:00
|
|
|
if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
|
|
|
|
orig = NULL;
|
|
|
|
|
|
|
|
- if (options.gss_keyex)
|
|
|
|
- gss = ssh_gssapi_server_mechanisms();
|
|
|
|
- else
|
|
|
|
- gss = NULL;
|
|
|
|
+ if (options.gss_keyex) {
|
|
|
|
+ if (FIPS_mode()) {
|
|
|
|
+ logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
|
|
|
|
+ options.gss_keyex = 0;
|
|
|
|
+ } else {
|
|
|
|
+ gss = ssh_gssapi_server_mechanisms();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (gss && orig)
|
|
|
|
xasprintf(&newstr, "%s,%s", gss, orig);
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/sshkey.c.fips openssh-8.6p1/sshkey.c
|
|
|
|
--- openssh-8.6p1/sshkey.c.fips 2021-05-06 12:08:36.493926838 +0200
|
|
|
|
+++ openssh-8.6p1/sshkey.c 2021-05-06 12:08:36.502926908 +0200
|
2020-10-15 20:26:16 +00:00
|
|
|
@@ -34,6 +34,7 @@
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#include <openssl/pem.h>
|
2022-12-16 10:52:54 +00:00
|
|
|
+#include <openssl/fips.h>
|
2020-10-15 20:26:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "crypto_api.h"
|
|
|
|
@@ -57,6 +58,7 @@
|
|
|
|
#define SSHKEY_INTERNAL
|
|
|
|
#include "sshkey.h"
|
|
|
|
#include "match.h"
|
|
|
|
+#include "log.h"
|
|
|
|
#include "ssh-sk.h"
|
|
|
|
|
|
|
|
#ifdef WITH_XMSS
|
2022-07-14 14:09:45 +00:00
|
|
|
@@ -285,6 +285,18 @@ sshkey_alg_list(int certs_only, int plai
|
|
|
|
for (kt = keytypes; kt->type != -1; kt++) {
|
|
|
|
if (kt->name == NULL || kt->type == KEY_NULL)
|
|
|
|
continue;
|
|
|
|
+ if (FIPS_mode()) {
|
|
|
|
+ switch (kt->type) {
|
|
|
|
+ case KEY_ED25519:
|
|
|
|
+ case KEY_ED25519_SK:
|
|
|
|
+ case KEY_ED25519_CERT:
|
|
|
|
+ case KEY_ED25519_SK_CERT:
|
|
|
|
+ continue;
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
if (!include_sigonly && kt->sigonly)
|
|
|
|
continue;
|
|
|
|
if ((certs_only && !kt->cert) || (plain_only && kt->cert))
|
2022-07-13 14:19:53 +00:00
|
|
|
@@ -1503,6 +1503,20 @@ sshkey_read(struct sshkey *ret, char **c
|
|
|
|
return SSH_ERR_EC_CURVE_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ switch (type) {
|
|
|
|
+ case KEY_ED25519:
|
|
|
|
+ case KEY_ED25519_SK:
|
|
|
|
+ case KEY_ED25519_CERT:
|
|
|
|
+ case KEY_ED25519_SK_CERT:
|
|
|
|
+ if (FIPS_mode()) {
|
|
|
|
+ sshkey_free(k);
|
|
|
|
+ logit_f("Ed25519 keys are not allowed in FIPS mode");
|
|
|
|
+ return SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
/* Fill in ret from parsed key */
|
|
|
|
ret->type = type;
|
|
|
|
if (sshkey_is_cert(ret)) {
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -1705,6 +1707,8 @@ rsa_generate_private_key(u_int bits, RSA
|
2022-06-30 08:26:35 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (EVP_PKEY_keygen(ctx, &res) <= 0) {
|
2022-07-11 15:26:00 +00:00
|
|
|
+ if (FIPS_mode())
|
|
|
|
+ logit_f("the key length might be unsupported by FIPS mode approved key generation method");
|
2020-10-15 20:26:16 +00:00
|
|
|
ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
2022-07-11 15:26:00 +00:00
|
|
|
@@ -2916,6 +2916,11 @@ sshkey_sign(struct sshkey *key,
|
|
|
|
break;
|
|
|
|
case KEY_ED25519_SK:
|
|
|
|
case KEY_ED25519_SK_CERT:
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Ed25519 keys are not allowed in FIPS mode");
|
2022-07-11 15:26:00 +00:00
|
|
|
+ return SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ }
|
|
|
|
+ /* Fallthrough */
|
|
|
|
case KEY_ECDSA_SK_CERT:
|
|
|
|
case KEY_ECDSA_SK:
|
|
|
|
r = sshsk_sign(sk_provider, key, sigp, lenp, data,
|
|
|
|
@@ -2973,6 +2978,10 @@ sshkey_verify(const struct sshkey *key,
|
|
|
|
return ssh_ed25519_verify(key, sig, siglen, data, dlen, compat);
|
|
|
|
case KEY_ED25519_SK:
|
|
|
|
case KEY_ED25519_SK_CERT:
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Ed25519 keys are not allowed in FIPS mode");
|
2022-07-11 15:26:00 +00:00
|
|
|
+ return SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ }
|
|
|
|
return ssh_ed25519_sk_verify(key, sig, siglen, data, dlen,
|
|
|
|
compat, detailsp);
|
|
|
|
#ifdef WITH_XMSS
|
2021-05-06 12:51:30 +00:00
|
|
|
diff -up openssh-8.6p1/ssh-keygen.c.fips openssh-8.6p1/ssh-keygen.c
|
|
|
|
--- openssh-8.6p1/ssh-keygen.c.fips 2021-05-06 12:08:36.467926637 +0200
|
|
|
|
+++ openssh-8.6p1/ssh-keygen.c 2021-05-06 12:08:36.503926916 +0200
|
2022-12-16 10:52:54 +00:00
|
|
|
@@ -20,6 +20,7 @@
|
|
|
|
|
|
|
|
#ifdef WITH_OPENSSL
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
+#include <openssl/fips.h>
|
|
|
|
#include <openssl/pem.h>
|
|
|
|
#include "openbsd-compat/openssl-compat.h"
|
|
|
|
#endif
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -205,6 +205,12 @@ type_bits_valid(int type, const char *na
|
2020-10-15 20:26:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef WITH_OPENSSL
|
|
|
|
+ if (FIPS_mode()) {
|
|
|
|
+ if (type == KEY_DSA)
|
|
|
|
+ fatal("DSA keys are not allowed in FIPS mode");
|
2022-07-11 15:26:00 +00:00
|
|
|
+ if (type == KEY_ED25519 || type == KEY_ED25519_SK)
|
2020-10-15 20:26:16 +00:00
|
|
|
+ fatal("ED25519 keys are not allowed in FIPS mode");
|
|
|
|
+ }
|
|
|
|
switch (type) {
|
|
|
|
case KEY_DSA:
|
|
|
|
if (*bitsp != 1024)
|
2021-05-06 12:51:30 +00:00
|
|
|
@@ -1098,9 +1104,17 @@ do_gen_all_hostkeys(struct passwd *pw)
|
2020-10-15 20:26:16 +00:00
|
|
|
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 private key in %s: %s",
|
2021-05-06 12:51:30 +00:00
|
|
|
prv_tmp, strerror(errno));
|
2022-07-11 13:45:56 +00:00
|
|
|
diff -up openssh-8.7p1/kexgen.c.fips3 openssh-8.7p1/kexgen.c
|
|
|
|
--- openssh-8.7p1/kexgen.c.fips3 2022-07-11 16:11:21.973519913 +0200
|
|
|
|
+++ openssh-8.7p1/kexgen.c 2022-07-11 16:25:31.172187365 +0200
|
|
|
|
@@ -31,6 +31,7 @@
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
2022-12-16 10:52:54 +00:00
|
|
|
+#include <openssl/fips.h>
|
2022-07-11 13:45:56 +00:00
|
|
|
|
|
|
|
#include "sshkey.h"
|
|
|
|
#include "kex.h"
|
|
|
|
@@ -115,10 +116,20 @@ kex_gen_client(struct ssh *ssh)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case KEX_C25519_SHA256:
|
|
|
|
- r = kex_c25519_keypair(kex);
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Key exchange type c25519 is not allowed in FIPS mode");
|
2022-07-11 13:45:56 +00:00
|
|
|
+ r = SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ } else {
|
|
|
|
+ r = kex_c25519_keypair(kex);
|
|
|
|
+ }
|
|
|
|
break;
|
|
|
|
case KEX_KEM_SNTRUP761X25519_SHA512:
|
|
|
|
- r = kex_kem_sntrup761x25519_keypair(kex);
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Key exchange type sntrup761 is not allowed in FIPS mode");
|
2022-07-11 13:45:56 +00:00
|
|
|
+ r = SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ } else {
|
|
|
|
+ r = kex_kem_sntrup761x25519_keypair(kex);
|
|
|
|
+ }
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r = SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
@@ -186,11 +197,21 @@ input_kex_gen_reply(int type, u_int32_t
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case KEX_C25519_SHA256:
|
|
|
|
- r = kex_c25519_dec(kex, server_blob, &shared_secret);
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Key exchange type c25519 is not allowed in FIPS mode");
|
2022-07-11 13:45:56 +00:00
|
|
|
+ r = SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ } else {
|
|
|
|
+ r = kex_c25519_dec(kex, server_blob, &shared_secret);
|
|
|
|
+ }
|
|
|
|
break;
|
|
|
|
case KEX_KEM_SNTRUP761X25519_SHA512:
|
|
|
|
- r = kex_kem_sntrup761x25519_dec(kex, server_blob,
|
|
|
|
- &shared_secret);
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Key exchange type sntrup761 is not allowed in FIPS mode");
|
2022-07-11 13:45:56 +00:00
|
|
|
+ r = SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ } else {
|
|
|
|
+ r = kex_kem_sntrup761x25519_dec(kex, server_blob,
|
|
|
|
+ &shared_secret);
|
|
|
|
+ }
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r = SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
@@ -285,12 +306,22 @@ input_kex_gen_init(int type, u_int32_t s
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case KEX_C25519_SHA256:
|
|
|
|
- r = kex_c25519_enc(kex, client_pubkey, &server_pubkey,
|
|
|
|
- &shared_secret);
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Key exchange type c25519 is not allowed in FIPS mode");
|
2022-07-11 13:45:56 +00:00
|
|
|
+ r = SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ } else {
|
|
|
|
+ r = kex_c25519_enc(kex, client_pubkey, &server_pubkey,
|
|
|
|
+ &shared_secret);
|
|
|
|
+ }
|
|
|
|
break;
|
|
|
|
case KEX_KEM_SNTRUP761X25519_SHA512:
|
|
|
|
- r = kex_kem_sntrup761x25519_enc(kex, client_pubkey,
|
|
|
|
- &server_pubkey, &shared_secret);
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Key exchange type sntrup761 is not allowed in FIPS mode");
|
2022-07-11 13:45:56 +00:00
|
|
|
+ r = SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ } else {
|
|
|
|
+ r = kex_kem_sntrup761x25519_enc(kex, client_pubkey,
|
|
|
|
+ &server_pubkey, &shared_secret);
|
|
|
|
+ }
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r = SSH_ERR_INVALID_ARGUMENT;
|
2022-07-11 15:26:00 +00:00
|
|
|
diff -up openssh-8.7p1/ssh-ed25519.c.fips3 openssh-8.7p1/ssh-ed25519.c
|
|
|
|
--- openssh-8.7p1/ssh-ed25519.c.fips3 2022-07-11 16:53:41.428343304 +0200
|
|
|
|
+++ openssh-8.7p1/ssh-ed25519.c 2022-07-11 16:56:09.284663661 +0200
|
|
|
|
@@ -24,6 +24,7 @@
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
2022-12-16 10:52:54 +00:00
|
|
|
+#include <openssl/fips.h>
|
2022-07-11 15:26:00 +00:00
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "sshbuf.h"
|
|
|
|
@@ -52,6 +53,10 @@ ssh_ed25519_sign(const struct sshkey *ke
|
|
|
|
key->ed25519_sk == NULL ||
|
|
|
|
datalen >= INT_MAX - crypto_sign_ed25519_BYTES)
|
|
|
|
return SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Ed25519 keys are not allowed in FIPS mode");
|
2022-07-11 15:26:00 +00:00
|
|
|
+ return SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ }
|
|
|
|
smlen = slen = datalen + crypto_sign_ed25519_BYTES;
|
|
|
|
if ((sig = malloc(slen)) == NULL)
|
|
|
|
return SSH_ERR_ALLOC_FAIL;
|
|
|
|
@@ -108,6 +113,10 @@ ssh_ed25519_verify(const struct sshkey *
|
|
|
|
datalen >= INT_MAX - crypto_sign_ed25519_BYTES ||
|
|
|
|
signature == NULL || signaturelen == 0)
|
|
|
|
return SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ if (FIPS_mode()) {
|
2022-07-13 14:19:53 +00:00
|
|
|
+ logit_f("Ed25519 keys are not allowed in FIPS mode");
|
2022-07-11 15:26:00 +00:00
|
|
|
+ return SSH_ERR_INVALID_ARGUMENT;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if ((b = sshbuf_from(signature, signaturelen)) == NULL)
|
|
|
|
return SSH_ERR_ALLOC_FAIL;
|