Skip to content

Commit 5f4c09a

Browse files
committed
Support for swtpm port arguments
1 parent a2ee75c commit 5f4c09a

File tree

4 files changed

+60
-14
lines changed

4 files changed

+60
-14
lines changed

.github/workflows/make-test-swtpm.yml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ jobs:
133133
needs_install: true
134134

135135
# Old wolfSSL (v4.7.0)
136+
# Builds latest wolfSSL for examples/client/client and examples/server/server
137+
# Builds old wolfSSL (v4.7.0) for linking wolfTPM against older shared library
136138
- name: old-wolfssl
137-
wolfssl_config: --enable-wolftpm
138-
wolfssl_cflags: "-DWOLFSSL_PUBLIC_MP -DWOLFSSL_TEST_CERT -DWOLFSSL_KEY_GEN"
139-
wolfssl_ref: v4.7.0-stable
140139
test_command: "make check && WOLFSSL_PATH=./wolfssl NO_PUBASPRIV=1 ./examples/run_examples.sh"
141140
needs_install: true
142141

@@ -166,15 +165,33 @@ jobs:
166165
sudo make install
167166
sudo ldconfig
168167
168+
# For old-wolfssl test: checkout and build old wolfSSL for linking
169+
- name: Checkout old wolfSSL
170+
if: matrix.name == 'old-wolfssl'
171+
uses: actions/checkout@master
172+
with:
173+
repository: wolfssl/wolfssl
174+
path: wolfssl-old
175+
ref: v4.7.0-stable
176+
- name: Setup old wolfSSL for linking
177+
if: matrix.name == 'old-wolfssl'
178+
working-directory: ./wolfssl-old
179+
run: |
180+
./autogen.sh
181+
CFLAGS="-DWOLFSSL_PUBLIC_MP -DWOLFSSL_TEST_CERT -DWOLFSSL_KEY_GEN" ./configure --enable-wolftpm
182+
make
183+
sudo make install
184+
sudo ldconfig
185+
169186
- name: Setup ibmswtpm2
170-
if: matrix.needs_swtpm == true || matrix.needs_swtpm == null
187+
if: matrix.needs_swtpm != false
171188
uses: actions/checkout@master
172189
with:
173190
repository: kgoldman/ibmswtpm2
174191
path: ibmswtpm2
175192

176193
- name: Generate TPM port
177-
if: matrix.needs_swtpm == true || matrix.needs_swtpm == null
194+
if: matrix.needs_swtpm != false
178195
run: |
179196
# Generate deterministic port from matrix name (base 40000, spacing 2 for port+1)
180197
MATRIX_HASH=$(echo -n "${{ matrix.name }}" | cksum | cut -d' ' -f1)
@@ -184,7 +201,7 @@ jobs:
184201
echo "Generated TPM port: $TPM_PORT (matrix: ${{ matrix.name }})"
185202
186203
- name: Start TPM simulator
187-
if: matrix.needs_swtpm == true || matrix.needs_swtpm == null
204+
if: matrix.needs_swtpm != false
188205
working-directory: ./ibmswtpm2/src
189206
run: |
190207
make
@@ -202,14 +219,9 @@ jobs:
202219
WOLFTPM_CONFIG="${{ matrix.wolftpm_config || '--enable-swtpm' }}"
203220
WOLFTPM_CFLAGS="${{ matrix.wolftpm_cflags || '' }}"
204221
WOLFTPM_CC="${{ matrix.wolftpm_cc || '' }}"
205-
# Add TPM port to CFLAGS if SWTPM is needed (as string)
222+
# Add TPM port to configure if SWTPM is needed
206223
if [ -n "$TPM_PORT" ]; then
207-
PORT_DEF='-DTPM2_SWTPM_PORT="'$TPM_PORT'"'
208-
if [ -n "$WOLFTPM_CFLAGS" ]; then
209-
WOLFTPM_CFLAGS="$WOLFTPM_CFLAGS $PORT_DEF"
210-
else
211-
WOLFTPM_CFLAGS="$PORT_DEF"
212-
fi
224+
WOLFTPM_CONFIG="$WOLFTPM_CONFIG --with-swtpm-port=$TPM_PORT"
213225
fi
214226
if [ -n "$WOLFTPM_CC" ]; then
215227
if [ -n "$WOLFTPM_CFLAGS" ]; then

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ endif(WIN32)
167167
if("${WOLFTPM_INTERFACE}" STREQUAL "SWTPM")
168168
list(APPEND WOLFTPM_DEFINITIONS "-DWOLFTPM_SWTPM")
169169

170+
# SWTPM port configuration
171+
set(WOLFTPM_SWTPM_PORT "2321" CACHE STRING
172+
"Set SWTPM socket port (default: 2321)")
173+
list(APPEND WOLFTPM_DEFINITIONS "-DTPM2_SWTPM_PORT=\"${WOLFTPM_SWTPM_PORT}\"")
174+
170175
elseif("${WOLFTPM_INTERFACE}" STREQUAL "DEVTPM")
171176
list(APPEND WOLFTPM_DEFINITIONS "-DWOLFTPM_LINUX_DEV")
172177

Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ dist_doc_DATA =
2626
DISTCLEANFILES+= aminclude.am
2727

2828
# make sure we pass the correct flags to distcheck
29-
AM_DISTCHECK_CONFIGURE_FLAGS = --enable-swtpm
29+
# SWTPM_PORT can be set via --with-swtpm-port during configure
30+
# Use @SWTPM_PORT@ substitution from configure.ac
31+
AM_DISTCHECK_CONFIGURE_FLAGS = --enable-swtpm @DISTCHECK_SWTPM_PORT_FLAG@
3032

3133
exampledir = $(docdir)/example
3234
dist_example_DATA=

configure.ac

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ AC_ARG_ENABLE([swtpm],
231231
[ ENABLED_SWTPM=no ]
232232
)
233233

234+
# SWTPM port configuration
235+
SWTPM_PORT="2321"
236+
AC_ARG_WITH([swtpm-port],
237+
[AS_HELP_STRING([--with-swtpm-port=PORT],[Set SWTPM socket port (default: 2321)])],
238+
[
239+
if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
240+
SWTPM_PORT="$withval"
241+
fi
242+
]
243+
)
244+
234245
if test "x$ENABLED_SWTPM" = "xyes"
235246
then
236247
if test "x$ENABLED_DEVTPM" = "xyes"
@@ -239,8 +250,21 @@ then
239250
fi
240251

241252
AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_SWTPM"
253+
AM_CFLAGS="$AM_CFLAGS -DTPM2_SWTPM_PORT=\"$SWTPM_PORT\""
254+
255+
# Set distcheck flag if port is not default (only when SWTPM is enabled)
256+
if test "x$SWTPM_PORT" != "x2321"; then
257+
DISTCHECK_SWTPM_PORT_FLAG="--with-swtpm-port=$SWTPM_PORT"
258+
else
259+
DISTCHECK_SWTPM_PORT_FLAG=""
260+
fi
261+
else
262+
DISTCHECK_SWTPM_PORT_FLAG=""
242263
fi
243264

265+
AC_SUBST([SWTPM_PORT])
266+
AC_SUBST([DISTCHECK_SWTPM_PORT_FLAG])
267+
244268
# Windows TBS device Support
245269
AC_ARG_ENABLE([wintbs],,
246270
[ ENABLED_WINTBS=$enableval ],
@@ -579,6 +603,9 @@ echo " * Advanced IO: $ENABLED_ADVIO"
579603
echo " * I2C: $ENABLED_I2C"
580604
echo " * Linux kernel TPM device: $ENABLED_DEVTPM"
581605
echo " * SWTPM: $ENABLED_SWTPM"
606+
if test "x$ENABLED_SWTPM" = "xyes"; then
607+
echo " * SWTPM Port: $SWTPM_PORT"
608+
fi
582609
echo " * WINAPI: $ENABLED_WINAPI"
583610
echo " * TIS/SPI Check Wait State: $ENABLED_CHECKWAITSTATE"
584611

0 commit comments

Comments
 (0)