|
1 | 1 | import hashlib |
| 2 | +import re |
2 | 3 | from datetime import datetime |
3 | 4 |
|
4 | 5 | SPDX_VERSION = 'SPDX-2.2' |
@@ -29,11 +30,31 @@ def file_writer(output, filepath: str, sha1: str, license: str, copyright='NOASS |
29 | 30 | output.write('FileComment: '+ comment + '\n') |
30 | 31 | output.write('\n') |
31 | 32 |
|
| 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 | + |
32 | 52 | def package_writer(output, packageName: str, version: str, url: str, license: str, ver_code: str, file_analyzed=True, |
33 | 53 | copyright='NOASSERTION', summary='NOASSERTION', description='NOASSERTION', file_licenses='NOASSERTION'): |
34 | 54 | output.write('PackageName: '+ packageName + '\n') |
35 | 55 | output.write('SPDXID: SPDXRef-Package-'+ packageName + '\n') |
36 | 56 | output.write('PackageVersion: '+ version + '\n') |
| 57 | + cpe_writer(output, packageName, version, url) |
37 | 58 | output.write('PackageDownloadLocation: '+ url + '\n') |
38 | 59 | output.write('PackageLicenseDeclared: ' + license + '\n') |
39 | 60 | output.write('PackageLicenseConcluded: '+ license + '\n') |
|
0 commit comments