mirror of https://github.com/wolfSSL/wolfTPM.git
swtpm: Rename SOCKET option to SWTPM
parent
8d6abc3856
commit
9617dab37e
18
configure.ac
18
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"])
|
||||
|
|
|
@ -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)
|
||||
|
|
10
src/tpm2.c
10
src/tpm2.c
|
@ -24,7 +24,7 @@
|
|||
#include <wolftpm/tpm2_packet.h>
|
||||
#include <wolftpm/tpm2_tis.h>
|
||||
#include <wolftpm/tpm2_linux.h>
|
||||
#include <wolftpm/tpm2_socket.h>
|
||||
#include <wolftpm/tpm2_swtpm.h>
|
||||
|
||||
/******************************************************************************/
|
||||
/* --- 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
|
||||
|
|
|
@ -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 <wolftpm/tpm2.h>
|
||||
#include <wolftpm/tpm2_socket.h>
|
||||
#include <wolftpm/tpm2_swtpm.h>
|
||||
#include <wolftpm/tpm2_packet.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
@ -45,14 +45,14 @@
|
|||
#include <netdb.h>
|
||||
|
||||
|
||||
#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 */
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <wolftpm/tpm2.h>
|
||||
|
||||
|
@ -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_ */
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue