• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 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# SPDX-License-Identifier: curl
22#
23#***************************************************************************
24
25dnl ----------------------------------------------------
26dnl check for GnuTLS
27dnl ----------------------------------------------------
28
29AC_DEFUN([CURL_WITH_GNUTLS], [
30if test "x$OPT_GNUTLS" != xno; then
31  ssl_msg=
32
33  if test X"$OPT_GNUTLS" != Xno; then
34
35    addld=""
36    addlib=""
37    gtlslib=""
38    version=""
39    addcflags=""
40
41    if test "x$OPT_GNUTLS" = "xyes"; then
42      dnl this is with no particular path given
43      CURL_CHECK_PKGCONFIG(gnutls)
44
45      if test "$PKGCONFIG" != "no" ; then
46        addlib=`$PKGCONFIG --libs-only-l gnutls`
47        addld=`$PKGCONFIG --libs-only-L gnutls`
48        addcflags=`$PKGCONFIG --cflags-only-I gnutls`
49        version=`$PKGCONFIG --modversion gnutls`
50        gtlslib=`echo $addld | $SED -e 's/^-L//'`
51      else
52        dnl without pkg-config, we try libgnutls-config as that was how it
53        dnl used to be done
54        check=`libgnutls-config --version 2>/dev/null`
55        if test -n "$check"; then
56          addlib=`libgnutls-config --libs`
57          addcflags=`libgnutls-config --cflags`
58          version=`libgnutls-config --version`
59          gtlslib=`libgnutls-config --prefix`/lib$libsuff
60        fi
61      fi
62    else
63      dnl this is with a given path, first check if there's a libgnutls-config
64      dnl there and if not, make an educated guess
65      cfg=$OPT_GNUTLS/bin/libgnutls-config
66      check=`$cfg --version 2>/dev/null`
67      if test -n "$check"; then
68        addlib=`$cfg --libs`
69        addcflags=`$cfg --cflags`
70        version=`$cfg --version`
71        gtlslib=`$cfg --prefix`/lib$libsuff
72      else
73        dnl without pkg-config and libgnutls-config, we guess a lot!
74        addlib=-lgnutls
75        addld=-L$OPT_GNUTLS/lib$libsuff
76        addcflags=-I$OPT_GNUTLS/include
77        version="" # we just don't know
78        gtlslib=$OPT_GNUTLS/lib$libsuff
79      fi
80    fi
81
82    if test -z "$version"; then
83      dnl lots of efforts, still no go
84      version="unknown"
85    fi
86
87    if test -n "$addlib"; then
88
89      CLEANLIBS="$LIBS"
90      CLEANCPPFLAGS="$CPPFLAGS"
91      CLEANLDFLAGS="$LDFLAGS"
92      CLEANLDFLAGSPC="$LDFLAGSPC"
93
94      LIBS="$addlib $LIBS"
95      LDFLAGS="$LDFLAGS $addld"
96      LDFLAGSPC="$LDFLAGSPC $addld"
97      if test "$addcflags" != "-I/usr/include"; then
98        CPPFLAGS="$CPPFLAGS $addcflags"
99      fi
100
101      dnl this function is selected since it was introduced in 3.1.10
102      AC_CHECK_LIB(gnutls, gnutls_x509_crt_get_dn2,
103        [
104        AC_DEFINE(USE_GNUTLS, 1, [if GnuTLS is enabled])
105        GNUTLS_ENABLED=1
106        USE_GNUTLS="yes"
107        ssl_msg="GnuTLS"
108        QUIC_ENABLED=yes
109        test gnutls != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
110        ],
111        [
112          LIBS="$CLEANLIBS"
113          CPPFLAGS="$CLEANCPPFLAGS"
114        ])
115
116      if test "x$USE_GNUTLS" = "xyes"; then
117        AC_MSG_NOTICE([detected GnuTLS version $version])
118        check_for_ca_bundle=1
119        if test -n "$gtlslib"; then
120          dnl when shared libs were found in a path that the run-time
121          dnl linker doesn't search through, we need to add it to
122          dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
123          dnl due to this
124          if test "x$cross_compiling" != "xyes"; then
125            CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$gtlslib"
126            export CURL_LIBRARY_PATH
127            AC_MSG_NOTICE([Added $gtlslib to CURL_LIBRARY_PATH])
128          fi
129        fi
130        LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE gnutls nettle"
131      fi
132
133    fi
134
135  fi dnl GNUTLS not disabled
136
137  test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
138fi
139
140dnl ---
141dnl Check which crypto backend GnuTLS uses
142dnl ---
143
144if test "$GNUTLS_ENABLED" = "1"; then
145  USE_GNUTLS_NETTLE=
146  # First check if we can detect either crypto library via transitive linking
147  AC_CHECK_LIB(gnutls, nettle_MD5Init, [ USE_GNUTLS_NETTLE=1 ])
148
149  # If not, try linking directly to both of them to see if they are available
150  if test "$USE_GNUTLS_NETTLE" = ""; then
151    AC_CHECK_LIB(nettle, nettle_MD5Init, [ USE_GNUTLS_NETTLE=1 ])
152  fi
153  if test "$USE_GNUTLS_NETTLE" = ""; then
154    AC_MSG_ERROR([GnuTLS found, but nettle was not found])
155  fi
156  LIBS="-lnettle $LIBS"
157fi
158
159dnl ---
160dnl We require GnuTLS with SRP support.
161dnl ---
162if test "$GNUTLS_ENABLED" = "1"; then
163  AC_CHECK_LIB(gnutls, gnutls_srp_verifier,
164    [
165      AC_DEFINE(HAVE_GNUTLS_SRP, 1, [if you have the function gnutls_srp_verifier])
166      HAVE_GNUTLS_SRP=1
167    ])
168fi
169
170])
171