Skip to content

Commit 4cef60f

Browse files
committed
feat(sbom): capture build config via WOLFHSM_CFG_DIR
1 parent 4c0af52 commit 4cef60f

2 files changed

Lines changed: 51 additions & 3 deletions

File tree

Makefile

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ clean:
6060
# ---- SBOM generation ----
6161
CC ?= cc
6262
WOLFSSL_DIR ?= ../wolfssl
63+
WOLFHSM_CFG_DIR ?= test/config
6364
VERSION = $(shell sed -n 's/^. wolfHSM Release v//p' ChangeLog.md | head -1 | cut -d' ' -f1)
6465
SRCS := $(sort $(wildcard src/*.c))
6566
SBOM_CDX = wolfhsm-$(VERSION).cdx.json
@@ -84,12 +85,41 @@ sbom:
8485
echo " Set WOLFSSL_DIR to such a tree." >&2; \
8586
exit 1; \
8687
fi
88+
@if [ ! -f "$(WOLFHSM_CFG_DIR)/wolfhsm_cfg.h" ]; then \
89+
echo "ERROR: $(WOLFHSM_CFG_DIR)/wolfhsm_cfg.h not found." >&2; \
90+
echo " Set WOLFHSM_CFG_DIR to the directory holding the" >&2; \
91+
echo " wolfhsm_cfg.h (and user_settings.h) your build uses." >&2; \
92+
exit 1; \
93+
fi
8794
@echo "wolfHSM version: $(VERSION)"
8895
@echo "Sources: $(words $(SRCS)) .c files in src/"
96+
@echo "Config: $(WOLFHSM_CFG_DIR)/wolfhsm_cfg.h"
97+
# Effective build config for the SBOM: preprocess wolfhsm/wh_settings.h with
98+
# the same defines and include path the test build compiles under, so the -dM
99+
# dump holds every WOLFHSM_CFG_* option (explicit and defaulted) plus the
100+
# wolfSSL options from user_settings.h — the configuration the library is
101+
# actually built with. Point WOLFHSM_CFG_DIR at the directory holding your
102+
# build's wolfhsm_cfg.h/user_settings.h for an integrator-accurate SBOM.
103+
#
104+
# ponytail: wh_settings.h pulls libc headers (stdint/stdio/strings/stdatomic),
105+
# so ~330 toolchain constants (INT16_MAX, ACCESSPERMS, ...) ride along into
106+
# the SBOM next to the ~175 real config macros. The dump is deliberately NOT
107+
# filtered here: a prefix allowlist would silently drop real options that
108+
# carry no standard prefix (GCM_TABLE_4BIT, FP_MAX_BITS, SINGLE_THREADED).
109+
# The durable fix belongs in gen-sbom's noise filter (wolfSSL PR #10343,
110+
# scripts/gen-sbom _NOISE_MACRO_RE), either of:
111+
# a) provenance filtering: accept a -dD dump and use its #line markers to
112+
# drop macros defined in system headers, or
113+
# b) an --options-baseline flag: subtract a second -dM dump made with the
114+
# same flags minus the -include, plus the libc headers it pulls.
115+
# Once gen-sbom grows that, this recipe needs no change — it already hands
116+
# over the full dump.
89117
@_defines=$$(mktemp "$${TMPDIR:-/tmp}/wolfhsm-defines.XXXXXX") && \
90118
trap 'rm -f "$$_defines"' 0 && \
91-
if ! $(CC) -dM -E -I. -I$(WOLFSSL_DIR) -x c /dev/null >"$$_defines" 2>/dev/null; then \
92-
echo "ERROR: $(CC) -dM -E failed." >&2; exit 1; \
119+
if ! $(CC) -dM -E -DWOLFHSM_CFG -DWOLFSSL_USER_SETTINGS \
120+
-I. -I$(WOLFHSM_CFG_DIR) -I$(WOLFSSL_DIR) \
121+
-include wolfhsm/wh_settings.h -x c /dev/null >"$$_defines"; then \
122+
echo "ERROR: $(CC) -dM -E on wolfhsm/wh_settings.h failed." >&2; exit 1; \
93123
fi && \
94124
if ! command -v python3 >/dev/null 2>&1; then \
95125
echo "ERROR: python3 not found." >&2; exit 1; \

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ make sbom WOLFSSL_DIR=../wolfssl
4040
This parses the version from `ChangeLog.md`, collects `src/*.c`, and writes
4141
`wolfhsm-<version>.cdx.json` and `wolfhsm-<version>.spdx.json`.
4242

43+
The SBOM records the build configuration by preprocessing
44+
`wolfhsm/wh_settings.h` against a config directory. `WOLFHSM_CFG_DIR`
45+
(default: `test/config`) selects the directory holding the `wolfhsm_cfg.h`
46+
and `user_settings.h` your build uses — point it at your port's config so the
47+
recorded `WOLFHSM_CFG_*` and wolfSSL options match the library you ship:
48+
49+
```sh
50+
make sbom WOLFSSL_DIR=../wolfssl WOLFHSM_CFG_DIR=path/to/your/config
51+
```
52+
53+
Note: alongside the real config macros, the dump currently includes libc
54+
constants pulled in by `wh_settings.h`'s system includes; see the comment on
55+
the `sbom` target in `Makefile` for why they are not filtered here and what
56+
the planned gen-sbom fix is.
57+
4358
`WOLFSSL_DIR` must point to a wolfssl source tree containing `scripts/gen-sbom`,
4459
which ships in wolfSSL PR #10343 (pending a future wolfSSL release). If the
4560
script is absent the target fails with a message telling you what is missing.
@@ -50,12 +65,15 @@ To invoke `gen-sbom` directly instead of through the target, run the same
5065
command it runs:
5166

5267
```sh
68+
cc -dM -E -DWOLFHSM_CFG -DWOLFSSL_USER_SETTINGS \
69+
-I. -Itest/config -I$WOLFSSL_DIR \
70+
-include wolfhsm/wh_settings.h -x c /dev/null > wolfhsm-defines.h
5371
python3 $WOLFSSL_DIR/scripts/gen-sbom \
5472
--name wolfhsm \
5573
--version $(sed -n 's/^# wolfHSM Release v\([0-9][0-9.]*\).*/\1/p' ChangeLog.md | head -1) \
5674
--supplier "wolfSSL Inc." \
5775
--license-file LICENSING \
58-
--options-h $WOLFSSL_DIR/include/wolfssl/options.h \
76+
--options-h wolfhsm-defines.h \
5977
--srcs src/*.c \
6078
--cdx-out wolfhsm.cdx.json \
6179
--spdx-out wolfhsm.spdx.json

0 commit comments

Comments
 (0)