@@ -57,138 +57,40 @@ clean:
5757 make -C tools clean
5858 make -C examples clean
5959
60- # ---- SBOM generation ----
61- CC ?= cc
62- WOLFSSL_DIR ?= ../wolfssl
63- WOLFHSM_CFG_DIR ?= test/config
64- PREFIX ?= /usr/local
65- SBOM_INSTALL_DIR ?= $(PREFIX ) /share/doc/wolfhsm
66- SBOM_VALIDATE ?= yes
67- SBOM_DEP_WOLFSSL ?= yes
68- VERSION = $(shell sed -n 's/^. wolfHSM Release v//p' ChangeLog.md | head -1 | cut -d' ' -f1)
69- SRCS := $(sort $(wildcard src/* .c) )
70- SBOM_CDX = wolfhsm-$(VERSION ) .cdx.json
71- SBOM_SPDX = wolfhsm-$(VERSION ) .spdx.json
72- SBOM_SPDX_TV = wolfhsm-$(VERSION ) .spdx
73-
74- .PHONY : sbom install-sbom uninstall-sbom
75-
76- sbom :
77- @if [ -z " $( VERSION) " ]; then \
78- echo " ERROR: could not parse version from ChangeLog.md." >&2 ; \
79- exit 1; \
80- fi
81- @if [ -z " $( WOLFSSL_DIR) " ] || [ ! -d " $( WOLFSSL_DIR) " ]; then \
82- echo " ERROR: WOLFSSL_DIR=$( WOLFSSL_DIR) is not a directory." >&2 ; \
83- echo " Set WOLFSSL_DIR to your wolfssl source tree." >&2 ; \
84- exit 1; \
85- fi
86- @if [ ! -f " $( WOLFSSL_DIR) /scripts/gen-sbom" ]; then \
87- echo " ERROR: $( WOLFSSL_DIR) /scripts/gen-sbom not found." >&2 ; \
88- echo " The sbom target needs a wolfSSL source tree that includes" >&2 ; \
89- echo " scripts/gen-sbom (wolfSSL PR #10343, pending a future release)." >&2 ; \
90- echo " Set WOLFSSL_DIR to such a tree." >&2 ; \
91- exit 1; \
92- fi
93- @if [ ! -f " $( WOLFHSM_CFG_DIR) /wolfhsm_cfg.h" ]; then \
94- echo " ERROR: $( WOLFHSM_CFG_DIR) /wolfhsm_cfg.h not found." >&2 ; \
95- echo " Set WOLFHSM_CFG_DIR to the directory holding the" >&2 ; \
96- echo " wolfhsm_cfg.h (and user_settings.h) your build uses." >&2 ; \
97- exit 1; \
98- fi
99- @if [ " $( SBOM_VALIDATE) " != " no" ] && \
100- ! command -v pyspdxtools > /dev/null 2>&1 ; then \
101- echo " ERROR: 'pyspdxtools' not found (pip install spdx-tools)." >&2 ; \
102- echo " It validates the SPDX output and converts it to" >&2 ; \
103- echo " tag-value. Set SBOM_VALIDATE=no to skip both." >&2 ; \
104- exit 1; \
105- fi
106- @echo " wolfHSM version: $( VERSION) "
107- @echo " Sources: $( words $( SRCS) ) .c files in src/"
108- @echo " Config: $( WOLFHSM_CFG_DIR) /wolfhsm_cfg.h"
109- # Effective build config for the SBOM: preprocess wolfhsm/wh_settings.h with
110- # the same defines and include path the test build compiles under, so the -dM
111- # dump holds every WOLFHSM_CFG_* option (explicit and defaulted) plus the
112- # wolfSSL options from user_settings.h — the configuration the library is
113- # actually built with. Point WOLFHSM_CFG_DIR at the directory holding your
114- # build's wolfhsm_cfg.h/user_settings.h for an integrator-accurate SBOM.
60+ # ---- SBOM generation (vendored wolfGlass driver) ----
61+ # Version comes from ChangeLog.md: there is no release version macro in the
62+ # public headers (WOLFHSM_CFG_INFOVERSION is a protocol info string, not the
63+ # product release). Parsing ChangeLog.md is a known fragility to fix later.
11564#
116- # ponytail: wh_settings.h pulls libc headers (stdint/stdio/strings/stdatomic),
117- # so ~330 toolchain constants (INT16_MAX, ACCESSPERMS, ...) ride along into
118- # the SBOM next to the ~175 real config macros. The dump is deliberately NOT
119- # filtered here: a prefix allowlist would silently drop real options that
120- # carry no standard prefix (GCM_TABLE_4BIT, FP_MAX_BITS, SINGLE_THREADED).
121- # The durable fix belongs in gen-sbom's noise filter (wolfSSL PR #10343,
122- # scripts/gen-sbom _NOISE_MACRO_RE), either of:
123- # a) provenance filtering: accept a -dD dump and use its #line markers to
124- # drop macros defined in system headers, or
125- # b) an --options-baseline flag: subtract a second -dM dump made with the
126- # same flags minus the -include, plus the libc headers it pulls.
127- # Once gen-sbom grows that, this recipe needs no change — it already hands
128- # over the full dump.
129- @_defines=$$(mktemp "$${TMPDIR:-/tmp}/wolfhsm-defines.XXXXXX") && \
130- trap 'rm -f "$$_defines"' 0 && \
131- if ! $(CC) -dM -E -DWOLFHSM_CFG -DWOLFSSL_USER_SETTINGS \
65+ # Config capture MUST use SBOM_OPTIONS_H, not SBOM_CFLAGS. The driver's
66+ # --cflags path keeps only -D tokens and drops -I / -include, so feeding
67+ # `-include wolfhsm/wh_settings.h` via SBOM_CFLAGS produced an empty SBOM
68+ # (two raw -D flags). Capture the expanded header the same way PR #414 did.
69+ WOLFSSL_DIR ?= ../wolfssl
70+ HOSTCC ?= cc
71+ SBOM_NAME := wolfhsm
72+ SBOM_ROOT := $(CURDIR )
73+ SBOM_SRCS := $(sort $(wildcard src/* .c) )
74+ SBOM_VERSION := $(shell sed -n 's/^. wolfHSM Release v//p' ChangeLog.md | head -1 | cut -d' ' -f1)
75+ SBOM_LICENSE_FILE := $(CURDIR ) /LICENSING
76+ SBOM_DEP_WOLFSSL ?= yes
77+ SBOM_OPTIONS_H := $(CURDIR ) /.sbom-wolfhsm-defines.h
78+
79+ ifeq ($(origin WOLFHSM_CFG_DIR ) ,undefined)
80+ $(error WOLFHSM_CFG_DIR is required — point it at the directory \
81+ holding the wolfhsm_cfg.h/user_settings.h your build uses; do \
82+ not assume test/config is a release configuration)
83+ endif
84+
85+ include tools/sbom/build/sbom.mk
86+
87+ # Always re-capture: a stale dump would hide config changes. The driver's
88+ # --cflags path cannot do this — it drops -I/-include.
89+ .PHONY : sbom-defines
90+ sbom-defines :
91+ @echo " SBOM: capturing config via $( HOSTCC) -dM -E -include wolfhsm/wh_settings.h"
92+ @$(HOSTCC ) -dM -E -DWOLFHSM_CFG -DWOLFSSL_USER_SETTINGS \
13293 -I. -I$(WOLFHSM_CFG_DIR ) -I$(WOLFSSL_DIR ) \
133- -include wolfhsm/wh_settings.h -x c /dev/null >"$$_defines"; then \
134- echo "ERROR: $(CC) -dM -E on wolfhsm/wh_settings.h failed." >&2; exit 1; \
135- fi && \
136- if ! command -v python3 >/dev/null 2>&1; then \
137- echo "ERROR: python3 not found." >&2; exit 1; \
138- fi && \
139- if [ -z "$${SOURCE_DATE_EPOCH:-}" ] && \
140- command -v git >/dev/null 2>&1 && \
141- git rev-parse --git-dir >/dev/null 2>&1; then \
142- sde=$$(git log -1 --format=%ct 2>/dev/null); \
143- if [ -n "$$sde" ]; then \
144- SOURCE_DATE_EPOCH="$$sde"; export SOURCE_DATE_EPOCH; \
145- fi; \
146- fi && \
147- dep_args=""; \
148- if [ "$(SBOM_DEP_WOLFSSL)" != "no" ]; then \
149- if python3 $(WOLFSSL_DIR)/scripts/gen-sbom --help 2>/dev/null \
150- | grep -q -- '--dep-wolfssl'; then \
151- dep_args="--dep-wolfssl yes"; \
152- wv=$$(sed -n 's/.*LIBWOLFSSL_VERSION_STRING[[:space:]]*"\([^"]*\)".*/\1/p' \
153- "$(WOLFSSL_DIR)/wolfssl/version.h" 2>/dev/null); \
154- if [ -n "$$wv" ]; then \
155- dep_args="$$dep_args --dep-version wolfssl=$$wv"; \
156- fi; \
157- else \
158- echo "NOTE: this gen-sbom lacks --dep-wolfssl; wolfssl will not"; \
159- echo " be listed as a dependency component in the SBOM."; \
160- fi; \
161- fi && \
162- python3 $(WOLFSSL_DIR)/scripts/gen-sbom \
163- --name wolfhsm \
164- --version $(VERSION) \
165- --supplier "wolfSSL Inc." \
166- --license-file LICENSING \
167- --options-h "$$_defines" \
168- --srcs $(SRCS) \
169- $$dep_args \
170- --cdx-out $(SBOM_CDX) \
171- --spdx-out $(SBOM_SPDX) && \
172- if [ "$(SBOM_VALIDATE)" != "no" ]; then \
173- pyspdxtools --infile $(SBOM_SPDX) --outfile $(SBOM_SPDX_TV) && \
174- echo "Done: $(SBOM_CDX) $(SBOM_SPDX) $(SBOM_SPDX_TV)"; \
175- else \
176- echo "Done: $(SBOM_CDX) $(SBOM_SPDX)"; \
177- fi
178-
179- # SBOM install is opt-in (`make install-sbom`), matching the family
180- # convention in wolfssl's scripts/sbom.am: plain `make` never installs
181- # SBOM files. wolfHSM's root Makefile has no install/uninstall targets
182- # to hook, so uninstall-sbom is standalone rather than chained.
183- install-sbom : sbom
184- @mkdir -p $(DESTDIR )$(SBOM_INSTALL_DIR )
185- install -m 0644 $(SBOM_CDX ) $(DESTDIR )$(SBOM_INSTALL_DIR ) /
186- install -m 0644 $(SBOM_SPDX ) $(DESTDIR )$(SBOM_INSTALL_DIR ) /
187- @if [ -f " $( SBOM_SPDX_TV) " ]; then \
188- install -m 0644 $(SBOM_SPDX_TV ) $(DESTDIR )$(SBOM_INSTALL_DIR ) /; \
189- fi
190-
191- uninstall-sbom :
192- -rm -f $(DESTDIR )$(SBOM_INSTALL_DIR ) /$(SBOM_CDX ) \
193- $(DESTDIR )$(SBOM_INSTALL_DIR ) /$(SBOM_SPDX ) \
194- $(DESTDIR )$(SBOM_INSTALL_DIR ) /$(SBOM_SPDX_TV )
94+ -include wolfhsm/wh_settings.h -x c /dev/null > $(SBOM_OPTIONS_H )
95+
96+ sbom : sbom-defines
0 commit comments