| 1 |
AC_DEFUN([SUDO_CHECK_OPENSSL], [ |
| 2 |
openssl_missing=no |
| 3 |
if test "${enable_openssl-no}" != no; then |
| 4 |
# Use pkg-config to find the openssl cflags and libs if possible. |
| 5 |
if test "$enable_openssl" != "yes" -a "$enable_openssl" != "maybe"; then |
| 6 |
PKG_CONFIG_LIBDIR= |
| 7 |
for d in ${enable_openssl}/*/pkgconfig; do |
| 8 |
if test -d "$d"; then |
| 9 |
PKG_CONFIG_LIBDIR="$PKG_CONFIG_LIBDIR:$d" |
| 10 |
fi |
| 11 |
done |
| 12 |
if test -n "$PKG_CONFIG_LIBDIR"; then |
| 13 |
PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR#:} |
| 14 |
export PKG_CONFIG_LIBDIR |
| 15 |
fi |
| 16 |
elif test "$cross_compiling" = "yes" -a -z "$PKG_CONFIG"; then |
| 17 |
# Cannot use pkg-config when cross-compiling |
| 18 |
PKG_CONFIG=false |
| 19 |
fi |
| 20 |
: ${PKG_CONFIG='pkg-config'} |
| 21 |
pkg_openssl=`printf $enable_openssl_pkgconfig_template "openssl"` |
| 22 |
pkg_libcrypto=lib`printf $enable_openssl_pkgconfig_template "crypto"` |
| 23 |
if $PKG_CONFIG --exists "$pkg_openssl >= 1.0.1" >/dev/null 2>&1; then |
| 24 |
AC_DEFINE(HAVE_OPENSSL) |
| 25 |
if test "$enable_openssl" = "maybe"; then |
| 26 |
enable_openssl=yes |
| 27 |
fi |
| 28 |
|
| 29 |
# Check whether --static is needed (don't assume name of ssl lib) |
| 30 |
# There may be dependent libraries or -pthread. |
| 31 |
O_LDFLAGS="$LDFLAGS" |
| 32 |
LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs-only-L $pkg_openssl`" |
| 33 |
libssl="`$PKG_CONFIG --libs-only-l $pkg_openssl | sed 's/^ *-l//'`" |
| 34 |
libssl_extra="`echo $libssl | sed 's/^[[^ ]]* *//'`" |
| 35 |
libssl="`echo $libssl | sed 's/ .*//'`" |
| 36 |
AC_CHECK_LIB([$libssl], [SSL_new], [STATIC=""], [STATIC="--static"], [$libssl_extra]) |
| 37 |
LDFLAGS="$O_LDFLAGS" |
| 38 |
|
| 39 |
# Use pkg-config to determine OpenSSL libs and cflags |
| 40 |
for f in `$PKG_CONFIG $STATIC --libs $pkg_openssl`; do |
| 41 |
case "$f" in |
| 42 |
-L*) |
| 43 |
f="${f#-L}" |
| 44 |
SUDO_APPEND_LIBPATH([LIBTLS], [$f]) |
| 45 |
;; |
| 46 |
*) |
| 47 |
# Do not use AX_APPEND_FLAG as it will break static builds by removing |
| 48 |
# duplicates such as -lz or -latomic which are needed by -lssl and -lcrypto |
| 49 |
LIBTLS="$LIBTLS $f" |
| 50 |
;; |
| 51 |
esac |
| 52 |
done |
| 53 |
if $PKG_CONFIG --exists $pkg_libcrypto >/dev/null 2>&1; then |
| 54 |
# Use OpenSSL's sha2 functions if possible (don't assume name of crypto) |
| 55 |
O_LDFLAGS="$LDFLAGS" |
| 56 |
libcrypto= |
| 57 |
libcrypto_extra= |
| 58 |
for f in `$PKG_CONFIG $STATIC --libs $pkg_libcrypto`; do |
| 59 |
case "$f" in |
| 60 |
-l*) |
| 61 |
if test -z "$libcrypto"; then |
| 62 |
libcrypto="${f#-l}" |
| 63 |
else |
| 64 |
libcrypto_extra="$libcrypto_extra $f" |
| 65 |
fi |
| 66 |
;; |
| 67 |
*) |
| 68 |
AX_APPEND_FLAG([$f], [LDFLAGS]) |
| 69 |
;; |
| 70 |
esac |
| 71 |
done |
| 72 |
AC_CHECK_LIB([$libcrypto], [EVP_MD_CTX_new], [DIGEST=digest_openssl.lo], [], [$libcrypto_extra]) |
| 73 |
LDFLAGS="$O_LDFLAGS" |
| 74 |
|
| 75 |
# Use pkg-config to determine libcrypto libs and cflags |
| 76 |
for f in `$PKG_CONFIG $STATIC --libs $pkg_libcrypto`; do |
| 77 |
case "$f" in |
| 78 |
-L*) |
| 79 |
f="${f#-L}" |
| 80 |
SUDO_APPEND_LIBPATH([LIBCRYPTO], [$f]) |
| 81 |
;; |
| 82 |
*) |
| 83 |
AX_APPEND_FLAG([$f], [LIBCRYPTO]) |
| 84 |
;; |
| 85 |
esac |
| 86 |
done |
| 87 |
else |
| 88 |
# No separate pkg config for libcrypto |
| 89 |
LIBCRYPTO="$LIBTLS" |
| 90 |
LIBCRYPTO_R="$LIBTLS_R" |
| 91 |
fi |
| 92 |
for f in `$PKG_CONFIG --cflags-only-I $pkg_openssl`; do |
| 93 |
AX_APPEND_FLAG([$f], [CPPFLAGS]) |
| 94 |
done |
| 95 |
else |
| 96 |
# No pkg-config file present, try to do it manually |
| 97 |
O_LDFLAGS="$LDFLAGS" |
| 98 |
if test "$enable_openssl" != "yes" -a "$enable_openssl" != "maybe"; then |
| 99 |
SUDO_APPEND_LIBPATH(LDFLAGS, [${enable_openssl}/lib]) |
| 100 |
fi |
| 101 |
AC_CHECK_LIB([ssl], [SSL_new], [ |
| 102 |
# Check OPENSSL_VERSION_NUMBER in headers |
| 103 |
O_CPPFLAGS="$CPPFLAGS" |
| 104 |
if test "$enable_openssl" != "yes" -a "$enable_openssl" != "maybe"; then |
| 105 |
# Note: we only reset CPPFLAGS on failure |
| 106 |
AX_APPEND_FLAG([-I${enable_openssl}/include], [CPPFLAGS]) |
| 107 |
fi |
| 108 |
AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[#include <openssl/opensslv.h> |
| 109 |
#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x1000100fL |
| 110 |
#error "OpenSSL too old" |
| 111 |
#endif |
| 112 |
]])], [ |
| 113 |
# OpenSSL >= 1.0.1 detected, use it. |
| 114 |
AC_DEFINE(HAVE_OPENSSL) |
| 115 |
if test "$enable_openssl" != "yes" -a "$enable_openssl" != "maybe"; then |
| 116 |
SUDO_APPEND_LIBPATH(LIBCRYPTO, [${enable_openssl}/lib]) |
| 117 |
SUDO_APPEND_LIBPATH(LIBTLS, [${enable_openssl}/lib]) |
| 118 |
else |
| 119 |
enable_openssl=yes |
| 120 |
fi |
| 121 |
LIBCRYPTO="${LIBCRYPTO} -lcrypto" |
| 122 |
LIBTLS="${LIBTLS} -lssl -lcrypto" |
| 123 |
|
| 124 |
# Use OpenSSL's sha2 functions if possible |
| 125 |
AC_CHECK_LIB([crypto], [EVP_MD_CTX_new], [ |
| 126 |
DIGEST=digest_openssl.lo |
| 127 |
]) |
| 128 |
], [ |
| 129 |
# OpenSSL < 1.0.1 detected, ignore it. |
| 130 |
if test "$enable_openssl" = "maybe"; then |
| 131 |
AC_MSG_WARN([OpenSSL too old (1.0.1 or higher required), Sudo logsrv connections will not be encrypted.]) |
| 132 |
openssl_missing=yes |
| 133 |
enable_openssl=no |
| 134 |
else |
| 135 |
AC_MSG_ERROR([OpenSSL too old (1.0.1 or higher required).]) |
| 136 |
fi |
| 137 |
CPPFLAGS="$O_CPPFLAGS" |
| 138 |
]) |
| 139 |
], [ |
| 140 |
if test "$enable_openssl" = "maybe"; then |
| 141 |
openssl_missing=yes |
| 142 |
enable_openssl=no |
| 143 |
else |
| 144 |
AC_MSG_ERROR([OpenSSL development libraries not found.]) |
| 145 |
fi |
| 146 |
], [-lcrypto]) |
| 147 |
LDFLAGS="$O_LDFLAGS" |
| 148 |
fi |
| 149 |
if test "$enable_openssl" != "yes" -a "$enable_openssl" != "maybe"; then |
| 150 |
unset PKG_CONFIG_LIBDIR |
| 151 |
fi |
| 152 |
fi |
| 153 |
# |
| 154 |
# Note that enable_openssl may be reset above. |
| 155 |
# |
| 156 |
if test "${enable_openssl-no}" != no; then |
| 157 |
OLIBS="$LIBS" |
| 158 |
LIBS="$LIBS $LIBTLS" |
| 159 |
AC_CHECK_FUNCS([X509_STORE_CTX_get0_cert ASN1_STRING_get0_data SSL_CTX_get0_certificate SSL_CTX_set0_tmp_dh_pkey TLS_method]) |
| 160 |
# SSL_CTX_set_min_proto_version may be a macro |
| 161 |
AC_CHECK_DECL([SSL_CTX_set_min_proto_version], [AC_DEFINE(HAVE_SSL_CTX_SET_MIN_PROTO_VERSION)], [], [ |
| 162 |
AC_INCLUDES_DEFAULT |
| 163 |
#include <openssl/ssl.h> |
| 164 |
]) |
| 165 |
AC_CHECK_FUNCS([SSL_read_ex], [], [ |
| 166 |
SSL_COMPAT_SRC=lib/ssl_compat |
| 167 |
]) |
| 168 |
# LibreSSL TLS 1.3 support may not be enabled, check for declaration too. |
| 169 |
AC_CHECK_FUNC([SSL_CTX_set_ciphersuites], [ |
| 170 |
AC_CHECK_DECL([SSL_CTX_set_ciphersuites], [AC_DEFINE(HAVE_SSL_CTX_SET_CIPHERSUITES)], [], [ |
| 171 |
AC_INCLUDES_DEFAULT |
| 172 |
#include <openssl/ssl.h> |
| 173 |
]) |
| 174 |
]) |
| 175 |
LIBS="$OLIBS" |
| 176 |
elif test "${enable_wolfssl-no}" != no; then |
| 177 |
# Check for OpenSSL compatibility functions in wolfSSL. |
| 178 |
# Use pkg-config to find the wolfssl cflags and libs if possible. |
| 179 |
if test "$enable_wolfssl" != "yes"; then |
| 180 |
PKG_CONFIG_LIBDIR="${enable_wolfssl}/lib/pkgconfig:${enable_wolfssl}/lib64/pkgconfig:${enable_wolfssl}/share/pkgconfig" |
| 181 |
export PKG_CONFIG_LIBDIR |
| 182 |
elif test "$cross_compiling" = "yes" -a -z "$PKG_CONFIG"; then |
| 183 |
# Cannot use pkg-config when cross-compiling |
| 184 |
PKG_CONFIG=false |
| 185 |
fi |
| 186 |
: ${PKG_CONFIG='pkg-config'} |
| 187 |
if $PKG_CONFIG --exists wolfssl >/dev/null 2>&1; then |
| 188 |
AC_DEFINE(HAVE_OPENSSL) |
| 189 |
AC_DEFINE(HAVE_WOLFSSL) |
| 190 |
|
| 191 |
O_CPPFLAGS="$CPPFLAGS" |
| 192 |
CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags-only-I wolfssl`" |
| 193 |
O_LDFLAGS="$LDFLAGS" |
| 194 |
LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs-only-L wolfssl`" |
| 195 |
|
| 196 |
# Check whether --static is needed |
| 197 |
libssl="`$PKG_CONFIG --libs-only-l wolfssl | sed 's/^ *-l//'`" |
| 198 |
libssl_extra=`echo $libssl | sed 's/^[[^ ]]* *//'` |
| 199 |
libssl=`echo $libssl | sed 's/ .*//'` |
| 200 |
AC_CHECK_LIB([$libssl], [wolfSSL_new], [STATIC=""], [STATIC="--static"], [$libssl_extra]) |
| 201 |
|
| 202 |
# Use wolfSSL's sha2 functions if possible |
| 203 |
AC_CHECK_DECL([EVP_MD_CTX_new], [DIGEST=digest_openssl.lo], [], [ |
| 204 |
AC_INCLUDES_DEFAULT |
| 205 |
#include <wolfssl/options.h> |
| 206 |
#include <wolfssl/openssl/evp.h> |
| 207 |
]) |
| 208 |
CPPFLAGS="$O_CPPFLAGS" |
| 209 |
LDFLAGS="$O_LDFLAGS" |
| 210 |
|
| 211 |
# Use pkg-config to determine wolfSSL libs and cflags |
| 212 |
for f in `$PKG_CONFIG $STATIC --libs wolfssl`; do |
| 213 |
case "$f" in |
| 214 |
-L*) |
| 215 |
f="${f#-L}" |
| 216 |
SUDO_APPEND_LIBPATH([LIBTLS], [$f]) |
| 217 |
;; |
| 218 |
*) |
| 219 |
AX_APPEND_FLAG([$f], [LIBTLS]) |
| 220 |
;; |
| 221 |
esac |
| 222 |
done |
| 223 |
# No separate pkg config for libcrypto |
| 224 |
LIBCRYPTO="$LIBTLS" |
| 225 |
LIBCRYPTO_R="$LIBTLS_R" |
| 226 |
for f in `$PKG_CONFIG --cflags-only-I wolfssl`; do |
| 227 |
AX_APPEND_FLAG([$f], [CPPFLAGS]) |
| 228 |
# So we find the openssl compat headers under wolfssl |
| 229 |
AX_APPEND_FLAG([$f/wolfssl], [CPPFLAGS]) |
| 230 |
done |
| 231 |
if test "$cross_compiling" != "yes" -a "$CPPFLAGS" = "$O_CPPFLAGS"; then |
| 232 |
# So we find the openssl compat headers under wolfssl (XXX) |
| 233 |
AX_APPEND_FLAG([-I/usr/include/wolfssl], [CPPFLAGS]) |
| 234 |
fi |
| 235 |
else |
| 236 |
AC_DEFINE(HAVE_OPENSSL) |
| 237 |
AC_DEFINE(HAVE_WOLFSSL) |
| 238 |
|
| 239 |
# No pkg-config file present, try to do it manually |
| 240 |
if test "$enable_wolfssl" != "yes"; then |
| 241 |
SUDO_APPEND_LIBPATH(LIBCRYPTO, [${enable_wolfssl}/lib]) |
| 242 |
SUDO_APPEND_LIBPATH(LIBTLS, [${enable_wolfssl}/lib]) |
| 243 |
AX_APPEND_FLAG([-I${enable_wolfssl}/include], [CPPFLAGS]) |
| 244 |
# So we find the openssl compat headers under wolfssl |
| 245 |
AX_APPEND_FLAG([-I${enable_wolfssl}/include/wolfssl], [CPPFLAGS]) |
| 246 |
else |
| 247 |
# So we find the openssl compat headers under wolfssl (XXX) |
| 248 |
AX_APPEND_FLAG([-I/usr/include/wolfssl], [CPPFLAGS]) |
| 249 |
fi |
| 250 |
LIBTLS="${LIBTLS} -lwolfssl" |
| 251 |
LIBCRYPTO="${LIBCRYPTO} -lwolfssl" |
| 252 |
|
| 253 |
# Use wolfSSL's sha2 functions if possible |
| 254 |
AC_CHECK_DECL([EVP_MD_CTX_new], [DIGEST=digest_openssl.lo], [], [ |
| 255 |
AC_INCLUDES_DEFAULT |
| 256 |
#include <wolfssl/options.h> |
| 257 |
#include <wolfssl/openssl/evp.h> |
| 258 |
]) |
| 259 |
fi |
| 260 |
dnl |
| 261 |
dnl Check for specific OpenSSL API compatibility macros |
| 262 |
dnl |
| 263 |
AC_CHECK_DECL([X509_STORE_CTX_get0_cert], [AC_DEFINE(HAVE_X509_STORE_CTX_GET0_CERT)], [], [ |
| 264 |
AC_INCLUDES_DEFAULT |
| 265 |
#include <wolfssl/options.h> |
| 266 |
#include <wolfssl/openssl/x509.h> |
| 267 |
]) |
| 268 |
AC_CHECK_DECL([ASN1_STRING_get0_data], [AC_DEFINE(HAVE_ASN1_STRING_GET0_DATA)], [], [ |
| 269 |
AC_INCLUDES_DEFAULT |
| 270 |
#include <wolfssl/options.h> |
| 271 |
#include <wolfssl/openssl/asn1.h> |
| 272 |
]) |
| 273 |
AC_CHECK_DECL([SSL_CTX_get0_certificate], [AC_DEFINE(HAVE_SSL_CTX_GET0_CERTIFICATE)], [], [ |
| 274 |
AC_INCLUDES_DEFAULT |
| 275 |
#include <wolfssl/options.h> |
| 276 |
#include <wolfssl/openssl/ssl.h> |
| 277 |
]) |
| 278 |
AC_CHECK_DECL([SSL_CTX_set0_tmp_dh_pkey], [AC_DEFINE(HAVE_SSL_CTX_SET0_TMP_DH_PKEY)], [], [ |
| 279 |
AC_INCLUDES_DEFAULT |
| 280 |
#include <wolfssl/options.h> |
| 281 |
#include <wolfssl/openssl/ssl.h> |
| 282 |
]) |
| 283 |
AC_CHECK_DECL([TLS_method], [AC_DEFINE(HAVE_TLS_METHOD)], [], [ |
| 284 |
AC_INCLUDES_DEFAULT |
| 285 |
#include <wolfssl/options.h> |
| 286 |
#include <wolfssl/openssl/ssl.h> |
| 287 |
]) |
| 288 |
AC_CHECK_DECL([SSL_CTX_set_min_proto_version], [AC_DEFINE(HAVE_SSL_CTX_SET_MIN_PROTO_VERSION)], [], [ |
| 289 |
AC_INCLUDES_DEFAULT |
| 290 |
#include <wolfssl/options.h> |
| 291 |
#include <wolfssl/openssl/ssl.h> |
| 292 |
]) |
| 293 |
AC_CHECK_DECL([SSL_CTX_set_ciphersuites], [AC_DEFINE(HAVE_SSL_CTX_SET_CIPHERSUITES)], [], [ |
| 294 |
AC_INCLUDES_DEFAULT |
| 295 |
#include <wolfssl/options.h> |
| 296 |
#include <wolfssl/openssl/ssl.h> |
| 297 |
]) |
| 298 |
AC_CHECK_DECL([SSL_read_ex], [AC_DEFINE(HAVE_SSL_READ_EX)], [ |
| 299 |
SSL_COMPAT_SRC=lib/ssl_compat |
| 300 |
], [ |
| 301 |
AC_INCLUDES_DEFAULT |
| 302 |
#include <wolfssl/options.h> |
| 303 |
#include <wolfssl/openssl/ssl.h> |
| 304 |
]) |
| 305 |
fi |
| 306 |
if test -n "$SSL_COMPAT_SRC"; then |
| 307 |
LIBTLS='$(top_builddir)/lib/ssl_compat/libssl_compat.la '"${LIBTLS}" |
| 308 |
fi |
| 309 |
]) |