diff options
| author | Adam Janovsky | 2021-04-15 17:59:57 +0200 |
|---|---|---|
| committer | Adam Janovsky | 2021-04-15 17:59:57 +0200 |
| commit | 923cbb555e36bc0375359189a542a601fa82bf2c (patch) | |
| tree | bdccfd2becfa0c16e0979a6a950d4acff0305ae2 | |
| parent | d6a6b223bd689368d9deb86cdaa903ac180e8226 (diff) | |
| download | sec-certs-923cbb555e36bc0375359189a542a601fa82bf2c.tar.gz sec-certs-923cbb555e36bc0375359189a542a601fa82bf2c.tar.zst sec-certs-923cbb555e36bc0375359189a542a601fa82bf2c.zip | |
delete stale fuzzy matching procedure
| -rw-r--r-- | sec_certs/dataset.py | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/sec_certs/dataset.py b/sec_certs/dataset.py index e35e8cd9..c8999bc8 100644 --- a/sec_certs/dataset.py +++ b/sec_certs/dataset.py @@ -695,46 +695,6 @@ class CCDataset(Dataset, ComplexSerializableType): if update_json is True: self.to_json(self.json_path) - # TODO: Probably breaks a logic of ceritifcate managing itself. Needs design refactoring - def fuzzy_match_cpe(self, cpe_path: Path, update_json: bool = False, vuln_cpe_path: Optional[Path] = None): - def get_cpe_titles(cpe_path: Path, only_vuln=True, vuln_path=None): - root = ET.parse(str(cpe_path)).getroot() - if only_vuln and vuln_path: - with vuln_path.open('r') as handle: - vuln_cpes = set(json.load(handle)) - lst = [] - for cpe_item in root.findall('{http://cpe.mitre.org/dictionary/2.0}cpe-item'): - title = cpe_item.find('{http://cpe.mitre.org/dictionary/2.0}title').text - cpe_uri = cpe_item.find('{http://scap.nist.gov/schema/cpe-extension/2.3}cpe23-item').attrib['name'] - if cpe_uri in vuln_cpes: - lst.append(title) - else: - lst = [child.text for child in root.findall('{http://cpe.mitre.org/dictionary/2.0}cpe-item/{http://cpe.mitre.org/dictionary/2.0}title')] - return lst - - digests = [x for x in self.certs.keys()] - logging.info('Loading CPE titles...') - cpe_titles = get_cpe_titles(cpe_path, only_vuln=True, vuln_path=vuln_cpe_path) - logging.info(f'Retreving among {len(cpe_titles)} cpe titles.') - - def chunk_list(a: List, n: int): - k, m = divmod(len(a), n) - return (a[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n)) - - chunks = chunk_list(digests, constants.N_THREADS) - chunks_dicts = [{x: self[x].name for x in y} for y in chunks] - - results = cert_processing.process_parallel(helpers.match_certs, list( - zip(chunks_dicts, [cpe_titles for _ in range(constants.N_THREADS)])), constants.N_THREADS, - use_threading=False, unpack=True) - - for chunk in results: - for digest, matches in chunk.items(): - self[digest].cpe_matching = matches - - if update_json is True: - self.to_json(self.json_path) - class FIPSDataset(Dataset, ComplexSerializableType): FIPS_BASE_URL: ClassVar[str] = 'https://csrc.nist.gov' |
