Skip to content

Commit

Permalink
lib: add ability to disable auths individually
Browse files Browse the repository at this point in the history
Both with configure and cmake

Closes #11490
  • Loading branch information
wyattoday authored and bagder committed Sep 7, 2023
1 parent 33dac9d commit e92edfb
Show file tree
Hide file tree
Showing 33 changed files with 266 additions and 76 deletions.
24 changes: 17 additions & 7 deletions CMakeLists.txt
Expand Up @@ -191,8 +191,18 @@ option(CURL_DISABLE_ALTSVC "disables alt-svc support" OFF)
mark_as_advanced(CURL_DISABLE_ALTSVC)
option(CURL_DISABLE_COOKIES "disables cookies support" OFF)
mark_as_advanced(CURL_DISABLE_COOKIES)
option(CURL_DISABLE_CRYPTO_AUTH "disables cryptographic authentication" OFF)
mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
option(CURL_DISABLE_BASIC_AUTH "disables Basic authentication" OFF)
mark_as_advanced(CURL_DISABLE_BASIC_AUTH)
option(CURL_DISABLE_BEARER_AUTH "disables Bearer authentication" OFF)
mark_as_advanced(CURL_DISABLE_BEARER_AUTH)
option(CURL_DISABLE_DIGEST_AUTH "disables Digest authentication" OFF)
mark_as_advanced(CURL_DISABLE_DIGEST_AUTH)
option(CURL_DISABLE_KERBEROS_AUTH "disables Kerberos authentication" OFF)
mark_as_advanced(CURL_DISABLE_KERBEROS_AUTH)
option(CURL_DISABLE_NEGOTIATE_AUTH "disables negotiate authentication" OFF)
mark_as_advanced(CURL_DISABLE_NEGOTIATE_AUTH)
option(CURL_DISABLE_AWS "disables AWS-SIG4" OFF)
mark_as_advanced(CURL_DISABLE_AWS)
option(CURL_DISABLE_DICT "disables DICT" OFF)
mark_as_advanced(CURL_DISABLE_DICT)
option(CURL_DISABLE_DOH "disables DNS-over-HTTPS" OFF)
Expand Down Expand Up @@ -1448,7 +1458,7 @@ endmacro()

# NTLM support requires crypto function adaptions from various SSL libs
# TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
if(NOT (CURL_DISABLE_CRYPTO_AUTH OR CURL_DISABLE_NTLM) AND
if(NOT (CURL_DISABLE_NTLM) AND
(USE_OPENSSL OR USE_MBEDTLS OR USE_DARWINSSL OR USE_WIN32_CRYPTO OR USE_GNUTLS))
set(use_curl_ntlm_core ON)
endif()
Expand All @@ -1471,16 +1481,16 @@ _add_if("GSS-API" HAVE_GSSAPI)
_add_if("alt-svc" NOT CURL_DISABLE_ALTSVC)
_add_if("HSTS" NOT CURL_DISABLE_HSTS)
# TODO SSP1 missing for SPNEGO
_add_if("SPNEGO" NOT CURL_DISABLE_CRYPTO_AUTH AND
_add_if("SPNEGO" NOT CURL_DISABLE_NEGOTIATE_AUTH AND
(HAVE_GSSAPI OR USE_WINDOWS_SSPI))
_add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
_add_if("Kerberos" NOT CURL_DISABLE_KERBEROS_AUTH AND
(HAVE_GSSAPI OR USE_WINDOWS_SSPI))
# NTLM support requires crypto function adaptions from various SSL libs
# TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
_add_if("NTLM" NOT (CURL_DISABLE_CRYPTO_AUTH OR CURL_DISABLE_NTLM) AND
_add_if("NTLM" NOT (CURL_DISABLE_NTLM) AND
(use_curl_ntlm_core OR USE_WINDOWS_SSPI))
# TODO missing option (autoconf: --enable-ntlm-wb)
_add_if("NTLM_WB" NOT (CURL_DISABLE_CRYPTO_AUTH OR CURL_DISABLE_NTLM) AND
_add_if("NTLM_WB" NOT (CURL_DISABLE_NTLM) AND
(use_curl_ntlm_core OR USE_WINDOWS_SSPI) AND
NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
# TODO missing option (--enable-tls-srp), depends on GNUTLS_SRP/OPENSSL_SRP
Expand Down
117 changes: 106 additions & 11 deletions configure.ac
Expand Up @@ -3935,17 +3935,113 @@ AS_HELP_STRING([--disable-sspi],[Disable SSPI]),
)

dnl ************************************************************
dnl disable cryptographic authentication
dnl disable basic authentication
dnl
AC_MSG_CHECKING([whether to enable cryptographic authentication methods])
AC_ARG_ENABLE(crypto-auth,
AS_HELP_STRING([--enable-crypto-auth],[Enable cryptographic authentication])
AS_HELP_STRING([--disable-crypto-auth],[Disable cryptographic authentication]),
AC_MSG_CHECKING([whether to enable basic authentication method])
AC_ARG_ENABLE(basic-auth,
AS_HELP_STRING([--enable-basic-auth],[Enable basic authentication (default)])
AS_HELP_STRING([--disable-basic-auth],[Disable basic authentication]),
[ case "$enableval" in
no)
AC_MSG_RESULT(no)
AC_DEFINE(CURL_DISABLE_CRYPTO_AUTH, 1, [to disable cryptographic authentication])
CURL_DISABLE_CRYPTO_AUTH=1
AC_DEFINE(CURL_DISABLE_BASIC_AUTH, 1, [to disable basic authentication])
CURL_DISABLE_BASIC_AUTH=1
;;
*) AC_MSG_RESULT(yes)
;;
esac ],
AC_MSG_RESULT(yes)
)

dnl ************************************************************
dnl disable bearer authentication
dnl
AC_MSG_CHECKING([whether to enable bearer authentication method])
AC_ARG_ENABLE(bearer-auth,
AS_HELP_STRING([--enable-bearer-auth],[Enable bearer authentication (default)])
AS_HELP_STRING([--disable-bearer-auth],[Disable bearer authentication]),
[ case "$enableval" in
no)
AC_MSG_RESULT(no)
AC_DEFINE(CURL_DISABLE_BEARER_AUTH, 1, [to disable bearer authentication])
CURL_DISABLE_BEARER_AUTH=1
;;
*) AC_MSG_RESULT(yes)
;;
esac ],
AC_MSG_RESULT(yes)
)

dnl ************************************************************
dnl disable digest authentication
dnl
AC_MSG_CHECKING([whether to enable digest authentication method])
AC_ARG_ENABLE(digest-auth,
AS_HELP_STRING([--enable-digest-auth],[Enable digest authentication (default)])
AS_HELP_STRING([--disable-digest-auth],[Disable digest authentication]),
[ case "$enableval" in
no)
AC_MSG_RESULT(no)
AC_DEFINE(CURL_DISABLE_DIGEST_AUTH, 1, [to disable digest authentication])
CURL_DISABLE_DIGEST_AUTH=1
;;
*) AC_MSG_RESULT(yes)
;;
esac ],
AC_MSG_RESULT(yes)
)

dnl ************************************************************
dnl disable kerberos authentication
dnl
AC_MSG_CHECKING([whether to enable kerberos authentication method])
AC_ARG_ENABLE(kerberos-auth,
AS_HELP_STRING([--enable-kerberos-auth],[Enable kerberos authentication (default)])
AS_HELP_STRING([--disable-kerberos-auth],[Disable kerberos authentication]),
[ case "$enableval" in
no)
AC_MSG_RESULT(no)
AC_DEFINE(CURL_DISABLE_KERBEROS_AUTH, 1, [to disable kerberos authentication])
CURL_DISABLE_KERBEROS_AUTH=1
;;
*) AC_MSG_RESULT(yes)
;;
esac ],
AC_MSG_RESULT(yes)
)

dnl ************************************************************
dnl disable negotiate authentication
dnl
AC_MSG_CHECKING([whether to enable negotiate authentication method])
AC_ARG_ENABLE(negotiate-auth,
AS_HELP_STRING([--enable-negotiate-auth],[Enable negotiate authentication (default)])
AS_HELP_STRING([--disable-negotiate-auth],[Disable negotiate authentication]),
[ case "$enableval" in
no)
AC_MSG_RESULT(no)
AC_DEFINE(CURL_DISABLE_NEGOTIATE_AUTH, 1, [to disable negotiate authentication])
CURL_DISABLE_NEGOTIATE_AUTH=1
;;
*) AC_MSG_RESULT(yes)
;;
esac ],
AC_MSG_RESULT(yes)
)


dnl ************************************************************
dnl disable aws
dnl
AC_MSG_CHECKING([whether to enable aws sig methods])
AC_ARG_ENABLE(aws,
AS_HELP_STRING([--enable-aws],[Enable AWS sig support (default)])
AS_HELP_STRING([--disable-aws],[Disable AWS sig support]),
[ case "$enableval" in
no)
AC_MSG_RESULT(no)
AC_DEFINE(CURL_DISABLE_AWS, 1, [to disable AWS sig support])
CURL_DISABLE_AWS=1
;;
*) AC_MSG_RESULT(yes)
;;
Expand Down Expand Up @@ -4498,20 +4594,19 @@ if test "x$hsts" = "xyes"; then
SUPPORT_FEATURES="$SUPPORT_FEATURES HSTS"
fi

if test "x$CURL_DISABLE_CRYPTO_AUTH" != "x1" -a \
if test "x$CURL_DISABLE_NEGOTIATE_AUTH" != "x1" -a \
\( "x$HAVE_GSSAPI" = "x1" -o "x$USE_WINDOWS_SSPI" = "x1" \); then
SUPPORT_FEATURES="$SUPPORT_FEATURES SPNEGO"
fi

if test "x$CURL_DISABLE_CRYPTO_AUTH" != "x1" -a \
if test "x$CURL_DISABLE_KERBEROS_AUTH" != "x1" -a \
\( "x$HAVE_GSSAPI" = "x1" -o "x$USE_WINDOWS_SSPI" = "x1" \); then
SUPPORT_FEATURES="$SUPPORT_FEATURES Kerberos"
fi

use_curl_ntlm_core=no

if test "x$CURL_DISABLE_CRYPTO_AUTH" != "x1" -a \
"x$CURL_DISABLE_NTLM" != "x1"; then
if test "x$CURL_DISABLE_NTLM" != "x1"; then
if test "x$OPENSSL_ENABLED" = "x1" -o "x$MBEDTLS_ENABLED" = "x1" \
-o "x$GNUTLS_ENABLED" = "x1" \
-o "x$SECURETRANSPORT_ENABLED" = "x1" \
Expand Down
24 changes: 22 additions & 2 deletions docs/CURL-DISABLE.md
Expand Up @@ -12,9 +12,29 @@ Disable support for binding the local end of connections.

Disable support for HTTP cookies.

## `CURL_DISABLE_CRYPTO_AUTH`
## `CURL_DISABLE_BASIC_AUTH`

Disable support for authentication methods using crypto.
Disable support for the Basic authentication methods.

## `CURL_DISABLE_BEARER_AUTH`

Disable support for the Bearer authentication methods.

## `CURL_DISABLE_DIGEST_AUTH`

Disable support for the Digest authentication methods.

## `CURL_DISABLE_KERBEROS_AUTH`

Disable support for the Kerberos authentication methods.

## `CURL_DISABLE_NEGOTIATE_AUTH`

Disable support for the negotiate authentication methods.

## `CURL_DISABLE_AWS`

Disable **AWS-SIG4** support.

## `CURL_DISABLE_DICT`

Expand Down
19 changes: 17 additions & 2 deletions lib/curl_config.h.cmake
Expand Up @@ -41,8 +41,23 @@
/* disables cookies support */
#cmakedefine CURL_DISABLE_COOKIES 1

/* disables cryptographic authentication */
#cmakedefine CURL_DISABLE_CRYPTO_AUTH 1
/* disables Basic authentication */
#cmakedefine CURL_DISABLE_BASIC_AUTH 1

/* disables Bearer authentication */
#cmakedefine CURL_DISABLE_BEARER_AUTH 1

/* disables Digest authentication */
#cmakedefine CURL_DISABLE_DIGEST_AUTH 1

/* disables Kerberos authentication */
#cmakedefine CURL_DISABLE_KERBEROS_AUTH 1

/* disables negotiate authentication */
#cmakedefine CURL_DISABLE_NEGOTIATE_AUTH 1

/* disables AWS-SIG4 */
#cmakedefine CURL_DISABLE_AWS 1

/* disables DICT */
#cmakedefine CURL_DISABLE_DICT 1
Expand Down
3 changes: 2 additions & 1 deletion lib/curl_hmac.h
Expand Up @@ -24,7 +24,8 @@
*
***************************************************************************/

#ifndef CURL_DISABLE_CRYPTO_AUTH
#if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) \
|| !defined(CURL_DISABLE_AWS)

#include <curl/curl.h>

Expand Down
4 changes: 2 additions & 2 deletions lib/curl_md4.h
Expand Up @@ -27,13 +27,13 @@
#include "curl_setup.h"
#include <curl/curl.h>

#if !defined(CURL_DISABLE_CRYPTO_AUTH)
#if defined(USE_CURL_NTLM_CORE)

#define MD4_DIGEST_LENGTH 16

CURLcode Curl_md4it(unsigned char *output, const unsigned char *input,
const size_t len);

#endif /* !defined(CURL_DISABLE_CRYPTO_AUTH) */
#endif /* defined(USE_CURL_NTLM_CORE) */

#endif /* HEADER_CURL_MD4_H */
4 changes: 3 additions & 1 deletion lib/curl_md5.h
Expand Up @@ -24,7 +24,9 @@
*
***************************************************************************/

#ifndef CURL_DISABLE_CRYPTO_AUTH
#if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) \
|| !defined(CURL_DISABLE_DIGEST_AUTH)

#include "curl_hmac.h"

#define MD5_DIGEST_LEN 16
Expand Down
8 changes: 4 additions & 4 deletions lib/curl_sasl.c
Expand Up @@ -420,7 +420,7 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct Curl_easy *data,
}
else
#endif
#ifndef CURL_DISABLE_CRYPTO_AUTH
#ifndef CURL_DISABLE_DIGEST_AUTH
if((enabledmechs & SASL_MECH_DIGEST_MD5) &&
Curl_auth_is_digest_supported()) {
mech = SASL_MECH_STRING_DIGEST_MD5;
Expand Down Expand Up @@ -530,8 +530,8 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct Curl_easy *data,
struct bufref resp;
const char *hostname, *disp_hostname;
int port;
#if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5) || \
defined(USE_NTLM)
#if defined(USE_KERBEROS5) || defined(USE_NTLM) \
|| !defined(CURL_DISABLE_DIGEST_AUTH)
const char *service = data->set.str[STRING_SERVICE_NAME] ?
data->set.str[STRING_SERVICE_NAME] :
sasl->params->service;
Expand Down Expand Up @@ -577,7 +577,6 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct Curl_easy *data,
case SASL_EXTERNAL:
result = Curl_auth_create_external_message(conn->user, &resp);
break;
#ifndef CURL_DISABLE_CRYPTO_AUTH
#ifdef USE_GSASL
case SASL_GSASL:
result = get_server_message(sasl, data, &serverdata);
Expand All @@ -587,6 +586,7 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct Curl_easy *data,
newstate = SASL_GSASL;
break;
#endif
#ifndef CURL_DISABLE_DIGEST_AUTH
case SASL_CRAMMD5:
result = get_server_message(sasl, data, &serverdata);
if(!result)
Expand Down
6 changes: 3 additions & 3 deletions lib/curl_setup.h
Expand Up @@ -652,19 +652,19 @@
#endif

/* Single point where USE_SPNEGO definition might be defined */
#if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
#if !defined(CURL_DISABLE_NEGOTIATE_AUTH) && \
(defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
#define USE_SPNEGO
#endif

/* Single point where USE_KERBEROS5 definition might be defined */
#if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
#if !defined(CURL_DISABLE_KERBEROS_AUTH) && \
(defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
#define USE_KERBEROS5
#endif

/* Single point where USE_NTLM definition might be defined */
#if !defined(CURL_DISABLE_CRYPTO_AUTH) && !defined(CURL_DISABLE_NTLM)
#if !defined(CURL_DISABLE_NTLM)
# if defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
defined(USE_GNUTLS) || defined(USE_SECTRANSP) || \
defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \
Expand Down
4 changes: 3 additions & 1 deletion lib/curl_sha256.h
Expand Up @@ -25,7 +25,9 @@
*
***************************************************************************/

#ifndef CURL_DISABLE_CRYPTO_AUTH
#if !defined(CURL_DISABLE_AWS) || !defined(CURL_DISABLE_DIGEST_AUTH) \
|| defined(USE_LIBSSH2)

#include <curl/curl.h>
#include "curl_hmac.h"

Expand Down
2 changes: 1 addition & 1 deletion lib/easy.c
Expand Up @@ -1064,7 +1064,7 @@ void curl_easy_reset(struct Curl_easy *data)
memset(&data->state.authhost, 0, sizeof(struct auth));
memset(&data->state.authproxy, 0, sizeof(struct auth));

#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH)
Curl_http_auth_cleanup_digest(data);
#endif
}
Expand Down
5 changes: 3 additions & 2 deletions lib/hmac.c
Expand Up @@ -26,7 +26,8 @@

#include "curl_setup.h"

#ifndef CURL_DISABLE_CRYPTO_AUTH
#if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) \
|| !defined(CURL_DISABLE_AWS)

#include <curl/curl.h>

Expand Down Expand Up @@ -169,4 +170,4 @@ CURLcode Curl_hmacit(const struct HMAC_params *hashparams,
return CURLE_OK;
}

#endif /* CURL_DISABLE_CRYPTO_AUTH */
#endif /* Using NTLM (without SSPI) or AWS */

0 comments on commit e92edfb

Please sign in to comment.