44 changes: 12 additions & 32 deletions .ci/travis-build-and-run-tests.sh
Expand Up @@ -72,8 +72,20 @@ if [[ "$CC" == clang* ]]; then
else #GCC
export ENABLE_COVERAGE=true
echo "Exported ENABLE_COVERAGE=true"
config_flags="--disable-hardening --enable-code-coverage"
fi

# Travis is using some EGLIBC version of libc
# which appears to have some atexit() handling
# issues when dlclose is used. Just disable it
# for gcc builds, as clang DOES NOT run the
# the system tests.
# I cannot reproduce this on:
# OS: Ubuntu 16.04.3 LTS
# C: ldd (Ubuntu GLIBC 2.23-0ubuntu10) 2.23
config_flags="--disable-dlclose $config_flags"
echo "Enabling configure flag --disable-dlclose"

# Bootstrap in the tpm2.0-tss tools directory
./bootstrap

Expand All @@ -91,42 +103,10 @@ fi
mkdir ./build
pushd ./build

# Test building without tcti tabrmd
../configure --enable-unit --without-tcti-tabrmd $config_flags

make -j$(nproc)
make -j$(nproc) check
make -j$(nproc) clean

# Test building without tcti socket
../configure --enable-unit --without-tcti-socket $config_flags
make -j$(nproc)
make -j$(nproc) check
make -j$(nproc) clean

# Test building wihtout tcti device
../configure --enable-unit --without-tcti-device $config_flags
make -j$(nproc)
make -j$(nproc) check
make -j$(nproc) clean

# Build all device TCTIs
../configure --enable-unit $config_flags
make -j$(nproc)
make -j$(nproc) check

if [ "$ENABLE_COVERAGE" == "true" ]; then
# clean before build with coverage
make clean

# Build all device TCTIs with gcov
../configure --disable-hardening --enable-code-coverage
make -j$(nproc)
make -j$(nproc) check
fi
# no clean here, keep artifacts for system testing

# Move out of build back to the tpm2-tools directory
popd

# Switch over to the test directory
Expand Down
35 changes: 8 additions & 27 deletions Makefile.am
Expand Up @@ -33,18 +33,17 @@

ACLOCAL_AMFLAGS = -I m4

INCLUDE_DIRS = -I$(top_srcdir)/tools -I$(top_srcdir)/lib -I$(top_srcdir)/lib/tcti
INCLUDE_DIRS = -I$(top_srcdir)/tools -I$(top_srcdir)/lib
LIB_COMMON := lib/libcommon.a

AM_CFLAGS := \
$(INCLUDE_DIRS) $(EXTRA_CFLAGS) $(SAPI_CFLAGS) $(TCTI_SOCK_CFLAGS) \
$(TCTI_TABRMD_CFLAGS) $(TCTI_DEV_CFLAGS) $(CRYPTO_CFLAGS) $(CODE_COVERAGE_CFLAGS)
$(INCLUDE_DIRS) $(EXTRA_CFLAGS) $(SAPI_CFLAGS) $(CRYPTO_CFLAGS) \
$(CODE_COVERAGE_CFLAGS)

AM_LDFLAGS := $(EXTRA_LDFLAGS) $(CODE_COVERAGE_LIBS)

LDADD = \
$(LIB_COMMON) $(SAPI_LIBS) $(TCTI_SOCK_LIBS) $(TCTI_TABRMD_LIBS) \
$(TCTI_DEV_LIBS) $(CRYPTO_LIBS)
$(LIB_COMMON) $(SAPI_LIBS) $(CRYPTO_LIBS) -ldl

# keep me sorted
bin_PROGRAMS = \
Expand Down Expand Up @@ -96,27 +95,8 @@ bin_PROGRAMS = \
tools/tpm2_unseal \
tools/tpm2_verifysignature

tcti_src =
if HAVE_TCTI_DEV
tcti_src += \
lib/tcti/tpm2_tools_tcti_device.c \
lib/tcti/tpm2_tools_tcti_device.h
endif
if HAVE_TCTI_SOCK
tcti_src += \
lib/tcti/tpm2_tools_tcti_socket.c \
lib/tcti/tpm2_tools_tcti_socket.h
endif
if HAVE_TCTI_TABRMD
tcti_src += \
lib/tcti/tpm2_tools_tcti_abrmd.c \
lib/tcti/tpm2_tools_tcti_abrmd.h
endif


noinst_LIBRARIES = $(LIB_COMMON)
lib_libcommon_a_SOURCES = \
$(tcti_src) \
lib/conversion.c \
lib/conversion.h \
lib/files.c \
Expand Down Expand Up @@ -152,7 +132,9 @@ lib_libcommon_a_SOURCES = \
lib/tpm2_options.c \
lib/tpm2_options.h \
lib/tpm2_session.c \
lib/tpm2_session.h
lib/tpm2_session.h \
lib/tpm2_tcti_ldr.c \
lib/tpm2_tcti_ldr.h

TOOL_SRC := tools/tpm2_tool.c tools/tpm2_tool.h

Expand Down Expand Up @@ -236,8 +218,7 @@ test_unit_test_string_bytes_LDADD = $(CMOCKA_LIBS) $(LIB_COMMON)
test_unit_test_string_bytes_SOURCES = test/unit/test_string_bytes.c

test_unit_test_files_CFLAGS = $(AM_CFLAGS) $(CMOCKA_CFLAGS)
test_unit_test_files_LDADD = $(LIB_COMMON) $(CMOCKA_LIBS) $(TCTI_SOCK_LIBS) \
$(TCTI_DEV_LIBS)
test_unit_test_files_LDADD = $(LIB_COMMON) $(CMOCKA_LIBS)
test_unit_test_files_SOURCES = test/unit/test_files.c

test_unit_test_tpm2_header_CFLAGS = $(AM_CFLAGS) $(CMOCKA_CFLAGS)
Expand Down
70 changes: 8 additions & 62 deletions configure.ac
Expand Up @@ -16,70 +16,9 @@ AS_IF(
[AC_MSG_WARN([Required executable pandoc not found, man pages will not be built])])
AM_CONDITIONAL([HAVE_PANDOC],[test "x${PANDOC}" = "xyes"])
PKG_CHECK_MODULES([SAPI],[sapi])
# disable libtcti-device selectively (enabled by default)
AC_ARG_WITH(
[tcti-device],
[AS_HELP_STRING([--with-tcti-device],
[Build tools with support for the device TCTI.])],
[],
[with_tcti_device=check])
AS_IF(
[test "x$with_tcti_device" != "xno"],
[PKG_CHECK_MODULES(
[TCTI_DEV],
[tcti-device],
[AC_DEFINE([HAVE_TCTI_DEV],[1])
with_tcti_device=yes],
[if test "x$with_tcti_device" = "xyes"; then
AC_MSG_FAILURE([--with-tcti-device option provided but libtcti-device not detected.])
fi])])
AM_CONDITIONAL([HAVE_TCTI_DEV],[test "x$with_tcti_device" = "xyes"])
# disable libtcti-socket selectively (enabled by default)
AC_ARG_WITH(
[tcti-socket],
[AS_HELP_STRING([--with-tcti-socket],
[Build tools with support for the socket TCTI.])],
[],
[with_tcti_socket=check])
AS_IF(
[test "x$with_tcti_socket" != "xno"],
[PKG_CHECK_MODULES(
[TCTI_SOCK],
[tcti-socket],
[AC_DEFINE([HAVE_TCTI_SOCK],[1])
with_tcti_socket=yes],
[if test "x$with_tcti_socket" = "xyes"; then
AC_MSG_FAILURE([--with-tcti-socket option provided but libtcti-socket not detected.])
fi])])
AM_CONDITIONAL([HAVE_TCTI_SOCK],[test "x$with_tcti_socket" = "xyes"])
# selectively disable libtcti-tabrmd
AC_ARG_WITH(
[tcti-tabrmd],
[AS_HELP_STRING([--with-tcti-tabrmd],
[Build tools with support for the tabrmd TCTI.])],
[],
[with_tcti_tabrmd=check])
AS_IF(
[test "x$with_tcti_tabrmd" != "xno"],
[PKG_CHECK_MODULES(
[TCTI_TABRMD],
[tcti-tabrmd],
[AC_DEFINE([HAVE_TCTI_TABRMD], [1])
with_tcti_tabrmd=yes],
[if test "x$with_tcti_tabrmd" = "xyes"; then
AC_MSG_FAILURE([--with-tcti-tabrmd option provided but libtcti-tabrmd not detected.])
fi])])
AM_CONDITIONAL([HAVE_TCTI_TABRMD],[test "x$with_tcti_tabrmd" = "xyes"])
# ensure we have at least one TCTI enabled, can't do much without one
AS_IF(
[test "x$with_tcti_device" != "xyes" -a \
"x$with_tcti_socket" != "xyes" -a \
"x$with_tcti_tabrmd" != "xyes"],
[AC_MSG_ERROR(
[no TCTIs: at least one TCTI library must be enabled],
[1])])
PKG_CHECK_MODULES([CRYPTO], [libcrypto >= 1.0.2g])
PKG_CHECK_MODULES([CURL],[libcurl])

AC_ARG_ENABLE([unit],
[AS_HELP_STRING([--enable-unit],
[build cmocka unit tests (default is no)])],
Expand All @@ -92,6 +31,13 @@ AS_IF([test "x$enable_unit" != xno],
[1])])])
AM_CONDITIONAL([UNIT], [test "x$enable_unit" != xno])

AC_ARG_ENABLE([dlclose],
[AS_HELP_STRING([--disable-dlclose],
[Some versions of libc cause a sigsegv on exit, this disables the dlclose and works around that bug])],
[]
[AC_DEFINE([DISABLE_DLCLOSE], [1])]
)

AC_ARG_ENABLE([hardening],
[AS_HELP_STRING([--enable-hardening],
[Enable compiler and linker options to frustrate memory corruption exploits @<:@yes@:>@])],
Expand Down
66 changes: 0 additions & 66 deletions lib/tcti/tpm2_tools_tcti_abrmd.c

This file was deleted.

81 changes: 0 additions & 81 deletions lib/tcti/tpm2_tools_tcti_device.c

This file was deleted.