blob: 02fef7c20585745d653f0a41694fc5287717d87b [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001# This class is used to check recipes against public CVEs.
2#
3# In order to use this class just inherit the class in the
4# local.conf file and it will add the cve_check task for
5# every recipe. The task can be used per recipe, per image,
6# or using the special cases "world" and "universe". The
7# cve_check task will print a warning for every unpatched
8# CVE found and generate a file in the recipe WORKDIR/cve
9# directory. If an image is build it will generate a report
10# in DEPLOY_DIR_IMAGE for all the packages used.
11#
12# Example:
13# bitbake -c cve_check openssl
14# bitbake core-image-sato
15# bitbake -k -c cve_check universe
16#
17# DISCLAIMER
18#
19# This class/tool is meant to be used as support and not
20# the only method to check against CVEs. Running this tool
21# doesn't guarantee your packages are free of CVEs.
22
Brad Bishop37a0e4d2017-12-04 01:01:44 -050023# The product name that the CVE database uses. Defaults to BPN, but may need to
24# be overriden per recipe (for example tiff.bb sets CVE_PRODUCT=libtiff).
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025CVE_PRODUCT ??= "${BPN}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040026CVE_VERSION ??= "${PV}"
Brad Bishop37a0e4d2017-12-04 01:01:44 -050027
Patrick Williamsc0f7c042017-02-23 20:41:17 -060028CVE_CHECK_DB_DIR ?= "${DL_DIR}/CVE_CHECK"
Andrew Geissler82c905d2020-04-13 13:39:40 -050029CVE_CHECK_DB_FILE ?= "${CVE_CHECK_DB_DIR}/nvdcve_1.1.db"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050030CVE_CHECK_DB_FILE_LOCK ?= "${CVE_CHECK_DB_FILE}.lock"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060031
Brad Bishop316dfdd2018-06-25 12:45:53 -040032CVE_CHECK_LOG ?= "${T}/cve.log"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033CVE_CHECK_TMP_FILE ?= "${TMPDIR}/cve_check"
Andrew Geisslerb7d28612020-07-24 16:15:54 -050034CVE_CHECK_SUMMARY_DIR ?= "${LOG_DIR}/cve"
35CVE_CHECK_SUMMARY_FILE_NAME ?= "cve-summary"
36CVE_CHECK_SUMMARY_FILE ?= "${CVE_CHECK_SUMMARY_DIR}/${CVE_CHECK_SUMMARY_FILE_NAME}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060037
38CVE_CHECK_DIR ??= "${DEPLOY_DIR}/cve"
39CVE_CHECK_MANIFEST ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.cve"
40CVE_CHECK_COPY_FILES ??= "1"
41CVE_CHECK_CREATE_MANIFEST ??= "1"
42
43# Whitelist for packages (PN)
Brad Bishop96ff1982019-08-19 13:50:42 -040044CVE_CHECK_PN_WHITELIST ?= ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -060045
Brad Bishop96ff1982019-08-19 13:50:42 -040046# Whitelist for CVE. If a CVE is found, then it is considered patched.
47# The value is a string containing space separated CVE values:
48#
49# CVE_CHECK_WHITELIST = 'CVE-2014-2524 CVE-2018-1234'
50#
51CVE_CHECK_WHITELIST ?= ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052
Andrew Geisslerb7d28612020-07-24 16:15:54 -050053python cve_save_summary_handler () {
54 import shutil
55 import datetime
56
57 cve_tmp_file = d.getVar("CVE_CHECK_TMP_FILE")
58
59 cve_summary_name = d.getVar("CVE_CHECK_SUMMARY_FILE_NAME")
60 cvelogpath = d.getVar("CVE_CHECK_SUMMARY_DIR")
61 bb.utils.mkdirhier(cvelogpath)
62
63 timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
64 cve_summary_file = os.path.join(cvelogpath, "%s-%s.txt" % (cve_summary_name, timestamp))
65
Andrew Geisslerc9f78652020-09-18 14:11:35 -050066 if os.path.exists(cve_tmp_file):
67 shutil.copyfile(cve_tmp_file, cve_summary_file)
Andrew Geisslerb7d28612020-07-24 16:15:54 -050068
Andrew Geisslerc9f78652020-09-18 14:11:35 -050069 if cve_summary_file and os.path.exists(cve_summary_file):
70 cvefile_link = os.path.join(cvelogpath, cve_summary_name)
Andrew Geisslerb7d28612020-07-24 16:15:54 -050071
Andrew Geisslerc9f78652020-09-18 14:11:35 -050072 if os.path.exists(os.path.realpath(cvefile_link)):
73 os.remove(cvefile_link)
74 os.symlink(os.path.basename(cve_summary_file), cvefile_link)
Andrew Geisslerb7d28612020-07-24 16:15:54 -050075}
76
77addhandler cve_save_summary_handler
78cve_save_summary_handler[eventmask] = "bb.event.BuildCompleted"
79
Patrick Williamsc0f7c042017-02-23 20:41:17 -060080python do_cve_check () {
81 """
82 Check recipe for patched and unpatched CVEs
83 """
84
Brad Bishop96ff1982019-08-19 13:50:42 -040085 if os.path.exists(d.getVar("CVE_CHECK_DB_FILE")):
Andrew Geissler82c905d2020-04-13 13:39:40 -050086 try:
87 patched_cves = get_patches_cves(d)
88 except FileNotFoundError:
89 bb.fatal("Failure in searching patches")
90 whitelisted, patched, unpatched = check_cves(d, patched_cves)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060091 if patched or unpatched:
92 cve_data = get_cve_info(d, patched + unpatched)
Andrew Geissler82c905d2020-04-13 13:39:40 -050093 cve_write_data(d, patched, unpatched, whitelisted, cve_data)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060094 else:
Brad Bishop96ff1982019-08-19 13:50:42 -040095 bb.note("No CVE database found, skipping CVE check")
96
Patrick Williamsc0f7c042017-02-23 20:41:17 -060097}
98
Andrew Geissler1e34c2d2020-05-29 16:02:59 -050099addtask cve_check before do_build after do_fetch
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500100do_cve_check[depends] = "cve-update-db-native:do_fetch"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600101do_cve_check[nostamp] = "1"
102
103python cve_check_cleanup () {
104 """
105 Delete the file used to gather all the CVE information.
106 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500107 bb.utils.remove(e.data.getVar("CVE_CHECK_TMP_FILE"))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108}
109
110addhandler cve_check_cleanup
111cve_check_cleanup[eventmask] = "bb.cooker.CookerExit"
112
113python cve_check_write_rootfs_manifest () {
114 """
115 Create CVE manifest when building an image
116 """
117
118 import shutil
119
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500120 if d.getVar("CVE_CHECK_COPY_FILES") == "1":
121 deploy_file = os.path.join(d.getVar("CVE_CHECK_DIR"), d.getVar("PN"))
122 if os.path.exists(deploy_file):
123 bb.utils.remove(deploy_file)
124
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500125 if os.path.exists(d.getVar("CVE_CHECK_TMP_FILE")):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600126 bb.note("Writing rootfs CVE manifest")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127 deploy_dir = d.getVar("DEPLOY_DIR_IMAGE")
128 link_name = d.getVar("IMAGE_LINK_NAME")
129 manifest_name = d.getVar("CVE_CHECK_MANIFEST")
130 cve_tmp_file = d.getVar("CVE_CHECK_TMP_FILE")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600131
132 shutil.copyfile(cve_tmp_file, manifest_name)
133
134 if manifest_name and os.path.exists(manifest_name):
135 manifest_link = os.path.join(deploy_dir, "%s.cve" % link_name)
136 # If we already have another manifest, update symlinks
137 if os.path.exists(os.path.realpath(manifest_link)):
138 os.remove(manifest_link)
139 os.symlink(os.path.basename(manifest_name), manifest_link)
140 bb.plain("Image CVE report stored in: %s" % manifest_name)
141}
142
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500143ROOTFS_POSTPROCESS_COMMAND_prepend = "${@'cve_check_write_rootfs_manifest; ' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500144do_rootfs[recrdeptask] += "${@'do_cve_check' if d.getVar('CVE_CHECK_CREATE_MANIFEST') == '1' else ''}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600145
146def get_patches_cves(d):
147 """
148 Get patches that solve CVEs using the "CVE: " tag.
149 """
150
151 import re
152
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500153 pn = d.getVar("PN")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600154 cve_match = re.compile("CVE:( CVE\-\d{4}\-\d+)+")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500155
156 # Matches last CVE-1234-211432 in the file name, also if written
157 # with small letters. Not supporting multiple CVE id's in a single
158 # file name.
159 cve_file_name_match = re.compile(".*([Cc][Vv][Ee]\-\d{4}\-\d+)")
160
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600161 patched_cves = set()
162 bb.debug(2, "Looking for patches that solves CVEs for %s" % pn)
163 for url in src_patches(d):
164 patch_file = bb.fetch.decodeurl(url)[2]
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500165
Andrew Geissler82c905d2020-04-13 13:39:40 -0500166 if not os.path.isfile(patch_file):
167 bb.error("File Not found: %s" % patch_file)
168 raise FileNotFoundError
169
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500170 # Check patch file name for CVE ID
171 fname_match = cve_file_name_match.search(patch_file)
172 if fname_match:
173 cve = fname_match.group(1).upper()
174 patched_cves.add(cve)
175 bb.debug(2, "Found CVE %s from patch file name %s" % (cve, patch_file))
176
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600177 with open(patch_file, "r", encoding="utf-8") as f:
178 try:
179 patch_text = f.read()
180 except UnicodeDecodeError:
181 bb.debug(1, "Failed to read patch %s using UTF-8 encoding"
182 " trying with iso8859-1" % patch_file)
183 f.close()
184 with open(patch_file, "r", encoding="iso8859-1") as f:
185 patch_text = f.read()
186
Brad Bishopbba38f32018-08-23 16:11:46 +0800187 # Search for one or more "CVE: " lines
188 text_match = False
189 for match in cve_match.finditer(patch_text):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600190 # Get only the CVEs without the "CVE: " tag
191 cves = patch_text[match.start()+5:match.end()]
192 for cve in cves.split():
193 bb.debug(2, "Patch %s solves %s" % (patch_file, cve))
194 patched_cves.add(cve)
Brad Bishopbba38f32018-08-23 16:11:46 +0800195 text_match = True
196
197 if not fname_match and not text_match:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600198 bb.debug(2, "Patch %s doesn't solve CVEs" % patch_file)
199
200 return patched_cves
201
202def check_cves(d, patched_cves):
203 """
Brad Bishopf3fd2882019-06-21 08:06:37 -0400204 Connect to the NVD database and find unpatched cves.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600205 """
Brad Bishopf3fd2882019-06-21 08:06:37 -0400206 from distutils.version import LooseVersion
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600207
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600208 cves_unpatched = []
Brad Bishopf3fd2882019-06-21 08:06:37 -0400209 # CVE_PRODUCT can contain more than one product (eg. curl/libcurl)
Brad Bishop96ff1982019-08-19 13:50:42 -0400210 products = d.getVar("CVE_PRODUCT").split()
Brad Bishop316dfdd2018-06-25 12:45:53 -0400211 # If this has been unset then we're not scanning for CVEs here (for example, image recipes)
Brad Bishop96ff1982019-08-19 13:50:42 -0400212 if not products:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500213 return ([], [], [])
Brad Bishop316dfdd2018-06-25 12:45:53 -0400214 pv = d.getVar("CVE_VERSION").split("+git")[0]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600215
216 # If the recipe has been whitlisted we return empty lists
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500217 if d.getVar("PN") in d.getVar("CVE_CHECK_PN_WHITELIST").split():
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600218 bb.note("Recipe has been whitelisted, skipping check")
Andrew Geissler82c905d2020-04-13 13:39:40 -0500219 return ([], [], [])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600220
Brad Bishop96ff1982019-08-19 13:50:42 -0400221 old_cve_whitelist = d.getVar("CVE_CHECK_CVE_WHITELIST")
222 if old_cve_whitelist:
223 bb.warn("CVE_CHECK_CVE_WHITELIST is deprecated, please use CVE_CHECK_WHITELIST.")
224 cve_whitelist = d.getVar("CVE_CHECK_WHITELIST").split()
225
Brad Bishopf3fd2882019-06-21 08:06:37 -0400226 import sqlite3
Brad Bishop6dbb3162019-11-25 09:41:34 -0500227 db_file = d.expand("file:${CVE_CHECK_DB_FILE}?mode=ro")
228 conn = sqlite3.connect(db_file, uri=True)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600229
Brad Bishop6dbb3162019-11-25 09:41:34 -0500230 # For each of the known product names (e.g. curl has CPEs using curl and libcurl)...
Brad Bishop96ff1982019-08-19 13:50:42 -0400231 for product in products:
Brad Bishop96ff1982019-08-19 13:50:42 -0400232 if ":" in product:
233 vendor, product = product.split(":", 1)
Brad Bishop96ff1982019-08-19 13:50:42 -0400234 else:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500235 vendor = "%"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600236
Brad Bishop6dbb3162019-11-25 09:41:34 -0500237 # Find all relevant CVE IDs.
238 for cverow in conn.execute("SELECT DISTINCT ID FROM PRODUCTS WHERE PRODUCT IS ? AND VENDOR LIKE ?", (product, vendor)):
239 cve = cverow[0]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600240
Brad Bishop96ff1982019-08-19 13:50:42 -0400241 if cve in cve_whitelist:
242 bb.note("%s-%s has been whitelisted for %s" % (product, pv, cve))
Brad Bishop64c979e2019-11-04 13:55:29 -0500243 # TODO: this should be in the report as 'whitelisted'
244 patched_cves.add(cve)
Brad Bishop6dbb3162019-11-25 09:41:34 -0500245 continue
Brad Bishopf3fd2882019-06-21 08:06:37 -0400246 elif cve in patched_cves:
247 bb.note("%s has been patched" % (cve))
Brad Bishop6dbb3162019-11-25 09:41:34 -0500248 continue
249
250 vulnerable = False
251 for row in conn.execute("SELECT * FROM PRODUCTS WHERE ID IS ? AND PRODUCT IS ? AND VENDOR LIKE ?", (cve, product, vendor)):
252 (_, _, _, version_start, operator_start, version_end, operator_end) = row
253 #bb.debug(2, "Evaluating row " + str(row))
254
Andrew Geissler82c905d2020-04-13 13:39:40 -0500255 if (operator_start == '=' and pv == version_start) or version_start == '-':
Brad Bishop6dbb3162019-11-25 09:41:34 -0500256 vulnerable = True
Brad Bishop96ff1982019-08-19 13:50:42 -0400257 else:
258 if operator_start:
259 try:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500260 vulnerable_start = (operator_start == '>=' and LooseVersion(pv) >= LooseVersion(version_start))
261 vulnerable_start |= (operator_start == '>' and LooseVersion(pv) > LooseVersion(version_start))
Brad Bishop96ff1982019-08-19 13:50:42 -0400262 except:
Brad Bishop64c979e2019-11-04 13:55:29 -0500263 bb.warn("%s: Failed to compare %s %s %s for %s" %
Brad Bishop96ff1982019-08-19 13:50:42 -0400264 (product, pv, operator_start, version_start, cve))
Brad Bishop6dbb3162019-11-25 09:41:34 -0500265 vulnerable_start = False
Brad Bishop96ff1982019-08-19 13:50:42 -0400266 else:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500267 vulnerable_start = False
Brad Bishop96ff1982019-08-19 13:50:42 -0400268
269 if operator_end:
270 try:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500271 vulnerable_end = (operator_end == '<=' and LooseVersion(pv) <= LooseVersion(version_end))
272 vulnerable_end |= (operator_end == '<' and LooseVersion(pv) < LooseVersion(version_end))
Brad Bishop96ff1982019-08-19 13:50:42 -0400273 except:
Brad Bishop64c979e2019-11-04 13:55:29 -0500274 bb.warn("%s: Failed to compare %s %s %s for %s" %
Brad Bishop96ff1982019-08-19 13:50:42 -0400275 (product, pv, operator_end, version_end, cve))
Brad Bishop6dbb3162019-11-25 09:41:34 -0500276 vulnerable_end = False
Brad Bishop96ff1982019-08-19 13:50:42 -0400277 else:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500278 vulnerable_end = False
Brad Bishop96ff1982019-08-19 13:50:42 -0400279
280 if operator_start and operator_end:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500281 vulnerable = vulnerable_start and vulnerable_end
Brad Bishop96ff1982019-08-19 13:50:42 -0400282 else:
Brad Bishop6dbb3162019-11-25 09:41:34 -0500283 vulnerable = vulnerable_start or vulnerable_end
Brad Bishop96ff1982019-08-19 13:50:42 -0400284
Brad Bishop6dbb3162019-11-25 09:41:34 -0500285 if vulnerable:
Brad Bishop64c979e2019-11-04 13:55:29 -0500286 bb.note("%s-%s is vulnerable to %s" % (product, pv, cve))
Brad Bishop96ff1982019-08-19 13:50:42 -0400287 cves_unpatched.append(cve)
Brad Bishop6dbb3162019-11-25 09:41:34 -0500288 break
289
290 if not vulnerable:
291 bb.note("%s-%s is not vulnerable to %s" % (product, pv, cve))
292 # TODO: not patched but not vulnerable
293 patched_cves.add(cve)
294
Brad Bishopf3fd2882019-06-21 08:06:37 -0400295 conn.close()
296
Andrew Geissler82c905d2020-04-13 13:39:40 -0500297 return (list(cve_whitelist), list(patched_cves), cves_unpatched)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600298
299def get_cve_info(d, cves):
300 """
Brad Bishop96ff1982019-08-19 13:50:42 -0400301 Get CVE information from the database.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600302 """
303
Brad Bishop6dbb3162019-11-25 09:41:34 -0500304 import sqlite3
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600305
306 cve_data = {}
Brad Bishop6dbb3162019-11-25 09:41:34 -0500307 conn = sqlite3.connect(d.getVar("CVE_CHECK_DB_FILE"))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600308
Brad Bishop6dbb3162019-11-25 09:41:34 -0500309 for cve in cves:
310 for row in conn.execute("SELECT * FROM NVD WHERE ID IS ?", (cve,)):
311 cve_data[row[0]] = {}
312 cve_data[row[0]]["summary"] = row[1]
313 cve_data[row[0]]["scorev2"] = row[2]
314 cve_data[row[0]]["scorev3"] = row[3]
315 cve_data[row[0]]["modified"] = row[4]
316 cve_data[row[0]]["vector"] = row[5]
317
318 conn.close()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600319 return cve_data
320
Andrew Geissler82c905d2020-04-13 13:39:40 -0500321def cve_write_data(d, patched, unpatched, whitelisted, cve_data):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600322 """
323 Write CVE information in WORKDIR; and to CVE_CHECK_DIR, and
324 CVE manifest if enabled.
325 """
326
Brad Bishop316dfdd2018-06-25 12:45:53 -0400327 cve_file = d.getVar("CVE_CHECK_LOG")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600328 nvd_link = "https://web.nvd.nist.gov/view/vuln/detail?vulnId="
329 write_string = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500330 unpatched_cves = []
Brad Bishop316dfdd2018-06-25 12:45:53 -0400331 bb.utils.mkdirhier(os.path.dirname(cve_file))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600332
333 for cve in sorted(cve_data):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500334 write_string += "PACKAGE NAME: %s\n" % d.getVar("PN")
Andrew Geissler4ed12e12020-06-05 18:00:41 -0500335 write_string += "PACKAGE VERSION: %s%s\n" % (d.getVar("EXTENDPE"), d.getVar("PV"))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600336 write_string += "CVE: %s\n" % cve
Andrew Geissler82c905d2020-04-13 13:39:40 -0500337 if cve in whitelisted:
338 write_string += "CVE STATUS: Whitelisted\n"
339 elif cve in patched:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600340 write_string += "CVE STATUS: Patched\n"
341 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500342 unpatched_cves.append(cve)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600343 write_string += "CVE STATUS: Unpatched\n"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600344 write_string += "CVE SUMMARY: %s\n" % cve_data[cve]["summary"]
Brad Bishopf3fd2882019-06-21 08:06:37 -0400345 write_string += "CVSS v2 BASE SCORE: %s\n" % cve_data[cve]["scorev2"]
346 write_string += "CVSS v3 BASE SCORE: %s\n" % cve_data[cve]["scorev3"]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600347 write_string += "VECTOR: %s\n" % cve_data[cve]["vector"]
348 write_string += "MORE INFORMATION: %s%s\n\n" % (nvd_link, cve)
349
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500350 if unpatched_cves:
351 bb.warn("Found unpatched CVE (%s), for more information check %s" % (" ".join(unpatched_cves),cve_file))
352
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600353 with open(cve_file, "w") as f:
354 bb.note("Writing file %s with CVE information" % cve_file)
355 f.write(write_string)
356
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500357 if d.getVar("CVE_CHECK_COPY_FILES") == "1":
358 cve_dir = d.getVar("CVE_CHECK_DIR")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600359 bb.utils.mkdirhier(cve_dir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500360 deploy_file = os.path.join(cve_dir, d.getVar("PN"))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600361 with open(deploy_file, "w") as f:
362 f.write(write_string)
363
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500364 if d.getVar("CVE_CHECK_CREATE_MANIFEST") == "1":
Andrew Geisslerb7d28612020-07-24 16:15:54 -0500365 cvelogpath = d.getVar("CVE_CHECK_SUMMARY_DIR")
366 bb.utils.mkdirhier(cvelogpath)
367
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500368 with open(d.getVar("CVE_CHECK_TMP_FILE"), "a") as f:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600369 f.write("%s" % write_string)