Skip to content

Commit d435b75

Browse files
timesys-nathanpaulbartell
authored andcommitted
SBOM/SPDX Generation: Add in LicenseRef info for licenses which are not recognized by SPDX (OASIS-IPR)
The sbom.spdx for corePKCS11 fails the SPDX validation check because OASIS-IPR is not a valid SPDX License This commit changes the following output to convert it to a LicenseRef and fix the validation check. $ diff -u sbom-original.spdx sbom-fixup.spdx --- sbom-original.spdx 2024-03-29 09:46:53.203092500 -0400 +++ sbom-fixup.spdx 2024-03-29 09:48:03.900301885 -0400 @@ -340,8 +340,8 @@ SPDXID: SPDXRef-Package-pkcs11 PackageVersion: v2.40_errata01 PackageDownloadLocation: https://github.com/amazon-freertos/pkcs11.git -PackageLicenseDeclared: OASIS-IPR -PackageLicenseConcluded: OASIS-IPR +PackageLicenseDeclared: LicenseRef-OASIS-IPR +PackageLicenseConcluded: LicenseRef-OASIS-IPR PackageLicenseInfoFromFiles: NOASSERTION FilesAnalyzed: True PackageVerificationCode: 0c50b69c6789adbc08378264ec75fa6e6a616364 @@ -1848,3 +1848,7 @@ Relationship: SPDXRef-Package-corePKCS11 DEPENDS_ON SPDXRef-Package-pkcs11 Relationship: SPDXRef-Package-corePKCS11 DEPENDS_ON SPDXRef-Package-mbedtls + +LicenseID: LicenseRef-OASIS-IPR +LicenseName: OASIS-IPR +ExtractedText: <text>OASIS-IPR</text>
1 parent e2129bf commit d435b75

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

sbom-generator/scan_dir.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
REPO_PATH = ''
1111
SOURCE_PATH = ''
1212

13+
def needs_licenseref(license):
14+
#SPDX license list can be found at https://spdx.org/licenses/
15+
not_in_spdx = ["OASIS-IPR"]
16+
if license in not_in_spdx:
17+
return True
18+
return False
19+
1320
def scan_dir():
1421
dependency_path = os.path.join(REPO_PATH, 'source/dependency')
1522
path_3rdparty = os.path.join(REPO_PATH, 'source/dependency/3rdparty')
@@ -20,6 +27,7 @@ def scan_dir():
2027
total_file_list = []
2128
dependency_info = {}
2229
dependency_file_list = {}
30+
licenseref_info = ""
2331
with open(manifest_path) as f:
2432
manifest = yaml.load(f, Loader=SafeLoader)
2533
root_license = manifest['license']
@@ -111,7 +119,17 @@ def scan_dir():
111119
if library_name == root_name:
112120
continue
113121
info = dependency_info[library_name]
114-
package_writer(output, library_name, info['version'], info['repository']['url'], info['license'], package_hash(dependency_file_list[library_name]))
122+
123+
#Is this license part of the SPDX license list? If not, then we need to use LicenseRef for proper SPDX validation
124+
if needs_licenseref(info['license']):
125+
license = "LicenseRef-" + info['license']
126+
licenseref_info += "\nLicenseID: LicenseRef-%s\n" % info['license']
127+
licenseref_info += "LicenseName: %s\n" % info['license']
128+
licenseref_info += "ExtractedText: <text>%s</text>\n" % info['license']
129+
else:
130+
license = info['license']
131+
132+
package_writer(output, library_name, info['version'], info['repository']['url'], license, package_hash(dependency_file_list[library_name]))
115133
output.write(output_buffer[library_name].getvalue())
116134

117135
#print relationships
@@ -120,6 +138,10 @@ def scan_dir():
120138
continue
121139
output.write('Relationship: SPDXRef-Package-' + manifest['name'] + ' DEPENDS_ON SPDXRef-Package-' + library_name + '\n')
122140

141+
#print any LicenseRef info
142+
if licenseref_info != "":
143+
output.write(licenseref_info)
144+
123145
if __name__ == "__main__":
124146
parser = ArgumentParser(description='SBOM generator')
125147
parser.add_argument('--repo-root-path',

0 commit comments

Comments
 (0)