mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-31 00:03:08 +03:00
build: make HAVE_LIBCRYPT32
local to wincng.c
libssh2 uses `wincrypt.h` aka the `crypt32` Windows system library for the function `CryptDecodeObjectEx()` [1]. This function has been available for Win32 (and UWP/WinRT apps) for a long while. Even old MinGW supports it, and also Watcom 1.9, of the rare/old compilers I checked. CMake had it permanently enabled, while it also did an extra check for the header to add the lib to the lib list. Autotools did the detection proper. Other builds had it permanently enabled. It seems safe to assume this function/header/lib is available in all environments we support. In this patch we simplify by deleting these detections and feature flags from all build tools. Keep the feature flag internal to `wincng.h`, and for extra safety add the new macro `LIBSSH2_WINCNG_DISABLE_WINCRYPT` do disable it via custom `CPPFLAGS`. WinCNG's other requirement is `bcrypt`. That also has been universally available for a long time. Here the only known outlier is old/legacy MinGW, which is missing support. [1] https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptdecodeobjectex Closes #916
This commit is contained in:
@ -338,18 +338,8 @@ if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
|
||||
set(CRYPTO_BACKEND_DEFINE "LIBSSH2_WINCNG")
|
||||
set(CRYPTO_BACKEND_INCLUDE_DIR "")
|
||||
|
||||
set(HAVE_LIBCRYPT32 TRUE)
|
||||
list(APPEND LIBRARIES bcrypt)
|
||||
list(APPEND PC_LIBS -lbcrypt)
|
||||
|
||||
# Reading keys from files is optional and depends on Wincrypt
|
||||
check_include_files("windows.h;wincrypt.h" HAVE_WINCRYPT_H)
|
||||
|
||||
if(HAVE_WINCRYPT_H)
|
||||
list(APPEND LIBRARIES crypt32)
|
||||
list(APPEND PC_LIBS -lcrypt32)
|
||||
endif()
|
||||
|
||||
list(APPEND LIBRARIES crypt32 bcrypt)
|
||||
list(APPEND PC_LIBS -lcrypt32 -lbcrypt)
|
||||
elseif(${SPECIFIC_CRYPTO_REQUIREMENT} STREQUAL ${REQUIRED})
|
||||
message(FATAL_ERROR "WinCNG not available")
|
||||
endif()
|
||||
|
@ -1,3 +1,3 @@
|
||||
CRYPTO_CSOURCES = wincng.c
|
||||
CRYPTO_HHEADERS = wincng.h
|
||||
CRYPTO_LTLIBS = $(LTLIBBCRYPT) $(LTLIBCRYPT32)
|
||||
CRYPTO_LTLIBS = $(LTLIBBCRYPT)
|
||||
|
@ -449,10 +449,8 @@ m4_case([$1],
|
||||
[wincng], [
|
||||
# Look for Windows Cryptography API: Next Generation
|
||||
|
||||
LIBSSH2_LIB_HAVE_LINKFLAGS([crypt32], [], [
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
])
|
||||
LIBS="$LIBS -lcrypt32"
|
||||
|
||||
LIBSSH2_LIB_HAVE_LINKFLAGS([bcrypt], [], [
|
||||
#include <windows.h>
|
||||
#include <bcrypt.h>
|
||||
@ -504,4 +502,3 @@ AC_HELP_STRING([--disable-werror],[Disable compiler warnings as errors]),
|
||||
CFLAGS="$CFLAGS -Werror"
|
||||
fi
|
||||
])
|
||||
|
||||
|
@ -77,9 +77,6 @@
|
||||
/* use Ioctlsocket() for non-blocking sockets */
|
||||
#undef HAVE_IOCTLSOCKET_CASE
|
||||
|
||||
/* Define if you have the crypt32 library. */
|
||||
#undef HAVE_LIBCRYPT32
|
||||
|
||||
/* Define if you have the gcrypt library. */
|
||||
#undef HAVE_LIBGCRYPT
|
||||
|
||||
|
@ -50,9 +50,6 @@
|
||||
#cmakedefine HAVE_ARPA_INET_H
|
||||
#cmakedefine HAVE_NETINET_IN_H
|
||||
|
||||
/* Libraries */
|
||||
#cmakedefine HAVE_LIBCRYPT32
|
||||
|
||||
/* Types */
|
||||
#cmakedefine HAVE_LONGLONG
|
||||
|
||||
|
@ -48,6 +48,10 @@
|
||||
#define _WIN32_WINNT 0x0600
|
||||
#endif
|
||||
|
||||
#if !defined(LIBSSH2_WINCNG_DISABLE_WINCRYPT) && !defined(HAVE_LIBCRYPT32)
|
||||
#define HAVE_LIBCRYPT32
|
||||
#endif
|
||||
|
||||
/* specify the required libraries for dependencies using MSVC */
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "bcrypt.lib")
|
||||
@ -63,7 +67,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_LIBCRYPT32
|
||||
#include <wincrypt.h>
|
||||
#include <wincrypt.h> /* for CryptDecodeObjectEx() */
|
||||
#endif
|
||||
|
||||
#define PEM_RSA_HEADER "-----BEGIN RSA PRIVATE KEY-----"
|
||||
|
@ -9,7 +9,6 @@
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
|
||||
#define HAVE_LIBCRYPT32
|
||||
#define HAVE_IOCTLSOCKET
|
||||
#define HAVE_SELECT
|
||||
#define HAVE_SNPRINTF
|
||||
|
Reference in New Issue
Block a user