From b816f1fbda7a0fe1eb03c985d96b67cab8f4a50c Mon Sep 17 00:00:00 2001 From: Matthew Albrecht Date: Wed, 8 Jan 2020 15:57:57 -0600 Subject: [PATCH] Allow custom OpenSSL lib, only include openssl/x509v3.h when used. (#143) * Allow custom OpenSSL lib, only include openssl/x509v3.h when used. Using fnmatch on Unix systems, PathMatchSpecA is the best WINAPI equivalent. * Moved shlwapi into WIN32 block. --- CMakeLists.txt | 6 ++++-- ixwebsocket/IXSocketFactory.cpp | 4 ++-- ixwebsocket/IXSocketOpenSSL.cpp | 10 ++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03842f91..e6819ff1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,7 +158,7 @@ if (APPLE AND USE_TLS AND NOT USE_MBED_TLS AND NOT USE_OPEN_SSL) endif() if (WIN32) - target_link_libraries(ixwebsocket wsock32 ws2_32) + target_link_libraries(ixwebsocket wsock32 ws2_32 shlwapi) add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() @@ -175,7 +175,9 @@ if (USE_TLS AND USE_OPEN_SSL) set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /usr/local/opt/openssl/include) endif() - find_package(OpenSSL REQUIRED) + if(NOT OPENSSL_FOUND) + find_package(OpenSSL REQUIRED) + endif() add_definitions(${OPENSSL_DEFINITIONS}) message(STATUS "OpenSSL: " ${OPENSSL_VERSION}) include_directories(${OPENSSL_INCLUDE_DIR}) diff --git a/ixwebsocket/IXSocketFactory.cpp b/ixwebsocket/IXSocketFactory.cpp index f8e1625c..2ca505f5 100644 --- a/ixwebsocket/IXSocketFactory.cpp +++ b/ixwebsocket/IXSocketFactory.cpp @@ -10,12 +10,12 @@ #ifdef IXWEBSOCKET_USE_MBED_TLS #include "IXSocketMbedTLS.h" -#elif defined(_WIN32) -#include "IXSocketSChannel.h" #elif defined(IXWEBSOCKET_USE_OPEN_SSL) #include "IXSocketOpenSSL.h" #elif __APPLE__ #include "IXSocketAppleSSL.h" +#elif defined(_WIN32) +#include "IXSocketSChannel.h" #endif #else diff --git a/ixwebsocket/IXSocketOpenSSL.cpp b/ixwebsocket/IXSocketOpenSSL.cpp index 57f3d304..260324a9 100644 --- a/ixwebsocket/IXSocketOpenSSL.cpp +++ b/ixwebsocket/IXSocketOpenSSL.cpp @@ -11,8 +11,14 @@ #include "IXSocketConnect.h" #include #include +#ifdef _WIN32 +#include +#else #include +#endif +#if OPENSSL_VERSION_NUMBER < 0x10100000L #include +#endif #define socketerrno errno namespace ix @@ -136,7 +142,11 @@ namespace ix */ bool SocketOpenSSL::checkHost(const std::string& host, const char* pattern) { +#ifdef _WIN32 + return PathMatchSpecA(host.c_str(), pattern); +#else return fnmatch(pattern, host.c_str(), 0) != FNM_NOMATCH; +#endif } bool SocketOpenSSL::openSSLCheckServerCert(SSL* ssl,