From da52584ffc0ffcd6ddce0948831b1940e6af3310 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Mon, 23 Nov 2026 15:54:29 -0800 Subject: [PATCH 1/4] Route the TPM client through the wolfTPM user transport --- include/wolftrust/tpm_psa_transport.h | 3 + src/client/tpm_psa_transport.c | 77 +++++------------- tests/firmware/interface-guest/Makefile | 6 +- tests/firmware/interface-guest/tpm_tests.c | 8 +- tests/host/tpm_client/Makefile | 8 +- tests/host/tpm_client/main.c | 95 +++++++--------------- 6 files changed, 69 insertions(+), 128 deletions(-) diff --git a/include/wolftrust/tpm_psa_transport.h b/include/wolftrust/tpm_psa_transport.h index 8d8f0bb6..3f55e388 100644 --- a/include/wolftrust/tpm_psa_transport.h +++ b/include/wolftrust/tpm_psa_transport.h @@ -42,4 +42,7 @@ int wt_tpm_psa_random(uint8_t* out, size_t len); /* Drop the cached connection (after a transport error or for teardown). */ void wt_tpm_psa_close(void); +/* Route wolfTPM commands through this transport; call before wolfTPM2_Init. */ +int wt_tpm_psa_register(void); + #endif /* WOLFTRUST_TPM_PSA_TRANSPORT_H */ diff --git a/src/client/tpm_psa_transport.c b/src/client/tpm_psa_transport.c index 73f1463c..143a44d2 100644 --- a/src/client/tpm_psa_transport.c +++ b/src/client/tpm_psa_transport.c @@ -97,75 +97,36 @@ int wt_tpm_psa_random(uint8_t* out, size_t len) return rc; } -#if defined(WOLFTPM_SWTPM) -/* wolfTPM client transport: built with WOLFTPM_SWTPM so the core routes - * every command through TPM2_SWTPM_SendCommand, which this file provides in - * place of the socket client. One synchronous call returns the response. */ +#if defined(WOLFTPM_USER_TRANSPORT) #include -#include -#include -#include -/* The core still runs its TIS chip-startup sequence; the mediated door has - * no TIS registers, so startup wait, locality, and device info are no-ops. */ -int TPM2_TIS_StartupWait(TPM2_CTX* ctx, int timeout) +static int wt_tpm_user_send(TPM2_CTX* ctx, const BYTE* cmd, UINT32 cmd_sz, + BYTE* rsp, UINT32 rsp_max, UINT32* rsp_sz, + void* user_ctx) { - (void)ctx; - (void)timeout; - return TPM_RC_SUCCESS; -} - -int TPM2_TIS_RequestLocality(TPM2_CTX* ctx, int timeout) -{ - if (ctx == NULL) { - return BAD_FUNC_ARG; - } - (void)timeout; - ctx->locality = WOLFTPM_LOCALITY_DEFAULT; - return TPM_RC_SUCCESS; -} + size_t got = 0U; + int rc; -int TPM2_TIS_GetInfo(TPM2_CTX* ctx) -{ (void)ctx; - return TPM_RC_SUCCESS; + (void)user_ctx; + rc = wt_tpm_psa_transact(cmd, (size_t)cmd_sz, rsp, (size_t)rsp_max, + &got); + if (rc == 0) { + *rsp_sz = (UINT32)got; + } + return rc; } -void TPM2_SwtpmClose(TPM2_CTX* ctx) +static void wt_tpm_user_close(TPM2_CTX* ctx, void* user_ctx) { (void)ctx; + (void)user_ctx; wt_tpm_psa_close(); } -int TPM2_SWTPM_SendCommand(TPM2_CTX* ctx, TPM2_Packet* packet) +int wt_tpm_psa_register(void) { - size_t rsp_len = 0U; - uint32_t declared; - int rc; - - (void)ctx; - if (packet == NULL || packet->buf == NULL || packet->pos <= 0 || - packet->size <= 0 || packet->pos > packet->size) { - return BAD_FUNC_ARG; - } - rc = wt_tpm_psa_transact(packet->buf, (size_t)packet->pos, packet->buf, - (size_t)packet->size, &rsp_len); - if (rc != 0 || rsp_len < (size_t)TPM2_HEADER_SIZE || - rsp_len > (size_t)packet->size) { - return TPM_RC_FAILURE; - } - /* The response header declares its own total length; reject a mediated - * frame whose body length disagrees rather than let the core parse stale - * buffer tail past the bytes actually received. */ - declared = ((uint32_t)packet->buf[2] << 24) | - ((uint32_t)packet->buf[3] << 16) | - ((uint32_t)packet->buf[4] << 8) | - (uint32_t)packet->buf[5]; - if (declared != (uint32_t)rsp_len) { - return TPM_RC_FAILURE; - } - /* Bind the parser to the bytes actually received. */ - packet->size = (int)rsp_len; - return TPM_RC_SUCCESS; + return (int)TPM2_SetUserTransport(wt_tpm_user_send, wt_tpm_user_close, + NULL); } -#endif /* WOLFTPM_SWTPM */ +#endif /* WOLFTPM_USER_TRANSPORT */ diff --git a/tests/firmware/interface-guest/Makefile b/tests/firmware/interface-guest/Makefile index 2f8353f2..d0dd61b1 100644 --- a/tests/firmware/interface-guest/Makefile +++ b/tests/firmware/interface-guest/Makefile @@ -87,7 +87,7 @@ SRCS := main.c ../psa-guest/guest_libc.c $(ROOT)/src/client/psa_ffm_client.c ifeq ($(WT_INTERFACE),tpm) APP_NAME := tpm-guest0 CFLAGS += -I$(WOLFTPM_DIR) -DWOLFTPM_USER_SETTINGS -DWT_TPM_ROLE_APP \ - -DWOLFTPM_SWTPM -DWOLF_CRYPTO_CB -DWOLFTPM_CRYPTOCB -DWOLFTPM_SMALL_STACK \ + -DWOLFTPM_USER_TRANSPORT -DWOLF_CRYPTO_CB -DWOLFTPM_CRYPTOCB -DWOLFTPM_SMALL_STACK \ -DWT_INTERFACE_TPM -DWT_TPM_APP_NAME=\"$(APP_NAME)\" \ -DWOLFSSL_SP_ASM -DWOLFSSL_SP_ARM_CORTEX_M_ASM -DWOLFSSL_ARM_ARCH=8 \ -DNO_ERROR_STRINGS -DWOLFSSL_PUBLIC_MP -DWC_RSA_DIRECT \ @@ -100,8 +100,8 @@ SRCS += tpm_tests.c $(ROOT)/src/client/tpm_psa_transport.c \ $(addprefix $(WOLFSSL_DIR)/wolfcrypt/src/, aes.c cryptocb.c ecc.c \ random.c sha256.c asn.c coding.c error.c hash.c hmac.c memory.c sha.c \ sp_cortexm.c sp_int.c wolfmath.c wc_port.c sha512.c kdf.c pwdbased.c) -KEEP := -Wl,-u,wt_tpm_psa_transact,-u,TPM2_SWTPM_SendCommand -WIRED := wt_tpm_psa_transact TPM2_SWTPM_SendCommand wt_tpm_psa_random +KEEP := -Wl,-u,wt_tpm_psa_transact,-u,TPM2_SetUserTransport +WIRED := wt_tpm_psa_transact wt_tpm_psa_register TPM2_SetUserTransport wt_tpm_psa_random ABSENT := 'fwTPM|FWTPM_|WP11_|wh_Client|wt_crypto_native' else APP_NAME := pkcs11-guest0 diff --git a/tests/firmware/interface-guest/tpm_tests.c b/tests/firmware/interface-guest/tpm_tests.c index e8bf5c81..2318c3ce 100644 --- a/tests/firmware/interface-guest/tpm_tests.c +++ b/tests/firmware/interface-guest/tpm_tests.c @@ -393,8 +393,14 @@ int wt_tpm_run(void) int sig_size = (int)sizeof(sig); int pcr_size = (int)sizeof(pcr); int tries; - int rc = -1; + int rc; + rc = wt_tpm_psa_register(); + if (rc != 0) { + app_line_i32("tpm transport FAILED rc=", rc); + return -1; + } + rc = -1; for (tries = 0; tries < 50 && rc != 0; tries++) { rc = wolfTPM2_Init(&g_dev, NULL, NULL); if (rc != 0) { diff --git a/tests/host/tpm_client/Makefile b/tests/host/tpm_client/Makefile index e9e84e8b..b4df7c9c 100644 --- a/tests/host/tpm_client/Makefile +++ b/tests/host/tpm_client/Makefile @@ -24,7 +24,7 @@ CC ?= cc BUILD_DIR ?= build CFLAGS := \ - -DWOLFTPM_SWTPM \ + -DWOLFTPM_USER_TRANSPORT \ -DWOLFTPM_USER_SETTINGS \ -DWOLFTPM2_NO_WOLFCRYPT \ -DSINGLE_THREADED \ @@ -46,10 +46,11 @@ endif _SRCS := \ $(ROOT)/src/client/tpm_psa_transport.c \ $(WOLFTPM)/src/tpm2.c \ + $(WOLFTPM)/src/tpm2_packet.c \ $(WOLFTPM)/src/tpm2_util.c \ main.c -_OBJS := $(addprefix $(BUILD_DIR)/,msg_client.o tpm_psa_transport.o tpm2.o tpm2_util.o main.o) +_OBJS := $(addprefix $(BUILD_DIR)/,msg_client.o tpm_psa_transport.o tpm2.o tpm2_packet.o tpm2_util.o main.o) TEST_BIN := $(BUILD_DIR)/test_tpm_client .PHONY: all run compilers sanitize valgrind clean @@ -68,6 +69,9 @@ $(BUILD_DIR)/msg_client.o: $(ROOT)/src/client/msg_client.c | $(BUILD_DIR) $(BUILD_DIR)/tpm2.o: $(WOLFTPM)/src/tpm2.c | $(BUILD_DIR) $(CC) $(CFLAGS) -c -o $@ $< +$(BUILD_DIR)/tpm2_packet.o: $(WOLFTPM)/src/tpm2_packet.c | $(BUILD_DIR) + $(CC) $(CFLAGS) -c -o $@ $< + $(BUILD_DIR)/tpm2_util.o: $(WOLFTPM)/src/tpm2_util.c | $(BUILD_DIR) $(CC) $(CFLAGS) -c -o $@ $< diff --git a/tests/host/tpm_client/main.c b/tests/host/tpm_client/main.c index 371bb2bd..4d806619 100644 --- a/tests/host/tpm_client/main.c +++ b/tests/host/tpm_client/main.c @@ -19,7 +19,7 @@ */ /* TPM PSA client suite: a scripted PSA transport checks connection recovery, - * synchronous execution, response framing, and the SWTPM initialization contract. */ + * synchronous execution, response framing, and the user transport contract. */ #include "psa/client.h" #include "psa/error.h" @@ -27,7 +27,6 @@ #include #include -#include #include #include @@ -189,12 +188,13 @@ static void set_success_response(size_t declared, size_t received) g_response_len = received; } -static void packet_init(TPM2_Packet* packet, uint8_t* frame, size_t size) +static TPM_RC send_startup(void) { - (void)memset(frame, 0, size); - packet->buf = frame; - packet->size = (int)size; - packet->pos = TPM2_HEADER_SIZE; + Startup_In in; + + (void)memset(&in, 0, sizeof(in)); + in.startupType = TPM_SU_CLEAR; + return TPM2_Startup(&in); } static void test_arguments(void) @@ -256,94 +256,60 @@ static void test_connection_recovery(void) static void test_execution_and_framing(void) { TPM2_CTX ctx; - TPM2_Packet packet; - uint8_t frame[32]; - int rc; + + check(TPM2_Init(&ctx, NULL, NULL) == TPM_RC_SUCCESS, + "user transport initializes without a TIS startup"); mock_reset(); - packet_init(&packet, frame, sizeof(frame)); set_success_response(TPM2_HEADER_SIZE, TPM2_HEADER_SIZE); - rc = TPM2_SWTPM_SendCommand(&ctx, &packet); - check(rc == TPM_RC_SUCCESS && g_calls == 1 && - packet.size == TPM2_HEADER_SIZE, + check(send_startup() == TPM_RC_SUCCESS && g_calls == 1, "one synchronous call returns the framed response"); mock_reset(); - packet_init(&packet, frame, sizeof(frame)); g_call_status = PSA_ERROR_CONNECTION_BUSY; - rc = TPM2_SWTPM_SendCommand(&ctx, &packet); - check(rc == TPM_RC_FAILURE && g_calls == 1, + check(send_startup() == TPM_RC_FAILURE && g_calls == 1, "a failed command is never implicitly replayed"); mock_reset(); - packet_init(&packet, frame, sizeof(frame)); set_success_response(TPM2_HEADER_SIZE, TPM2_HEADER_SIZE - 1U); - check(TPM2_SWTPM_SendCommand(&ctx, &packet) == TPM_RC_FAILURE, + check(send_startup() == TPM_RC_FAILURE, "a response shorter than the TPM header is refused"); mock_reset(); - packet_init(&packet, frame, sizeof(frame)); set_success_response(TPM2_HEADER_SIZE + 1U, TPM2_HEADER_SIZE); - check(TPM2_SWTPM_SendCommand(&ctx, &packet) == TPM_RC_FAILURE, + check(send_startup() == TPM_RC_FAILURE, "a response whose declared length disagrees is refused"); mock_reset(); - packet_init(&packet, frame, sizeof(frame)); set_success_response(TPM2_HEADER_SIZE, TPM2_HEADER_SIZE); - g_forced_out_len = sizeof(frame) + 1U; - check(TPM2_SWTPM_SendCommand(&ctx, &packet) == TPM_RC_FAILURE, + g_forced_out_len = WT_TPM_FRAME_MAX + 1U; + check(send_startup() == TPM_RC_FAILURE, "a response reported beyond the packet capacity is refused"); -} - -static void test_packet_bounds(void) -{ - TPM2_CTX ctx; - TPM2_Packet packet; - uint8_t frame[32]; - mock_reset(); - packet_init(&packet, frame, sizeof(frame)); - packet.size = 0; - check(TPM2_SWTPM_SendCommand(&ctx, &packet) == BAD_FUNC_ARG && - g_connects == 0 && g_calls == 0, - "SWTPM transport rejects a zero packet capacity before I/O"); - - packet_init(&packet, frame, sizeof(frame)); - packet.size = -1; - check(TPM2_SWTPM_SendCommand(&ctx, &packet) == BAD_FUNC_ARG && - g_connects == 0 && g_calls == 0, - "SWTPM transport rejects a negative packet capacity before I/O"); - - packet_init(&packet, frame, sizeof(frame)); - packet.pos = packet.size + 1; - check(TPM2_SWTPM_SendCommand(&ctx, &packet) == BAD_FUNC_ARG && - g_connects == 0 && g_calls == 0, - "SWTPM transport rejects a command beyond packet capacity"); + (void)TPM2_Cleanup(&ctx); } -static void test_locality_contract(void) +static void test_init_contract(void) { TPM2_CTX ctx; int rc; mock_reset(); - check(TPM2_TIS_RequestLocality(NULL, 1) == BAD_FUNC_ARG, - "locality request rejects a NULL context"); rc = TPM2_Init(&ctx, NULL, NULL); check(rc == TPM_RC_SUCCESS && ctx.locality == WOLFTPM_LOCALITY_DEFAULT && TPM2_GetActiveCtx() == &ctx, - "direct TPM initialization records the granted locality"); + "direct TPM initialization uses the default locality"); + set_success_response(TPM2_HEADER_SIZE, TPM2_HEADER_SIZE); + check(send_startup() == TPM_RC_SUCCESS && g_connects == 1, + "the first command opens the service connection"); check(TPM2_Cleanup(&ctx) == TPM_RC_SUCCESS && - TPM2_GetActiveCtx() == NULL, - "direct TPM cleanup clears the active context"); + TPM2_GetActiveCtx() == NULL && g_closes == 1, + "TPM cleanup closes the service connection"); - rc = TPM2_Init_ex(&ctx, NULL, NULL, 1); - check(rc == TPM_RC_SUCCESS && ctx.locality == WOLFTPM_LOCALITY_DEFAULT && - TPM2_GetActiveCtx() == &ctx, - "explicit SWTPM startup records the granted locality"); - check(TPM2_Cleanup(&ctx) == TPM_RC_SUCCESS && - TPM2_GetActiveCtx() == NULL, - "explicit SWTPM startup remains cleanup-safe"); + check(TPM2_Init_ex(&ctx, NULL, NULL, 1) == BAD_FUNC_ARG && + g_calls == 1, + "a TIS chip startup is refused without I/O"); + (void)TPM2_Cleanup(&ctx); } static int rng_stream_ok(const uint8_t* out, size_t len) @@ -473,11 +439,12 @@ static void test_random(void) int main(void) { + check(wt_tpm_psa_register() == 0, + "the PSA transport registers with wolfTPM"); test_arguments(); test_connection_recovery(); test_execution_and_framing(); - test_packet_bounds(); - test_locality_contract(); + test_init_contract(); test_random(); wt_tpm_psa_close(); From 40bfc6e72fcdf7c4db98783c6462086cb9984b06 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Tue, 24 Nov 2026 11:35:28 -0800 Subject: [PATCH 2/4] Document registering the wolfTPM user transport --- docs/TPM.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/TPM.md b/docs/TPM.md index 67b06635..7d3db4df 100644 --- a/docs/TPM.md +++ b/docs/TPM.md @@ -50,6 +50,42 @@ interface profile follows the runner's `WT_PROFILE` unless `WT_INTERFACE_PROFILE` is set. [Footprint](Footprint.md#tpm-20-and-pkcs11) has the Secure image and application sizes for every port and engine. +## Application setup + +The application builds wolfTPM with `WOLFTPM_USER_TRANSPORT`, which is +wolfTPM's application transport (`--enable-usertransport`, or CMake +`WOLFTPM_INTERFACE=USER`), and links `src/client/tpm_psa_transport.c`. Before +it initializes wolfTPM, it calls `wt_tpm_psa_register()` once: + +```c +#include +#include + +WOLFTPM2_DEV dev; +int rc; + +rc = wt_tpm_psa_register(); +if (rc == 0) { + rc = wolfTPM2_Init(&dev, NULL, NULL); +} +/* ... TPM2_* and wolfTPM2_* calls ... */ +wolfTPM2_Cleanup(&dev); +``` + +`wt_tpm_psa_register()` hands wolfTPM a send callback and a close callback +through `TPM2_SetUserTransport()`, and returns its result. After that, every +command that wolfTPM builds goes to `wt_tpm_psa_transact()`. That function +sends the command to `SERVICE_TPM` in one call and returns the response for +wolfTPM to parse. `wolfTPM2_Cleanup()` closes the PSA connection once, through +the close callback. The application never handles TPM frames itself, and it +does not override any wolfTPM function. `tests/firmware/interface-guest/tpm_tests.c` +is the reference client. + +Register before any thread initializes wolfTPM, because the registration is not +thread safe. Each wolfTPM context keeps the registration it was initialized +with. wolfTPM's [application transport](https://github.com/wolfSSL/wolfTPM/blob/master/docs/system-interfaces.md#application-transport) +documents the callback contract. + ## Service boundary The application links the wolfTPM client and `SERVICE_TPM` transport. It does From 79e8f1a7ef893cc3946de413d9753551c81a5893 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Tue, 24 Nov 2026 15:37:13 -0800 Subject: [PATCH 3/4] Pass the PSA transport to wolfTPM as its IO callback --- docs/TPM.md | 29 ++++++++-------------- include/wolftrust/tpm_psa_transport.h | 10 ++++++-- src/client/tpm_psa_transport.c | 20 ++------------- tests/firmware/interface-guest/Makefile | 4 +-- tests/firmware/interface-guest/tpm_tests.c | 11 +++----- tests/host/tpm_client/main.c | 16 ++++++------ 6 files changed, 35 insertions(+), 55 deletions(-) diff --git a/docs/TPM.md b/docs/TPM.md index 7d3db4df..d2f6c712 100644 --- a/docs/TPM.md +++ b/docs/TPM.md @@ -54,8 +54,8 @@ has the Secure image and application sizes for every port and engine. The application builds wolfTPM with `WOLFTPM_USER_TRANSPORT`, which is wolfTPM's application transport (`--enable-usertransport`, or CMake -`WOLFTPM_INTERFACE=USER`), and links `src/client/tpm_psa_transport.c`. Before -it initializes wolfTPM, it calls `wt_tpm_psa_register()` once: +`WOLFTPM_INTERFACE=USER`), and links `src/client/tpm_psa_transport.c`. It +passes `wt_tpm_psa_io` as the wolfTPM IO callback: ```c #include @@ -64,26 +64,19 @@ it initializes wolfTPM, it calls `wt_tpm_psa_register()` once: WOLFTPM2_DEV dev; int rc; -rc = wt_tpm_psa_register(); -if (rc == 0) { - rc = wolfTPM2_Init(&dev, NULL, NULL); -} +rc = wolfTPM2_Init(&dev, wt_tpm_psa_io, NULL); /* ... TPM2_* and wolfTPM2_* calls ... */ wolfTPM2_Cleanup(&dev); +wt_tpm_psa_close(); ``` -`wt_tpm_psa_register()` hands wolfTPM a send callback and a close callback -through `TPM2_SetUserTransport()`, and returns its result. After that, every -command that wolfTPM builds goes to `wt_tpm_psa_transact()`. That function -sends the command to `SERVICE_TPM` in one call and returns the response for -wolfTPM to parse. `wolfTPM2_Cleanup()` closes the PSA connection once, through -the close callback. The application never handles TPM frames itself, and it -does not override any wolfTPM function. `tests/firmware/interface-guest/tpm_tests.c` -is the reference client. - -Register before any thread initializes wolfTPM, because the registration is not -thread safe. Each wolfTPM context keeps the registration it was initialized -with. wolfTPM's [application transport](https://github.com/wolfSSL/wolfTPM/blob/master/docs/system-interfaces.md#application-transport) +In this build wolfTPM's IO callback carries a whole command, so every command +that wolfTPM builds goes to `wt_tpm_psa_transact()`. That function sends the +command to `SERVICE_TPM` in one call and returns the response for wolfTPM to +parse. `wt_tpm_psa_close()` drops the PSA connection when the application is +done. The application never handles TPM frames itself, and it does not override +any wolfTPM function. `tests/firmware/interface-guest/tpm_tests.c` is the +reference client. wolfTPM's [application transport](https://github.com/wolfSSL/wolfTPM/blob/master/docs/system-interfaces.md#application-transport) documents the callback contract. ## Service boundary diff --git a/include/wolftrust/tpm_psa_transport.h b/include/wolftrust/tpm_psa_transport.h index 3f55e388..9fb25c57 100644 --- a/include/wolftrust/tpm_psa_transport.h +++ b/include/wolftrust/tpm_psa_transport.h @@ -42,7 +42,13 @@ int wt_tpm_psa_random(uint8_t* out, size_t len); /* Drop the cached connection (after a transport error or for teardown). */ void wt_tpm_psa_close(void); -/* Route wolfTPM commands through this transport; call before wolfTPM2_Init. */ -int wt_tpm_psa_register(void); +#if defined(WOLFTPM_USER_TRANSPORT) +#include + +/* wolfTPM IO callback for this transport: wolfTPM2_Init(&dev, wt_tpm_psa_io, + * NULL). Call wt_tpm_psa_close() after wolfTPM2_Cleanup. */ +int wt_tpm_psa_io(TPM2_CTX* ctx, const BYTE* cmd, UINT32 cmd_sz, BYTE* rsp, + UINT32 rsp_max, UINT32* rsp_sz, void* user_ctx); +#endif #endif /* WOLFTRUST_TPM_PSA_TRANSPORT_H */ diff --git a/src/client/tpm_psa_transport.c b/src/client/tpm_psa_transport.c index 143a44d2..935e64cc 100644 --- a/src/client/tpm_psa_transport.c +++ b/src/client/tpm_psa_transport.c @@ -98,11 +98,8 @@ int wt_tpm_psa_random(uint8_t* out, size_t len) } #if defined(WOLFTPM_USER_TRANSPORT) -#include - -static int wt_tpm_user_send(TPM2_CTX* ctx, const BYTE* cmd, UINT32 cmd_sz, - BYTE* rsp, UINT32 rsp_max, UINT32* rsp_sz, - void* user_ctx) +int wt_tpm_psa_io(TPM2_CTX* ctx, const BYTE* cmd, UINT32 cmd_sz, BYTE* rsp, + UINT32 rsp_max, UINT32* rsp_sz, void* user_ctx) { size_t got = 0U; int rc; @@ -116,17 +113,4 @@ static int wt_tpm_user_send(TPM2_CTX* ctx, const BYTE* cmd, UINT32 cmd_sz, } return rc; } - -static void wt_tpm_user_close(TPM2_CTX* ctx, void* user_ctx) -{ - (void)ctx; - (void)user_ctx; - wt_tpm_psa_close(); -} - -int wt_tpm_psa_register(void) -{ - return (int)TPM2_SetUserTransport(wt_tpm_user_send, wt_tpm_user_close, - NULL); -} #endif /* WOLFTPM_USER_TRANSPORT */ diff --git a/tests/firmware/interface-guest/Makefile b/tests/firmware/interface-guest/Makefile index d0dd61b1..fdb2f976 100644 --- a/tests/firmware/interface-guest/Makefile +++ b/tests/firmware/interface-guest/Makefile @@ -100,8 +100,8 @@ SRCS += tpm_tests.c $(ROOT)/src/client/tpm_psa_transport.c \ $(addprefix $(WOLFSSL_DIR)/wolfcrypt/src/, aes.c cryptocb.c ecc.c \ random.c sha256.c asn.c coding.c error.c hash.c hmac.c memory.c sha.c \ sp_cortexm.c sp_int.c wolfmath.c wc_port.c sha512.c kdf.c pwdbased.c) -KEEP := -Wl,-u,wt_tpm_psa_transact,-u,TPM2_SetUserTransport -WIRED := wt_tpm_psa_transact wt_tpm_psa_register TPM2_SetUserTransport wt_tpm_psa_random +KEEP := -Wl,-u,wt_tpm_psa_transact,-u,wt_tpm_psa_io +WIRED := wt_tpm_psa_transact wt_tpm_psa_io wt_tpm_psa_random ABSENT := 'fwTPM|FWTPM_|WP11_|wh_Client|wt_crypto_native' else APP_NAME := pkcs11-guest0 diff --git a/tests/firmware/interface-guest/tpm_tests.c b/tests/firmware/interface-guest/tpm_tests.c index 2318c3ce..462328db 100644 --- a/tests/firmware/interface-guest/tpm_tests.c +++ b/tests/firmware/interface-guest/tpm_tests.c @@ -393,16 +393,10 @@ int wt_tpm_run(void) int sig_size = (int)sizeof(sig); int pcr_size = (int)sizeof(pcr); int tries; - int rc; + int rc = -1; - rc = wt_tpm_psa_register(); - if (rc != 0) { - app_line_i32("tpm transport FAILED rc=", rc); - return -1; - } - rc = -1; for (tries = 0; tries < 50 && rc != 0; tries++) { - rc = wolfTPM2_Init(&g_dev, NULL, NULL); + rc = wolfTPM2_Init(&g_dev, wt_tpm_psa_io, NULL); if (rc != 0) { wt_tpm_psa_close(); wt_tpm_wait(); @@ -516,6 +510,7 @@ int wt_tpm_run(void) app_line("tpm lockout ok"); #endif (void)wolfTPM2_Cleanup(&g_dev); + wt_tpm_psa_close(); app_line("tpm round trip ok"); return 0; } diff --git a/tests/host/tpm_client/main.c b/tests/host/tpm_client/main.c index 4d806619..22103441 100644 --- a/tests/host/tpm_client/main.c +++ b/tests/host/tpm_client/main.c @@ -257,7 +257,7 @@ static void test_execution_and_framing(void) { TPM2_CTX ctx; - check(TPM2_Init(&ctx, NULL, NULL) == TPM_RC_SUCCESS, + check(TPM2_Init(&ctx, wt_tpm_psa_io, NULL) == TPM_RC_SUCCESS, "user transport initializes without a TIS startup"); mock_reset(); @@ -295,7 +295,9 @@ static void test_init_contract(void) int rc; mock_reset(); - rc = TPM2_Init(&ctx, NULL, NULL); + check(TPM2_Init(&ctx, NULL, NULL) == BAD_FUNC_ARG && g_calls == 0, + "initialization without the PSA IO callback is refused"); + rc = TPM2_Init(&ctx, wt_tpm_psa_io, NULL); check(rc == TPM_RC_SUCCESS && ctx.locality == WOLFTPM_LOCALITY_DEFAULT && TPM2_GetActiveCtx() == &ctx, "direct TPM initialization uses the default locality"); @@ -303,10 +305,12 @@ static void test_init_contract(void) check(send_startup() == TPM_RC_SUCCESS && g_connects == 1, "the first command opens the service connection"); check(TPM2_Cleanup(&ctx) == TPM_RC_SUCCESS && - TPM2_GetActiveCtx() == NULL && g_closes == 1, - "TPM cleanup closes the service connection"); + TPM2_GetActiveCtx() == NULL && g_closes == 0, + "TPM cleanup leaves the service connection to the caller"); + wt_tpm_psa_close(); + check(g_closes == 1, "closing the transport closes the connection"); - check(TPM2_Init_ex(&ctx, NULL, NULL, 1) == BAD_FUNC_ARG && + check(TPM2_Init_ex(&ctx, wt_tpm_psa_io, NULL, 1) == BAD_FUNC_ARG && g_calls == 1, "a TIS chip startup is refused without I/O"); (void)TPM2_Cleanup(&ctx); @@ -439,8 +443,6 @@ static void test_random(void) int main(void) { - check(wt_tpm_psa_register() == 0, - "the PSA transport registers with wolfTPM"); test_arguments(); test_connection_recovery(); test_execution_and_framing(); From bab86a2144dd57edfbab3d063bd84174f3026372 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Wed, 25 Nov 2026 13:46:12 -0800 Subject: [PATCH 4/4] Pin wolfTPM to the release with the application transport --- .github/workflows/auto-pin-dependencies.yml | 2 +- lib/wolfTPM | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-pin-dependencies.yml b/.github/workflows/auto-pin-dependencies.yml index 92bec33c..0a9bee24 100644 --- a/.github/workflows/auto-pin-dependencies.yml +++ b/.github/workflows/auto-pin-dependencies.yml @@ -40,7 +40,7 @@ jobs: "lib/wolfSSL|https://github.com/wolfSSL/wolfSSL.git|v*-stable|51975e27a5439668733976a584d417dfd7776026" "lib/wolfHSM|https://github.com/wolfSSL/wolfHSM.git|wolfHSM-v*|66e2482333ff175a14d10a25c501367362212a38" "lib/wolfIP|https://github.com/wolfSSL/wolfIP.git|v*|" - "lib/wolfTPM|https://github.com/wolfSSL/wolfTPM.git|v*|e9da7bab386f40bd8959c47590d4a9b328eb9121" + "lib/wolfTPM|https://github.com/wolfSSL/wolfTPM.git|v*|899abf15dc785d51c14592c23df071604b839a64" "lib/wolfPKCS11|https://github.com/wolfSSL/wolfPKCS11.git|v*-stable|270a337ab6aa47feb7f60fa5a7a736e01c9da9ee" ) diff --git a/lib/wolfTPM b/lib/wolfTPM index e9da7bab..899abf15 160000 --- a/lib/wolfTPM +++ b/lib/wolfTPM @@ -1 +1 @@ -Subproject commit e9da7bab386f40bd8959c47590d4a9b328eb9121 +Subproject commit 899abf15dc785d51c14592c23df071604b839a64