swtpm: Rename SOCKET option to SWTPM

pull/121/head
Elms 2020-09-24 08:10:27 -07:00
parent 8d6abc3856
commit 9617dab37e
10 changed files with 52 additions and 52 deletions

View File

@ -179,21 +179,21 @@ then
AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_LINUX_DEV" AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_LINUX_DEV"
fi fi
# Socket TPM device Support # SW TPM device Support
AC_ARG_ENABLE([socket], AC_ARG_ENABLE([swtpm],
[AS_HELP_STRING([--enable-socket],[Enable use of TPM through the socket driver (default: disabled)])], [AS_HELP_STRING([--enable-swtpm],[Enable use of TPM through the SW socket driver (default: disabled)])],
[ ENABLED_SOCKET=$enableval ], [ ENABLED_SWTPM=$enableval ],
[ ENABLED_SOCKET=no ] [ ENABLED_SWTPM=no ]
) )
if test "x$ENABLED_SOCKET" = "xyes" if test "x$ENABLED_SWTPM" = "xyes"
then then
if test "x$ENABLED_DEVTPM" = "xyes" if test "x$ENABLED_DEVTPM" = "xyes"
then then
AC_MSG_ERROR([Cannot enable both socket and devtpm]) AC_MSG_ERROR([Cannot enable both swtpm and devtpm])
fi fi
AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_SOCKET" AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_SWTPM"
fi 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_MICROCHIP], [test "x$ENABLED_MICROCHIP" = "xyes"])
AM_CONDITIONAL([BUILD_INFINEON], [test "x$ENABLED_INFINEON" = "xyes"]) AM_CONDITIONAL([BUILD_INFINEON], [test "x$ENABLED_INFINEON" = "xyes"])
AM_CONDITIONAL([BUILD_DEVTPM], [test "x$ENABLED_DEVTPM" = "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_NUVOTON], [test "x$ENABLED_NUVOTON" = "xyes"])
AM_CONDITIONAL([BUILD_CHECKWAITSTATE], [test "x$ENABLED_CHECKWAITSTATE" = "xyes"]) AM_CONDITIONAL([BUILD_CHECKWAITSTATE], [test "x$ENABLED_CHECKWAITSTATE" = "xyes"])
AM_CONDITIONAL([BUILD_AUTODETECT], [test "x$ENABLED_AUTODETECT" = "xyes"]) AM_CONDITIONAL([BUILD_AUTODETECT], [test "x$ENABLED_AUTODETECT" = "xyes"])

View File

@ -13,8 +13,8 @@ src_libwolftpm_la_SOURCES = \
if BUILD_DEVTPM if BUILD_DEVTPM
src_libwolftpm_la_SOURCES += src/tpm2_linux.c src_libwolftpm_la_SOURCES += src/tpm2_linux.c
endif endif
if BUILD_SOCKET if BUILD_SWTPM
src_libwolftpm_la_SOURCES += src/tpm2_socket.c src_libwolftpm_la_SOURCES += src/tpm2_swtpm.c
endif endif
src_libwolftpm_la_CFLAGS = -DBUILDING_WOLFTPM $(AM_CFLAGS) src_libwolftpm_la_CFLAGS = -DBUILDING_WOLFTPM $(AM_CFLAGS)

View File

@ -24,7 +24,7 @@
#include <wolftpm/tpm2_packet.h> #include <wolftpm/tpm2_packet.h>
#include <wolftpm/tpm2_tis.h> #include <wolftpm/tpm2_tis.h>
#include <wolftpm/tpm2_linux.h> #include <wolftpm/tpm2_linux.h>
#include <wolftpm/tpm2_socket.h> #include <wolftpm/tpm2_swtpm.h>
/******************************************************************************/ /******************************************************************************/
/* --- Local Variables -- */ /* --- Local Variables -- */
@ -170,8 +170,8 @@ static TPM_RC TPM2_SendCommandAuth(TPM2_CTX* ctx, TPM2_Packet* packet,
/* submit command and wait for response */ /* submit command and wait for response */
#ifdef WOLFTPM_LINUX_DEV #ifdef WOLFTPM_LINUX_DEV
rc = (TPM_RC)TPM2_LINUX_SendCommand(ctx, cmd, cmdSz); rc = (TPM_RC)TPM2_LINUX_SendCommand(ctx, cmd, cmdSz);
#elif defined(WOLFTPM_SOCKET) #elif defined(WOLFTPM_SWTPM)
rc = (TPM_RC)TPM2_SOCKET_SendCommand(ctx, cmd, cmdSz); rc = (TPM_RC)TPM2_SWTPM_SendCommand(ctx, cmd, cmdSz);
#else #else
rc = (TPM_RC)TPM2_TIS_SendCommand(ctx, cmd, cmdSz); rc = (TPM_RC)TPM2_TIS_SendCommand(ctx, cmd, cmdSz);
#endif #endif
@ -242,8 +242,8 @@ static TPM_RC TPM2_SendCommand(TPM2_CTX* ctx, TPM2_Packet* packet)
/* submit command and wait for response */ /* submit command and wait for response */
#ifdef WOLFTPM_LINUX_DEV #ifdef WOLFTPM_LINUX_DEV
rc = (TPM_RC)TPM2_LINUX_SendCommand(ctx, packet->buf, packet->pos); rc = (TPM_RC)TPM2_LINUX_SendCommand(ctx, packet->buf, packet->pos);
#elif defined(WOLFTPM_SOCKET) #elif defined(WOLFTPM_SWTPM)
rc = (TPM_RC)TPM2_SOCKET_SendCommand(ctx, packet->buf, packet->pos); rc = (TPM_RC)TPM2_SWTPM_SendCommand(ctx, packet->buf, packet->pos);
#else #else
rc = (TPM_RC)TPM2_TIS_SendCommand(ctx, packet->buf, packet->pos); rc = (TPM_RC)TPM2_TIS_SendCommand(ctx, packet->buf, packet->pos);
#endif #endif

View File

@ -1,4 +1,4 @@
/* tpm2_socket.c /* tpm2_swtpm.c
* *
* Copyright (C) 2006-2020 wolfSSL Inc. * Copyright (C) 2006-2020 wolfSSL Inc.
* *
@ -30,9 +30,9 @@
* https://github.com/stefanberger/swtpm * https://github.com/stefanberger/swtpm
*/ */
#ifdef WOLFTPM_SOCKET #ifdef WOLFTPM_SWTPM
#include <wolftpm/tpm2.h> #include <wolftpm/tpm2.h>
#include <wolftpm/tpm2_socket.h> #include <wolftpm/tpm2_swtpm.h>
#include <wolftpm/tpm2_packet.h> #include <wolftpm/tpm2_packet.h>
#include <unistd.h> #include <unistd.h>
@ -45,14 +45,14 @@
#include <netdb.h> #include <netdb.h>
#ifndef TPM2_SOCKET_HOST #ifndef TPM2_SWTPM_HOST
#define TPM2_SOCKET_HOST "localhost" #define TPM2_SWTPM_HOST "localhost"
#endif #endif
#ifndef TPM2_SOCKET_PORT #ifndef TPM2_SWTPM_PORT
#define TPM2_SOCKET_PORT "2321" #define TPM2_SWTPM_PORT "2321"
#endif #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; TPM_RC rc = TPM_RC_SUCCESS;
ssize_t wrc = 0; 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; 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; TPM_RC rc = TPM_RC_SUCCESS;
ssize_t wrc = 0; ssize_t wrc = 0;
size_t bytes_remaining = rxSz; 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; 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; TPM_RC rc = SOCKET_ERROR_E;
struct addrinfo hints; struct addrinfo hints;
@ -159,7 +159,7 @@ static TPM_RC tpm_tcp_connect(TPM2_CTX* ctx, const char* host, const char* port)
return rc; return rc;
} }
static TPM_RC tpm_tcp_disconnect(TPM2_CTX* ctx) static TPM_RC SwTpmDisconnect(TPM2_CTX* ctx)
{ {
TPM_RC rc = TPM_RC_SUCCESS; TPM_RC rc = TPM_RC_SUCCESS;
uint32_t tss_cmd; uint32_t tss_cmd;
@ -170,7 +170,7 @@ static TPM_RC tpm_tcp_disconnect(TPM2_CTX* ctx)
/* end swtpm session */ /* end swtpm session */
tss_cmd = htonl(TPM_SESSION_END); 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 #ifdef WOLFTPM_DEBUG_VERBOSE
if (rc != TPM_RC_SUCCESS) { if (rc != TPM_RC_SUCCESS) {
printf("Failed to transmit SESSION_END\n"); 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 */ /* 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; int rc = TPM_RC_FAILURE;
word32 rspSz = 0; word32 rspSz = 0;
@ -203,7 +203,7 @@ int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz)
} }
if (ctx->tcpCtx.fd <= 0) { 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 #ifdef WOLFTPM_DEBUG_VERBOSE
@ -214,28 +214,28 @@ int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz)
/* send start */ /* send start */
tss_word = htonl(TPM_SEND_COMMAND); tss_word = htonl(TPM_SEND_COMMAND);
if (rc == TPM_RC_SUCCESS) { if (rc == TPM_RC_SUCCESS) {
rc = tpm_tcp_transmit(ctx, &tss_word, sizeof(uint32_t)); rc = SwTpmTransmit(ctx, &tss_word, sizeof(uint32_t));
} }
/* locality */ /* locality */
if (rc == TPM_RC_SUCCESS) { 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 */ /* buffer size */
tss_word = htonl(cmdSz); tss_word = htonl(cmdSz);
if (rc == TPM_RC_SUCCESS) { 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 */ /* Send the TPM command buffer */
if (rc == TPM_RC_SUCCESS) { if (rc == TPM_RC_SUCCESS) {
rc = tpm_tcp_transmit(ctx, cmd, cmdSz); rc = SwTpmTransmit(ctx, cmd, cmdSz);
} }
/* receive response */ /* receive response */
if (rc == TPM_RC_SUCCESS) { 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); rspSz = ntohl(tss_word);
if (rspSz > cmdSz) { if (rspSz > cmdSz) {
#ifdef WOLFTPM_DEBUG_VERBOSE #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 */ /* TODO: could hang as currently implemented, but is not TSS complient */
if (rc == TPM_RC_SUCCESS) { if (rc == TPM_RC_SUCCESS) {
rc = tpm_tcp_receive(ctx, cmd, rspSz); rc = SwTpmReceive(ctx, cmd, rspSz);
} }
/* receive ack */ /* receive ack */
if (rc == TPM_RC_SUCCESS) { 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); tss_word = ntohl(tss_word);
#ifdef WOLFTPM_DEBUG #ifdef WOLFTPM_DEBUG
if (tss_word != 0) { if (tss_word != 0) {
@ -272,7 +272,7 @@ int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz)
#endif #endif
if (ctx->tcpCtx.fd > 0) { if (ctx->tcpCtx.fd > 0) {
TPM_RC rc_disconnect = tpm_tcp_disconnect(ctx); TPM_RC rc_disconnect = SwTpmDisconnect(ctx);
if (rc == TPM_RC_SUCCESS) { if (rc == TPM_RC_SUCCESS) {
rc = rc_disconnect; rc = rc_disconnect;
} }
@ -280,4 +280,4 @@ int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz)
return rc; return rc;
} }
#endif /* WOLFTPM_SOCKET */ #endif /* WOLFTPM_SWTPM */

View File

@ -46,7 +46,7 @@ static int wolfTPM2_Init_ex(TPM2_CTX* ctx, TPM2HalIoCb ioCb, void* userCtx,
if (ctx == NULL) if (ctx == NULL)
return BAD_FUNC_ARG; 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); rc = TPM2_Init_minimal(ctx, userCtx);
/* Using standard file I/O for the Linux TPM device */ /* Using standard file I/O for the Linux TPM device */
(void)ioCb; (void)ioCb;

View File

@ -93,7 +93,7 @@ static void test_wolfTPM2_Init(void)
AssertIntNE(rc, 0); AssertIntNE(rc, 0);
/* Test second argument, TPM2 IO Callbacks */ /* Test second argument, TPM2 IO Callbacks */
rc = wolfTPM2_Init(&dev, NULL, NULL); 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 */ /* Custom IO Callbacks are not needed for Linux TIS driver */
AssertIntEQ(rc, 0); AssertIntEQ(rc, 0);
#else #else

View File

@ -9,7 +9,7 @@ nobase_include_HEADERS+= \
wolftpm/tpm2_types.h \ wolftpm/tpm2_types.h \
wolftpm/tpm2_wrap.h \ wolftpm/tpm2_wrap.h \
wolftpm/tpm2_linux.h \ wolftpm/tpm2_linux.h \
wolftpm/tpm2_socket.h \ wolftpm/tpm2_swtpm.h \
wolftpm/version.h \ wolftpm/version.h \
wolftpm/visibility.h \ wolftpm/visibility.h \
wolftpm/options.h wolftpm/options.h

View File

@ -1612,11 +1612,11 @@ static const BYTE TPM_20_EK_AUTH_POLICY[] = {
/* HAL IO Callbacks */ /* HAL IO Callbacks */
struct TPM2_CTX; struct TPM2_CTX;
#ifdef WOLFTPM_SOCKET #ifdef WOLFTPM_SWTPM
struct wolfTPM_tcpContext { struct wolfTPM_tcpContext {
int fd; int fd;
}; };
#endif /* WOLFTPM_SOCKET */ #endif /* WOLFTPM_SWTPM */
/* make sure advanced IO is enabled for I2C */ /* make sure advanced IO is enabled for I2C */
#ifdef WOLFTPM_I2C #ifdef WOLFTPM_I2C
@ -1640,7 +1640,7 @@ typedef int (*TPM2HalIoCb)(struct TPM2_CTX*, const BYTE* txBuf, BYTE* rxBuf,
typedef struct TPM2_CTX { typedef struct TPM2_CTX {
TPM2HalIoCb ioCb; TPM2HalIoCb ioCb;
void* userCtx; void* userCtx;
#ifdef WOLFTPM_SOCKET #ifdef WOLFTPM_SWTPM
struct wolfTPM_tcpContext tcpCtx; struct wolfTPM_tcpContext tcpCtx;
#endif #endif
#ifndef WOLFTPM2_NO_WOLFCRYPT #ifndef WOLFTPM2_NO_WOLFCRYPT

View File

@ -1,4 +1,4 @@
/* tpm2_socket.h /* tpm2_swtpm.h
* *
* Copyright (C) 2006-2020 wolfSSL Inc. * Copyright (C) 2006-2020 wolfSSL Inc.
* *
@ -19,8 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#ifndef _TPM2_SOCKET_H_ #ifndef _TPM2_SWTPM_H_
#define _TPM2_SOCKET_H_ #define _TPM2_SWTPM_H_
#include <wolftpm/tpm2.h> #include <wolftpm/tpm2.h>
@ -38,11 +38,11 @@
#define TPM_STOP 21 #define TPM_STOP 21
/* TPM2 IO for using TPM through a Socket connection */ /* TPM2 IO for using TPM through a Socket connection */
int TPM2_SOCKET_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz); int TPM2_SWTPM_SendCommand(TPM2_CTX* ctx, byte* cmd, word16 cmdSz);
/* int TPM2_SOCKET_PowerOn(TPM2_CTX* ctx); */ /* int TPM2_SWTPM_PowerOn(TPM2_CTX* ctx); */
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif
#endif /* _TPM2_SOCKET_H_ */ #endif /* _TPM2_SWTPM_H_ */

View File

@ -270,7 +270,7 @@ typedef int64_t INT64;
#endif #endif
#ifndef TPM_TIMEOUT_TRIES #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 #define TPM_TIMEOUT_TRIES 0
#else #else
#define TPM_TIMEOUT_TRIES 1000000 #define TPM_TIMEOUT_TRIES 1000000