]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/test-dnssec-complex.c
Merge pull request #2326 from poettering/dnssec15
[thirdparty/systemd.git] / src / resolve / test-dnssec-complex.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2016 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include "sd-bus.h"
23
24 #include "alloc-util.h"
25 #include "bus-common-errors.h"
26 #include "dns-type.h"
27 #include "random-util.h"
28 #include "string-util.h"
29 #include "time-util.h"
30
31 #define DNS_CALL_TIMEOUT_USEC (45*USEC_PER_SEC)
32
33 static void test_lookup(sd_bus *bus, const char *name, uint16_t type, const char *result) {
34 _cleanup_(sd_bus_message_unrefp) sd_bus_message *req = NULL, *reply = NULL;
35 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
36 _cleanup_free_ char *m = NULL;
37 int r;
38
39 /* If the name starts with a dot, we prefix one to three random labels */
40 if (startswith(name, ".")) {
41 uint64_t i, u;
42
43 u = 1 + (random_u64() & 3);
44 name ++;
45
46 for (i = 0; i < u; i++) {
47 _cleanup_free_ char *b = NULL;
48 char *x;
49
50 assert_se(asprintf(&b, "x%" PRIu64 "x", random_u64()));
51 x = strjoin(b, ".", name, NULL);
52 assert_se(x);
53 free(m);
54 name = m = x;
55 }
56 }
57
58 assert_se(sd_bus_message_new_method_call(
59 bus,
60 &req,
61 "org.freedesktop.resolve1",
62 "/org/freedesktop/resolve1",
63 "org.freedesktop.resolve1.Manager",
64 "ResolveRecord") >= 0);
65
66 assert_se(sd_bus_message_append(req, "isqqt", 0, name, DNS_CLASS_IN, type, UINT64_C(0)) >= 0);
67
68 r = sd_bus_call(bus, req, DNS_CALL_TIMEOUT_USEC, &error, &reply);
69
70 if (r < 0) {
71 assert_se(result);
72 assert_se(sd_bus_error_has_name(&error, result));
73 log_info("[OK] %s/%s resulted in <%s>.", name, dns_type_to_string(type), error.name);
74 } else {
75 assert_se(!result);
76 log_info("[OK] %s/%s succeeded.", name, dns_type_to_string(type));
77 }
78 }
79
80 int main(int argc, char* argv[]) {
81 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
82
83 /* Note that this is a manual test as it requires:
84 *
85 * Full network access
86 * A DNSSEC capable DNS server
87 * That zones contacted are still set up as they were when I wrote this.
88 */
89
90 assert_se(sd_bus_open_system(&bus) >= 0);
91
92 /* Normally signed */
93 test_lookup(bus, "www.eurid.eu", DNS_TYPE_A, NULL);
94 test_lookup(bus, "sigok.verteiltesysteme.net", DNS_TYPE_A, NULL);
95
96 /* Normally signed, NODATA */
97 test_lookup(bus, "www.eurid.eu", DNS_TYPE_RP, BUS_ERROR_NO_SUCH_RR);
98 test_lookup(bus, "sigok.verteiltesysteme.net", DNS_TYPE_RP, BUS_ERROR_NO_SUCH_RR);
99
100 /* Invalid signature */
101 test_lookup(bus, "sigfail.verteiltesysteme.net", DNS_TYPE_A, BUS_ERROR_DNSSEC_FAILED);
102
103 /* Invalid signature, RSA, wildcard */
104 test_lookup(bus, ".wilda.rhybar.0skar.cz", DNS_TYPE_A, BUS_ERROR_DNSSEC_FAILED);
105
106 /* Invalid signature, ECDSA, wildcard */
107 test_lookup(bus, ".wilda.rhybar.ecdsa.0skar.cz", DNS_TYPE_A, BUS_ERROR_DNSSEC_FAILED);
108
109 /* NXDOMAIN in NSEC domain */
110 test_lookup(bus, "hhh.nasa.gov", DNS_TYPE_A, _BUS_ERROR_DNS "NXDOMAIN");
111
112 /* wildcard, NSEC zone */
113 test_lookup(bus, ".wilda.nsec.0skar.cz", DNS_TYPE_A, NULL);
114
115 /* wildcard, NSEC zone, NODATA */
116 test_lookup(bus, ".wilda.nsec.0skar.cz", DNS_TYPE_RP, BUS_ERROR_NO_SUCH_RR);
117
118 /* wildcard, NSEC3 zone */
119 test_lookup(bus, ".wilda.0skar.cz", DNS_TYPE_A, NULL);
120
121 /* wildcard, NSEC3 zone, NODATA */
122 test_lookup(bus, ".wilda.0skar.cz", DNS_TYPE_RP, BUS_ERROR_NO_SUCH_RR);
123
124 /* wildcard, NSEC zone, CNAME */
125 test_lookup(bus, ".wild.nsec.0skar.cz", DNS_TYPE_A, NULL);
126
127 /* wildcard, NSEC zone, NODATA, CNAME */
128 test_lookup(bus, ".wild.nsec.0skar.cz", DNS_TYPE_RP, BUS_ERROR_NO_SUCH_RR);
129
130 /* wildcard, NSEC3 zone, CNAME */
131 test_lookup(bus, ".wild.0skar.cz", DNS_TYPE_A, NULL);
132
133 /* wildcard, NSEC3 zone, NODATA, CNAME */
134 test_lookup(bus, ".wild.0skar.cz", DNS_TYPE_RP, BUS_ERROR_NO_SUCH_RR);
135
136 /* NODATA due to empty non-terminal in NSEC domain */
137 test_lookup(bus, "herndon.nasa.gov", DNS_TYPE_A, BUS_ERROR_NO_SUCH_RR);
138
139 /* NXDOMAIN in NSEC root zone: */
140 test_lookup(bus, "jasdhjas.kjkfgjhfjg", DNS_TYPE_A, _BUS_ERROR_DNS "NXDOMAIN");
141
142 /* NXDOMAIN in NSEC3 .com zone: */
143 test_lookup(bus, "kjkfgjhfjgsdfdsfd.com", DNS_TYPE_A, _BUS_ERROR_DNS "NXDOMAIN");
144
145 return 0;
146 }