Skip to content

Commit b0fa016

Browse files
SBOM/SPDX Generation: Add CPE information for CVE security scanners
1 parent b7ee231 commit b0fa016

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sbom-generator/sbom_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import hashlib
2+
import re
23
from datetime import datetime
34

45
SPDX_VERSION = 'SPDX-2.2'
@@ -29,11 +30,31 @@ def file_writer(output, filepath: str, sha1: str, license: str, copyright='NOASS
2930
output.write('FileComment: '+ comment + '\n')
3031
output.write('\n')
3132

33+
def cpe_writer(output, packageName: str, version: str):
34+
#Example: release/v6.0.5 -> v6.0.5
35+
version_stripped = re.sub(r'.*/', '', version)
36+
#Example: v6.0.5 -> 6.0.5
37+
version_stripped = re.sub('^v', '', version_stripped)
38+
39+
#Map package name to part:vendor:product
40+
# Note: All of these have existing CPEs in the NVD
41+
specifier_lookup = {
42+
'FreeRTOS-Kernel': 'o:amazon:freertos:',
43+
'FreeRTOS-Plus-FAT': 'o:amazon:freertos\\+fat:',
44+
'mbedtls': 'a:arm:mbed_tls:',
45+
'llhttp': 'a:llhttp:llhttp:',
46+
}
47+
48+
#If there are no existing CPEs in NVD -- nothing to do for now
49+
if packageName in specifier_lookup:
50+
output.write('ExternalRef: SECURITY cpe23Type cpe:2.3:' + specifier_lookup[packageName] + version_stripped + ':*:*:*:*:*:*:*' + '\n')
51+
3252
def package_writer(output, packageName: str, version: str, url: str, license: str, ver_code: str, file_analyzed=True,
3353
copyright='NOASSERTION', summary='NOASSERTION', description='NOASSERTION', file_licenses='NOASSERTION'):
3454
output.write('PackageName: '+ packageName + '\n')
3555
output.write('SPDXID: SPDXRef-Package-'+ packageName + '\n')
3656
output.write('PackageVersion: '+ version + '\n')
57+
cpe_writer(output, packageName, version, url)
3758
output.write('PackageDownloadLocation: '+ url + '\n')
3859
output.write('PackageLicenseDeclared: ' + license + '\n')
3960
output.write('PackageLicenseConcluded: '+ license + '\n')

0 commit comments

Comments
 (0)