Skip to content

Commit ebbfa62

Browse files
committed
Add network namespace isolation, macOS CI, and Windows build support for fwTPM
Use unshare --user --net to isolate fwtpm_check.sh TCP ports in CI, eliminating flaky port conflicts on shared runners. Add macOS CI with socket transport tests. Add Windows socket portability (Winsock2) and build-only CI via CMake.
1 parent 0b2a1c3 commit ebbfa62

9 files changed

Lines changed: 228 additions & 116 deletions

File tree

.github/workflows/cmake-build.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-latest
12+
runs-on: ${{ matrix.config.os || 'ubuntu-latest' }}
1313
strategy:
1414
fail-fast: false
1515
matrix:
@@ -93,13 +93,18 @@ jobs:
9393
# fwTPM server-only mode (no client library or examples)
9494
- name: "fwTPM Only"
9595
options: "-DWOLFTPM_FWTPM_ONLY=yes -DWOLFTPM_INTERFACE=SWTPM"
96+
# fwTPM socket on Windows (build-only)
97+
- name: "fwTPM Socket (Windows)"
98+
options: "-DWOLFTPM_FWTPM=yes -DWOLFTPM_INTERFACE=SWTPM"
99+
os: windows-latest
96100

97101
steps:
98102
#pull wolfTPM
99103
- uses: actions/checkout@master
100104

101105
# Install cmake
102106
- name: Install cmake
107+
if: runner.os == 'Linux'
103108
run: |
104109
sudo apt-get update
105110
sudo apt-get install -y cmake
@@ -112,25 +117,37 @@ jobs:
112117
path: wolfssl
113118
- name: Build wolfssl
114119
working-directory: ./wolfssl
120+
shell: bash
115121
run: |
116122
mkdir build
117123
cd build
124+
EXTRA_CFLAGS="-DWC_RSA_NO_PADDING -DWOLFSSL_PUBLIC_MP"
125+
if [ "$RUNNER_OS" = "Windows" ]; then
126+
# Suppress MSVC struct padding warnings from wolfSSL headers
127+
EXTRA_CFLAGS="$EXTRA_CFLAGS /wd4820"
128+
fi
118129
# wolfSSL PR 7188 broke "make install" unless WOLFSSL_INSTALL is set
119-
cmake -DWOLFSSL_TPM=yes -DWOLFSSL_INSTALL=yes -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install" -DCMAKE_C_FLAGS="-DWC_RSA_NO_PADDING" ..
120-
cmake --build .
121-
cmake --install .
130+
cmake -DWOLFSSL_TPM=yes -DWOLFSSL_INSTALL=yes -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install" -DCMAKE_C_FLAGS="$EXTRA_CFLAGS" ..
131+
cmake --build . --config Release
132+
cmake --install . --config Release
122133
123134
#build wolftpm
124135
- name: Build wolfTPM (${{ matrix.config.name }})
136+
shell: bash
125137
run: |
126138
mkdir build
127139
cd build
128-
cmake ${{ matrix.config.options }} -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install" -DWITH_WOLFSSL="$GITHUB_WORKSPACE/install" ..
129-
cmake --build .
130-
cmake --install .
140+
EXTRA_CFLAGS=""
141+
if [ "$RUNNER_OS" = "Windows" ]; then
142+
EXTRA_CFLAGS="/wd4820"
143+
fi
144+
cmake ${{ matrix.config.options }} -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install" -DWITH_WOLFSSL="$GITHUB_WORKSPACE/install" -DCMAKE_C_FLAGS="$EXTRA_CFLAGS" ..
145+
cmake --build . --config Release
146+
cmake --install . --config Release
131147
132148
- name: Test fwTPM
133149
if: contains(matrix.config.options, 'WOLFTPM_FWTPM')
150+
shell: bash
134151
run: |
135152
cd build
136153
LD_LIBRARY_PATH="$GITHUB_WORKSPACE/install/lib" ctest --output-on-failure

.github/workflows/fwtpm-test.yml

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
# make check — unit tests + examples against fwtpm_server
1212
# ----------------------------------------------------------------
1313
fwtpm-examples:
14-
runs-on: ubuntu-latest
14+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
1515
strategy:
1616
fail-fast: false
1717
matrix:
@@ -148,6 +148,13 @@ jobs:
148148

149149
# Note: ASan / UBSan / LeakSan coverage moved to sanitizer.yml
150150

151+
# macOS: fwTPM with socket transport
152+
- name: fwtpm-macos-socket
153+
wolftpm_config: --enable-fwtpm --enable-swtpm --enable-debug
154+
wolfssl_config: --enable-wolftpm --enable-pkcallbacks --enable-keygen
155+
build_only: false
156+
os: macos-latest
157+
151158
steps:
152159
- name: Checkout wolfTPM
153160
uses: actions/checkout@v4
@@ -161,8 +168,12 @@ jobs:
161168
- name: Install tpm2-tools
162169
if: ${{ !matrix.build_only }}
163170
run: |
164-
sudo apt-get update
165-
sudo apt-get install -y tpm2-tools libtss2-tcti-mssim0
171+
if [ "$(uname)" = "Darwin" ]; then
172+
brew install tpm2-tools
173+
else
174+
sudo apt-get update
175+
sudo apt-get install -y tpm2-tools libtss2-tcti-mssim0
176+
fi
166177
167178
- name: Build wolfSSL
168179
working-directory: ./wolfssl
@@ -182,7 +193,9 @@ jobs:
182193
CC=${{ matrix.cc || 'gcc' }} eval ./configure $CONFIGURE_ARGS
183194
make
184195
sudo make install
185-
sudo ldconfig
196+
if command -v ldconfig >/dev/null 2>&1; then
197+
sudo ldconfig
198+
fi
186199
187200
- name: Build wolfTPM
188201
run: |
@@ -208,7 +221,17 @@ jobs:
208221
if: ${{ !matrix.build_only }}
209222
env:
210223
WOLFSSL_PATH: ./wolfssl
211-
run: make check
224+
run: |
225+
if command -v unshare >/dev/null 2>&1; then
226+
FWTPM_USE_FIXED_PORT=1 \
227+
unshare --user --net --map-root-user /bin/bash -c '
228+
set -e
229+
ip link set lo up
230+
make check
231+
'
232+
else
233+
make check
234+
fi
212235
213236
- name: Print test-suite.log on failure
214237
if: ${{ failure() && !matrix.build_only }}
@@ -404,27 +427,23 @@ jobs:
404427
CFLAGS="${{ matrix.extra_cflags }} -g -O1"
405428
make
406429
407-
- name: Start fwtpm_server
408-
run: |
409-
rm -f fwtpm_nv.bin
410-
./src/fwtpm/fwtpm_server > /tmp/fwtpm_server.log 2>&1 &
411-
echo $! > /tmp/fwtpm_server.pid
412-
sleep 1
413-
kill -0 $(cat /tmp/fwtpm_server.pid)
414-
415430
- name: Run unit.test under valgrind
416431
run: |
417-
valgrind --error-exitcode=1 --leak-check=full \
418-
--errors-for-leak-kinds=definite \
419-
--show-leak-kinds=definite \
420-
./tests/unit.test
421-
422-
- name: Stop fwtpm_server
423-
if: always()
424-
run: |
425-
if [ -f /tmp/fwtpm_server.pid ]; then
426-
kill $(cat /tmp/fwtpm_server.pid) 2>/dev/null || true
427-
fi
432+
unshare --user --net --map-root-user /bin/bash -c '
433+
ip link set lo up
434+
rm -f fwtpm_nv.bin
435+
./src/fwtpm/fwtpm_server > /tmp/fwtpm_server.log 2>&1 &
436+
SERVER_PID=$!
437+
sleep 1
438+
kill -0 $SERVER_PID
439+
valgrind --error-exitcode=1 --leak-check=full \
440+
--errors-for-leak-kinds=definite \
441+
--show-leak-kinds=definite \
442+
./tests/unit.test
443+
RC=$?
444+
kill $SERVER_PID 2>/dev/null || true
445+
exit $RC
446+
'
428447
429448
- name: Upload failure logs
430449
if: failure()

.github/workflows/sanitizer.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ jobs:
7878
LD_LIBRARY_PATH: /tmp/wolfssl-install/lib
7979
ASAN_OPTIONS: ${{ matrix.asan_options }}
8080
UBSAN_OPTIONS: ${{ matrix.ubsan_options }}
81-
run: make check
81+
run: |
82+
FWTPM_USE_FIXED_PORT=1 \
83+
unshare --user --net --map-root-user /bin/bash -c '
84+
set -e
85+
ip link set lo up
86+
make check
87+
'
8288
8389
- name: Upload failure logs
8490
if: failure()

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,13 @@ if(WOLFTPM_FWTPM)
520520
${CMAKE_CURRENT_SOURCE_DIR}
521521
${CMAKE_CURRENT_BINARY_DIR}
522522
)
523-
if(UNIX AND NOT APPLE)
524-
target_link_libraries(fwtpm_server PRIVATE pthread rt)
523+
if(UNIX)
524+
target_link_libraries(fwtpm_server PRIVATE pthread)
525+
if(NOT APPLE)
526+
target_link_libraries(fwtpm_server PRIVATE rt)
527+
endif()
528+
elseif(WIN32)
529+
target_link_libraries(fwtpm_server PRIVATE ws2_32)
525530
endif()
526531

527532
# fwtpm_unit_test executable
@@ -538,7 +543,7 @@ if(WOLFTPM_FWTPM)
538543
${CMAKE_CURRENT_SOURCE_DIR}
539544
${CMAKE_CURRENT_BINARY_DIR}
540545
)
541-
if(UNIX AND NOT APPLE)
546+
if(UNIX)
542547
target_link_libraries(fwtpm_unit_test PRIVATE pthread)
543548
endif()
544549

configure.ac

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ WOLFTPM_DEFAULT_SWTPM=no
233233
case $host_cpu in
234234
x86_64|amd64|aarch64)
235235
# Defensive exclusion: fwtpm_server uses POSIX sockets and is not
236-
# currently portable to Windows / Darwin. Auto-enable on Linux/BSD only.
236+
# currently portable to Windows. Auto-enable on Linux/BSD/macOS only.
237237
case $host_os in
238-
*mingw*|*cygwin*|*msys*|*darwin*|*win32*)
238+
*mingw*|*cygwin*|*msys*|*win32*)
239239
;;
240240
*)
241241
WOLFTPM_DEFAULT_FWTPM=yes
@@ -341,7 +341,13 @@ then
341341
# as a compile flag only for the fwtpm_server target in src/fwtpm/include.am.
342342
if test "x$ENABLED_SWTPM" != "xyes" && test "x$ENABLED_SWTPM" != "xuart"
343343
then
344-
# TIS/shared-memory transport for fwTPM (instead of socket)
344+
# TIS/shared-memory transport uses POSIX mmap/sem_open — not available
345+
# on Windows. Require socket transport (--enable-swtpm) on Windows.
346+
case $host_os in
347+
*mingw*|*cygwin*|*msys*|*win32*)
348+
AC_MSG_ERROR([fwTPM TIS/SHM transport is not supported on Windows. Use --enable-fwtpm --enable-swtpm for socket transport.])
349+
;;
350+
esac
345351
AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_FWTPM_HAL -DWOLFTPM_ADV_IO"
346352
ENABLED_FWTPM_TIS=yes
347353
fi

0 commit comments

Comments
 (0)