diff --git a/CHANGES b/CHANGES index 2b4a10b061..8fde9a4996 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +5264. [func] New DNS Cookie algorithm - siphash24 - has been added to + BIND 9. [GL #605] + --- 9.11.9 released --- 5260. [bug] dnstap-read was producing malformed output for large diff --git a/bin/named/client.c b/bin/named/client.c index c54a70b68e..b59ae957de 100644 --- a/bin/named/client.c +++ b/bin/named/client.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1928,6 +1929,42 @@ compute_cookie(ns_client_t *client, uint32_t when, uint32_t nonce, const unsigned char *secret, isc_buffer_t *buf) { switch (ns_g_server->cookiealg) { + case ns_cookiealg_siphash24: { + unsigned char digest[ISC_SIPHASH24_TAG_LENGTH] = { 0 }; + unsigned char input[16 + 16] = { 0 }; + size_t inputlen = 0; + isc_netaddr_t netaddr; + unsigned char *cp; + + cp = isc_buffer_used(buf); + isc_buffer_putmem(buf, client->cookie, 8); + isc_buffer_putuint8(buf, NS_COOKIE_VERSION_1); + isc_buffer_putuint24(buf, 0); /* Reserved */ + isc_buffer_putuint32(buf, when); + + memmove(input, cp, 16); + + isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr); + switch (netaddr.family) { + case AF_INET: + cp = (unsigned char *)&netaddr.type.in; + memmove(input + 16, cp, 4); + inputlen = 20; + break; + case AF_INET6: + cp = (unsigned char *)&netaddr.type.in6; + memmove(input + 16, cp, 16); + inputlen = 32; + break; + default: + INSIST(0); + ISC_UNREACHABLE(); + } + + isc_siphash24(secret, input, inputlen, digest); + isc_buffer_putmem(buf, digest, 8); + break; + } #if defined(HAVE_OPENSSL_AES) || defined(HAVE_OPENSSL_EVP_AES) case ns_cookiealg_aes: { unsigned char digest[ISC_AES_BLOCK_LENGTH]; @@ -1936,15 +1973,15 @@ compute_cookie(ns_client_t *client, uint32_t when, uint32_t nonce, unsigned char *cp; unsigned int i; - memset(input, 0, sizeof(input)); cp = isc_buffer_used(buf); isc_buffer_putmem(buf, client->cookie, 8); isc_buffer_putuint32(buf, nonce); isc_buffer_putuint32(buf, when); memmove(input, cp, 16); isc_aes128_crypt(secret, input, digest); - for (i = 0; i < 8; i++) + for (i = 0; i < 8; i++) { input[i] = digest[i] ^ digest[i + 8]; + } isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr); switch (netaddr.family) { case AF_INET: @@ -1957,14 +1994,19 @@ compute_cookie(ns_client_t *client, uint32_t when, uint32_t nonce, cp = (unsigned char *)&netaddr.type.in6; memmove(input + 8, cp, 16); isc_aes128_crypt(secret, input, digest); - for (i = 0; i < 8; i++) + for (i = 0; i < 8; i++) { input[i + 8] = digest[i] ^ digest[i + 8]; + } isc_aes128_crypt(ns_g_server->secret, input + 8, digest); break; + default: + INSIST(0); + ISC_UNREACHABLE(); } - for (i = 0; i < 8; i++) + for (i = 0; i < 8; i++) { digest[i] ^= digest[i + 8]; + } isc_buffer_putmem(buf, digest, 8); break; } diff --git a/bin/named/include/named/types.h b/bin/named/include/named/types.h index 486ec31777..7999d107e1 100644 --- a/bin/named/include/named/types.h +++ b/bin/named/include/named/types.h @@ -43,7 +43,10 @@ typedef ISC_LIST(ns_altsecret_t) ns_altsecretlist_t; typedef enum { ns_cookiealg_aes, ns_cookiealg_sha1, - ns_cookiealg_sha256 + ns_cookiealg_sha256, + ns_cookiealg_siphash24 } ns_cookiealg_t; +#define NS_COOKIE_VERSION_1 1 + #endif /* NAMED_TYPES_H */ diff --git a/bin/named/named.conf.docbook b/bin/named/named.conf.docbook index 34afce024e..33a2bf1391 100644 --- a/bin/named/named.conf.docbook +++ b/bin/named/named.conf.docbook @@ -238,7 +238,7 @@ options { check-wildcard boolean; cleaning-interval integer; clients-per-query integer; - cookie-algorithm ( aes | sha1 | sha256 ); + cookie-algorithm ( aes | sha1 | sha256 | siphash24 ); cookie-secret string; coresize ( default | unlimited | sizeval ); datasize ( default | unlimited | sizeval ); diff --git a/bin/named/server.c b/bin/named/server.c index 767d83f9d7..c917cad11c 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -8482,7 +8483,9 @@ load_configuration(const char *filename, ns_server_t *server, obj = NULL; result = ns_config_get(maps, "cookie-algorithm", &obj); INSIST(result == ISC_R_SUCCESS); - if (strcasecmp(cfg_obj_asstring(obj), "aes") == 0) { + if (strcasecmp(cfg_obj_asstring(obj), "siphash24") == 0) { + server->cookiealg = ns_cookiealg_siphash24; + } else if (strcasecmp(cfg_obj_asstring(obj), "aes") == 0) { #if defined(HAVE_OPENSSL_AES) || defined(HAVE_OPENSSL_EVP_AES) server->cookiealg = ns_cookiealg_aes; #else @@ -8545,11 +8548,16 @@ load_configuration(const char *filename, ns_server_t *server, usedlength = isc_buffer_usedlength(&b); switch (server->cookiealg) { + case ns_cookiealg_siphash24: + if (usedlength != ISC_SIPHASH24_KEY_LENGTH) { + CHECKM(ISC_R_RANGE, + "SipHash-2-4 cookie-secret must be 128 bits"); + } + break; case ns_cookiealg_aes: if (usedlength != ISC_AES128_KEYLENGTH) { CHECKM(ISC_R_RANGE, - "AES cookie-secret must be " - "128 bits"); + "AES cookie-secret must be 128 bits"); } break; case ns_cookiealg_sha1: diff --git a/bin/tests/system/cookie/bad-cookie-badaes.conf.in b/bin/tests/system/cookie/bad-cookie-badaes.conf.in new file mode 100644 index 0000000000..6c8e42cabd --- /dev/null +++ b/bin/tests/system/cookie/bad-cookie-badaes.conf.in @@ -0,0 +1,15 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + cookie-algorithm aes; + cookie-secret "ebc7701beabb4a40c57d140eeb6733faaa"; // 136 bits +}; diff --git a/bin/tests/system/cookie/bad-cookie-badsiphash24.conf b/bin/tests/system/cookie/bad-cookie-badsiphash24.conf new file mode 100644 index 0000000000..392cb04473 --- /dev/null +++ b/bin/tests/system/cookie/bad-cookie-badsiphash24.conf @@ -0,0 +1,15 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + cookie-algorithm siphash24; + cookie-secret "ebc7701beabb4a40c57d140eeb6733faaabbccdd"; // 160 bits +}; diff --git a/bin/tests/system/cookie/clean.sh b/bin/tests/system/cookie/clean.sh index 01abbc8f6a..eed42a264b 100644 --- a/bin/tests/system/cookie/clean.sh +++ b/bin/tests/system/cookie/clean.sh @@ -13,3 +13,5 @@ rm -f ns1/named_dump.db rm -f ns*/named.memstats rm -f ns*/named.run rm -f ns*/named.lock +rm -f ./good-cookie-aes.conf +rm -f ./bad-cookie-badaes.conf diff --git a/bin/tests/system/cookie/good-cookie-aes.conf.in b/bin/tests/system/cookie/good-cookie-aes.conf.in new file mode 100644 index 0000000000..efb56a67a4 --- /dev/null +++ b/bin/tests/system/cookie/good-cookie-aes.conf.in @@ -0,0 +1,15 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + cookie-algorithm aes; + cookie-secret "ebc7701beabb4a40c57d140eeb6733fa"; // 128 bits +}; diff --git a/bin/tests/system/cookie/good-cookie-siphash24.conf b/bin/tests/system/cookie/good-cookie-siphash24.conf new file mode 100644 index 0000000000..2e2f628543 --- /dev/null +++ b/bin/tests/system/cookie/good-cookie-siphash24.conf @@ -0,0 +1,15 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + cookie-algorithm siphash24; + cookie-secret "ebc7701beabb4a40c57d140eeb6733fa"; // 128 bits +}; diff --git a/bin/tests/system/cookie/ns4/named.conf.in b/bin/tests/system/cookie/ns4/named.conf.in index cd7c07f23c..c993dd2db5 100644 --- a/bin/tests/system/cookie/ns4/named.conf.in +++ b/bin/tests/system/cookie/ns4/named.conf.in @@ -27,8 +27,8 @@ options { listen-on { 10.53.0.4; }; listen-on-v6 { none; }; recursion yes; - cookie-algorithm sha1; - cookie-secret "569d36a6cc27d6bf55502183302ba352745255a2"; + cookie-algorithm siphash24; + cookie-secret "569d36a6cc27d6bf55502183302ba352"; require-server-cookie yes; }; diff --git a/bin/tests/system/cookie/ns5/named.conf.in b/bin/tests/system/cookie/ns5/named.conf.in index 0d050a62ea..a46f32f9f5 100644 --- a/bin/tests/system/cookie/ns5/named.conf.in +++ b/bin/tests/system/cookie/ns5/named.conf.in @@ -27,9 +27,9 @@ options { listen-on { 10.53.0.5; }; listen-on-v6 { none; }; recursion yes; - cookie-algorithm sha1; - cookie-secret "569d36a6cc27d6bf55502183302ba352745255a2"; - cookie-secret "6b300e27a0db46d4b046e4189790fa7db3c1ffb3"; + cookie-algorithm siphash24; + cookie-secret "569d36a6cc27d6bf55502183302ba352"; + cookie-secret "6b300e27a0db46d4b046e4189790fa7d"; require-server-cookie yes; }; diff --git a/bin/tests/system/cookie/ns6/named.conf.in b/bin/tests/system/cookie/ns6/named.conf.in index 634a939bd9..b61d321315 100644 --- a/bin/tests/system/cookie/ns6/named.conf.in +++ b/bin/tests/system/cookie/ns6/named.conf.in @@ -27,8 +27,8 @@ options { listen-on { 10.53.0.6; }; listen-on-v6 { none; }; recursion yes; - cookie-algorithm sha1; - cookie-secret "6b300e27a0db46d4b046e4189790fa7db3c1ffb3"; + cookie-algorithm siphash24; + cookie-secret "6b300e27a0db46d4b046e4189790fa7d"; require-server-cookie yes; }; diff --git a/bin/tests/system/cookie/setup.sh b/bin/tests/system/cookie/setup.sh index 7929f09545..f4b1335022 100644 --- a/bin/tests/system/cookie/setup.sh +++ b/bin/tests/system/cookie/setup.sh @@ -21,3 +21,8 @@ copy_setports ns5/named.conf.in ns5/named.conf copy_setports ns6/named.conf.in ns6/named.conf copy_setports ns7/named.conf.in ns7/named.conf copy_setports ns8/named.conf.in ns8/named.conf + +if ../feature-test --have-aes; then + cp good-cookie-aes.conf.in good-cookie-aes.conf + cp bad-cookie-badaes.conf.in bad-cookie-badaes.conf +fi diff --git a/bin/tests/system/cookie/tests.sh b/bin/tests/system/cookie/tests.sh index 0c4d25a77a..f82bb00546 100755 --- a/bin/tests/system/cookie/tests.sh +++ b/bin/tests/system/cookie/tests.sh @@ -211,12 +211,12 @@ status=`expr $status + $ret` # # Test shared cookie-secret support. # -# NS4 has cookie-secret "569d36a6cc27d6bf55502183302ba352745255a2"; +# NS4 has cookie-secret "569d36a6cc27d6bf55502183302ba352"; # -# NS5 has cookie-secret "569d36a6cc27d6bf55502183302ba352745255a2"; -# NS5 has cookie-secret "6b300e27a0db46d4b046e4189790fa7db3c1ffb3"; (alternate) +# NS5 has cookie-secret "569d36a6cc27d6bf55502183302ba352"; +# NS5 has cookie-secret "6b300e27a0db46d4b046e4189790fa7d"; (alternate) # -# NS6 has cookie-secret "6b300e27a0db46d4b046e4189790fa7db3c1ffb3"; +# NS6 has cookie-secret "6b300e27a0db46d4b046e4189790fa7d"; # # Server cookies from NS4 are accepted by NS5 and not NS6 # Server cookies from NS5 are accepted by NS4 and not NS6 diff --git a/bin/tests/system/feature-test.c b/bin/tests/system/feature-test.c index 27a02d0b3a..c1249ed62c 100644 --- a/bin/tests/system/feature-test.c +++ b/bin/tests/system/feature-test.c @@ -41,6 +41,7 @@ usage() { fprintf(stderr, " --enable-filter-aaaa\n"); fprintf(stderr, " --gethostname\n"); fprintf(stderr, " --gssapi\n"); + fprintf(stderr, " --have-aes\n"); fprintf(stderr, " --have-dlopen\n"); fprintf(stderr, " --have-geoip\n"); fprintf(stderr, " --have-geoip2\n"); @@ -114,6 +115,14 @@ main(int argc, char **argv) { #endif } + if (strcmp(argv[1], "--have-aes") == 0) { +#if defined(HAVE_OPENSSL_AES) || defined(HAVE_OPENSSL_EVP_AES) + return (0); +#else + return (1); +#endif + } + if (strcmp(argv[1], "--have-dlopen") == 0) { #if defined(HAVE_DLOPEN) && defined(ISC_DLZ_DLOPEN) return (0); diff --git a/bin/tests/system/ifconfig.sh b/bin/tests/system/ifconfig.sh index aedb35fd0c..41b0182f80 100755 --- a/bin/tests/system/ifconfig.sh +++ b/bin/tests/system/ifconfig.sh @@ -105,13 +105,7 @@ case "$1" in [ "$ipv6" ] && ifconfig lo0 inet6 \ fd92:7065:b8e:${ipv6}ff::$ns alias ;; - *-unknown-netbsd*) - ifconfig lo0 10.53.$i.$ns alias \ - netmask 255.255.255.0 - [ "$ipv6" ] && ifconfig lo0 inet6 \ - fd92:7065:b8e:${ipv6}ff::$ns alias - ;; - *-unknown-openbsd*) + *-unknown-dragonfly*|*-unknown-netbsd*|*-unknown-openbsd*) ifconfig lo0 10.53.$i.$ns alias \ netmask 255.255.255.0 [ "$ipv6" ] && ifconfig lo0 inet6 \ diff --git a/config.h.in b/config.h.in index 8ae7692568..a45d3780bc 100644 --- a/config.h.in +++ b/config.h.in @@ -139,9 +139,6 @@ int sigwait(const unsigned int *set, int *sig); /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD -/* Use AES for Client Cookie generation */ -#undef AES_CC - /* Define to enable the "filter-aaaa-on-v4" and "filter-aaaa-on-v6" options. */ #undef ALLOW_FILTER_AAAA @@ -540,12 +537,6 @@ int sigwait(const unsigned int *set, int *sig); /* Define if zlib was found */ #undef HAVE_ZLIB -/* Use HMAC-SHA1 for Client Cookie generation */ -#undef HMAC_SHA1_CC - -/* Use HMAC-SHA256 for Client Cookie generation */ -#undef HMAC_SHA256_CC - /* return type of gai_strerror */ #undef IRS_GAISTRERROR_RETURN_T diff --git a/config.h.win32 b/config.h.win32 index 71b94415f4..f441b1f341 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -367,15 +367,6 @@ typedef __int64 off_t; /* HMAC_*() return ints */ @HMAC_RETURN_INT@ -/* Use AES for Client Cookie generation */ -@AES_CC@ - -/* Use HMAC-SHA1 for Client Cookie generation */ -@HMAC_SHA1_CC@ - -/* Use HMAC-SHA256 for Client Cookie generation */ -@HMAC_SHA256_CC@ - /* Define to 1 if you have the `readline' function. */ @HAVE_READLINE@ diff --git a/configure b/configure index 4a5db6c5f4..2a4d9ed025 100755 --- a/configure +++ b/configure @@ -1797,8 +1797,7 @@ Optional Packages: --with-gost Crypto GOST [yes|no|raw|asn1]. --with-eddsa Crypto EDDSA [yes|all|no]. --with-aes Crypto AES - --with-cc-alg=ALG choose the algorithm for Client Cookie - [aes|sha1|sha256] + --with-cc-alg=ALG deprecated --with-lmdb=PATH build with LMDB library [yes|no|path] --with-libxml2=PATH build with libxml2 library [yes|no|path] --with-libjson=PATH build with libjson0 library [yes|no|path] @@ -17053,7 +17052,7 @@ fi if test "${with_aes+set}" = set; then : withval=$with_aes; with_aes="$withval" else - with_aes="checkcc" + with_aes="yes" fi @@ -17068,44 +17067,6 @@ else fi -# -# Client Cookie algorithm choice -# - -# Check whether --with-cc-alg was given. -if test "${with_cc_alg+set}" = set; then : - withval=$with_cc_alg; with_cc_alg="$withval" -else - with_cc_alg="auto" -fi - - -case $with_cc_alg in - *1) - with_cc_alg="sha1" - ;; - *2*) - with_cc_alg="sha256" - ;; - auto) - if test "no" != "$with_aes" - then - with_aes="yes" - fi - ;; - *) - with_cc_alg="aes" - if test "no" != "$with_aes" - then - with_aes="yes" - fi - ;; -esac -if test "checkcc" = "with_aes" -then - with_aes="no" -fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OpenSSL library" >&5 $as_echo_n "checking for OpenSSL library... " >&6; } OPENSSL_WARNING= @@ -17822,58 +17783,22 @@ fi # Choose Client Cookie algorithm # -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the Algorithm for Client Cookie" >&5 -$as_echo_n "checking for the Algorithm for Client Cookie... " >&6; } -if test "auto" = "$with_cc_alg" -then - if test "yes" = "$with_aes" - then - with_cc_alg="aes" - else - with_cc_alg="sha256" - fi +# Check whether --with-cc-alg was given. +if test "${with_cc_alg+set}" = set; then : + withval=$with_cc_alg; : +else + with_cc_alg="siphash24" fi -case $with_cc_alg in - sha1) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: sha1" >&5 -$as_echo "sha1" >&6; } - if test "X$CRYPTO" = "X-DOPENSSL" - then - if test "checkcc" = "$want_openssl_hash" - then - want_openssl_hash="yes" - fi - fi -$as_echo "#define HMAC_SHA1_CC 1" >>confdefs.h - ;; - sha256) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: sha256" >&5 -$as_echo "sha256" >&6; } - if test "X$CRYPTO" = "X-DOPENSSL" - then - if test "checkcc" = "$want_openssl_hash" - then - want_openssl_hash="yes" - fi - fi - -$as_echo "#define HMAC_SHA256_CC 1" >>confdefs.h - - ;; - aes) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: aes" >&5 -$as_echo "aes" >&6; } - if test "yes" != "$with_aes" - then - as_fn_error $? "\"Client Cookie wants to use unavailable AES\"" "$LINENO" 5; - fi - -$as_echo "#define AES_CC 1" >>confdefs.h - - ;; +case $with_cc_alg in #( + siphash24) : + : ;; #( + *) : + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: The Client Cookie is always SipHash 2-4 based" >&5 +$as_echo "$as_me: WARNING: The Client Cookie is always SipHash 2-4 based" >&2;} ;; esac + if test "checkcc" = "$want_openssl_hash" then want_openssl_hash="no" diff --git a/configure.ac b/configure.ac index ffd54c78d7..c4c525c72f 100644 --- a/configure.ac +++ b/configure.ac @@ -1481,7 +1481,7 @@ AC_ARG_WITH(gost, AC_ARG_WITH(eddsa, AS_HELP_STRING([--with-eddsa], [Crypto EDDSA [yes|all|no].]), with_eddsa="$withval", with_eddsa="auto") AC_ARG_WITH(aes, AS_HELP_STRING([--with-aes], [Crypto AES]), - with_aes="$withval", with_aes="checkcc") + with_aes="$withval", with_aes="yes") # # was --enable-openssl-hash specified? @@ -1491,41 +1491,6 @@ AC_ARG_ENABLE(openssl-hash, [use OpenSSL for hash functions [default=no]]), want_openssl_hash="$enableval", want_openssl_hash="checkcc") -# -# Client Cookie algorithm choice -# -AC_ARG_WITH(cc-alg, - AS_HELP_STRING([--with-cc-alg=ALG], - [choose the algorithm for Client Cookie - [aes|sha1|sha256]]), - with_cc_alg="$withval", with_cc_alg="auto") - -case $with_cc_alg in - *1) - with_cc_alg="sha1" - ;; - *2*) - with_cc_alg="sha256" - ;; - auto) - if test "no" != "$with_aes" - then - with_aes="yes" - fi - ;; - *) - with_cc_alg="aes" - if test "no" != "$with_aes" - then - with_aes="yes" - fi - ;; -esac -if test "checkcc" = "with_aes" -then - with_aes="no" -fi - AC_MSG_CHECKING(for OpenSSL library) OPENSSL_WARNING= openssldirs="/usr /usr/local /usr/local/ssl /opt/local /usr/pkg /usr/sfw" @@ -2055,52 +2020,14 @@ AC_SUBST(ISC_PLATFORM_WANTAES) # # Choose Client Cookie algorithm # +AC_ARG_WITH([cc-alg], + [AS_HELP_STRING([--with-cc-alg=ALG], [deprecated])], + [:], [with_cc_alg="siphash24"]) + +AS_CASE([$with_cc_alg], + [siphash24],[:], + [AC_MSG_WARN([The Client Cookie is always SipHash 2-4 based])]) -AC_MSG_CHECKING(for the Algorithm for Client Cookie) -if test "auto" = "$with_cc_alg" -then - if test "yes" = "$with_aes" - then - with_cc_alg="aes" - else - with_cc_alg="sha256" - fi -fi -case $with_cc_alg in - sha1) - AC_MSG_RESULT(sha1) - if test "X$CRYPTO" = "X-DOPENSSL" - then - if test "checkcc" = "$want_openssl_hash" - then - want_openssl_hash="yes" - fi - fi - AC_DEFINE(HMAC_SHA1_CC, 1, - [Use HMAC-SHA1 for Client Cookie generation]) - ;; - sha256) - AC_MSG_RESULT(sha256) - if test "X$CRYPTO" = "X-DOPENSSL" - then - if test "checkcc" = "$want_openssl_hash" - then - want_openssl_hash="yes" - fi - fi - AC_DEFINE(HMAC_SHA256_CC, 1, - [Use HMAC-SHA256 for Client Cookie generation]) - ;; - aes) - AC_MSG_RESULT(aes) - if test "yes" != "$with_aes" - then - AC_MSG_ERROR("Client Cookie wants to use unavailable AES"); - fi - AC_DEFINE(AES_CC, 1, - [Use AES for Client Cookie generation]) - ;; -esac if test "checkcc" = "$want_openssl_hash" then want_openssl_hash="no" diff --git a/doc/arm/notes.xml b/doc/arm/notes.xml index 23d2710f68..02f9363b14 100644 --- a/doc/arm/notes.xml +++ b/doc/arm/notes.xml @@ -112,6 +112,18 @@ and IPv6 lookups. [GL #182] + + + A SipHash 2-4 based DNS Cookie (RFC 7873) algorithm has been added. + + + If you are running multiple DNS Servers (different versions of BIND 9 + or DNS server from multiple vendors) responding from the same IP + address (anycast or load-balancing scenarios), you'll have to make + sure that all the servers are configured with the same DNS Cookie + algorithm and same Server Secret for the best performance. + + diff --git a/doc/misc/options b/doc/misc/options index c6b80d5a8e..e11beed292 100644 --- a/doc/misc/options +++ b/doc/misc/options @@ -114,7 +114,7 @@ options { check-wildcard ; cleaning-interval ; clients-per-query ; - cookie-algorithm ( aes | sha1 | sha256 ); + cookie-algorithm ( aes | sha1 | sha256 | siphash24 ); cookie-secret ; // may occur multiple times coresize ( default | unlimited | ); datasize ( default | unlimited | ); diff --git a/lib/bind9/check.c b/lib/bind9/check.c index 2a0e7353e6..d45e732b1c 100644 --- a/lib/bind9/check.c +++ b/lib/bind9/check.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -1417,8 +1418,14 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, if (strcasecmp(ccalg, "aes") == 0 && usedlength != ISC_AES128_KEYLENGTH) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, - "AES cookie-secret must be " - "128 bits"); + "AES cookie-secret must be 128 bits"); + if (result == ISC_R_SUCCESS) + result = ISC_R_RANGE; + } + if (strcasecmp(ccalg, "siphash24") == 0 && + usedlength != ISC_SIPHASH24_KEY_LENGTH) { + cfg_obj_log(obj, logctx, ISC_LOG_ERROR, + "SipHash-2-4 cookie-secret must be 128 bits"); if (result == ISC_R_SUCCESS) result = ISC_R_RANGE; } diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 3a945366f3..8ad7e249af 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -22,18 +22,13 @@ #include #include #include +#include #include #include #include #include #include -#ifdef AES_CC -#include -#else -#include -#endif - #include #include #include @@ -207,7 +202,7 @@ typedef struct query { isc_mem_t * mctx; dns_dispatchmgr_t * dispatchmgr; dns_dispatch_t * dispatch; - bool exclusivesocket; + bool exclusivesocket; dns_adbaddrinfo_t * addrinfo; isc_socket_t * tcpsocket; isc_time_t start; @@ -219,7 +214,7 @@ typedef struct query { dns_tsigkey_t *tsigkey; isc_socketevent_t sendevent; isc_dscp_t dscp; - int ednsversion; + int ednsversion; unsigned int options; unsigned int attributes; unsigned int sends; @@ -2009,79 +2004,46 @@ add_triededns512(fetchctx_t *fctx, isc_sockaddr_t *address) { ISC_LIST_INITANDAPPEND(fctx->edns512, tried, link); } +static inline size_t +addr2buf(void *buf, const size_t bufsize, const isc_sockaddr_t *sockaddr) { + isc_netaddr_t netaddr; + isc_netaddr_fromsockaddr(&netaddr, sockaddr); + switch (netaddr.family) { + case AF_INET: + INSIST(bufsize >= 4); + memmove(buf, &netaddr.type.in, 4); + return (4); + case AF_INET6: + INSIST(bufsize >= 16); + memmove(buf, &netaddr.type.in6, 16); + return (16); + default: + INSIST(0); + ISC_UNREACHABLE(); + } + return (0); +} + +static inline size_t +add_serveraddr(uint8_t *buf, const size_t bufsize, const resquery_t *query) +{ + return (addr2buf(buf, bufsize, &query->addrinfo->sockaddr)); +} + +#define CLIENT_COOKIE_SIZE 8U + static void -compute_cc(resquery_t *query, unsigned char *cookie, size_t len) { -#ifdef AES_CC - unsigned char digest[ISC_AES_BLOCK_LENGTH]; - unsigned char input[16]; - isc_netaddr_t netaddr; - unsigned int i; +compute_cc(const resquery_t *query, uint8_t *cookie, const size_t len) { + INSIST(len >= CLIENT_COOKIE_SIZE); + INSIST(sizeof(query->fctx->res->view->secret) + >= ISC_SIPHASH24_KEY_LENGTH); - INSIST(len >= 8U); + uint8_t buf[16] = { 0 }; + size_t buflen = add_serveraddr(buf, sizeof(buf), query); - isc_netaddr_fromsockaddr(&netaddr, &query->addrinfo->sockaddr); - switch (netaddr.family) { - case AF_INET: - memmove(input, (unsigned char *)&netaddr.type.in, 4); - memset(input + 4, 0, 12); - break; - case AF_INET6: - memmove(input, (unsigned char *)&netaddr.type.in6, 16); - break; - } - isc_aes128_crypt(query->fctx->res->view->secret, input, digest); - for (i = 0; i < 8; i++) - digest[i] ^= digest[i + 8]; - memmove(cookie, digest, 8); -#endif -#ifdef HMAC_SHA1_CC - unsigned char digest[ISC_SHA1_DIGESTLENGTH]; - isc_netaddr_t netaddr; - isc_hmacsha1_t hmacsha1; - - INSIST(len >= 8U); - - isc_hmacsha1_init(&hmacsha1, query->fctx->res->view->secret, - ISC_SHA1_DIGESTLENGTH); - isc_netaddr_fromsockaddr(&netaddr, &query->addrinfo->sockaddr); - switch (netaddr.family) { - case AF_INET: - isc_hmacsha1_update(&hmacsha1, - (unsigned char *)&netaddr.type.in, 4); - break; - case AF_INET6: - isc_hmacsha1_update(&hmacsha1, - (unsigned char *)&netaddr.type.in6, 16); - break; - } - isc_hmacsha1_sign(&hmacsha1, digest, sizeof(digest)); - memmove(cookie, digest, 8); - isc_hmacsha1_invalidate(&hmacsha1); -#endif -#ifdef HMAC_SHA256_CC - unsigned char digest[ISC_SHA256_DIGESTLENGTH]; - isc_netaddr_t netaddr; - isc_hmacsha256_t hmacsha256; - - INSIST(len >= 8U); - - isc_hmacsha256_init(&hmacsha256, query->fctx->res->view->secret, - ISC_SHA256_DIGESTLENGTH); - isc_netaddr_fromsockaddr(&netaddr, &query->addrinfo->sockaddr); - switch (netaddr.family) { - case AF_INET: - isc_hmacsha256_update(&hmacsha256, - (unsigned char *)&netaddr.type.in, 4); - break; - case AF_INET6: - isc_hmacsha256_update(&hmacsha256, - (unsigned char *)&netaddr.type.in6, 16); - break; - } - isc_hmacsha256_sign(&hmacsha256, digest, sizeof(digest)); - memmove(cookie, digest, 8); - isc_hmacsha256_invalidate(&hmacsha256); -#endif + uint8_t digest[ISC_SIPHASH24_TAG_LENGTH] = { 0 }; + isc_siphash24(query->fctx->res->view->secret, buf, buflen, digest); + memmove(cookie, digest, CLIENT_COOKIE_SIZE); } static isc_result_t @@ -2560,10 +2522,12 @@ resquery_send(resquery_t *query) { */ dns_message_reset(fctx->qmessage, DNS_MESSAGE_INTENTRENDER); - if (query->exclusivesocket) + if (query->exclusivesocket) { sock = dns_dispatch_getentrysocket(query->dispentry); - else + } else { sock = dns_dispatch_getsocket(query->dispatch); + } + /* * Send the query! */ @@ -4871,9 +4835,9 @@ validated(isc_task_t *task, isc_event_t *event) { REQUIRE(event->ev_type == DNS_EVENT_VALIDATORDONE); valarg = event->ev_arg; fctx = valarg->fctx; + REQUIRE(VALID_FCTX(fctx)); res = fctx->res; addrinfo = valarg->addrinfo; - REQUIRE(VALID_FCTX(fctx)); REQUIRE(!ISC_LIST_EMPTY(fctx->validators)); vevent = (dns_validatorevent_t *)event; diff --git a/lib/isc/Makefile.in b/lib/isc/Makefile.in index ba53ef1091..0fd08379ae 100644 --- a/lib/isc/Makefile.in +++ b/lib/isc/Makefile.in @@ -60,7 +60,7 @@ OBJS = @ISC_EXTRA_OBJS@ @ISC_PK11_O@ @ISC_PK11_RESULT_O@ \ parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \ ratelimiter.@O@ refcount.@O@ region.@O@ regex.@O@ result.@O@ \ rwlock.@O@ \ - safe.@O@ serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \ + safe.@O@ serial.@O@ siphash.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \ string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \ tm.@O@ timer.@O@ version.@O@ \ ${UNIXOBJS} ${NLSOBJS} ${THREADOBJS} @@ -79,7 +79,7 @@ SRCS = @ISC_EXTRA_SRCS@ @ISC_PK11_C@ @ISC_PK11_RESULT_C@ \ netaddr.c netscope.c pool.c ondestroy.c \ parseint.c portset.c quota.c radix.c random.c ${CHACHASRCS} \ ratelimiter.c refcount.c region.c regex.c result.c rwlock.c \ - safe.c serial.c sha1.c sha2.c sockaddr.c stats.c string.c \ + safe.c serial.c siphash.c sha1.c sha2.c sockaddr.c stats.c string.c \ strtoul.c symtab.c task.c taskpool.c timer.c \ tm.c version.c diff --git a/lib/isc/include/isc/Makefile.in b/lib/isc/include/isc/Makefile.in index 46982068a7..46dfd39d9f 100644 --- a/lib/isc/include/isc/Makefile.in +++ b/lib/isc/include/isc/Makefile.in @@ -21,7 +21,7 @@ VERSION=@BIND9_VERSION@ HEADERS = aes.h app.h assertions.h boolean.h backtrace.h base32.h base64.h \ bind9.h buffer.h bufferlist.h commandline.h \ counter.h crc64.h deprecated.h entropy.h errno.h \ - error.h event.h eventclass.h file.h formatcheck.h \ + endian.h error.h event.h eventclass.h file.h formatcheck.h \ fsaccess.h hash.h heap.h hex.h hmacmd5.h hmacsha.h \ ht.h httpd.h int.h interfaceiter.h @ISC_IPV6_H@ iterated_hash.h \ json.h lang.h lex.h lfsr.h lib.h likely.h list.h \ @@ -30,7 +30,7 @@ HEADERS = aes.h app.h assertions.h boolean.h backtrace.h base32.h base64.h \ parseint.h pool.h portset.h print.h queue.h quota.h \ radix.h random.h ratelimiter.h refcount.h regex.h \ region.h resource.h result.h resultclass.h rwlock.h \ - safe.h serial.h sha1.h sha2.h sockaddr.h socket.h \ + safe.h serial.h siphash.h sha1.h sha2.h sockaddr.h socket.h \ stats.h stdio.h stdlib.h string.h symtab.h task.h \ taskpool.h timer.h tm.h types.h util.h version.h \ xml.h diff --git a/lib/isc/include/isc/endian.h b/lib/isc/include/isc/endian.h new file mode 100644 index 0000000000..54421d55d4 --- /dev/null +++ b/lib/isc/include/isc/endian.h @@ -0,0 +1,187 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#pragma once + +#if defined(__DragonFly__) || defined(__FreeBSD__) || \ + defined(__NetBSD__) || defined (__OpenBSD__) || defined(__bsdi__) + +# include + +/* + * Recent BSDs should have [bl]e{16,32,64}toh() defined in . + * Older ones might not, but these should have the alternatively named + * [bl]etoh{16,32,64}() functions defined. + */ +# ifndef be16toh +# define be16toh(x) betoh16(x) +# define le16toh(x) letoh16(x) +# define be32toh(x) betoh32(x) +# define le32toh(x) letoh32(x) +# define be64toh(x) betoh64(x) +# define le64toh(x) letoh64(x) +# endif /* !be16toh */ + +#elif defined(_WIN32) + +/* + * Windows is always little-endian and has its own byte-swapping routines, so + * use these. + */ + +# include + +# define htobe16(x) _byteswap_ushort(x) +# define htole16(x) (x) +# define be16toh(x) _byteswap_ushort(x) +# define le16toh(x) (x) + +# define htobe32(x) _byteswap_ulong(x) +# define htole32(x) (x) +# define be32toh(x) _byteswap_ulong(x) +# define le32toh(x) (x) + +# define htobe64(x) _byteswap_uint64(x) +# define htole64(x) (x) +# define be64toh(x) _byteswap_uint64(x) +# define le64toh(x) (x) + +#elif defined __APPLE__ + +/* + * macOS has its own byte-swapping routines, so use these. + */ + +# include + +# define htobe16(x) OSSwapHostToBigInt16(x) +# define htole16(x) OSSwapHostToLittleInt16(x) +# define be16toh(x) OSSwapBigToHostInt16(x) +# define le16toh(x) OSSwapLittleToHostInt16(x) + +# define htobe32(x) OSSwapHostToBigInt32(x) +# define htole32(x) OSSwapHostToLittleInt32(x) +# define be32toh(x) OSSwapBigToHostInt32(x) +# define le32toh(x) OSSwapLittleToHostInt32(x) + +# define htobe64(x) OSSwapHostToBigInt64(x) +# define htole64(x) OSSwapHostToLittleInt64(x) +# define be64toh(x) OSSwapBigToHostInt64(x) +# define le64toh(x) OSSwapLittleToHostInt64(x) + +#elif defined(sun) || defined(__sun) || defined(__SVR4) + +/* + * For Solaris, rely on the fallback definitions below, though use + * Solaris-specific versions of bswap_{16,32,64}(). + */ + +# include + +# define bswap_16(x) BSWAP_16(x) +# define bswap_32(x) BSWAP_32(x) +# define bswap_64(x) BSWAP_64(x) + +#elif defined(__ANDROID__) || defined(__CYGWIN__) || \ + defined(__GNUC__) || defined(__GNU__) + +# include +# include + +#else + +#endif /* Specific platform support */ + +/* + * Fallback definitions. + */ + +#include + +#ifndef bswap_16 +# define bswap_16(x) \ + ((uint16_t)((((uint16_t) (x) & 0xff00) >> 8) | \ + (((uint16_t) (x) & 0x00ff) << 8))) +#endif /* !bswap_16 */ + +#ifndef bswap_32 +# define bswap_32(x) \ + ((uint32_t)((((uint32_t) (x) & 0xff000000) >> 24) | \ + (((uint32_t) (x) & 0x00ff0000) >> 8) | \ + (((uint32_t) (x) & 0x0000ff00) << 8) | \ + (((uint32_t) (x) & 0x000000ff) << 24))) +#endif /* !bswap_32 */ + +#ifndef bswap_64 +# define bswap_64(x) \ + ((uint64_t)((((uint64_t) (x) & 0xff00000000000000ULL) >> 56) | \ + (((uint64_t) (x) & 0x00ff000000000000ULL) >> 40) | \ + (((uint64_t) (x) & 0x0000ff0000000000ULL) >> 24) | \ + (((uint64_t) (x) & 0x000000ff00000000ULL) >> 8) | \ + (((uint64_t) (x) & 0x00000000ff000000ULL) << 8) | \ + (((uint64_t) (x) & 0x0000000000ff0000ULL) << 24) | \ + (((uint64_t) (x) & 0x000000000000ff00ULL) << 40) | \ + (((uint64_t) (x) & 0x00000000000000ffULL) << 56))) +#endif /* !bswap_64 */ + +#ifndef htobe16 +# if WORDS_BIGENDIAN + +# define htobe16(x) (x) +# define htole16(x) bswap_16(x) +# define be16toh(x) (x) +# define le16toh(x) bswap_16(x) + +# else /* WORDS_BIGENDIAN */ + +# define htobe16(x) bswap_16(x) +# define htole16(x) (x) +# define be16toh(x) bswap_16(x) +# define le16toh(x) (x) + +# endif /* WORDS_BIGENDIAN */ +#endif /* !htobe16 */ + +#ifndef htobe32 +# if WORDS_BIGENDIAN + +# define htobe32(x) (x) +# define htole32(x) bswap_32(x) +# define be32toh(x) (x) +# define le32toh(x) bswap_32(x) + +# else /* WORDS_BIGENDIAN */ + +# define htobe32(x) bswap_32(x) +# define htole32(x) (x) +# define be32toh(x) bswap_32(x) +# define le32toh(x) (x) + +# endif /* WORDS_BIGENDIAN */ +#endif /* !htobe32 */ + +#ifndef htobe64 +# if WORDS_BIGENDIAN + +# define htobe64(x) (x) +# define htole64(x) bswap_64(x) +# define be64toh(x) (x) +# define le64toh(x) bswap_64(x) + +#else /* WORDS_BIGENDIAN */ + +# define htobe64(x) bswap_64(x) +# define htole64(x) (x) +# define be64toh(x) bswap_64(x) +# define le64toh(x) (x) + +# endif /* WORDS_BIGENDIAN */ +#endif /* !htobe64 */ diff --git a/lib/isc/include/isc/siphash.h b/lib/isc/include/isc/siphash.h new file mode 100644 index 0000000000..472e8f2253 --- /dev/null +++ b/lib/isc/include/isc/siphash.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + + +/*! \file isc/siphash.h */ + +#pragma once + +#include +#include +#include + +#define ISC_SIPHASH24_KEY_LENGTH 128 / 8 +#define ISC_SIPHASH24_TAG_LENGTH 64 / 8 + +ISC_LANG_BEGINDECLS + +void +isc_siphash24(const uint8_t *key, + const uint8_t *in, size_t inlen, + uint8_t *out); + +ISC_LANG_ENDDECLS diff --git a/lib/isc/siphash.c b/lib/isc/siphash.c new file mode 100644 index 0000000000..455ac4faf5 --- /dev/null +++ b/lib/isc/siphash.c @@ -0,0 +1,135 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +/* + siphash() function is SipHash reference C implementation + + Copyright (c) 2012-2016 Jean-Philippe Aumasson + Copyright (c) 2012-2014 Daniel J. Bernstein + + To the extent possible under law, the author(s) have dedicated all copyright + and related and neighboring rights to this software to the public domain + worldwide. This software is distributed without any warranty. + + You should have received a copy of the CC0 Public Domain Dedication along + with this software. If not, see . + */ + +/*! \file isc/siphash.c */ + +#include + +#include +#include +#include + +#include +#include +#include + +#define ROTATE(x, b) (uint64_t)( ((x) << (b)) | ( (x) >> (64 - (b))) ) + +#define HALF_ROUND(a, b, c, d, s, t) \ + a += b; c += d; \ + b = ROTATE(b, s) ^ a; \ + d = ROTATE(d, t) ^ c; \ + a = ROTATE(a, 32); + +#define FULL_ROUND(v0, v1, v2, v3) \ + HALF_ROUND(v0, v1, v2, v3, 13, 16); \ + HALF_ROUND(v2, v1, v0, v3, 17, 21); + +#define DOUBLE_ROUND(v0, v1, v2, v3) \ + FULL_ROUND(v0, v1, v2, v3) \ + FULL_ROUND(v0, v1, v2, v3) + +#define SIPROUND FULL_ROUND + +void +isc_siphash24(const uint8_t *k, const uint8_t *in, size_t inlen, uint8_t *out) +{ + const uint64_t *key = (const uint64_t *)k; + uint64_t k0 = le64toh(key[0]); + uint64_t k1 = le64toh(key[1]); + + uint64_t v0 = 0x736f6d6570736575ULL ^ k0; + uint64_t v1 = 0x646f72616e646f6dULL ^ k1; + uint64_t v2 = 0x6c7967656e657261ULL ^ k0; + uint64_t v3 = 0x7465646279746573ULL ^ k1; + + size_t left = inlen; + + uint64_t b = ((uint64_t)inlen) << 56; + + const uint64_t *inbuf = (const uint64_t *)in; + while (left >= 8) { + uint64_t m = le64toh(*inbuf); + + v3 ^= m; + + SIPROUND(v0, v1, v2, v3); + SIPROUND(v0, v1, v2, v3); + + v0 ^= m; + + inbuf++; left -= 8; + } + + const uint8_t *end = in + (inlen - left); + + switch (left) { + case 7: + b |= ((uint64_t)end[6]) << 48; + /* FALLTHROUGH */ + case 6: + b |= ((uint64_t)end[5]) << 40; + /* FALLTHROUGH */ + case 5: + b |= ((uint64_t)end[4]) << 32; + /* FALLTHROUGH */ + case 4: + b |= ((uint64_t)end[3]) << 24; + /* FALLTHROUGH */ + case 3: + b |= ((uint64_t)end[2]) << 16; + /* FALLTHROUGH */ + case 2: + b |= ((uint64_t)end[1]) << 8; + /* FALLTHROUGH */ + case 1: + b |= ((uint64_t)end[0]); + /* FALLTHROUGH */ + case 0: + break; + default: + INSIST(0); + ISC_UNREACHABLE(); + } + + v3 ^= b; + + SIPROUND(v0, v1, v2, v3); + SIPROUND(v0, v1, v2, v3); + + v0 ^= b; + + v2 ^= 0xff; + + SIPROUND(v0, v1, v2, v3); + SIPROUND(v0, v1, v2, v3); + SIPROUND(v0, v1, v2, v3); + SIPROUND(v0, v1, v2, v3); + + b = v0 ^ v1 ^ v2 ^ v3; + + uint64_t *outbuf = (uint64_t *)out; + *outbuf = htole64(b); +} diff --git a/lib/isc/tests/Kyuafile b/lib/isc/tests/Kyuafile index 4cd2574627..2106ba0251 100644 --- a/lib/isc/tests/Kyuafile +++ b/lib/isc/tests/Kyuafile @@ -23,6 +23,7 @@ tap_test_program{name='random_test'} tap_test_program{name='regex_test'} tap_test_program{name='result_test'} tap_test_program{name='safe_test'} +tap_test_program{name='siphash_test'} tap_test_program{name='sockaddr_test'} tap_test_program{name='socket_test'} tap_test_program{name='symtab_test'} diff --git a/lib/isc/tests/Makefile.in b/lib/isc/tests/Makefile.in index 2fdee0b61b..36d22070fe 100644 --- a/lib/isc/tests/Makefile.in +++ b/lib/isc/tests/Makefile.in @@ -30,7 +30,7 @@ SRCS = isctest.c aes_test.c atomic_test.c buffer_test.c \ heap_test.c ht_test.c inet_ntop_test.c lex_test.c \ mem_test.c netaddr_test.c parse_test.c pool_test.c \ print_test.c queue_test.c radix_test.c random_test.c \ - regex_test.c result_test.c safe_test.c sockaddr_test.c \ + regex_test.c result_test.c safe_test.c siphash_test.c sockaddr_test.c \ socket_test.c socket_test.c symtab_test.c task_test.c \ taskpool_test.c time_test.c timer_test.c @@ -42,7 +42,7 @@ TARGETS = aes_test@EXEEXT@ atomic_test@EXEEXT@ buffer_test@EXEEXT@ \ netaddr_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \ print_test@EXEEXT@ queue_test@EXEEXT@ radix_test@EXEEXT@ \ random_test@EXEEXT@ regex_test@EXEEXT@ result_test@EXEEXT@ \ - safe_test@EXEEXT@ sockaddr_test@EXEEXT@ socket_test@EXEEXT@ \ + safe_test@EXEEXT@ siphash_test@EXEEXT@ sockaddr_test@EXEEXT@ socket_test@EXEEXT@ \ socket_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \ taskpool_test@EXEEXT@ time_test@EXEEXT@ timer_test@EXEEXT@ @@ -160,6 +160,11 @@ safe_test@EXEEXT@: safe_test.@O@ ${ISCDEPLIBS} ${LDFLAGS} -o $@ safe_test.@O@ \ ${ISCLIBS} ${LIBS} +siphash_test@EXEEXT@: siphash_test.@O@ ../siphash.c ${ISCDEPLIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \ + ${LDFLAGS} -o $@ siphash_test.@O@ \ + ${ISCLIBS} ${LIBS} + socket_test@EXEEXT@: socket_test.@O@ isctest.@O@ ${ISCDEPLIBS} ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \ ${LDFLAGS} -o $@ socket_test.@O@ isctest.@O@ \ diff --git a/lib/isc/tests/siphash_test.c b/lib/isc/tests/siphash_test.c new file mode 100644 index 0000000000..0a9c431ed9 --- /dev/null +++ b/lib/isc/tests/siphash_test.c @@ -0,0 +1,131 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#include + +#if HAVE_CMOCKA + +#include +#include +#include + +#include + +#define UNIT_TESTING +#include + +#include +#include + +#include "../siphash.c" + +const uint8_t vectors[64][8] = { + { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, }, + { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, }, + { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, }, + { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, }, + { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, }, + { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, }, + { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, }, + { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, }, + { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, }, + { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, }, + { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, }, + { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, }, + { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, }, + { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, }, + { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, }, + { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, }, + { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, }, + { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, }, + { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, }, + { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, }, + { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, }, + { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, }, + { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, }, + { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, }, + { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, }, + { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, }, + { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, }, + { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, }, + { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, }, + { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, }, + { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, }, + { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, }, + { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, }, + { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, }, + { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, }, + { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, }, + { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, }, + { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, }, + { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, }, + { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, }, + { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, }, + { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, }, + { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, }, + { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, }, + { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, }, + { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, }, + { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, }, + { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, }, + { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, }, + { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, }, + { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, }, + { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, }, + { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, }, + { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, }, + { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, }, + { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, }, + { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, }, + { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, }, + { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, }, + { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, }, + { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, }, + { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, }, + { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, }, + { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, }, +}; + +static void +isc_siphash24_test(void **state) { + UNUSED(state); + + uint8_t in[64], out[8], key[16]; + for (int i = 0; i < 16; i++) { + key[i] = i; + } + + for (int i = 0; i < 64; i++) { + in[i] = i; + isc_siphash24(key, in, i, out); + assert_memory_equal(out, vectors[i], 8); + } +} + +int main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(isc_siphash24_test), + }; + + return (cmocka_run_group_tests(tests, NULL, NULL)); +} + +#else /* HAVE_CMOCKA */ + +#include + +int +main(void) { + printf("1..0 # Skipped: cmocka not available\n"); + return (0); +} + +#endif diff --git a/lib/isc/win32/libisc.def.in b/lib/isc/win32/libisc.def.in index 7b9f23d776..fb48fbfadf 100644 --- a/lib/isc/win32/libisc.def.in +++ b/lib/isc/win32/libisc.def.in @@ -605,6 +605,7 @@ isc_sha512_final isc_sha512_init isc_sha512_invalidate isc_sha512_update +isc_siphash24 isc_sockaddr_any isc_sockaddr_any6 isc_sockaddr_anyofpf diff --git a/lib/isc/win32/libisc.vcxproj.filters.in b/lib/isc/win32/libisc.vcxproj.filters.in index d6a52341eb..5fc1cf1610 100644 --- a/lib/isc/win32/libisc.vcxproj.filters.in +++ b/lib/isc/win32/libisc.vcxproj.filters.in @@ -67,6 +67,9 @@ Library Header Files + + Library Header Files + Library Header Files @@ -233,6 +236,7 @@ Library Header Files + Library Header Files @@ -637,6 +641,7 @@ Library Source Files + Library Source Files diff --git a/lib/isc/win32/libisc.vcxproj.in b/lib/isc/win32/libisc.vcxproj.in index bb0456ff5a..0cd79fdfd0 100644 --- a/lib/isc/win32/libisc.vcxproj.in +++ b/lib/isc/win32/libisc.vcxproj.in @@ -312,6 +312,7 @@ copy InstallFiles ..\Build\Release\ + @@ -368,6 +369,7 @@ copy InstallFiles ..\Build\Release\ + @@ -481,6 +483,7 @@ copy InstallFiles ..\Build\Release\ + diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c index 94bfc71b8c..119450c827 100644 --- a/lib/isccfg/namedconf.c +++ b/lib/isccfg/namedconf.c @@ -912,7 +912,7 @@ static cfg_type_t cfg_type_bracketed_portlist = { &cfg_rep_list, &cfg_type_portrange }; -static const char *cookiealg_enums[] = { "aes", "sha1", "sha256", NULL }; +static const char *cookiealg_enums[] = { "aes", "sha1", "sha256", "siphash24", NULL }; static cfg_type_t cfg_type_cookiealg = { "cookiealg", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string, &cookiealg_enums diff --git a/util/copyrights b/util/copyrights index cb7a235c2a..31477c1bc9 100644 --- a/util/copyrights +++ b/util/copyrights @@ -911,13 +911,17 @@ ./bin/tests/system/common/root.hint ZONE 2000,2001,2004,2007,2016,2018,2019 ./bin/tests/system/conf.sh.in SH 2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019 ./bin/tests/system/conf.sh.win32 SH 2016,2017,2018,2019 +./bin/tests/system/cookie/bad-cookie-badaes.conf.in X 2019 ./bin/tests/system/cookie/bad-cookie-badhex.conf CONF-C 2014,2015,2016,2018,2019 ./bin/tests/system/cookie/bad-cookie-badsha1.conf CONF-C 2017,2018,2019 ./bin/tests/system/cookie/bad-cookie-badsha256.conf CONF-C 2017,2018,2019 +./bin/tests/system/cookie/bad-cookie-badsiphash24.conf X 2019 ./bin/tests/system/cookie/bad-cookie-toolong.conf CONF-C 2014,2015,2016,2018,2019 ./bin/tests/system/cookie/clean.sh SH 2014,2015,2016,2018,2019 +./bin/tests/system/cookie/good-cookie-aes.conf.in X 2019 ./bin/tests/system/cookie/good-cookie-sha1.conf CONF-C 2017,2018,2019 ./bin/tests/system/cookie/good-cookie-sha256.conf CONF-C 2017,2018,2019 +./bin/tests/system/cookie/good-cookie-siphash24.conf X 2019 ./bin/tests/system/cookie/ns1/example.db ZONE 2014,2015,2016,2018,2019 ./bin/tests/system/cookie/ns1/named.conf.in CONF-C 2018,2019 ./bin/tests/system/cookie/ns1/root.hint ZONE 2014,2015,2016,2018,2019 @@ -3919,6 +3923,7 @@ ./lib/isc/include/isc/counter.h C 2014,2016,2018,2019 ./lib/isc/include/isc/crc64.h C 2013,2016,2018,2019 ./lib/isc/include/isc/deprecated.h C 2017,2018,2019 +./lib/isc/include/isc/endian.h C 2019 ./lib/isc/include/isc/entropy.h C 2000,2001,2004,2005,2006,2007,2009,2016,2018,2019 ./lib/isc/include/isc/errno.h C 2016,2018,2019 ./lib/isc/include/isc/error.h C 1998,1999,2000,2001,2004,2005,2006,2007,2009,2016,2017,2018,2019 @@ -3978,6 +3983,7 @@ ./lib/isc/include/isc/serial.h C 1999,2000,2001,2004,2005,2006,2007,2009,2016,2018,2019 ./lib/isc/include/isc/sha1.h C 2000,2001,2004,2005,2006,2007,2009,2014,2016,2017,2018,2019 ./lib/isc/include/isc/sha2.h C 2005,2006,2007,2009,2014,2016,2017,2018,2019 +./lib/isc/include/isc/siphash.h C 2019 ./lib/isc/include/isc/sockaddr.h C 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2009,2012,2015,2016,2018,2019 ./lib/isc/include/isc/socket.h C 1998,1999,2000,2001,2002,2004,2005,2006,2007,2008,2009,2011,2012,2013,2014,2016,2018,2019 ./lib/isc/include/isc/stats.h C 2009,2012,2016,2018,2019 @@ -4073,6 +4079,7 @@ ./lib/isc/serial.c C 1999,2000,2001,2004,2005,2007,2016,2018,2019 ./lib/isc/sha1.c C 2000,2001,2003,2004,2005,2007,2009,2011,2012,2014,2016,2017,2018,2019 ./lib/isc/sha2.c C 2005,2006,2007,2009,2011,2012,2014,2016,2017,2018,2019 +./lib/isc/siphash.c C 2019 ./lib/isc/sockaddr.c C 1999,2000,2001,2002,2003,2004,2005,2006,2007,2010,2011,2012,2014,2015,2016,2017,2018,2019 ./lib/isc/socket_api.c C 2009,2011,2012,2013,2014,2015,2016,2018,2019 ./lib/isc/sparc64/Makefile.in MAKE 2007,2012,2016,2018,2019 @@ -4112,6 +4119,7 @@ ./lib/isc/tests/regex_test.c C 2013,2015,2016,2018,2019 ./lib/isc/tests/result_test.c C 2015,2016,2018,2019 ./lib/isc/tests/safe_test.c C 2013,2015,2016,2017,2018,2019 +./lib/isc/tests/siphash_test.c C 2019 ./lib/isc/tests/sockaddr_test.c C 2012,2015,2016,2017,2018,2019 ./lib/isc/tests/socket_test.c C 2011,2012,2013,2014,2015,2016,2017,2018,2019 ./lib/isc/tests/symtab_test.c C 2011,2012,2013,2016,2018,2019 diff --git a/win32utils/Configure b/win32utils/Configure index 93939f3213..6f9381404f 100644 --- a/win32utils/Configure +++ b/win32utils/Configure @@ -340,8 +340,7 @@ my @projectlist = ("..\\bin\\check\\win32\\checkconf.vcxproj", my %configdefh; -my @substdefh = ("AES_CC", - "ALLOW_FILTER_AAAA", +my @substdefh = ("ALLOW_FILTER_AAAA", "CONFIGARGS", "DNS_RDATASET_FIXED", "ENABLE_RPZ_NSDNAME", @@ -368,8 +367,6 @@ my @substdefh = ("AES_CC", "HAVE_PKCS11_GOST", "HAVE_READLINE", "HAVE_ZLIB", - "HMAC_SHA1_CC", - "HMAC_SHA256_CC", "ISC_LIST_CHECKINIT", "PREFER_GOSTASN1", "TUNE_LARGE", @@ -2244,21 +2241,6 @@ if ($use_aes eq "yes") { $configcond{"AES"} = 1; } -# with-cc-alg -if ($cookie_algorithm eq "aes") { - if ($use_aes ne "yes") { - $cookie_algorithm = "sha256"; - } else { - $configdefh{"AES_CC"} = 1; - } -} -if ($cookie_algorithm eq "sha1") { - $configdefh{"HMAC_SHA1_CC"} = 1; -} elsif ($cookie_algorithm eq "sha256") { - $configdefh{"HMAC_SHA256_CC"} = 1; -} elsif ($cookie_algorithm ne "aes") { - die "Unrecognized cookie algorithm: $cookie_algorithm\n"; -} # enable-openssl-hash if ($enable_openssl_hash eq "yes") {