]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make dnssec-keygen FIPS mode aware
authorMark Andrews <marka@isc.org>
Fri, 17 Dec 2021 06:43:58 +0000 (17:43 +1100)
committerMark Andrews <marka@isc.org>
Mon, 3 Apr 2023 02:05:29 +0000 (12:05 +1000)
- Reject SHA1 based key generation
- Increase the minimum RSA key size to 2048 bits

bin/dnssec/Makefile.am
bin/dnssec/dnssec-keygen.c

index 32c462620a7302f0471b05aa513e7f2c65a8b61b..007c66f355ebb2bb9b8f69be573b3a3e110a7ee1 100644 (file)
@@ -12,7 +12,8 @@ noinst_LTLIBRARIES = libdnssectool.la
 LDADD +=                       \
        libdnssectool.la        \
        $(LIBISC_LIBS)          \
-       $(LIBDNS_LIBS)
+       $(LIBDNS_LIBS)          \
+       $(OPENSSL_LIBS)
 
 bin_PROGRAMS = \
        dnssec-cds              \
@@ -31,7 +32,8 @@ libdnssectool_la_SOURCES =    \
 
 dnssec_keygen_CPPFLAGS =       \
        $(AM_CPPFLAGS)          \
-       $(LIBISCCFG_CFLAGS)
+       $(LIBISCCFG_CFLAGS)     \
+       $(OPENSSL_CFLAGS)
 
 dnssec_keygen_LDADD =          \
        $(LDADD)                \
index 35246e5f052436dc1079891528ae6641f2e67d58..662c4462f5a47ea7652b93f16435c2b942ee95e4 100644 (file)
@@ -36,6 +36,7 @@
 #include <isc/attributes.h>
 #include <isc/buffer.h>
 #include <isc/commandline.h>
+#include <isc/fips.h>
 #include <isc/mem.h>
 #include <isc/region.h>
 #include <isc/result.h>
 #include "dnssectool.h"
 
 #define MAX_RSA 4096 /* should be long enough... */
+#define MAX_DH 4096 /* should be long enough... */
 
 const char *program = "dnssec-keygen";
 
+/*
+ * These are are set here for backwards compatibility.  They are
+ * raised to 2048 in FIPS mode.
+ */
+static int min_rsa = 1024;
+static int min_dh = 128;
+
 isc_log_t *lctx = NULL;
 
 noreturn static void
@@ -139,16 +148,22 @@ usage(void) {
        fprintf(stderr, "    -l <file>: configuration file with dnssec-policy "
                        "statement\n");
        fprintf(stderr, "    -a <algorithm>:\n");
-       fprintf(stderr, "        RSASHA1 | NSEC3RSASHA1 |\n");
+       if (!isc_fips_mode()) {
+               fprintf(stderr, "        RSASHA1 | NSEC3RSASHA1 |\n");
+       }
        fprintf(stderr, "        RSASHA256 | RSASHA512 |\n");
        fprintf(stderr, "        ECDSAP256SHA256 | ECDSAP384SHA384 |\n");
        fprintf(stderr, "        ED25519 | ED448\n");
        fprintf(stderr, "    -3: use NSEC3-capable algorithm\n");
        fprintf(stderr, "    -b <key size in bits>:\n");
-       fprintf(stderr, "        RSASHA1:\t[1024..%d]\n", MAX_RSA);
-       fprintf(stderr, "        NSEC3RSASHA1:\t[1024..%d]\n", MAX_RSA);
-       fprintf(stderr, "        RSASHA256:\t[1024..%d]\n", MAX_RSA);
-       fprintf(stderr, "        RSASHA512:\t[1024..%d]\n", MAX_RSA);
+       if (!isc_fips_mode()) {
+               fprintf(stderr, "        RSASHA1:\t[%d..%d]\n", min_rsa,
+                       MAX_RSA);
+               fprintf(stderr, "        NSEC3RSASHA1:\t[%d..%d]\n", min_rsa,
+                       MAX_RSA);
+       }
+       fprintf(stderr, "        RSASHA256:\t[%d..%d]\n", min_rsa, MAX_RSA);
+       fprintf(stderr, "        RSASHA512:\t[%d..%d]\n", min_rsa, MAX_RSA);
        fprintf(stderr, "        ECDSAP256SHA256:\tignored\n");
        fprintf(stderr, "        ECDSAP384SHA384:\tignored\n");
        fprintf(stderr, "        ED25519:\tignored\n");
@@ -318,6 +333,17 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv) {
                        fatal("unsupported algorithm: %s", algstr);
                }
 
+               if (isc_fips_mode()) {
+                       /* verify only in FIPS mode */
+                       switch (ctx->alg) {
+                       case DST_ALG_RSASHA1:
+                       case DST_ALG_NSEC3RSASHA1:
+                               fatal("unsupported algorithm: %s", algstr);
+                       default:
+                               break;
+                       }
+               }
+
                if (ctx->use_nsec3) {
                        switch (ctx->alg) {
                        case DST_ALG_RSASHA1:
@@ -360,6 +386,11 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv) {
                        switch (ctx->alg) {
                        case DST_ALG_RSASHA1:
                        case DST_ALG_NSEC3RSASHA1:
+                               if (isc_fips_mode()) {
+                                       fatal("key size not specified (-b "
+                                             "option)");
+                               }
+                               FALLTHROUGH;
                        case DST_ALG_RSASHA256:
                        case DST_ALG_RSASHA512:
                                ctx->size = 2048;
@@ -515,14 +546,14 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv) {
        switch (ctx->alg) {
        case DNS_KEYALG_RSASHA1:
        case DNS_KEYALG_NSEC3RSASHA1:
-       case DNS_KEYALG_RSASHA256:
-               if (ctx->size != 0 && (ctx->size < 1024 || ctx->size > MAX_RSA))
-               {
-                       fatal("RSA key size %d out of range", ctx->size);
+               if (isc_fips_mode()) {
+                       fatal("SHA1 based keys not supported in FIPS mode");
                }
-               break;
+               FALLTHROUGH;
+       case DNS_KEYALG_RSASHA256:
        case DNS_KEYALG_RSASHA512:
-               if (ctx->size != 0 && (ctx->size < 1024 || ctx->size > MAX_RSA))
+               if (ctx->size != 0 &&
+                   (ctx->size < min_rsa || ctx->size > MAX_RSA))
                {
                        fatal("RSA key size %d out of range", ctx->size);
                }
@@ -1106,6 +1137,14 @@ main(int argc, char **argv) {
                fatal("could not initialize dst: %s", isc_result_totext(ret));
        }
 
+       /*
+        * After dst_lib_init which will set FIPS mode if requested
+        * at build time.  The minumums are both raised to 2048.
+        */
+       if (isc_fips_mode()) {
+               min_rsa = min_dh = 2048;
+       }
+
        setup_logging(mctx, &lctx);
 
        ctx.rdclass = strtoclass(classname);