build-sys: add optional --with-tpm1

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2021-08-05 15:22:49 +04:00 committed by Stefan Berger
parent e60c35ecf9
commit 057242b84d
5 changed files with 147 additions and 12 deletions

View File

@ -67,6 +67,10 @@ m4_if(
AM_CONDITIONAL([HAVE_VERSION_SCRIPT], [test "x$have_version_script" = "xyes"])
AC_ARG_WITH([tpm1],
AS_HELP_STRING([--with-tpm1], [build libtpms with TPM 1.2 support]), [], [with_tpm1=yes])
AM_CONDITIONAL([WITH_TPM1], [test "x$with_tpm1" != "xno"])
AS_IF([test "x$with_tpm1" != "xno"], [AC_DEFINE([WITH_TPM1], [1], [With TPM 1.2 support])])
AC_ARG_WITH([tpm2],
AS_HELP_STRING([--with-tpm2],[build libtpms with TPM2 support]),
@ -337,6 +341,7 @@ echo
echo "Version to build : $PACKAGE_VERSION"
echo "Crypto library : $cryptolib"
echo "Debug build : $enable_debug"
echo "With TPM1.2 support : $with_tpm1"
echo "With TPM2 support : $with_tpm2"
echo "HAVE_VERSION_SCRIPT : $have_version_script"
echo "Use openssl crypto for : $use_openssl_functions_for"

View File

@ -6,8 +6,11 @@
AM_CFLAGS = @AM_CFLAGS@
AM_LDFLAGS = @AM_LDFLAGS@ $(HARDENING_LDFLAGS) $(SANITIZERS) $(FUZZER)
noinst_LTLIBRARIES =
noinst_HEADERS =
lib_LTLIBRARIES=libtpms.la
lib_LTLIBRARIES = libtpms.la
libtpms_la_LIBADD =
common_CFLAGS = -include tpm_library_conf.h \
-I$(top_srcdir)/include/libtpms \
@ -22,13 +25,14 @@ common_CFLAGS += -DTPM_LIBTPMS_CALLBACKS
# let the default NVRAM write to disk
common_CFLAGS += -DTPM_NV_DISK
if WITH_TPM1
#
# TPM1.2
#
noinst_LTLIBRARIES = libtpms_tpm12.la
noinst_LTLIBRARIES += libtpms_tpm12.la
libtpms_la_LIBADD = libtpms_tpm12.la
libtpms_la_LIBADD += libtpms_tpm12.la
libtpms_tpm12_la_LIBADD =
@ -93,7 +97,7 @@ libtpms_tpm12_la_SOURCES = \
tpm_tpm12_interface.c \
tpm_tpm12_tis.c
noinst_HEADERS = \
noinst_HEADERS += \
tpm12/tpm_admin.h \
tpm12/tpm_audit.h \
tpm12/tpm_auth.h \
@ -164,6 +168,8 @@ endif # LIBTPMS_USE_OPENSSL
endif # LIBTPMS_USE_FREEBL
endif # WITH_TPM1
# TPM2
#
@ -559,6 +565,9 @@ libtpms_tpm2_la_CFLAGS += \
-I $(srcdir)/tpm2/crypto \
-I $(srcdir)/tpm2/crypto/openssl
libtpms_tpm2_la_LIBADD += -lcrypto
endif # LIBTPMS_USE_OPENSSL
endif # WITH_TPM2
@ -568,6 +577,7 @@ endif # WITH_TPM2
#
libtpms_la_SOURCES = \
disabled_interface.c \
tpm_debug.c \
tpm_library.c \
tpm_memory.c \

111
src/disabled_interface.c Normal file
View File

@ -0,0 +1,111 @@
#include <stddef.h>
#include "tpm_error.h"
#include "tpm_library_intern.h"
static TPM_RESULT Disabled_MainInit(void)
{
return TPM_FAIL;
}
static void Disabled_Terminate(void)
{
}
static TPM_RESULT Disabled_Process(unsigned char **respbuffer, uint32_t *resp_size,
uint32_t *respbufsize,
unsigned char *command, uint32_t command_size)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_VolatileAllStore(unsigned char **buffer,
uint32_t *buflen)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_CancelCommand(void)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_GetTPMProperty(enum TPMLIB_TPMProperty prop,
int *result)
{
return TPM_FAIL;
}
static char *Disabled_GetInfo(enum TPMLIB_InfoFlags flags)
{
return NULL;
}
static uint32_t Disabled_SetBufferSize(uint32_t wanted_size,
uint32_t *min_size,
uint32_t *max_size)
{
return 0;
}
static TPM_RESULT Disabled_ValidateState(enum TPMLIB_StateType st,
unsigned int flags)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_GetState(enum TPMLIB_StateType st,
unsigned char **buffer, uint32_t *buflen)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_SetState(enum TPMLIB_StateType st,
const unsigned char *buffer, uint32_t buflen)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_IO_Hash_Start(void)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_IO_Hash_Data(const unsigned char *data,
uint32_t data_length)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_IO_Hash_End(void)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_IO_TpmEstablished_Get(TPM_BOOL *tpmEstablished)
{
return TPM_FAIL;
}
static TPM_RESULT Disabled_IO_TpmEstablished_Reset(void)
{
return TPM_FAIL;
}
const struct tpm_interface DisabledInterface = {
.MainInit = Disabled_MainInit,
.Terminate = Disabled_Terminate,
.Process = Disabled_Process,
.VolatileAllStore = Disabled_VolatileAllStore,
.CancelCommand = Disabled_CancelCommand,
.GetTPMProperty = Disabled_GetTPMProperty,
.GetInfo = Disabled_GetInfo,
.TpmEstablishedGet = Disabled_IO_TpmEstablished_Get,
.TpmEstablishedReset = Disabled_IO_TpmEstablished_Reset,
.HashStart = Disabled_IO_Hash_Start,
.HashData = Disabled_IO_Hash_Data,
.HashEnd = Disabled_IO_Hash_End,
.SetBufferSize = Disabled_SetBufferSize,
.ValidateState = Disabled_ValidateState,
.SetState = Disabled_SetState,
.GetState = Disabled_GetState,
};

View File

@ -79,9 +79,15 @@ static const struct tags_and_indices {
};
static const struct tpm_interface *const tpm_iface[] = {
#if WITH_TPM1
&TPM12Interface,
#else
&DisabledInterface,
#endif
#if WITH_TPM2
&TPM2Interface,
#else
&DisabledInterface,
#endif
NULL,
};
@ -102,36 +108,38 @@ uint32_t TPMLIB_GetVersion(void)
TPM_RESULT TPMLIB_ChooseTPMVersion(TPMLIB_TPMVersion ver)
{
TPM_RESULT ret = TPM_SUCCESS;
/* TPMLIB_Terminate will reset previous choice */
if (tpmvers_locked)
return TPM_FAIL;
switch (ver) {
#if WITH_TPM1
case TPMLIB_TPM_VERSION_1_2:
if (tpmvers_choice != 0)
ClearAllCachedState();
tpmvers_choice = 0; // entry 0 in tpm_iface
break;
case TPMLIB_TPM_VERSION_2:
return TPM_SUCCESS;
#endif
#if WITH_TPM2
case TPMLIB_TPM_VERSION_2:
if (tpmvers_choice != 1)
ClearAllCachedState();
tpmvers_choice = 1; // entry 1 in tpm_iface
break;
return TPM_SUCCESS;
#endif
default:
ret = TPM_FAIL;
return TPM_FAIL;
}
return ret;
}
TPM_RESULT TPMLIB_MainInit(void)
{
if (!tpm_iface[tpmvers_choice]) {
return TPM_FAIL;
}
tpmvers_locked = TRUE;
return tpm_iface[tpmvers_choice]->MainInit();

View File

@ -85,6 +85,7 @@ struct tpm_interface {
unsigned char **buffer, uint32_t *buflen);
};
extern const struct tpm_interface DisabledInterface;
extern const struct tpm_interface TPM12Interface;
extern const struct tpm_interface TPM2Interface;