diff options
| author | GeogeFI | 2022-12-25 22:35:03 +0100 |
|---|---|---|
| committer | GeogeFI | 2022-12-25 22:35:03 +0100 |
| commit | 33cc8b4200a197603354b1142d1f4a4e964bd88b (patch) | |
| tree | 917e7fe258333f2b3cccd4bafab900a380aa0201 | |
| parent | 9087cf1e35b9ad1bbe6a003bbfecdb96b9f7bb0e (diff) | |
| download | sec-certs-33cc8b4200a197603354b1142d1f4a4e964bd88b.tar.gz sec-certs-33cc8b4200a197603354b1142d1f4a4e964bd88b.tar.zst sec-certs-33cc8b4200a197603354b1142d1f4a4e964bd88b.zip | |
refactor: Refactoring from notes of code review
| -rw-r--r-- | src/sec_certs/dataset/cve.py | 1 | ||||
| -rw-r--r-- | src/sec_certs/sample/cpe.py | 6 | ||||
| -rw-r--r-- | src/sec_certs/sample/cve.py | 13 |
3 files changed, 14 insertions, 6 deletions
diff --git a/src/sec_certs/dataset/cve.py b/src/sec_certs/dataset/cve.py index 6960c6fc..566bc2e4 100644 --- a/src/sec_certs/dataset/cve.py +++ b/src/sec_certs/dataset/cve.py @@ -35,6 +35,7 @@ class CVEDataset(JSONPathDataset, ComplexSerializableType): self.cves = cves self.json_path = Path(json_path) self.cpe_to_cve_ids_lookup: dict[str, set[str]] = dict() + self.cves_with_vulnerable_configurations: list[CVE] = [] @property def serialized_attributes(self) -> list[str]: diff --git a/src/sec_certs/sample/cpe.py b/src/sec_certs/sample/cpe.py index 29e078b6..0c8cd149 100644 --- a/src/sec_certs/sample/cpe.py +++ b/src/sec_certs/sample/cpe.py @@ -19,6 +19,12 @@ class CPEConfiguration(ComplexSerializableType): self.platform: str = platform self.cpes: set[str] = cpes + def __hash__(self) -> int: + return hash(self.platform) + sum([hash(cpe) for cpe in self.cpes]) + + def __lt__(self, other: CPEConfiguration) -> bool: + return self.platform < other.platform + def __eq__(self, other: Any) -> bool: return isinstance(other, self.__class__) and self.platform == other.platform and self.cpes == other.cpes diff --git a/src/sec_certs/sample/cve.py b/src/sec_certs/sample/cve.py index d3ea1590..caf2b4d7 100644 --- a/src/sec_certs/sample/cve.py +++ b/src/sec_certs/sample/cve.py @@ -47,8 +47,8 @@ class CVE(PandasSerializableType, ComplexSerializableType): raise ValueError("NIST Dict for CVE Impact badly formatted.") cve_id: str - vulnerable_cpes: list[CPE] - vulnerable_cpe_configurations: list[CPEConfiguration] + vulnerable_cpes: set[CPE] + vulnerable_cpe_configurations: set[CPEConfiguration] impact: Impact published_date: datetime.datetime | None cwe_ids: set[str] | None @@ -69,8 +69,8 @@ class CVE(PandasSerializableType, ComplexSerializableType): def __init__( self, cve_id: str, - vulnerable_cpes: list[CPE], - vulnerable_cpe_configurations: list[CPEConfiguration], + vulnerable_cpes: set[CPE], + vulnerable_cpe_configurations: set[CPEConfiguration], impact: Impact, published_date: str, cwe_ids: set[str] | None, @@ -220,8 +220,9 @@ class CVE(PandasSerializableType, ComplexSerializableType): cve_id = dct["cve"]["CVE_data_meta"]["ID"] impact = cls.Impact.from_nist_dict(dct) cpe_and_cpe_configurations = get_vulnerable_cpes_from_nist_dict(dct) - vulnerable_cpes = list(itertools.chain.from_iterable(cpe_and_cpe_configurations[0])) - vulnerable_cpe_configurations = list(itertools.chain.from_iterable(cpe_and_cpe_configurations[1])) + # There exist CVEs such as (CVE-2022-0177) which are rejected and do not contain any assinged CPEs + vulnerable_cpes = set(itertools.chain.from_iterable(cpe_and_cpe_configurations[0])) if cpe_and_cpe_configurations else set() + vulnerable_cpe_configurations = set(itertools.chain.from_iterable(cpe_and_cpe_configurations[1])) if cpe_and_cpe_configurations else set() published_date = dct["publishedDate"] cwe_ids = cls.parse_cwe_data(dct) |
