support/scripts/pkg-stats: fix typos
PATCH v2 1/7 support/scripts/pkg-stats: fix typos
--- support/scripts/pkg-stats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
support/scripts/pkg-stats +3 -3
@@ -84,7 +84,7 @@ class Package: all_ignored_cves = dict() all_cpeids = dict() # This is the list of all possible checks. Add new checks to this list so - # a tool that post-processeds the json output knows the checks before + # a tool that post-processes the json output knows the checks before # iterating over the packages. status_checks = ['cve', 'developers', 'hash', 'license', 'license-files', 'patches', 'pkg-check', 'url', 'version']
@@ -259,7 +259,7 @@ class Package: if var in self.all_cpeids: self.cpeid = self.all_cpeids[var] # Set a preliminary status, it might be overridden by check_package_cpes() - self.status['cpe'] = ("warning", "not checked against CPE dictionnary") + self.status['cpe'] = ("warning", "not checked against CPE dictionary") else: self.status['cpe'] = ("error", "no verified CPE identifier")
@@ -499,7 +499,7 @@ def check_package_latest_version_set_status(pkg, status, version, identifier): async def check_package_get_latest_version_by_distro(session, pkg, retry=True): - url = "https://release-monitoring.org//api/project/Buildroot/%s" % pkg.name + url = "https://release-monitoring.org/api/project/Buildroot/%s" % pkg.name try: async with session.get(url) as resp: if resp.status != 200:
Signature · 6 lines
2.41.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 2/7 support/scripts/pkg-stats: ignore llvm-project.mk
Fixes:
f6eaf60 ("package/llvm-project: new group for llvm packages")
--- support/scripts/pkg-stats | 1 + 1 file changed, 1 insertion(+)
support/scripts/pkg-stats +1 -0
@@ -345,6 +345,7 @@ def get_pkglist(npackages, package_list): "package/gstreamer/gstreamer.mk", "package/gstreamer1/gstreamer1.mk", "package/gtk2-themes/gtk2-themes.mk", + "package/llvm-project/llvm-project.mk", "package/matchbox/matchbox.mk", "package/opengl/opengl.mk", "package/qt5/qt5.mk",
Signature · 6 lines
2.41.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 3/7 support/scripts/{cpedb, cve}.py: rework CPE ID handling
In reply to Daniel LangBoth files define helpers to extract various elements from a given CPE ID. Combine these helpers into a new class with only static methods.
--- support/scripts/cpedb.py | 62 ++++++++++++++++++++------------- support/scripts/cve.py | 29 ++++----------- support/scripts/gen-missing-cpe | 6 ++-- support/scripts/pkg-stats | 4 +-- 4 files changed, 48 insertions(+), 53 deletions(-)
support/scripts/cpedb.py +37 -25
@@ -19,6 +19,38 @@ ns = { } +class CPE_ID: + # Check if two CPE IDs match each other + @staticmethod + def matches(cpe1, cpe2): + cpe1_elems = cpe1.split(":") + cpe2_elems = cpe2.split(":") + + remains = filter(lambda x: x[0] not in ["*", "-"] and x[1] not in ["*", "-"] and x[0] != x[1], + zip(cpe1_elems, cpe2_elems)) + return len(list(remains)) == 0 + + @staticmethod + def version(cpe): + return cpe.split(":")[5] + + @staticmethod + def product(cpe): + return cpe.split(":")[4] + + @staticmethod + def short_name(cpe): + return ":".join(cpe.split(":")[2:6]) + + @staticmethod + def version_update(cpe): + return ":".join(cpe.split(":")[5:6]) + + @staticmethod + def no_version(cpe): + return ":".join(cpe.split(":")[:5]) + + class CPE: def __init__(self, cpe_str, titles, refs): self.cpe_str = cpe_str
@@ -48,8 +80,8 @@ class CPE: "http://scap.nist.gov/schema/scap-core/0.1", "https://scap.nist.gov/schema/nvd/scap-core_0.1.xsd"])) item = SubElement(cpes, 'cpe-item') - cpe_short_name = CPE.short_name(self.cpe_str) - cpe_new_ver = CPE.version_update(self.cpe_str) + cpe_short_name = CPE_ID.short_name(self.cpe_str) + cpe_new_ver = CPE_ID.version_update(self.cpe_str) item.set('name', 'cpe:/' + cpe_short_name) self.titles[0].text.replace(self.cpe_cur_ver, cpe_new_ver)
@@ -66,26 +98,6 @@ class CPE: # And use minidom to pretty print the XML return minidom.parseString(xmlstr).toprettyxml(encoding="utf-8").decode("utf-8") - @staticmethod - def version(cpe): - return cpe.split(":")[5] - - @staticmethod - def product(cpe): - return cpe.split(":")[4] - - @staticmethod - def short_name(cpe): - return ":".join(cpe.split(":")[2:6]) - - @staticmethod - def version_update(cpe): - return ":".join(cpe.split(":")[5:6]) - - @staticmethod - def no_version(cpe): - return ":".join(cpe.split(":")[:5]) - class CPEDB: def __init__(self, nvd_path):
@@ -138,7 +150,7 @@ class CPEDB: cpe_str = cpe.find(".//{http://scap.nist.gov/schema/cpe-extension/2.3}cpe23-item").get('name') item = CPE(cpe_str, cpe_titles, cpe_ref) - cpe_str_no_version = CPE.no_version(cpe_str) + cpe_str_no_version = CPE_ID.no_version(cpe_str) # This dict must have a unique key for every CPE version # which allows matching to the specific obj data of that # NIST dict entry
@@ -151,12 +163,12 @@ class CPEDB: self.all_cpes_no_version.update({cpe_str_no_version: item}) def find_partial(self, cpe_str): - cpe_str_no_version = CPE.no_version(cpe_str) + cpe_str_no_version = CPE_ID.no_version(cpe_str) if cpe_str_no_version in self.all_cpes_no_version: return cpe_str_no_version def find_partial_obj(self, cpe_str): - cpe_str_no_version = CPE.no_version(cpe_str) + cpe_str_no_version = CPE_ID.no_version(cpe_str) if cpe_str_no_version in self.all_cpes_no_version: return self.all_cpes_no_version[cpe_str_no_version]
support/scripts/cve.py +6 -23
@@ -25,6 +25,7 @@ import time import gzip import sys import operator +from cpedb import CPE_ID try: import ijson
@@ -53,24 +54,6 @@ ops = { } -# Check if two CPE IDs match each other -def cpe_matches(cpe1, cpe2): - cpe1_elems = cpe1.split(":") - cpe2_elems = cpe2.split(":") - - remains = filter(lambda x: x[0] not in ["*", "-"] and x[1] not in ["*", "-"] and x[0] != x[1], - zip(cpe1_elems, cpe2_elems)) - return len(list(remains)) == 0 - - -def cpe_product(cpe): - return cpe.split(':')[4] - - -def cpe_version(cpe): - return cpe.split(':')[5] - - class CVE: """An accessor class for CVE Items in NVD files""" CVE_AFFECTS = 1
@@ -158,8 +141,8 @@ class CVE: for cpe in node.get('cpe_match', ()): if not cpe['vulnerable']: return - product = cpe_product(cpe['cpe23Uri']) - version = cpe_version(cpe['cpe23Uri']) + product = CPE_ID.product(cpe['cpe23Uri']) + version = CPE_ID.version(cpe['cpe23Uri']) # ignore when product is '-', which means N/A if product == '-': return
@@ -211,7 +194,7 @@ class CVE: @property def affected_products(self): """The set of CPE products referred by this CVE definition""" - return set(cpe_product(p['id']) for p in self.each_cpe()) + return set(CPE_ID.product(p['id']) for p in self.each_cpe()) def affects(self, name, version, cve_ignore_list, cpeid=None): """
@@ -233,10 +216,10 @@ class CVE: # version, as they might be different due to # <pkg>_CPE_ID_VERSION else: - pkg_version = distutils.version.LooseVersion(cpe_version(cpeid)) + pkg_version = distutils.version.LooseVersion(CPE_ID.version(cpeid)) for cpe in self.each_cpe(): - if not cpe_matches(cpe['id'], cpeid): + if not CPE_ID.matches(cpe['id'], cpeid): continue if not cpe['v_start'] and not cpe['v_end']: return self.CVE_AFFECTS
support/scripts/gen-missing-cpe +3 -3
@@ -5,7 +5,7 @@ import sys import json import subprocess import os -from cpedb import CPEDB, CPE +from cpedb import CPEDB, CPE_ID def gen_update_xml_reports(cpeids, cpedb, output):
@@ -14,7 +14,7 @@ def gen_update_xml_reports(cpeids, cpedb, output): for cpe in cpeids: result = cpedb.find(cpe) if not result: - result = cpedb.find_partial(CPE.no_version(cpe)) + result = cpedb.find_partial(CPE_ID.no_version(cpe)) if result: cpe_need_update.append(cpe) else:
@@ -22,7 +22,7 @@ def gen_update_xml_reports(cpeids, cpedb, output): for cpe in cpe_need_update: xml = cpedb.gen_update_xml(cpe) - fname = CPE.product(cpe) + '-' + CPE.version(cpe) + '.xml' + fname = CPE_ID.product(cpe) + '-' + CPE_ID.version(cpe) + '.xml' print("Generating %s" % fname) with open(os.path.join(output, fname), 'w+') as fp: fp.write(xml)
support/scripts/pkg-stats +2 -2
@@ -37,7 +37,7 @@ brpath = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")) sys.path.append(os.path.join(brpath, "utils")) from getdeveloperlib import parse_developers # noqa: E402 -from cpedb import CPEDB_URL # noqa: E402 +from cpedb import CPEDB_URL, CPE_ID # noqa: E402 INFRA_RE = re.compile(r"\$\(eval \$\(([a-z-]*)-package\)\)") URL_RE = re.compile(r"\s*https?://\S*\s*$")
@@ -632,7 +632,7 @@ def check_package_cves(nvd_path, packages): pkg.status['cve'] = ("na", "no version information available") continue if pkg.cpeid: - cpe_product = cvecheck.cpe_product(pkg.cpeid) + cpe_product = CPE_ID.product(pkg.cpeid) cpe_product_pkgs[cpe_product].append(pkg) else: cpe_product_pkgs[pkg.name].append(pkg)
Signature · 6 lines
2.41.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 4/7 support/scripts/nvd_api_v2.py: new helper class
In reply to Daniel LangThe current NVD data feeds used for CVE and CPE checking will be retired by 2023-12-05 [0]. Both have to be switched to the new v2 API. Since fetching data from both sources workes the same, a common base class is used to handle the API interaction.
To store the data locally a sqlite database is used.
[0]: https://nvd.nist.gov/General/News/change-timeline
--- DEVELOPERS | 1 + support/scripts/nvd_api_v2.py | 138 ++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100755 support/scripts/nvd_api_v2.py
DEVELOPERS +1 -0
@@ -668,6 +668,7 @@ F: package/paho-mqtt-cpp/ F: package/pangomm/ F: package/pangomm2_46/ F: package/sam-ba/ +F: support/scripts/nvd_api_v2.py N: Damien Lanson <[email protected]> F: package/libvdpau/
support/scripts/nvd_api_v2.py new file +138 -0
138 lines not on this page · raw message
Signature · 6 lines
2.41.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 5/7 support/scripts/cve.py: switch to NVD API v2
In reply to Daniel LangThe currently used feed will be retired in December 2023 [0]. As an alternative the new v2 API [1]. The new API allows downloading sets of CVEs (2k at a time) that were modified after a given UTC timestamp. Rate limiting of 5 requests in a sliding 30 seconds window is used [2].
[0]: https://nvd.nist.gov/General/News/change-timeline
[1]: https://nvd.nist.gov/developers/vulnerabilities
[2]: https://nvd.nist.gov/developers/start-here
---
v1 -> v2:
- switch to sqlite database for a more future proof storage
--- DEVELOPERS | 1 + support/scripts/cve.py | 415 ++++++++++++++++++++------------------ support/scripts/pkg-stats | 27 ++- 3 files changed, 236 insertions(+), 207 deletions(-)
DEVELOPERS +1 -0
@@ -668,6 +668,7 @@ F: package/paho-mqtt-cpp/ F: package/pangomm/ F: package/pangomm2_46/ F: package/sam-ba/ +F: support/scripts/cve.py F: support/scripts/nvd_api_v2.py N: Damien Lanson <[email protected]>
support/scripts/cve.py +222 -193
444 lines not on this page · raw message
support/scripts/pkg-stats +13 -14
@@ -32,6 +32,7 @@ import time import gzip import xml.etree.ElementTree import requests +from cve import CVE_API brpath = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))
@@ -608,15 +609,17 @@ async def check_package_latest_version(packages): def check_package_cve_affects(cve, cpe_product_pkgs): - for product in cve.affected_products: - if product not in cpe_product_pkgs: + product = cve.affected_product + if product not in cpe_product_pkgs: + return + for pkg in cpe_product_pkgs[product]: + if cve.identifier in pkg.cves or cve.identifier in pkg.unsure_cves: continue - for pkg in cpe_product_pkgs[product]: - cve_status = cve.affects(pkg.name, pkg.current_version, pkg.ignored_cves, pkg.cpeid) - if cve_status == cve.CVE_AFFECTS: - pkg.cves.append(cve.identifier) - elif cve_status == cve.CVE_UNKNOWN: - pkg.unsure_cves.append(cve.identifier) + cve_status = cve.affects(pkg.name, pkg.current_version, pkg.ignored_cves, pkg.cpeid) + if cve_status == cve.CVE_AFFECTS: + pkg.cves.append(cve.identifier) + elif cve_status == cve.CVE_UNKNOWN: + pkg.unsure_cves.append(cve.identifier) def check_package_cves(nvd_path, packages):
@@ -637,7 +640,8 @@ def check_package_cves(nvd_path, packages): else: cpe_product_pkgs[pkg.name].append(pkg) - for cve in cvecheck.CVE.read_nvd_dir(nvd_path): + cve_api = CVE_API(nvd_path) + for cve in cve_api.load_all(): check_package_cve_affects(cve, cpe_product_pkgs) for pkg in packages:
@@ -1286,13 +1290,8 @@ def parse_args(): def __main__(): - global cvecheck - args = parse_args() - if args.nvd_path: - import cve as cvecheck - show_info_js = None if args.packages: package_list = args.packages.split(",")
Signature · 6 lines
2.41.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 6/7 support/scripts/cpedb.py: switch to NVD API v2
In reply to Daniel LangThe currently used feed will be retired in December 2023 [0]. As an alternative the new v2 API [1]. The new API allows downloading sets of CPEs (10k at a time) that were modified after a given UTC timestamp. Rate limiting of 5 requests in a sliding 30 seconds window is used [2].
Rename script to match the CVE naming.
[0]: https://nvd.nist.gov/General/News/change-timeline
[1]: https://nvd.nist.gov/developers/products
[2]: https://nvd.nist.gov/developers/start-here
--- DEVELOPERS | 1 + support/scripts/cpe.py | 225 ++++++++++++++++++++++++++++++++ support/scripts/cpedb.py | 186 -------------------------- support/scripts/cve.py | 2 +- support/scripts/gen-missing-cpe | 27 ++-- support/scripts/pkg-stats | 39 +----- 6 files changed, 244 insertions(+), 236 deletions(-) create mode 100755 support/scripts/cpe.py delete mode 100644 support/scripts/cpedb.py
DEVELOPERS +1 -0
@@ -668,6 +668,7 @@ F: package/paho-mqtt-cpp/ F: package/pangomm/ F: package/pangomm2_46/ F: package/sam-ba/ +F: support/scripts/cpe.py F: support/scripts/cve.py F: support/scripts/nvd_api_v2.py
support/scripts/cpe.py new file +225 -0
225 lines not on this page · raw message
support/scripts/cpedb.py deleted +0 -186
186 lines not on this page · raw message
support/scripts/cve.py +1 -1
@@ -20,7 +20,7 @@ import distutils.version import operator from nvd_api_v2 import NVD_API -from cpedb import CPE_ID +from cpe import CPE_ID class CVE:
support/scripts/gen-missing-cpe +14 -13
@@ -5,23 +5,23 @@ import sys import json import subprocess import os -from cpedb import CPEDB, CPE_ID +from cpe import CPE_API, CPE_ID -def gen_update_xml_reports(cpeids, cpedb, output): +def gen_update_xml_reports(cpeids, cpe_api, output): cpe_need_update = [] for cpe in cpeids: - result = cpedb.find(cpe) - if not result: - result = cpedb.find_partial(CPE_ID.no_version(cpe)) - if result: - cpe_need_update.append(cpe) - else: - print("WARNING: no match found for '%s'" % cpe) + if cpe_api.is_official(cpe): + continue + result = cpe_api.find_partial(cpe) + if result: + cpe_need_update.append(cpe) + else: + print("WARNING: no match found for '%s'" % cpe) for cpe in cpe_need_update: - xml = cpedb.gen_update_xml(cpe) + xml = cpe_api.gen_update_xml(cpe) fname = CPE_ID.product(cpe) + '-' + CPE_ID.version(cpe) + '.xml' print("Generating %s" % fname) with open(os.path.join(output, fname), 'w+') as fp:
@@ -55,10 +55,11 @@ def __main__(): if not os.path.isdir(args.output): print("ERROR: output directory %s does not exist" % args.output) sys.exit(1) - cpedb = CPEDB(args.nvd_path) - cpedb.get_xml_dict() + cpe_api = CPE_API(args.nvd_path) + cpe_api.load_ids() + cpe_api.generate_partials() cpeids = get_cpe_ids() - gen_update_xml_reports(cpeids, cpedb, args.output) + gen_update_xml_reports(cpeids, cpe_api, args.output) if __name__ == "__main__":
support/scripts/pkg-stats +3 -36
@@ -28,17 +28,13 @@ import re import subprocess import json import sys -import time -import gzip -import xml.etree.ElementTree -import requests +from cpe import CPE_API, CPE_ID from cve import CVE_API brpath = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")) sys.path.append(os.path.join(brpath, "utils")) from getdeveloperlib import parse_developers # noqa: E402 -from cpedb import CPEDB_URL, CPE_ID # noqa: E402 INFRA_RE = re.compile(r"\$\(eval \$\(([a-z-]*)-package\)\)") URL_RE = re.compile(r"\s*https?://\S*\s*$")
@@ -653,37 +649,8 @@ def check_package_cves(nvd_path, packages): def check_package_cpes(nvd_path, packages): - class CpeXmlParser: - cpes = [] - - def start(self, tag, attrib): - if tag == "{http://scap.nist.gov/schema/cpe-extension/2.3}cpe23-item": - self.cpes.append(attrib['name']) - - def close(self): - return self.cpes - - print("CPE: Setting up NIST dictionary") - if not os.path.exists(os.path.join(nvd_path, "cpe")): - os.makedirs(os.path.join(nvd_path, "cpe")) - - cpe_dict_local = os.path.join(nvd_path, "cpe", os.path.basename(CPEDB_URL)) - if not os.path.exists(cpe_dict_local) or os.stat(cpe_dict_local).st_mtime < time.time() - 86400: - print("CPE: Fetching xml manifest from [" + CPEDB_URL + "]") - cpe_dict = requests.get(CPEDB_URL) - open(cpe_dict_local, "wb").write(cpe_dict.content) - - print("CPE: Unzipping xml manifest...") - nist_cpe_file = gzip.GzipFile(fileobj=open(cpe_dict_local, 'rb')) - - parser = xml.etree.ElementTree.XMLParser(target=CpeXmlParser()) - while True: - c = nist_cpe_file.read(1024*1024) - if not c: - break - parser.feed(c) - cpes = parser.close() - + cpe_api = CPE_API(nvd_path) + cpes = cpe_api.load_ids() for p in packages: if not p.cpeid: continue
Signature · 6 lines
2.41.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 7/7 support/scripts/pkg-stats: Only match CPE vendor and product
In reply to Daniel LangInstead of checking if the whole CPE string is known in the database, only check if a string with the same vendor and product exists.
--- support/scripts/pkg-stats | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
support/scripts/pkg-stats +3 -2
@@ -650,11 +650,12 @@ def check_package_cves(nvd_path, packages): def check_package_cpes(nvd_path, packages): cpe_api = CPE_API(nvd_path) - cpes = cpe_api.load_ids() + cpe_api.load_ids() + cpe_api.generate_partials() for p in packages: if not p.cpeid: continue - if p.cpeid in cpes: + if cpe_api.find_partial(p.cpeid): p.status['cpe'] = ("ok", "verified CPE identifier") else: p.status['cpe'] = ("error", "CPE version unknown in CPE database")
Signature · 6 lines
2.41.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot