6460f2e
From e2bbb899195ea98b6b5f6c972ab764a53b387789 Mon Sep 17 00:00:00 2001
6460f2e
From: Yuri Schaeffer <yuri@nlnetlabs.nl>
6460f2e
Date: Fri, 4 Nov 2016 15:35:06 +0100
6460f2e
Subject: [PATCH] HMAC_CTX_init deprecated in openssl-1.1.0
6460f2e
6460f2e
---
6460f2e
 m4/acx_ssl.m4                  | 12 +++++++++---
6460f2e
 signer/src/Makefile.am         |  4 ++--
6460f2e
 signer/src/wire/tsig-openssl.c | 15 ++++++++++++---
6460f2e
 3 files changed, 23 insertions(+), 8 deletions(-)
6460f2e
6460f2e
diff --git a/m4/acx_ssl.m4 b/m4/acx_ssl.m4
6460f2e
index 1dc6e40..3d64626 100644
6460f2e
--- a/m4/acx_ssl.m4
6460f2e
+++ b/m4/acx_ssl.m4
6460f2e
@@ -35,12 +35,18 @@ AC_DEFUN([ACX_SSL], [
6460f2e
             if test x_$ssldir = x_/usr/sfw; then
6460f2e
                 SSL_LIBS="$SSL_LIBS -R$ssldir/lib";
6460f2e
             fi
6460f2e
-            AC_CHECK_LIB(crypto, HMAC_CTX_init,, [
6460f2e
-                    AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required])
6460f2e
-            ])
6460f2e
+            AC_CHECK_LIB(crypto, HMAC_CTX_reset, [
6460f2e
+                    AC_DEFINE_UNQUOTED([HAVE_SSL_NEW_HMAC], [], [Define if you have the SSL libraries with new HMAC related functions.])
6460f2e
+                    SSL_LIBS="$SSL_LIBS -lcrypto";
6460f2e
+            ], [
6460f2e
+                    AC_CHECK_LIB(crypto, HMAC_CTX_init,, [
6460f2e
+                            AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required])
6460f2e
+                    ])
6460f2e
+            ] )
6460f2e
             AC_CHECK_FUNCS([EVP_sha1 EVP_sha256])
6460f2e
         fi
6460f2e
         AC_SUBST(HAVE_SSL)
6460f2e
+        AC_SUBST(HAVE_SSL_NEW_HMAC)
6460f2e
         AC_SUBST(SSL_INCLUDES)
6460f2e
         AC_SUBST(SSL_LIBS)
6460f2e
     fi
6460f2e
diff --git a/signer/src/Makefile.am b/signer/src/Makefile.am
6460f2e
index 60e8877..b39eac8 100644
6460f2e
--- a/signer/src/Makefile.am
6460f2e
+++ b/signer/src/Makefile.am
6460f2e
@@ -133,7 +133,7 @@ ods_signer_SOURCES=		ods-signer.c \
6460f2e
 				wire/xfrd.c wire/xfrd.h
6460f2e
 
6460f2e
 ods_signer_LDADD=		$(LIBHSM)
6460f2e
-ods_signer_LDADD+=		@LDNS_LIBS@ @XML2_LIBS@ @RT_LIBS@
6460f2e
+ods_signer_LDADD+=		@LDNS_LIBS@ @XML2_LIBS@ @RT_LIBS@ @SSL_LIBS@ 
6460f2e
 ods_signer_LDADD+=		$(LIBCOMPAT)
6460f2e
 
6460f2e
 ods_getconf_SOURCES=		ods-getconf.c \
6460f2e
@@ -193,5 +193,5 @@ ods_getconf_SOURCES=		ods-getconf.c \
6460f2e
 				wire/xfrd.c wire/xfrd.h
6460f2e
 
6460f2e
 ods_getconf_LDADD=		$(LIBHSM)
6460f2e
-ods_getconf_LDADD+=		@LDNS_LIBS@ @XML2_LIBS@ @RT_LIBS@
6460f2e
+ods_getconf_LDADD+=		@SSL_LIBS@ @LDNS_LIBS@ @XML2_LIBS@ @RT_LIBS@
6460f2e
 ods_getconf_LDADD+=		$(LIBCOMPAT)
6460f2e
diff --git a/signer/src/wire/tsig-openssl.c b/signer/src/wire/tsig-openssl.c
6460f2e
index c26b1e7..24fd342 100644
6460f2e
--- a/signer/src/wire/tsig-openssl.c
6460f2e
+++ b/signer/src/wire/tsig-openssl.c
6460f2e
@@ -131,8 +131,11 @@ static void
6460f2e
 cleanup_context(void *data)
6460f2e
 {
6460f2e
     HMAC_CTX* context = (HMAC_CTX*) data;
6460f2e
+#ifdef HAVE_SSL_NEW_HMAC
6460f2e
+    HMAC_CTX_free(context);
6460f2e
+#else
6460f2e
     HMAC_CTX_cleanup(context);
6460f2e
-    return;
6460f2e
+#endif
6460f2e
 }
6460f2e
 
6460f2e
 static void
6460f2e
@@ -155,9 +158,15 @@ context_add_cleanup(void* context)
6460f2e
 static void*
6460f2e
 create_context(allocator_type* allocator)
6460f2e
 {
6460f2e
-    HMAC_CTX* context = (HMAC_CTX*) allocator_alloc(allocator,
6460f2e
-        sizeof(HMAC_CTX));
6460f2e
+    HMAC_CTX* context;
6460f2e
+#ifdef HAVE_SSL_NEW_HMAC
6460f2e
+    context = HMAC_CTX_new();
6460f2e
+    if (!context) return NULL;
6460f2e
+    HMAC_CTX_reset(context);
6460f2e
+#else
6460f2e
+    context = (HMAC_CTX*) allocator_alloc(allocator, sizeof(HMAC_CTX));
6460f2e
     HMAC_CTX_init(context);
6460f2e
+#endif
6460f2e
     context_add_cleanup(context);
6460f2e
     return context;
6460f2e
 }
6460f2e
-- 
6460f2e
2.9.3
6460f2e