utils/generate-cyclonedx: generate vcs externalReferences for source repos

Some packages do not have a http/https download URL for a source tarball,
but are acquired over a version control system like git. If so, add
externalReferences of type "vcs" for such URLs.

As most git repositories use a https:// transport that may not indicated the
repository type, add a "comment" due to the lack of a better mechanism in
CycloneDX.

While the hashes are calculated over a tarball created locally, it still may
be useful, so add them for "vcs" externalReferences as well.

Signed-off-by: Martin Willi <martin@strongswan.org>
Acked-By: Thomas Perale <thomas.perale@mind.be>
Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>
This commit is contained in:
Martin Willi
2026-04-09 10:14:01 +02:00
committed by Arnout Vandecappelle
parent 1791b79422
commit e8c54ffb3d
2 changed files with 37 additions and 1 deletions

View File

@@ -325,6 +325,7 @@ def cyclonedx_external_refs(comp):
dict: External reference information in CycloneDX format, or empty dict
"""
SOURCE_DIST_SCHEMES = {"http", "https"}
VCS_SCHEMES = {"git", "svn", "cvs", "hg", "bzr"}
refs = []
for download in comp.get("downloads", []):
@@ -336,6 +337,13 @@ def cyclonedx_external_refs(comp):
"url": f"{uri}/{source}",
**cyclonedx_source_hashes(comp, source),
})
elif set(schemes) & VCS_SCHEMES:
refs.append({
"type": "vcs",
"url": uri,
"comment": f"{schemes[0]} repository",
**cyclonedx_source_hashes(comp, source),
})
if refs:
return {"externalReferences": refs}
return {}