2014-05-30 01:22:53 -04:00
|
|
|
/*
|
2017-10-12 00:11:37 -04:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2014-05-30 01:22:53 -04:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2021-06-03 02:37:05 -04:00
|
|
|
*
|
2014-05-30 01:22:53 -04:00
|
|
|
* 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/.
|
2018-02-23 03:53:12 -05:00
|
|
|
*
|
2014-05-30 01:22:53 -04:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
|
*/
|
|
|
|
|
|
Include <sched.h> where necessary for musl libc
All unit tests define the UNIT_TESTING macro, which causes <cmocka.h> to
replace malloc(), calloc(), realloc(), and free() with its own functions
tracking memory allocations. In order for this not to break
compilation, the system header declaring the prototypes for these
standard functions must be included before <cmocka.h>.
Normally, these prototypes are only present in <stdlib.h>, so we make
sure it is included before <cmocka.h>. However, musl libc also defines
the prototypes for calloc() and free() in <sched.h>, which is included
by <pthread.h>, which is included e.g. by <isc/mutex.h>. Thus, unit
tests including "dnstest.h" (which includes <isc/mem.h>, which includes
<isc/mutex.h>) after <cmocka.h> will not compile with musl libc as for
these programs, <sched.h> will be included after <cmocka.h>.
Always including <cmocka.h> after all other header files is not a
feasible solution as that causes the mock assertion macros defined in
<isc/util.h> to mangle the contents of <cmocka.h>, thus breaking
compilation. We cannot really use the __noreturn__ or analyzer_noreturn
attributes with cmocka assertion functions because they do return if the
tested condition is true. The problem is that what BIND unit tests do
is incompatible with Clang Static Analyzer's assumptions: since we use
cmocka, our custom assertion handlers are present in a shared library
(i.e. it is the cmocka library that checks the assertion condition, not
a macro in unit test code). Redefining cmocka's assertion macros in
<isc/util.h> is an ugly hack to overcome that problem - unfortunately,
this is the only way we can think of to make Clang Static Analyzer
properly process unit test code. Giving up on Clang Static Analyzer
being able to properly process unit test code is not a satisfactory
solution.
Undefining _GNU_SOURCE for unit test code could work around the problem
(musl libc's <sched.h> only defines the prototypes for calloc() and
free() when _GNU_SOURCE is defined), but doing that could introduce
discrepancies for unit tests including entire *.c files, so it is also
not a good solution.
All in all, including <sched.h> before <cmocka.h> for all affected unit
tests seems to be the most benign way of working around this musl libc
quirk. While quite an ugly solution, it achieves our goals here, which
are to keep the benefit of proper static analysis of unit test code and
to fix compilation against musl libc.
2019-07-30 15:08:40 -04:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
2018-11-14 06:50:53 -05:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
#include <stdarg.h>
|
2018-04-17 11:29:14 -04:00
|
|
|
#include <stdbool.h>
|
2018-11-14 06:50:53 -05:00
|
|
|
#include <stddef.h>
|
2014-05-30 01:22:53 -04:00
|
|
|
#include <stdio.h>
|
Include <sched.h> where necessary for musl libc
All unit tests define the UNIT_TESTING macro, which causes <cmocka.h> to
replace malloc(), calloc(), realloc(), and free() with its own functions
tracking memory allocations. In order for this not to break
compilation, the system header declaring the prototypes for these
standard functions must be included before <cmocka.h>.
Normally, these prototypes are only present in <stdlib.h>, so we make
sure it is included before <cmocka.h>. However, musl libc also defines
the prototypes for calloc() and free() in <sched.h>, which is included
by <pthread.h>, which is included e.g. by <isc/mutex.h>. Thus, unit
tests including "dnstest.h" (which includes <isc/mem.h>, which includes
<isc/mutex.h>) after <cmocka.h> will not compile with musl libc as for
these programs, <sched.h> will be included after <cmocka.h>.
Always including <cmocka.h> after all other header files is not a
feasible solution as that causes the mock assertion macros defined in
<isc/util.h> to mangle the contents of <cmocka.h>, thus breaking
compilation. We cannot really use the __noreturn__ or analyzer_noreturn
attributes with cmocka assertion functions because they do return if the
tested condition is true. The problem is that what BIND unit tests do
is incompatible with Clang Static Analyzer's assumptions: since we use
cmocka, our custom assertion handlers are present in a shared library
(i.e. it is the cmocka library that checks the assertion condition, not
a macro in unit test code). Redefining cmocka's assertion macros in
<isc/util.h> is an ugly hack to overcome that problem - unfortunately,
this is the only way we can think of to make Clang Static Analyzer
properly process unit test code. Giving up on Clang Static Analyzer
being able to properly process unit test code is not a satisfactory
solution.
Undefining _GNU_SOURCE for unit test code could work around the problem
(musl libc's <sched.h> only defines the prototypes for calloc() and
free() when _GNU_SOURCE is defined), but doing that could introduce
discrepancies for unit tests including entire *.c files, so it is also
not a good solution.
All in all, including <sched.h> before <cmocka.h> for all affected unit
tests seems to be the most benign way of working around this musl libc
quirk. While quite an ugly solution, it achieves our goals here, which
are to keep the benefit of proper static analysis of unit test code and
to fix compilation against musl libc.
2019-07-30 15:08:40 -04:00
|
|
|
#include <stdlib.h>
|
2018-03-28 08:19:37 -04:00
|
|
|
#include <unistd.h>
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2018-11-14 06:50:53 -05:00
|
|
|
#define UNIT_TESTING
|
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
|
2014-05-30 01:22:53 -04:00
|
|
|
#include <isc/base64.h>
|
|
|
|
|
#include <isc/buffer.h>
|
2019-12-20 14:37:11 -05:00
|
|
|
#include <isc/md.h>
|
2014-05-30 01:22:53 -04:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
|
|
#include <dns/fixedname.h>
|
|
|
|
|
#include <dns/keytable.h>
|
2019-12-20 14:37:11 -05:00
|
|
|
#include <dns/name.h>
|
2014-05-30 01:22:53 -04:00
|
|
|
#include <dns/nta.h>
|
|
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
|
#include <dns/rdatastruct.h>
|
|
|
|
|
#include <dns/rootns.h>
|
|
|
|
|
#include <dns/view.h>
|
|
|
|
|
|
|
|
|
|
#include <dst/dst.h>
|
2020-02-12 07:59:18 -05:00
|
|
|
|
2022-05-03 05:37:31 -04:00
|
|
|
#include <tests/dns.h>
|
2018-11-14 06:50:53 -05:00
|
|
|
|
2022-07-26 07:03:45 -04:00
|
|
|
static int
|
|
|
|
|
setup_test(void **state) {
|
|
|
|
|
setup_loopmgr(state);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
teardown_test(void **state) {
|
|
|
|
|
teardown_loopmgr(state);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-30 01:22:53 -04:00
|
|
|
dns_keytable_t *keytable = NULL;
|
|
|
|
|
dns_ntatable_t *ntatable = NULL;
|
|
|
|
|
|
|
|
|
|
static const char *keystr1 = "BQEAAAABok+vaUC9neRv8yeT/"
|
|
|
|
|
"FEGgN7svR8s7VBUVSBd8NsAiV8AlaAg "
|
|
|
|
|
"O5FHar3JQd95i/puZos6Vi6at9/"
|
|
|
|
|
"JBbN8qVmO2AuiXxVqfxMKxIcy+LEB "
|
|
|
|
|
"0Vw4NaSJ3N3uaVREso6aTSs98H/"
|
|
|
|
|
"25MjcwLOr7SFfXA7bGhZatLtYY/xu kp6Km5hMfkE=";
|
|
|
|
|
|
|
|
|
|
static const char *keystr2 = "BQEAAAABwuHz9Cem0BJ0JQTO7C/a3McR6hMaufljs1dfG/"
|
|
|
|
|
"inaJpYv7vH "
|
|
|
|
|
"XTrAOm/MeKp+/x6eT4QLru0KoZkvZJnqTI8JyaFTw2OM/"
|
|
|
|
|
"ItBfh/hL2lm "
|
|
|
|
|
"Cft2O7n3MfeqYtvjPnY7dWghYW4sVfH7VVEGm958o9nfi7953"
|
|
|
|
|
"2Qeklxh x8pXWdeAaRU=";
|
|
|
|
|
|
2014-06-18 19:47:22 -04:00
|
|
|
static dns_view_t *view = NULL;
|
|
|
|
|
|
2014-05-30 01:22:53 -04:00
|
|
|
/*
|
|
|
|
|
* Test utilities. In general, these assume input parameters are valid
|
2018-11-14 06:50:53 -05:00
|
|
|
* (checking with assert_int_equal, thus aborting if not) and unlikely run time
|
2014-05-30 01:22:53 -04:00
|
|
|
* errors (such as memory allocation failure) won't happen. This helps keep
|
|
|
|
|
* the test code concise.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Utility to convert C-string to dns_name_t. Return a pointer to
|
|
|
|
|
* static data, and so is not thread safe.
|
|
|
|
|
*/
|
|
|
|
|
static dns_name_t *
|
|
|
|
|
str2name(const char *namestr) {
|
|
|
|
|
static dns_fixedname_t fname;
|
|
|
|
|
static dns_name_t *name;
|
|
|
|
|
static isc_buffer_t namebuf;
|
|
|
|
|
|
2018-03-28 08:38:09 -04:00
|
|
|
name = dns_fixedname_initname(&fname);
|
2023-03-30 16:34:12 -04:00
|
|
|
isc_buffer_init(&namebuf, UNCONST(namestr), strlen(namestr));
|
2014-05-30 01:22:53 -04:00
|
|
|
isc_buffer_add(&namebuf, strlen(namestr));
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(
|
|
|
|
|
dns_name_fromtext(name, &namebuf, dns_rootname, 0, NULL),
|
|
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
return (name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-12-11 03:09:15 -05:00
|
|
|
create_keystruct(uint16_t flags, uint8_t proto, uint8_t alg, const char *keystr,
|
|
|
|
|
dns_rdata_dnskey_t *keystruct) {
|
2014-05-30 01:22:53 -04:00
|
|
|
unsigned char keydata[4096];
|
|
|
|
|
isc_buffer_t keydatabuf;
|
|
|
|
|
isc_region_t r;
|
2019-12-11 03:09:15 -05:00
|
|
|
const dns_rdataclass_t rdclass = dns_rdataclass_in;
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2019-12-11 03:09:15 -05:00
|
|
|
keystruct->common.rdclass = rdclass;
|
|
|
|
|
keystruct->common.rdtype = dns_rdatatype_dnskey;
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 04:56:42 -04:00
|
|
|
keystruct->mctx = mctx;
|
2019-12-11 03:09:15 -05:00
|
|
|
ISC_LINK_INIT(&keystruct->common, link);
|
|
|
|
|
keystruct->flags = flags;
|
|
|
|
|
keystruct->protocol = proto;
|
|
|
|
|
keystruct->algorithm = alg;
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
isc_buffer_init(&keydatabuf, keydata, sizeof(keydata));
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(isc_base64_decodestring(keystr, &keydatabuf),
|
|
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
isc_buffer_usedregion(&keydatabuf, &r);
|
2019-12-11 03:09:15 -05:00
|
|
|
keystruct->datalen = r.length;
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 04:56:42 -04:00
|
|
|
keystruct->data = isc_mem_allocate(mctx, r.length);
|
2019-12-11 03:09:15 -05:00
|
|
|
memmove(keystruct->data, r.base, r.length);
|
|
|
|
|
}
|
2018-11-14 06:50:53 -05:00
|
|
|
|
2019-12-11 03:09:15 -05:00
|
|
|
static void
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(dns_name_t *name, uint16_t flags, uint8_t proto, uint8_t alg,
|
|
|
|
|
const char *keystr, unsigned char *digest,
|
|
|
|
|
dns_rdata_ds_t *dsstruct) {
|
2019-12-11 03:09:15 -05:00
|
|
|
isc_result_t result;
|
|
|
|
|
unsigned char rrdata[4096];
|
|
|
|
|
isc_buffer_t rrdatabuf;
|
2019-12-20 14:37:11 -05:00
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
|
|
|
|
dns_rdata_dnskey_t dnskey;
|
2019-12-11 03:09:15 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Populate DNSKEY rdata structure.
|
|
|
|
|
*/
|
2019-12-20 14:37:11 -05:00
|
|
|
create_keystruct(flags, proto, alg, keystr, &dnskey);
|
2019-12-11 03:09:15 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Convert to wire format.
|
|
|
|
|
*/
|
|
|
|
|
isc_buffer_init(&rrdatabuf, rrdata, sizeof(rrdata));
|
2019-12-20 14:37:11 -05:00
|
|
|
result = dns_rdata_fromstruct(&rdata, dnskey.common.rdclass,
|
|
|
|
|
dnskey.common.rdtype, &dnskey,
|
|
|
|
|
&rrdatabuf);
|
2019-12-11 03:09:15 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
|
|
/*
|
2019-12-20 14:37:11 -05:00
|
|
|
* Build DS rdata struct.
|
2019-12-11 03:09:15 -05:00
|
|
|
*/
|
2019-12-20 14:37:11 -05:00
|
|
|
result = dns_ds_fromkeyrdata(name, &rdata, DNS_DSDIGEST_SHA256, digest,
|
|
|
|
|
dsstruct);
|
2019-12-11 03:09:15 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
2019-12-20 14:37:11 -05:00
|
|
|
dns_rdata_freestruct(&dnskey);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Common setup: create a keytable and ntatable to test with a few keys */
|
|
|
|
|
static void
|
2018-08-07 10:46:53 -04:00
|
|
|
create_tables(void) {
|
2019-12-20 14:37:11 -05:00
|
|
|
unsigned char digest[ISC_MAX_MD_SIZE];
|
|
|
|
|
dns_rdata_ds_t ds;
|
|
|
|
|
dns_fixedname_t fn;
|
|
|
|
|
dns_name_t *keyname = dns_fixedname_name(&fn);
|
2023-03-30 15:13:41 -04:00
|
|
|
isc_stdtime_t now = isc_stdtime_now();
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2023-08-15 11:29:27 -04:00
|
|
|
assert_int_equal(dns_test_makeview("view", false, false, &view),
|
2022-06-16 20:40:47 -04:00
|
|
|
ISC_R_SUCCESS);
|
2014-06-18 19:47:22 -04:00
|
|
|
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keytable_create(view, &keytable);
|
2023-04-05 03:36:37 -04:00
|
|
|
dns_ntatable_create(view, loopmgr, &ntatable);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* Add a normal key */
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("example.com.", &fn);
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds,
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
2017-10-27 18:45:18 -04:00
|
|
|
|
|
|
|
|
/* Add an initializing managed key */
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("managed.com.", &fn);
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_add(keytable, true, true, keyname, &ds,
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* Add a null key */
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_marksecure(keytable, str2name("null.example")),
|
|
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* Add a negative trust anchor, duration 1 hour */
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(dns_ntatable_add(ntatable,
|
|
|
|
|
str2name("insecure.example"), false,
|
|
|
|
|
now, 3600),
|
|
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-08-07 10:46:53 -04:00
|
|
|
destroy_tables(void) {
|
2018-11-14 06:50:53 -05:00
|
|
|
if (ntatable != NULL) {
|
2022-10-03 09:54:12 -04:00
|
|
|
dns_ntatable_shutdown(ntatable);
|
2014-05-30 01:22:53 -04:00
|
|
|
dns_ntatable_detach(&ntatable);
|
2018-11-14 06:50:53 -05:00
|
|
|
}
|
|
|
|
|
if (keytable != NULL) {
|
2014-05-30 01:22:53 -04:00
|
|
|
dns_keytable_detach(&keytable);
|
2018-11-14 06:50:53 -05:00
|
|
|
}
|
2014-06-18 19:47:22 -04:00
|
|
|
|
|
|
|
|
dns_view_detach(&view);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
2018-11-14 06:50:53 -05:00
|
|
|
/* add keys to the keytable */
|
2022-07-26 07:03:45 -04:00
|
|
|
ISC_LOOP_TEST_IMPL(add) {
|
2014-05-30 01:22:53 -04:00
|
|
|
dns_keynode_t *keynode = NULL;
|
|
|
|
|
dns_keynode_t *null_keynode = NULL;
|
2019-12-20 14:37:11 -05:00
|
|
|
unsigned char digest[ISC_MAX_MD_SIZE];
|
|
|
|
|
dns_rdata_ds_t ds;
|
|
|
|
|
dns_fixedname_t fn;
|
|
|
|
|
dns_name_t *keyname = dns_fixedname_name(&fn);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2022-07-26 07:03:45 -04:00
|
|
|
UNUSED(arg);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
create_tables();
|
|
|
|
|
|
|
|
|
|
/*
|
2019-12-19 22:39:33 -05:00
|
|
|
* Getting the keynode for the example.com key should succeed.
|
2014-05-30 01:22:53 -04:00
|
|
|
*/
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("example.com"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/*
|
2019-12-19 22:39:33 -05:00
|
|
|
* Try to add the same key. This should have no effect but
|
|
|
|
|
* report success.
|
2014-05-30 01:22:53 -04:00
|
|
|
*/
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("example.com.", &fn);
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds,
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2019-12-19 22:39:33 -05:00
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("example.com"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* Add another key (different keydata) */
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds,
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("example.com"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2017-10-27 18:45:18 -04:00
|
|
|
|
|
|
|
|
/*
|
2019-12-19 22:39:33 -05:00
|
|
|
* Get the keynode for the managed.com key. Ensure the
|
2017-10-27 18:45:18 -04:00
|
|
|
* retrieved key is an initializing key, then mark it as trusted using
|
|
|
|
|
* dns_keynode_trust() and ensure the latter works as expected.
|
|
|
|
|
*/
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("managed.com"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_int_equal(dns_keynode_initial(keynode), true);
|
2017-10-27 18:45:18 -04:00
|
|
|
dns_keynode_trust(keynode);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(dns_keynode_initial(keynode), false);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2017-10-27 18:45:18 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Add a different managed key for managed.com, marking it as an
|
2019-12-20 19:23:25 -05:00
|
|
|
* initializing key. Since there is already a trusted key at the
|
|
|
|
|
* node, the node should *not* be marked as initializing.
|
2017-10-27 18:45:18 -04:00
|
|
|
*/
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("managed.com.", &fn);
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_add(keytable, true, true, keyname, &ds,
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("managed.com"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2019-12-20 19:23:25 -05:00
|
|
|
assert_int_equal(dns_keynode_initial(keynode), false);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2017-10-27 18:45:18 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Add the same managed key again, but this time mark it as a
|
|
|
|
|
* non-initializing key. Ensure the previously added key is upgraded
|
|
|
|
|
* to a non-initializing key and make sure there are still two key
|
|
|
|
|
* nodes for managed.com, both containing non-initializing keys.
|
|
|
|
|
*/
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_add(keytable, true, false, keyname, &ds,
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("managed.com"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_int_equal(dns_keynode_initial(keynode), false);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2017-10-27 18:45:18 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Add a managed key at a new node, two.com, marking it as an
|
2019-12-19 22:39:33 -05:00
|
|
|
* initializing key.
|
2017-10-27 18:45:18 -04:00
|
|
|
*/
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("two.com.", &fn);
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_add(keytable, true, true, keyname, &ds,
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("two.com"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_int_equal(dns_keynode_initial(keynode), true);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2017-10-27 18:45:18 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Add a different managed key for two.com, marking it as a
|
2019-12-20 19:23:25 -05:00
|
|
|
* non-initializing key. Since there is already an iniitalizing
|
|
|
|
|
* trust anchor for two.com and we haven't run dns_keynode_trust(),
|
|
|
|
|
* the initialization status should not change.
|
2017-10-27 18:45:18 -04:00
|
|
|
*/
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_add(keytable, true, false, keyname, &ds,
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("two.com"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2019-12-20 19:23:25 -05:00
|
|
|
assert_int_equal(dns_keynode_initial(keynode), true);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Add a normal key to a name that has a null key. The null key node
|
|
|
|
|
* will be updated with the normal key.
|
|
|
|
|
*/
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(dns_keytable_find(keytable, str2name("null.example"),
|
|
|
|
|
&null_keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("null.example.", &fn);
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds,
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("null.example"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2020-11-26 07:10:40 -05:00
|
|
|
assert_ptr_equal(keynode, null_keynode); /* should be the same node */
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&null_keynode);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try to add a null key to a name that already has a key. It's
|
2019-12-19 22:39:33 -05:00
|
|
|
* effectively no-op, so the same key node is still there.
|
2014-05-30 01:22:53 -04:00
|
|
|
* (Note: this and above checks confirm that if a name has a null key
|
|
|
|
|
* that's the only key for the name).
|
|
|
|
|
*/
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_marksecure(keytable, str2name("null.example")),
|
|
|
|
|
ISC_R_SUCCESS);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(dns_keytable_find(keytable, str2name("null.example"),
|
|
|
|
|
&null_keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2020-11-26 07:10:40 -05:00
|
|
|
assert_ptr_equal(keynode, null_keynode);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&null_keynode);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2014-05-30 01:22:53 -04:00
|
|
|
destroy_tables();
|
2022-07-26 07:03:45 -04:00
|
|
|
|
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
2018-11-14 06:50:53 -05:00
|
|
|
/* delete keys from the keytable */
|
2022-07-26 07:03:45 -04:00
|
|
|
ISC_LOOP_TEST_IMPL(delete) {
|
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
2014-05-30 01:22:53 -04:00
|
|
|
create_tables();
|
|
|
|
|
|
|
|
|
|
/* dns_keytable_delete requires exact match */
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_delete(keytable, str2name("example.org"),
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_NOTFOUND);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_delete(keytable,
|
|
|
|
|
str2name("s.example.com"), NULL,
|
|
|
|
|
NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_NOTFOUND);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_delete(keytable, str2name("example.com"),
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* works also for nodes with a null key */
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_delete(keytable, str2name("null.example"),
|
|
|
|
|
NULL, NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* or a negative trust anchor */
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(
|
|
|
|
|
dns_ntatable_delete(ntatable, str2name("insecure.example")),
|
|
|
|
|
ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
destroy_tables();
|
2022-07-26 07:03:45 -04:00
|
|
|
|
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
2018-11-14 06:50:53 -05:00
|
|
|
/* delete key nodes from the keytable */
|
2022-07-26 07:03:45 -04:00
|
|
|
ISC_LOOP_TEST_IMPL(deletekey) {
|
2019-12-11 03:09:15 -05:00
|
|
|
dns_rdata_dnskey_t dnskey;
|
|
|
|
|
dns_fixedname_t fn;
|
|
|
|
|
dns_name_t *keyname = dns_fixedname_name(&fn);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2022-07-26 07:03:45 -04:00
|
|
|
UNUSED(arg);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
create_tables();
|
|
|
|
|
|
|
|
|
|
/* key name doesn't match */
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("example.org.", &fn);
|
2019-12-11 03:09:15 -05:00
|
|
|
create_keystruct(257, 3, 5, keystr1, &dnskey);
|
|
|
|
|
assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_NOTFOUND);
|
2019-12-11 03:09:15 -05:00
|
|
|
dns_rdata_freestruct(&dnskey);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* subdomain match is the same as no match */
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("sub.example.org.", &fn);
|
2019-12-11 03:09:15 -05:00
|
|
|
create_keystruct(257, 3, 5, keystr1, &dnskey);
|
|
|
|
|
assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_NOTFOUND);
|
2019-12-11 03:09:15 -05:00
|
|
|
dns_rdata_freestruct(&dnskey);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* name matches but key doesn't match (resulting in PARTIALMATCH) */
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("example.com.", &fn);
|
2019-12-11 03:09:15 -05:00
|
|
|
create_keystruct(257, 3, 5, keystr2, &dnskey);
|
|
|
|
|
assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
|
2018-11-14 06:50:53 -05:00
|
|
|
DNS_R_PARTIALMATCH);
|
2019-12-11 03:09:15 -05:00
|
|
|
dns_rdata_freestruct(&dnskey);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/*
|
2019-12-23 23:26:03 -05:00
|
|
|
* exact match: should return SUCCESS on the first try, then
|
|
|
|
|
* PARTIALMATCH on the second (because the name existed but
|
|
|
|
|
* not a matching key).
|
2014-05-30 01:22:53 -04:00
|
|
|
*/
|
2019-12-11 03:09:15 -05:00
|
|
|
create_keystruct(257, 3, 5, keystr1, &dnskey);
|
|
|
|
|
assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_SUCCESS);
|
2019-12-11 03:09:15 -05:00
|
|
|
assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
|
2019-12-23 23:26:03 -05:00
|
|
|
DNS_R_PARTIALMATCH);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* after deleting the node, any deletekey or delete attempt should
|
|
|
|
|
* result in NOTFOUND.
|
|
|
|
|
*/
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_delete(keytable, keyname, NULL, NULL),
|
|
|
|
|
ISC_R_SUCCESS);
|
2019-12-23 23:26:03 -05:00
|
|
|
assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
|
2018-11-14 06:50:53 -05:00
|
|
|
ISC_R_NOTFOUND);
|
2019-12-11 03:09:15 -05:00
|
|
|
dns_rdata_freestruct(&dnskey);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/*
|
2015-02-06 17:08:28 -05:00
|
|
|
* A null key node for a name is not deleted when searched by key;
|
|
|
|
|
* it must be deleted by dns_keytable_delete()
|
2014-05-30 01:22:53 -04:00
|
|
|
*/
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("null.example.", &fn);
|
2019-12-11 03:09:15 -05:00
|
|
|
create_keystruct(257, 3, 5, keystr1, &dnskey);
|
|
|
|
|
assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
|
2018-11-14 06:50:53 -05:00
|
|
|
DNS_R_PARTIALMATCH);
|
2022-06-16 20:40:47 -04:00
|
|
|
assert_int_equal(dns_keytable_delete(keytable, keyname, NULL, NULL),
|
|
|
|
|
ISC_R_SUCCESS);
|
2019-12-11 03:09:15 -05:00
|
|
|
dns_rdata_freestruct(&dnskey);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
destroy_tables();
|
2022-07-26 07:03:45 -04:00
|
|
|
|
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
2018-11-14 06:50:53 -05:00
|
|
|
/* check find-variant operations */
|
2022-07-26 07:03:45 -04:00
|
|
|
ISC_LOOP_TEST_IMPL(find) {
|
2014-05-30 01:22:53 -04:00
|
|
|
dns_keynode_t *keynode = NULL;
|
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
|
dns_name_t *name;
|
|
|
|
|
|
2022-07-26 07:03:45 -04:00
|
|
|
UNUSED(arg);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
create_tables();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* dns_keytable_find() requires exact name match. It matches node
|
2017-10-28 13:59:40 -04:00
|
|
|
* that has a null key, too.
|
2014-05-30 01:22:53 -04:00
|
|
|
*/
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("example.org"), &keynode),
|
|
|
|
|
ISC_R_NOTFOUND);
|
|
|
|
|
assert_int_equal(dns_keytable_find(keytable,
|
|
|
|
|
str2name("sub.example.com"),
|
|
|
|
|
&keynode),
|
|
|
|
|
ISC_R_NOTFOUND);
|
|
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("example.com"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(
|
|
|
|
|
dns_keytable_find(keytable, str2name("null.example"), &keynode),
|
|
|
|
|
ISC_R_SUCCESS);
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_keynode_detach(&keynode);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* dns_keytable_finddeepestmatch() allows partial match. Also match
|
2017-10-28 13:59:40 -04:00
|
|
|
* nodes with a null key.
|
2014-05-30 01:22:53 -04:00
|
|
|
*/
|
2018-03-28 08:38:09 -04:00
|
|
|
name = dns_fixedname_initname(&fname);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(dns_keytable_finddeepestmatch(
|
|
|
|
|
keytable, str2name("example.com"), name),
|
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_true(dns_name_equal(name, str2name("example.com")));
|
|
|
|
|
assert_int_equal(dns_keytable_finddeepestmatch(
|
|
|
|
|
keytable, str2name("s.example.com"), name),
|
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_true(dns_name_equal(name, str2name("example.com")));
|
|
|
|
|
assert_int_equal(dns_keytable_finddeepestmatch(
|
|
|
|
|
keytable, str2name("example.org"), name),
|
|
|
|
|
ISC_R_NOTFOUND);
|
|
|
|
|
assert_int_equal(dns_keytable_finddeepestmatch(
|
|
|
|
|
keytable, str2name("null.example"), name),
|
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_true(dns_name_equal(name, str2name("null.example")));
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
destroy_tables();
|
2022-07-26 07:03:45 -04:00
|
|
|
|
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
2018-11-14 06:50:53 -05:00
|
|
|
/* check issecuredomain() */
|
2022-07-26 07:03:45 -04:00
|
|
|
ISC_LOOP_TEST_IMPL(issecuredomain) {
|
2018-04-17 11:29:14 -04:00
|
|
|
bool issecure;
|
2014-05-30 01:22:53 -04:00
|
|
|
const char **n;
|
|
|
|
|
const char *names[] = { "example.com", "sub.example.com",
|
|
|
|
|
"null.example", "sub.null.example", NULL };
|
|
|
|
|
|
2022-07-26 07:03:45 -04:00
|
|
|
UNUSED(arg);
|
2014-05-30 01:22:53 -04:00
|
|
|
create_tables();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Domains that are an exact or partial match of a key name are
|
|
|
|
|
* considered secure. It's the case even if the key is null
|
|
|
|
|
* (validation will then fail, but that's actually the intended effect
|
|
|
|
|
* of installing a null key).
|
|
|
|
|
*/
|
|
|
|
|
for (n = names; *n != NULL; n++) {
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(dns_keytable_issecuredomain(keytable,
|
|
|
|
|
str2name(*n), NULL,
|
|
|
|
|
&issecure),
|
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_true(issecure);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2017-10-28 13:59:40 -04:00
|
|
|
* If the key table has no entry (not even a null one) for a domain or
|
|
|
|
|
* any of its ancestors, that domain is considered insecure.
|
2014-05-30 01:22:53 -04:00
|
|
|
*/
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(dns_keytable_issecuredomain(keytable,
|
|
|
|
|
str2name("example.org"),
|
|
|
|
|
NULL, &issecure),
|
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
assert_false(issecure);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
destroy_tables();
|
2022-07-26 07:03:45 -04:00
|
|
|
|
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
2018-11-14 06:50:53 -05:00
|
|
|
/* check dns_keytable_dump() */
|
2022-07-26 07:03:45 -04:00
|
|
|
ISC_LOOP_TEST_IMPL(dump) {
|
2018-11-16 03:19:06 -05:00
|
|
|
FILE *f = fopen("/dev/null", "w");
|
|
|
|
|
|
2022-07-26 07:03:45 -04:00
|
|
|
UNUSED(arg);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
create_tables();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Right now, we only confirm the dump attempt doesn't cause disruption
|
|
|
|
|
* (so we don't check the dump content).
|
|
|
|
|
*/
|
2018-11-16 03:19:06 -05:00
|
|
|
assert_int_equal(dns_keytable_dump(keytable, f), ISC_R_SUCCESS);
|
|
|
|
|
fclose(f);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
destroy_tables();
|
2022-07-26 07:03:45 -04:00
|
|
|
|
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2014-05-30 01:22:53 -04:00
|
|
|
}
|
|
|
|
|
|
2018-11-14 06:50:53 -05:00
|
|
|
/* check negative trust anchors */
|
2022-07-26 07:03:45 -04:00
|
|
|
ISC_LOOP_TEST_IMPL(nta) {
|
2014-05-30 01:22:53 -04:00
|
|
|
isc_result_t result;
|
2018-04-17 11:29:14 -04:00
|
|
|
bool issecure, covered;
|
2019-12-20 14:37:11 -05:00
|
|
|
dns_fixedname_t fn;
|
|
|
|
|
dns_name_t *keyname = dns_fixedname_name(&fn);
|
|
|
|
|
unsigned char digest[ISC_MAX_MD_SIZE];
|
|
|
|
|
dns_rdata_ds_t ds;
|
2015-01-20 16:29:18 -05:00
|
|
|
dns_view_t *myview = NULL;
|
2023-03-30 15:13:41 -04:00
|
|
|
isc_stdtime_t now = isc_stdtime_now();
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2023-08-15 11:29:27 -04:00
|
|
|
result = dns_test_makeview("view", false, false, &myview);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2023-04-15 17:49:45 -04:00
|
|
|
dns_view_initsecroots(myview);
|
|
|
|
|
|
2015-01-20 16:29:18 -05:00
|
|
|
result = dns_view_getsecroots(myview, &keytable);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2023-04-05 03:36:37 -04:00
|
|
|
dns_view_initntatable(myview, loopmgr);
|
2015-01-20 16:29:18 -05:00
|
|
|
result = dns_view_getntatable(myview, &ntatable);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2022-06-09 15:29:58 -04:00
|
|
|
dns_test_namefromstring("example.", &fn);
|
2019-12-20 14:37:11 -05:00
|
|
|
create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
|
2022-06-16 20:40:47 -04:00
|
|
|
result = dns_keytable_add(keytable, false, false, keyname, &ds, NULL,
|
|
|
|
|
NULL),
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2019-12-20 14:37:11 -05:00
|
|
|
result = dns_ntatable_add(ntatable, str2name("insecure.example"), false,
|
2018-04-17 11:29:14 -04:00
|
|
|
now, 1);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* Should be secure */
|
2015-01-20 16:29:18 -05:00
|
|
|
result = dns_view_issecuredomain(myview,
|
2014-05-30 01:22:53 -04:00
|
|
|
str2name("test.secure.example"), now,
|
2019-04-24 05:17:15 -04:00
|
|
|
true, &covered, &issecure);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2019-04-24 05:17:15 -04:00
|
|
|
assert_false(covered);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_true(issecure);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* Should not be secure */
|
2015-01-20 16:29:18 -05:00
|
|
|
result = dns_view_issecuredomain(myview,
|
2014-05-30 01:22:53 -04:00
|
|
|
str2name("test.insecure.example"), now,
|
2019-04-24 05:17:15 -04:00
|
|
|
true, &covered, &issecure);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2019-04-24 05:17:15 -04:00
|
|
|
assert_true(covered);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_false(issecure);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* NTA covered */
|
2015-01-20 16:29:18 -05:00
|
|
|
covered = dns_view_ntacovers(myview, now, str2name("insecure.example"),
|
2014-05-30 01:22:53 -04:00
|
|
|
dns_rootname);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_true(covered);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* Not NTA covered */
|
2015-01-20 16:29:18 -05:00
|
|
|
covered = dns_view_ntacovers(myview, now, str2name("secure.example"),
|
2014-05-30 01:22:53 -04:00
|
|
|
dns_rootname);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_false(covered);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* As of now + 2, the NTA should be clear */
|
2015-01-20 16:29:18 -05:00
|
|
|
result = dns_view_issecuredomain(myview,
|
2014-05-30 01:22:53 -04:00
|
|
|
str2name("test.insecure.example"),
|
2019-04-24 05:17:15 -04:00
|
|
|
now + 2, true, &covered, &issecure);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2019-04-24 05:17:15 -04:00
|
|
|
assert_false(covered);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_true(issecure);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
/* Now check deletion */
|
2017-10-28 13:59:40 -04:00
|
|
|
result = dns_view_issecuredomain(myview, str2name("test.new.example"),
|
2019-04-24 05:17:15 -04:00
|
|
|
now, true, &covered, &issecure);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2019-04-24 05:17:15 -04:00
|
|
|
assert_false(covered);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_true(issecure);
|
2017-10-28 13:59:40 -04:00
|
|
|
|
2014-06-18 19:47:22 -04:00
|
|
|
result = dns_ntatable_add(ntatable, str2name("new.example"), false, now,
|
2018-04-17 11:29:14 -04:00
|
|
|
3600);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2015-01-20 16:29:18 -05:00
|
|
|
result = dns_view_issecuredomain(myview, str2name("test.new.example"),
|
2019-04-24 05:17:15 -04:00
|
|
|
now, true, &covered, &issecure);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2019-04-24 05:17:15 -04:00
|
|
|
assert_true(covered);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_false(issecure);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
|
|
|
|
result = dns_ntatable_delete(ntatable, str2name("new.example"));
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2015-01-20 16:29:18 -05:00
|
|
|
result = dns_view_issecuredomain(myview, str2name("test.new.example"),
|
2019-04-24 05:17:15 -04:00
|
|
|
now, true, &covered, &issecure);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2019-04-24 05:17:15 -04:00
|
|
|
assert_false(covered);
|
2018-11-14 06:50:53 -05:00
|
|
|
assert_true(issecure);
|
2014-05-30 01:22:53 -04:00
|
|
|
|
2023-04-05 03:36:37 -04:00
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
|
|
|
|
|
2014-05-30 01:22:53 -04:00
|
|
|
/* Clean up */
|
|
|
|
|
dns_ntatable_detach(&ntatable);
|
|
|
|
|
dns_keytable_detach(&keytable);
|
2015-01-20 16:29:18 -05:00
|
|
|
dns_view_detach(&myview);
|
2018-11-14 06:50:53 -05:00
|
|
|
}
|
2014-05-30 01:22:53 -04:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 04:56:42 -04:00
|
|
|
ISC_TEST_LIST_START
|
2022-07-26 07:03:45 -04:00
|
|
|
ISC_TEST_ENTRY_CUSTOM(add, setup_test, teardown_test)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(delete, setup_test, teardown_test)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(deletekey, setup_test, teardown_test)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(find, setup_test, teardown_test)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(issecuredomain, setup_test, teardown_test)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(dump, setup_test, teardown_test)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(nta, setup_test, teardown_test)
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 04:56:42 -04:00
|
|
|
ISC_TEST_LIST_END
|
2018-11-14 06:50:53 -05:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 04:56:42 -04:00
|
|
|
ISC_TEST_MAIN
|