Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,37 @@ function sanitize_sbom() {
logmust mv "$tmp" "$sbom_file"
}

#
# Copy the hashes recorded in the CycloneDX documents a package ships (e.g.
# zfs's Rust crate SBOMs) onto the matching components, by purl, of the SBOM
# Syft generated from that package. Syft reads those documents but drops their
# hashes, and scanners such as Mend identify some ecosystems, Rust crates among
# them, only by hash.
#
function restore_sbom_hashes() {
local sbom_file="$1"
local extract_dir="$2"
local hashes tmp

hashes="$(logmust mktemp)"
find "$extract_dir" -name '*.cdx.json' -type f -print0 |
xargs -0 -r jq -s '[ .[].components[]?
| select(.purl != null and .hashes != null)
| { (.purl): .hashes } ] | add // {}' >"$hashes" ||
die "restore_sbom_hashes: cannot read the SBOMs in '$extract_dir'"

if [[ -s "$hashes" ]]; then
tmp="$(logmust mktemp)"
logmust jq --slurpfile h "$hashes" '
.components |= map(
if .hashes == null and $h[0][.purl // ""] != null
then .hashes = $h[0][.purl] else . end)' \
"$sbom_file" >"$tmp"
logmust mv "$tmp" "$sbom_file"
fi
logmust rm -f "$hashes"
}

function generate_sbom() {
if [[ "$SBOM_DEEP_SCAN" != "true" ]]; then
return 0
Expand Down Expand Up @@ -1681,6 +1712,7 @@ function generate_sbom() {
--source-version "$deb_version" \
-o "cyclonedx-json@1.6=$sbom_file"

logmust restore_sbom_hashes "$sbom_file" "$extract_dir"
logmust rm -rf "$extract_dir"

#
Expand Down
1 change: 1 addition & 0 deletions packages/zfs/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function prepare() {
logmust install_kernel_headers_and_dbgsyms
logmust install_pkgs "$DEPDIR"/delphix-rust/*.deb
logmust cargo install cargo-bundle-licenses@2.1.1 --locked
logmust cargo install cargo-cyclonedx@0.5.9 --locked
logmust install_pkgs "$DEPDIR"/delphix-go/*.deb
logmust install_pkgs "$DEPDIR"/dwarves/*.deb
}
Expand Down
Loading