Skip to content

Commit

Permalink
config: fix building SMB with configure using Win32 Crypto
Browse files Browse the repository at this point in the history
Align conditions for NTLM features between CMake and configure
builds by differentiating between USE_NTLM and USE_CURL_NTLM_CORE,
just like curl_setup.h does internally to detect support of:

- USE_NTLM: required for NTLM crypto authentication feature
- USE_CURL_NTLM_CORE: required for SMB protocol

Simulate USE_WIN32_CRYPTO detection by checking for CryptCreateHash
in wincrypt.h which is not available in Windows App environment.

Consolidate additions of crypt32 to linked libraries.
Fix condition of Schannel SSL backend in CMake build.

Closes curl#6277
  • Loading branch information
mback2k committed Mar 1, 2021
1 parent 8d152d0 commit 4d056da
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 33 deletions.
40 changes: 23 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ if(CMAKE_USE_SCHANNEL)
set(SSL_ENABLED ON)
set(USE_SCHANNEL ON) # Windows native SSL/TLS support
set(USE_WINDOWS_SSPI ON) # CMAKE_USE_SCHANNEL implies CURL_WINDOWS_SSPI
list(APPEND CURL_LIBS "crypt32")
endif()
if(CURL_WINDOWS_SSPI)
set(USE_WINDOWS_SSPI ON)
Expand Down Expand Up @@ -505,10 +504,6 @@ if(USE_QUICHE)
cmake_pop_check_state()
endif()

if(WIN32)
set(USE_WIN32_CRYPTO ON)
endif()

if(NOT CURL_DISABLE_LDAP)
if(WIN32)
option(USE_WIN32_LDAP "Use Windows LDAP implementation" ON)
Expand Down Expand Up @@ -874,9 +869,7 @@ if(NOT UNIX)
check_include_file_concat("winsock.h" HAVE_WINSOCK_H)
check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H)
check_include_file_concat("winsock2.h" HAVE_WINSOCK2_H)
if(NOT CURL_WINDOWS_SSPI AND USE_OPENSSL)
set(CURL_LIBS ${CURL_LIBS} "crypt32")
endif()
check_include_file_concat("wincrypt.h" HAVE_WINCRYPT_H)
endif()

check_include_file_concat("stdio.h" HAVE_STDIO_H)
Expand Down Expand Up @@ -1333,12 +1326,22 @@ if(BUILD_TESTING)
add_subdirectory(tests)
endif()

# simulate USE_WIN32_CRYPTO via HAVE_WINCRYPT_H and HAVE_CRYPTCREATEHASH
# TODO align condition with curl_setup.h regarding Windows App environment
if(WIN32 AND HAVE_WINCRYPT_H)
check_function_exists(CryptCreateHash USE_WIN32_CRYPTO)
endif()

# add crypt32 to linked libraries if USE_WIN32_CRYPTO or USE_SCHANNEL is set
if(USE_WIN32_CRYPTO OR USE_SCHANNEL)
set(CURL_LIBS ${CURL_LIBS} "crypt32")
endif()

# 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 AND (USE_OPENSSL OR USE_DARWINSSL OR USE_MBEDTLS OR USE_WIN32_CRYPTO))
set(use_ntlm ON)
else()
set(use_ntlm OFF)
if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_MBEDTLS OR
USE_DARWINSSL OR USE_WIN32_CRYPTO))
set(use_curl_ntlm_core ON)
endif()

# Helper to populate a list (_items) with a label when conditions (the remaining
Expand Down Expand Up @@ -1373,9 +1376,10 @@ _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_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" use_ntlm OR USE_WINDOWS_SSPI)
_add_if("NTLM" (use_curl_ntlm_core OR USE_WINDOWS_SSPI))
# TODO missing option (autoconf: --enable-ntlm-wb)
_add_if("NTLM_WB" use_ntlm AND NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
_add_if("NTLM_WB" (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
_add_if("TLS-SRP" USE_TLS_SRP)
# TODO option --with-nghttp2 tests for nghttp2 lib and nghttp2/nghttp2.h header
Expand Down Expand Up @@ -1409,8 +1413,10 @@ _add_if("POP3" NOT CURL_DISABLE_POP3)
_add_if("POP3S" NOT CURL_DISABLE_POP3 AND SSL_ENABLED)
_add_if("IMAP" NOT CURL_DISABLE_IMAP)
_add_if("IMAPS" NOT CURL_DISABLE_IMAP AND SSL_ENABLED)
_add_if("SMB" NOT CURL_DISABLE_SMB AND use_ntlm)
_add_if("SMBS" NOT CURL_DISABLE_SMB AND SSL_ENABLED AND use_ntlm)
_add_if("SMB" NOT CURL_DISABLE_SMB AND
use_curl_ntlm_core AND (CURL_SIZEOF_CURL_OFF_T GREATER 4))
_add_if("SMBS" NOT CURL_DISABLE_SMB AND SSL_ENABLED AND
use_curl_ntlm_core AND (CURL_SIZEOF_CURL_OFF_T GREATER 4))
_add_if("SMTP" NOT CURL_DISABLE_SMTP)
_add_if("SMTPS" NOT CURL_DISABLE_SMTP AND SSL_ENABLED)
_add_if("SCP" USE_LIBSSH2 OR USE_LIBSSH)
Expand All @@ -1426,7 +1432,7 @@ message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")

# Clear list and collect SSL backends
set(_items)
_add_if("Schannel" SSL_ENABLED AND USE_WINDOWS_SSPI)
_add_if("Schannel" SSL_ENABLED AND USE_SCHANNEL)
_add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
_add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
_add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
Expand Down
33 changes: 33 additions & 0 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,39 @@ AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
])


dnl CURL_CHECK_HEADER_WINCRYPT
dnl -------------------------------------------------
dnl Check for compilable and valid wincrypt.h header

AC_DEFUN([CURL_CHECK_HEADER_WINCRYPT], [
AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
AC_CACHE_CHECK([for wincrypt.h], [curl_cv_header_wincrypt_h], [
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
#undef inline
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <wincrypt.h>
]],[[
int dummy=2*PROV_RSA_FULL;
]])
],[
curl_cv_header_wincrypt_h="yes"
],[
curl_cv_header_wincrypt_h="no"
])
])
case "$curl_cv_header_wincrypt_h" in
yes)
AC_DEFINE_UNQUOTED(HAVE_WINCRYPT_H, 1,
[Define to 1 if you have the wincrypt.h header file.])
;;
esac
])


dnl CURL_CHECK_HEADER_WINLDAP
dnl -------------------------------------------------
dnl Check for compilable and valid winldap.h header
Expand Down
46 changes: 30 additions & 16 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,15 @@ case X-"$curl_cv_native_windows" in
CURL_CHECK_HEADER_WINSOCK
CURL_CHECK_HEADER_WINSOCK2
CURL_CHECK_HEADER_WS2TCPIP
CURL_CHECK_HEADER_WINCRYPT
CURL_CHECK_HEADER_WINLDAP
CURL_CHECK_HEADER_WINBER
;;
*)
curl_cv_header_winsock_h="no"
curl_cv_header_winsock2_h="no"
curl_cv_header_ws2tcpip_h="no"
curl_cv_header_wincrypt_h="no"
curl_cv_header_winldap_h="no"
curl_cv_header_winber_h="no"
;;
Expand Down Expand Up @@ -1648,7 +1650,6 @@ if test -z "$ssl_backends" -o "x$OPT_SCHANNEL" != xno; then
AC_DEFINE(USE_WINDOWS_SSPI, 1, [to enable SSPI support])
AC_SUBST(USE_WINDOWS_SSPI, [1])
curl_sspi_msg="enabled"
LIBS="-lcrypt32 $LIBS"
else
AC_MSG_RESULT(no)
fi
Expand All @@ -1657,6 +1658,17 @@ else
AC_MSG_RESULT(no)
fi

dnl simulate USE_WIN32_CRYPTO via HAVE_WINCRYPT_H and HAVE_CRYPTCREATEHASH
dnl TODO align condition with curl_setup.h regarding Windows App environment
if test "x$curl_cv_header_wincrypt_h" = "xyes"; then
AC_CHECK_FUNCS([CryptCreateHash], [USE_WIN32_CRYPTO=1])
fi

dnl add crypt32 to linked libraries if USE_WIN32_CRYPTO or USE_SCHANNEL is set
if test "x$USE_WIN32_CRYPTO" = "x1" -o "x$USE_SCHANNEL" = "x1"; then
LIBS="-lcrypt32 $LIBS"
fi

OPT_SECURETRANSPORT=no
AC_ARG_WITH(darwinssl,dnl
AC_HELP_STRING([--with-darwinssl],[enable Apple OS native SSL/TLS])
Expand Down Expand Up @@ -5220,17 +5232,23 @@ if test "x$CURL_DISABLE_CRYPTO_AUTH" != "x1" -a \
SUPPORT_FEATURES="$SUPPORT_FEATURES Kerberos"
fi

if test "x$CURL_DISABLE_CRYPTO_AUTH" != "x1"; then
if test "x$OPENSSL_ENABLED" = "x1" -o "x$USE_WINDOWS_SSPI" = "x1" \
-o "x$GNUTLS_ENABLED" = "x1" -o "x$MBEDTLS_ENABLED" = "x1" \
-o "x$NSS_ENABLED" = "x1" -o "x$SECURETRANSPORT_ENABLED" = "x1" \
-o "x$WOLFSSL_NTLM" = "x1"; then
SUPPORT_FEATURES="$SUPPORT_FEATURES NTLM"
if test "x$CURL_DISABLE_CRYPTO_AUTH" != "x1" -a \
\( "x$OPENSSL_ENABLED" = "x1" -o "x$MBEDTLS_ENABLED" = "x1" \
-o "x$GNUTLS_ENABLED" = "x1" -o "x$NSS_ENABLED" = "x1" \
-o "x$SECURETRANSPORT_ENABLED" = "x1" \
-o "x$USE_WIN32_CRYPTO" = "x1" \
-o "x$WOLFSSL_NTLM" = "x1" \); then
use_curl_ntlm_core=yes
else
use_curl_ntlm_core=no
fi
if test "x$use_curl_ntlm_core" = "xyes" \
-o "x$USE_WINDOWS_SSPI" = "x1"; then
SUPPORT_FEATURES="$SUPPORT_FEATURES NTLM"

if test "x$CURL_DISABLE_HTTP" != "x1" -a \
"x$NTLM_WB_ENABLED" = "x1"; then
SUPPORT_FEATURES="$SUPPORT_FEATURES NTLM_WB"
fi
if test "x$CURL_DISABLE_HTTP" != "x1" -a \
"x$NTLM_WB_ENABLED" = "x1"; then
SUPPORT_FEATURES="$SUPPORT_FEATURES NTLM_WB"
fi
fi

Expand Down Expand Up @@ -5324,11 +5342,7 @@ if test "x$CURL_DISABLE_IMAP" != "x1"; then
fi
fi
if test "x$CURL_DISABLE_SMB" != "x1" \
-a "x$CURL_DISABLE_CRYPTO_AUTH" != "x1" \
-a \( "x$OPENSSL_ENABLED" = "x1" \
-o "x$GNUTLS_ENABLED" = "x1" -o "x$MBEDTLS_ENABLED" = "x1" \
-o "x$NSS_ENABLED" = "x1" -o "x$SECURETRANSPORT_ENABLED" = "x1" \
-o "x$WOLFSSL_NTLM" = "x1" \); then
-a "x$use_curl_ntlm_core" = "xyes"; then
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS SMB"
if test "x$SSL_ENABLED" = "x1"; then
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS SMBS"
Expand Down

0 comments on commit 4d056da

Please sign in to comment.