]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add a few OpenSSL fallback funcs
authorNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Fri, 18 Nov 2016 18:08:47 +0000 (20:08 +0200)
committerNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Wed, 7 Dec 2016 12:03:05 +0000 (14:03 +0200)
Add four fallback function implementations to use in place of functions
removed/deprecated in OpenSSL 1.1. Those are to be used in the following
patches to make the build work and not produce deprecation warnings.

configure
configure.ac
src/include/autoconf.h.in
src/include/missing-h
src/lib/missing.c

index 779c6fbe0ffeab634dc7a3a86c53fc79a05e0c80..bbefb8b427ca1f5b2d722f9b91f54df9ac993015 100755 (executable)
--- a/configure
+++ b/configure
@@ -8785,6 +8785,10 @@ fi
                 for ac_func in \
       SSL_get_client_random \
       SSL_get_server_random \
+      HMAC_CTX_new \
+      HMAC_CTX_free \
+      ASN1_STRING_get0_data \
+      CONF_modules_load_file \
 
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
index b9fed71d05a8e10138e14fd63dff6940a59862cb..485f66c69f3e56f64b962d5542bbe3c794a7ec5d 100644 (file)
@@ -1183,6 +1183,10 @@ if test "x$WITH_OPENSSL" = xyes; then
     AC_CHECK_FUNCS( \
       SSL_get_client_random \
       SSL_get_server_random \
+      HMAC_CTX_new \
+      HMAC_CTX_free \
+      ASN1_STRING_get0_data \
+      CONF_modules_load_file \
     )
     CPPFLAGS="$old_CPPFLAGS"
   fi
index e0a3e50590c833834dcf00f482fbe443e3e8760b..aa91effc75e0925b4071366f2316ea25ad12f571 100644 (file)
@@ -32,6 +32,9 @@
 /* Define to 1 if you have the <arpa/inet.h> header file. */
 #undef HAVE_ARPA_INET_H
 
+/* Define to 1 if you have the `ASN1_STRING_get0_data' function. */
+#undef HAVE_ASN1_STRING_GET0_DATA
+
 /* Define if your compiler supports the __bounded__ attribute (usually OpenBSD
    gcc). */
 #undef HAVE_ATTRIBUTE_BOUNDED
@@ -63,6 +66,9 @@
 /* Define to 1 if you have the `collectdclient' library (-lcollectdclient). */
 #undef HAVE_COLLECTDC_H
 
+/* Define to 1 if you have the `CONF_modules_load_file' function. */
+#undef HAVE_CONF_MODULES_LOAD_FILE
+
 /* Do we have the crypt function */
 #undef HAVE_CRYPT
 
 /* Define to 1 if you have the <history.h> header file. */
 #undef HAVE_HISTORY_H
 
+/* Define to 1 if you have the `HMAC_CTX_free' function. */
+#undef HAVE_HMAC_CTX_FREE
+
+/* Define to 1 if you have the `HMAC_CTX_new' function. */
+#undef HAVE_HMAC_CTX_NEW
+
 /* Define if the function (or macro) htonll exists. */
 #undef HAVE_HTONLL
 
index 9d59394e4e38668881bfd8650184996d8c6eafc1..3cc205b09690a209c541d6685b32ffa6b79adc5d 100644 (file)
@@ -83,6 +83,18 @@ RCSIDH(missing_h, "$Id$")
 #  endif
 #endif
 
+#ifdef HAVE_OPENSSL_HMAC_H
+#  include <openssl/hmac.h>
+#endif
+
+#ifdef HAVE_OPENSSL_ASN1_H
+#  include <openssl/asn1.h>
+#endif
+
+#ifdef HAVE_OPENSSL_CONF_H
+#  include <openssl/conf.h>
+#endif
+
 /*
  *     Don't look for winsock.h if we're on cygwin.
  */
@@ -436,6 +448,46 @@ uint128_t ntohlll(uint128_t num);
 typedef void(*sig_t)(int);
 #endif
 
+#ifdef HAVE_OPENSSL_HMAC_H
+#  ifndef HAVE_HMAC_CTX_NEW
+HMAC_CTX *HMAC_CTX_new(void);
+#  endif
+#  ifndef HAVE_HMAC_CTX_FREE
+void HMAC_CTX_free(HMAC_CTX *ctx);
+#  endif
+#endif
+
+#ifdef HAVE_OPENSSL_ASN1_H
+#  ifndef HAVE_ASN1_STRING_GET0_DATA
+static inline const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x)
+{
+       /*
+        * Trick the compiler into not issuing the warning on qualifier stripping.
+        * We know that ASN1_STRING_data doesn't change x, and we're casting
+        * the return value back to const immediately, so it's OK.
+        */
+       union {
+               const ASN1_STRING       *c;
+               ASN1_STRING             *nc;
+       } const_strip = {.c = x};
+       return ASN1_STRING_data(const_strip.nc);
+}
+#  endif
+#endif
+
+#ifdef HAVE_OPENSSL_CONF_H
+#  ifndef HAVE_CONF_MODULES_LOAD_FILE
+static inline int CONF_modules_load_file(const char *filename,
+                                        const char *appname,
+                                        unsigned long flags)
+{
+       (void)filename;
+       (void)flags;
+       return OPENSSL_config(appname);
+}
+#  endif
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index 1d73c76090add10696895092f4742edd2dc09b40..00c21361843ec14849629ee1957dfeb1cc1ba5b8 100644 (file)
@@ -315,6 +315,32 @@ uint128_t ntohlll(uint128_t const num)
 }
 #endif
 
+#ifdef HAVE_OPENSSL_HMAC_H
+#  ifndef HAVE_HMAC_CTX_NEW
+HMAC_CTX *HMAC_CTX_new(void)
+{
+       HMAC_CTX *ctx;
+       ctx = OPENSSL_malloc(sizeof(*ctx));
+       memset(ctx, 0, sizeof(*ctx));
+       if (ctx == NULL) {
+                return NULL;
+        }
+        HMAC_CTX_init(ctx);
+       return ctx;
+}
+#  endif
+#  ifndef HAVE_HMAC_CTX_FREE
+void HMAC_CTX_free(HMAC_CTX *ctx)
+{
+        if (ctx == NULL) {
+                return;
+        }
+        HMAC_CTX_cleanup(ctx);
+        OPENSSL_free(ctx);
+}
+#  endif
+#endif
+
 /** Call talloc strdup, setting the type on the new chunk correctly
  *
  * For some bizarre reason the talloc string functions don't set the