interplane.Get Omega
Read in your language

omega-packages

aien-dev/omega-packages

Brought by drakestapleton

branch main Branches Tags History

omega-packages / scripts / sbom.sh

64 lines · 3849 bytes Raw Blame History
1#!/bin/sh
2# sbom.sh TREE OMC -- print a minimal SPDX 2.3 JSON SBOM for omc on stdout.
3# TREE is the unpacked omega-mv-<commit> source that omc was born from (scripts/omc-from-seed.sh).
4# omc is a static ELF with no runtime dependencies, so the SBOM lists only what it is built from:
5# the pinned source archive and every seed input named in TREE/seed/challenge/expected.txt, each with
6# the sha256 measured from TREE. Exit 1 when a measured input disagrees with expected.txt.
7set -eu
8here=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
9. "$here/pins.env"
10[ $# -eq 2 ] || { echo "usage: sbom.sh TREE OMC" >&2; exit 2; }
11tree=$1 omc=$2
12exp=$tree/seed/challenge/expected.txt
13[ -r "$exp" ] || { echo "FAIL no $exp" >&2; exit 1; }
14osha=$(sha256sum "$omc" | cut -d' ' -f1)
15[ "$osha" = "$OMC_SHA256" ] || { echo "FAIL omc sha256 $osha, pinned $OMC_SHA256" >&2; exit 1; }
16created=$(date -u -d "@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%Y-%m-%dT%H:%M:%SZ)
17
18files= rels= n=0
19while read -r kind path sha bytes; do
20 [ "$kind" = input ] || continue
21 got=$(sha256sum "$tree/$path" | cut -d' ' -f1)
22 [ "$got" = "$sha" ] || { echo "FAIL $path sha256 $got, expected.txt $sha" >&2; exit 1; }
23 sha1=$(sha1sum "$tree/$path" | cut -d' ' -f1)
24 n=$((n + 1))
25 id=SPDXRef-File-seed-$n
26 files="$files${files:+,}
27 {\"SPDXID\": \"$id\", \"fileName\": \"./$path\", \"checksums\": [{\"algorithm\": \"SHA256\", \"checksumValue\": \"$got\"}, {\"algorithm\": \"SHA1\", \"checksumValue\": \"$sha1\"}], \"licenseConcluded\": \"Apache-2.0\", \"copyrightText\": \"NOASSERTION\", \"comment\": \"$bytes bytes; seed-chain input, path inside the omega-mv $OMEGA_MV_COMMIT archive\"}"
28 rels="$rels,
29 {\"spdxElementId\": \"SPDXRef-Package-omc\", \"relationshipType\": \"GENERATED_FROM\", \"relatedSpdxElement\": \"$id\"}"
30done < "$exp"
31[ "$n" -gt 0 ] || { echo "FAIL no input rows in $exp" >&2; exit 1; }
32
33cat <<EOF
34{
35 "spdxVersion": "SPDX-2.3",
36 "dataLicense": "CC0-1.0",
37 "SPDXID": "SPDXRef-DOCUMENT",
38 "name": "omc-$OMC_VERSION",
39 "documentNamespace": "https://github.com/aien-dev/omega-packages/spdx/omc-$OMC_VERSION-$osha",
40 "creationInfo": {"created": "$created", "creators": ["Organization: aien-dev", "Tool: omega-packages scripts/sbom.sh"]},
41 "documentDescribes": ["SPDXRef-Package-omc"],
42 "packages": [
43 {"SPDXID": "SPDXRef-Package-omc", "name": "omc", "versionInfo": "$OMC_VERSION",
44 "supplier": "Organization: aien-dev", "downloadLocation": "https://github.com/aien-dev/omega-packages/releases",
45 "filesAnalyzed": false, "primaryPackagePurpose": "APPLICATION",
46 "checksums": [{"algorithm": "SHA256", "checksumValue": "$osha"}],
47 "licenseConcluded": "Apache-2.0", "licenseDeclared": "Apache-2.0", "copyrightText": "NOASSERTION",
48 "comment": "Static AArch64 Linux ELF, no runtime dependencies. Built by seed/omega-from-seed.sh: seed0 (408 bytes) -> hex1 -> asm2 -> om4 -> omc -> omc -> omc."},
49 {"SPDXID": "SPDXRef-Package-omega-mv", "name": "omega-mv", "versionInfo": "$OMEGA_MV_COMMIT",
50 "supplier": "Organization: aien-dev",
51 "downloadLocation": "https://github.com/aien-dev/omega-mv/archive/$OMEGA_MV_COMMIT.tar.gz",
52 "filesAnalyzed": false,
53 "checksums": [{"algorithm": "SHA256", "checksumValue": "$OMEGA_MV_TARBALL_SHA256"}],
54 "licenseConcluded": "Apache-2.0", "licenseDeclared": "Apache-2.0", "copyrightText": "NOASSERTION",
55 "comment": "Source archive. The files listed below are its seed-chain inputs, measured from the unpacked archive and checked against seed/challenge/expected.txt."}
56 ],
57 "files": [$files
58 ],
59 "relationships": [
60 {"spdxElementId": "SPDXRef-DOCUMENT", "relationshipType": "DESCRIBES", "relatedSpdxElement": "SPDXRef-Package-omc"},
61 {"spdxElementId": "SPDXRef-Package-omc", "relationshipType": "GENERATED_FROM", "relatedSpdxElement": "SPDXRef-Package-omega-mv"}$rels
62 ]
63}
64EOF