Skip to content

Commit be88063

Browse files
committed
fix(bomsh): snapshot traced library before make sbom's libtool relink
bomsh_sbom.py hashes -f at call time, so without the pre-install snapshot it hashes the post-relink bytes and the SPDX externalRef gitoid stops matching the manifest, failing verifier check (C). Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
1 parent cf0bdd9 commit be88063

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

.github/workflows/sbom.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,9 +1077,14 @@ jobs:
10771077
- name: Upload bomsh trace diagnostics
10781078
# Diagnostic-only, short retention. Kept separate so the
10791079
# provenance bundle above stays slim for downstream consumers
1080-
# who don't need to debug ptrace gaps. `_bomsh.artefact` is
1081-
# included here (not in the provenance bundle) because it is
1082-
# a CI-internal pointer file, not part of the SBOM contract.
1080+
# who don't need to debug ptrace gaps. `_bomsh.artefact` and
1081+
# `_bomsh.snapshot` are included here (not in the provenance
1082+
# bundle) because they are CI-internal: the manifest is a
1083+
# pointer file, and the snapshot is the byte-identical copy
1084+
# of the bomtrace3-traced library taken before `make sbom`'s
1085+
# libtool relink. Bundling the snapshot lets a reviewer
1086+
# reproduce check (C) by hand (`sha1("blob "+len+"\\0"+bytes)`)
1087+
# to confirm the SPDX externalRef gitoid is honest.
10831088
if: always()
10841089
uses: actions/upload-artifact@v4
10851090
with:
@@ -1088,6 +1093,7 @@ jobs:
10881093
bomsh_raw_logfile.sha1
10891094
_bomsh.conf
10901095
_bomsh.artefact
1096+
_bomsh.snapshot
10911097
if-no-files-found: warn
10921098
retention-days: 14
10931099

@@ -1104,3 +1110,5 @@ jobs:
11041110
test ! -d omnibor || (echo "omnibor/ not cleaned"; exit 1)
11051111
test ! -f _bomsh.artefact \
11061112
|| (echo "_bomsh.artefact not cleaned"; exit 1)
1113+
test ! -f _bomsh.snapshot \
1114+
|| (echo "_bomsh.snapshot not cleaned"; exit 1)

Makefile.am

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ BOMSH_SPDX_OUT = omnibor.wolfssl-$(PACKAGE_VERSION).spdx.json
486486
# the on-disk gitoid disagrees, so the install-time relink remains
487487
# visible.
488488
BOMSH_ARTEFACT_MANIFEST = $(abs_builddir)/_bomsh.artefact
489+
# Byte-identical copy of the traced library, captured BEFORE `make sbom`
490+
# runs `make install` (during which libtool relinks src/.libs/lib*.so*
491+
# in place to fix RPATH). bomsh_sbom.py hashes the file at -f at call
492+
# time rather than reading the ADG, so pointing -f at this snapshot keeps
493+
# the SPDX externalRef pinned to the bomsh-traced gitoid -- otherwise it
494+
# would hash the post-relink bytes and disagree with the manifest.
495+
BOMSH_ARTEFACT_SNAPSHOT = $(abs_builddir)/_bomsh.snapshot
489496
bomshdir = $(datadir)/doc/$(PACKAGE)
490497

491498
.PHONY: bomsh install-bomsh uninstall-bomsh
@@ -514,15 +521,10 @@ bomsh:
514521
@printf 'raw_logfile=%s\n' '$(BOMSH_RAWLOG_BASE)' > '$(BOMSH_CONF)'
515522
$(BOMTRACE3) -c '$(BOMSH_CONF)' $(MAKE)
516523
$(BOMSH_CREATE_BOM) -r '$(BOMSH_RAWLOG)' -b '$(BOMSH_OMNIBORDIR)'
517-
@# Capture the gitoid of the bomtrace3-traced library BEFORE the
518-
@# `make sbom` below, which calls `make install DESTDIR=...` --
519-
@# libtool's --mode=install relinks src/.libs/lib*.so* in place
520-
@# to fix RPATH, mutating the bytes that bomsh recorded in the
521-
@# ADG via bomsh_create_bom above. Capturing here pins the
522-
@# verifier's check (C) to the bomsh-traced gitoid (so SPDX <->
523-
@# manifest agree even though the on-disk bytes diverge after
524-
@# install). The on-disk divergence is surfaced as a verifier
525-
@# warning, not a failure.
524+
@# Snapshot the traced library before `make sbom`'s install-time
525+
@# libtool relink rewrites it (RPATH fix). -f points at the snapshot
526+
@# so bomsh_sbom.py emits the bomsh-traced gitoid; the manifest's path
527+
@# field stays on the live library so the verifier's NOTE keeps firing.
526528
@bomsh_artifact=""; \
527529
for lib in \
528530
$(addprefix "$(abs_builddir)/src/.libs"/,$(WOLFSSL_LIB_DSO_BASENAMES)) \
@@ -531,7 +533,8 @@ bomsh:
531533
if test -f "$$lib"; then bomsh_artifact="$$lib"; break; fi; \
532534
done; \
533535
if test -n "$$bomsh_artifact"; then \
534-
bomsh_artifact_gid=`$(PYTHON3) -c 'import hashlib,sys;d=open(sys.argv[1],"rb").read();h=hashlib.sha1();h.update(("blob %d\0"%len(d)).encode());h.update(d);print(h.hexdigest())' "$$bomsh_artifact"`; \
536+
cp "$$bomsh_artifact" '$(BOMSH_ARTEFACT_SNAPSHOT)'; \
537+
bomsh_artifact_gid=`$(PYTHON3) -c 'import hashlib,sys;d=open(sys.argv[1],"rb").read();h=hashlib.sha1();h.update(("blob %d\0"%len(d)).encode());h.update(d);print(h.hexdigest())' '$(BOMSH_ARTEFACT_SNAPSHOT)'`; \
535538
printf '%s\t%s\n' "$$bomsh_artifact" "$$bomsh_artifact_gid" \
536539
> '$(BOMSH_ARTEFACT_MANIFEST)'; \
537540
fi
@@ -541,17 +544,18 @@ bomsh:
541544
echo " The OmniBOR graph in $(BOMSH_OMNIBORDIR) is still produced."; \
542545
exit 0; \
543546
fi; \
544-
if test ! -f '$(BOMSH_ARTEFACT_MANIFEST)'; then \
547+
if test ! -f '$(BOMSH_ARTEFACT_MANIFEST)' \
548+
|| test ! -f '$(BOMSH_ARTEFACT_SNAPSHOT)'; then \
545549
echo "NOTE: no built libwolfssl artifact found in $(abs_builddir)/src/.libs/"; \
546550
echo " OmniBOR graph produced; SPDX enrichment skipped."; \
547551
exit 0; \
548552
fi; \
549553
bomsh_artifact=`awk 'NR==1 {print $$1}' '$(BOMSH_ARTEFACT_MANIFEST)'`; \
550-
echo "Enriching SPDX with OmniBOR ExternalRefs (artifact: $$bomsh_artifact)..."; \
554+
echo "Enriching SPDX with OmniBOR ExternalRefs (artifact: $$bomsh_artifact, snapshot: $(BOMSH_ARTEFACT_SNAPSHOT))..."; \
551555
$(BOMSH_SBOM) \
552556
-b '$(BOMSH_OMNIBORDIR)' \
553557
-i '$(abs_builddir)/$(SBOM_SPDX)' \
554-
-f "$$bomsh_artifact" \
558+
-f '$(BOMSH_ARTEFACT_SNAPSHOT)' \
555559
-s spdx-json \
556560
-O '$(abs_builddir)'
557561

@@ -568,7 +572,7 @@ uninstall-bomsh:
568572
-rm -rf '$(DESTDIR)$(bomshdir)/omnibor'
569573
-rm -f '$(DESTDIR)$(bomshdir)/$(BOMSH_SPDX_OUT)'
570574

571-
CLEANFILES += $(BOMSH_RAWLOG) $(BOMSH_RAWLOG_BASE).sha256 $(BOMSH_CONF) $(BOMSH_SPDX_OUT) $(BOMSH_ARTEFACT_MANIFEST)
575+
CLEANFILES += $(BOMSH_RAWLOG) $(BOMSH_RAWLOG_BASE).sha256 $(BOMSH_CONF) $(BOMSH_SPDX_OUT) $(BOMSH_ARTEFACT_MANIFEST) $(BOMSH_ARTEFACT_SNAPSHOT)
572576

573577
# Hook SBOM/Bomsh cleanup into `make uninstall` so packagers don't leave
574578
# stale artefacts behind after install-sbom/install-bomsh. uninstall-sbom

0 commit comments

Comments
 (0)