summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorian <florian@openbsd.org>2021-04-02 06:37:40 +0000
committerflorian <florian@openbsd.org>2021-04-02 06:37:40 +0000
commita944512f6d2ec1bd7efca16ecbd21cb41cedeb30 (patch)
tree87a58d747579f5a3827dbaeb89963d2db17b2d56
parentif cipher list is not specified for a relay action, use the global (diff)
downloadwireguard-openbsd-a944512f6d2ec1bd7efca16ecbd21cb41cedeb30.tar.xz
wireguard-openbsd-a944512f6d2ec1bd7efca16ecbd21cb41cedeb30.zip
Implement ZONEMD (RFC8976), based on DS (ds_43.c)
OK sthen
-rw-r--r--usr.bin/dig/lib/dns/include/dns/types.h1
-rw-r--r--usr.bin/dig/lib/dns/rdata.c7
-rw-r--r--usr.bin/dig/lib/dns/rdata/generic/zonemd_63.c118
3 files changed, 124 insertions, 2 deletions
diff --git a/usr.bin/dig/lib/dns/include/dns/types.h b/usr.bin/dig/lib/dns/include/dns/types.h
index b8b117fb16d..63ea8d67f51 100644
--- a/usr.bin/dig/lib/dns/include/dns/types.h
+++ b/usr.bin/dig/lib/dns/include/dns/types.h
@@ -138,6 +138,7 @@ enum {
dns_rdatatype_cdnskey = 60,
dns_rdatatype_openpgpkey = 61,
dns_rdatatype_csync = 62,
+ dns_rdatatype_zonemd = 63,
dns_rdatatype_spf = 99,
dns_rdatatype_unspec = 103,
dns_rdatatype_nid = 104,
diff --git a/usr.bin/dig/lib/dns/rdata.c b/usr.bin/dig/lib/dns/rdata.c
index 22d8f9c824b..c27409efc3c 100644
--- a/usr.bin/dig/lib/dns/rdata.c
+++ b/usr.bin/dig/lib/dns/rdata.c
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: rdata.c,v 1.32 2020/09/14 08:40:43 florian Exp $ */
+/* $Id: rdata.c,v 1.33 2021/04/02 06:37:40 florian Exp $ */
/*! \file */
@@ -833,7 +833,8 @@ dns_rdatatype_fromtext(dns_rdatatype_t *typep, isc_textregion_t *source) {
{"unspec", 103},
{"uri", 256},
{"wks", 11},
- {"x25", 19}
+ {"x25", 19},
+ {"zonemd", 63},
};
const dns_rdata_type_lookup_t *p;
unsigned int n;
@@ -1003,6 +1004,8 @@ dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) {
return (isc_str_tobuffer("OPENPGPKEY", target));
case 62:
return (isc_str_tobuffer("CSYNC", target));
+ case 63:
+ return (isc_str_tobuffer("ZONEMD", target));
case 99:
return (isc_str_tobuffer("SPF", target));
case 100:
diff --git a/usr.bin/dig/lib/dns/rdata/generic/zonemd_63.c b/usr.bin/dig/lib/dns/rdata/generic/zonemd_63.c
new file mode 100644
index 00000000000..cb9c3ca7657
--- /dev/null
+++ b/usr.bin/dig/lib/dns/rdata/generic/zonemd_63.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id: zonemd_63.c,v 1.1 2021/04/02 06:37:40 florian Exp $ */
+
+/* RFC8976 */
+
+#ifndef RDATA_GENERIC_ZONEMD_63_C
+#define RDATA_GENERIC_ZONEMD_63_C
+
+#define DNS_ZONEMD_DIGEST_SHA384 (1)
+
+static inline isc_result_t
+totext_zonemd(ARGS_TOTEXT) {
+ isc_region_t sr;
+ char buf[sizeof("4294967295 ")];
+ uint32_t n;
+
+ REQUIRE(rdata->type == dns_rdatatype_zonemd);
+ REQUIRE(rdata->length > 6);
+
+ dns_rdata_toregion(rdata, &sr);
+
+ /* serial */
+ n = uint32_fromregion(&sr);
+ isc_region_consume(&sr, 4);
+ snprintf(buf, sizeof(buf), "%u ", n);
+ RETERR(isc_str_tobuffer(buf, target));
+
+ /* scheme */
+ n = uint8_fromregion(&sr);
+ isc_region_consume(&sr, 1);
+ snprintf(buf, sizeof(buf), "%u ", n);
+ RETERR(isc_str_tobuffer(buf, target));
+
+ /* hash algo */
+ n = uint8_fromregion(&sr);
+ isc_region_consume(&sr, 1);
+ snprintf(buf, sizeof(buf), "%u", n);
+ RETERR(isc_str_tobuffer(buf, target));
+
+ /* Digest */
+ if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
+ RETERR(isc_str_tobuffer(" (", target));
+ RETERR(isc_str_tobuffer(tctx->linebreak, target));
+ if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) {
+ if (tctx->width == 0) /* No splitting */
+ RETERR(isc_hex_totext(&sr, 0, "", target));
+ else
+ RETERR(isc_hex_totext(&sr, tctx->width - 2,
+ tctx->linebreak, target));
+ } else
+ RETERR(isc_str_tobuffer("[omitted]", target));
+ if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
+ RETERR(isc_str_tobuffer(" )", target));
+ return (ISC_R_SUCCESS);
+}
+
+static inline isc_result_t
+fromwire_zonemd(ARGS_FROMWIRE) {
+ isc_region_t sr;
+
+ REQUIRE(type == dns_rdatatype_zonemd);
+
+ UNUSED(type);
+ UNUSED(rdclass);
+ UNUSED(dctx);
+ UNUSED(options);
+
+ isc_buffer_activeregion(source, &sr);
+ /*
+ * serial: 4
+ * scheme: 1
+ * hash algorith: 1
+ * digest: at least 1
+ */
+ if (sr.length < 7)
+ return (ISC_R_UNEXPECTEDEND);
+
+ if (sr.base[5] == DNS_ZONEMD_DIGEST_SHA384) {
+ if (sr.length < 6 + ISC_SHA384_DIGESTLENGTH)
+ return (ISC_R_UNEXPECTEDEND);
+ else
+ /* truncate in case there is additional junk */
+ sr.length = 6 + ISC_SHA384_DIGESTLENGTH;
+ }
+
+ isc_buffer_forward(source, sr.length);
+ return (isc_mem_tobuffer(target, sr.base, sr.length));
+}
+
+static inline isc_result_t
+towire_zonemd(ARGS_TOWIRE) {
+ isc_region_t sr;
+
+ REQUIRE(rdata->type == dns_rdatatype_zonemd);
+ REQUIRE(rdata->length != 0);
+
+ UNUSED(cctx);
+
+ dns_rdata_toregion(rdata, &sr);
+ return (isc_mem_tobuffer(target, sr.base, sr.length));
+}
+
+#endif /* RDATA_GENERIC_ZONEMD_63_C */