diff --git a/configure.ac b/configure.ac index 986dcf8..96b4811 100644 --- a/configure.ac +++ b/configure.ac @@ -179,21 +179,21 @@ then AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_LINUX_DEV" fi -# Socket TPM device Support -AC_ARG_ENABLE([socket], - [AS_HELP_STRING([--enable-socket],[Enable use of TPM through the socket driver (default: disabled)])], - [ ENABLED_SOCKET=$enableval ], - [ ENABLED_SOCKET=no ] +# SW TPM device Support +AC_ARG_ENABLE([swtpm], + [AS_HELP_STRING([--enable-swtpm],[Enable use of TPM through the SW socket driver (default: disabled)])], + [ ENABLED_SWTPM=$enableval ], + [ ENABLED_SWTPM=no ] ) -if test "x$ENABLED_SOCKET" = "xyes" +if test "x$ENABLED_SWTPM" = "xyes" then if test "x$ENABLED_DEVTPM" = "xyes" then - AC_MSG_ERROR([Cannot enable both socket and devtpm]) + AC_MSG_ERROR([Cannot enable both swtpm and devtpm]) fi - AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_SOCKET" + AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_SWTPM" fi @@ -335,7 +335,7 @@ AM_CONDITIONAL([BUILD_ST], [test "x$ENABLED_ST" = "xyes"]) AM_CONDITIONAL([BUILD_MICROCHIP], [test "x$ENABLED_MICROCHIP" = "xyes"]) AM_CONDITIONAL([BUILD_INFINEON], [test "x$ENABLED_INFINEON" = "xyes"]) AM_CONDITIONAL([BUILD_DEVTPM], [test "x$ENABLED_DEVTPM" = "xyes"]) -AM_CONDITIONAL([BUILD_SOCKET], [test "x$ENABLED_SOCKET" = "xyes"]) +AM_CONDITIONAL([BUILD_SWTPM], [test "x$ENABLED_SWTPM" = "xyes"]) AM_CONDITIONAL([BUILD_NUVOTON], [test "x$ENABLED_NUVOTON" = "xyes"]) AM_CONDITIONAL([BUILD_CHECKWAITSTATE], [test "x$ENABLED_CHECKWAITSTATE" = "xyes"]) AM_CONDITIONAL([BUILD_AUTODETECT], [test "x$ENABLED_AUTODETECT" = "xyes"]) diff --git a/src/include.am b/src/include.am index e809cb9..5628628 100644 --- a/src/include.am +++ b/src/include.am @@ -13,8 +13,8 @@ src_libwolftpm_la_SOURCES = \ if BUILD_DEVTPM src_libwolftpm_la_SOURCES += src/tpm2_linux.c endif -if BUILD_SOCKET -src_libwolftpm_la_SOURCES += src/tpm2_socket.c +if BUILD_SWTPM +src_libwolftpm_la_SOURCES += src/tpm2_swtpm.c endif src_libwolftpm_la_CFLAGS = -DBUILDING_WOLFTPM $(AM_CFLAGS) diff --git a/src/tpm2.c b/src/tpm2.c index 74bef1a..9f871c8 100644 --- a/src/tpm2.c +++ b/src/tpm2.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include /******************************************************************************/ /* --- Local Variables -- */ @@ -170,8 +170,8 @@ static TPM_RC TPM2_SendCommandAuth(TPM2_CTX* ctx, TPM2_Packet* packet, /* submit command and wait for response */ #ifdef WOLFTPM_LINUX_DEV rc = (TPM_RC)TPM2_LINUX_SendCommand(ctx, cmd, cmdSz); -#elif defined(WOLFTPM_SOCKET) - rc = (TPM_RC)TPM2_SOCKET_SendCommand(ctx, cmd, cmdSz); +#elif defined(WOLFTPM_SWTPM) + rc = (TPM_RC)TPM2_SWTPM_SendCommand(ctx, cmd, cmdSz); #else rc = (TPM_RC)TPM2_TIS_SendCommand(ctx, cmd, cmdSz); #endif @@ -242,8 +242,8 @@ static TPM_RC TPM2_SendCommand(TPM2_CTX* ctx, TPM2_Packet* packet) /* submit command and wait for response */ #ifdef WOLFTPM_LINUX_DEV rc = (TPM_RC)TPM2_LINUX_SendCommand(ctx, packet->buf, packet->pos); -#elif defined(WOLFTPM_SOCKET) - rc = (TPM_RC)TPM2_SOCKET_SendCommand(ctx, packet->buf, packet->pos); +#elif defined(WOLFTPM_SWTPM) + rc = (TPM_RC)TPM2_SWTPM_SendCommand(ctx, packet->buf, packet->pos); #else rc = (TPM_RC)TPM2_TIS_SendCommand(ctx, packet->buf, packet->pos); #endif diff --git a/src/tpm2_socket.c b/src/tpm2_swtpm.c similarity index 83% rename from src/tpm2_socket.c rename to src/tpm2_swtpm.c index 86412c8..0ce1b60 100644 --- a/src/tpm2_socket.c +++ b/src/tpm2_swtpm.c @@ -1,4 +1,4 @@ -/* tpm2_socket.c +/* tpm2_swtpm.c * * Copyright (C) 2006-2020 wolfSSL Inc. * @@ -30,9 +30,9 @@ * https://github.com/stefanberger/swtpm */ -#ifdef WOLFTPM_SOCKET +#ifdef WOLFTPM_SWTPM #include -#include +#include #include #include @@ -45,14 +45,14 @@ #include -#ifndef TPM2_SOCKET_HOST -#define TPM2_SOCKET_HOST "localhost" +#ifndef TPM2_SWTPM_HOST +#define TPM2_SWTPM_HOST "localhost" #endif -#ifndef TPM2_SOCKET_PORT -#define TPM2_SOCKET_PORT "2321" +#ifndef TPM2_SWTPM_PORT +#define TPM2_SWTPM_PORT "2321" #endif -static TPM_RC tpm_tcp_transmit(TPM2_CTX* ctx, const void* buffer, ssize_t bufSz) +static TPM_RC SwTpmTransmit(TPM2_CTX* ctx, const void* buffer, ssize_t bufSz) { TPM_RC rc = TPM_RC_SUCCESS; ssize_t wrc = 0; @@ -76,7 +76,7 @@ static TPM_RC tpm_tcp_transmit(TPM2_CTX* ctx, const void* buffer, ssize_t bufSz) return rc; } -static TPM_RC tpm_tcp_receive(TPM2_CTX* ctx, void* buffer, size_t rxSz) { +static TPM_RC SwTpmReceive(TPM2_CTX* ctx, void* buffer, size_t rxSz) { TPM_RC rc = TPM_RC_SUCCESS; ssize_t wrc = 0; size_t bytes_remaining = rxSz; @@ -113,7 +113,7 @@ static TPM_RC tpm_tcp_receive(TPM2_CTX* ctx, void* buffer, size_t rxSz) { return rc; } -static TPM_RC tpm_tcp_connect(TPM2_CTX* ctx, const char* host, const char* port) +static TPM_RC SwTpmConnect(TPM2_CTX* ctx, const char* host, const char* port) { TPM_RC rc = SOCKET_ERROR_E; struct addrinfo hints; @@ -159,7 +159,7 @@ static TPM_RC tpm_tcp_connect(TPM2_CTX* ctx, const char* host, const char* port) return rc; } -static TPM_RC tpm_tcp_disconnect(TPM2_CTX* ctx) +static TPM_RC SwTpmDisconnect(TPM2_CTX* ctx) { TPM_RC rc = TPM_RC_SUCCESS; uint32_t tss_cmd; @@ -170,7 +170,7 @@ static TPM_RC tpm_tcp_disconnect(TPM2_CTX* ctx) /* end swtpm session */ tss_cmd = htonl(TPM_SESSION_END); - rc = tpm_tcp_transmit(ctx, &tss_cmd, sizeof(uint32_t)); + rc = SwTpmTransmit(ctx, &tss_cmd, sizeof(uint32_t)); #ifdef WOLFTPM_DEBUG_VERBOSE if (rc != TPM_RC_SUCCESS) { printf("Failed to transmit SESSION_END\n"); @@ -192,7 +192,7 @@ static TPM_RC tpm_tcp_disconnect(TPM2_CTX* ctx) } /* Talk to a TPM through socket */ -int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz) +int TPM2_SWTPM_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz) { int rc = TPM_RC_FAILURE; word32 rspSz = 0; @@ -203,7 +203,7 @@ int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz) } if (ctx->tcpCtx.fd <= 0) { - rc = tpm_tcp_connect(ctx, TPM2_SOCKET_HOST, TPM2_SOCKET_PORT); + rc = SwTpmConnect(ctx, TPM2_SWTPM_HOST, TPM2_SWTPM_PORT); } #ifdef WOLFTPM_DEBUG_VERBOSE @@ -214,28 +214,28 @@ int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz) /* send start */ tss_word = htonl(TPM_SEND_COMMAND); if (rc == TPM_RC_SUCCESS) { - rc = tpm_tcp_transmit(ctx, &tss_word, sizeof(uint32_t)); + rc = SwTpmTransmit(ctx, &tss_word, sizeof(uint32_t)); } /* locality */ if (rc == TPM_RC_SUCCESS) { - rc = tpm_tcp_transmit(ctx, &ctx->locality, sizeof(uint8_t)); + rc = SwTpmTransmit(ctx, &ctx->locality, sizeof(uint8_t)); } /* buffer size */ tss_word = htonl(cmdSz); if (rc == TPM_RC_SUCCESS) { - rc = tpm_tcp_transmit(ctx, &tss_word, sizeof(uint32_t)); + rc = SwTpmTransmit(ctx, &tss_word, sizeof(uint32_t)); } /* Send the TPM command buffer */ if (rc == TPM_RC_SUCCESS) { - rc = tpm_tcp_transmit(ctx, cmd, cmdSz); + rc = SwTpmTransmit(ctx, cmd, cmdSz); } /* receive response */ if (rc == TPM_RC_SUCCESS) { - rc = tpm_tcp_receive(ctx, &tss_word, sizeof(uint32_t)); + rc = SwTpmReceive(ctx, &tss_word, sizeof(uint32_t)); rspSz = ntohl(tss_word); if (rspSz > cmdSz) { #ifdef WOLFTPM_DEBUG_VERBOSE @@ -249,12 +249,12 @@ int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz) /* TODO: could hang as currently implemented, but is not TSS complient */ if (rc == TPM_RC_SUCCESS) { - rc = tpm_tcp_receive(ctx, cmd, rspSz); + rc = SwTpmReceive(ctx, cmd, rspSz); } /* receive ack */ if (rc == TPM_RC_SUCCESS) { - rc = tpm_tcp_receive(ctx, &tss_word, sizeof(uint32_t)); + rc = SwTpmReceive(ctx, &tss_word, sizeof(uint32_t)); tss_word = ntohl(tss_word); #ifdef WOLFTPM_DEBUG if (tss_word != 0) { @@ -272,7 +272,7 @@ int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz) #endif if (ctx->tcpCtx.fd > 0) { - TPM_RC rc_disconnect = tpm_tcp_disconnect(ctx); + TPM_RC rc_disconnect = SwTpmDisconnect(ctx); if (rc == TPM_RC_SUCCESS) { rc = rc_disconnect; } @@ -280,4 +280,4 @@ int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz) return rc; } -#endif /* WOLFTPM_SOCKET */ +#endif /* WOLFTPM_SWTPM */ diff --git a/src/tpm2_wrap.c b/src/tpm2_wrap.c index 5ab0407..c6a98ef 100644 --- a/src/tpm2_wrap.c +++ b/src/tpm2_wrap.c @@ -46,7 +46,7 @@ static int wolfTPM2_Init_ex(TPM2_CTX* ctx, TPM2HalIoCb ioCb, void* userCtx, if (ctx == NULL) return BAD_FUNC_ARG; -#if defined(WOLFTPM_LINUX_DEV) || defined(WOLFTPM_SOCKET) +#if defined(WOLFTPM_LINUX_DEV) || defined(WOLFTPM_SWTPM) rc = TPM2_Init_minimal(ctx, userCtx); /* Using standard file I/O for the Linux TPM device */ (void)ioCb; diff --git a/tests/unit_tests.c b/tests/unit_tests.c index c984f69..64cbceb 100644 --- a/tests/unit_tests.c +++ b/tests/unit_tests.c @@ -93,7 +93,7 @@ static void test_wolfTPM2_Init(void) AssertIntNE(rc, 0); /* Test second argument, TPM2 IO Callbacks */ rc = wolfTPM2_Init(&dev, NULL, NULL); -#if defined(WOLFTPM_LINUX_DEV) || defined(WOLFTPM_SOCKET) +#if defined(WOLFTPM_LINUX_DEV) || defined(WOLFTPM_SWTPM) /* Custom IO Callbacks are not needed for Linux TIS driver */ AssertIntEQ(rc, 0); #else diff --git a/wolftpm/include.am b/wolftpm/include.am index c10adfb..11f8664 100644 --- a/wolftpm/include.am +++ b/wolftpm/include.am @@ -9,7 +9,7 @@ nobase_include_HEADERS+= \ wolftpm/tpm2_types.h \ wolftpm/tpm2_wrap.h \ wolftpm/tpm2_linux.h \ - wolftpm/tpm2_socket.h \ + wolftpm/tpm2_swtpm.h \ wolftpm/version.h \ wolftpm/visibility.h \ wolftpm/options.h diff --git a/wolftpm/tpm2.h b/wolftpm/tpm2.h index 887a439..f5758fd 100644 --- a/wolftpm/tpm2.h +++ b/wolftpm/tpm2.h @@ -1612,11 +1612,11 @@ static const BYTE TPM_20_EK_AUTH_POLICY[] = { /* HAL IO Callbacks */ struct TPM2_CTX; -#ifdef WOLFTPM_SOCKET +#ifdef WOLFTPM_SWTPM struct wolfTPM_tcpContext { int fd; }; -#endif /* WOLFTPM_SOCKET */ +#endif /* WOLFTPM_SWTPM */ /* make sure advanced IO is enabled for I2C */ #ifdef WOLFTPM_I2C @@ -1640,7 +1640,7 @@ typedef int (*TPM2HalIoCb)(struct TPM2_CTX*, const BYTE* txBuf, BYTE* rxBuf, typedef struct TPM2_CTX { TPM2HalIoCb ioCb; void* userCtx; -#ifdef WOLFTPM_SOCKET +#ifdef WOLFTPM_SWTPM struct wolfTPM_tcpContext tcpCtx; #endif #ifndef WOLFTPM2_NO_WOLFCRYPT diff --git a/wolftpm/tpm2_socket.h b/wolftpm/tpm2_swtpm.h similarity index 85% rename from wolftpm/tpm2_socket.h rename to wolftpm/tpm2_swtpm.h index fa4f947..fb758ad 100644 --- a/wolftpm/tpm2_socket.h +++ b/wolftpm/tpm2_swtpm.h @@ -1,4 +1,4 @@ -/* tpm2_socket.h +/* tpm2_swtpm.h * * Copyright (C) 2006-2020 wolfSSL Inc. * @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef _TPM2_SOCKET_H_ -#define _TPM2_SOCKET_H_ +#ifndef _TPM2_SWTPM_H_ +#define _TPM2_SWTPM_H_ #include @@ -38,11 +38,11 @@ #define TPM_STOP 21 /* TPM2 IO for using TPM through a Socket connection */ -int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz); -/* int TPM2_SOCKET_PowerOn(TPM2_CTX* ctx); */ +int TPM2_SWTPM_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz); +/* int TPM2_SWTPM_PowerOn(TPM2_CTX* ctx); */ #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* _TPM2_SOCKET_H_ */ +#endif /* _TPM2_SWTPM_H_ */ diff --git a/wolftpm/tpm2_types.h b/wolftpm/tpm2_types.h index 3d6c2cc..f02fbaf 100644 --- a/wolftpm/tpm2_types.h +++ b/wolftpm/tpm2_types.h @@ -270,7 +270,7 @@ typedef int64_t INT64; #endif #ifndef TPM_TIMEOUT_TRIES - #if defined(WOLFTPM_LINUX_DEV) || defined(WOLFTPM_SOCKET) + #if defined(WOLFTPM_LINUX_DEV) || defined(WOLFTPM_SWTPM) #define TPM_TIMEOUT_TRIES 0 #else #define TPM_TIMEOUT_TRIES 1000000