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