0110-Support-hash-function-from-nettle-only.patch 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. From 2024f9729713fd657d65e64c2e4e471baa0a3e5b Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
  3. Date: Wed, 25 Nov 2020 17:18:55 +0100
  4. Subject: Support hash function from nettle (only)
  5. Unlike COPTS=-DHAVE_DNSSEC, allow usage of just sha256 function from
  6. nettle, but keep DNSSEC disabled at build time. Skips use of internal
  7. hash implementation without support for validation built-in.
  8. ---
  9. Makefile | 8 +++++---
  10. bld/pkg-wrapper | 41 ++++++++++++++++++++++-------------------
  11. src/config.h | 8 ++++++++
  12. src/crypto.c | 7 +++++++
  13. src/dnsmasq.h | 2 +-
  14. src/hash_questions.c | 2 +-
  15. 6 files changed, 44 insertions(+), 24 deletions(-)
  16. --- a/Makefile
  17. +++ b/Makefile
  18. @@ -53,7 +53,7 @@ top?=$(CURDIR)
  19. dbus_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --cflags dbus-1`
  20. dbus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --libs dbus-1`
  21. -ubus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_UBUS "" --copy -lubox -lubus`
  22. +ubus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_UBUS "" --copy '-lubox -lubus'`
  23. idn_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --cflags libidn`
  24. idn_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --libs libidn`
  25. idn2_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LIBIDN2 $(PKG_CONFIG) --cflags libidn2`
  26. @@ -62,8 +62,10 @@ ct_cflags = `echo $(COPTS) | $(top)/
  27. ct_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --libs libnetfilter_conntrack`
  28. lua_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --cflags lua5.2`
  29. lua_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --libs lua5.2`
  30. -nettle_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --cflags nettle hogweed`
  31. -nettle_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --libs nettle hogweed`
  32. +nettle_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --cflags 'nettle hogweed' \
  33. + HAVE_NETTLEHASH $(PKG_CONFIG) --cflags nettle`
  34. +nettle_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --libs 'nettle hogweed' \
  35. + HAVE_NETTLEHASH $(PKG_CONFIG) --libs nettle`
  36. gmp_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC NO_GMP --copy -lgmp`
  37. sunos_libs = `if uname | grep SunOS >/dev/null 2>&1; then echo -lsocket -lnsl -lposix4; fi`
  38. version = -DVERSION='\"`$(top)/bld/get-version $(top)`\"'
  39. --- a/bld/pkg-wrapper
  40. +++ b/bld/pkg-wrapper
  41. @@ -1,35 +1,37 @@
  42. #!/bin/sh
  43. -search=$1
  44. -shift
  45. -pkg=$1
  46. -shift
  47. -op=$1
  48. -shift
  49. -
  50. in=`cat`
  51. -if grep "^\#[[:space:]]*define[[:space:]]*$search" config.h >/dev/null 2>&1 || \
  52. - echo $in | grep $search >/dev/null 2>&1; then
  53. +search()
  54. +{
  55. + grep "^\#[[:space:]]*define[[:space:]]*$1" config.h >/dev/null 2>&1 || \
  56. + echo $in | grep $1 >/dev/null 2>&1
  57. +}
  58. +
  59. +while [ "$#" -gt 0 ]; do
  60. + search=$1
  61. + pkg=$2
  62. + op=$3
  63. + lib=$4
  64. + shift 4
  65. +if search "$search"; then
  66. +
  67. # Nasty, nasty, in --copy, arg 2 (if non-empty) is another config to search for, used with NO_GMP
  68. if [ $op = "--copy" ]; then
  69. if [ -z "$pkg" ]; then
  70. - pkg="$*"
  71. - elif grep "^\#[[:space:]]*define[[:space:]]*$pkg" config.h >/dev/null 2>&1 || \
  72. - echo $in | grep $pkg >/dev/null 2>&1; then
  73. + pkg="$lib"
  74. + elif search "$pkg"; then
  75. pkg=""
  76. else
  77. - pkg="$*"
  78. + pkg="$lib"
  79. fi
  80. - elif grep "^\#[[:space:]]*define[[:space:]]*${search}_STATIC" config.h >/dev/null 2>&1 || \
  81. - echo $in | grep ${search}_STATIC >/dev/null 2>&1; then
  82. - pkg=`$pkg --static $op $*`
  83. + elif search "${search}_STATIC"; then
  84. + pkg=`$pkg --static $op $lib`
  85. else
  86. - pkg=`$pkg $op $*`
  87. + pkg=`$pkg $op $lib`
  88. fi
  89. - if grep "^\#[[:space:]]*define[[:space:]]*${search}_STATIC" config.h >/dev/null 2>&1 || \
  90. - echo $in | grep ${search}_STATIC >/dev/null 2>&1; then
  91. + if search "${search}_STATIC"; then
  92. if [ $op = "--libs" ] || [ $op = "--copy" ]; then
  93. echo "-Wl,-Bstatic $pkg -Wl,-Bdynamic"
  94. else
  95. @@ -40,3 +42,4 @@ if grep "^\#[[:space:]]*define[[:space:]
  96. fi
  97. fi
  98. +done
  99. --- a/src/config.h
  100. +++ b/src/config.h
  101. @@ -117,6 +117,9 @@ HAVE_AUTH
  102. define this to include the facility to act as an authoritative DNS
  103. server for one or more zones.
  104. +HAVE_NETTLEHASH
  105. + include just hash function from nettle, but no DNSSEC.
  106. +
  107. HAVE_DNSSEC
  108. include DNSSEC validator.
  109. @@ -184,6 +187,7 @@ RESOLVFILE
  110. /* #define HAVE_IDN */
  111. /* #define HAVE_LIBIDN2 */
  112. /* #define HAVE_CONNTRACK */
  113. +/* #define HAVE_NETTLEHASH */
  114. /* #define HAVE_DNSSEC */
  115. @@ -408,6 +412,10 @@ static char *compile_opts =
  116. "no-"
  117. #endif
  118. "auth "
  119. +#if !defined(HAVE_NETTLEHASH) && !defined(HAVE_DNSSEC)
  120. +"no-"
  121. +#endif
  122. +"nettlehash "
  123. #ifndef HAVE_DNSSEC
  124. "no-"
  125. #endif
  126. --- a/src/crypto.c
  127. +++ b/src/crypto.c
  128. @@ -23,6 +23,9 @@
  129. #include <nettle/ecdsa.h>
  130. #include <nettle/ecc-curve.h>
  131. #include <nettle/eddsa.h>
  132. +#endif
  133. +
  134. +#if defined(HAVE_DNSSEC) || defined(HAVE_NETTLEHASH)
  135. #include <nettle/nettle-meta.h>
  136. #include <nettle/bignum.h>
  137. @@ -165,6 +168,10 @@ int hash_init(const struct nettle_hash *
  138. return 1;
  139. }
  140. +
  141. +#endif
  142. +
  143. +#ifdef HAVE_DNSSEC
  144. static int dnsmasq_rsa_verify(struct blockdata *key_data, unsigned int key_len, unsigned char *sig, size_t sig_len,
  145. unsigned char *digest, size_t digest_len, int algo)
  146. --- a/src/dnsmasq.h
  147. +++ b/src/dnsmasq.h
  148. @@ -150,7 +150,7 @@ extern int capget(cap_user_header_t head
  149. #include <priv.h>
  150. #endif
  151. -#ifdef HAVE_DNSSEC
  152. +#if defined(HAVE_DNSSEC) || defined(HAVE_NETTLEHASH)
  153. # include <nettle/nettle-meta.h>
  154. #endif
  155. --- a/src/hash_questions.c
  156. +++ b/src/hash_questions.c
  157. @@ -28,7 +28,7 @@
  158. #include "dnsmasq.h"
  159. -#ifdef HAVE_DNSSEC
  160. +#if defined(HAVE_DNSSEC) || defined(HAVE_NETTLEHASH)
  161. unsigned char *hash_questions(struct dns_header *header, size_t plen, char *name)
  162. {
  163. int q;