]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add libcrypto checks.
authorGuy Harris <[email protected]>
Tue, 23 Jan 2018 01:20:02 +0000 (17:20 -0800)
committerGuy Harris <[email protected]>
Tue, 23 Jan 2018 01:20:02 +0000 (17:20 -0800)
Put the optional libraries after libpcap, which is *not* optional.

CMakeLists.txt
Makefile.in
cmake/Modules/FindCRYPTO.cmake [new file with mode: 0644]

index 1771cd5c8e85464a937dc81e1f0acbddb4882974..51a633447fa8ec5c3b3b74bf1666728292f8b0cf 100644 (file)
@@ -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
index baa2c240e7bff7615ba901ca004e7b671830d792..311bba6d666aa0149866df78346a99b7ac766f1c 100644 (file)
@@ -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 (file)
index 0000000..c60389e
--- /dev/null
@@ -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
+)