From: Guy Harris Date: Tue, 23 Jan 2018 01:20:02 +0000 (-0800) Subject: Add libcrypto checks. X-Git-Tag: tcpdump-4.99-bp~1401 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/54587515efd5e2584b0a343eb4e312dd56d70579 Add libcrypto checks. Put the optional libraries after libpcap, which is *not* optional. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 1771cd5c..51a63344 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ set(LIBRARY_NAME netdissect) ################################################################### option(WITH_SMI "Build with libsmi, if available" ON) +option(WITH_CRYPTO "Build with OpenSSL/libressl libcrypto, if available" ON) option(ENABLE_SMB "Build with the SMB dissector" ON) # @@ -333,16 +334,6 @@ check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_SOCKADDR_SA_L # External dependencies ###################################### -# -# libsmi. -# -if(WITH_SMI) - find_package(SMI) - if(SMI_FOUND) - set(USE_LIBSMI ON) - endif(SMI_FOUND) -endif(WITH_SMI) - # # libpcap/WinPcap. # First find it, then check for functions in it. @@ -462,6 +453,55 @@ check_function_exists(bpf_dump HAVE_BPF_DUMP) cmake_pop_check_state() +# +# libsmi. +# +if(WITH_SMI) + find_package(SMI) + if(SMI_FOUND) + set(USE_LIBSMI ON) + endif(SMI_FOUND) +endif(WITH_SMI) + +# +# OpenSSL/libressl libcrypto. +# +if(WITH_CRYPTO) + find_package(CRYPTO) + if(CRYPTO_FOUND) + # + # Check for some functions. + # + cmake_push_check_state() + set(CMAKE_REQUIRED_LIBRARIES crypto) + + # + # 1) do we have EVP_CIPHER_CTX_new? + # If so, we use it to allocate an EVP_CIPHER_CTX, as + # EVP_CIPHER_CTX may be opaque; otherwise, we allocate + # it ourselves. + # + check_function_exists(EVP_CIPHER_CTX_new HAVE_EVP_CIPHER_CTX_NEW) + + # + # 2) do we have EVP_CipherInit_ex()? + # If so, we use it, because we need to be able to make two + # "initialize the cipher" calls, one with the cipher and key, + # and one with the IV, and, as of OpenSSL 1.1, You Can't Do That + # with EVP_CipherInit(), because a call to EVP_CipherInit() will + # unconditionally clear the context, and if you don't supply a + # cipher, it'll clear the cipher, rendering the context unusable + # and causing a crash. + # + check_function_exists(EVP_CipherInit_ex HAVE_EVP_CIPHERINIT_EX) + + # + # We have libcrypto. + # + set(HAVE_LIBCRYPTO ON) + endif(CRYPTO_FOUND) +endif(WITH_CRYPTO) + ###################################### # Input files ###################################### @@ -690,7 +730,11 @@ source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H}) ###################################### add_executable(tcpdump ${TCPDUMP_SOURCE_LIST_C}) -target_link_libraries(tcpdump netdissect ${PCAP_LIBRARY} ${SMI_LIBRARY}) +target_link_libraries(tcpdump netdissect + ${PCAP_LIBRARY} + ${CRYPTO_LIBRARY} + ${SMI_LIBRARY} +) ###################################### # Write out the config.h file diff --git a/Makefile.in b/Makefile.in index baa2c240..311bba6d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -332,6 +332,7 @@ EXTRA_DIST = \ bpf_dump.c \ cmake_uninstall.cmake.in \ cmakeconfig.h.in \ + cmake/Modules/FindCRYPTO.cmake \ cmake/Modules/FindPCAP.cmake \ cmake/Modules/FindSMI.cmake \ config.guess \ diff --git a/cmake/Modules/FindCRYPTO.cmake b/cmake/Modules/FindCRYPTO.cmake new file mode 100644 index 00000000..c60389ec --- /dev/null +++ b/cmake/Modules/FindCRYPTO.cmake @@ -0,0 +1,21 @@ +# +# Try to find libcrypto. +# + +# Try to find the header +find_path(CRYPTO_INCLUDE_DIR openssl/crypto.h) + +# Try to find the library +find_library(CRYPTO_LIBRARY crypto) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CRYPTO + DEFAULT_MSG + CRYPTO_INCLUDE_DIR + CRYPTO_LIBRARY +) + +mark_as_advanced( + CRYPTO_INCLUDE_DIR + CRYPTO_LIBRARY +)