Skip to content

Fixes to support Firmware TPM swtpm transport server on Windows - #623

Merged
aidangarske merged 1 commit into
wolfSSL:masterfrom
dgarske:fwtpm_win_socket
Oct 6, 2026
Merged

aidangarske merged 1 commit into
wolfSSL:masterfrom
dgarske:fwtpm_win_socket

Conversation

@dgarske

@dgarske dgarske commented Oct 6, 2026

Copy link
Copy Markdown
Member

Description

The socket transport has not worked on Windows. wolfTPM_tcpContext.fd is an int, while a Winsock SOCKET is an unsigned pointer-width handle and is not a C runtime file descriptor.

  • tcpCtx.fd is uintptr_t on Windows. The fd < 0 guards, which cannot fire on an unsigned type, now use an invalid-socket sentinel.
  • read(), write() and close() do not accept a SOCKET. The transport uses recv, send and closesocket there; UART mode keeps the POSIX calls.
  • SwTpmConnect() called getaddrinfo() before WSAStartup().
  • setsockopt() was passed void* where Winsock declares const char*.
  • FWTPM_IO_ServerLoop() held socket handles in int maxFd, and four connection handlers took int clientFd.
  • SOCKET_INVALID was 0xFFFFFFFF, which matches no socket on a 64 bit build.

Non-Windows builds generate identical code.

Hardware / test status

Linux x86-64: TLS 1.3 handshake against the firmware TPM, ML-KEM-768 key exchange, ML-DSA-65 identity held in the TPM.
Windows x64, MSYS2, mingw-w64 gcc 13.2.0, -Werror on: same handshake completes; previously the transport could not connect at all.

@dgarske dgarske self-assigned this Oct 6, 2026
Copilot AI balanced review requested due to automatic review settings October 6, 2026 03:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The socket-width, lifecycle, API, and platform-specific changes are consistent and covered by an end-to-end Windows workflow.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes Windows socket-handle compatibility for swtpm transport and adds end-to-end Windows coverage.

Changes:

  • Uses pointer-width socket types, correct invalid sentinels, and Winsock APIs.
  • Corrects fwTPM server and TLS example socket handling.
  • Adds a Windows MSYS2 transport test.
File Description
wolftpm/​tpm2.h Widens Windows socket storage.
wolftpm/​tpm2_socket.h Defines portable invalid-socket handling.
src/​tpm2_swtpm.c Adds correct Winsock initialization and I/O.
src/​fwtpm/​fwtpm_io.c Preserves Windows socket width in server paths.
examples/​tls/​tls_server.c Initializes sockets with the portable sentinel.
examples/​tls/​tls_common.h Uses portable socket validity checks.
examples/​tls/​tls_client.c Initializes sockets with the portable sentinel.
.github/​workflows/​win-swtpm-test.yml Adds Windows swtpm integration coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dgarske dgarske assigned wolfSSL-Bot and aidangarske and unassigned dgarske Oct 6, 2026
@dgarske
dgarske requested a review from aidangarske October 6, 2026 17:57
@aidangarske
aidangarske merged commit 1b76090 into wolfSSL:master Oct 6, 2026
234 checks passed
@aidangarske
aidangarske deleted the fwtpm_win_socket branch October 6, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants