Skip to contentSkip to conversation

spdx: SHA 512 support

PATCH New Joshua Watt 1 participant 3 messages May 13

lore
Share & tools
lore
#0 lore raw

cover spdx: SHA 512 support

Add SHA 512 support for compliance with BSI TR-03183

Joshua Watt (2):
spdx: Use checksum list from bitbake
spdx: Add SHA 512 support

 meta/lib/oe/sbom30.py       |  7 +++++++
 meta/lib/oe/spdx30_tasks.py | 10 ++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/2 spdx: Use checksum list from bitbake

Instead of manually curating a hardcoded list of checksums, use the same list that bitbake uses.

---
 meta/lib/oe/spdx30_tasks.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
meta/lib/oe/spdx30_tasks.py +4 -2
index 1821dd7de4..0a30be5767 100644
@@ -547,8 +547,10 @@ def add_download_files(d, objset):
             _enrich_source_package(d, dl, fd, file_name, primary_purpose)
 
             if fd.method.supports_checksum(fd):
-                # TODO Need something better than hard coding this
-                for checksum_id in ["sha256", "sha1"]:
+                for checksum_id in bb.fetch2.CHECKSUM_LIST:
+                    if checksum_id not in oe.spdx30.HashAlgorithm.NAMED_INDIVIDUALS:
+                        continue
+
                     expected_checksum = getattr(fd, "%s_expected" % checksum_id, None)
                     if expected_checksum is None:
                         continue
Signature · 1 line
2.54.0
#2 lore raw

PATCH 2/2 spdx: Add SHA 512 support

In reply to Joshua Watt

Adds support for adding SHA-512 hashes (where possible). This is to improve compliance with SBoM standards, in particular BSI TR-03181 [1].

SHA 256 hashes are still included for each file, and still used to index files in the database. Also, while SHA 512 is supported as a hash for downloads, most recipes are still using SHA 256 and would need to be upgraded for full compliance with BSI TR-03183

[1]: https://www.bsi.bund.de/EN/Themen/Unternehmen-und-Organisationen/Standards-und-Zertifizierung/Technische-Richtlinien/TR-nach-Thema-sortiert/tr03183/TR-03183_node.html

---
 meta/lib/oe/sbom30.py       | 7 +++++++
 meta/lib/oe/spdx30_tasks.py | 4 ++++
 2 files changed, 11 insertions(+)
meta/lib/oe/sbom30.py +7 -0
index 0f1f9281ad..b379ff947c 100644
@@ -638,6 +638,7 @@ class ObjectSet(oe.spdx30.SHACLObjectSet):
     def new_file(self, _id, name, path, *, purposes=[], hashfile=True):
         if hashfile:
             sha256_hash = bb.utils.sha256_file(path)
+            sha512_hash = bb.utils.sha512_file(path)
 
             for f in self.by_sha256_hash.get(sha256_hash, []):
                 if not isinstance(f, oe.spdx30.software_File):
@@ -684,6 +685,12 @@ class ObjectSet(oe.spdx30.SHACLObjectSet):
                     hashValue=sha256_hash,
                 )
             )
+            spdx_file.verifiedUsing.append(
+                oe.spdx30.Hash(
+                    algorithm=oe.spdx30.HashAlgorithm.sha512,
+                    hashValue=sha512_hash,
+                )
+            )
 
         return self.add(spdx_file)
 
meta/lib/oe/spdx30_tasks.py +4 -0
index 0a30be5767..7cc46d579b 100644
@@ -1478,6 +1478,10 @@ def create_image_spdx(d):
                             oe.spdx30.Hash(
                                 algorithm=oe.spdx30.HashAlgorithm.sha256,
                                 hashValue=bb.utils.sha256_file(image_path),
+                            ),
+                            oe.spdx30.Hash(
+                                algorithm=oe.spdx30.HashAlgorithm.sha512,
+                                hashValue=bb.utils.sha512_file(image_path),
                             )
                         ],
                     )
Signature · 1 line
2.54.0