1 1.1 christos /* $NetBSD: rdata_test.c,v 1.6 2026/01/29 18:37:56 christos Exp $ */ 2 1.1 christos 3 1.1 christos /* 4 1.1 christos * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 1.1 christos * 6 1.1 christos * SPDX-License-Identifier: MPL-2.0 7 1.1 christos * 8 1.1 christos * This Source Code Form is subject to the terms of the Mozilla Public 9 1.1 christos * License, v. 2.0. If a copy of the MPL was not distributed with this 10 1.1 christos * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 1.1 christos * 12 1.1 christos * See the COPYRIGHT file distributed with this work for additional 13 1.1 christos * information regarding copyright ownership. 14 1.1 christos */ 15 1.1 christos 16 1.1 christos #include <inttypes.h> 17 1.1 christos #include <sched.h> /* IWYU pragma: keep */ 18 1.1 christos #include <setjmp.h> 19 1.1 christos #include <stdarg.h> 20 1.1 christos #include <stdbool.h> 21 1.1 christos #include <stddef.h> 22 1.1 christos #include <stdlib.h> 23 1.1 christos #include <string.h> 24 1.1 christos #include <unistd.h> 25 1.1 christos 26 1.1 christos #define UNIT_TESTING 27 1.1 christos 28 1.4 christos #include <cmocka.h> 29 1.1 christos #include <openssl_shim.h> 30 1.1 christos 31 1.1 christos #include <openssl/err.h> 32 1.1 christos 33 1.1 christos #include <isc/commandline.h> 34 1.1 christos #include <isc/hex.h> 35 1.1 christos #include <isc/lex.h> 36 1.1 christos #include <isc/stdio.h> 37 1.1 christos #include <isc/types.h> 38 1.1 christos #include <isc/util.h> 39 1.1 christos 40 1.1 christos #include <dns/rdata.h> 41 1.1 christos 42 1.1 christos #include <tests/dns.h> 43 1.1 christos 44 1.1 christos /* 45 1.1 christos * An array of these structures is passed to compare_ok(). 46 1.1 christos */ 47 1.1 christos struct compare_ok { 48 1.1 christos const char *text1; /* text passed to fromtext_*() */ 49 1.1 christos const char *text2; /* text passed to fromtext_*() */ 50 1.1 christos int answer; /* -1, 0, 1 */ 51 1.1 christos int lineno; /* source line defining this RDATA */ 52 1.1 christos }; 53 1.1 christos typedef struct compare_ok compare_ok_t; 54 1.1 christos 55 1.1 christos struct textvsunknown { 56 1.1 christos const char *text1; 57 1.1 christos const char *text2; 58 1.1 christos }; 59 1.1 christos typedef struct textvsunknown textvsunknown_t; 60 1.1 christos 61 1.1 christos /* 62 1.1 christos * An array of these structures is passed to check_text_ok(). 63 1.1 christos */ 64 1.1 christos typedef struct text_ok { 65 1.1 christos const char *text_in; /* text passed to fromtext_*() */ 66 1.1 christos const char *text_out; /* text expected from totext_*(); 67 1.1 christos * NULL indicates text_in is invalid */ 68 1.1 christos unsigned int loop; 69 1.1 christos } text_ok_t; 70 1.1 christos 71 1.1 christos /* 72 1.1 christos * An array of these structures is passed to check_wire_ok(). 73 1.1 christos */ 74 1.1 christos typedef struct wire_ok { 75 1.1 christos unsigned char data[512]; /* RDATA in wire format */ 76 1.1 christos size_t len; /* octets of data to parse */ 77 1.1 christos bool ok; /* is this RDATA valid? */ 78 1.1 christos unsigned int loop; 79 1.1 christos } wire_ok_t; 80 1.1 christos 81 1.3 christos #define COMPARE(r1, r2, answer) { r1, r2, answer, __LINE__ } 82 1.3 christos #define COMPARE_SENTINEL() { NULL, NULL, 0, __LINE__ } 83 1.1 christos 84 1.3 christos #define TEXT_VALID_CHANGED(data_in, data_out) { data_in, data_out, 0 } 85 1.3 christos #define TEXT_VALID(data) { data, data, 0 } 86 1.3 christos #define TEXT_VALID_LOOP(loop, data) { data, data, loop } 87 1.3 christos #define TEXT_VALID_LOOPCHG(loop, data_in, data_out) { data_in, data_out, loop } 88 1.3 christos #define TEXT_INVALID(data) { data, NULL, 0 } 89 1.3 christos #define TEXT_SENTINEL() TEXT_INVALID(NULL) 90 1.1 christos 91 1.1 christos #define VARGC(...) (sizeof((unsigned char[]){ __VA_ARGS__ })) 92 1.3 christos #define WIRE_TEST(ok, loop, ...) \ 93 1.3 christos { { __VA_ARGS__ }, VARGC(__VA_ARGS__), ok, loop } 94 1.1 christos #define WIRE_VALID(...) WIRE_TEST(true, 0, __VA_ARGS__) 95 1.1 christos #define WIRE_VALID_LOOP(loop, ...) WIRE_TEST(true, loop, __VA_ARGS__) 96 1.1 christos /* 97 1.1 christos * WIRE_INVALID() test cases must always have at least one octet specified to 98 1.1 christos * distinguish them from WIRE_SENTINEL(). Use the 'empty_ok' parameter passed 99 1.1 christos * to check_wire_ok() for indicating whether empty RDATA is allowed for a given 100 1.1 christos * RR type or not. 101 1.1 christos */ 102 1.1 christos #define WIRE_INVALID(FIRST, ...) WIRE_TEST(false, 0, FIRST, __VA_ARGS__) 103 1.1 christos #define WIRE_SENTINEL() WIRE_TEST(false, 0) 104 1.1 christos 105 1.1 christos static void 106 1.1 christos detect_uncleared_libcrypto_error(void) { 107 1.1 christos const char *file, *func, *data; 108 1.1 christos int line, flags; 109 1.1 christos long err; 110 1.1 christos bool leak = false; 111 1.1 christos while ((err = ERR_get_error_all(&file, &line, &func, &data, &flags)) != 112 1.1 christos 0L) 113 1.1 christos { 114 1.1 christos fprintf(stderr, 115 1.1 christos "# Uncleared libcrypto error: %s:%d %s %s %ld %x\n", 116 1.1 christos file, line, func, data, err, flags); 117 1.1 christos leak = true; 118 1.1 christos } 119 1.1 christos assert_false(leak); 120 1.1 christos } 121 1.1 christos 122 1.1 christos /* 123 1.1 christos * Call dns_rdata_fromwire() for data in 'src', which is 'srclen' octets in 124 1.1 christos * size and represents RDATA of given 'type' and 'class'. Store the resulting 125 1.1 christos * uncompressed wire form in 'dst', which is 'dstlen' octets in size, and make 126 1.1 christos * 'rdata' refer to that uncompressed wire form. 127 1.1 christos */ 128 1.1 christos static isc_result_t 129 1.1 christos wire_to_rdata(const unsigned char *src, size_t srclen, dns_rdataclass_t rdclass, 130 1.1 christos dns_rdatatype_t type, unsigned char *dst, size_t dstlen, 131 1.1 christos dns_rdata_t *rdata) { 132 1.1 christos isc_buffer_t source, target; 133 1.1 christos isc_result_t result; 134 1.1 christos 135 1.1 christos /* 136 1.1 christos * Set up len-octet buffer pointing at data. 137 1.1 christos */ 138 1.1 christos isc_buffer_constinit(&source, src, srclen); 139 1.1 christos isc_buffer_add(&source, srclen); 140 1.1 christos isc_buffer_setactive(&source, srclen); 141 1.1 christos 142 1.1 christos /* 143 1.1 christos * Initialize target buffer. 144 1.1 christos */ 145 1.1 christos isc_buffer_init(&target, dst, dstlen); 146 1.1 christos 147 1.1 christos /* 148 1.1 christos * Try converting input data into uncompressed wire form. 149 1.1 christos */ 150 1.4 christos result = dns_rdata_fromwire(rdata, rdclass, type, &source, 151 1.4 christos DNS_DECOMPRESS_ALWAYS, &target); 152 1.1 christos detect_uncleared_libcrypto_error(); 153 1.1 christos 154 1.4 christos return result; 155 1.1 christos } 156 1.1 christos 157 1.1 christos /* 158 1.1 christos * Call dns_rdata_towire() for rdata and write to result to dst. 159 1.1 christos */ 160 1.1 christos static isc_result_t 161 1.1 christos rdata_towire(dns_rdata_t *rdata, unsigned char *dst, size_t dstlen, 162 1.1 christos size_t *length) { 163 1.1 christos isc_buffer_t target; 164 1.1 christos dns_compress_t cctx; 165 1.1 christos isc_result_t result; 166 1.1 christos 167 1.1 christos /* 168 1.1 christos * Initialize target buffer. 169 1.1 christos */ 170 1.1 christos isc_buffer_init(&target, dst, dstlen); 171 1.1 christos 172 1.1 christos /* 173 1.1 christos * Try converting input data into uncompressed wire form. 174 1.1 christos */ 175 1.4 christos dns_compress_init(&cctx, mctx, 0); 176 1.1 christos result = dns_rdata_towire(rdata, &cctx, &target); 177 1.1 christos detect_uncleared_libcrypto_error(); 178 1.1 christos dns_compress_invalidate(&cctx); 179 1.1 christos 180 1.1 christos *length = isc_buffer_usedlength(&target); 181 1.1 christos 182 1.4 christos return result; 183 1.1 christos } 184 1.1 christos 185 1.1 christos static isc_result_t 186 1.1 christos additionaldata_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype, 187 1.4 christos dns_rdataset_t *found DNS__DB_FLARG) { 188 1.1 christos UNUSED(arg); 189 1.1 christos UNUSED(name); 190 1.1 christos UNUSED(qtype); 191 1.1 christos UNUSED(found); 192 1.4 christos return ISC_R_SUCCESS; 193 1.1 christos } 194 1.1 christos 195 1.1 christos /* 196 1.1 christos * call dns_rdata_additionaldata() for rdata. 197 1.1 christos */ 198 1.1 christos static isc_result_t 199 1.1 christos rdata_additionadata(dns_rdata_t *rdata) { 200 1.4 christos return dns_rdata_additionaldata(rdata, dns_rootname, additionaldata_cb, 201 1.4 christos NULL); 202 1.1 christos } 203 1.1 christos 204 1.1 christos /* 205 1.1 christos * Call dns_rdata_checknames() with various owner names chosen to 206 1.1 christos * match well known forms. 207 1.1 christos * 208 1.1 christos * We are currently only checking that the calls do not trigger 209 1.1 christos * assertion failures. 210 1.1 christos * 211 1.1 christos * XXXMPA A future extension could be to record the expected 212 1.1 christos * result and the expected value of 'bad'. 213 1.1 christos */ 214 1.1 christos static void 215 1.1 christos rdata_checknames(dns_rdata_t *rdata) { 216 1.1 christos dns_fixedname_t fixed, bfixed; 217 1.1 christos dns_name_t *name, *bad; 218 1.1 christos isc_result_t result; 219 1.1 christos 220 1.1 christos name = dns_fixedname_initname(&fixed); 221 1.1 christos bad = dns_fixedname_initname(&bfixed); 222 1.1 christos 223 1.1 christos (void)dns_rdata_checknames(rdata, dns_rootname, NULL); 224 1.1 christos (void)dns_rdata_checknames(rdata, dns_rootname, bad); 225 1.1 christos 226 1.4 christos result = dns_name_fromstring(name, "example.net", dns_rootname, 0, 227 1.4 christos NULL); 228 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 229 1.1 christos (void)dns_rdata_checknames(rdata, name, NULL); 230 1.1 christos (void)dns_rdata_checknames(rdata, name, bad); 231 1.1 christos 232 1.4 christos result = dns_name_fromstring(name, "in-addr.arpa", dns_rootname, 0, 233 1.4 christos NULL); 234 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 235 1.1 christos (void)dns_rdata_checknames(rdata, name, NULL); 236 1.1 christos (void)dns_rdata_checknames(rdata, name, bad); 237 1.1 christos 238 1.4 christos result = dns_name_fromstring(name, "ip6.arpa", dns_rootname, 0, NULL); 239 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 240 1.1 christos (void)dns_rdata_checknames(rdata, name, NULL); 241 1.1 christos (void)dns_rdata_checknames(rdata, name, bad); 242 1.1 christos } 243 1.1 christos 244 1.1 christos /* 245 1.1 christos * Test whether converting rdata to a type-specific struct and then back to 246 1.1 christos * rdata results in the same uncompressed wire form. This checks whether 247 1.1 christos * tostruct_*() and fromstruct_*() routines for given RR class and type behave 248 1.1 christos * consistently. 249 1.1 christos * 250 1.1 christos * This function is called for every correctly processed input RDATA, from both 251 1.1 christos * check_text_ok_single() and check_wire_ok_single(). 252 1.1 christos */ 253 1.1 christos static void 254 1.1 christos check_struct_conversions(dns_rdata_t *rdata, size_t structsize, 255 1.1 christos unsigned int loop) { 256 1.1 christos dns_rdataclass_t rdclass = rdata->rdclass; 257 1.1 christos dns_rdatatype_t type = rdata->type; 258 1.1 christos isc_result_t result; 259 1.1 christos isc_buffer_t target; 260 1.1 christos void *rdata_struct; 261 1.1 christos char buf[1024]; 262 1.1 christos unsigned int count = 0; 263 1.1 christos 264 1.1 christos rdata_struct = isc_mem_allocate(mctx, structsize); 265 1.1 christos assert_non_null(rdata_struct); 266 1.1 christos 267 1.1 christos /* 268 1.1 christos * Convert from uncompressed wire form into type-specific struct. 269 1.1 christos */ 270 1.1 christos result = dns_rdata_tostruct(rdata, rdata_struct, NULL); 271 1.1 christos detect_uncleared_libcrypto_error(); 272 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 273 1.1 christos 274 1.1 christos /* 275 1.1 christos * Convert from type-specific struct into uncompressed wire form. 276 1.1 christos */ 277 1.1 christos isc_buffer_init(&target, buf, sizeof(buf)); 278 1.1 christos result = dns_rdata_fromstruct(NULL, rdclass, type, rdata_struct, 279 1.1 christos &target); 280 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 281 1.1 christos 282 1.1 christos /* 283 1.1 christos * Ensure results are consistent. 284 1.1 christos */ 285 1.1 christos assert_int_equal(isc_buffer_usedlength(&target), rdata->length); 286 1.1 christos 287 1.1 christos assert_memory_equal(buf, rdata->data, rdata->length); 288 1.1 christos 289 1.1 christos /* 290 1.1 christos * Check that one can walk hip rendezvous servers and 291 1.1 christos * https/svcb parameters. 292 1.1 christos */ 293 1.1 christos switch (type) { 294 1.1 christos case dns_rdatatype_hip: { 295 1.1 christos dns_rdata_hip_t *hip = rdata_struct; 296 1.1 christos 297 1.1 christos for (result = dns_rdata_hip_first(hip); result == ISC_R_SUCCESS; 298 1.1 christos result = dns_rdata_hip_next(hip)) 299 1.1 christos { 300 1.1 christos dns_name_t name; 301 1.1 christos dns_name_init(&name, NULL); 302 1.1 christos dns_rdata_hip_current(hip, &name); 303 1.1 christos assert_int_not_equal(dns_name_countlabels(&name), 0); 304 1.1 christos assert_true(dns_name_isabsolute(&name)); 305 1.1 christos count++; 306 1.1 christos } 307 1.1 christos assert_int_equal(result, ISC_R_NOMORE); 308 1.1 christos assert_int_equal(count, loop); 309 1.1 christos break; 310 1.1 christos } 311 1.1 christos case dns_rdatatype_https: { 312 1.1 christos dns_rdata_in_https_t *https = rdata_struct; 313 1.1 christos 314 1.1 christos for (result = dns_rdata_in_https_first(https); 315 1.1 christos result == ISC_R_SUCCESS; 316 1.1 christos result = dns_rdata_in_https_next(https)) 317 1.1 christos { 318 1.1 christos isc_region_t region; 319 1.1 christos dns_rdata_in_https_current(https, ®ion); 320 1.1 christos assert_true(region.length >= 4); 321 1.1 christos count++; 322 1.1 christos } 323 1.1 christos assert_int_equal(result, ISC_R_NOMORE); 324 1.1 christos assert_int_equal(count, loop); 325 1.1 christos break; 326 1.1 christos } 327 1.1 christos case dns_rdatatype_svcb: { 328 1.1 christos dns_rdata_in_svcb_t *svcb = rdata_struct; 329 1.1 christos 330 1.1 christos for (result = dns_rdata_in_svcb_first(svcb); 331 1.1 christos result == ISC_R_SUCCESS; 332 1.1 christos result = dns_rdata_in_svcb_next(svcb)) 333 1.1 christos { 334 1.1 christos isc_region_t region; 335 1.1 christos dns_rdata_in_svcb_current(svcb, ®ion); 336 1.1 christos assert_true(region.length >= 4); 337 1.1 christos count++; 338 1.1 christos } 339 1.1 christos assert_int_equal(result, ISC_R_NOMORE); 340 1.1 christos assert_int_equal(count, loop); 341 1.1 christos break; 342 1.1 christos } 343 1.1 christos } 344 1.1 christos 345 1.1 christos isc_mem_free(mctx, rdata_struct); 346 1.1 christos } 347 1.1 christos 348 1.1 christos /* 349 1.1 christos * Check whether converting supplied text form RDATA into uncompressed wire 350 1.1 christos * form succeeds (tests fromtext_*()). If so, try converting it back into text 351 1.1 christos * form and see if it results in the original text (tests totext_*()). 352 1.1 christos */ 353 1.1 christos static void 354 1.1 christos check_text_ok_single(const text_ok_t *text_ok, dns_rdataclass_t rdclass, 355 1.1 christos dns_rdatatype_t type, size_t structsize) { 356 1.1 christos unsigned char buf_fromtext[1024], buf_fromwire[1024], buf_towire[1024]; 357 1.1 christos dns_rdata_t rdata = DNS_RDATA_INIT, rdata2 = DNS_RDATA_INIT; 358 1.1 christos char buf_totext[1024] = { 0 }; 359 1.1 christos isc_buffer_t target; 360 1.1 christos isc_result_t result; 361 1.1 christos size_t length = 0; 362 1.1 christos 363 1.1 christos if (debug) { 364 1.1 christos fprintf(stdout, "#check_text_ok_single(%s)\n", 365 1.1 christos text_ok->text_in); 366 1.1 christos } 367 1.1 christos /* 368 1.1 christos * Try converting text form RDATA into uncompressed wire form. 369 1.1 christos */ 370 1.1 christos result = dns_test_rdatafromstring(&rdata, rdclass, type, buf_fromtext, 371 1.1 christos sizeof(buf_fromtext), 372 1.1 christos text_ok->text_in, false); 373 1.1 christos /* 374 1.1 christos * Check whether result is as expected. 375 1.1 christos */ 376 1.1 christos if (text_ok->text_out != NULL) { 377 1.1 christos if (debug && result != ISC_R_SUCCESS) { 378 1.1 christos fprintf(stdout, "# '%s'\n", text_ok->text_in); 379 1.1 christos fprintf(stdout, "# result=%s\n", 380 1.1 christos isc_result_totext(result)); 381 1.1 christos } 382 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 383 1.1 christos } else { 384 1.1 christos if (debug && result == ISC_R_SUCCESS) { 385 1.1 christos fprintf(stdout, "#'%s'\n", text_ok->text_in); 386 1.1 christos } 387 1.1 christos assert_int_not_equal(result, ISC_R_SUCCESS); 388 1.1 christos } 389 1.1 christos 390 1.1 christos /* 391 1.1 christos * If text form RDATA was not parsed correctly, performing any 392 1.1 christos * additional checks is pointless. 393 1.1 christos */ 394 1.1 christos if (result != ISC_R_SUCCESS) { 395 1.1 christos return; 396 1.1 christos } 397 1.1 christos 398 1.1 christos /* 399 1.1 christos * Try converting uncompressed wire form RDATA back into text form and 400 1.1 christos * check whether the resulting text is the same as the original one. 401 1.1 christos */ 402 1.1 christos isc_buffer_init(&target, buf_totext, sizeof(buf_totext)); 403 1.1 christos result = dns_rdata_totext(&rdata, NULL, &target); 404 1.1 christos detect_uncleared_libcrypto_error(); 405 1.1 christos if (result != ISC_R_SUCCESS && debug) { 406 1.1 christos size_t i; 407 1.1 christos fprintf(stdout, "# dns_rdata_totext -> %s", 408 1.1 christos isc_result_totext(result)); 409 1.1 christos for (i = 0; i < rdata.length; i++) { 410 1.1 christos if ((i % 16) == 0) { 411 1.1 christos fprintf(stdout, "\n#"); 412 1.1 christos } 413 1.1 christos fprintf(stdout, " %02x", rdata.data[i]); 414 1.1 christos } 415 1.1 christos fprintf(stdout, "\n"); 416 1.1 christos } 417 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 418 1.1 christos /* 419 1.1 christos * Ensure buf_totext is properly NUL terminated as dns_rdata_totext() 420 1.1 christos * may attempt different output formats writing into the apparently 421 1.1 christos * unused part of the buffer. 422 1.1 christos */ 423 1.1 christos isc_buffer_putuint8(&target, 0); 424 1.1 christos if (debug && strcmp(buf_totext, text_ok->text_out) != 0) { 425 1.1 christos fprintf(stdout, "# '%s' != '%s'\n", buf_totext, 426 1.1 christos text_ok->text_out); 427 1.1 christos } 428 1.1 christos assert_string_equal(buf_totext, text_ok->text_out); 429 1.1 christos 430 1.1 christos if (debug) { 431 1.1 christos fprintf(stdout, "#dns_rdata_totext -> '%s'\n", buf_totext); 432 1.1 christos } 433 1.1 christos 434 1.1 christos /* 435 1.1 christos * Ensure that fromtext_*() output is valid input for fromwire_*(). 436 1.1 christos */ 437 1.1 christos result = wire_to_rdata(rdata.data, rdata.length, rdclass, type, 438 1.1 christos buf_fromwire, sizeof(buf_fromwire), &rdata2); 439 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 440 1.1 christos assert_int_equal(rdata.length, rdata2.length); 441 1.1 christos assert_memory_equal(rdata.data, buf_fromwire, rdata.length); 442 1.1 christos 443 1.1 christos /* 444 1.1 christos * Ensure that fromtext_*() output is valid input for towire_*(). 445 1.1 christos */ 446 1.1 christos result = rdata_towire(&rdata, buf_towire, sizeof(buf_towire), &length); 447 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 448 1.1 christos assert_int_equal(rdata.length, length); 449 1.1 christos assert_memory_equal(rdata.data, buf_towire, length); 450 1.1 christos 451 1.1 christos /* 452 1.1 christos * Test that additionaldata_*() succeeded. 453 1.1 christos */ 454 1.1 christos result = rdata_additionadata(&rdata); 455 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 456 1.1 christos 457 1.1 christos /* 458 1.1 christos * Exercise checknames_*(). 459 1.1 christos */ 460 1.1 christos rdata_checknames(&rdata); 461 1.1 christos 462 1.1 christos /* 463 1.1 christos * Perform two-way conversion checks between uncompressed wire form and 464 1.1 christos * type-specific struct. 465 1.1 christos */ 466 1.1 christos check_struct_conversions(&rdata, structsize, text_ok->loop); 467 1.1 christos } 468 1.1 christos 469 1.1 christos /* 470 1.1 christos * Test whether converting rdata to text form and then parsing the result of 471 1.1 christos * that conversion again results in the same uncompressed wire form. This 472 1.1 christos * checks whether totext_*() output is parsable by fromtext_*() for given RR 473 1.1 christos * class and type. 474 1.1 christos * 475 1.1 christos * This function is called for every input RDATA which is successfully parsed 476 1.1 christos * by check_wire_ok_single() and whose type is not a meta-type. 477 1.1 christos */ 478 1.1 christos static void 479 1.1 christos check_text_conversions(dns_rdata_t *rdata) { 480 1.1 christos char buf_totext[1024] = { 0 }; 481 1.1 christos unsigned char buf_fromtext[1024]; 482 1.1 christos isc_result_t result; 483 1.1 christos isc_buffer_t target; 484 1.1 christos dns_rdata_t rdata2 = DNS_RDATA_INIT; 485 1.1 christos 486 1.1 christos /* 487 1.1 christos * Convert uncompressed wire form RDATA into text form. This 488 1.1 christos * conversion must succeed since input RDATA was successfully 489 1.1 christos * parsed by check_wire_ok_single(). 490 1.1 christos */ 491 1.1 christos isc_buffer_init(&target, buf_totext, sizeof(buf_totext)); 492 1.1 christos result = dns_rdata_totext(rdata, NULL, &target); 493 1.1 christos detect_uncleared_libcrypto_error(); 494 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 495 1.1 christos /* 496 1.1 christos * Ensure buf_totext is properly NUL terminated as dns_rdata_totext() 497 1.1 christos * may attempt different output formats writing into the apparently 498 1.1 christos * unused part of the buffer. 499 1.1 christos */ 500 1.1 christos isc_buffer_putuint8(&target, 0); 501 1.1 christos if (debug) { 502 1.1 christos fprintf(stdout, "#'%s'\n", buf_totext); 503 1.1 christos } 504 1.1 christos 505 1.1 christos /* 506 1.1 christos * Try parsing text form RDATA output by dns_rdata_totext() again. 507 1.1 christos */ 508 1.1 christos result = dns_test_rdatafromstring(&rdata2, rdata->rdclass, rdata->type, 509 1.1 christos buf_fromtext, sizeof(buf_fromtext), 510 1.1 christos buf_totext, false); 511 1.1 christos if (debug && result != ISC_R_SUCCESS) { 512 1.1 christos fprintf(stdout, "# result = %s\n", isc_result_totext(result)); 513 1.1 christos fprintf(stdout, "# '%s'\n", buf_fromtext); 514 1.1 christos } 515 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 516 1.1 christos assert_int_equal(rdata2.length, rdata->length); 517 1.1 christos assert_memory_equal(buf_fromtext, rdata->data, rdata->length); 518 1.1 christos } 519 1.1 christos 520 1.1 christos /* 521 1.1 christos * Test whether converting rdata to multi-line text form and then parsing the 522 1.1 christos * result of that conversion again results in the same uncompressed wire form. 523 1.1 christos * This checks whether multi-line totext_*() output is parsable by fromtext_*() 524 1.1 christos * for given RR class and type. 525 1.1 christos * 526 1.1 christos * This function is called for every input RDATA which is successfully parsed 527 1.1 christos * by check_wire_ok_single() and whose type is not a meta-type. 528 1.1 christos */ 529 1.1 christos static void 530 1.1 christos check_multiline_text_conversions(dns_rdata_t *rdata) { 531 1.1 christos char buf_totext[1024] = { 0 }; 532 1.1 christos unsigned char buf_fromtext[1024]; 533 1.1 christos isc_result_t result; 534 1.1 christos isc_buffer_t target; 535 1.1 christos dns_rdata_t rdata2 = DNS_RDATA_INIT; 536 1.1 christos unsigned int flags; 537 1.1 christos 538 1.1 christos /* 539 1.1 christos * Convert uncompressed wire form RDATA into multi-line text form. 540 1.1 christos * This conversion must succeed since input RDATA was successfully 541 1.1 christos * parsed by check_wire_ok_single(). 542 1.1 christos */ 543 1.1 christos isc_buffer_init(&target, buf_totext, sizeof(buf_totext)); 544 1.1 christos flags = dns_master_styleflags(&dns_master_style_default); 545 1.1 christos result = dns_rdata_tofmttext(rdata, dns_rootname, flags, 80 - 32, 4, 546 1.1 christos "\n", &target); 547 1.1 christos detect_uncleared_libcrypto_error(); 548 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 549 1.1 christos /* 550 1.1 christos * Ensure buf_totext is properly NUL terminated as 551 1.1 christos * dns_rdata_tofmttext() may attempt different output formats 552 1.1 christos * writing into the apparently unused part of the buffer. 553 1.1 christos */ 554 1.1 christos isc_buffer_putuint8(&target, 0); 555 1.1 christos if (debug) { 556 1.1 christos fprintf(stdout, "#'%s'\n", buf_totext); 557 1.1 christos } 558 1.1 christos 559 1.1 christos /* 560 1.1 christos * Try parsing multi-line text form RDATA output by 561 1.1 christos * dns_rdata_tofmttext() again. 562 1.1 christos */ 563 1.1 christos result = dns_test_rdatafromstring(&rdata2, rdata->rdclass, rdata->type, 564 1.1 christos buf_fromtext, sizeof(buf_fromtext), 565 1.1 christos buf_totext, false); 566 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 567 1.1 christos assert_int_equal(rdata2.length, rdata->length); 568 1.1 christos assert_memory_equal(buf_fromtext, rdata->data, rdata->length); 569 1.1 christos } 570 1.1 christos 571 1.1 christos /* 572 1.1 christos * Test whether supplied wire form RDATA is properly handled as being either 573 1.1 christos * valid or invalid for an RR of given rdclass and type. 574 1.1 christos */ 575 1.1 christos static void 576 1.1 christos check_wire_ok_single(const wire_ok_t *wire_ok, dns_rdataclass_t rdclass, 577 1.1 christos dns_rdatatype_t type, size_t structsize) { 578 1.1 christos unsigned char buf[1024], buf_towire[1024]; 579 1.1 christos isc_result_t result; 580 1.1 christos dns_rdata_t rdata = DNS_RDATA_INIT; 581 1.1 christos size_t length = 0; 582 1.1 christos 583 1.1 christos /* 584 1.1 christos * Try converting wire data into uncompressed wire form. 585 1.1 christos */ 586 1.1 christos result = wire_to_rdata(wire_ok->data, wire_ok->len, rdclass, type, buf, 587 1.1 christos sizeof(buf), &rdata); 588 1.1 christos /* 589 1.1 christos * Check whether result is as expected. 590 1.1 christos */ 591 1.1 christos if (wire_ok->ok) { 592 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 593 1.1 christos } else { 594 1.1 christos assert_int_not_equal(result, ISC_R_SUCCESS); 595 1.1 christos } 596 1.1 christos 597 1.1 christos if (result != ISC_R_SUCCESS) { 598 1.1 christos return; 599 1.1 christos } 600 1.1 christos 601 1.1 christos /* 602 1.1 christos * If data was parsed correctly, perform two-way conversion checks 603 1.1 christos * between uncompressed wire form and type-specific struct. 604 1.1 christos * 605 1.1 christos * If the RR type is not a meta-type, additionally perform two-way 606 1.1 christos * conversion checks between: 607 1.1 christos * 608 1.1 christos * - uncompressed wire form and text form, 609 1.1 christos * - uncompressed wire form and multi-line text form. 610 1.1 christos */ 611 1.1 christos check_struct_conversions(&rdata, structsize, wire_ok->loop); 612 1.1 christos if (!dns_rdatatype_ismeta(rdata.type)) { 613 1.1 christos check_text_conversions(&rdata); 614 1.1 christos check_multiline_text_conversions(&rdata); 615 1.1 christos } 616 1.1 christos 617 1.1 christos /* 618 1.1 christos * Ensure that fromwire_*() output is valid input for towire_*(). 619 1.1 christos */ 620 1.1 christos result = rdata_towire(&rdata, buf_towire, sizeof(buf_towire), &length); 621 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 622 1.1 christos assert_int_equal(rdata.length, length); 623 1.1 christos assert_memory_equal(rdata.data, buf_towire, length); 624 1.1 christos 625 1.1 christos /* 626 1.1 christos * Test that additionaldata_*() succeeded. 627 1.1 christos */ 628 1.1 christos result = rdata_additionadata(&rdata); 629 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 630 1.1 christos 631 1.1 christos /* 632 1.1 christos * Exercise checknames_*(). 633 1.1 christos */ 634 1.1 christos rdata_checknames(&rdata); 635 1.1 christos } 636 1.1 christos 637 1.1 christos /* 638 1.1 christos * Test fromtext_*() and totext_*() routines for given RR class and type for 639 1.1 christos * each text form RDATA in the supplied array. See the comment for 640 1.1 christos * check_text_ok_single() for an explanation of how exactly these routines are 641 1.1 christos * tested. 642 1.1 christos */ 643 1.1 christos static void 644 1.1 christos check_text_ok(const text_ok_t *text_ok, dns_rdataclass_t rdclass, 645 1.1 christos dns_rdatatype_t type, size_t structsize) { 646 1.1 christos size_t i; 647 1.1 christos 648 1.1 christos /* 649 1.1 christos * Check all entries in the supplied array. 650 1.1 christos */ 651 1.1 christos for (i = 0; text_ok[i].text_in != NULL; i++) { 652 1.1 christos check_text_ok_single(&text_ok[i], rdclass, type, structsize); 653 1.1 christos } 654 1.1 christos } 655 1.1 christos 656 1.1 christos /* 657 1.1 christos * For each wire form RDATA in the supplied array, check whether it is properly 658 1.1 christos * handled as being either valid or invalid for an RR of given rdclass and 659 1.1 christos * type, then check whether trying to process a zero-length wire data buffer 660 1.1 christos * yields the expected result. This checks whether the fromwire_*() routine 661 1.1 christos * for given RR class and type behaves as expected. 662 1.1 christos */ 663 1.1 christos static void 664 1.1 christos check_wire_ok(const wire_ok_t *wire_ok, bool empty_ok, dns_rdataclass_t rdclass, 665 1.1 christos dns_rdatatype_t type, size_t structsize) { 666 1.1 christos wire_ok_t empty_wire = WIRE_TEST(empty_ok, 0); 667 1.1 christos size_t i; 668 1.1 christos 669 1.1 christos /* 670 1.1 christos * Check all entries in the supplied array. 671 1.1 christos */ 672 1.1 christos for (i = 0; wire_ok[i].len != 0; i++) { 673 1.1 christos if (debug) { 674 1.1 christos fprintf(stderr, "calling check_wire_ok_single on %zu\n", 675 1.1 christos i); 676 1.1 christos } 677 1.1 christos check_wire_ok_single(&wire_ok[i], rdclass, type, structsize); 678 1.1 christos } 679 1.1 christos 680 1.1 christos /* 681 1.1 christos * Check empty wire data. 682 1.1 christos */ 683 1.1 christos check_wire_ok_single(&empty_wire, rdclass, type, structsize); 684 1.1 christos } 685 1.1 christos 686 1.1 christos /* 687 1.1 christos * Check that two records compare as expected with dns_rdata_compare(). 688 1.1 christos */ 689 1.1 christos static void 690 1.1 christos check_compare_ok_single(const compare_ok_t *compare_ok, 691 1.1 christos dns_rdataclass_t rdclass, dns_rdatatype_t type) { 692 1.1 christos dns_rdata_t rdata1 = DNS_RDATA_INIT, rdata2 = DNS_RDATA_INIT; 693 1.1 christos unsigned char buf1[1024], buf2[1024]; 694 1.1 christos isc_result_t result; 695 1.1 christos int answer; 696 1.1 christos 697 1.1 christos result = dns_test_rdatafromstring(&rdata1, rdclass, type, buf1, 698 1.1 christos sizeof(buf1), compare_ok->text1, 699 1.1 christos false); 700 1.1 christos if (result != ISC_R_SUCCESS) { 701 1.1 christos fail_msg("# line %d: '%s': expected success, got failure", 702 1.1 christos compare_ok->lineno, compare_ok->text1); 703 1.1 christos } 704 1.1 christos 705 1.1 christos result = dns_test_rdatafromstring(&rdata2, rdclass, type, buf2, 706 1.1 christos sizeof(buf2), compare_ok->text2, 707 1.1 christos false); 708 1.1 christos 709 1.1 christos if (result != ISC_R_SUCCESS) { 710 1.1 christos fail_msg("# line %d: '%s': expected success, got failure", 711 1.1 christos compare_ok->lineno, compare_ok->text2); 712 1.1 christos } 713 1.1 christos 714 1.1 christos answer = dns_rdata_compare(&rdata1, &rdata2); 715 1.1 christos detect_uncleared_libcrypto_error(); 716 1.1 christos if (compare_ok->answer == 0 && answer != 0) { 717 1.1 christos fail_msg("# line %d: dns_rdata_compare('%s', '%s'): " 718 1.1 christos "expected equal, got %s", 719 1.1 christos compare_ok->lineno, compare_ok->text1, 720 1.1 christos compare_ok->text2, 721 1.1 christos (answer > 0) ? "greater than" : "less than"); 722 1.1 christos } 723 1.1 christos if (compare_ok->answer < 0 && answer >= 0) { 724 1.1 christos fail_msg("# line %d: dns_rdata_compare('%s', '%s'): " 725 1.1 christos "expected less than, got %s", 726 1.1 christos compare_ok->lineno, compare_ok->text1, 727 1.1 christos compare_ok->text2, 728 1.1 christos (answer == 0) ? "equal" : "greater than"); 729 1.1 christos } 730 1.1 christos if (compare_ok->answer > 0 && answer <= 0) { 731 1.1 christos fail_msg("line %d: dns_rdata_compare('%s', '%s'): " 732 1.1 christos "expected greater than, got %s", 733 1.1 christos compare_ok->lineno, compare_ok->text1, 734 1.1 christos compare_ok->text2, 735 1.1 christos (answer == 0) ? "equal" : "less than"); 736 1.1 christos } 737 1.1 christos } 738 1.1 christos 739 1.1 christos /* 740 1.1 christos * Check that all the records sets in compare_ok compare as expected 741 1.1 christos * with dns_rdata_compare(). 742 1.1 christos */ 743 1.1 christos static void 744 1.1 christos check_compare_ok(const compare_ok_t *compare_ok, dns_rdataclass_t rdclass, 745 1.1 christos dns_rdatatype_t type) { 746 1.1 christos size_t i; 747 1.1 christos /* 748 1.1 christos * Check all entries in the supplied array. 749 1.1 christos */ 750 1.1 christos for (i = 0; compare_ok[i].text1 != NULL; i++) { 751 1.1 christos check_compare_ok_single(&compare_ok[i], rdclass, type); 752 1.1 christos } 753 1.1 christos } 754 1.1 christos 755 1.1 christos /* 756 1.1 christos * Test whether supplied sets of text form and/or wire form RDATA are handled 757 1.1 christos * as expected. 758 1.1 christos * 759 1.1 christos * The empty_ok argument denotes whether an attempt to parse a zero-length wire 760 1.1 christos * data buffer should succeed or not (it is valid for some RR types). There is 761 1.1 christos * no point in performing a similar check for empty text form RDATA, because 762 1.1 christos * dns_rdata_fromtext() returns ISC_R_UNEXPECTEDEND before calling fromtext_*() 763 1.1 christos * for the given RR class and type. 764 1.1 christos */ 765 1.1 christos static void 766 1.1 christos check_rdata(const text_ok_t *text_ok, const wire_ok_t *wire_ok, 767 1.1 christos const compare_ok_t *compare_ok, bool empty_ok, 768 1.1 christos dns_rdataclass_t rdclass, dns_rdatatype_t type, size_t structsize) { 769 1.1 christos if (text_ok != NULL) { 770 1.1 christos check_text_ok(text_ok, rdclass, type, structsize); 771 1.1 christos } 772 1.1 christos if (wire_ok != NULL) { 773 1.1 christos check_wire_ok(wire_ok, empty_ok, rdclass, type, structsize); 774 1.1 christos } 775 1.1 christos if (compare_ok != NULL) { 776 1.1 christos check_compare_ok(compare_ok, rdclass, type); 777 1.1 christos } 778 1.1 christos } 779 1.1 christos 780 1.1 christos /* 781 1.1 christos * Check presentation vs unknown format of the record. 782 1.1 christos */ 783 1.1 christos static void 784 1.1 christos check_textvsunknown_single(const textvsunknown_t *textvsunknown, 785 1.1 christos dns_rdataclass_t rdclass, dns_rdatatype_t type) { 786 1.1 christos dns_rdata_t rdata1 = DNS_RDATA_INIT, rdata2 = DNS_RDATA_INIT; 787 1.1 christos unsigned char buf1[1024], buf2[1024]; 788 1.1 christos isc_result_t result; 789 1.1 christos 790 1.1 christos result = dns_test_rdatafromstring(&rdata1, rdclass, type, buf1, 791 1.1 christos sizeof(buf1), textvsunknown->text1, 792 1.1 christos false); 793 1.1 christos if (debug && result != ISC_R_SUCCESS) { 794 1.1 christos fprintf(stdout, "# '%s'\n", textvsunknown->text1); 795 1.1 christos fprintf(stdout, "# result=%s\n", isc_result_totext(result)); 796 1.1 christos } 797 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 798 1.1 christos result = dns_test_rdatafromstring(&rdata2, rdclass, type, buf2, 799 1.1 christos sizeof(buf2), textvsunknown->text2, 800 1.1 christos false); 801 1.1 christos if (debug && result != ISC_R_SUCCESS) { 802 1.1 christos fprintf(stdout, "# '%s'\n", textvsunknown->text2); 803 1.1 christos fprintf(stdout, "# result=%s\n", isc_result_totext(result)); 804 1.1 christos } 805 1.1 christos assert_int_equal(result, ISC_R_SUCCESS); 806 1.1 christos if (debug && rdata1.length != rdata2.length) { 807 1.1 christos fprintf(stdout, "# '%s'\n", textvsunknown->text1); 808 1.1 christos fprintf(stdout, "# rdata1.length (%u) != rdata2.length (%u)\n", 809 1.1 christos rdata1.length, rdata2.length); 810 1.1 christos } 811 1.1 christos assert_int_equal(rdata1.length, rdata2.length); 812 1.1 christos if (debug && memcmp(rdata1.data, rdata2.data, rdata1.length) != 0) { 813 1.1 christos unsigned int i; 814 1.1 christos fprintf(stdout, "# '%s'\n", textvsunknown->text1); 815 1.1 christos for (i = 0; i < rdata1.length; i++) { 816 1.1 christos if (rdata1.data[i] != rdata2.data[i]) { 817 1.1 christos fprintf(stderr, "# %u: %02x != %02x\n", i, 818 1.1 christos rdata1.data[i], rdata2.data[i]); 819 1.1 christos } 820 1.1 christos } 821 1.1 christos } 822 1.1 christos assert_memory_equal(rdata1.data, rdata2.data, rdata1.length); 823 1.1 christos } 824 1.1 christos 825 1.1 christos static void 826 1.1 christos check_textvsunknown(const textvsunknown_t *textvsunknown, 827 1.1 christos dns_rdataclass_t rdclass, dns_rdatatype_t type) { 828 1.1 christos size_t i; 829 1.1 christos 830 1.1 christos /* 831 1.1 christos * Check all entries in the supplied array. 832 1.1 christos */ 833 1.1 christos for (i = 0; textvsunknown[i].text1 != NULL; i++) { 834 1.1 christos check_textvsunknown_single(&textvsunknown[i], rdclass, type); 835 1.1 christos } 836 1.1 christos } 837 1.1 christos 838 1.1 christos /* 839 1.1 christos * Common tests for RR types based on KEY that require key data: 840 1.1 christos * 841 1.1 christos * - CDNSKEY (RFC 7344) 842 1.1 christos * - DNSKEY (RFC 4034) 843 1.1 christos * - RKEY (draft-reid-dnsext-rkey-00) 844 1.1 christos */ 845 1.1 christos static void 846 1.1 christos key_required(void **state, dns_rdatatype_t type, size_t size) { 847 1.1 christos wire_ok_t wire_ok[] = { /* 848 1.1 christos * RDATA must be at least 5 octets in size: 849 1.1 christos * 850 1.1 christos * - 2 octets for Flags, 851 1.1 christos * - 1 octet for Protocol, 852 1.1 christos * - 1 octet for Algorithm, 853 1.1 christos * - Public Key must not be empty. 854 1.1 christos * 855 1.1 christos * RFC 2535 section 3.1.2 allows the Public Key 856 1.1 christos * to be empty if bits 0-1 of Flags are both 857 1.1 christos * set, but that only applies to KEY records: 858 1.1 christos * for the RR types tested here, the Public Key 859 1.1 christos * must not be empty. 860 1.1 christos */ 861 1.1 christos WIRE_INVALID(0x00), 862 1.1 christos WIRE_INVALID(0x00, 0x00), 863 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00), 864 1.1 christos WIRE_INVALID(0xc0, 0x00, 0x00, 0x00), 865 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00), 866 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00), 867 1.1 christos WIRE_SENTINEL() 868 1.1 christos }; 869 1.1 christos 870 1.1 christos UNUSED(state); 871 1.1 christos 872 1.1 christos check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in, type, size); 873 1.1 christos } 874 1.1 christos 875 1.1 christos /* APL RDATA manipulations */ 876 1.1 christos ISC_RUN_TEST_IMPL(apl) { 877 1.1 christos text_ok_t text_ok[] = { 878 1.1 christos /* empty list */ 879 1.1 christos TEXT_VALID(""), 880 1.1 christos /* min,max prefix IPv4 */ 881 1.1 christos TEXT_VALID("1:0.0.0.0/0"), TEXT_VALID("1:127.0.0.1/32"), 882 1.1 christos /* min,max prefix IPv6 */ 883 1.1 christos TEXT_VALID("2:::/0"), TEXT_VALID("2:::1/128"), 884 1.1 christos /* negated */ 885 1.1 christos TEXT_VALID("!1:0.0.0.0/0"), TEXT_VALID("!1:127.0.0.1/32"), 886 1.1 christos TEXT_VALID("!2:::/0"), TEXT_VALID("!2:::1/128"), 887 1.1 christos /* bits set after prefix length - not disallowed */ 888 1.1 christos TEXT_VALID("1:127.0.0.0/0"), TEXT_VALID("2:8000::/0"), 889 1.1 christos /* multiple */ 890 1.1 christos TEXT_VALID("1:0.0.0.0/0 1:127.0.0.1/32"), 891 1.1 christos TEXT_VALID("1:0.0.0.0/0 !1:127.0.0.1/32"), 892 1.1 christos /* family 0, prefix 0, positive */ 893 1.1 christos TEXT_VALID("\\# 4 00000000"), 894 1.1 christos /* family 0, prefix 0, negative */ 895 1.1 christos TEXT_VALID("\\# 4 00000080"), 896 1.1 christos /* prefix too long */ 897 1.1 christos TEXT_INVALID("1:0.0.0.0/33"), TEXT_INVALID("2:::/129"), 898 1.1 christos /* 899 1.1 christos * Sentinel. 900 1.1 christos */ 901 1.1 christos TEXT_SENTINEL() 902 1.1 christos }; 903 1.1 christos wire_ok_t wire_ok[] = { /* zero length */ 904 1.1 christos WIRE_VALID(), 905 1.1 christos /* prefix too big IPv4 */ 906 1.1 christos WIRE_INVALID(0x00, 0x01, 33U, 0x00), 907 1.1 christos /* prefix too big IPv6 */ 908 1.1 christos WIRE_INVALID(0x00, 0x02, 129U, 0x00), 909 1.1 christos /* trailing zero octet in afdpart */ 910 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x01, 0x00), 911 1.1 christos /* 912 1.1 christos * Sentinel. 913 1.1 christos */ 914 1.1 christos WIRE_SENTINEL() 915 1.1 christos }; 916 1.1 christos 917 1.1 christos check_rdata(text_ok, wire_ok, NULL, true, dns_rdataclass_in, 918 1.1 christos dns_rdatatype_apl, sizeof(dns_rdata_in_apl_t)); 919 1.1 christos } 920 1.1 christos 921 1.1 christos /* 922 1.1 christos * http://broadband-forum.org/ftp/pub/approved-specs/af-saa-0069.000.pdf 923 1.1 christos * 924 1.1 christos * ATMA RRs have the following RDATA format: 925 1.1 christos * 926 1.1 christos * 1 1 1 1 1 1 927 1.1 christos * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 928 1.1 christos * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 929 1.1 christos * | FORMAT | | 930 1.1 christos * +--+--+--+--+--+--+--+--+ | 931 1.1 christos * / ADDRESS / 932 1.1 christos * | | 933 1.1 christos * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 934 1.1 christos * 935 1.1 christos * The fields have the following meaning: 936 1.1 christos * 937 1.1 christos * * FORMAT: One octet that indicates the format of ADDRESS. The two 938 1.1 christos * possible values for FORMAT are value 0 indicating ATM End System Address 939 1.1 christos * (AESA) format and value 1 indicating E.164 format. 940 1.1 christos * 941 1.1 christos * * ADDRESS: Variable length string of octets containing the ATM address of 942 1.1 christos * the node to which this RR pertains. 943 1.1 christos * 944 1.1 christos * When the format value is 0, indicating that the address is in AESA format, 945 1.1 christos * the address is coded as described in ISO 8348/AD 2 using the preferred 946 1.1 christos * binary encoding of the ISO NSAP format. When the format value is 1, 947 1.1 christos * indicating that the address is in E.164 format, the Address/Number Digits 948 1.1 christos * appear in the order in which they would be entered on a numeric keypad. 949 1.1 christos * Digits are coded in IA5 characters with the leftmost bit of each digit set 950 1.1 christos * to 0. This ATM address appears in ATM End System Address Octets field (AESA 951 1.1 christos * format) or the Address/Number Digits field (E.164 format) of the Called 952 1.1 christos * party number information element [ATMUNI3.1]. Subaddress information is 953 1.1 christos * intentionally not included because E.164 subaddress information is used for 954 1.1 christos * routing. 955 1.1 christos * 956 1.1 christos * ATMA RRs cause no additional section processing. 957 1.1 christos */ 958 1.1 christos ISC_RUN_TEST_IMPL(atma) { 959 1.1 christos text_ok_t text_ok[] = { TEXT_VALID("00"), 960 1.1 christos TEXT_VALID_CHANGED("0.0", "00"), 961 1.1 christos /* 962 1.1 christos * multiple consecutive periods 963 1.1 christos */ 964 1.1 christos TEXT_INVALID("0..0"), 965 1.1 christos /* 966 1.1 christos * trailing period 967 1.1 christos */ 968 1.1 christos TEXT_INVALID("00."), 969 1.1 christos /* 970 1.1 christos * leading period 971 1.1 christos */ 972 1.1 christos TEXT_INVALID(".00"), 973 1.1 christos /* 974 1.1 christos * Not full octets. 975 1.1 christos */ 976 1.1 christos TEXT_INVALID("000"), 977 1.1 christos /* 978 1.1 christos * E.164 979 1.1 christos */ 980 1.1 christos TEXT_VALID("+61200000000"), 981 1.1 christos /* 982 1.1 christos * E.164 with periods 983 1.1 christos */ 984 1.1 christos TEXT_VALID_CHANGED("+61.2.0000.0000", "+6120000" 985 1.1 christos "0000"), 986 1.1 christos /* 987 1.1 christos * E.164 with period at end 988 1.1 christos */ 989 1.1 christos TEXT_INVALID("+61200000000."), 990 1.1 christos /* 991 1.1 christos * E.164 with multiple consecutive periods 992 1.1 christos */ 993 1.1 christos TEXT_INVALID("+612..00000000"), 994 1.1 christos /* 995 1.1 christos * E.164 with period before the leading digit. 996 1.1 christos */ 997 1.1 christos TEXT_INVALID("+.61200000000"), 998 1.1 christos /* 999 1.1 christos * Sentinel. 1000 1.1 christos */ 1001 1.1 christos TEXT_SENTINEL() }; 1002 1.1 christos wire_ok_t wire_ok[] = { 1003 1.1 christos /* 1004 1.1 christos * Too short. 1005 1.1 christos */ 1006 1.1 christos WIRE_INVALID(0x00), WIRE_INVALID(0x01), 1007 1.1 christos /* 1008 1.1 christos * all digits 1009 1.1 christos */ 1010 1.1 christos WIRE_VALID(0x01, '6', '1', '2', '0', '0', '0'), 1011 1.1 christos /* 1012 1.1 christos * non digit 1013 1.1 christos */ 1014 1.1 christos WIRE_INVALID(0x01, '+', '6', '1', '2', '0', '0', '0'), 1015 1.1 christos /* 1016 1.1 christos * Sentinel. 1017 1.1 christos */ 1018 1.1 christos WIRE_SENTINEL() 1019 1.1 christos }; 1020 1.1 christos 1021 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 1022 1.1 christos dns_rdatatype_atma, sizeof(dns_rdata_in_atma_t)); 1023 1.1 christos } 1024 1.1 christos 1025 1.1 christos /* AMTRELAY RDATA manipulations */ 1026 1.1 christos ISC_RUN_TEST_IMPL(amtrelay) { 1027 1.1 christos text_ok_t text_ok[] = { 1028 1.1 christos TEXT_INVALID(""), TEXT_INVALID("0"), TEXT_INVALID("0 0"), 1029 1.6 christos TEXT_INVALID("0 0 0"), 1030 1.1 christos /* gateway type 0 */ 1031 1.6 christos TEXT_INVALID("0 0 0 x"), /* bad placeholder */ 1032 1.6 christos TEXT_VALID("0 0 0 ."), TEXT_VALID("0 1 0 ."), 1033 1.6 christos TEXT_INVALID("0 2 0 ."), /* discovery out of range */ 1034 1.6 christos TEXT_VALID("255 1 0 ."), /* max precedence */ 1035 1.6 christos TEXT_INVALID("256 1 0 ."), /* precedence out of range */ 1036 1.1 christos 1037 1.1 christos /* IPv4 gateway */ 1038 1.1 christos TEXT_INVALID("0 0 1"), /* no address */ 1039 1.1 christos TEXT_VALID("0 0 1 0.0.0.0"), 1040 1.1 christos TEXT_INVALID("0 0 1 0.0.0.0 x"), /* extra */ 1041 1.1 christos TEXT_INVALID("0 0 1 0.0.0.0.0"), /* bad address */ 1042 1.1 christos TEXT_INVALID("0 0 1 ::"), /* bad address */ 1043 1.1 christos TEXT_INVALID("0 0 1 ."), /* bad address */ 1044 1.1 christos 1045 1.1 christos /* IPv6 gateway */ 1046 1.1 christos TEXT_INVALID("0 0 2"), /* no address */ 1047 1.1 christos TEXT_VALID("0 0 2 ::"), TEXT_INVALID("0 0 2 :: xx"), /* extra */ 1048 1.1 christos TEXT_INVALID("0 0 2 0.0.0.0"), /* bad address */ 1049 1.1 christos TEXT_INVALID("0 0 2 ."), /* bad address */ 1050 1.1 christos 1051 1.1 christos /* hostname gateway */ 1052 1.1 christos TEXT_INVALID("0 0 3"), /* no name */ 1053 1.1 christos /* IPv4 is a valid name */ 1054 1.1 christos TEXT_VALID_CHANGED("0 0 3 0.0.0.0", "0 0 3 0.0.0.0."), 1055 1.1 christos /* IPv6 is a valid name */ 1056 1.1 christos TEXT_VALID_CHANGED("0 0 3 ::", "0 0 3 ::."), 1057 1.1 christos TEXT_VALID_CHANGED("0 0 3 example", "0 0 3 example."), 1058 1.1 christos TEXT_VALID("0 0 3 example."), 1059 1.1 christos TEXT_INVALID("0 0 3 example. x"), /* extra */ 1060 1.1 christos 1061 1.1 christos /* unknown gateway */ 1062 1.1 christos TEXT_VALID("\\# 2 0004"), TEXT_VALID("\\# 2 0084"), 1063 1.1 christos TEXT_VALID("\\# 2 007F"), TEXT_VALID("\\# 3 000400"), 1064 1.1 christos TEXT_VALID("\\# 3 008400"), TEXT_VALID("\\# 3 00FF00"), 1065 1.1 christos 1066 1.1 christos /* 1067 1.1 christos * Sentinel. 1068 1.1 christos */ 1069 1.1 christos TEXT_SENTINEL() 1070 1.1 christos }; 1071 1.1 christos wire_ok_t wire_ok[] = { 1072 1.1 christos WIRE_INVALID(0x00), WIRE_VALID(0x00, 0x00), 1073 1.1 christos WIRE_VALID(0x00, 0x80), WIRE_INVALID(0x00, 0x00, 0x00), 1074 1.1 christos WIRE_INVALID(0x00, 0x80, 0x00), 1075 1.1 christos 1076 1.1 christos WIRE_INVALID(0x00, 0x01), WIRE_INVALID(0x00, 0x01, 0x00), 1077 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x00), 1078 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x00), 1079 1.1 christos WIRE_VALID(0x00, 0x01, 0x00, 0x00, 0x00, 0x00), 1080 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00), 1081 1.1 christos 1082 1.1 christos WIRE_INVALID(0x00, 0x02), WIRE_INVALID(0x00, 0x02, 0x00), 1083 1.1 christos WIRE_VALID(0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 1084 1.1 christos 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 1085 1.1 christos 0x15), 1086 1.1 christos WIRE_INVALID(0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 1087 1.1 christos 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 1088 1.1 christos 0x14, 0x15, 0x16), 1089 1.1 christos 1090 1.1 christos WIRE_INVALID(0x00, 0x03), WIRE_VALID(0x00, 0x03, 0x00), 1091 1.1 christos WIRE_INVALID(0x00, 0x03, 0x00, 0x00), /* extra */ 1092 1.1 christos 1093 1.1 christos WIRE_VALID(0x00, 0x04), WIRE_VALID(0x00, 0x04, 0x00), 1094 1.1 christos /* 1095 1.1 christos * Sentinel. 1096 1.1 christos */ 1097 1.1 christos WIRE_SENTINEL() 1098 1.1 christos }; 1099 1.1 christos 1100 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 1101 1.1 christos dns_rdatatype_amtrelay, sizeof(dns_rdata_amtrelay_t)); 1102 1.1 christos } 1103 1.1 christos 1104 1.6 christos /* BRIB RDATA - base64 encoded opaque */ 1105 1.6 christos ISC_RUN_TEST_IMPL(brib) { 1106 1.6 christos text_ok_t text_ok[] = { /* empty */ 1107 1.6 christos TEXT_INVALID(""), 1108 1.6 christos /* valid base64 string */ 1109 1.6 christos TEXT_VALID("aaaa"), 1110 1.6 christos /* invalid base64 string */ 1111 1.6 christos TEXT_INVALID("aaaaa"), 1112 1.6 christos /* 1113 1.6 christos * Sentinel. 1114 1.6 christos */ 1115 1.6 christos TEXT_SENTINEL() 1116 1.6 christos }; 1117 1.6 christos 1118 1.6 christos check_rdata(text_ok, NULL, NULL, true, dns_rdataclass_in, 1119 1.6 christos dns_rdatatype_brid, sizeof(dns_rdata_brid_t)); 1120 1.6 christos } 1121 1.6 christos 1122 1.1 christos ISC_RUN_TEST_IMPL(cdnskey) { 1123 1.1 christos key_required(state, dns_rdatatype_cdnskey, sizeof(dns_rdata_cdnskey_t)); 1124 1.1 christos } 1125 1.1 christos 1126 1.1 christos /* 1127 1.1 christos * CSYNC tests. 1128 1.1 christos * 1129 1.1 christos * RFC 7477: 1130 1.1 christos * 1131 1.1 christos * 2.1. The CSYNC Resource Record Format 1132 1.1 christos * 1133 1.1 christos * 2.1.1. The CSYNC Resource Record Wire Format 1134 1.1 christos * 1135 1.1 christos * The CSYNC RDATA consists of the following fields: 1136 1.1 christos * 1137 1.1 christos * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 1138 1.1 christos * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 1139 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1140 1.1 christos * | SOA Serial | 1141 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1142 1.1 christos * | Flags | Type Bit Map / 1143 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1144 1.1 christos * / Type Bit Map (continued) / 1145 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1146 1.1 christos * 1147 1.1 christos * 2.1.1.1. The SOA Serial Field 1148 1.1 christos * 1149 1.1 christos * The SOA Serial field contains a copy of the 32-bit SOA serial number 1150 1.1 christos * from the child zone. If the soaminimum flag is set, parental agents 1151 1.1 christos * querying children's authoritative servers MUST NOT act on data from 1152 1.1 christos * zones advertising an SOA serial number less than this value. See 1153 1.1 christos * [RFC1982] for properly implementing "less than" logic. If the 1154 1.1 christos * soaminimum flag is not set, parental agents MUST ignore the value in 1155 1.1 christos * the SOA Serial field. Clients can set the field to any value if the 1156 1.1 christos * soaminimum flag is unset, such as the number zero. 1157 1.1 christos * 1158 1.1 christos * (...) 1159 1.1 christos * 1160 1.1 christos * 2.1.1.2. The Flags Field 1161 1.1 christos * 1162 1.1 christos * The Flags field contains 16 bits of boolean flags that define 1163 1.1 christos * operations that affect the processing of the CSYNC record. The flags 1164 1.1 christos * defined in this document are as follows: 1165 1.1 christos * 1166 1.1 christos * 0x00 0x01: "immediate" 1167 1.1 christos * 1168 1.1 christos * 0x00 0x02: "soaminimum" 1169 1.1 christos * 1170 1.1 christos * The definitions for how the flags are to be used can be found in 1171 1.1 christos * Section 3. 1172 1.1 christos * 1173 1.1 christos * The remaining flags are reserved for use by future specifications. 1174 1.1 christos * Undefined flags MUST be set to 0 by CSYNC publishers. Parental 1175 1.1 christos * agents MUST NOT process a CSYNC record if it contains a 1 value for a 1176 1.1 christos * flag that is unknown to or unsupported by the parental agent. 1177 1.1 christos * 1178 1.1 christos * 2.1.1.2.1. The Type Bit Map Field 1179 1.1 christos * 1180 1.1 christos * The Type Bit Map field indicates the record types to be processed by 1181 1.1 christos * the parental agent, according to the procedures in Section 3. The 1182 1.1 christos * Type Bit Map field is encoded in the same way as the Type Bit Map 1183 1.1 christos * field of the NSEC record, described in [RFC4034], Section 4.1.2. If 1184 1.1 christos * a bit has been set that a parental agent implementation does not 1185 1.1 christos * understand, the parental agent MUST NOT act upon the record. 1186 1.1 christos * Specifically, a parental agent must not simply copy the data, and it 1187 1.1 christos * must understand the semantics associated with a bit in the Type Bit 1188 1.1 christos * Map field that has been set to 1. 1189 1.1 christos */ 1190 1.1 christos ISC_RUN_TEST_IMPL(csync) { 1191 1.1 christos text_ok_t text_ok[] = { TEXT_INVALID(""), 1192 1.1 christos TEXT_INVALID("0"), 1193 1.1 christos TEXT_VALID("0 0"), 1194 1.1 christos TEXT_VALID("0 0 A"), 1195 1.1 christos TEXT_VALID("0 0 NS"), 1196 1.1 christos TEXT_VALID("0 0 AAAA"), 1197 1.1 christos TEXT_VALID("0 0 A AAAA"), 1198 1.1 christos TEXT_VALID("0 0 A NS AAAA"), 1199 1.1 christos TEXT_INVALID("0 0 A NS AAAA BOGUS"), 1200 1.1 christos TEXT_SENTINEL() }; 1201 1.1 christos wire_ok_t wire_ok[] = { 1202 1.1 christos /* 1203 1.1 christos * Short. 1204 1.1 christos */ 1205 1.1 christos WIRE_INVALID(0x00), 1206 1.1 christos /* 1207 1.1 christos * Short. 1208 1.1 christos */ 1209 1.1 christos WIRE_INVALID(0x00, 0x00), 1210 1.1 christos /* 1211 1.1 christos * Short. 1212 1.1 christos */ 1213 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00), 1214 1.1 christos /* 1215 1.1 christos * Short. 1216 1.1 christos */ 1217 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00), 1218 1.1 christos /* 1219 1.1 christos * Short. 1220 1.1 christos */ 1221 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00), 1222 1.1 christos /* 1223 1.1 christos * Serial + flags only. 1224 1.1 christos */ 1225 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 1226 1.1 christos /* 1227 1.1 christos * Bad type map. 1228 1.1 christos */ 1229 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 1230 1.1 christos /* 1231 1.1 christos * Bad type map. 1232 1.1 christos */ 1233 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 1234 1.1 christos /* 1235 1.1 christos * Good type map. 1236 1.1 christos */ 1237 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 1238 1.1 christos 0x02), 1239 1.1 christos /* 1240 1.1 christos * Sentinel. 1241 1.1 christos */ 1242 1.1 christos WIRE_SENTINEL() 1243 1.1 christos }; 1244 1.1 christos 1245 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 1246 1.1 christos dns_rdatatype_csync, sizeof(dns_rdata_csync_t)); 1247 1.1 christos } 1248 1.1 christos 1249 1.1 christos ISC_RUN_TEST_IMPL(dnskey) { 1250 1.1 christos key_required(state, dns_rdatatype_dnskey, sizeof(dns_rdata_dnskey_t)); 1251 1.1 christos } 1252 1.1 christos 1253 1.1 christos /* 1254 1.1 christos * DOA tests. 1255 1.1 christos * 1256 1.1 christos * draft-durand-doa-over-dns-03: 1257 1.1 christos * 1258 1.1 christos * 3.2. DOA RDATA Wire Format 1259 1.1 christos * 1260 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1261 1.1 christos * 0: | | 1262 1.1 christos * | DOA-ENTERPRISE | 1263 1.1 christos * | | 1264 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1265 1.1 christos * 4: | | 1266 1.1 christos * | DOA-TYPE | 1267 1.1 christos * | | 1268 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1269 1.1 christos * 8: | DOA-LOCATION | DOA-MEDIA-TYPE / 1270 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1271 1.1 christos * 10: / / 1272 1.1 christos * / DOA-MEDIA-TYPE (continued) / 1273 1.1 christos * / / 1274 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1275 1.1 christos * / / 1276 1.1 christos * / DOA-DATA / 1277 1.1 christos * / / 1278 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1279 1.1 christos * 1280 1.1 christos * DOA-ENTERPRISE: a 32-bit unsigned integer in network order. 1281 1.1 christos * 1282 1.1 christos * DOA-TYPE: a 32-bit unsigned integer in network order. 1283 1.1 christos * 1284 1.1 christos * DOA-LOCATION: an 8-bit unsigned integer. 1285 1.1 christos * 1286 1.1 christos * DOA-MEDIA-TYPE: A <character-string> (see [RFC1035]). The first 1287 1.1 christos * octet of the <character-string> contains the number of characters to 1288 1.1 christos * follow. 1289 1.1 christos * 1290 1.1 christos * DOA-DATA: A variable length blob of binary data. The length of the 1291 1.1 christos * DOA-DATA is not contained within the wire format of the RR and has to 1292 1.1 christos * be computed from the RDLENGTH of the entire RR once other fields have 1293 1.1 christos * been taken into account. 1294 1.1 christos * 1295 1.1 christos * 3.3. DOA RDATA Presentation Format 1296 1.1 christos * 1297 1.1 christos * The DOA-ENTERPRISE field is presented as an unsigned 32-bit decimal 1298 1.1 christos * integer with range 0 - 4,294,967,295. 1299 1.1 christos * 1300 1.1 christos * The DOA-TYPE field is presented as an unsigned 32-bit decimal integer 1301 1.1 christos * with range 0 - 4,294,967,295. 1302 1.1 christos * 1303 1.1 christos * The DOA-LOCATION field is presented as an unsigned 8-bit decimal 1304 1.1 christos * integer with range 0 - 255. 1305 1.1 christos * 1306 1.1 christos * The DOA-MEDIA-TYPE field is presented as a single <character-string>. 1307 1.1 christos * 1308 1.1 christos * The DOA-DATA is presented as Base64 encoded data [RFC4648] unless the 1309 1.1 christos * DOA-DATA is empty in which case it is presented as a single dash 1310 1.1 christos * character ("-", ASCII 45). White space is permitted within Base64 1311 1.1 christos * data. 1312 1.1 christos */ 1313 1.1 christos ISC_RUN_TEST_IMPL(doa) { 1314 1.1 christos text_ok_t text_ok[] = { 1315 1.1 christos /* 1316 1.1 christos * Valid, non-empty DOA-DATA. 1317 1.1 christos */ 1318 1.1 christos TEXT_VALID("0 0 1 \"text/plain\" Zm9v"), 1319 1.1 christos /* 1320 1.1 christos * Valid, non-empty DOA-DATA with whitespace in between. 1321 1.1 christos */ 1322 1.1 christos TEXT_VALID_CHANGED("0 0 1 \"text/plain\" Zm 9v", "0 0 1 " 1323 1.1 christos "\"text/" 1324 1.1 christos "plain\" " 1325 1.1 christos "Zm9v"), 1326 1.1 christos /* 1327 1.1 christos * Valid, unquoted DOA-MEDIA-TYPE, non-empty DOA-DATA. 1328 1.1 christos */ 1329 1.1 christos TEXT_VALID_CHANGED("0 0 1 text/plain Zm9v", "0 0 1 " 1330 1.1 christos "\"text/plain\" " 1331 1.1 christos "Zm9v"), 1332 1.1 christos /* 1333 1.1 christos * Invalid, quoted non-empty DOA-DATA. 1334 1.1 christos */ 1335 1.1 christos TEXT_INVALID("0 0 1 \"text/plain\" \"Zm9v\""), 1336 1.1 christos /* 1337 1.1 christos * Valid, empty DOA-DATA. 1338 1.1 christos */ 1339 1.1 christos TEXT_VALID("0 0 1 \"text/plain\" -"), 1340 1.1 christos /* 1341 1.1 christos * Invalid, quoted empty DOA-DATA. 1342 1.1 christos */ 1343 1.1 christos TEXT_INVALID("0 0 1 \"text/plain\" \"-\""), 1344 1.1 christos /* 1345 1.1 christos * Invalid, missing "-" in empty DOA-DATA. 1346 1.1 christos */ 1347 1.1 christos TEXT_INVALID("0 0 1 \"text/plain\""), 1348 1.1 christos /* 1349 1.1 christos * Valid, undefined DOA-LOCATION. 1350 1.1 christos */ 1351 1.1 christos TEXT_VALID("0 0 100 \"text/plain\" Zm9v"), 1352 1.1 christos /* 1353 1.1 christos * Invalid, DOA-LOCATION too big. 1354 1.1 christos */ 1355 1.1 christos TEXT_INVALID("0 0 256 \"text/plain\" ZM9v"), 1356 1.1 christos /* 1357 1.1 christos * Valid, empty DOA-MEDIA-TYPE, non-empty DOA-DATA. 1358 1.1 christos */ 1359 1.1 christos TEXT_VALID("0 0 2 \"\" aHR0cHM6Ly93d3cuaXNjLm9yZy8="), 1360 1.1 christos /* 1361 1.1 christos * Valid, empty DOA-MEDIA-TYPE, empty DOA-DATA. 1362 1.1 christos */ 1363 1.1 christos TEXT_VALID("0 0 1 \"\" -"), 1364 1.1 christos /* 1365 1.1 christos * Valid, DOA-MEDIA-TYPE with a space. 1366 1.1 christos */ 1367 1.1 christos TEXT_VALID("0 0 1 \"plain text\" Zm9v"), 1368 1.1 christos /* 1369 1.1 christos * Invalid, missing DOA-MEDIA-TYPE. 1370 1.1 christos */ 1371 1.1 christos TEXT_INVALID("1234567890 1234567890 1"), 1372 1.1 christos /* 1373 1.1 christos * Valid, DOA-DATA over 255 octets. 1374 1.1 christos */ 1375 1.1 christos TEXT_VALID("1234567890 1234567890 1 \"image/gif\" " 1376 1.1 christos "R0lGODlhKAAZAOMCAGZmZgBmmf///zOZzMz//5nM/zNmmWbM" 1377 1.1 christos "/5nMzMzMzACZ/////////////////////yH5BAEKAA8ALAAA" 1378 1.1 christos "AAAoABkAAATH8IFJK5U2a4337F5ogRkpnoCJrly7PrCKyh8c" 1379 1.1 christos "3HgAhzT35MDbbtO7/IJIHbGiOiaTxVTpSVWWLqNq1UVyapNS" 1380 1.1 christos "1wd3OAxug0LhnCubcVhsxysQnOt4ATpvvzHlFzl1AwODhWeF" 1381 1.1 christos "AgRpen5/UhheAYMFdUB4SFcpGEGGdQeCAqBBLTuSk30EeXd9" 1382 1.1 christos "pEsAbKGxjHqDSE0Sp6ixN4N1BJmbc7lIhmsBich1awPAjkY1" 1383 1.1 christos "SZR8bJWrz382SGqIBQQFQd4IsUTaX+ceuudPEQA7"), 1384 1.1 christos /* 1385 1.1 christos * Invalid, bad Base64 in DOA-DATA. 1386 1.1 christos */ 1387 1.1 christos TEXT_INVALID("1234567890 1234567890 1 \"image/gif\" R0lGODl"), 1388 1.1 christos /* 1389 1.1 christos * Sentinel. 1390 1.1 christos */ 1391 1.1 christos TEXT_SENTINEL() 1392 1.1 christos }; 1393 1.1 christos wire_ok_t wire_ok[] = { 1394 1.1 christos /* 1395 1.1 christos * Valid, empty DOA-MEDIA-TYPE, empty DOA-DATA. 1396 1.1 christos */ 1397 1.1 christos WIRE_VALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01, 1398 1.1 christos 0x00), 1399 1.1 christos /* 1400 1.1 christos * Invalid, missing DOA-MEDIA-TYPE. 1401 1.1 christos */ 1402 1.1 christos WIRE_INVALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 1403 1.1 christos 0x01), 1404 1.1 christos /* 1405 1.1 christos * Invalid, malformed DOA-MEDIA-TYPE length. 1406 1.1 christos */ 1407 1.1 christos WIRE_INVALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 1408 1.1 christos 0x01, 0xff), 1409 1.1 christos /* 1410 1.1 christos * Valid, empty DOA-DATA. 1411 1.1 christos */ 1412 1.1 christos WIRE_VALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01, 1413 1.1 christos 0x03, 0x66, 0x6f, 0x6f), 1414 1.1 christos /* 1415 1.1 christos * Valid, non-empty DOA-DATA. 1416 1.1 christos */ 1417 1.1 christos WIRE_VALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01, 1418 1.1 christos 0x03, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72), 1419 1.1 christos /* 1420 1.1 christos * Valid, DOA-DATA over 255 octets. 1421 1.1 christos */ 1422 1.1 christos WIRE_VALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01, 1423 1.1 christos 0x06, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x00, 0x66, 1424 1.1 christos 0x99, 0xff, 0xff, 0xff, 0x33, 0x99, 0xcc, 0xcc, 0xff, 1425 1.1 christos 0xff, 0x99, 0xcc, 0xff, 0x33, 0x66, 0x99, 0x66, 0xcc, 1426 1.1 christos 0xff, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x99, 1427 1.1 christos 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 1428 1.1 christos 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x21, 0xf9, 1429 1.1 christos 0x04, 0x01, 0x0a, 0x00, 0x0f, 0x00, 0x2c, 0x00, 0x00, 1430 1.1 christos 0x00, 0x00, 0x28, 0x00, 0x19, 0x00, 0x00, 0x04, 0xc7, 1431 1.1 christos 0xf0, 0x81, 0x49, 0x2b, 0x95, 0x36, 0x6b, 0x8d, 0xf7, 1432 1.1 christos 0xec, 0x5e, 0x68, 0x81, 0x19, 0x29, 0x9e, 0x80, 0x89, 1433 1.1 christos 0xae, 0x5c, 0xbb, 0x3e, 0xb0, 0x8a, 0xca, 0x1f, 0x1c, 1434 1.1 christos 0xdc, 0x78, 0x00, 0x87, 0x34, 0xf7, 0xe4, 0xc0, 0xdb, 1435 1.1 christos 0x6e, 0xd3, 0xbb, 0xfc, 0x82, 0x48, 0x1d, 0xb1, 0xa2, 1436 1.1 christos 0x3a, 0x26, 0x93, 0xc5, 0x54, 0xe9, 0x49, 0x55, 0x96, 1437 1.1 christos 0x2e, 0xa3, 0x6a, 0xd5, 0x45, 0x72, 0x6a, 0x93, 0x52, 1438 1.1 christos 0xd7, 0x07, 0x77, 0x38, 0x0c, 0x6e, 0x83, 0x42, 0xe1, 1439 1.1 christos 0x9c, 0x2b, 0x9b, 0x71, 0x58, 0x6c, 0xc7, 0x2b, 0x10, 1440 1.1 christos 0x9c, 0xeb, 0x78, 0x01, 0x3a, 0x6f, 0xbf, 0x31, 0xe5, 1441 1.1 christos 0x17, 0x39, 0x75, 0x03, 0x03, 0x83, 0x85, 0x67, 0x85, 1442 1.1 christos 0x02, 0x04, 0x69, 0x7a, 0x7e, 0x7f, 0x52, 0x18, 0x5e, 1443 1.1 christos 0x01, 0x83, 0x05, 0x75, 0x40, 0x78, 0x48, 0x57, 0x29, 1444 1.1 christos 0x18, 0x41, 0x86, 0x75, 0x07, 0x82, 0x02, 0xa0, 0x41, 1445 1.1 christos 0x2d, 0x3b, 0x92, 0x93, 0x7d, 0x04, 0x79, 0x77, 0x7d, 1446 1.1 christos 0xa4, 0x4b, 0x00, 0x6c, 0xa1, 0xb1, 0x8c, 0x7a, 0x83, 1447 1.1 christos 0x48, 0x4d, 0x12, 0xa7, 0xa8, 0xb1, 0x37, 0x83, 0x75, 1448 1.1 christos 0x04, 0x99, 0x9b, 0x73, 0xb9, 0x48, 0x86, 0x6b, 0x01, 1449 1.1 christos 0x89, 0xc8, 0x75, 0x6b, 0x03, 0xc0, 0x8e, 0x46, 0x35, 1450 1.1 christos 0x49, 0x94, 0x7c, 0x6c, 0x95, 0xab, 0xcf, 0x7f, 0x36, 1451 1.1 christos 0x48, 0x6a, 0x88, 0x05, 0x04, 0x05, 0x41, 0xde, 0x08, 1452 1.1 christos 0xb1, 0x44, 0xda, 0x5f, 0xe7, 0x1e, 0xba, 0xe7, 0x4f, 1453 1.1 christos 0x11, 0x00, 0x3b), 1454 1.1 christos /* 1455 1.1 christos * Sentinel. 1456 1.1 christos */ 1457 1.1 christos WIRE_SENTINEL() 1458 1.1 christos }; 1459 1.1 christos 1460 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 1461 1.1 christos dns_rdatatype_doa, sizeof(dns_rdata_doa_t)); 1462 1.1 christos } 1463 1.1 christos 1464 1.1 christos /* 1465 1.1 christos * DS tests. 1466 1.1 christos * 1467 1.1 christos * RFC 4034: 1468 1.1 christos * 1469 1.1 christos * 5.1. DS RDATA Wire Format 1470 1.1 christos * 1471 1.1 christos * The RDATA for a DS RR consists of a 2 octet Key Tag field, a 1 octet 1472 1.1 christos * Algorithm field, a 1 octet Digest Type field, and a Digest field. 1473 1.1 christos * 1474 1.1 christos * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 1475 1.1 christos * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 1476 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1477 1.1 christos * | Key Tag | Algorithm | Digest Type | 1478 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1479 1.1 christos * / / 1480 1.1 christos * / Digest / 1481 1.1 christos * / / 1482 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1483 1.1 christos * 1484 1.1 christos * 5.1.1. The Key Tag Field 1485 1.1 christos * 1486 1.1 christos * The Key Tag field lists the key tag of the DNSKEY RR referred to by 1487 1.1 christos * the DS record, in network byte order. 1488 1.1 christos * 1489 1.1 christos * The Key Tag used by the DS RR is identical to the Key Tag used by 1490 1.1 christos * RRSIG RRs. Appendix B describes how to compute a Key Tag. 1491 1.1 christos * 1492 1.1 christos * 5.1.2. The Algorithm Field 1493 1.1 christos * 1494 1.1 christos * The Algorithm field lists the algorithm number of the DNSKEY RR 1495 1.1 christos * referred to by the DS record. 1496 1.1 christos * 1497 1.1 christos * The algorithm number used by the DS RR is identical to the algorithm 1498 1.1 christos * number used by RRSIG and DNSKEY RRs. Appendix A.1 lists the 1499 1.1 christos * algorithm number types. 1500 1.1 christos * 1501 1.1 christos * 5.1.3. The Digest Type Field 1502 1.1 christos * 1503 1.1 christos * The DS RR refers to a DNSKEY RR by including a digest of that DNSKEY 1504 1.1 christos * RR. The Digest Type field identifies the algorithm used to construct 1505 1.1 christos * the digest. Appendix A.2 lists the possible digest algorithm types. 1506 1.1 christos * 1507 1.1 christos * 5.1.4. The Digest Field 1508 1.1 christos * 1509 1.1 christos * The DS record refers to a DNSKEY RR by including a digest of that 1510 1.1 christos * DNSKEY RR. 1511 1.1 christos * 1512 1.1 christos * The digest is calculated by concatenating the canonical form of the 1513 1.1 christos * fully qualified owner name of the DNSKEY RR with the DNSKEY RDATA, 1514 1.1 christos * and then applying the digest algorithm. 1515 1.1 christos * 1516 1.1 christos * digest = digest_algorithm( DNSKEY owner name | DNSKEY RDATA); 1517 1.1 christos * 1518 1.1 christos * "|" denotes concatenation 1519 1.1 christos * 1520 1.1 christos * DNSKEY RDATA = Flags | Protocol | Algorithm | Public Key. 1521 1.1 christos * 1522 1.1 christos * The size of the digest may vary depending on the digest algorithm and 1523 1.1 christos * DNSKEY RR size. As of the time of this writing, the only defined 1524 1.1 christos * digest algorithm is SHA-1, which produces a 20 octet digest. 1525 1.1 christos */ 1526 1.1 christos ISC_RUN_TEST_IMPL(ds) { 1527 1.1 christos text_ok_t text_ok[] = { 1528 1.1 christos /* 1529 1.1 christos * Invalid, empty record. 1530 1.1 christos */ 1531 1.1 christos TEXT_INVALID(""), 1532 1.1 christos /* 1533 1.1 christos * Invalid, no algorithm. 1534 1.1 christos */ 1535 1.1 christos TEXT_INVALID("0"), 1536 1.1 christos /* 1537 1.1 christos * Invalid, no digest type. 1538 1.1 christos */ 1539 1.1 christos TEXT_INVALID("0 0"), 1540 1.1 christos /* 1541 1.1 christos * Invalid, no digest. 1542 1.1 christos */ 1543 1.1 christos TEXT_INVALID("0 0 0"), 1544 1.1 christos /* 1545 1.1 christos * Valid, 1-octet digest for a reserved digest type. 1546 1.1 christos */ 1547 1.1 christos TEXT_VALID("0 0 0 00"), 1548 1.1 christos /* 1549 1.1 christos * Invalid, short SHA-1 digest. 1550 1.1 christos */ 1551 1.1 christos TEXT_INVALID("0 0 1 00"), 1552 1.1 christos TEXT_INVALID("0 0 1 4FDCE83016EDD29077621FE568F8DADDB5809B"), 1553 1.1 christos /* 1554 1.1 christos * Valid, 20-octet SHA-1 digest. 1555 1.1 christos */ 1556 1.1 christos TEXT_VALID("0 0 1 4FDCE83016EDD29077621FE568F8DADDB5809B6A"), 1557 1.1 christos /* 1558 1.1 christos * Invalid, excessively long SHA-1 digest. 1559 1.1 christos */ 1560 1.1 christos TEXT_INVALID("0 0 1 4FDCE83016EDD29077621FE568F8DADDB5809B" 1561 1.1 christos "6A00"), 1562 1.1 christos /* 1563 1.1 christos * Invalid, short SHA-256 digest. 1564 1.1 christos */ 1565 1.1 christos TEXT_INVALID("0 0 2 00"), 1566 1.1 christos TEXT_INVALID("0 0 2 D001BD422FFDA9B745425B71DC17D007E69186" 1567 1.1 christos "9BD59C5F237D9BF85434C313"), 1568 1.1 christos /* 1569 1.1 christos * Valid, 32-octet SHA-256 digest. 1570 1.1 christos */ 1571 1.1 christos TEXT_VALID_CHANGED("0 0 2 " 1572 1.1 christos "D001BD422FFDA9B745425B71DC17D007E691869B" 1573 1.1 christos "D59C5F237D9BF85434C3133F", 1574 1.1 christos "0 0 2 " 1575 1.1 christos "D001BD422FFDA9B745425B71DC17D007E691869B" 1576 1.1 christos "D59C5F237D9BF854 34C3133F"), 1577 1.1 christos /* 1578 1.1 christos * Invalid, excessively long SHA-256 digest. 1579 1.1 christos */ 1580 1.1 christos TEXT_INVALID("0 0 2 D001BD422FFDA9B745425B71DC17D007E69186" 1581 1.1 christos "9BD59C5F237D9BF85434C3133F00"), 1582 1.1 christos /* 1583 1.1 christos * Valid, GOST is no longer supported, hence no length checks. 1584 1.1 christos */ 1585 1.1 christos TEXT_VALID("0 0 3 00"), 1586 1.1 christos /* 1587 1.1 christos * Invalid, short SHA-384 digest. 1588 1.1 christos */ 1589 1.1 christos TEXT_INVALID("0 0 4 00"), 1590 1.1 christos TEXT_INVALID("0 0 4 AC748D6C5AA652904A8763D64B7DFFFFA98152" 1591 1.1 christos "BE12128D238BEBB4814B648F5A841E15CAA2DE348891" 1592 1.1 christos "A37A699F65E5"), 1593 1.1 christos /* 1594 1.1 christos * Valid, 48-octet SHA-384 digest. 1595 1.1 christos */ 1596 1.1 christos TEXT_VALID_CHANGED("0 0 4 " 1597 1.1 christos "AC748D6C5AA652904A8763D64B7DFFFFA98152BE" 1598 1.1 christos "12128D238BEBB4814B648F5A841E15CAA2DE348891A" 1599 1.1 christos "37A" 1600 1.1 christos "699F65E54D", 1601 1.1 christos "0 0 4 " 1602 1.1 christos "AC748D6C5AA652904A8763D64B7DFFFFA98152BE" 1603 1.1 christos "12128D238BEBB481 " 1604 1.1 christos "4B648F5A841E15CAA2DE348891A37A" 1605 1.1 christos "699F65E54D"), 1606 1.1 christos /* 1607 1.1 christos * Invalid, excessively long SHA-384 digest. 1608 1.1 christos */ 1609 1.1 christos TEXT_INVALID("0 0 4 AC748D6C5AA652904A8763D64B7DFFFFA98152" 1610 1.1 christos "BE12128D238BEBB4814B648F5A841E15CAA2DE348891" 1611 1.1 christos "A37A699F65E54D00"), 1612 1.1 christos /* 1613 1.1 christos * Valid, 1-octet digest for an unassigned digest type. 1614 1.1 christos */ 1615 1.1 christos TEXT_VALID("0 0 5 00"), 1616 1.1 christos /* 1617 1.1 christos * Sentinel. 1618 1.1 christos */ 1619 1.1 christos TEXT_SENTINEL() 1620 1.1 christos }; 1621 1.1 christos wire_ok_t wire_ok[] = { 1622 1.1 christos /* 1623 1.1 christos * Invalid, truncated key tag. 1624 1.1 christos */ 1625 1.1 christos WIRE_INVALID(0x00), 1626 1.1 christos /* 1627 1.1 christos * Invalid, no algorithm. 1628 1.1 christos */ 1629 1.1 christos WIRE_INVALID(0x00, 0x00), 1630 1.1 christos /* 1631 1.1 christos * Invalid, no digest type. 1632 1.1 christos */ 1633 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00), 1634 1.1 christos /* 1635 1.1 christos * Invalid, no digest. 1636 1.1 christos */ 1637 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00), 1638 1.1 christos /* 1639 1.1 christos * Valid, 1-octet digest for a reserved digest type. 1640 1.1 christos */ 1641 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00), 1642 1.1 christos /* 1643 1.1 christos * Invalid, short SHA-1 digest. 1644 1.1 christos */ 1645 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x01, 0x00), 1646 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x01, 0x4F, 0xDC, 0xE8, 0x30, 1647 1.1 christos 0x16, 0xED, 0xD2, 0x90, 0x77, 0x62, 0x1F, 0xE5, 1648 1.1 christos 0x68, 0xF8, 0xDA, 0xDD, 0xB5, 0x80, 0x9B), 1649 1.1 christos /* 1650 1.1 christos * Valid, 20-octet SHA-1 digest. 1651 1.1 christos */ 1652 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x01, 0x4F, 0xDC, 0xE8, 0x30, 0x16, 1653 1.1 christos 0xED, 0xD2, 0x90, 0x77, 0x62, 0x1F, 0xE5, 0x68, 0xF8, 1654 1.1 christos 0xDA, 0xDD, 0xB5, 0x80, 0x9B, 0x6A), 1655 1.1 christos /* 1656 1.1 christos * Invalid, excessively long SHA-1 digest. 1657 1.1 christos */ 1658 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x01, 0x4F, 0xDC, 0xE8, 0x30, 1659 1.1 christos 0x16, 0xED, 0xD2, 0x90, 0x77, 0x62, 0x1F, 0xE5, 1660 1.1 christos 0x68, 0xF8, 0xDA, 0xDD, 0xB5, 0x80, 0x9B, 0x6A, 1661 1.1 christos 0x00), 1662 1.1 christos /* 1663 1.1 christos * Invalid, short SHA-256 digest. 1664 1.1 christos */ 1665 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x02, 0x00), 1666 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x02, 0xD0, 0x01, 0xBD, 0x42, 1667 1.1 christos 0x2F, 0xFD, 0xA9, 0xB7, 0x45, 0x42, 0x5B, 0x71, 1668 1.1 christos 0xDC, 0x17, 0xD0, 0x07, 0xE6, 0x91, 0x86, 0x9B, 1669 1.1 christos 0xD5, 0x9C, 0x5F, 0x23, 0x7D, 0x9B, 0xF8, 0x54, 1670 1.1 christos 0x34, 0xC3, 0x13), 1671 1.1 christos /* 1672 1.1 christos * Valid, 32-octet SHA-256 digest. 1673 1.1 christos */ 1674 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x02, 0xD0, 0x01, 0xBD, 0x42, 0x2F, 1675 1.1 christos 0xFD, 0xA9, 0xB7, 0x45, 0x42, 0x5B, 0x71, 0xDC, 0x17, 1676 1.1 christos 0xD0, 0x07, 0xE6, 0x91, 0x86, 0x9B, 0xD5, 0x9C, 0x5F, 1677 1.1 christos 0x23, 0x7D, 0x9B, 0xF8, 0x54, 0x34, 0xC3, 0x13, 1678 1.1 christos 0x3F), 1679 1.1 christos /* 1680 1.1 christos * Invalid, excessively long SHA-256 digest. 1681 1.1 christos */ 1682 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x02, 0xD0, 0x01, 0xBD, 0x42, 1683 1.1 christos 0x2F, 0xFD, 0xA9, 0xB7, 0x45, 0x42, 0x5B, 0x71, 1684 1.1 christos 0xDC, 0x17, 0xD0, 0x07, 0xE6, 0x91, 0x86, 0x9B, 1685 1.1 christos 0xD5, 0x9C, 0x5F, 0x23, 0x7D, 0x9B, 0xF8, 0x54, 1686 1.1 christos 0x34, 0xC3, 0x13, 0x3F, 0x00), 1687 1.1 christos /* 1688 1.1 christos * Valid, GOST is no longer supported, hence no length checks. 1689 1.1 christos */ 1690 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x03, 0x00), 1691 1.1 christos /* 1692 1.1 christos * Invalid, short SHA-384 digest. 1693 1.1 christos */ 1694 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x04, 0x00), 1695 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x04, 0xAC, 0x74, 0x8D, 0x6C, 1696 1.1 christos 0x5A, 0xA6, 0x52, 0x90, 0x4A, 0x87, 0x63, 0xD6, 1697 1.1 christos 0x4B, 0x7D, 0xFF, 0xFF, 0xA9, 0x81, 0x52, 0xBE, 1698 1.1 christos 0x12, 0x12, 0x8D, 0x23, 0x8B, 0xEB, 0xB4, 0x81, 1699 1.1 christos 0x4B, 0x64, 0x8F, 0x5A, 0x84, 0x1E, 0x15, 0xCA, 1700 1.1 christos 0xA2, 0xDE, 0x34, 0x88, 0x91, 0xA3, 0x7A, 0x69, 1701 1.1 christos 0x9F, 0x65, 0xE5), 1702 1.1 christos /* 1703 1.1 christos * Valid, 48-octet SHA-384 digest. 1704 1.1 christos */ 1705 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x04, 0xAC, 0x74, 0x8D, 0x6C, 0x5A, 1706 1.1 christos 0xA6, 0x52, 0x90, 0x4A, 0x87, 0x63, 0xD6, 0x4B, 0x7D, 1707 1.1 christos 0xFF, 0xFF, 0xA9, 0x81, 0x52, 0xBE, 0x12, 0x12, 0x8D, 1708 1.1 christos 0x23, 0x8B, 0xEB, 0xB4, 0x81, 0x4B, 0x64, 0x8F, 0x5A, 1709 1.1 christos 0x84, 0x1E, 0x15, 0xCA, 0xA2, 0xDE, 0x34, 0x88, 0x91, 1710 1.1 christos 0xA3, 0x7A, 0x69, 0x9F, 0x65, 0xE5, 0x4D), 1711 1.1 christos /* 1712 1.1 christos * Invalid, excessively long SHA-384 digest. 1713 1.1 christos */ 1714 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x04, 0xAC, 0x74, 0x8D, 0x6C, 1715 1.1 christos 0x5A, 0xA6, 0x52, 0x90, 0x4A, 0x87, 0x63, 0xD6, 1716 1.1 christos 0x4B, 0x7D, 0xFF, 0xFF, 0xA9, 0x81, 0x52, 0xBE, 1717 1.1 christos 0x12, 0x12, 0x8D, 0x23, 0x8B, 0xEB, 0xB4, 0x81, 1718 1.1 christos 0x4B, 0x64, 0x8F, 0x5A, 0x84, 0x1E, 0x15, 0xCA, 1719 1.1 christos 0xA2, 0xDE, 0x34, 0x88, 0x91, 0xA3, 0x7A, 0x69, 1720 1.1 christos 0x9F, 0x65, 0xE5, 0x4D, 0x00), 1721 1.1 christos WIRE_VALID(0x00, 0x00, 0x04, 0x00, 0x00), 1722 1.1 christos /* 1723 1.1 christos * Sentinel. 1724 1.1 christos */ 1725 1.1 christos WIRE_SENTINEL() 1726 1.1 christos }; 1727 1.1 christos 1728 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 1729 1.1 christos dns_rdatatype_ds, sizeof(dns_rdata_ds_t)); 1730 1.1 christos } 1731 1.1 christos 1732 1.1 christos /* 1733 1.6 christos * DSYNC tests. 1734 1.6 christos * 1735 1.6 christos * draft-ietf-dnsop-generalized-notify-09 1736 1.6 christos * 1737 1.6 christos * 2.1. Wire Format 1738 1.6 christos * 1739 1.6 christos * The DSYNC RDATA wire format is encoded as follows: 1740 1.6 christos * 1741 1.6 christos * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 1742 1.6 christos * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 1743 1.6 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1744 1.6 christos * | RRtype | Scheme | Port 1745 1.6 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1746 1.6 christos * | Target ... / 1747 1.6 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-/ 1748 1.6 christos * 1749 1.6 christos * RRtype The type of generalized NOTIFY that this DSYNC RR defines the 1750 1.6 christos * desired target address for (see "Resource Record (RR) TYPEs" IANA 1751 1.6 christos * registry). For now, only CDS and CSYNC are supported values, with 1752 1.6 christos * the former indicating an updated CDS or CDNSKEY record set. 1753 1.6 christos * 1754 1.6 christos * Scheme The mode used for contacting the desired notification 1755 1.6 christos * address. This is an 8-bit unsigned integer. Records with value 0 1756 1.6 christos * (null scheme) are ignored by consumers. Value 1 is described in 1757 1.6 christos * this document, and values 128-255 are reserved for private use. 1758 1.6 christos * All other values are currently unassigned. 1759 1.6 christos * 1760 1.6 christos * Port The port on the target host of the notification service. This 1761 1.6 christos * is a 16-bit unsigned integer in network byte order. Records with 1762 1.6 christos * value 0 are ignored by consumers. 1763 1.6 christos * 1764 1.6 christos * Target The fully-qualified, uncompressed domain name of the target 1765 1.6 christos * host providing the service of listening for generalized 1766 1.6 christos * notifications of the specified type. This name MUST resolve to 1767 1.6 christos * one or more address records. 1768 1.6 christos * 1769 1.6 christos * 2.2. Presentation Format 1770 1.6 christos * 1771 1.6 christos * The presentation format of the RDATA portion is as follows: 1772 1.6 christos * 1773 1.6 christos * * The RRtype field is represented as a mnemonic from the "Resource 1774 1.6 christos * Record (RR) TYPEs" registry. 1775 1.6 christos * 1776 1.6 christos * * The Scheme field is represented by its mnemonic if assigned (see 1777 1.6 christos * Section 6.2), otherwise as an unsigned decimal integer. 1778 1.6 christos * 1779 1.6 christos * * The Port field is represented as an unsigned decimal integer. 1780 1.6 christos * 1781 1.6 christos * * The Target field is represented as a <domain-name> ([RFC1035], 1782 1.6 christos * Section 5.1). 1783 1.6 christos */ 1784 1.6 christos ISC_RUN_TEST_IMPL(dsync) { 1785 1.6 christos text_ok_t text_ok[] = { 1786 1.6 christos /* 1787 1.6 christos * Invalid, empty record. 1788 1.6 christos */ 1789 1.6 christos TEXT_INVALID(""), 1790 1.6 christos /* 1791 1.6 christos * Known type and known scheme. 1792 1.6 christos */ 1793 1.6 christos TEXT_VALID("CDS NOTIFY 0 example.com"), 1794 1.6 christos /* 1795 1.6 christos * Known type and unknown scheme. 1796 1.6 christos */ 1797 1.6 christos TEXT_VALID("CDS 3 0 example.com"), 1798 1.6 christos /* 1799 1.6 christos * Unknown type and known scheme. 1800 1.6 christos */ 1801 1.6 christos TEXT_VALID("TYPE1000 NOTIFY 0 example.com"), 1802 1.6 christos /* 1803 1.6 christos * Unknown type and unknown scheme. 1804 1.6 christos */ 1805 1.6 christos TEXT_VALID("TYPE1000 3 0 example.com"), 1806 1.6 christos /* 1807 1.6 christos * Unknown type and unknown scheme, max port. 1808 1.6 christos */ 1809 1.6 christos TEXT_VALID("TYPE1000 3 65535 example.com"), 1810 1.6 christos /* 1811 1.6 christos * Unknown type and max scheme, max port. 1812 1.6 christos */ 1813 1.6 christos TEXT_VALID("TYPE64000 255 65535 example.com"), 1814 1.6 christos /* 1815 1.6 christos * Invalid type and max scheme, max port. 1816 1.6 christos */ 1817 1.6 christos TEXT_INVALID("INVALID 255 65536 example.com"), 1818 1.6 christos /* 1819 1.6 christos * Unknown type and too big scheme, max port. 1820 1.6 christos */ 1821 1.6 christos TEXT_INVALID("TYPE1000 256 65536 example.com"), 1822 1.6 christos /* 1823 1.6 christos * Unknown type and unknown scheme, port too big. 1824 1.6 christos */ 1825 1.6 christos TEXT_INVALID("TYPE1000 3 65536 example.com"), 1826 1.6 christos /* 1827 1.6 christos * Unknown type and bad scheme, max port. 1828 1.6 christos */ 1829 1.6 christos TEXT_INVALID("TYPE1000 UNKNOWN 65535 example.com"), 1830 1.6 christos /* 1831 1.6 christos * Sentinel. 1832 1.6 christos */ 1833 1.6 christos TEXT_SENTINEL() 1834 1.6 christos }; 1835 1.6 christos check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in, 1836 1.6 christos dns_rdatatype_dsync, sizeof(dns_rdata_dsync_t)); 1837 1.6 christos } 1838 1.6 christos 1839 1.6 christos /* 1840 1.1 christos * EDNS Client Subnet tests. 1841 1.1 christos * 1842 1.1 christos * RFC 7871: 1843 1.1 christos * 1844 1.1 christos * 6. Option Format 1845 1.1 christos * 1846 1.1 christos * This protocol uses an EDNS0 [RFC6891] option to include client 1847 1.1 christos * address information in DNS messages. The option is structured as 1848 1.1 christos * follows: 1849 1.1 christos * 1850 1.1 christos * +0 (MSB) +1 (LSB) 1851 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1852 1.1 christos * 0: | OPTION-CODE | 1853 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1854 1.1 christos * 2: | OPTION-LENGTH | 1855 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1856 1.1 christos * 4: | FAMILY | 1857 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1858 1.1 christos * 6: | SOURCE PREFIX-LENGTH | SCOPE PREFIX-LENGTH | 1859 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1860 1.1 christos * 8: | ADDRESS... / 1861 1.1 christos * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 1862 1.1 christos * 1863 1.1 christos * o (Defined in [RFC6891]) OPTION-CODE, 2 octets, for ECS is 8 (0x00 1864 1.1 christos * 0x08). 1865 1.1 christos * 1866 1.1 christos * o (Defined in [RFC6891]) OPTION-LENGTH, 2 octets, contains the 1867 1.1 christos * length of the payload (everything after OPTION-LENGTH) in octets. 1868 1.1 christos * 1869 1.1 christos * o FAMILY, 2 octets, indicates the family of the address contained in 1870 1.1 christos * the option, using address family codes as assigned by IANA in 1871 1.1 christos * Address Family Numbers [Address_Family_Numbers]. 1872 1.1 christos * 1873 1.1 christos * The format of the address part depends on the value of FAMILY. This 1874 1.1 christos * document only defines the format for FAMILY 1 (IPv4) and FAMILY 2 1875 1.1 christos * (IPv6), which are as follows: 1876 1.1 christos * 1877 1.1 christos * o SOURCE PREFIX-LENGTH, an unsigned octet representing the leftmost 1878 1.1 christos * number of significant bits of ADDRESS to be used for the lookup. 1879 1.1 christos * In responses, it mirrors the same value as in the queries. 1880 1.1 christos * 1881 1.1 christos * o SCOPE PREFIX-LENGTH, an unsigned octet representing the leftmost 1882 1.1 christos * number of significant bits of ADDRESS that the response covers. 1883 1.1 christos * In queries, it MUST be set to 0. 1884 1.1 christos * 1885 1.1 christos * o ADDRESS, variable number of octets, contains either an IPv4 or 1886 1.1 christos * IPv6 address, depending on FAMILY, which MUST be truncated to the 1887 1.1 christos * number of bits indicated by the SOURCE PREFIX-LENGTH field, 1888 1.1 christos * padding with 0 bits to pad to the end of the last octet needed. 1889 1.1 christos * 1890 1.1 christos * o A server receiving an ECS option that uses either too few or too 1891 1.1 christos * many ADDRESS octets, or that has non-zero ADDRESS bits set beyond 1892 1.1 christos * SOURCE PREFIX-LENGTH, SHOULD return FORMERR to reject the packet, 1893 1.1 christos * as a signal to the software developer making the request to fix 1894 1.1 christos * their implementation. 1895 1.1 christos * 1896 1.1 christos * All fields are in network byte order ("big-endian", per [RFC1700], 1897 1.1 christos * Data Notation). 1898 1.1 christos */ 1899 1.1 christos ISC_RUN_TEST_IMPL(edns_client_subnet) { 1900 1.1 christos wire_ok_t wire_ok[] = { 1901 1.1 christos /* 1902 1.1 christos * Option code with no content. 1903 1.1 christos */ 1904 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 0x00), 1905 1.1 christos /* 1906 1.1 christos * Option code family 0, source 0, scope 0. 1907 1.1 christos */ 1908 1.1 christos WIRE_VALID(0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00), 1909 1.1 christos /* 1910 1.1 christos * Option code family 1 (IPv4), source 0, scope 0. 1911 1.1 christos */ 1912 1.1 christos WIRE_VALID(0x00, 0x08, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00), 1913 1.1 christos /* 1914 1.1 christos * Option code family 2 (IPv6) , source 0, scope 0. 1915 1.1 christos */ 1916 1.1 christos WIRE_VALID(0x00, 0x08, 0x00, 0x04, 0x00, 0x02, 0x00, 0x00), 1917 1.1 christos /* 1918 1.1 christos * Extra octet. 1919 1.1 christos */ 1920 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 1921 1.1 christos 0x00), 1922 1.1 christos /* 1923 1.1 christos * Source too long for IPv4. 1924 1.1 christos */ 1925 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 8, 0x00, 0x01, 33, 0x00, 0x00, 1926 1.1 christos 0x00, 0x00, 0x00), 1927 1.1 christos /* 1928 1.1 christos * Source too long for IPv6. 1929 1.1 christos */ 1930 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 20, 0x00, 0x02, 129, 0x00, 0x00, 1931 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1932 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 1933 1.1 christos /* 1934 1.1 christos * Scope too long for IPv4. 1935 1.1 christos */ 1936 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 8, 0x00, 0x01, 0x00, 33, 0x00, 1937 1.1 christos 0x00, 0x00, 0x00), 1938 1.1 christos /* 1939 1.1 christos * Scope too long for IPv6. 1940 1.1 christos */ 1941 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 20, 0x00, 0x02, 0x00, 129, 0x00, 1942 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1943 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 1944 1.1 christos /* 1945 1.1 christos * When family=0, source and scope should be 0. 1946 1.1 christos */ 1947 1.1 christos WIRE_VALID(0x00, 0x08, 0x00, 4, 0x00, 0x00, 0x00, 0x00), 1948 1.1 christos /* 1949 1.1 christos * When family=0, source and scope should be 0. 1950 1.1 christos */ 1951 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 5, 0x00, 0x00, 0x01, 0x00, 0x00), 1952 1.1 christos /* 1953 1.1 christos * When family=0, source and scope should be 0. 1954 1.1 christos */ 1955 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 5, 0x00, 0x00, 0x00, 0x01, 0x00), 1956 1.1 christos /* 1957 1.1 christos * Length too short for source IPv4. 1958 1.1 christos */ 1959 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 7, 0x00, 0x01, 32, 0x00, 0x00, 1960 1.1 christos 0x00, 0x00), 1961 1.1 christos /* 1962 1.1 christos * Length too short for source IPv6. 1963 1.1 christos */ 1964 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 19, 0x00, 0x02, 128, 0x00, 0x00, 1965 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1966 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 1967 1.1 christos /* 1968 1.1 christos * Sentinel. 1969 1.1 christos */ 1970 1.1 christos WIRE_SENTINEL() 1971 1.1 christos }; 1972 1.1 christos 1973 1.1 christos check_rdata(NULL, wire_ok, NULL, true, dns_rdataclass_in, 1974 1.1 christos dns_rdatatype_opt, sizeof(dns_rdata_opt_t)); 1975 1.1 christos } 1976 1.1 christos 1977 1.1 christos /* 1978 1.1 christos * http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt 1979 1.1 christos * 1980 1.1 christos * The RDATA portion of both the NIMLOC and EID records contains 1981 1.1 christos * uninterpreted binary data. The representation in the text master file 1982 1.1 christos * is an even number of hex characters (0 to 9, a to f), case is not 1983 1.1 christos * significant. For readability, whitespace may be included in the value 1984 1.1 christos * field and should be ignored when reading a master file. 1985 1.1 christos */ 1986 1.1 christos ISC_RUN_TEST_IMPL(eid) { 1987 1.1 christos text_ok_t text_ok[] = { TEXT_VALID("AABBCC"), 1988 1.1 christos TEXT_VALID_CHANGED("AA bb cc", "AABBCC"), 1989 1.1 christos TEXT_INVALID("aab"), 1990 1.1 christos /* 1991 1.1 christos * Sentinel. 1992 1.1 christos */ 1993 1.1 christos TEXT_SENTINEL() }; 1994 1.1 christos wire_ok_t wire_ok[] = { WIRE_VALID(0x00), WIRE_VALID(0xAA, 0xBB, 0xCC), 1995 1.1 christos /* 1996 1.1 christos * Sentinel. 1997 1.1 christos */ 1998 1.1 christos WIRE_SENTINEL() }; 1999 1.1 christos 2000 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 2001 1.1 christos dns_rdatatype_eid, sizeof(dns_rdata_in_eid_t)); 2002 1.1 christos } 2003 1.1 christos 2004 1.1 christos /* 2005 1.1 christos * test that an oversized HIP record will be rejected 2006 1.1 christos */ 2007 1.1 christos ISC_RUN_TEST_IMPL(hip) { 2008 1.1 christos text_ok_t text_ok[] = { 2009 1.1 christos /* RFC 8005 examples. */ 2010 1.1 christos TEXT_VALID_LOOP(0, "2 200100107B1A74DF365639CC39F1D578 " 2011 1.1 christos "AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cI" 2012 1.1 christos "vM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbW" 2013 1.1 christos "Iy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+b" 2014 1.1 christos "SRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWx" 2015 1.1 christos "Z48AWkskmdHaVDP4BcelrTI3rMXdXF5D"), 2016 1.1 christos TEXT_VALID_LOOP(1, "2 200100107B1A74DF365639CC39F1D578 " 2017 1.1 christos "AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cI" 2018 1.1 christos "vM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbW" 2019 1.1 christos "Iy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+b" 2020 1.1 christos "SRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWx" 2021 1.1 christos "Z48AWkskmdHaVDP4BcelrTI3rMXdXF5D " 2022 1.1 christos "rvs1.example.com."), 2023 1.1 christos TEXT_VALID_LOOP(2, "2 200100107B1A74DF365639CC39F1D578 " 2024 1.1 christos "AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cI" 2025 1.1 christos "vM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbW" 2026 1.1 christos "Iy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+b" 2027 1.1 christos "SRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWx" 2028 1.1 christos "Z48AWkskmdHaVDP4BcelrTI3rMXdXF5D " 2029 1.1 christos "rvs1.example.com. rvs2.example.com."), 2030 1.1 christos /* 2031 1.1 christos * Sentinel. 2032 1.1 christos */ 2033 1.1 christos TEXT_SENTINEL() 2034 1.1 christos }; 2035 1.1 christos unsigned char hipwire[DNS_RDATA_MAXLENGTH] = { 0x01, 0x00, 0x00, 0x01, 2036 1.1 christos 0x00, 0x00, 0x04, 0x41, 2037 1.1 christos 0x42, 0x43, 0x44, 0x00 }; 2038 1.1 christos unsigned char buf[1024 * 1024]; 2039 1.1 christos dns_rdata_t rdata = DNS_RDATA_INIT; 2040 1.1 christos isc_result_t result; 2041 1.1 christos size_t i; 2042 1.1 christos 2043 1.1 christos /* 2044 1.1 christos * Fill the rest of input buffer with compression pointers. 2045 1.1 christos */ 2046 1.1 christos for (i = 12; i < sizeof(hipwire) - 2; i += 2) { 2047 1.1 christos hipwire[i] = 0xc0; 2048 1.1 christos hipwire[i + 1] = 0x06; 2049 1.1 christos } 2050 1.1 christos 2051 1.1 christos result = wire_to_rdata(hipwire, sizeof(hipwire), dns_rdataclass_in, 2052 1.1 christos dns_rdatatype_hip, buf, sizeof(buf), &rdata); 2053 1.1 christos assert_int_equal(result, DNS_R_FORMERR); 2054 1.1 christos check_text_ok(text_ok, dns_rdataclass_in, dns_rdatatype_hip, 2055 1.1 christos sizeof(dns_rdata_hip_t)); 2056 1.1 christos } 2057 1.1 christos 2058 1.6 christos /* HHIT RDATA - base64 encoded opaque */ 2059 1.6 christos ISC_RUN_TEST_IMPL(hhit) { 2060 1.6 christos text_ok_t text_ok[] = { /* empty */ 2061 1.6 christos TEXT_INVALID(""), 2062 1.6 christos /* valid base64 string */ 2063 1.6 christos TEXT_VALID("aaaa"), 2064 1.6 christos /* invalid base64 string */ 2065 1.6 christos TEXT_INVALID("aaaaa"), 2066 1.6 christos /* 2067 1.6 christos * Sentinel. 2068 1.6 christos */ 2069 1.6 christos TEXT_SENTINEL() 2070 1.6 christos }; 2071 1.6 christos 2072 1.6 christos check_rdata(text_ok, NULL, NULL, true, dns_rdataclass_in, 2073 1.6 christos dns_rdatatype_hhit, sizeof(dns_rdata_hhit_t)); 2074 1.6 christos } 2075 1.6 christos 2076 1.1 christos /* 2077 1.1 christos * ISDN tests. 2078 1.1 christos * 2079 1.1 christos * RFC 1183: 2080 1.1 christos * 2081 1.1 christos * 3.2. The ISDN RR 2082 1.1 christos * 2083 1.1 christos * The ISDN RR is defined with mnemonic ISDN and type code 20 (decimal). 2084 1.1 christos * 2085 1.1 christos * An ISDN (Integrated Service Digital Network) number is simply a 2086 1.1 christos * telephone number. The intent of the members of the CCITT is to 2087 1.1 christos * upgrade all telephone and data network service to a common service. 2088 1.1 christos * 2089 1.1 christos * The numbering plan (E.163/E.164) is the same as the familiar 2090 1.1 christos * international plan for POTS (an un-official acronym, meaning Plain 2091 1.1 christos * Old Telephone Service). In E.166, CCITT says "An E.163/E.164 2092 1.1 christos * telephony subscriber may become an ISDN subscriber without a number 2093 1.1 christos * change." 2094 1.1 christos * 2095 1.1 christos * ISDN has the following format: 2096 1.1 christos * 2097 1.1 christos * <owner> <ttl> <class> ISDN <ISDN-address> <sa> 2098 1.1 christos * 2099 1.1 christos * The <ISDN-address> field is required; <sa> is optional. 2100 1.1 christos * 2101 1.1 christos * <ISDN-address> identifies the ISDN number of <owner> and DDI (Direct 2102 1.1 christos * Dial In) if any, as defined by E.164 [8] and E.163 [7], the ISDN and 2103 1.1 christos * PSTN (Public Switched Telephone Network) numbering plan. E.163 2104 1.1 christos * defines the country codes, and E.164 the form of the addresses. Its 2105 1.1 christos * format in master files is a <character-string> syntactically 2106 1.1 christos * identical to that used in TXT and HINFO. 2107 1.1 christos * 2108 1.1 christos * <sa> specifies the subaddress (SA). The format of <sa> in master 2109 1.1 christos * files is a <character-string> syntactically identical to that used in 2110 1.1 christos * TXT and HINFO. 2111 1.1 christos * 2112 1.1 christos * The format of ISDN is class insensitive. ISDN RRs cause no 2113 1.1 christos * additional section processing. 2114 1.1 christos * 2115 1.1 christos * The <ISDN-address> is a string of characters, normally decimal 2116 1.1 christos * digits, beginning with the E.163 country code and ending with the DDI 2117 1.1 christos * if any. Note that ISDN, in Q.931, permits any IA5 character in the 2118 1.1 christos * general case. 2119 1.1 christos * 2120 1.1 christos * The <sa> is a string of hexadecimal digits. For digits 0-9, the 2121 1.1 christos * concrete encoding in the Q.931 call setup information element is 2122 1.1 christos * identical to BCD. 2123 1.1 christos * 2124 1.1 christos * For example: 2125 1.1 christos * 2126 1.1 christos * Relay.Prime.COM. IN ISDN 150862028003217 2127 1.1 christos * sh.Prime.COM. IN ISDN 150862028003217 004 2128 1.1 christos * 2129 1.1 christos * (Note: "1" is the country code for the North American Integrated 2130 1.1 christos * Numbering Area, i.e., the system of "area codes" familiar to people 2131 1.1 christos * in those countries.) 2132 1.1 christos * 2133 1.1 christos * The RR data is the ASCII representation of the digits. It is encoded 2134 1.1 christos * as one or two <character-string>s, i.e., count followed by 2135 1.1 christos * characters. 2136 1.1 christos */ 2137 1.1 christos ISC_RUN_TEST_IMPL(isdn) { 2138 1.1 christos wire_ok_t wire_ok[] = { /* 2139 1.1 christos * "". 2140 1.1 christos */ 2141 1.1 christos WIRE_VALID(0x00), 2142 1.1 christos /* 2143 1.1 christos * "\001". 2144 1.1 christos */ 2145 1.1 christos WIRE_VALID(0x01, 0x01), 2146 1.1 christos /* 2147 1.1 christos * "\001" "". 2148 1.1 christos */ 2149 1.1 christos WIRE_VALID(0x01, 0x01, 0x00), 2150 1.1 christos /* 2151 1.1 christos * "\001" "\001". 2152 1.1 christos */ 2153 1.1 christos WIRE_VALID(0x01, 0x01, 0x01, 0x01), 2154 1.1 christos /* 2155 1.1 christos * Sentinel. 2156 1.1 christos */ 2157 1.1 christos WIRE_SENTINEL() 2158 1.1 christos }; 2159 1.1 christos 2160 1.1 christos check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in, 2161 1.1 christos dns_rdatatype_isdn, sizeof(dns_rdata_isdn_t)); 2162 1.1 christos } 2163 1.1 christos 2164 1.1 christos /* 2165 1.1 christos * KEY tests. 2166 1.1 christos */ 2167 1.1 christos ISC_RUN_TEST_IMPL(key) { 2168 1.4 christos wire_ok_t wire_ok[] = { 2169 1.4 christos /* 2170 1.4 christos * RDATA is comprised of: 2171 1.4 christos * 2172 1.4 christos * - 2 octets for Flags, 2173 1.4 christos * - 1 octet for Protocol, 2174 1.4 christos * - 1 octet for Algorithm, 2175 1.4 christos * - variable number of octets for Public Key. 2176 1.4 christos * 2177 1.4 christos * RFC 2535 section 3.1.2 states that if bits 2178 1.4 christos * 0-1 of Flags are both set, the RR stops after 2179 1.4 christos * the algorithm octet and thus its length must 2180 1.4 christos * be 4 octets. In any other case, though, the 2181 1.4 christos * Public Key part must not be empty. 2182 1.4 christos * 2183 1.4 christos * Algorithms PRIVATEDNS (253) and PRIVATEOID (254) 2184 1.4 christos * have an algorithm identifier embedded and the start 2185 1.4 christos * of the public key. 2186 1.4 christos */ 2187 1.4 christos WIRE_INVALID(0x00), WIRE_INVALID(0x00, 0x00), 2188 1.4 christos WIRE_INVALID(0x00, 0x00, 0x00), 2189 1.4 christos WIRE_VALID(0xc0, 0x00, 0x00, 0x00), 2190 1.4 christos WIRE_INVALID(0xc0, 0x00, 0x00, 0x00, 0x00), 2191 1.4 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00), 2192 1.4 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00), 2193 1.5 christos /* PRIVATEDNS example. without key data */ 2194 1.5 christos WIRE_VALID(0x00, 0x00, 0x00, 253, 0x07, 'e', 'x', 'a', 'm', 'p', 2195 1.5 christos 'l', 'e', 0x00), 2196 1.4 christos /* PRIVATEDNS example. + keydata */ 2197 1.4 christos WIRE_VALID(0x00, 0x00, 0x00, 253, 0x07, 'e', 'x', 'a', 'm', 'p', 2198 1.4 christos 'l', 'e', 0x00, 0x00), 2199 1.4 christos /* PRIVATEDNS compression pointer. */ 2200 1.4 christos WIRE_INVALID(0x00, 0x00, 0x00, 253, 0xc0, 0x00, 0x00), 2201 1.4 christos /* PRIVATEOID */ 2202 1.4 christos WIRE_INVALID(0x00, 0x00, 0x00, 254, 0x00), 2203 1.5 christos /* PRIVATEOID 1.3.6.1.4.1.2495 without key data */ 2204 1.5 christos WIRE_VALID(0x00, 0x00, 0x00, 254, 0x09, 0x06, 0x07, 0x2b, 0x06, 2205 1.5 christos 0x01, 0x04, 0x01, 0x93, 0x3f), 2206 1.4 christos /* PRIVATEOID 1.3.6.1.4.1.2495 + keydata */ 2207 1.5 christos WIRE_VALID(0x00, 0x00, 0x00, 254, 0x09, 0x06, 0x07, 0x2b, 0x06, 2208 1.5 christos 0x01, 0x04, 0x01, 0x93, 0x3f, 0x00), 2209 1.4 christos /* PRIVATEOID malformed OID - high-bit set on last octet */ 2210 1.4 christos WIRE_INVALID(0x00, 0x00, 0x00, 254, 0x06, 0x07, 0x2b, 0x06, 2211 1.4 christos 0x01, 0x04, 0x01, 0x93, 0xbf, 0x00), 2212 1.4 christos /* PRIVATEOID malformed OID - wrong tag */ 2213 1.5 christos WIRE_INVALID(0x00, 0x00, 0x00, 254, 0x09, 0x07, 0x07, 0x2b, 2214 1.5 christos 0x06, 0x01, 0x04, 0x01, 0x93, 0x3f, 0x00), 2215 1.4 christos WIRE_SENTINEL() 2216 1.4 christos }; 2217 1.4 christos text_ok_t text_ok[] = { /* PRIVATEDNS example. */ 2218 1.5 christos TEXT_VALID("0 0 253 B2V4YW1wbGUA"), 2219 1.4 christos /* PRIVATEDNS example. + keydata */ 2220 1.4 christos TEXT_VALID("0 0 253 B2V4YW1wbGUAAA=="), 2221 1.4 christos /* PRIVATEDNS compression pointer. */ 2222 1.4 christos TEXT_INVALID("0 0 253 wAAA"), 2223 1.4 christos /* PRIVATEOID */ 2224 1.4 christos TEXT_INVALID("0 0 254 AA=="), 2225 1.4 christos /* PRIVATEOID 1.3.6.1.4.1.2495 */ 2226 1.5 christos TEXT_VALID("0 0 254 CQYHKwYBBAGTPw=="), 2227 1.4 christos /* PRIVATEOID 1.3.6.1.4.1.2495 + keydata */ 2228 1.5 christos TEXT_VALID("0 0 254 CQYHKwYBBAGTPwA="), 2229 1.4 christos /* PRIVATEOID malformed OID - high-bit set on 2230 1.4 christos last octet */ 2231 1.5 christos TEXT_INVALID("0 0 254 CQYHKwYBBAGTvwA="), 2232 1.4 christos /* PRIVATEOID malformed OID - wrong tag */ 2233 1.5 christos TEXT_INVALID("0 0 254 CQcHKwYBBAGTPwA="), 2234 1.4 christos /* 2235 1.4 christos * Sentinel. 2236 1.1 christos */ 2237 1.4 christos TEXT_SENTINEL() 2238 1.1 christos }; 2239 1.1 christos 2240 1.4 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 2241 1.1 christos dns_rdatatype_key, sizeof(dns_rdata_key_t)); 2242 1.1 christos } 2243 1.1 christos 2244 1.1 christos /* 2245 1.1 christos * LOC tests. 2246 1.1 christos */ 2247 1.1 christos ISC_RUN_TEST_IMPL(loc) { 2248 1.1 christos text_ok_t text_ok[] = { 2249 1.1 christos TEXT_VALID_CHANGED("0 N 0 E 0", "0 0 0.000 N 0 0 0.000 E 0.00m " 2250 1.1 christos "1m 10000m 10m"), 2251 1.1 christos TEXT_VALID_CHANGED("0 S 0 W 0", "0 0 0.000 N 0 0 0.000 E 0.00m " 2252 1.1 christos "1m 10000m 10m"), 2253 1.1 christos TEXT_VALID_CHANGED("0 0 N 0 0 E 0", "0 0 0.000 N 0 0 0.000 E " 2254 1.1 christos "0.00m 1m 10000m 10m"), 2255 1.1 christos TEXT_VALID_CHANGED("0 0 0 N 0 0 0 E 0", 2256 1.1 christos "0 0 0.000 N 0 0 0.000 E 0.00m 1m 10000m " 2257 1.1 christos "10m"), 2258 1.1 christos TEXT_VALID_CHANGED("0 0 0 N 0 0 0 E 0", 2259 1.1 christos "0 0 0.000 N 0 0 0.000 E 0.00m 1m 10000m " 2260 1.1 christos "10m"), 2261 1.1 christos TEXT_VALID_CHANGED("0 0 0. N 0 0 0. E 0", 2262 1.1 christos "0 0 0.000 N 0 0 0.000 E 0.00m 1m 10000m " 2263 1.1 christos "10m"), 2264 1.1 christos TEXT_VALID_CHANGED("0 0 .0 N 0 0 .0 E 0", 2265 1.1 christos "0 0 0.000 N 0 0 0.000 E 0.00m 1m 10000m " 2266 1.1 christos "10m"), 2267 1.1 christos TEXT_INVALID("0 North 0 East 0"), 2268 1.1 christos TEXT_INVALID("0 South 0 West 0"), 2269 1.1 christos TEXT_INVALID("0 0 . N 0 0 0. E 0"), 2270 1.1 christos TEXT_INVALID("0 0 0. N 0 0 . E 0"), 2271 1.1 christos TEXT_INVALID("0 0 0. N 0 0 0. E m"), 2272 1.1 christos TEXT_INVALID("0 0 0. N 0 0 0. E 0 ."), 2273 1.1 christos TEXT_INVALID("0 0 0. N 0 0 0. E 0 m"), 2274 1.1 christos TEXT_INVALID("0 0 0. N 0 0 0. E 0 0 ."), 2275 1.1 christos TEXT_INVALID("0 0 0. N 0 0 0. E 0 0 m"), 2276 1.1 christos TEXT_INVALID("0 0 0. N 0 0 0. E 0 0 0 ."), 2277 1.1 christos TEXT_INVALID("0 0 0. N 0 0 0. E 0 0 0 m"), 2278 1.1 christos TEXT_VALID_CHANGED("90 N 180 E 0", "90 0 0.000 N 180 0 0.000 E " 2279 1.1 christos "0.00m 1m 10000m 10m"), 2280 1.1 christos TEXT_INVALID("90 1 N 180 E 0"), 2281 1.1 christos TEXT_INVALID("90 0 1 N 180 E 0"), 2282 1.1 christos TEXT_INVALID("90 N 180 1 E 0"), 2283 1.1 christos TEXT_INVALID("90 N 180 0 1 E 0"), 2284 1.1 christos TEXT_VALID_CHANGED("90 S 180 W 0", "90 0 0.000 S 180 0 0.000 W " 2285 1.1 christos "0.00m 1m 10000m 10m"), 2286 1.1 christos TEXT_INVALID("90 1 S 180 W 0"), 2287 1.1 christos TEXT_INVALID("90 0 1 S 180 W 0"), 2288 1.1 christos TEXT_INVALID("90 S 180 1 W 0"), 2289 1.1 christos TEXT_INVALID("90 S 180 0 1 W 0"), 2290 1.1 christos TEXT_INVALID("0 0 0.000 E 0 0 0.000 E -0.95m 1m 10000m 10m"), 2291 1.1 christos TEXT_VALID("0 0 0.000 N 0 0 0.000 E -0.95m 1m 10000m 10m"), 2292 1.1 christos TEXT_VALID("0 0 0.000 N 0 0 0.000 E -0.05m 1m 10000m 10m"), 2293 1.1 christos TEXT_VALID("0 0 0.000 N 0 0 0.000 E -100000.00m 1m 10000m 10m"), 2294 1.1 christos TEXT_VALID("0 0 0.000 N 0 0 0.000 E 42849672.95m 1m 10000m " 2295 1.1 christos "10m"), 2296 1.1 christos /* 2297 1.1 christos * Sentinel. 2298 1.1 christos */ 2299 1.1 christos TEXT_SENTINEL() 2300 1.1 christos }; 2301 1.1 christos 2302 1.1 christos check_rdata(text_ok, 0, NULL, false, dns_rdataclass_in, 2303 1.1 christos dns_rdatatype_loc, sizeof(dns_rdata_loc_t)); 2304 1.1 christos } 2305 1.1 christos 2306 1.1 christos /* 2307 1.1 christos * http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt 2308 1.1 christos * 2309 1.1 christos * The RDATA portion of both the NIMLOC and EID records contains 2310 1.1 christos * uninterpreted binary data. The representation in the text master file 2311 1.1 christos * is an even number of hex characters (0 to 9, a to f), case is not 2312 1.1 christos * significant. For readability, whitespace may be included in the value 2313 1.1 christos * field and should be ignored when reading a master file. 2314 1.1 christos */ 2315 1.1 christos ISC_RUN_TEST_IMPL(nimloc) { 2316 1.1 christos text_ok_t text_ok[] = { TEXT_VALID("AABBCC"), 2317 1.1 christos TEXT_VALID_CHANGED("AA bb cc", "AABBCC"), 2318 1.1 christos TEXT_INVALID("aab"), 2319 1.1 christos /* 2320 1.1 christos * Sentinel. 2321 1.1 christos */ 2322 1.1 christos TEXT_SENTINEL() }; 2323 1.1 christos wire_ok_t wire_ok[] = { WIRE_VALID(0x00), WIRE_VALID(0xAA, 0xBB, 0xCC), 2324 1.1 christos /* 2325 1.1 christos * Sentinel. 2326 1.1 christos */ 2327 1.1 christos WIRE_SENTINEL() }; 2328 1.1 christos 2329 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 2330 1.1 christos dns_rdatatype_nimloc, sizeof(dns_rdata_in_nimloc_t)); 2331 1.1 christos } 2332 1.1 christos 2333 1.1 christos /* 2334 1.1 christos * NSEC tests. 2335 1.1 christos * 2336 1.1 christos * RFC 4034: 2337 1.1 christos * 2338 1.1 christos * 4.1. NSEC RDATA Wire Format 2339 1.1 christos * 2340 1.1 christos * The RDATA of the NSEC RR is as shown below: 2341 1.1 christos * 2342 1.1 christos * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 2343 1.1 christos * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2344 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2345 1.1 christos * / Next Domain Name / 2346 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2347 1.1 christos * / Type Bit Maps / 2348 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2349 1.1 christos * 2350 1.1 christos * 4.1.1. The Next Domain Name Field 2351 1.1 christos * 2352 1.1 christos * The Next Domain field contains the next owner name (in the canonical 2353 1.1 christos * ordering of the zone) that has authoritative data or contains a 2354 1.1 christos * delegation point NS RRset; see Section 6.1 for an explanation of 2355 1.1 christos * canonical ordering. The value of the Next Domain Name field in the 2356 1.1 christos * last NSEC record in the zone is the name of the zone apex (the owner 2357 1.1 christos * name of the zone's SOA RR). This indicates that the owner name of 2358 1.1 christos * the NSEC RR is the last name in the canonical ordering of the zone. 2359 1.1 christos * 2360 1.1 christos * A sender MUST NOT use DNS name compression on the Next Domain Name 2361 1.1 christos * field when transmitting an NSEC RR. 2362 1.1 christos * 2363 1.1 christos * Owner names of RRsets for which the given zone is not authoritative 2364 1.1 christos * (such as glue records) MUST NOT be listed in the Next Domain Name 2365 1.1 christos * unless at least one authoritative RRset exists at the same owner 2366 1.1 christos * name. 2367 1.1 christos * 2368 1.1 christos * 4.1.2. The Type Bit Maps Field 2369 1.1 christos * 2370 1.1 christos * The Type Bit Maps field identifies the RRset types that exist at the 2371 1.1 christos * NSEC RR's owner name. 2372 1.1 christos * 2373 1.1 christos * The RR type space is split into 256 window blocks, each representing 2374 1.1 christos * the low-order 8 bits of the 16-bit RR type space. Each block that 2375 1.1 christos * has at least one active RR type is encoded using a single octet 2376 1.1 christos * window number (from 0 to 255), a single octet bitmap length (from 1 2377 1.1 christos * to 32) indicating the number of octets used for the window block's 2378 1.1 christos * bitmap, and up to 32 octets (256 bits) of bitmap. 2379 1.1 christos * 2380 1.1 christos * Blocks are present in the NSEC RR RDATA in increasing numerical 2381 1.1 christos * order. 2382 1.1 christos * 2383 1.1 christos * Type Bit Maps Field = ( Window Block # | Bitmap Length | Bitmap )+ 2384 1.1 christos * 2385 1.1 christos * where "|" denotes concatenation. 2386 1.1 christos * 2387 1.1 christos * Each bitmap encodes the low-order 8 bits of RR types within the 2388 1.1 christos * window block, in network bit order. The first bit is bit 0. For 2389 1.1 christos * window block 0, bit 1 corresponds to RR type 1 (A), bit 2 corresponds 2390 1.1 christos * to RR type 2 (NS), and so forth. For window block 1, bit 1 2391 1.1 christos * corresponds to RR type 257, and bit 2 to RR type 258. If a bit is 2392 1.1 christos * set, it indicates that an RRset of that type is present for the NSEC 2393 1.1 christos * RR's owner name. If a bit is clear, it indicates that no RRset of 2394 1.1 christos * that type is present for the NSEC RR's owner name. 2395 1.1 christos * 2396 1.1 christos * Bits representing pseudo-types MUST be clear, as they do not appear 2397 1.1 christos * in zone data. If encountered, they MUST be ignored upon being read. 2398 1.1 christos */ 2399 1.1 christos ISC_RUN_TEST_IMPL(nsec) { 2400 1.1 christos text_ok_t text_ok[] = { TEXT_INVALID(""), TEXT_INVALID("."), 2401 1.1 christos TEXT_VALID(". RRSIG"), TEXT_SENTINEL() }; 2402 1.1 christos wire_ok_t wire_ok[] = { WIRE_INVALID(0x00), WIRE_INVALID(0x00, 0x00), 2403 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00), 2404 1.1 christos WIRE_VALID(0x00, 0x00, 0x01, 0x02), 2405 1.1 christos WIRE_SENTINEL() }; 2406 1.1 christos 2407 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 2408 1.1 christos dns_rdatatype_nsec, sizeof(dns_rdata_nsec_t)); 2409 1.1 christos } 2410 1.1 christos 2411 1.1 christos /* 2412 1.1 christos * NSEC3 tests. 2413 1.1 christos * 2414 1.1 christos * RFC 5155. 2415 1.1 christos */ 2416 1.1 christos ISC_RUN_TEST_IMPL(nsec3) { 2417 1.1 christos text_ok_t text_ok[] = { TEXT_INVALID(""), 2418 1.1 christos TEXT_INVALID("."), 2419 1.1 christos TEXT_INVALID(". RRSIG"), 2420 1.1 christos TEXT_INVALID("1 0 10 76931F"), 2421 1.1 christos TEXT_INVALID("1 0 10 76931F " 2422 1.1 christos "IMQ912BREQP1POLAH3RMONG&" 2423 1.1 christos "UED541AS"), 2424 1.1 christos TEXT_INVALID("1 0 10 76931F " 2425 1.1 christos "IMQ912BREQP1POLAH3RMONGAUED541AS " 2426 1.1 christos "A RRSIG BADTYPE"), 2427 1.1 christos TEXT_VALID("1 0 10 76931F " 2428 1.1 christos "AJHVGTICN6K0VDA53GCHFMT219SRRQLM A " 2429 1.1 christos "RRSIG"), 2430 1.1 christos TEXT_VALID("1 0 10 76931F " 2431 1.1 christos "AJHVGTICN6K0VDA53GCHFMT219SRRQLM"), 2432 1.1 christos TEXT_VALID("1 0 10 - " 2433 1.1 christos "AJHVGTICN6K0VDA53GCHFMT219SRRQLM"), 2434 1.1 christos TEXT_SENTINEL() }; 2435 1.1 christos 2436 1.1 christos check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in, 2437 1.1 christos dns_rdatatype_nsec3, sizeof(dns_rdata_nsec3_t)); 2438 1.1 christos } 2439 1.1 christos 2440 1.1 christos /* NXT RDATA manipulations */ 2441 1.1 christos ISC_RUN_TEST_IMPL(nxt) { 2442 1.1 christos compare_ok_t compare_ok[] = { 2443 1.1 christos COMPARE("a. A SIG", "a. A SIG", 0), 2444 1.1 christos /* 2445 1.1 christos * Records that differ only in the case of the next 2446 1.1 christos * name should be equal. 2447 1.1 christos */ 2448 1.1 christos COMPARE("A. A SIG", "a. A SIG", 0), 2449 1.1 christos /* 2450 1.1 christos * Sorting on name field. 2451 1.1 christos */ 2452 1.1 christos COMPARE("A. A SIG", "b. A SIG", -1), 2453 1.1 christos COMPARE("b. A SIG", "A. A SIG", 1), 2454 1.1 christos /* bit map differs */ 2455 1.1 christos COMPARE("b. A SIG", "b. A AAAA SIG", -1), 2456 1.1 christos /* order of bit map does not matter */ 2457 1.1 christos COMPARE("b. A SIG AAAA", "b. A AAAA SIG", 0), COMPARE_SENTINEL() 2458 1.1 christos }; 2459 1.1 christos 2460 1.1 christos check_rdata(NULL, NULL, compare_ok, false, dns_rdataclass_in, 2461 1.1 christos dns_rdatatype_nxt, sizeof(dns_rdata_nxt_t)); 2462 1.1 christos } 2463 1.1 christos 2464 1.1 christos ISC_RUN_TEST_IMPL(rkey) { 2465 1.1 christos text_ok_t text_ok[] = { /* 2466 1.1 christos * Valid, flags set to 0 and a key is present. 2467 1.1 christos */ 2468 1.1 christos TEXT_VALID("0 0 0 aaaa"), 2469 1.1 christos /* 2470 1.1 christos * Invalid, non-zero flags. 2471 1.1 christos */ 2472 1.1 christos TEXT_INVALID("1 0 0 aaaa"), 2473 1.1 christos TEXT_INVALID("65535 0 0 aaaa"), 2474 1.1 christos /* 2475 1.1 christos * Sentinel. 2476 1.1 christos */ 2477 1.1 christos TEXT_SENTINEL() 2478 1.1 christos }; 2479 1.1 christos wire_ok_t wire_ok[] = { /* 2480 1.1 christos * Valid, flags set to 0 and a key is present. 2481 1.1 christos */ 2482 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00), 2483 1.1 christos /* 2484 1.1 christos * Invalid, non-zero flags. 2485 1.1 christos */ 2486 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x00), 2487 1.1 christos WIRE_INVALID(0xff, 0xff, 0x00, 0x00, 0x00), 2488 1.1 christos /* 2489 1.1 christos * Sentinel. 2490 1.1 christos */ 2491 1.1 christos WIRE_SENTINEL() 2492 1.1 christos }; 2493 1.1 christos key_required(state, dns_rdatatype_rkey, sizeof(dns_rdata_rkey_t)); 2494 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 2495 1.1 christos dns_rdatatype_rkey, sizeof(dns_rdata_rkey_t)); 2496 1.1 christos } 2497 1.1 christos 2498 1.3 christos ISC_RUN_TEST_IMPL(resinfo) { 2499 1.3 christos text_ok_t text_ok[] = { 2500 1.3 christos TEXT_VALID_CHANGED("qnamemin exterr=15,16,17 " 2501 1.3 christos "infourl=https://resolver.example.com/guide", 2502 1.3 christos "\"qnamemin\" \"exterr=15,16,17\" " 2503 1.3 christos "\"infourl=https://resolver.example.com/" 2504 1.3 christos "guide\""), 2505 1.3 christos /* 2506 1.3 christos * Sentinel. 2507 1.3 christos */ 2508 1.3 christos TEXT_SENTINEL() 2509 1.3 christos }; 2510 1.3 christos check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in, 2511 1.3 christos dns_rdatatype_resinfo, sizeof(dns_rdata_rkey_t)); 2512 1.3 christos } 2513 1.3 christos 2514 1.1 christos /* SSHFP RDATA manipulations */ 2515 1.1 christos ISC_RUN_TEST_IMPL(sshfp) { 2516 1.1 christos text_ok_t text_ok[] = { TEXT_INVALID(""), /* too short */ 2517 1.1 christos TEXT_INVALID("0"), /* reserved, too short */ 2518 1.1 christos TEXT_VALID("0 0"), /* no finger print */ 2519 1.1 christos TEXT_VALID("0 0 AA"), /* reserved */ 2520 1.1 christos TEXT_INVALID("0 1 AA"), /* too short SHA 1 2521 1.1 christos * digest */ 2522 1.1 christos TEXT_INVALID("0 2 AA"), /* too short SHA 256 2523 1.1 christos * digest */ 2524 1.1 christos TEXT_VALID("0 3 AA"), /* unknown finger print 2525 1.1 christos * type */ 2526 1.1 christos /* good length SHA 1 digest */ 2527 1.1 christos TEXT_VALID("1 1 " 2528 1.1 christos "00112233445566778899AABBCCDDEEFF171" 2529 1.1 christos "81920"), 2530 1.1 christos /* good length SHA 256 digest */ 2531 1.1 christos TEXT_VALID("4 2 " 2532 1.1 christos "A87F1B687AC0E57D2A081A2F282672334D9" 2533 1.1 christos "0ED316D2B818CA9580EA3 84D92401"), 2534 1.1 christos /* 2535 1.1 christos * totext splits the fingerprint into chunks and 2536 1.1 christos * emits uppercase hex. 2537 1.1 christos */ 2538 1.1 christos TEXT_VALID_CHANGED("1 2 " 2539 1.1 christos "00112233445566778899aabbccd" 2540 1.1 christos "deeff " 2541 1.1 christos "00112233445566778899AABBCCD" 2542 1.1 christos "DEEFF", 2543 1.1 christos "1 2 " 2544 1.1 christos "00112233445566778899AABBCCD" 2545 1.1 christos "DEEFF" 2546 1.1 christos "00112233445566778899AABB " 2547 1.1 christos "CCDDEEFF"), 2548 1.1 christos TEXT_SENTINEL() }; 2549 1.1 christos wire_ok_t wire_ok[] = { 2550 1.1 christos WIRE_INVALID(0x00), /* reserved too short */ 2551 1.1 christos WIRE_VALID(0x00, 0x00), /* reserved no finger print */ 2552 1.1 christos WIRE_VALID(0x00, 0x00, 0x00), /* reserved */ 2553 1.1 christos 2554 1.1 christos /* too short SHA 1 digests */ 2555 1.1 christos WIRE_INVALID(0x00, 0x01), WIRE_INVALID(0x00, 0x01, 0x00), 2556 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 2557 1.1 christos 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 2558 1.1 christos 0xEE, 0xFF, 0x17, 0x18, 0x19), 2559 1.1 christos /* good length SHA 1 digest */ 2560 1.1 christos WIRE_VALID(0x00, 0x01, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 2561 1.1 christos 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 2562 1.1 christos 0x17, 0x18, 0x19, 0x20), 2563 1.1 christos /* too long SHA 1 digest */ 2564 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 2565 1.1 christos 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 2566 1.1 christos 0xEE, 0xFF, 0x17, 0x18, 0x19, 0x20, 0x21), 2567 1.1 christos /* too short SHA 256 digests */ 2568 1.1 christos WIRE_INVALID(0x00, 0x02), WIRE_INVALID(0x00, 0x02, 0x00), 2569 1.1 christos WIRE_INVALID(0x00, 0x02, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 2570 1.1 christos 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 2571 1.1 christos 0xEE, 0xFF, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 2572 1.1 christos 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 2573 1.1 christos 0x31), 2574 1.1 christos /* good length SHA 256 digest */ 2575 1.1 christos WIRE_VALID(0x00, 0x02, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 2576 1.1 christos 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 2577 1.1 christos 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 2578 1.1 christos 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32), 2579 1.1 christos /* too long SHA 256 digest */ 2580 1.1 christos WIRE_INVALID(0x00, 0x02, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 2581 1.1 christos 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 2582 1.1 christos 0xEE, 0xFF, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 2583 1.1 christos 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 2584 1.1 christos 0x31, 0x32, 0x33), 2585 1.1 christos /* unknown digest, * no fingerprint */ 2586 1.1 christos WIRE_VALID(0x00, 0x03), WIRE_VALID(0x00, 0x03, 0x00), /* unknown 2587 1.1 christos * digest 2588 1.1 christos */ 2589 1.1 christos WIRE_SENTINEL() 2590 1.1 christos }; 2591 1.1 christos 2592 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 2593 1.1 christos dns_rdatatype_sshfp, sizeof(dns_rdata_sshfp_t)); 2594 1.1 christos } 2595 1.1 christos 2596 1.4 christos ISC_RUN_TEST_IMPL(wallet) { 2597 1.4 christos text_ok_t text_ok[] = { TEXT_VALID_CHANGED("cid-example wid-example", 2598 1.4 christos "\"cid-example\" " 2599 1.4 christos "\"wid-example\""), 2600 1.4 christos /* 2601 1.4 christos * Sentinel. 2602 1.4 christos */ 2603 1.4 christos TEXT_SENTINEL() }; 2604 1.4 christos check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in, 2605 1.4 christos dns_rdatatype_wallet, sizeof(dns_rdata_rkey_t)); 2606 1.4 christos } 2607 1.4 christos 2608 1.1 christos /* 2609 1.1 christos * WKS tests. 2610 1.1 christos * 2611 1.1 christos * RFC 1035: 2612 1.1 christos * 2613 1.1 christos * 3.4.2. WKS RDATA format 2614 1.1 christos * 2615 1.1 christos * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2616 1.1 christos * | ADDRESS | 2617 1.1 christos * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2618 1.1 christos * | PROTOCOL | | 2619 1.1 christos * +--+--+--+--+--+--+--+--+ | 2620 1.1 christos * | | 2621 1.1 christos * / <BIT MAP> / 2622 1.1 christos * / / 2623 1.1 christos * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2624 1.1 christos * 2625 1.1 christos * where: 2626 1.1 christos * 2627 1.1 christos * ADDRESS An 32 bit Internet address 2628 1.1 christos * 2629 1.1 christos * PROTOCOL An 8 bit IP protocol number 2630 1.1 christos * 2631 1.1 christos * <BIT MAP> A variable length bit map. The bit map must be a 2632 1.1 christos * multiple of 8 bits long. 2633 1.1 christos * 2634 1.1 christos * The WKS record is used to describe the well known services supported by 2635 1.1 christos * a particular protocol on a particular internet address. The PROTOCOL 2636 1.1 christos * field specifies an IP protocol number, and the bit map has one bit per 2637 1.1 christos * port of the specified protocol. The first bit corresponds to port 0, 2638 1.1 christos * the second to port 1, etc. If the bit map does not include a bit for a 2639 1.1 christos * protocol of interest, that bit is assumed zero. The appropriate values 2640 1.1 christos * and mnemonics for ports and protocols are specified in [RFC-1010]. 2641 1.1 christos * 2642 1.1 christos * For example, if PROTOCOL=TCP (6), the 26th bit corresponds to TCP port 2643 1.1 christos * 25 (SMTP). If this bit is set, a SMTP server should be listening on TCP 2644 1.1 christos * port 25; if zero, SMTP service is not supported on the specified 2645 1.1 christos * address. 2646 1.1 christos */ 2647 1.1 christos ISC_RUN_TEST_IMPL(wks) { 2648 1.1 christos text_ok_t text_ok[] = { /* 2649 1.1 christos * Valid, IPv4 address in dotted-quad form. 2650 1.1 christos */ 2651 1.1 christos TEXT_VALID("127.0.0.1 6"), 2652 1.1 christos /* 2653 1.1 christos * Invalid, IPv4 address not in dotted-quad 2654 1.1 christos * form. 2655 1.1 christos */ 2656 1.1 christos TEXT_INVALID("127.1 6"), 2657 1.1 christos /* 2658 1.1 christos * Sentinel. 2659 1.1 christos */ 2660 1.1 christos TEXT_SENTINEL() 2661 1.1 christos }; 2662 1.1 christos wire_ok_t wire_ok[] = { /* 2663 1.1 christos * Too short. 2664 1.1 christos */ 2665 1.1 christos WIRE_INVALID(0x00, 0x08, 0x00, 0x00), 2666 1.1 christos /* 2667 1.1 christos * Minimal TCP. 2668 1.1 christos */ 2669 1.1 christos WIRE_VALID(0x00, 0x08, 0x00, 0x00, 6), 2670 1.1 christos /* 2671 1.1 christos * Minimal UDP. 2672 1.1 christos */ 2673 1.1 christos WIRE_VALID(0x00, 0x08, 0x00, 0x00, 17), 2674 1.1 christos /* 2675 1.1 christos * Minimal other. 2676 1.1 christos */ 2677 1.1 christos WIRE_VALID(0x00, 0x08, 0x00, 0x00, 1), 2678 1.1 christos /* 2679 1.1 christos * Sentinel. 2680 1.1 christos */ 2681 1.1 christos WIRE_SENTINEL() 2682 1.1 christos }; 2683 1.1 christos 2684 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 2685 1.1 christos dns_rdatatype_wks, sizeof(dns_rdata_in_wks_t)); 2686 1.1 christos } 2687 1.1 christos 2688 1.1 christos ISC_RUN_TEST_IMPL(https_svcb) { 2689 1.1 christos /* 2690 1.1 christos * Known keys: mandatory, apln, no-default-alpn, port, 2691 1.1 christos * ipv4hint, port, ipv6hint, dohpath. 2692 1.1 christos */ 2693 1.1 christos text_ok_t text_ok[] = { 2694 1.1 christos /* unknown key invalid */ 2695 1.1 christos TEXT_INVALID("1 . unknown="), 2696 1.1 christos /* no domain */ 2697 1.1 christos TEXT_INVALID("0"), 2698 1.1 christos /* minimal record */ 2699 1.1 christos TEXT_VALID_LOOP(0, "0 ."), 2700 1.3 christos /* Alias form possible future extension */ 2701 1.3 christos TEXT_VALID_LOOP(1, "0 . alpn=\"h2\""), 2702 1.1 christos /* no "key" prefix */ 2703 1.1 christos TEXT_INVALID("2 svc.example.net. 0=\"2222\""), 2704 1.1 christos /* no key value */ 2705 1.1 christos TEXT_INVALID("2 svc.example.net. key"), 2706 1.1 christos /* no key value */ 2707 1.1 christos TEXT_INVALID("2 svc.example.net. key=\"2222\""), 2708 1.1 christos /* zero pad invalid */ 2709 1.1 christos TEXT_INVALID("2 svc.example.net. key07=\"2222\""), 2710 1.1 christos TEXT_VALID_LOOP(1, "2 svc.example.net. key8=\"2222\""), 2711 1.1 christos TEXT_VALID_LOOPCHG(1, "2 svc.example.net. key8=2222", 2712 1.1 christos "2 svc.example.net. key8=\"2222\""), 2713 1.1 christos TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h2", 2714 1.1 christos "2 svc.example.net. alpn=\"h2\""), 2715 1.1 christos TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h3", 2716 1.1 christos "2 svc.example.net. alpn=\"h3\""), 2717 1.1 christos /* alpn has 2 sub field "h2" and "h3" */ 2718 1.1 christos TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h2,h3", 2719 1.1 christos "2 svc.example.net. alpn=\"h2,h3\""), 2720 1.1 christos /* apln has 2 sub fields "h1,h2" and "h3" (comma escaped) */ 2721 1.1 christos TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h1\\\\,h2,h3", 2722 1.1 christos "2 svc.example.net. alpn=\"h1\\\\,h2,h3\""), 2723 1.1 christos TEXT_VALID_LOOP(1, "2 svc.example.net. port=50"), 2724 1.1 christos /* no-default-alpn, alpn is required */ 2725 1.1 christos TEXT_INVALID("2 svc.example.net. no-default-alpn"), 2726 1.1 christos /* no-default-alpn with alpn present */ 2727 1.1 christos TEXT_VALID_LOOPCHG( 2728 1.1 christos 2, "2 svc.example.net. no-default-alpn alpn=h2", 2729 1.1 christos "2 svc.example.net. alpn=\"h2\" no-default-alpn"), 2730 1.1 christos /* empty hint */ 2731 1.1 christos TEXT_INVALID("2 svc.example.net. ipv4hint="), 2732 1.1 christos TEXT_VALID_LOOP(1, "2 svc.example.net. " 2733 1.1 christos "ipv4hint=10.50.0.1,10.50.0.2"), 2734 1.1 christos /* empty hint */ 2735 1.1 christos TEXT_INVALID("2 svc.example.net. ipv6hint="), 2736 1.1 christos TEXT_VALID_LOOP(1, "2 svc.example.net. ipv6hint=::1,2002::1"), 2737 1.1 christos TEXT_VALID_LOOP(1, "2 svc.example.net. ech=abcdefghijkl"), 2738 1.1 christos /* bad base64 */ 2739 1.1 christos TEXT_INVALID("2 svc.example.net. ech=abcdefghijklm"), 2740 1.1 christos TEXT_VALID_LOOP(1, "2 svc.example.net. key8=\"2222\""), 2741 1.1 christos /* Out of key order on input (alpn == key1). */ 2742 1.1 christos TEXT_VALID_LOOPCHG(2, 2743 1.1 christos "2 svc.example.net. key8=\"2222\" alpn=h2", 2744 1.1 christos "2 svc.example.net. alpn=\"h2\" " 2745 1.1 christos "key8=\"2222\""), 2746 1.1 christos TEXT_VALID_LOOP(1, "2 svc.example.net. key65535=\"2222\""), 2747 1.1 christos TEXT_INVALID("2 svc.example.net. key65536=\"2222\""), 2748 1.1 christos TEXT_VALID_LOOP(1, "2 svc.example.net. key10"), 2749 1.1 christos TEXT_VALID_LOOPCHG(1, "2 svc.example.net. key11=", 2750 1.1 christos "2 svc.example.net. key11"), 2751 1.1 christos TEXT_VALID_LOOPCHG(1, "2 svc.example.net. key12=\"\"", 2752 1.1 christos "2 svc.example.net. key12"), 2753 1.1 christos /* empty alpn-id sub fields */ 2754 1.1 christos TEXT_INVALID("2 svc.example.net. alpn"), 2755 1.1 christos TEXT_INVALID("2 svc.example.net. alpn="), 2756 1.1 christos TEXT_INVALID("2 svc.example.net. alpn=,h1"), 2757 1.1 christos TEXT_INVALID("2 svc.example.net. alpn=h1,"), 2758 1.1 christos TEXT_INVALID("2 svc.example.net. alpn=h1,,h2"), 2759 1.3 christos /* empty alpn-id sub fields - RFC 1035 escaped commas */ 2760 1.3 christos TEXT_INVALID("2 svc.example.net. alpn=\\,abc"), 2761 1.3 christos TEXT_INVALID("2 svc.example.net. alpn=abc\\,"), 2762 1.3 christos TEXT_INVALID("2 svc.example.net. alpn=a\\,\\,abc"), 2763 1.1 christos /* mandatory */ 2764 1.1 christos TEXT_VALID_LOOP(2, "2 svc.example.net. mandatory=alpn " 2765 1.1 christos "alpn=\"h2\""), 2766 1.1 christos TEXT_VALID_LOOP(3, "2 svc.example.net. mandatory=alpn,port " 2767 1.1 christos "alpn=\"h2\" port=443"), 2768 1.1 christos TEXT_VALID_LOOPCHG(3, 2769 1.1 christos "2 svc.example.net. mandatory=port,alpn " 2770 1.1 christos "alpn=\"h2\" port=443", 2771 1.1 christos "2 svc.example.net. mandatory=alpn,port " 2772 1.1 christos "alpn=\"h2\" port=443"), 2773 1.1 christos TEXT_INVALID("2 svc.example.net. mandatory=mandatory"), 2774 1.1 christos TEXT_INVALID("2 svc.example.net. mandatory=port"), 2775 1.1 christos TEXT_INVALID("2 svc.example.net. mandatory=,port port=433"), 2776 1.1 christos TEXT_INVALID("2 svc.example.net. mandatory=port, port=433"), 2777 1.1 christos TEXT_INVALID("2 svc.example.net. " 2778 1.1 christos "mandatory=alpn,,port alpn=h2 port=433"), 2779 1.1 christos /* mandatory w/ unknown key values */ 2780 1.1 christos TEXT_VALID_LOOP(2, "2 svc.example.net. mandatory=key8 key8"), 2781 1.1 christos TEXT_VALID_LOOP(3, "2 svc.example.net. mandatory=key8,key9 " 2782 1.1 christos "key8 key9"), 2783 1.1 christos TEXT_VALID_LOOPCHG( 2784 1.1 christos 3, "2 svc.example.net. mandatory=key9,key8 key8 key9", 2785 1.1 christos "2 svc.example.net. mandatory=key8,key9 key8 key9"), 2786 1.1 christos TEXT_INVALID("2 svc.example.net. " 2787 1.1 christos "mandatory=key8,key8"), 2788 1.1 christos TEXT_INVALID("2 svc.example.net. mandatory=,key8"), 2789 1.1 christos TEXT_INVALID("2 svc.example.net. mandatory=key8,"), 2790 1.1 christos TEXT_INVALID("2 svc.example.net. " 2791 1.1 christos "mandatory=key8,,key8"), 2792 1.1 christos /* Invalid test vectors */ 2793 1.1 christos TEXT_INVALID("1 foo.example.com. ( key123=abc key123=def )"), 2794 1.1 christos TEXT_INVALID("1 foo.example.com. mandatory"), 2795 1.1 christos TEXT_INVALID("1 foo.example.com. alpn"), 2796 1.1 christos TEXT_INVALID("1 foo.example.com. port"), 2797 1.1 christos TEXT_INVALID("1 foo.example.com. ipv4hint"), 2798 1.1 christos TEXT_INVALID("1 foo.example.com. ipv6hint"), 2799 1.1 christos TEXT_INVALID("1 foo.example.com. no-default-alpn=abc"), 2800 1.1 christos TEXT_INVALID("1 foo.example.com. mandatory=key123"), 2801 1.1 christos TEXT_INVALID("1 foo.example.com. mandatory=mandatory"), 2802 1.1 christos TEXT_INVALID("1 foo.example.com. ( mandatory=key123,key123 " 2803 1.1 christos "key123=abc)"), 2804 1.1 christos /* dohpath tests */ 2805 1.4 christos TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/{dns}", 2806 1.4 christos "1 example.net. key7=\"/{dns}\""), 2807 1.4 christos TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/{+dns}", 2808 1.4 christos "1 example.net. key7=\"/{+dns}\""), 2809 1.4 christos TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/{#dns}", 2810 1.4 christos "1 example.net. key7=\"/{#dns}\""), 2811 1.4 christos TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/{.dns}", 2812 1.4 christos "1 example.net. key7=\"/{.dns}\""), 2813 1.4 christos TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=\"/{;dns}\"", 2814 1.4 christos "1 example.net. key7=\"/{;dns}\""), 2815 1.1 christos TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/{?dns}", 2816 1.1 christos "1 example.net. key7=\"/{?dns}\""), 2817 1.1 christos TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/some/path{?dns}", 2818 1.1 christos "1 example.net. key7=\"/some/path{?dns}\""), 2819 1.4 christos TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/{dns:9999}", 2820 1.4 christos "1 example.net. key7=\"/{dns:9999}\""), 2821 1.4 christos TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/{dns*}", 2822 1.4 christos "1 example.net. key7=\"/{dns*}\""), 2823 1.4 christos TEXT_VALID_LOOPCHG( 2824 1.4 christos 1, "1 example.net. dohpath=/some/path?key=value{&dns}", 2825 1.4 christos "1 example.net. key7=\"/some/path?key=value{&dns}\""), 2826 1.4 christos TEXT_VALID_LOOPCHG(1, 2827 1.4 christos "1 example.net. " 2828 1.4 christos "dohpath=/some/path?key=value{&dns,x*}", 2829 1.4 christos "1 example.net. " 2830 1.4 christos "key7=\"/some/path?key=value{&dns,x*}\""), 2831 1.4 christos TEXT_INVALID("1 example.com. dohpath=not-relative"), 2832 1.4 christos TEXT_INVALID("1 example.com. dohpath=/{?no_dns_variable}"), 2833 1.4 christos TEXT_INVALID("1 example.com. dohpath=/novariable"), 2834 1.4 christos TEXT_INVALID("1 example.com. dohpath=/{?dnsx}"), 2835 1.4 christos /* index too big > 9999 */ 2836 1.4 christos TEXT_INVALID("1 example.com. dohpath=/{?dns:10000}"), 2837 1.4 christos /* index not postive */ 2838 1.4 christos TEXT_INVALID("1 example.com. dohpath=/{?dns:0}"), 2839 1.4 christos /* index leading zero */ 2840 1.4 christos TEXT_INVALID("1 example.com. dohpath=/{?dns:01}"), 2841 1.4 christos /* two operators */ 2842 1.4 christos TEXT_INVALID("1 example.com. dohpath=/{??dns}"), 2843 1.4 christos /* invalid % encoding */ 2844 1.4 christos TEXT_INVALID("1 example.com. dohpath=/%a{?dns}"), 2845 1.4 christos /* invalid % encoding */ 2846 1.4 christos TEXT_INVALID("1 example.com. dohpath=/{?dns,%a}"), 2847 1.4 christos /* incomplete macro */ 2848 1.4 christos TEXT_INVALID("1 example.com. dohpath=/{?dns" /*}*/), 2849 1.1 christos TEXT_SENTINEL() 2850 1.1 christos 2851 1.1 christos }; 2852 1.1 christos wire_ok_t wire_ok[] = { 2853 1.1 christos /* 2854 1.1 christos * Too short 2855 1.1 christos */ 2856 1.1 christos WIRE_INVALID(0x00, 0x00), 2857 1.1 christos /* 2858 1.1 christos * Minimal length record. 2859 1.1 christos */ 2860 1.1 christos WIRE_VALID(0x00, 0x00, 0x00), 2861 1.1 christos /* 2862 1.3 christos * Alias with invalid dohpath. 2863 1.1 christos */ 2864 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00), 2865 1.1 christos /* 2866 1.1 christos * Bad key7= length (longer than rdata). 2867 1.1 christos */ 2868 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x07, 0x00, 0x01), 2869 1.1 christos /* 2870 1.1 christos * Port (0x03) too small (zero and one octets). 2871 1.1 christos */ 2872 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00), 2873 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00), 2874 1.1 christos /* Valid port */ 2875 1.1 christos WIRE_VALID_LOOP(1, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x02, 2876 1.1 christos 0x00, 0x00), 2877 1.1 christos /* 2878 1.1 christos * Port (0x03) too big (three octets). 2879 1.1 christos */ 2880 1.1 christos WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 2881 1.1 christos 0x00, 0x00), 2882 1.1 christos /* 2883 1.1 christos * Duplicate keys. 2884 1.1 christos */ 2885 1.1 christos WIRE_INVALID(0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 2886 1.1 christos 0x80, 0x00, 0x00), 2887 1.1 christos /* 2888 1.1 christos * Out of order keys. 2889 1.1 christos */ 2890 1.1 christos WIRE_INVALID(0x01, 0x01, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 2891 1.1 christos 0x80, 0x00, 0x00), 2892 1.1 christos /* 2893 1.1 christos * Empty of mandatory key list. 2894 1.1 christos */ 2895 1.1 christos WIRE_INVALID(0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00), 2896 1.1 christos /* 2897 1.1 christos * "mandatory=mandatory" is invalid 2898 1.1 christos */ 2899 1.1 christos WIRE_INVALID(0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 2900 1.1 christos 0x00), 2901 1.1 christos /* 2902 1.1 christos * Out of order mandatory key list. 2903 1.1 christos */ 2904 1.1 christos WIRE_INVALID(0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 2905 1.1 christos 0x80, 0x00, 0x71, 0x00, 0x71, 0x00, 0x00, 0x00, 2906 1.1 christos 0x80, 0x00, 0x00), 2907 1.1 christos /* 2908 1.1 christos * Alpn(0x00 0x01) (length 0x00 0x09) "h1,h2" + "h3" 2909 1.1 christos */ 2910 1.1 christos WIRE_VALID_LOOP(0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x09, 2911 1.1 christos 5, 'h', '1', ',', 'h', '2', 2, 'h', '3'), 2912 1.1 christos /* 2913 1.1 christos * Alpn(0x00 0x01) (length 0x00 0x09) "h1\h2" + "h3" 2914 1.1 christos */ 2915 1.1 christos WIRE_VALID_LOOP(0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x09, 2916 1.1 christos 5, 'h', '1', '\\', 'h', '2', 2, 'h', '3'), 2917 1.1 christos /* 2918 1.1 christos * no-default-alpn (0x00 0x02) without alpn, alpn is required. 2919 1.1 christos */ 2920 1.1 christos WIRE_INVALID(0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00), 2921 1.1 christos /* 2922 1.1 christos * Alpn(0x00 0x01) with zero length elements is invalid 2923 1.1 christos */ 2924 1.1 christos WIRE_INVALID(0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x05, 2925 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00), 2926 1.1 christos WIRE_SENTINEL() 2927 1.1 christos }; 2928 1.1 christos /* Test vectors from RFCXXXX */ 2929 1.1 christos textvsunknown_t textvsunknown[] = { 2930 1.1 christos /* AliasForm */ 2931 1.1 christos { "0 foo.example.com", "\\# 19 ( 00 00 03 66 6f 6f 07 65 78 61 " 2932 1.1 christos "6d 70 6c 65 03 63 6f 6d 00)" }, 2933 1.1 christos /* ServiceForm */ 2934 1.1 christos { "1 .", "\\# 3 ( 00 01 00)" }, 2935 1.1 christos /* Port example */ 2936 1.1 christos { "16 foo.example.com port=53", 2937 1.1 christos "\\# 25 ( 00 10 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 63 6f " 2938 1.1 christos "6d 00 00 03 00 02 00 35 )" }, 2939 1.1 christos /* Unregistered keys with unquoted value. */ 2940 1.1 christos { "1 foo.example.com key667=hello", 2941 1.1 christos "\\# 28 ( 00 01 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 63 6f " 2942 1.1 christos "6d 00 02 9b 00 05 68 65 6c 6c 6f )" }, 2943 1.1 christos /* 2944 1.1 christos * Quoted decimal-escaped character. 2945 1.1 christos * 1 foo.example.com key667="hello\210qoo" 2946 1.1 christos */ 2947 1.1 christos { "1 foo.example.com key667=\"hello\\210qoo\"", 2948 1.1 christos "\\# 32 ( 00 01 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 63 6f " 2949 1.1 christos "6d 00 02 9b 00 09 68 65 6c 6c 6f d2 71 6f 6f )" }, 2950 1.1 christos /* 2951 1.1 christos * IPv6 hints example, quoted. 2952 1.1 christos * 1 foo.example.com ipv6hint="2001:db8::1,2001:db8::53:1" 2953 1.1 christos */ 2954 1.1 christos { "1 foo.example.com ipv6hint=\"2001:db8::1,2001:db8::53:1\"", 2955 1.1 christos "\\# 55 ( 00 01 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 63 6f " 2956 1.1 christos "6d 00 00 06 00 20 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 " 2957 1.1 christos "00 01 20 01 0d b8 00 00 00 00 00 00 00 00 00 53 00 01 )" }, 2958 1.1 christos /* SvcParamValues and mandatory out of order. */ 2959 1.1 christos { "16 foo.example.org alpn=h2,h3-19 mandatory=ipv4hint,alpn " 2960 1.1 christos "ipv4hint=192.0.2.1", 2961 1.1 christos "\\# 48 ( 00 10 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 6f 72 " 2962 1.1 christos "67 00 00 00 00 04 00 01 00 04 00 01 00 09 02 68 32 05 68 33 " 2963 1.1 christos "2d 31 39 00 04 00 04 c0 00 02 01 )" }, 2964 1.1 christos /* 2965 1.1 christos * Quoted ALPN with escaped comma and backslash. 2966 1.1 christos * 16 foo.example.org alpn="f\\\\oo\\,bar,h2" 2967 1.1 christos */ 2968 1.1 christos { "16 foo.example.org alpn=\"f\\\\\\\\oo\\\\,bar,h2\"", 2969 1.1 christos "\\# 35 ( 00 10 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 6f 72 " 2970 1.1 christos "67 00 00 01 00 0c 08 66 5c 6f 6f 2c 62 61 72 02 68 32 )" }, 2971 1.1 christos /* 2972 1.1 christos * Unquoted ALPN with escaped comma and backslash. 2973 1.1 christos * 16 foo.example.org alpn=f\\\092oo\092,bar,h2 2974 1.1 christos */ 2975 1.1 christos { "16 foo.example.org alpn=f\\\\\\092oo\\092,bar,h2", 2976 1.1 christos "\\# 35 ( 00 10 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 6f 72 " 2977 1.1 christos "67 00 00 01 00 0c 08 66 5c 6f 6f 2c 62 61 72 02 68 32 )" }, 2978 1.1 christos { NULL, NULL } 2979 1.1 christos }; 2980 1.1 christos 2981 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 2982 1.1 christos dns_rdatatype_svcb, sizeof(dns_rdata_in_svcb_t)); 2983 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 2984 1.1 christos dns_rdatatype_https, sizeof(dns_rdata_in_https_t)); 2985 1.1 christos 2986 1.1 christos check_textvsunknown(textvsunknown, dns_rdataclass_in, 2987 1.1 christos dns_rdatatype_svcb); 2988 1.1 christos check_textvsunknown(textvsunknown, dns_rdataclass_in, 2989 1.1 christos dns_rdatatype_https); 2990 1.1 christos } 2991 1.1 christos 2992 1.1 christos /* 2993 1.1 christos * ZONEMD tests. 2994 1.1 christos * 2995 1.1 christos * Excerpted from RFC 8976: 2996 1.1 christos * 2997 1.1 christos * The ZONEMD RDATA wire format is encoded as follows: 2998 1.1 christos * 2999 1.1 christos * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3000 1.1 christos * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 3001 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 3002 1.1 christos * | Serial | 3003 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 3004 1.1 christos * | Scheme |Hash Algorithm | | 3005 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 3006 1.1 christos * | Digest | 3007 1.1 christos * / / 3008 1.1 christos * / / 3009 1.1 christos * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 3010 1.1 christos * 3011 1.1 christos * 2.2.1. The Serial Field 3012 1.1 christos * 3013 1.1 christos * The Serial field is a 32-bit unsigned integer in network byte order. 3014 1.1 christos * It is the serial number from the zone's SOA record ([RFC1035], 3015 1.1 christos * Section 3.3.13) for which the zone digest was generated. 3016 1.1 christos * 3017 1.1 christos * It is included here to clearly bind the ZONEMD RR to a particular 3018 1.1 christos * version of the zone's content. Without the serial number, a stand- 3019 1.1 christos * alone ZONEMD digest has no obvious association to any particular 3020 1.1 christos * instance of a zone. 3021 1.1 christos * 3022 1.1 christos * 2.2.2. The Scheme Field 3023 1.1 christos * 3024 1.1 christos * The Scheme field is an 8-bit unsigned integer that identifies the 3025 1.1 christos * methods by which data is collated and presented as input to the 3026 1.1 christos * hashing function. 3027 1.1 christos * 3028 1.1 christos * Herein, SIMPLE, with Scheme value 1, is the only standardized Scheme 3029 1.1 christos * defined for ZONEMD records and it MUST be supported by 3030 1.1 christos * implementations. The "ZONEMD Schemes" registry is further described 3031 1.1 christos * in Section 5. 3032 1.1 christos * 3033 1.1 christos * Scheme values 240-254 are allocated for Private Use. 3034 1.1 christos * 3035 1.1 christos * 2.2.3. The Hash Algorithm Field 3036 1.1 christos * 3037 1.1 christos * The Hash Algorithm field is an 8-bit unsigned integer that identifies 3038 1.1 christos * the cryptographic hash algorithm used to construct the digest. 3039 1.1 christos * 3040 1.1 christos * Herein, SHA384 ([RFC6234]), with Hash Algorithm value 1, is the only 3041 1.1 christos * standardized Hash Algorithm defined for ZONEMD records that MUST be 3042 1.1 christos * supported by implementations. When SHA384 is used, the size of the 3043 1.1 christos * Digest field is 48 octets. The result of the SHA384 digest algorithm 3044 1.1 christos * MUST NOT be truncated, and the entire 48-octet digest is published in 3045 1.1 christos * the ZONEMD record. 3046 1.1 christos * 3047 1.1 christos * SHA512 ([RFC6234]), with Hash Algorithm value 2, is also defined for 3048 1.1 christos * ZONEMD records and SHOULD be supported by implementations. When 3049 1.1 christos * SHA512 is used, the size of the Digest field is 64 octets. The 3050 1.1 christos * result of the SHA512 digest algorithm MUST NOT be truncated, and the 3051 1.1 christos * entire 64-octet digest is published in the ZONEMD record. 3052 1.1 christos * 3053 1.1 christos * Hash Algorithm values 240-254 are allocated for Private Use. 3054 1.1 christos * 3055 1.1 christos * The "ZONEMD Hash Algorithms" registry is further described in 3056 1.1 christos * Section 5. 3057 1.1 christos * 3058 1.1 christos * 2.2.4. The Digest Field 3059 1.1 christos * 3060 1.1 christos * The Digest field is a variable-length sequence of octets containing 3061 1.1 christos * the output of the hash algorithm. The length of the Digest field is 3062 1.1 christos * determined by deducting the fixed size of the Serial, Scheme, and 3063 1.1 christos * Hash Algorithm fields from the RDATA size in the ZONEMD RR header. 3064 1.1 christos * 3065 1.1 christos * The Digest field MUST NOT be shorter than 12 octets. Digests for the 3066 1.1 christos * SHA384 and SHA512 hash algorithms specified herein are never 3067 1.1 christos * truncated. Digests for future hash algorithms MAY be truncated but 3068 1.1 christos * MUST NOT be truncated to a length that results in less than 96 bits 3069 1.1 christos * (12 octets) of equivalent strength. 3070 1.1 christos * 3071 1.1 christos * Section 3 describes how to calculate the digest for a zone. 3072 1.1 christos * Section 4 describes how to use the digest to verify the contents of a 3073 1.1 christos * zone. 3074 1.1 christos * 3075 1.1 christos */ 3076 1.1 christos 3077 1.1 christos ISC_RUN_TEST_IMPL(zonemd) { 3078 1.1 christos text_ok_t text_ok[] = { 3079 1.1 christos TEXT_INVALID(""), 3080 1.1 christos /* No digest scheme or digest type*/ 3081 1.1 christos TEXT_INVALID("0"), 3082 1.1 christos /* No digest type */ 3083 1.1 christos TEXT_INVALID("0 0"), 3084 1.1 christos /* No digest */ 3085 1.1 christos TEXT_INVALID("0 0 0"), 3086 1.1 christos /* No digest */ 3087 1.1 christos TEXT_INVALID("99999999 0 0"), 3088 1.1 christos /* No digest */ 3089 1.1 christos TEXT_INVALID("2019020700 0 0"), 3090 1.1 christos /* Digest too short */ 3091 1.1 christos TEXT_INVALID("2019020700 1 1 DEADBEEF"), 3092 1.1 christos /* Digest too short */ 3093 1.1 christos TEXT_INVALID("2019020700 1 2 DEADBEEF"), 3094 1.1 christos /* Digest too short */ 3095 1.1 christos TEXT_INVALID("2019020700 1 3 DEADBEEFDEADBEEFDEADBE"), 3096 1.1 christos /* Digest type unknown */ 3097 1.1 christos TEXT_VALID("2019020700 1 3 DEADBEEFDEADBEEFDEADBEEF"), 3098 1.1 christos /* Digest type max */ 3099 1.1 christos TEXT_VALID("2019020700 1 255 DEADBEEFDEADBEEFDEADBEEF"), 3100 1.1 christos /* Digest type too big */ 3101 1.1 christos TEXT_INVALID("2019020700 0 256 DEADBEEFDEADBEEFDEADBEEF"), 3102 1.1 christos /* Scheme max */ 3103 1.1 christos TEXT_VALID("2019020700 255 3 DEADBEEFDEADBEEFDEADBEEF"), 3104 1.1 christos /* Scheme too big */ 3105 1.1 christos TEXT_INVALID("2019020700 256 3 DEADBEEFDEADBEEFDEADBEEF"), 3106 1.1 christos /* SHA384 */ 3107 1.1 christos TEXT_VALID("2019020700 1 1 " 3108 1.1 christos "7162D2BB75C047A53DE98767C9192BEB" 3109 1.1 christos "14DB01E7E2267135DAF0230A 19BA4A31" 3110 1.1 christos "6AF6BF64AA5C7BAE24B2992850300509"), 3111 1.1 christos /* SHA512 */ 3112 1.1 christos TEXT_VALID("2019020700 1 2 " 3113 1.1 christos "08CFA1115C7B948C4163A901270395EA" 3114 1.1 christos "226A930CD2CBCF2FA9A5E6EB 85F37C8A" 3115 1.1 christos "4E114D884E66F176EAB121CB02DB7D65" 3116 1.1 christos "2E0CC4827E7A3204 F166B47E5613FD27"), 3117 1.1 christos /* SHA384 too short and with private scheme */ 3118 1.1 christos TEXT_INVALID("2021042801 0 1 " 3119 1.1 christos "7162D2BB75C047A53DE98767C9192BEB" 3120 1.1 christos "6AF6BF64AA5C7BAE24B2992850300509"), 3121 1.1 christos /* SHA512 too short and with private scheme */ 3122 1.1 christos TEXT_INVALID("2021042802 5 2 " 3123 1.1 christos "A897B40072ECAE9E4CA3F1F227DE8F5E" 3124 1.1 christos "480CDEBB16DFC64C1C349A7B5F6C71AB" 3125 1.1 christos "E8A88B76EF0BA1604EC25752E946BF98"), 3126 1.1 christos TEXT_SENTINEL() 3127 1.1 christos }; 3128 1.1 christos wire_ok_t wire_ok[] = { 3129 1.1 christos /* 3130 1.1 christos * Short. 3131 1.1 christos */ 3132 1.1 christos WIRE_INVALID(0x00), 3133 1.1 christos /* 3134 1.1 christos * Short. 3135 1.1 christos */ 3136 1.1 christos WIRE_INVALID(0x00, 0x00), 3137 1.1 christos /* 3138 1.1 christos * Short. 3139 1.1 christos */ 3140 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00), 3141 1.1 christos /* 3142 1.1 christos * Short. 3143 1.1 christos */ 3144 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00), 3145 1.1 christos /* 3146 1.1 christos * Short. 3147 1.1 christos */ 3148 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00), 3149 1.1 christos /* 3150 1.1 christos * Short. 3151 1.1 christos */ 3152 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 3153 1.1 christos /* 3154 1.1 christos * Short 11-octet digest. 3155 1.1 christos */ 3156 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3157 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3158 1.1 christos 0x00), 3159 1.1 christos /* 3160 1.1 christos * Minimal, 12-octet hash for an undefined digest type. 3161 1.1 christos */ 3162 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3163 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3164 1.1 christos 0x00), 3165 1.1 christos /* 3166 1.1 christos * SHA-384 is defined, so we insist there be a digest of 3167 1.1 christos * the expected length. 3168 1.1 christos */ 3169 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 3170 1.1 christos 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3171 1.1 christos 0x00, 0x00), 3172 1.1 christos /* 3173 1.1 christos * 48-octet digest, valid for SHA-384. 3174 1.1 christos */ 3175 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xde, 0xad, 0xbe, 3176 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3177 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 3178 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3179 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 3180 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 3181 1.1 christos 0xce), 3182 1.1 christos /* 3183 1.1 christos * 56-octet digest, too long for SHA-384. 3184 1.1 christos */ 3185 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0xde, 0xad, 3186 1.1 christos 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 3187 1.1 christos 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3188 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 3189 1.1 christos 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 3190 1.1 christos 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3191 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 3192 1.1 christos 0xbe, 0xef, 0xfa, 0xce), 3193 1.1 christos /* 3194 1.1 christos * 56-octet digest, too short for SHA-512 3195 1.1 christos */ 3196 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xde, 0xad, 3197 1.1 christos 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 3198 1.1 christos 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3199 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 3200 1.1 christos 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 3201 1.1 christos 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3202 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 3203 1.1 christos 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad), 3204 1.1 christos /* 3205 1.1 christos * 64-octet digest, just right for SHA-512 3206 1.1 christos */ 3207 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xde, 0xad, 0xbe, 3208 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3209 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 3210 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3211 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 3212 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3213 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 3214 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef), 3215 1.1 christos /* 3216 1.1 christos * 72-octet digest, too long for SHA-512 3217 1.1 christos */ 3218 1.1 christos WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xde, 0xad, 3219 1.1 christos 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 3220 1.1 christos 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3221 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 3222 1.1 christos 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 3223 1.1 christos 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3224 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 3225 1.1 christos 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 3226 1.1 christos 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3227 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce), 3228 1.1 christos /* 3229 1.1 christos * 56-octet digest, valid for an undefined digest type. 3230 1.1 christos */ 3231 1.1 christos WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xde, 0xad, 0xbe, 3232 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3233 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 3234 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3235 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 3236 1.1 christos 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 3237 1.1 christos 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce), 3238 1.1 christos /* 3239 1.1 christos * Sentinel. 3240 1.1 christos */ 3241 1.1 christos WIRE_SENTINEL() 3242 1.1 christos }; 3243 1.1 christos 3244 1.1 christos check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in, 3245 1.1 christos dns_rdatatype_zonemd, sizeof(dns_rdata_zonemd_t)); 3246 1.1 christos } 3247 1.1 christos 3248 1.1 christos ISC_RUN_TEST_IMPL(atcname) { 3249 1.1 christos unsigned int i; 3250 1.1 christos 3251 1.1 christos #define UNR "# Unexpected result from dns_rdatatype_atcname for type %u\n" 3252 1.1 christos for (i = 0; i < 0xffffU; i++) { 3253 1.1 christos bool tf = dns_rdatatype_atcname((dns_rdatatype_t)i); 3254 1.1 christos switch (i) { 3255 1.1 christos case dns_rdatatype_nsec: 3256 1.1 christos case dns_rdatatype_key: 3257 1.1 christos case dns_rdatatype_rrsig: 3258 1.1 christos if (!tf) { 3259 1.1 christos print_message(UNR, i); 3260 1.1 christos } 3261 1.1 christos assert_true(tf); 3262 1.1 christos break; 3263 1.1 christos default: 3264 1.1 christos if (tf) { 3265 1.1 christos print_message(UNR, i); 3266 1.1 christos } 3267 1.1 christos assert_false(tf); 3268 1.1 christos break; 3269 1.1 christos } 3270 1.1 christos } 3271 1.1 christos #undef UNR 3272 1.1 christos } 3273 1.1 christos 3274 1.1 christos ISC_RUN_TEST_IMPL(atparent) { 3275 1.1 christos unsigned int i; 3276 1.1 christos 3277 1.1 christos #define UNR "# Unexpected result from dns_rdatatype_atparent for type %u\n" 3278 1.1 christos for (i = 0; i < 0xffffU; i++) { 3279 1.1 christos bool tf = dns_rdatatype_atparent((dns_rdatatype_t)i); 3280 1.1 christos switch (i) { 3281 1.1 christos case dns_rdatatype_ds: 3282 1.1 christos if (!tf) { 3283 1.1 christos print_message(UNR, i); 3284 1.1 christos } 3285 1.1 christos assert_true(tf); 3286 1.1 christos break; 3287 1.1 christos default: 3288 1.1 christos if (tf) { 3289 1.1 christos print_message(UNR, i); 3290 1.1 christos } 3291 1.1 christos assert_false(tf); 3292 1.1 christos break; 3293 1.1 christos } 3294 1.1 christos } 3295 1.1 christos #undef UNR 3296 1.1 christos } 3297 1.1 christos 3298 1.1 christos ISC_RUN_TEST_IMPL(iszonecutauth) { 3299 1.1 christos unsigned int i; 3300 1.1 christos #define UNR "# Unexpected result from dns_rdatatype_iszonecutauth for type %u\n" 3301 1.1 christos for (i = 0; i < 0xffffU; i++) { 3302 1.1 christos bool tf = dns_rdatatype_iszonecutauth((dns_rdatatype_t)i); 3303 1.1 christos switch (i) { 3304 1.1 christos case dns_rdatatype_ns: 3305 1.1 christos case dns_rdatatype_ds: 3306 1.1 christos case dns_rdatatype_nsec: 3307 1.1 christos case dns_rdatatype_key: 3308 1.1 christos case dns_rdatatype_rrsig: 3309 1.1 christos if (!tf) { 3310 1.1 christos print_message(UNR, i); 3311 1.1 christos } 3312 1.1 christos assert_true(tf); 3313 1.1 christos break; 3314 1.1 christos default: 3315 1.1 christos if (tf) { 3316 1.1 christos print_message(UNR, i); 3317 1.1 christos } 3318 1.1 christos assert_false(tf); 3319 1.1 christos break; 3320 1.1 christos } 3321 1.1 christos } 3322 1.1 christos #undef UNR 3323 1.1 christos } 3324 1.1 christos 3325 1.1 christos ISC_TEST_LIST_START 3326 1.1 christos 3327 1.1 christos /* types */ 3328 1.1 christos ISC_TEST_ENTRY(amtrelay) 3329 1.1 christos ISC_TEST_ENTRY(apl) 3330 1.1 christos ISC_TEST_ENTRY(atma) 3331 1.1 christos ISC_TEST_ENTRY(cdnskey) 3332 1.1 christos ISC_TEST_ENTRY(csync) 3333 1.1 christos ISC_TEST_ENTRY(dnskey) 3334 1.1 christos ISC_TEST_ENTRY(doa) 3335 1.1 christos ISC_TEST_ENTRY(ds) 3336 1.1 christos ISC_TEST_ENTRY(eid) 3337 1.1 christos ISC_TEST_ENTRY(hip) 3338 1.1 christos ISC_TEST_ENTRY(https_svcb) 3339 1.1 christos ISC_TEST_ENTRY(isdn) 3340 1.1 christos ISC_TEST_ENTRY(key) 3341 1.1 christos ISC_TEST_ENTRY(loc) 3342 1.1 christos ISC_TEST_ENTRY(nimloc) 3343 1.1 christos ISC_TEST_ENTRY(nsec) 3344 1.1 christos ISC_TEST_ENTRY(nsec3) 3345 1.1 christos ISC_TEST_ENTRY(nxt) 3346 1.1 christos ISC_TEST_ENTRY(rkey) 3347 1.3 christos ISC_TEST_ENTRY(resinfo) 3348 1.1 christos ISC_TEST_ENTRY(sshfp) 3349 1.4 christos ISC_TEST_ENTRY(wallet) 3350 1.1 christos ISC_TEST_ENTRY(wks) 3351 1.1 christos ISC_TEST_ENTRY(zonemd) 3352 1.1 christos 3353 1.1 christos /* other tests */ 3354 1.1 christos ISC_TEST_ENTRY(edns_client_subnet) 3355 1.1 christos ISC_TEST_ENTRY(atcname) 3356 1.1 christos ISC_TEST_ENTRY(atparent) 3357 1.1 christos ISC_TEST_ENTRY(iszonecutauth) 3358 1.1 christos ISC_TEST_LIST_END 3359 1.1 christos 3360 1.1 christos ISC_TEST_MAIN 3361