2009-02-26 06:09:19 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2009-02-26 06:09:19 +00:00
|
|
|
*
|
2021-06-03 08:37:05 +02:00
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2009-02-26 06:09:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* RFC 5205 */
|
|
|
|
|
2021-10-05 16:49:47 +02:00
|
|
|
#pragma once
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
#define RRTYPE_HIP_ATTRIBUTES (0)
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
fromtext_hip(ARGS_FROMTEXT) {
|
|
|
|
isc_token_t token;
|
|
|
|
dns_name_t name;
|
|
|
|
isc_buffer_t buffer;
|
|
|
|
isc_buffer_t hit_len;
|
|
|
|
isc_buffer_t key_len;
|
2009-02-26 06:09:19 +00:00
|
|
|
unsigned char *start;
|
2020-02-13 14:44:37 -08:00
|
|
|
size_t len;
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(type == dns_rdatatype_hip);
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
UNUSED(callbacks);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dummy HIT len.
|
|
|
|
*/
|
|
|
|
hit_len = *target;
|
|
|
|
RETERR(uint8_tobuffer(0, target));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Algorithm.
|
|
|
|
*/
|
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
|
2018-04-17 08:29:14 -07:00
|
|
|
false));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (token.value.as_ulong > 0xffU) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETTOK(ISC_R_RANGE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
RETERR(uint8_tobuffer(token.value.as_ulong, target));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dummy KEY len.
|
|
|
|
*/
|
|
|
|
key_len = *target;
|
|
|
|
RETERR(uint16_tobuffer(0, target));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HIT (base16).
|
|
|
|
*/
|
|
|
|
start = isc_buffer_used(target);
|
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
|
2018-04-17 08:29:14 -07:00
|
|
|
false));
|
2009-02-26 06:09:19 +00:00
|
|
|
RETTOK(isc_hex_decodestring(DNS_AS_STR(token), target));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in HIT len.
|
|
|
|
*/
|
|
|
|
len = (unsigned char *)isc_buffer_used(target) - start;
|
2020-02-13 21:48:23 +01:00
|
|
|
if (len > 0xffU) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETTOK(ISC_R_RANGE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-03-28 14:19:37 +02:00
|
|
|
RETERR(uint8_tobuffer((uint32_t)len, &hit_len));
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Public key (base64).
|
|
|
|
*/
|
|
|
|
start = isc_buffer_used(target);
|
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
|
2018-04-17 08:29:14 -07:00
|
|
|
false));
|
2009-02-26 06:09:19 +00:00
|
|
|
RETTOK(isc_base64_decodestring(DNS_AS_STR(token), target));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in KEY len.
|
|
|
|
*/
|
|
|
|
len = (unsigned char *)isc_buffer_used(target) - start;
|
2020-02-13 21:48:23 +01:00
|
|
|
if (len > 0xffffU) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETTOK(ISC_R_RANGE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-03-28 14:19:37 +02:00
|
|
|
RETERR(uint16_tobuffer((uint32_t)len, &key_len));
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (origin == NULL) {
|
2015-09-18 07:43:43 +10:00
|
|
|
origin = dns_rootname;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-09-18 07:43:43 +10:00
|
|
|
|
2009-02-26 06:09:19 +00:00
|
|
|
/*
|
|
|
|
* Rendezvous Servers.
|
|
|
|
*/
|
|
|
|
dns_name_init(&name, NULL);
|
|
|
|
do {
|
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token,
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_tokentype_string, true));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (token.type != isc_tokentype_string) {
|
2009-02-26 06:09:19 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
buffer_fromregion(&buffer, &token.value.as_region);
|
|
|
|
RETTOK(dns_name_fromtext(&name, &buffer, origin, options,
|
|
|
|
target));
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Let upper layer handle eol/eof.
|
|
|
|
*/
|
|
|
|
isc_lex_ungettoken(lexer, &token);
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
totext_hip(ARGS_TOTEXT) {
|
|
|
|
isc_region_t region;
|
|
|
|
dns_name_t name;
|
|
|
|
unsigned int length, key_len, hit_len;
|
2009-02-26 06:09:19 +00:00
|
|
|
unsigned char algorithm;
|
2020-02-13 14:44:37 -08:00
|
|
|
char buf[sizeof("225 ")];
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_hip);
|
2009-02-26 06:09:19 +00:00
|
|
|
REQUIRE(rdata->length != 0);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, ®ion);
|
|
|
|
|
|
|
|
hit_len = uint8_fromregion(®ion);
|
|
|
|
isc_region_consume(®ion, 1);
|
2009-02-26 11:18:56 +00:00
|
|
|
|
2009-02-26 06:09:19 +00:00
|
|
|
algorithm = uint8_fromregion(®ion);
|
|
|
|
isc_region_consume(®ion, 1);
|
|
|
|
|
|
|
|
key_len = uint16_fromregion(®ion);
|
|
|
|
isc_region_consume(®ion, 2);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETERR(str_totext("( ", target));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 11:18:56 +00:00
|
|
|
|
2009-02-26 06:09:19 +00:00
|
|
|
/*
|
|
|
|
* Algorithm
|
|
|
|
*/
|
2017-10-03 14:54:19 +11:00
|
|
|
snprintf(buf, sizeof(buf), "%u ", algorithm);
|
2009-02-26 06:09:19 +00:00
|
|
|
RETERR(str_totext(buf, target));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HIT.
|
|
|
|
*/
|
|
|
|
INSIST(hit_len < region.length);
|
|
|
|
length = region.length;
|
|
|
|
region.length = hit_len;
|
|
|
|
RETERR(isc_hex_totext(®ion, 1, "", target));
|
|
|
|
region.length = length - hit_len;
|
|
|
|
RETERR(str_totext(tctx->linebreak, target));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public KEY.
|
|
|
|
*/
|
|
|
|
INSIST(key_len <= region.length);
|
|
|
|
length = region.length;
|
|
|
|
region.length = key_len;
|
|
|
|
RETERR(isc_base64_totext(®ion, 1, "", target));
|
|
|
|
region.length = length - key_len;
|
2020-07-22 17:02:47 +10:00
|
|
|
if (region.length > 0) {
|
|
|
|
RETERR(str_totext(tctx->linebreak, target));
|
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Rendezvous Servers.
|
|
|
|
*/
|
|
|
|
dns_name_init(&name, NULL);
|
|
|
|
while (region.length > 0) {
|
|
|
|
dns_name_fromregion(&name, ®ion);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
RETERR(dns_name_totext(&name, false, target));
|
2009-02-26 06:09:19 +00:00
|
|
|
isc_region_consume(®ion, name.length);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (region.length > 0) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETERR(str_totext(tctx->linebreak, target));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETERR(str_totext(" )", target));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
fromwire_hip(ARGS_FROMWIRE) {
|
2009-02-26 06:09:19 +00:00
|
|
|
isc_region_t region, rr;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t name;
|
|
|
|
uint8_t hit_len;
|
|
|
|
uint16_t key_len;
|
Attempt to silence untrusted loop bound
Assign hit_len + key_len to len and test the result
rather than recomputing and letting the compiler simplify.
213 isc_region_consume(®ion, 2); /* hit length + algorithm */
9. tainted_return_value: Function uint16_fromregion returns tainted data. [show details]
10. tainted_data_transitive: Call to function uint16_fromregion with tainted argument *region.base returns tainted data.
11. tainted_return_value: Function uint16_fromregion returns tainted data.
12. tainted_data_transitive: Call to function uint16_fromregion with tainted argument *region.base returns tainted data.
13. var_assign: Assigning: key_len = uint16_fromregion(®ion), which taints key_len.
214 key_len = uint16_fromregion(®ion);
14. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
15. Condition key_len == 0, taking false branch.
215 if (key_len == 0) {
216 RETERR(DNS_R_FORMERR);
217 }
16. Condition !!(_r->length >= _l), taking true branch.
17. Condition !!(_r->length >= _l), taking true branch.
218 isc_region_consume(®ion, 2);
18. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
19. Condition region.length < (unsigned int)(hit_len + key_len), taking false branch.
219 if (region.length < (unsigned)(hit_len + key_len)) {
220 RETERR(DNS_R_FORMERR);
221 }
222
20. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
21. Condition _r != 0, taking false branch.
223 RETERR(mem_tobuffer(target, rr.base, 4 + hit_len + key_len));
22. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
23. var_assign_var: Compound assignment involving tainted variable 4 + hit_len + key_len to variable source->current taints source->current.
224 isc_buffer_forward(source, 4 + hit_len + key_len);
225
226 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
CID 281461 (#1 of 1): Untrusted loop bound (TAINTED_SCALAR)
24. tainted_data: Using tainted variable source->active - source->current as a loop boundary.
Ensure that tainted values are properly sanitized, by checking that their values are within a permissible range.
227 while (isc_buffer_activelength(source) > 0) {
228 dns_name_init(&name, NULL);
229 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
230 }
2021-02-03 17:20:09 +11:00
|
|
|
size_t len;
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(type == dns_rdatatype_hip);
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
|
|
|
|
isc_buffer_activeregion(source, ®ion);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (region.length < 4U) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETERR(DNS_R_FORMERR);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
rr = region;
|
|
|
|
hit_len = uint8_fromregion(®ion);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (hit_len == 0) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETERR(DNS_R_FORMERR);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_region_consume(®ion, 2); /* hit length + algorithm */
|
2009-02-26 06:09:19 +00:00
|
|
|
key_len = uint16_fromregion(®ion);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (key_len == 0) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETERR(DNS_R_FORMERR);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
isc_region_consume(®ion, 2);
|
Attempt to silence untrusted loop bound
Assign hit_len + key_len to len and test the result
rather than recomputing and letting the compiler simplify.
213 isc_region_consume(®ion, 2); /* hit length + algorithm */
9. tainted_return_value: Function uint16_fromregion returns tainted data. [show details]
10. tainted_data_transitive: Call to function uint16_fromregion with tainted argument *region.base returns tainted data.
11. tainted_return_value: Function uint16_fromregion returns tainted data.
12. tainted_data_transitive: Call to function uint16_fromregion with tainted argument *region.base returns tainted data.
13. var_assign: Assigning: key_len = uint16_fromregion(®ion), which taints key_len.
214 key_len = uint16_fromregion(®ion);
14. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
15. Condition key_len == 0, taking false branch.
215 if (key_len == 0) {
216 RETERR(DNS_R_FORMERR);
217 }
16. Condition !!(_r->length >= _l), taking true branch.
17. Condition !!(_r->length >= _l), taking true branch.
218 isc_region_consume(®ion, 2);
18. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
19. Condition region.length < (unsigned int)(hit_len + key_len), taking false branch.
219 if (region.length < (unsigned)(hit_len + key_len)) {
220 RETERR(DNS_R_FORMERR);
221 }
222
20. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
21. Condition _r != 0, taking false branch.
223 RETERR(mem_tobuffer(target, rr.base, 4 + hit_len + key_len));
22. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
23. var_assign_var: Compound assignment involving tainted variable 4 + hit_len + key_len to variable source->current taints source->current.
224 isc_buffer_forward(source, 4 + hit_len + key_len);
225
226 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
CID 281461 (#1 of 1): Untrusted loop bound (TAINTED_SCALAR)
24. tainted_data: Using tainted variable source->active - source->current as a loop boundary.
Ensure that tainted values are properly sanitized, by checking that their values are within a permissible range.
227 while (isc_buffer_activelength(source) > 0) {
228 dns_name_init(&name, NULL);
229 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
230 }
2021-02-03 17:20:09 +11:00
|
|
|
len = hit_len + key_len;
|
|
|
|
if (len > region.length) {
|
2009-02-26 06:09:19 +00:00
|
|
|
RETERR(DNS_R_FORMERR);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
|
Attempt to silence untrusted loop bound
Assign hit_len + key_len to len and test the result
rather than recomputing and letting the compiler simplify.
213 isc_region_consume(®ion, 2); /* hit length + algorithm */
9. tainted_return_value: Function uint16_fromregion returns tainted data. [show details]
10. tainted_data_transitive: Call to function uint16_fromregion with tainted argument *region.base returns tainted data.
11. tainted_return_value: Function uint16_fromregion returns tainted data.
12. tainted_data_transitive: Call to function uint16_fromregion with tainted argument *region.base returns tainted data.
13. var_assign: Assigning: key_len = uint16_fromregion(®ion), which taints key_len.
214 key_len = uint16_fromregion(®ion);
14. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
15. Condition key_len == 0, taking false branch.
215 if (key_len == 0) {
216 RETERR(DNS_R_FORMERR);
217 }
16. Condition !!(_r->length >= _l), taking true branch.
17. Condition !!(_r->length >= _l), taking true branch.
218 isc_region_consume(®ion, 2);
18. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
19. Condition region.length < (unsigned int)(hit_len + key_len), taking false branch.
219 if (region.length < (unsigned)(hit_len + key_len)) {
220 RETERR(DNS_R_FORMERR);
221 }
222
20. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
21. Condition _r != 0, taking false branch.
223 RETERR(mem_tobuffer(target, rr.base, 4 + hit_len + key_len));
22. lower_bounds: Casting narrower unsigned key_len to wider signed type int effectively tests its lower bound.
23. var_assign_var: Compound assignment involving tainted variable 4 + hit_len + key_len to variable source->current taints source->current.
224 isc_buffer_forward(source, 4 + hit_len + key_len);
225
226 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
CID 281461 (#1 of 1): Untrusted loop bound (TAINTED_SCALAR)
24. tainted_data: Using tainted variable source->active - source->current as a loop boundary.
Ensure that tainted values are properly sanitized, by checking that their values are within a permissible range.
227 while (isc_buffer_activelength(source) > 0) {
228 dns_name_init(&name, NULL);
229 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
230 }
2021-02-03 17:20:09 +11:00
|
|
|
RETERR(mem_tobuffer(target, rr.base, 4 + len));
|
|
|
|
isc_buffer_forward(source, 4 + len);
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2022-05-05 16:36:52 +01:00
|
|
|
dctx = dns_decompress_setpermitted(dctx, false);
|
2009-02-26 06:09:19 +00:00
|
|
|
while (isc_buffer_activelength(source) > 0) {
|
|
|
|
dns_name_init(&name, NULL);
|
|
|
|
RETERR(dns_name_fromwire(&name, source, dctx, options, target));
|
|
|
|
}
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
towire_hip(ARGS_TOWIRE) {
|
2009-02-26 06:09:19 +00:00
|
|
|
isc_region_t region;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_hip);
|
2009-02-26 06:09:19 +00:00
|
|
|
REQUIRE(rdata->length != 0);
|
|
|
|
|
|
|
|
UNUSED(cctx);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, ®ion);
|
|
|
|
return (mem_tobuffer(target, region.base, region.length));
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
compare_hip(ARGS_COMPARE) {
|
2009-02-26 06:09:19 +00:00
|
|
|
isc_region_t region1;
|
|
|
|
isc_region_t region2;
|
|
|
|
|
|
|
|
REQUIRE(rdata1->type == rdata2->type);
|
|
|
|
REQUIRE(rdata1->rdclass == rdata2->rdclass);
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata1->type == dns_rdatatype_hip);
|
2009-02-26 06:09:19 +00:00
|
|
|
REQUIRE(rdata1->length != 0);
|
|
|
|
REQUIRE(rdata2->length != 0);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata1, ®ion1);
|
|
|
|
dns_rdata_toregion(rdata2, ®ion2);
|
|
|
|
return (isc_region_compare(®ion1, ®ion2));
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
fromstruct_hip(ARGS_FROMSTRUCT) {
|
2009-02-26 06:09:19 +00:00
|
|
|
dns_rdata_hip_t *hip = source;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdata_hip_t myhip;
|
|
|
|
isc_result_t result;
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(type == dns_rdatatype_hip);
|
2019-09-27 10:40:51 +02:00
|
|
|
REQUIRE(hip != NULL);
|
2009-02-26 06:09:19 +00:00
|
|
|
REQUIRE(hip->common.rdtype == type);
|
|
|
|
REQUIRE(hip->common.rdclass == rdclass);
|
|
|
|
REQUIRE(hip->hit_len > 0 && hip->hit != NULL);
|
|
|
|
REQUIRE(hip->key_len > 0 && hip->key != NULL);
|
|
|
|
REQUIRE((hip->servers == NULL && hip->servers_len == 0) ||
|
2020-02-12 13:59:18 +01:00
|
|
|
(hip->servers != NULL && hip->servers_len != 0));
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
|
|
|
|
RETERR(uint8_tobuffer(hip->hit_len, target));
|
|
|
|
RETERR(uint8_tobuffer(hip->algorithm, target));
|
|
|
|
RETERR(uint16_tobuffer(hip->key_len, target));
|
|
|
|
RETERR(mem_tobuffer(target, hip->hit, hip->hit_len));
|
|
|
|
RETERR(mem_tobuffer(target, hip->key, hip->key_len));
|
2009-02-26 11:18:56 +00:00
|
|
|
|
2009-02-26 06:09:19 +00:00
|
|
|
myhip = *hip;
|
2020-02-12 13:59:18 +01:00
|
|
|
for (result = dns_rdata_hip_first(&myhip); result == ISC_R_SUCCESS;
|
2009-02-26 06:09:19 +00:00
|
|
|
result = dns_rdata_hip_next(&myhip))
|
2022-03-13 13:05:27 +01:00
|
|
|
{
|
|
|
|
/* initialize the names */
|
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
return (mem_tobuffer(target, hip->servers, hip->servers_len));
|
2009-02-26 06:09:19 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
tostruct_hip(ARGS_TOSTRUCT) {
|
|
|
|
isc_region_t region;
|
2009-02-26 06:09:19 +00:00
|
|
|
dns_rdata_hip_t *hip = target;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_hip);
|
2019-09-27 10:40:51 +02:00
|
|
|
REQUIRE(hip != NULL);
|
2009-02-26 06:09:19 +00:00
|
|
|
REQUIRE(rdata->length != 0);
|
|
|
|
|
|
|
|
hip->common.rdclass = rdata->rdclass;
|
|
|
|
hip->common.rdtype = rdata->type;
|
|
|
|
ISC_LINK_INIT(&hip->common, link);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, ®ion);
|
|
|
|
|
|
|
|
hip->hit_len = uint8_fromregion(®ion);
|
|
|
|
isc_region_consume(®ion, 1);
|
|
|
|
|
|
|
|
hip->algorithm = uint8_fromregion(®ion);
|
|
|
|
isc_region_consume(®ion, 1);
|
|
|
|
|
|
|
|
hip->key_len = uint16_fromregion(®ion);
|
|
|
|
isc_region_consume(®ion, 2);
|
|
|
|
|
|
|
|
hip->hit = hip->key = hip->servers = NULL;
|
|
|
|
|
|
|
|
hip->hit = mem_maybedup(mctx, region.base, hip->hit_len);
|
|
|
|
isc_region_consume(®ion, hip->hit_len);
|
|
|
|
|
2014-06-11 22:57:46 +10:00
|
|
|
INSIST(hip->key_len <= region.length);
|
|
|
|
|
2009-02-26 06:09:19 +00:00
|
|
|
hip->key = mem_maybedup(mctx, region.base, hip->key_len);
|
|
|
|
isc_region_consume(®ion, hip->key_len);
|
|
|
|
|
|
|
|
hip->servers_len = region.length;
|
|
|
|
if (hip->servers_len != 0) {
|
|
|
|
hip->servers = mem_maybedup(mctx, region.base, region.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
hip->offset = hip->servers_len;
|
|
|
|
hip->mctx = mctx;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
freestruct_hip(ARGS_FREESTRUCT) {
|
2009-02-26 06:09:19 +00:00
|
|
|
dns_rdata_hip_t *hip = source;
|
|
|
|
|
2019-09-27 10:40:51 +02:00
|
|
|
REQUIRE(hip != NULL);
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (hip->mctx == NULL) {
|
2009-02-26 06:09:19 +00:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2009-02-26 11:18:56 +00:00
|
|
|
isc_mem_free(hip->mctx, hip->hit);
|
|
|
|
isc_mem_free(hip->mctx, hip->key);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (hip->servers != NULL) {
|
2009-02-26 11:18:56 +00:00
|
|
|
isc_mem_free(hip->mctx, hip->servers);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
hip->mctx = NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
additionaldata_hip(ARGS_ADDLDATA) {
|
2019-07-05 16:20:20 +10:00
|
|
|
REQUIRE(rdata->type == dns_rdatatype_hip);
|
|
|
|
|
2009-02-26 06:09:19 +00:00
|
|
|
UNUSED(rdata);
|
2019-07-05 16:20:20 +10:00
|
|
|
UNUSED(owner);
|
2009-02-26 06:09:19 +00:00
|
|
|
UNUSED(add);
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
digest_hip(ARGS_DIGEST) {
|
2009-02-26 06:09:19 +00:00
|
|
|
isc_region_t r;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_hip);
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, &r);
|
|
|
|
return ((digest)(arg, &r));
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static bool
|
2020-02-13 14:44:37 -08:00
|
|
|
checkowner_hip(ARGS_CHECKOWNER) {
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(type == dns_rdatatype_hip);
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
UNUSED(name);
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
UNUSED(wildcard);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2009-02-26 06:09:19 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static bool
|
2020-02-13 14:44:37 -08:00
|
|
|
checknames_hip(ARGS_CHECKNAMES) {
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_hip);
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
UNUSED(rdata);
|
|
|
|
UNUSED(owner);
|
|
|
|
UNUSED(bad);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2009-02-26 06:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdata_hip_first(dns_rdata_hip_t *hip) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (hip->servers_len == 0) {
|
2009-02-26 06:09:19 +00:00
|
|
|
return (ISC_R_NOMORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
hip->offset = 0;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdata_hip_next(dns_rdata_hip_t *hip) {
|
2009-02-26 06:09:19 +00:00
|
|
|
isc_region_t region;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t name;
|
2009-02-26 06:09:19 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (hip->offset >= hip->servers_len) {
|
2009-02-26 06:09:19 +00:00
|
|
|
return (ISC_R_NOMORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-02-26 06:09:19 +00:00
|
|
|
|
|
|
|
region.base = hip->servers + hip->offset;
|
|
|
|
region.length = hip->servers_len - hip->offset;
|
|
|
|
dns_name_init(&name, NULL);
|
|
|
|
dns_name_fromregion(&name, ®ion);
|
|
|
|
hip->offset += name.length;
|
|
|
|
INSIST(hip->offset <= hip->servers_len);
|
2020-07-22 17:02:47 +10:00
|
|
|
return (hip->offset < hip->servers_len ? ISC_R_SUCCESS : ISC_R_NOMORE);
|
2009-02-26 06:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdata_hip_current(dns_rdata_hip_t *hip, dns_name_t *name) {
|
2009-02-26 06:09:19 +00:00
|
|
|
isc_region_t region;
|
|
|
|
|
|
|
|
REQUIRE(hip->offset < hip->servers_len);
|
|
|
|
|
|
|
|
region.base = hip->servers + hip->offset;
|
|
|
|
region.length = hip->servers_len - hip->offset;
|
|
|
|
dns_name_fromregion(name, ®ion);
|
|
|
|
|
|
|
|
INSIST(name->length + hip->offset <= hip->servers_len);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
casecompare_hip(ARGS_COMPARE) {
|
2009-12-04 22:06:37 +00:00
|
|
|
isc_region_t r1;
|
|
|
|
isc_region_t r2;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t name1;
|
|
|
|
dns_name_t name2;
|
|
|
|
int order;
|
|
|
|
uint8_t hit_len;
|
|
|
|
uint16_t key_len;
|
2009-12-04 22:06:37 +00:00
|
|
|
|
|
|
|
REQUIRE(rdata1->type == rdata2->type);
|
|
|
|
REQUIRE(rdata1->rdclass == rdata2->rdclass);
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata1->type == dns_rdatatype_hip);
|
2009-12-04 22:06:37 +00:00
|
|
|
REQUIRE(rdata1->length != 0);
|
|
|
|
REQUIRE(rdata2->length != 0);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata1, &r1);
|
|
|
|
dns_rdata_toregion(rdata2, &r2);
|
|
|
|
|
|
|
|
INSIST(r1.length > 4);
|
|
|
|
INSIST(r2.length > 4);
|
2014-08-27 21:36:13 -07:00
|
|
|
order = memcmp(r1.base, r2.base, 4);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (order != 0) {
|
2009-12-04 22:06:37 +00:00
|
|
|
return (order);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-12-04 22:06:37 +00:00
|
|
|
|
|
|
|
hit_len = uint8_fromregion(&r1);
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_region_consume(&r1, 2); /* hit length + algorithm */
|
2009-12-04 22:06:37 +00:00
|
|
|
key_len = uint16_fromregion(&r1);
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_region_consume(&r1, 2); /* key length */
|
2009-12-04 22:06:37 +00:00
|
|
|
isc_region_consume(&r2, 4);
|
2014-08-27 21:36:13 -07:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
INSIST(r1.length >= (unsigned)(hit_len + key_len));
|
|
|
|
INSIST(r2.length >= (unsigned)(hit_len + key_len));
|
2014-08-27 21:36:13 -07:00
|
|
|
order = memcmp(r1.base, r2.base, hit_len + key_len);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (order != 0) {
|
2009-12-04 22:06:37 +00:00
|
|
|
return (order);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-12-04 22:06:37 +00:00
|
|
|
isc_region_consume(&r1, hit_len + key_len);
|
|
|
|
isc_region_consume(&r2, hit_len + key_len);
|
|
|
|
|
|
|
|
dns_name_init(&name1, NULL);
|
|
|
|
dns_name_init(&name2, NULL);
|
2009-12-04 21:09:34 +00:00
|
|
|
while (r1.length != 0 && r2.length != 0) {
|
|
|
|
dns_name_fromregion(&name1, &r1);
|
|
|
|
dns_name_fromregion(&name2, &r2);
|
|
|
|
order = dns_name_rdatacompare(&name1, &name2);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (order != 0) {
|
2009-12-04 21:09:34 +00:00
|
|
|
return (order);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-12-04 21:09:34 +00:00
|
|
|
|
|
|
|
isc_region_consume(&r1, name_length(&name1));
|
|
|
|
isc_region_consume(&r2, name_length(&name2));
|
|
|
|
}
|
2009-12-04 22:06:37 +00:00
|
|
|
return (isc_region_compare(&r1, &r2));
|
2009-12-04 21:09:34 +00:00
|
|
|
}
|