|
|
c7e749 |
From ca1e22ee7d4e36204ec665305962e895ad63081e Mon Sep 17 00:00:00 2001
|
|
|
c7e749 |
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
|
|
|
c7e749 |
Date: Wed, 25 Nov 2020 17:18:55 +0100
|
|
|
c7e749 |
Subject: [PATCH] Support hash function from nettle (only)
|
|
|
c7e749 |
|
|
|
c7e749 |
Unlike COPTS=-DHAVE_DNSSEC, allow usage of just sha256 function from
|
|
|
c7e749 |
nettle, but keep DNSSEC disabled at build time. Skips use of internal
|
|
|
c7e749 |
hash implementation without support for validation built-in.
|
|
|
c7e749 |
---
|
|
|
c7e749 |
Makefile | 6 ++++--
|
|
|
c7e749 |
bld/pkg-wrapper | 39 +++++++++++++++++++++------------------
|
|
|
c7e749 |
src/config.h | 8 ++++++++
|
|
|
c7e749 |
src/dnssec.c | 17 +++++++++++++++--
|
|
|
c7e749 |
src/hash_questions.c | 7 ++++++-
|
|
|
c7e749 |
5 files changed, 54 insertions(+), 23 deletions(-)
|
|
|
c7e749 |
|
|
|
c7e749 |
diff --git a/Makefile b/Makefile
|
|
|
c7e749 |
index 8a3f2e2..9890ae1 100644
|
|
|
c7e749 |
--- a/Makefile
|
|
|
c7e749 |
+++ b/Makefile
|
|
|
c7e749 |
@@ -59,8 +59,10 @@ ct_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CON
|
|
|
c7e749 |
ct_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --libs libnetfilter_conntrack`
|
|
|
c7e749 |
lua_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --cflags lua5.1`
|
|
|
c7e749 |
lua_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --libs lua5.1`
|
|
|
c7e749 |
-nettle_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --cflags nettle hogweed`
|
|
|
c7e749 |
-nettle_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --libs nettle hogweed`
|
|
|
c7e749 |
+nettle_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --cflags 'nettle hogweed' \
|
|
|
c7e749 |
+ HAVE_NETTLEHASH $(PKG_CONFIG) --cflags nettle`
|
|
|
c7e749 |
+nettle_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --libs 'nettle hogweed' \
|
|
|
c7e749 |
+ HAVE_NETTLEHASH $(PKG_CONFIG) --libs nettle`
|
|
|
c7e749 |
gmp_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC NO_GMP --copy -lgmp`
|
|
|
c7e749 |
sunos_libs = `if uname | grep SunOS >/dev/null 2>&1; then echo -lsocket -lnsl -lposix4; fi`
|
|
|
c7e749 |
version = -DVERSION='\"`$(top)/bld/get-version $(top)`\"'
|
|
|
c7e749 |
diff --git a/bld/pkg-wrapper b/bld/pkg-wrapper
|
|
|
c7e749 |
index 0ddb678..3478962 100755
|
|
|
c7e749 |
--- a/bld/pkg-wrapper
|
|
|
c7e749 |
+++ b/bld/pkg-wrapper
|
|
|
c7e749 |
@@ -1,33 +1,35 @@
|
|
|
c7e749 |
#!/bin/sh
|
|
|
c7e749 |
|
|
|
c7e749 |
-search=$1
|
|
|
c7e749 |
-shift
|
|
|
c7e749 |
-pkg=$1
|
|
|
c7e749 |
-shift
|
|
|
c7e749 |
-op=$1
|
|
|
c7e749 |
-shift
|
|
|
c7e749 |
-
|
|
|
c7e749 |
in=`cat`
|
|
|
c7e749 |
|
|
|
c7e749 |
-if grep "^\#[[:space:]]*define[[:space:]]*$search" config.h >/dev/null 2>&1 || \
|
|
|
c7e749 |
- echo $in | grep $search >/dev/null 2>&1; then
|
|
|
c7e749 |
+search()
|
|
|
c7e749 |
+{
|
|
|
c7e749 |
+ grep "^\#[[:space:]]*define[[:space:]]*$1" config.h >/dev/null 2>&1 || \
|
|
|
c7e749 |
+ echo $in | grep $1 >/dev/null 2>&1
|
|
|
c7e749 |
+}
|
|
|
c7e749 |
+
|
|
|
c7e749 |
+while [ "$#" -gt 0 ]; do
|
|
|
c7e749 |
+ search=$1
|
|
|
c7e749 |
+ pkg=$2
|
|
|
c7e749 |
+ op=$3
|
|
|
c7e749 |
+ lib=$4
|
|
|
c7e749 |
+ shift 4
|
|
|
c7e749 |
+if search "$search"; then
|
|
|
c7e749 |
+
|
|
|
c7e749 |
# Nasty, nasty, in --copy, arg 2 is another config to search for, use with NO_GMP
|
|
|
c7e749 |
if [ $op = "--copy" ]; then
|
|
|
c7e749 |
- if grep "^\#[[:space:]]*define[[:space:]]*$pkg" config.h >/dev/null 2>&1 || \
|
|
|
c7e749 |
- echo $in | grep $pkg >/dev/null 2>&1; then
|
|
|
c7e749 |
+ if search "$pkg"; then
|
|
|
c7e749 |
pkg=""
|
|
|
c7e749 |
else
|
|
|
c7e749 |
- pkg="$*"
|
|
|
c7e749 |
+ pkg="$lib"
|
|
|
c7e749 |
fi
|
|
|
c7e749 |
- elif grep "^\#[[:space:]]*define[[:space:]]*${search}_STATIC" config.h >/dev/null 2>&1 || \
|
|
|
c7e749 |
- echo $in | grep ${search}_STATIC >/dev/null 2>&1; then
|
|
|
c7e749 |
- pkg=`$pkg --static $op $*`
|
|
|
c7e749 |
+ elif search "${search}_STATIC"; then
|
|
|
c7e749 |
+ pkg=`$pkg --static $op $lib`
|
|
|
c7e749 |
else
|
|
|
c7e749 |
- pkg=`$pkg $op $*`
|
|
|
c7e749 |
+ pkg=`$pkg $op $lib`
|
|
|
c7e749 |
fi
|
|
|
c7e749 |
|
|
|
c7e749 |
- if grep "^\#[[:space:]]*define[[:space:]]*${search}_STATIC" config.h >/dev/null 2>&1 || \
|
|
|
c7e749 |
- echo $in | grep ${search}_STATIC >/dev/null 2>&1; then
|
|
|
c7e749 |
+ if search "${search}_STATIC"; then
|
|
|
c7e749 |
if [ $op = "--libs" ] || [ $op = "--copy" ]; then
|
|
|
c7e749 |
echo "-Wl,-Bstatic $pkg -Wl,-Bdynamic"
|
|
|
c7e749 |
else
|
|
|
c7e749 |
@@ -38,3 +40,4 @@ if grep "^\#[[:space:]]*define[[:space:]]*$search" config.h >/dev/null 2>&1 || \
|
|
|
c7e749 |
fi
|
|
|
c7e749 |
fi
|
|
|
c7e749 |
|
|
|
c7e749 |
+done
|
|
|
c7e749 |
diff --git a/src/config.h b/src/config.h
|
|
|
c7e749 |
index 80a50e1..077147a 100644
|
|
|
c7e749 |
--- a/src/config.h
|
|
|
c7e749 |
+++ b/src/config.h
|
|
|
c7e749 |
@@ -111,6 +111,9 @@ HAVE_AUTH
|
|
|
c7e749 |
define this to include the facility to act as an authoritative DNS
|
|
|
c7e749 |
server for one or more zones.
|
|
|
c7e749 |
|
|
|
c7e749 |
+HAVE_NETTLEHASH
|
|
|
c7e749 |
+ include just hash function from nettle, but no DNSSEC.
|
|
|
c7e749 |
+
|
|
|
c7e749 |
HAVE_DNSSEC
|
|
|
c7e749 |
include DNSSEC validator.
|
|
|
c7e749 |
|
|
|
c7e749 |
@@ -174,6 +177,7 @@ RESOLVFILE
|
|
|
c7e749 |
/* #define HAVE_DBUS */
|
|
|
c7e749 |
/* #define HAVE_IDN */
|
|
|
c7e749 |
/* #define HAVE_CONNTRACK */
|
|
|
c7e749 |
+/* #define HAVE_NETTLEHASH */
|
|
|
c7e749 |
/* #define HAVE_DNSSEC */
|
|
|
c7e749 |
|
|
|
c7e749 |
|
|
|
c7e749 |
@@ -430,6 +434,10 @@ static char *compile_opts =
|
|
|
c7e749 |
"no-"
|
|
|
c7e749 |
#endif
|
|
|
c7e749 |
"auth "
|
|
|
c7e749 |
+#if !defined(HAVE_NETTLEHASH) && !defined(HAVE_DNSSEC)
|
|
|
c7e749 |
+"no-"
|
|
|
c7e749 |
+#endif
|
|
|
c7e749 |
+"nettlehash "
|
|
|
c7e749 |
#ifndef HAVE_DNSSEC
|
|
|
c7e749 |
"no-"
|
|
|
c7e749 |
#endif
|
|
|
c7e749 |
diff --git a/src/dnssec.c b/src/dnssec.c
|
|
|
c7e749 |
index f22faa1..d07cee9 100644
|
|
|
c7e749 |
--- a/src/dnssec.c
|
|
|
c7e749 |
+++ b/src/dnssec.c
|
|
|
c7e749 |
@@ -25,8 +25,14 @@
|
|
|
c7e749 |
# include <nettle/ecdsa.h>
|
|
|
c7e749 |
# include <nettle/ecc-curve.h>
|
|
|
c7e749 |
#endif
|
|
|
c7e749 |
+#endif
|
|
|
c7e749 |
+
|
|
|
c7e749 |
+#if defined(HAVE_DNSSEC) || defined(HAVE_NETTLEHASH)
|
|
|
c7e749 |
#include <nettle/nettle-meta.h>
|
|
|
c7e749 |
#include <nettle/bignum.h>
|
|
|
c7e749 |
+#endif
|
|
|
c7e749 |
+
|
|
|
c7e749 |
+#ifdef HAVE_DNSSEC
|
|
|
c7e749 |
|
|
|
c7e749 |
/* Nettle-3.0 moved to a new API for DSA. We use a name that's defined in the new API
|
|
|
c7e749 |
to detect Nettle-3, and invoke the backwards compatibility mode. */
|
|
|
c7e749 |
@@ -80,9 +86,12 @@ static char *nsec3_digest_name(int digest)
|
|
|
c7e749 |
default: return NULL;
|
|
|
c7e749 |
}
|
|
|
c7e749 |
}
|
|
|
c7e749 |
+#endif
|
|
|
c7e749 |
+
|
|
|
c7e749 |
+#if defined(HAVE_DNSSEC) || defined(HAVE_NETTLEHASH)
|
|
|
c7e749 |
|
|
|
c7e749 |
/* Find pointer to correct hash function in nettle library */
|
|
|
c7e749 |
-static const struct nettle_hash *hash_find(char *name)
|
|
|
c7e749 |
+const struct nettle_hash *hash_find(char *name)
|
|
|
c7e749 |
{
|
|
|
c7e749 |
int i;
|
|
|
c7e749 |
|
|
|
c7e749 |
@@ -99,7 +108,7 @@ static const struct nettle_hash *hash_find(char *name)
|
|
|
c7e749 |
}
|
|
|
c7e749 |
|
|
|
c7e749 |
/* expand ctx and digest memory allocations if necessary and init hash function */
|
|
|
c7e749 |
-static int hash_init(const struct nettle_hash *hash, void **ctxp, unsigned char **digestp)
|
|
|
c7e749 |
+int hash_init(const struct nettle_hash *hash, void **ctxp, unsigned char **digestp)
|
|
|
c7e749 |
{
|
|
|
c7e749 |
static void *ctx = NULL;
|
|
|
c7e749 |
static unsigned char *digest = NULL;
|
|
|
c7e749 |
@@ -135,6 +144,10 @@ static int hash_init(const struct nettle_hash *hash, void **ctxp, unsigned char
|
|
|
c7e749 |
|
|
|
c7e749 |
return 1;
|
|
|
c7e749 |
}
|
|
|
c7e749 |
+
|
|
|
c7e749 |
+#endif
|
|
|
c7e749 |
+
|
|
|
c7e749 |
+#ifdef HAVE_DNSSEC
|
|
|
c7e749 |
|
|
|
c7e749 |
static int dnsmasq_rsa_verify(struct blockdata *key_data, unsigned int key_len, unsigned char *sig, size_t sig_len,
|
|
|
c7e749 |
unsigned char *digest, size_t digest_len, int algo)
|
|
|
c7e749 |
diff --git a/src/hash_questions.c b/src/hash_questions.c
|
|
|
c7e749 |
index ae112ac..0d25359 100644
|
|
|
c7e749 |
--- a/src/hash_questions.c
|
|
|
c7e749 |
+++ b/src/hash_questions.c
|
|
|
c7e749 |
@@ -28,7 +28,12 @@
|
|
|
c7e749 |
|
|
|
c7e749 |
#include "dnsmasq.h"
|
|
|
c7e749 |
|
|
|
c7e749 |
-#ifdef HAVE_DNSSEC
|
|
|
c7e749 |
+#if defined(HAVE_DNSSEC) || defined(HAVE_NETTLEHASH)
|
|
|
c7e749 |
+#include <nettle/nettle-meta.h>
|
|
|
c7e749 |
+
|
|
|
c7e749 |
+const struct nettle_hash *hash_find(char *name);
|
|
|
c7e749 |
+int hash_init(const struct nettle_hash *hash, void **ctxp, unsigned char **digestp);
|
|
|
c7e749 |
+
|
|
|
c7e749 |
unsigned char *hash_questions(struct dns_header *header, size_t plen, char *name)
|
|
|
c7e749 |
{
|
|
|
c7e749 |
int q;
|
|
|
c7e749 |
--
|
|
|
c7e749 |
2.26.2
|
|
|
c7e749 |
|