To support QUIC payload and header decryption, it is necessary to choose an
external crypto library to handle the low-level crypto stuff. Since we will
use some Wireshark code, it is quite natural to choose the same library used
by Wireshark itself: libgcrypt.
More precisely, we will use libgcrypt and libgpg-error.
Both libraries have LGPL license, so there should be no issue from this point
of view.
These libraries are not required to build nDPI, and their usage is optional:
nDPI will keep working (and compiling) even if they are not available.
However, without them, QUIC sub-classification is next to impossible.
The configure flag "--disable-gcrypt" forces the build system to ignore these
libraries.
libgpg-error is only used for debug to have meaningful error messages and its
usage is trivial.
The same cannot be said for libgcrypt because its initialization is a significant
issue.
The rest of this commit message try explaining how libgcrypt is
initialized.
According to the documentation
https://gnupg.org/documentation/manuals/gcrypt/Initializing-the-library.html
https://gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html#Multi_002dThreading
libgcrypt must be initialized before using it, but such initialization should
be performed by the actual application and not by any library.
Forcing the users to proper initialize libgcrypt in their own code seems
unreasonable: most people using nDPI might be complete unaware of any crypto
stuff and update each and every one application linking to nDPI with specific
libgcrypt code should be out of question, anyway.
Fortunately, it seems a workaround exists to initialize libgcrypt in a library
https://lists.gnupg.org/pipermail/gcrypt-devel/2003-August/000458.html
Therefore, we could provide a wrapper to this initialization stuff in a nDPI
function. Unfortunately nDPI API lacks a global init function that must be
called only once, before any other functions. We could add it, but that would
be a major API break.
AFAIK, ndpi_init_detection_module() might be called multiple times, for example
to create multiple independent dpi engines in the same program.
The proposed solution is to (optionally) initialize libgcrypt in
ndpi_init_detection_module() anyway:
* if the actual application doesn't directly use libgcrypt and only calls
ndpi_init_detection_module() once, everything is formally correct and it
should work out of the box [by far the most common user case];
* if the actual application already uses libgcrypt directly, it already
performs the required initialization. In this case the ndpi_prefs.ndpi_dont_init_libgcrypt
flag should be passed to ndpi_init_detection_module() to avoid further
initializations.
The only scenario not supported by this solution is when the application is
unaware of libgcrypt and calls ndpi_init_detection_module() multiple times
concurrently. But this scenario should be uncommon.
A completely different option should be to switch to another crypto library,
with a huge impact on the QUIC dissector code.
Bottom line: crypto is hard, using libgcrypt is complex and the proposed
initialization, even if not perfect, should cover the most frequent user
cases and should work, for the time being.
If anyone has some suggestions...
207 lines
7.1 KiB
Plaintext
207 lines
7.1 KiB
Plaintext
AC_INIT([libndpi], [@NDPI_VERSION_SHORT@])
|
|
|
|
AC_CONFIG_MACRO_DIR([m4])
|
|
|
|
AM_INIT_AUTOMAKE([foreign subdir-objects])
|
|
|
|
EXTRA_TARGETS="example tests"
|
|
AC_ARG_WITH(only-libndpi, AS_HELP_STRING([--with-only-libndpi], [Build only libndpi (no examples, tests etc)]))
|
|
AS_IF([test "${with_only_libndpi+set}" = set],[
|
|
EXTRA_TARGETS=""
|
|
])
|
|
|
|
|
|
|
|
AC_ARG_WITH(sanitizer, AS_HELP_STRING([--with-sanitizer], [Build with support for address, undefined and leak sanitizer]))
|
|
AC_ARG_ENABLE(fuzztargets, AS_HELP_STRING([--enable-fuzztargets], [Enable fuzz targets]),[enable_fuzztargets=$enableval],[enable_fuzztargets=no])
|
|
AM_CONDITIONAL([BUILD_FUZZTARGETS], [test "x$enable_fuzztargets" = "xyes"])
|
|
|
|
AS_IF([test "${with_sanitizer+set}" = set],[
|
|
CFLAGS="${CFLAGS} -g3 -O0 -Wno-unused-value -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fsanitize=leak -fno-omit-frame-pointer"
|
|
LDFLAGS="${LDFLAGS} -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fsanitize=leak"
|
|
])
|
|
|
|
LT_INIT
|
|
|
|
SYSTEM=`uname -s`
|
|
if test $SYSTEM = "Darwin"; then
|
|
dnl> AC_PROG_CC(clang gcc)
|
|
AM_PROG_CC_C_O(clang gcc)
|
|
AC_PROG_CXX(clang++ g++)
|
|
AC_PROG_CC_STDC(clang gcc)
|
|
else
|
|
dnl> AC_PROG_CC
|
|
AM_PROG_CC_C_O
|
|
AC_PROG_CXX
|
|
AC_PROG_CC_STDC
|
|
fi
|
|
AC_LANG_WERROR
|
|
AX_PTHREAD
|
|
|
|
NDPI_VERSION_SHORT="@NDPI_VERSION_SHORT@"
|
|
NDPI_MAJOR="@NDPI_MAJOR@"
|
|
NDPI_MINOR="@NDPI_MINOR@"
|
|
NDPI_PATCH="@NDPI_PATCH@"
|
|
|
|
AC_DEFINE_UNQUOTED(NDPI_MAJOR_RELEASE, "${NDPI_MAJOR}", [nDPI major release])
|
|
AC_DEFINE_UNQUOTED(NDPI_MINOR_RELEASE, "${NDPI_MINOR}", [nDPI minor release])
|
|
AC_DEFINE_UNQUOTED(NDPI_PATCH_LEVEL, "${NDPI_PATCH}", [nDPI patch level])
|
|
|
|
if test -d ".git"; then :
|
|
GIT_TAG=`git log -1 --format=%h`
|
|
GIT_DATE=`git log -1 --format=%cd`
|
|
#
|
|
# On CentOS 6 `git rev-list HEAD --count` does not work
|
|
#
|
|
#
|
|
GIT_NUM=`git log --pretty=oneline | wc -l | tr -d '[[:space:]]'`
|
|
GIT_RELEASE="${PACKAGE_VERSION}-${GIT_NUM}-${GIT_TAG}"
|
|
|
|
A=`git log src/include/ndpi_typedefs.h|wc -l`
|
|
B=`git log src/include/ndpi_protocol_ids.h|wc -l`
|
|
C=`git log src/include/ndpi_api.h.in|wc -l`
|
|
NDPI_API_VERSION=$((A+B+C))
|
|
else
|
|
GIT_RELEASE="${PACKAGE_VERSION}"
|
|
GIT_DATE=`date -u -r CHANGELOG.md`
|
|
NDPI_API_VERSION=`date +%s | cut -c7-10`
|
|
fi
|
|
|
|
NDPI_API_VERSION=`echo $NDPI_API_VERSION | sed 's/^0*//'`
|
|
|
|
AC_DEFINE_UNQUOTED(NDPI_GIT_RELEASE, "${GIT_RELEASE}", [GIT Release])
|
|
AC_DEFINE_UNQUOTED(NDPI_GIT_DATE, "${GIT_DATE}", [Last GIT change])
|
|
|
|
AC_CHECK_HEADERS([netinet/in.h stdint.h stdlib.h string.h unistd.h])
|
|
|
|
ADDITIONAL_LIBS=
|
|
PCAP_HOME=$HOME/PF_RING/userland
|
|
|
|
DPDK_TARGET=
|
|
AC_MSG_CHECKING([DPDK (used by ndpiReader)])
|
|
if test -d $HOME/DPDK; then :
|
|
AC_MSG_RESULT(yes)
|
|
DPDK_TARGET=dpdk
|
|
else
|
|
AC_MSG_RESULT([no (missing $HOME/DPDK)])
|
|
fi
|
|
|
|
if ! test -d $PCAP_HOME; then :
|
|
PCAP_HOME=`pwd`/../../PF_RING/userland
|
|
fi
|
|
SHORT_MACHINE=`uname -m | cut -b1-3`
|
|
if test $SHORT_MACHINE = "arm"; then
|
|
LIBNUMA=""
|
|
else
|
|
AC_CHECK_LIB([numa], [numa_available], [LIBNUMA="-lnuma"])
|
|
fi
|
|
|
|
MACHINE=`uname -m`
|
|
|
|
CUSTOM_NDPI=
|
|
|
|
if test -d ../nDPI-custom; then :
|
|
CUSTOM_NDPI="-DCUSTOM_NDPI_PROTOCOLS"
|
|
AC_MSG_RESULT([Compiling with custom nDPI protocols])
|
|
fi
|
|
|
|
case "$host" in
|
|
*-*-mingw32*|*-*-msys)
|
|
CFLAGS="${CFLAGS} -DOS_WIN32"
|
|
LDFLAGS="${LDFLAGS} -lws2_32 -lucrtbase"
|
|
;;
|
|
*)
|
|
if test -f $PCAP_HOME/libpcap/libpcap.a; then :
|
|
echo "Using libpcap from $PCAP_HOME"
|
|
PCAP_INC="-I $PCAP_HOME/libpcap"
|
|
PCAP_LIB="$PCAP_HOME/libpcap/libpcap.a $PCAP_HOME/lib/libpfring.a $LIBNUMA `$PCAP_HOME/lib/pfring_config --libs`"
|
|
AC_CHECK_LIB([rt], [clock_gettime], [PCAP_LIB="$PCAP_LIB -lrt"])
|
|
AC_CHECK_LIB([nl], [nl_handle_alloc], [PCAP_LIB="$PCAP_LIB -lnl"])
|
|
# The dlopen() function is in libdl on GLIBC-based systems
|
|
# and in the C library for *BSD systems
|
|
AC_CHECK_LIB([dl], [dlopen, dlsym], [DL_LIB="-ldl"],[AC_CHECK_LIB([c], [dlopen, dlsym], [DL_LIB="-lc"],[AC_MSG_ERROR([unable to find the dlopen(), dlsym() functions]) ]) ])
|
|
else
|
|
AC_CHECK_LIB([pcap], [pcap_open_live], [PCAP_LIB="-lpcap"])
|
|
if test $ac_cv_lib_pcap_pcap_open_live = "no"; then :
|
|
echo ""
|
|
echo "ERROR: Missing libpcap(-dev) library required to compile the example application"
|
|
echo "ERROR: Please install it and try again"
|
|
exit
|
|
fi
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
AC_ARG_ENABLE([debug-messages],
|
|
AS_HELP_STRING([--enable-debug-messages], [Define NDPI_ENABLE_DEBUG_MESSAGES=1]), [
|
|
AC_DEFINE(NDPI_ENABLE_DEBUG_MESSAGES, 1, [Enable ndpi_debug_messages]) ])
|
|
|
|
@FUZZY@ AS_IF([test "x$enable_fuzztargets" = "xyes"], [
|
|
@FUZZY@ AC_PROG_CXX
|
|
@FUZZY@ AC_LANG_PUSH(C++)
|
|
@FUZZY@ tmp_saved_flags=$[]_AC_LANG_PREFIX[]FLAGS
|
|
@FUZZY@ AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer],,
|
|
@FUZZY@ [AC_MSG_ERROR([--enable-fuzztargets requires -fsanitize=fuzzer which is only supported by LLVM])],
|
|
@FUZZY@ [-Werror])
|
|
@FUZZY@ AS_IF([test "x$LIB_FUZZING_ENGINE" = "x"], [
|
|
@FUZZY@ LIB_FUZZING_ENGINE=-fsanitize=fuzzer
|
|
@FUZZY@ AC_SUBST(LIB_FUZZING_ENGINE)
|
|
@FUZZY@ ])
|
|
@FUZZY@ _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $LIB_FUZZING_ENGINE"
|
|
@FUZZY@ AC_MSG_CHECKING([whether $CXX accepts $LIB_FUZZING_ENGINE])
|
|
@FUZZY@ AC_LINK_IFELSE([AC_LANG_SOURCE([[
|
|
@FUZZY@ #include <sys/types.h>
|
|
@FUZZY@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size);
|
|
@FUZZY@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size) {
|
|
@FUZZY@ (void)Data;
|
|
@FUZZY@ (void)Size;
|
|
@FUZZY@ return 0;
|
|
@FUZZY@ }
|
|
@FUZZY@ ]])],
|
|
@FUZZY@ [ AC_MSG_RESULT(yes)
|
|
@FUZZY@ has_sanitizefuzzer=yes],
|
|
@FUZZY@ [ AC_MSG_RESULT(no) ]
|
|
@FUZZY@ )
|
|
@FUZZY@ _AC_LANG_PREFIX[]FLAGS=$tmp_saved_flags
|
|
@FUZZY@ AC_LANG_POP()
|
|
@FUZZY@ ])
|
|
AM_CONDITIONAL([HAS_FUZZLDFLAGS], [test "x$has_sanitizefuzzer" = "xyes"])
|
|
|
|
AC_CHECK_LIB(pthread, pthread_setaffinity_np, AC_DEFINE_UNQUOTED(HAVE_PTHREAD_SETAFFINITY_NP, 1, [libc has pthread_setaffinity_np]))
|
|
|
|
AC_ARG_ENABLE([gcrypt],
|
|
[AS_HELP_STRING([--disable-gcrypt], [Avoid compiling with libgcrypt/libgpg-error, even if they are present. QUIC sub-classification may be missing])],
|
|
[:],
|
|
[AC_CHECK_LIB(gcrypt, gcry_cipher_checktag)
|
|
AC_CHECK_LIB(gpg-error, gpg_strerror_r)])
|
|
|
|
dnl> PCRE
|
|
AC_ARG_WITH(pcre, [ --with-pcre Enable nDPI build with libpcre])
|
|
if test "${with_pcre+set}" = set; then :
|
|
AC_CHECK_LIB(pcre, pcre_compile, AC_DEFINE_UNQUOTED(HAVE_PCRE, 1, [libpcre(-dev) is present]))
|
|
if test "x$ac_cv_lib_pcre_pcre_compile" = xyes; then :
|
|
ADDITIONAL_LIBS=-lpcre
|
|
fi
|
|
fi
|
|
|
|
|
|
AC_CONFIG_FILES([Makefile example/Makefile example/Makefile.dpdk tests/Makefile libndpi.pc src/include/ndpi_define.h src/lib/Makefile python/Makefile fuzz/Makefile src/include/ndpi_api.h])
|
|
AC_CONFIG_HEADERS(src/include/ndpi_config.h)
|
|
AC_SUBST(GIT_RELEASE)
|
|
AC_SUBST(NDPI_MAJOR)
|
|
AC_SUBST(NDPI_MINOR)
|
|
AC_SUBST(NDPI_PATCH)
|
|
AC_SUBST(NDPI_VERSION_SHORT)
|
|
AC_SUBST(SVN_DATE)
|
|
AC_SUBST(JSON_C_LIB)
|
|
AC_SUBST(PCAP_INC)
|
|
AC_SUBST(PCAP_LIB)
|
|
AC_SUBST(ADDITIONAL_LIBS)
|
|
AC_SUBST(DL_LIB)
|
|
AC_SUBST(DPDK_TARGET)
|
|
AC_SUBST(HAVE_PTHREAD_SETAFFINITY_NP)
|
|
AC_SUBST(CUSTOM_NDPI)
|
|
AC_SUBST(NDPI_API_VERSION)
|
|
AC_SUBST(EXTRA_TARGETS)
|
|
AC_OUTPUT
|