Commit 2ef6a931fc for bind
commit 2ef6a931fc6c6ae4ec47bdb3581eefb226837992
Author: Martin Basti <mbasti@isc.org>
Date: Mon Nov 2 17:29:46 2026 +0000
Clamp RSA key sizes in dns_kasp_key_size() to the 1024-bit minimum
dns_kasp_key_size() kept its own copy of the RSA limits, clamping a
configured length up to 512 bits, or 1024 only for RSASHA512. The
dnssec-policy parser now rejects anything below 1024 for all RSA
algorithms, so use the same floor here and drop the per-algorithm
special case.
Assisted-by: Claude:claude-fable-5-1
diff --git a/lib/dns/kasp.c b/lib/dns/kasp.c
index 840e451561..72b51be2c2 100644
--- a/lib/dns/kasp.c
+++ b/lib/dns/kasp.c
@@ -422,7 +422,6 @@ dns_kasp_key_algorithm(dns_kasp_key_t *key) {
unsigned int
dns_kasp_key_size(dns_kasp_key_t *key) {
unsigned int size = 0;
- unsigned int min = 0;
REQUIRE(key != NULL);
@@ -433,11 +432,10 @@ dns_kasp_key_size(dns_kasp_key_t *key) {
case DST_ALG_RSASHA512:
case DST_ALG_RSASHA256PRIVATEOID:
case DST_ALG_RSASHA512PRIVATEOID:
- min = (key->algorithm == DST_ALG_RSASHA512) ? 1024 : 512;
if (key->length > -1) {
size = (unsigned int)key->length;
- if (size < min) {
- size = min;
+ if (size < 1024) {
+ size = 1024;
}
if (size > 4096) {
size = 4096;
diff --git a/tests/dns/kasp_test.c b/tests/dns/kasp_test.c
new file mode 100644
index 0000000000..54f7b029a0
--- /dev/null
+++ b/tests/dns/kasp_test.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#include <inttypes.h>
+#include <sched.h> /* IWYU pragma: keep */
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define UNIT_TESTING
+#include <cmocka.h>
+
+#include <isc/lib.h>
+#include <isc/util.h>
+
+#include <dns/kasp.h>
+#include <dns/lib.h>
+
+#include <tests/dns.h>
+
+/* Default and clamped RSA key sizes. */
+ISC_RUN_TEST_IMPL(kasp_key_size_rsa) {
+ struct {
+ dst_algorithm_t algorithm;
+ int length;
+ unsigned int expected;
+ } testcases[] = {
+ /* No configured length: default to 2048. */
+ { DST_ALG_RSASHA1, -1, 2048 },
+ { DST_ALG_NSEC3RSASHA1, -1, 2048 },
+ { DST_ALG_RSASHA256, -1, 2048 },
+ { DST_ALG_RSASHA512, -1, 2048 },
+ { DST_ALG_RSASHA256PRIVATEOID, -1, 2048 },
+ { DST_ALG_RSASHA512PRIVATEOID, -1, 2048 },
+ /* The minimum for all RSA algorithms is 1024. */
+ { DST_ALG_RSASHA1, 512, 1024 },
+ { DST_ALG_NSEC3RSASHA1, 512, 1024 },
+ { DST_ALG_RSASHA256, 512, 1024 },
+ { DST_ALG_RSASHA512, 512, 1024 },
+ { DST_ALG_RSASHA256PRIVATEOID, 512, 1024 },
+ { DST_ALG_RSASHA512PRIVATEOID, 512, 1024 },
+ { DST_ALG_RSASHA256, 1024, 1024 },
+ /* Values in range are returned unchanged. */
+ { DST_ALG_RSASHA256, 3072, 3072 },
+ { DST_ALG_RSASHA256, 4096, 4096 },
+ /* The maximum is 4096. */
+ { DST_ALG_RSASHA256, 8192, 4096 },
+ };
+ dns_kasp_t *kasp = NULL;
+
+ dns_kasp_create(isc_g_mctx, "test", &kasp);
+
+ for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
+ dns_kasp_key_t *key = NULL;
+
+ dns_kasp_key_create(kasp, &key);
+ key->algorithm = testcases[i].algorithm;
+ key->length = testcases[i].length;
+ assert_int_equal(dns_kasp_key_size(key), testcases[i].expected);
+ dns_kasp_key_destroy(key);
+ }
+
+ dns_kasp_detach(&kasp);
+}
+
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(kasp_key_size_rsa)
+ISC_TEST_LIST_END
+
+ISC_TEST_MAIN
diff --git a/tests/dns/meson.build b/tests/dns/meson.build
index 07b2581a5a..5a0ab35f5f 100644
--- a/tests/dns/meson.build
+++ b/tests/dns/meson.build
@@ -27,6 +27,7 @@ dns_tests = [
'dsdigest',
'dst',
'ede',
+ 'kasp',
'keymgr',
'keytable',
'master',