Merge branch '3544-add-dohpath-parsing-to-svbc-v9_16' into 'v9_16'

Add support for 'dohpath' to SVCB (and HTTPS) [v9_16]

See merge request isc-projects/bind9!6850
This commit is contained in:
Mark Andrews
2022-10-04 06:24:57 +00:00
11 changed files with 114 additions and 20 deletions
+3
View File
@@ -1,3 +1,6 @@
5991. [protocol] Add support for parsing and validating "dohpath" to
SVCB. [GL #3544]
5988. [bug] Some out of memory conditions in opensslrsa_link.c
could lead to memory leaks. [GL #3551]
@@ -24,3 +24,4 @@ svcb6 SVCB 6 . mandatory=port,alpn port=60 alpn=h3
svcb7 SVCB 7 . mandatory=port,alpn port=60 alpn=h1,h3
svcb8 SVCB 8 . mandatory=port,alpn port=60 alpn="h1\\,h2,h3"
svcb9 SVCB 0 44._svbc.example.net.
svcb10 SVCB 7 . alpn="h2,h3" dohpath=/{?dns}
+3
View File
@@ -429,6 +429,9 @@
/* Define to 1 if you have the `strlcpy' function. */
#undef HAVE_STRLCPY
/* Define to 1 if you have the `strnstr' function. */
#undef HAVE_STRNSTR
/* Define to 1 if you have the `sysconf' function. */
#undef HAVE_SYSCONF
Vendored
+1 -1
View File
@@ -19633,7 +19633,7 @@ fi
#
# Check for some other useful functions that are not ever-present.
#
for ac_func in strlcpy strlcat
for ac_func in strlcpy strlcat strnstr
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+1 -1
View File
@@ -1701,7 +1701,7 @@ AS_IF([test "$enable_tcp_fastopen" = "yes"],
#
# Check for some other useful functions that are not ever-present.
#
AC_CHECK_FUNCS([strlcpy strlcat])
AC_CHECK_FUNCS([strlcpy strlcat strnstr])
AC_SUBST(READLINE_LIB)
+3
View File
@@ -38,6 +38,9 @@ Feature Changes
- None.
- Add support for parsing and validating ``dohpath`` to SVBC records.
:gl:`#3544`
Bug Fixes
~~~~~~~~~
+42 -2
View File
@@ -33,13 +33,14 @@ enum encoding {
sbpr_base64,
sbpr_empty,
sbpr_alpn,
sbpr_keylist
sbpr_keylist,
sbpr_dohpath
};
static const struct {
const char *name; /* Restricted to lowercase LDH by registry. */
unsigned int value;
enum encoding encoding;
bool initial;
bool initial; /* Part of the first defined set of encodings. */
} sbpr[] = {
{ "mandatory", 0, sbpr_keylist, true },
{ "alpn", 1, sbpr_alpn, true },
@@ -48,6 +49,7 @@ static const struct {
{ "ipv4hint", 4, sbpr_ipv4s, true },
{ "ech", 5, sbpr_base64, true },
{ "ipv6hint", 6, sbpr_ipv6s, true },
{ "dohpath", 7, sbpr_dohpath, false },
};
static isc_result_t
@@ -151,6 +153,30 @@ svcb_validate(uint16_t key, isc_region_t *region) {
case sbpr_text:
case sbpr_base64:
break;
case sbpr_dohpath:
/*
* Minimum valid dohpath is "/{?dns}" as
* it MUST be relative (leading "/") and
* MUST contain "{?dns}".
*/
if (region->length < 7) {
return (DNS_R_FORMERR);
}
/* MUST be relative */
if (region->base[0] != '/') {
return (DNS_R_FORMERR);
}
/* MUST be UTF8 */
if (!isc_utf8_valid(region->base,
region->length)) {
return (DNS_R_FORMERR);
}
/* MUST contain "{?dns}" */
if (strnstr((char *)region->base, "{?dns}",
region->length) == NULL) {
return (DNS_R_FORMERR);
}
break;
case sbpr_empty:
if (region->length != 0) {
return (DNS_R_FORMERR);
@@ -256,6 +282,7 @@ svc_fromtext(isc_textregion_t *region, isc_buffer_t *target) {
switch (sbpr[i].encoding) {
case sbpr_text:
case sbpr_dohpath:
RETERR(multitxt_fromtext(region, target));
break;
case sbpr_alpn:
@@ -332,6 +359,19 @@ svc_fromtext(isc_textregion_t *region, isc_buffer_t *target) {
len = isc_buffer_usedlength(target) -
isc_buffer_usedlength(&sb) - 2;
RETERR(uint16_tobuffer(len, &sb)); /* length */
switch (sbpr[i].encoding) {
case sbpr_dohpath:
/*
* Apply constraints not applied by multitxt_fromtext.
*/
keyregion.base = isc_buffer_used(&sb);
keyregion.length = isc_buffer_usedlength(target) -
isc_buffer_usedlength(&sb);
RETERR(svcb_validate(sbpr[i].value, &keyregion));
break;
default:
break;
}
return (ISC_R_SUCCESS);
}
+24 -16
View File
@@ -2541,7 +2541,7 @@ static void
https_svcb(void **state) {
/*
* Known keys: mandatory, apln, no-default-alpn, port,
* ipv4hint, port, ipv6hint.
* ipv4hint, port, ipv6hint, dohpath.
*/
text_ok_t text_ok[] = {
/* unknown key invalid */
@@ -2560,9 +2560,9 @@ https_svcb(void **state) {
TEXT_INVALID("2 svc.example.net. key=\"2222\""),
/* zero pad invalid */
TEXT_INVALID("2 svc.example.net. key07=\"2222\""),
TEXT_VALID_LOOP(1, "2 svc.example.net. key7=\"2222\""),
TEXT_VALID_LOOPCHG(1, "2 svc.example.net. key7=2222",
"2 svc.example.net. key7=\"2222\""),
TEXT_VALID_LOOP(1, "2 svc.example.net. key8=\"2222\""),
TEXT_VALID_LOOPCHG(1, "2 svc.example.net. key8=2222",
"2 svc.example.net. key8=\"2222\""),
TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h2",
"2 svc.example.net. alpn=\"h2\""),
TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h3",
@@ -2590,12 +2590,12 @@ https_svcb(void **state) {
TEXT_VALID_LOOP(1, "2 svc.example.net. ech=abcdefghijkl"),
/* bad base64 */
TEXT_INVALID("2 svc.example.net. ech=abcdefghijklm"),
TEXT_VALID_LOOP(1, "2 svc.example.net. key7=\"2222\""),
TEXT_VALID_LOOP(1, "2 svc.example.net. key8=\"2222\""),
/* Out of key order on input (alpn == key1). */
TEXT_VALID_LOOPCHG(2,
"2 svc.example.net. key7=\"2222\" alpn=h2",
"2 svc.example.net. key8=\"2222\" alpn=h2",
"2 svc.example.net. alpn=\"h2\" "
"key7=\"2222\""),
"key8=\"2222\""),
TEXT_VALID_LOOP(1, "2 svc.example.net. key65535=\"2222\""),
TEXT_INVALID("2 svc.example.net. key65536=\"2222\""),
TEXT_VALID_LOOP(1, "2 svc.example.net. key10"),
@@ -2626,18 +2626,18 @@ https_svcb(void **state) {
TEXT_INVALID("2 svc.example.net. "
"mandatory=alpn,,port alpn=h2 port=433"),
/* mandatory w/ unknown key values */
TEXT_VALID_LOOP(2, "2 svc.example.net. mandatory=key7 key7"),
TEXT_VALID_LOOP(3, "2 svc.example.net. mandatory=key7,key8 "
"key7 key8"),
TEXT_VALID_LOOP(2, "2 svc.example.net. mandatory=key8 key8"),
TEXT_VALID_LOOP(3, "2 svc.example.net. mandatory=key8,key9 "
"key8 key9"),
TEXT_VALID_LOOPCHG(
3, "2 svc.example.net. mandatory=key8,key7 key7 key8",
"2 svc.example.net. mandatory=key7,key8 key7 key8"),
3, "2 svc.example.net. mandatory=key9,key8 key8 key9",
"2 svc.example.net. mandatory=key8,key9 key8 key9"),
TEXT_INVALID("2 svc.example.net. "
"mandatory=key7,key7"),
TEXT_INVALID("2 svc.example.net. mandatory=,key7"),
TEXT_INVALID("2 svc.example.net. mandatory=key7,"),
"mandatory=key8,key8"),
TEXT_INVALID("2 svc.example.net. mandatory=,key8"),
TEXT_INVALID("2 svc.example.net. mandatory=key8,"),
TEXT_INVALID("2 svc.example.net. "
"mandatory=key7,,key7"),
"mandatory=key8,,key8"),
/* Invalid test vectors */
TEXT_INVALID("1 foo.example.com. ( key123=abc key123=def )"),
TEXT_INVALID("1 foo.example.com. mandatory"),
@@ -2650,6 +2650,14 @@ https_svcb(void **state) {
TEXT_INVALID("1 foo.example.com. mandatory=mandatory"),
TEXT_INVALID("1 foo.example.com. ( mandatory=key123,key123 "
"key123=abc)"),
/* dohpath tests */
TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/{?dns}",
"1 example.net. key7=\"/{?dns}\""),
TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/some/path{?dns}",
"1 example.net. key7=\"/some/path{?dns}\""),
TEXT_INVALID("1 example.com. dohpath=no-slash"),
TEXT_INVALID("1 example.com. dohpath=/{?notdns}"),
TEXT_INVALID("1 example.com. dohpath=/notvariable"),
TEXT_SENTINEL()
};
+5
View File
@@ -32,6 +32,11 @@ size_t
strlcat(char *dst, const char *src, size_t size);
#endif /* if !defined(HAVE_STRLCAT) */
#if !defined(HAVE_STRNSTR)
char *
strnstr(const char *s, const char *find, size_t slen);
#endif /* if !defined(HAVE_STRNSTR) */
int
isc_string_strerror_r(int errnum, char *buf, size_t buflen);
+30
View File
@@ -12,9 +12,15 @@
*/
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -48,6 +54,7 @@
#include <string.h>
#include <isc/string.h> /* IWYU pragma: keep */
#include <isc/util.h>
#if !defined(HAVE_STRLCPY)
size_t
@@ -109,6 +116,29 @@ strlcat(char *dst, const char *src, size_t size) {
}
#endif /* !defined(HAVE_STRLCAT) */
#if !defined(HAVE_STRNSTR)
char *
strnstr(const char *s, const char *find, size_t slen) {
char c, sc, *r;
size_t len;
if ((c = *find++) != '\0') {
len = strlen(find);
do {
do {
if (slen-- < 1 || (sc = *s++) == '\0')
return (NULL);
} while (sc != c);
if (len > slen)
return (NULL);
} while (strncmp(s, find, len) != 0);
s--;
}
DE_CONST(s, r);
return (r);
}
#endif
int
isc_string_strerror_r(int errnum, char *buf, size_t buflen) {
#if defined(_WIN32) || defined(_WIN64)
+1
View File
@@ -778,6 +778,7 @@ pkcs_C_VerifyUpdate
@END PKCS11
strlcat
strlcpy
strnstr
syslog
@IF NOLONGER