curl-openssl.m4 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. #***************************************************************************
  22. # File version for 'aclocal' use. Keep it a single number.
  23. # serial 5
  24. dnl **********************************************************************
  25. dnl Check for OpenSSL libraries and headers
  26. dnl **********************************************************************
  27. AC_DEFUN([CURL_WITH_OPENSSL], [
  28. if test "x$OPT_OPENSSL" != xno; then
  29. ssl_msg=
  30. dnl backup the pre-ssl variables
  31. CLEANLDFLAGS="$LDFLAGS"
  32. CLEANCPPFLAGS="$CPPFLAGS"
  33. CLEANLIBS="$LIBS"
  34. dnl This is for Msys/Mingw
  35. case $host in
  36. *-*-msys* | *-*-mingw*)
  37. AC_MSG_CHECKING([for gdi32])
  38. my_ac_save_LIBS=$LIBS
  39. LIBS="-lgdi32 $LIBS"
  40. AC_LINK_IFELSE([ AC_LANG_PROGRAM([[
  41. #include <windef.h>
  42. #include <wingdi.h>
  43. ]],
  44. [[
  45. GdiFlush();
  46. ]])],
  47. [ dnl worked!
  48. AC_MSG_RESULT([yes])],
  49. [ dnl failed, restore LIBS
  50. LIBS=$my_ac_save_LIBS
  51. AC_MSG_RESULT(no)]
  52. )
  53. ;;
  54. esac
  55. case "$OPT_OPENSSL" in
  56. yes)
  57. dnl --with-openssl (without path) used
  58. PKGTEST="yes"
  59. PREFIX_OPENSSL=
  60. ;;
  61. *)
  62. dnl check the given --with-openssl spot
  63. PKGTEST="no"
  64. PREFIX_OPENSSL=$OPT_OPENSSL
  65. dnl Try pkg-config even when cross-compiling. Since we
  66. dnl specify PKG_CONFIG_LIBDIR we're only looking where
  67. dnl the user told us to look
  68. OPENSSL_PCDIR="$OPT_OPENSSL/lib/pkgconfig"
  69. if test -f "$OPENSSL_PCDIR/openssl.pc"; then
  70. AC_MSG_NOTICE([PKG_CONFIG_LIBDIR will be set to "$OPENSSL_PCDIR"])
  71. PKGTEST="yes"
  72. fi
  73. if test "$PKGTEST" != "yes"; then
  74. # try lib64 instead
  75. OPENSSL_PCDIR="$OPT_OPENSSL/lib64/pkgconfig"
  76. if test -f "$OPENSSL_PCDIR/openssl.pc"; then
  77. AC_MSG_NOTICE([PKG_CONFIG_LIBDIR will be set to "$OPENSSL_PCDIR"])
  78. PKGTEST="yes"
  79. fi
  80. fi
  81. if test "$PKGTEST" != "yes"; then
  82. if test ! -f "$PREFIX_OPENSSL/include/openssl/ssl.h"; then
  83. AC_MSG_ERROR([$PREFIX_OPENSSL is a bad --with-openssl prefix!])
  84. fi
  85. fi
  86. dnl in case pkg-config comes up empty, use what we got
  87. dnl via --with-openssl
  88. LIB_OPENSSL="$PREFIX_OPENSSL/lib$libsuff"
  89. if test "$PREFIX_OPENSSL" != "/usr" ; then
  90. SSL_LDFLAGS="-L$LIB_OPENSSL"
  91. SSL_CPPFLAGS="-I$PREFIX_OPENSSL/include"
  92. fi
  93. SSL_CPPFLAGS="$SSL_CPPFLAGS -I$PREFIX_OPENSSL/include/openssl"
  94. ;;
  95. esac
  96. if test "$PKGTEST" = "yes"; then
  97. CURL_CHECK_PKGCONFIG(openssl, [$OPENSSL_PCDIR])
  98. if test "$PKGCONFIG" != "no" ; then
  99. SSL_LIBS=`CURL_EXPORT_PCDIR([$OPENSSL_PCDIR]) dnl
  100. $PKGCONFIG --libs-only-l --libs-only-other openssl 2>/dev/null`
  101. SSL_LDFLAGS=`CURL_EXPORT_PCDIR([$OPENSSL_PCDIR]) dnl
  102. $PKGCONFIG --libs-only-L openssl 2>/dev/null`
  103. SSL_CPPFLAGS=`CURL_EXPORT_PCDIR([$OPENSSL_PCDIR]) dnl
  104. $PKGCONFIG --cflags-only-I openssl 2>/dev/null`
  105. AC_SUBST(SSL_LIBS)
  106. AC_MSG_NOTICE([pkg-config: SSL_LIBS: "$SSL_LIBS"])
  107. AC_MSG_NOTICE([pkg-config: SSL_LDFLAGS: "$SSL_LDFLAGS"])
  108. AC_MSG_NOTICE([pkg-config: SSL_CPPFLAGS: "$SSL_CPPFLAGS"])
  109. LIB_OPENSSL=`echo $SSL_LDFLAGS | sed -e 's/^-L//'`
  110. dnl use the values pkg-config reported. This is here
  111. dnl instead of below with CPPFLAGS and LDFLAGS because we only
  112. dnl learn about this via pkg-config. If we only have
  113. dnl the argument to --with-openssl we don't know what
  114. dnl additional libs may be necessary. Hope that we
  115. dnl don't need any.
  116. LIBS="$SSL_LIBS $LIBS"
  117. fi
  118. fi
  119. dnl finally, set flags to use SSL
  120. CPPFLAGS="$CPPFLAGS $SSL_CPPFLAGS"
  121. LDFLAGS="$LDFLAGS $SSL_LDFLAGS"
  122. AC_CHECK_LIB(crypto, HMAC_Update,[
  123. HAVECRYPTO="yes"
  124. LIBS="-lcrypto $LIBS"
  125. ],[
  126. if test -n "$LIB_OPENSSL" ; then
  127. LDFLAGS="$CLEANLDFLAGS -L$LIB_OPENSSL"
  128. fi
  129. if test "$PKGCONFIG" = "no" -a -n "$PREFIX_OPENSSL" ; then
  130. # only set this if pkg-config wasn't used
  131. CPPFLAGS="$CLEANCPPFLAGS -I$PREFIX_OPENSSL/include/openssl -I$PREFIX_OPENSSL/include"
  132. fi
  133. # Linking previously failed, try extra paths from --with-openssl or
  134. # pkg-config. Use a different function name to avoid reusing the earlier
  135. # cached result.
  136. AC_CHECK_LIB(crypto, HMAC_Init_ex,[
  137. HAVECRYPTO="yes"
  138. LIBS="-lcrypto $LIBS"], [
  139. dnl still no, but what about with -ldl?
  140. AC_MSG_CHECKING([OpenSSL linking with -ldl])
  141. LIBS="-lcrypto $CLEANLIBS -ldl"
  142. AC_LINK_IFELSE([ AC_LANG_PROGRAM([[
  143. #include <openssl/err.h>
  144. ]], [[
  145. ERR_clear_error();
  146. ]]) ],
  147. [
  148. AC_MSG_RESULT(yes)
  149. HAVECRYPTO="yes"
  150. ],
  151. [
  152. AC_MSG_RESULT(no)
  153. dnl ok, so what about both -ldl and -lpthread?
  154. dnl This may be necessary for static libraries.
  155. AC_MSG_CHECKING([OpenSSL linking with -ldl and -lpthread])
  156. LIBS="-lcrypto $CLEANLIBS -ldl -lpthread"
  157. AC_LINK_IFELSE([
  158. AC_LANG_PROGRAM([[
  159. #include <openssl/err.h>
  160. ]], [[
  161. ERR_clear_error();
  162. ]])],
  163. [
  164. AC_MSG_RESULT(yes)
  165. HAVECRYPTO="yes"
  166. ],
  167. [
  168. AC_MSG_RESULT(no)
  169. LDFLAGS="$CLEANLDFLAGS"
  170. CPPFLAGS="$CLEANCPPFLAGS"
  171. LIBS="$CLEANLIBS"
  172. ])
  173. ])
  174. ])
  175. ])
  176. if test X"$HAVECRYPTO" = X"yes"; then
  177. dnl This is only reasonable to do if crypto actually is there: check for
  178. dnl SSL libs NOTE: it is important to do this AFTER the crypto lib
  179. AC_CHECK_LIB(ssl, SSL_connect)
  180. if test "$ac_cv_lib_ssl_SSL_connect" != yes; then
  181. dnl we didn't find the SSL lib, try the RSAglue/rsaref stuff
  182. AC_MSG_CHECKING(for ssl with RSAglue/rsaref libs in use);
  183. OLIBS=$LIBS
  184. LIBS="-lRSAglue -lrsaref $LIBS"
  185. AC_CHECK_LIB(ssl, SSL_connect)
  186. if test "$ac_cv_lib_ssl_SSL_connect" != yes; then
  187. dnl still no SSL_connect
  188. AC_MSG_RESULT(no)
  189. LIBS=$OLIBS
  190. else
  191. AC_MSG_RESULT(yes)
  192. fi
  193. else
  194. dnl Have the libraries--check for OpenSSL headers
  195. AC_CHECK_HEADERS(openssl/x509.h openssl/rsa.h openssl/crypto.h \
  196. openssl/pem.h openssl/ssl.h openssl/err.h,
  197. ssl_msg="OpenSSL"
  198. test openssl != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
  199. OPENSSL_ENABLED=1
  200. AC_DEFINE(USE_OPENSSL, 1, [if OpenSSL is in use]))
  201. if test $ac_cv_header_openssl_x509_h = no; then
  202. dnl we don't use the "action" part of the AC_CHECK_HEADERS macro
  203. dnl since 'err.h' might in fact find a krb4 header with the same
  204. dnl name
  205. AC_CHECK_HEADERS(x509.h rsa.h crypto.h pem.h ssl.h err.h)
  206. if test $ac_cv_header_x509_h = yes &&
  207. test $ac_cv_header_crypto_h = yes &&
  208. test $ac_cv_header_ssl_h = yes; then
  209. dnl three matches
  210. ssl_msg="OpenSSL"
  211. OPENSSL_ENABLED=1
  212. fi
  213. fi
  214. fi
  215. if test X"$OPENSSL_ENABLED" != X"1"; then
  216. LIBS="$CLEANLIBS"
  217. fi
  218. if test X"$OPT_OPENSSL" != Xoff &&
  219. test "$OPENSSL_ENABLED" != "1"; then
  220. AC_MSG_ERROR([OpenSSL libs and/or directories were not found where specified!])
  221. fi
  222. fi
  223. if test X"$OPENSSL_ENABLED" = X"1"; then
  224. dnl These can only exist if OpenSSL exists
  225. AC_CHECK_FUNCS( RAND_egd )
  226. AC_MSG_CHECKING([for BoringSSL])
  227. AC_COMPILE_IFELSE([
  228. AC_LANG_PROGRAM([[
  229. #include <openssl/base.h>
  230. ]],[[
  231. #ifndef OPENSSL_IS_BORINGSSL
  232. #error not boringssl
  233. #endif
  234. ]])
  235. ],[
  236. AC_MSG_RESULT([yes])
  237. AC_DEFINE_UNQUOTED(HAVE_BORINGSSL, 1,
  238. [Define to 1 if using BoringSSL.])
  239. ssl_msg="BoringSSL"
  240. ],[
  241. AC_MSG_RESULT([no])
  242. ])
  243. AC_MSG_CHECKING([for libressl])
  244. AC_COMPILE_IFELSE([
  245. AC_LANG_PROGRAM([[
  246. #include <openssl/opensslv.h>
  247. ]],[[
  248. int dummy = LIBRESSL_VERSION_NUMBER;
  249. ]])
  250. ],[
  251. AC_MSG_RESULT([yes])
  252. AC_DEFINE_UNQUOTED(HAVE_LIBRESSL, 1,
  253. [Define to 1 if using libressl.])
  254. ssl_msg="libressl"
  255. ],[
  256. AC_MSG_RESULT([no])
  257. ])
  258. AC_MSG_CHECKING([for OpenSSL >= v3])
  259. AC_COMPILE_IFELSE([
  260. AC_LANG_PROGRAM([[
  261. #include <openssl/opensslv.h>
  262. ]],[[
  263. #if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
  264. return 0;
  265. #else
  266. #error older than 3
  267. #endif
  268. ]])
  269. ],[
  270. AC_MSG_RESULT([yes])
  271. AC_DEFINE_UNQUOTED(HAVE_OPENSSL3, 1,
  272. [Define to 1 if using OpenSSL 3 or later.])
  273. dnl OpenSSLv3 marks the DES functions deprecated but we have no
  274. dnl replacements (yet) so tell the compiler to not warn for them
  275. dnl
  276. dnl Ask OpenSSL to suppress the warnings.
  277. CPPFLAGS="$CPPFLAGS -DOPENSSL_SUPPRESS_DEPRECATED"
  278. ssl_msg="OpenSSL v3+"
  279. ],[
  280. AC_MSG_RESULT([no])
  281. ])
  282. fi
  283. if test "$OPENSSL_ENABLED" = "1"; then
  284. if test -n "$LIB_OPENSSL"; then
  285. dnl when the ssl shared libs were found in a path that the run-time
  286. dnl linker doesn't search through, we need to add it to CURL_LIBRARY_PATH
  287. dnl to prevent further configure tests to fail due to this
  288. if test "x$cross_compiling" != "xyes"; then
  289. CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$LIB_OPENSSL"
  290. export CURL_LIBRARY_PATH
  291. AC_MSG_NOTICE([Added $LIB_OPENSSL to CURL_LIBRARY_PATH])
  292. fi
  293. fi
  294. check_for_ca_bundle=1
  295. fi
  296. test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
  297. fi
  298. if test X"$OPT_OPENSSL" != Xno &&
  299. test "$OPENSSL_ENABLED" != "1"; then
  300. AC_MSG_NOTICE([OPT_OPENSSL: $OPT_OPENSSL])
  301. AC_MSG_NOTICE([OPENSSL_ENABLED: $OPENSSL_ENABLED])
  302. AC_MSG_ERROR([--with-openssl was given but OpenSSL could not be detected])
  303. fi
  304. dnl **********************************************************************
  305. dnl Check for the random seed preferences
  306. dnl **********************************************************************
  307. if test X"$OPENSSL_ENABLED" = X"1"; then
  308. AC_ARG_WITH(egd-socket,
  309. AS_HELP_STRING([--with-egd-socket=FILE],
  310. [Entropy Gathering Daemon socket pathname]),
  311. [ EGD_SOCKET="$withval" ]
  312. )
  313. if test -n "$EGD_SOCKET" ; then
  314. AC_DEFINE_UNQUOTED(EGD_SOCKET, "$EGD_SOCKET",
  315. [your Entropy Gathering Daemon socket pathname] )
  316. fi
  317. dnl Check for user-specified random device
  318. AC_ARG_WITH(random,
  319. AS_HELP_STRING([--with-random=FILE],
  320. [read randomness from FILE (default=/dev/urandom)]),
  321. [ RANDOM_FILE="$withval" ],
  322. [
  323. if test x$cross_compiling != xyes; then
  324. dnl Check for random device
  325. AC_CHECK_FILE("/dev/urandom", [ RANDOM_FILE="/dev/urandom"] )
  326. else
  327. AC_MSG_WARN([skipped the /dev/urandom detection when cross-compiling])
  328. fi
  329. ]
  330. )
  331. if test -n "$RANDOM_FILE" && test X"$RANDOM_FILE" != Xno ; then
  332. AC_SUBST(RANDOM_FILE)
  333. AC_DEFINE_UNQUOTED(RANDOM_FILE, "$RANDOM_FILE",
  334. [a suitable file to read random data from])
  335. fi
  336. fi
  337. dnl ---
  338. dnl We require OpenSSL with SRP support.
  339. dnl ---
  340. if test "$OPENSSL_ENABLED" = "1"; then
  341. AC_MSG_CHECKING([for SRP support in OpenSSL])
  342. AC_LINK_IFELSE([
  343. AC_LANG_PROGRAM([[
  344. #include <openssl/ssl.h>
  345. ]],[[
  346. SSL_CTX_set_srp_username(NULL, "");
  347. SSL_CTX_set_srp_password(NULL, "");
  348. ]])
  349. ],[
  350. AC_MSG_RESULT([yes])
  351. AC_DEFINE(HAVE_OPENSSL_SRP, 1, [if you have the functions SSL_CTX_set_srp_username and SSL_CTX_set_srp_password])
  352. AC_SUBST(HAVE_OPENSSL_SRP, [1])
  353. ],[
  354. AC_MSG_RESULT([no])
  355. ])
  356. fi
  357. dnl ---
  358. dnl Whether the OpenSSL configuration will be loaded automatically
  359. dnl ---
  360. if test X"$OPENSSL_ENABLED" = X"1"; then
  361. AC_ARG_ENABLE(openssl-auto-load-config,
  362. AS_HELP_STRING([--enable-openssl-auto-load-config],[Enable automatic loading of OpenSSL configuration])
  363. AS_HELP_STRING([--disable-openssl-auto-load-config],[Disable automatic loading of OpenSSL configuration]),
  364. [ if test X"$enableval" = X"no"; then
  365. AC_MSG_NOTICE([automatic loading of OpenSSL configuration disabled])
  366. AC_DEFINE(CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG, 1, [if the OpenSSL configuration won't be loaded automatically])
  367. fi
  368. ])
  369. fi
  370. ])