diff options
| author | Adam Janovsky | 2022-12-10 09:01:55 +0100 |
|---|---|---|
| committer | Adam Janovsky | 2022-12-10 09:01:55 +0100 |
| commit | 53a709e7e16e1ee07e0f4baeb270fcc1d41bb811 (patch) | |
| tree | 1abe1837e9198d165e1bc724190e3488403b3642 | |
| parent | 1c43b173667b2aee8ac64d423b1f46d774643eb3 (diff) | |
| download | sec-certs-53a709e7e16e1ee07e0f4baeb270fcc1d41bb811.tar.gz sec-certs-53a709e7e16e1ee07e0f4baeb270fcc1d41bb811.tar.zst sec-certs-53a709e7e16e1ee07e0f4baeb270fcc1d41bb811.zip | |
Rename CommonCriteriaCert -> CCCertificate
20 files changed, 218 insertions, 218 deletions
diff --git a/docs/api/sample.md b/docs/api/sample.md index 4ff17be1..c07f319c 100644 --- a/docs/api/sample.md +++ b/docs/api/sample.md @@ -9,11 +9,11 @@ The examples related to this package can be found at [common criteria notebook](./../notebooks/examples/common_criteria.ipynb) and [fips notebook](./../notebooks/examples/fips.ipynb). ``` -## CommonCriteriaCert +## CCCertificate ```{eval-rst} .. currentmodule:: sec_certs.sample -.. autoclass:: CommonCriteriaCert +.. autoclass:: CCCertificate :members: ``` diff --git a/notebooks/examples/common_criteria.ipynb b/notebooks/examples/common_criteria.ipynb index 8adb1656..fe53be27 100644 --- a/notebooks/examples/common_criteria.ipynb +++ b/notebooks/examples/common_criteria.ipynb @@ -1,12 +1,13 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Common Criteria example\n", "\n", - "This notebook illustrates basic functionality with the `CCDataset` class that holds Common Criteria dataset and of its sample `CommonCriteriaCert`.\n", + "This notebook illustrates basic functionality with the `CCDataset` class that holds Common Criteria dataset and of its sample `CCCertificate`.\n", "\n", "Note that there exists a front end to this functionality at [seccerts.org/cc](https://seccerts.org/cc/). Before reinventing the wheel, it's good idea to check our web. Maybe you don't even need to run the code, but just use our web instead. " ] @@ -17,8 +18,8 @@ "metadata": {}, "outputs": [], "source": [ - "from sec_certs.dataset.cc import CCDataset\n", - "from sec_certs.sample.cc import CommonCriteriaCert\n", + "from sec_certs.dataset import CCDataset\n", + "from sec_certs.sample import CCCertificate\n", "import pandas as pd" ] }, @@ -77,12 +78,13 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Simple dataset manipulation\n", "\n", - "The certificates of the dataset are stored in a dictionary that maps certificate's primary key (we call it `dgst`) to the `CommonCriteriaCert` object. The primary key of the certificate is simply a hash of the attributes that make the certificate unique.\n", + "The certificates of the dataset are stored in a dictionary that maps certificate's primary key (we call it `dgst`) to the `CCCertificate` object. The primary key of the certificate is simply a hash of the attributes that make the certificate unique.\n", "\n", "You can iterate over the dataset which is handy when selecting some subset of certificates." ] @@ -123,12 +125,13 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Dissect single certificate\n", "\n", - "The `CommonCriteriaCert` is basically a data structure that holds all the data we keep about a certificate. Other classes (`CCDataset` or `model` package members) are used to transform and process the certificates. You can see all its attributes at [API docs](https://seccerts.org/docs/api/sample.html)." + "The `CCCertificate` is basically a data structure that holds all the data we keep about a certificate. Other classes (`CCDataset` or `model` package members) are used to transform and process the certificates. You can see all its attributes at [API docs](https://seccerts.org/docs/api/sample.html)." ] }, { @@ -138,7 +141,7 @@ "outputs": [], "source": [ "# Select a certificate and print some attributes\n", - "cert: CommonCriteriaCert = dset[\"bad93fb821395db2\"]\n", + "cert: CCCertificate = dset[\"bad93fb821395db2\"]\n", "print(f\"{cert.name=}\")\n", "print(f\"{cert.heuristics.cpe_matches=}\")\n", "print(f\"{cert.heuristics.report_references.directly_referencing=}\")" @@ -240,7 +243,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.8.13 (default, Jul 27 2022, 12:09:23) \n[Clang 13.1.6 (clang-1316.0.21.2.3)]" }, "orig_nbformat": 4, "vscode": { diff --git a/src/sec_certs/__init__.py b/src/sec_certs/__init__.py index 816ea2b8..323c53ad 100644 --- a/src/sec_certs/__init__.py +++ b/src/sec_certs/__init__.py @@ -2,6 +2,6 @@ Tool for analysis of security certificates and their security targets (Common Criteria, NIST FIPS140-2...). Contains three main sub-packages: - dataset - package that holds the respective datasets and performs all processing of them -- sample - package that holds a single sample (e.g., Common Criteria certificate - CommonCriteriaCert). Mostly data structure, but can provide basic functionality. +- sample - package that holds a single sample (e.g., Common Criteria certificate - CCCertificate). Mostly data structure, but can provide basic functionality. - model - package that provides data pipelines (transformers, classifiers, ...) for complex transformations of datasets. """ diff --git a/src/sec_certs/dataset/cc.py b/src/sec_certs/dataset/cc.py index 148adbb5..ec661ebe 100644 --- a/src/sec_certs/dataset/cc.py +++ b/src/sec_certs/dataset/cc.py @@ -26,7 +26,7 @@ from sec_certs.dataset.protection_profile import ProtectionProfileDataset from sec_certs.model.reference_finder import ReferenceFinder from sec_certs.model.sar_transformer import SARTransformer from sec_certs.model.transitive_vulnerability_finder import TransitiveVulnerabilityFinder -from sec_certs.sample.cc import CommonCriteriaCert +from sec_certs.sample.cc import CCCertificate from sec_certs.sample.cc_certificate_id import CertificateId from sec_certs.sample.cc_maintenance_update import CommonCriteriaMaintenanceUpdate from sec_certs.sample.protection_profile import ProtectionProfile @@ -44,15 +44,15 @@ class CCAuxillaryDatasets(AuxillaryDatasets): mu_dset: CCDatasetMaintenanceUpdates | None = None -class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSerializableType): +class CCDataset(Dataset[CCCertificate, CCAuxillaryDatasets], ComplexSerializableType): """ - Class that holds CommonCriteriaCert. Serializable into json, pandas, dictionary. Conveys basic certificate manipulations + Class that holds CCCertificate. Serializable into json, pandas, dictionary. Conveys basic certificate manipulations and dataset transformations. Many private methods that perform internal operations, feel free to exploit them. """ def __init__( self, - certs: dict[str, CommonCriteriaCert] = dict(), + certs: dict[str, CCCertificate] = dict(), root_dir: str | Path = constants.DUMMY_NONEXISTING_PATH, name: str | None = None, description: str = "", @@ -76,7 +76,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali """ Return self serialized into pandas DataFrame """ - df = pd.DataFrame([x.pandas_tuple for x in self.certs.values()], columns=CommonCriteriaCert.pandas_columns) + df = pd.DataFrame([x.pandas_tuple for x in self.certs.values()], columns=CCCertificate.pandas_columns) df = df.set_index("dgst") df.not_valid_before = pd.to_datetime(df.not_valid_before, infer_datetime_format=True) @@ -230,7 +230,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali cert.set_local_paths(self.reports_pdf_dir, self.targets_pdf_dir, self.reports_txt_dir, self.targets_txt_dir) # TODO: This forgets to set local paths for other auxillary datasets - def _merge_certs(self, certs: dict[str, CommonCriteriaCert], cert_source: str | None = None) -> None: + def _merge_certs(self, certs: dict[str, CCCertificate], cert_source: str | None = None) -> None: """ Merges dictionary of certificates into the dataset. Assuming they all are CommonCriteria certificates """ @@ -268,7 +268,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali ) -> None: """ Downloads CSV and HTML files that hold lists of certificates from common criteria website. Parses these files - and constructs CommonCriteriaCert objects, fills the dataset with those. + and constructs CCCertificate objects, fills the dataset with those. :param bool to_download: If CSV and HTML files shall be downloaded (or existing files utilized), defaults to True :param bool keep_metadata: If CSV and HTML files shall be kept on disk after download, defaults to True @@ -295,7 +295,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali self._set_local_paths() self.state.meta_sources_parsed = True - def _get_all_certs_from_csv(self, get_active: bool, get_archived: bool) -> dict[str, CommonCriteriaCert]: + def _get_all_certs_from_csv(self, get_active: bool, get_archived: bool) -> dict[str, CCCertificate]: """ Creates dictionary of new certificates from csv sources. """ @@ -311,7 +311,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali return new_certs @staticmethod - def _parse_single_csv(file: Path) -> dict[str, CommonCriteriaCert]: + def _parse_single_csv(file: Path) -> dict[str, CCCertificate]: """ Using pandas, this parses a single CSV file. """ @@ -389,13 +389,13 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali updates: dict[str, set] = {x.dgst: set() for x in df_base.itertuples()} for x in df_main.itertuples(): updates[x.dgst].add( - CommonCriteriaCert.MaintenanceReport( + CCCertificate.MaintenanceReport( x.maintenance_date.date(), x.maintenance_title, x.maintenance_report_link, x.maintenance_st_link ) ) certs = { - x.dgst: CommonCriteriaCert( + x.dgst: CCCertificate( cert_status, x.category, x.cert_name, @@ -418,7 +418,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali } return certs - def _get_all_certs_from_html(self, get_active: bool, get_archived: bool) -> dict[str, CommonCriteriaCert]: + def _get_all_certs_from_html(self, get_active: bool, get_archived: bool) -> dict[str, CCCertificate]: """ Prepares dictionary of certificates from all html files. """ @@ -436,7 +436,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali return new_certs @staticmethod - def _parse_single_html(file: Path) -> dict[str, CommonCriteriaCert]: + def _parse_single_html(file: Path) -> dict[str, CCCertificate]: """ Prepares a dictionary of certificates from a single html file. """ @@ -451,7 +451,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali def _parse_table( soup: BeautifulSoup, cert_status: str, table_id: str, category_string: str - ) -> dict[str, CommonCriteriaCert]: + ) -> dict[str, CCCertificate]: tables = soup.find_all("table", id=table_id) if not len(tables) <= 1: @@ -476,8 +476,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali try: table_certs = { - x.dgst: x - for x in [CommonCriteriaCert.from_html_row(row, cert_status, category_string) for row in body] + x.dgst: x for x in [CCCertificate.from_html_row(row, cert_status, category_string) for row in body] } except ValueError as e: raise ValueError(f"Bad html file: {file.name} ({str(e)})") from e @@ -534,7 +533,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali ) cert_processing.process_parallel( - CommonCriteriaCert.download_pdf_report, + CCCertificate.download_pdf_report, certs_to_process, config.n_threads, progress_bar_desc="Downloading PDFs of CC certification reports", @@ -552,7 +551,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali ) cert_processing.process_parallel( - CommonCriteriaCert.download_pdf_st, + CCCertificate.download_pdf_st, certs_to_process, config.n_threads, progress_bar_desc="Downloading PDFs of CC security targets", @@ -570,7 +569,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali ) cert_processing.process_parallel( - CommonCriteriaCert.convert_report_pdf, + CCCertificate.convert_report_pdf, certs_to_process, config.n_threads, progress_bar_desc="Converting PDFs of certification reports to txt", @@ -588,7 +587,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali ) cert_processing.process_parallel( - CommonCriteriaCert.convert_st_pdf, + CCCertificate.convert_st_pdf, certs_to_process, config.n_threads, progress_bar_desc="Converting PDFs of security targets to txt", @@ -602,7 +601,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali logger.info("Extracting report metadata") certs_to_process = [x for x in self if x.state.report_is_ok_to_analyze()] processed_certs = cert_processing.process_parallel( - CommonCriteriaCert.extract_report_pdf_metadata, + CCCertificate.extract_report_pdf_metadata, certs_to_process, config.n_threads, use_threading=False, @@ -614,7 +613,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali logger.info("Extracting target metadata") certs_to_process = [x for x in self if x.state.st_is_ok_to_analyze()] processed_certs = cert_processing.process_parallel( - CommonCriteriaCert.extract_st_pdf_metadata, + CCCertificate.extract_st_pdf_metadata, certs_to_process, config.n_threads, use_threading=False, @@ -630,7 +629,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali logger.info("Extracting report frontpages") certs_to_process = [x for x in self if x.state.report_is_ok_to_analyze()] processed_certs = cert_processing.process_parallel( - CommonCriteriaCert.extract_report_pdf_frontpage, + CCCertificate.extract_report_pdf_frontpage, certs_to_process, config.n_threads, use_threading=False, @@ -642,7 +641,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali logger.info("Extracting target frontpages") certs_to_process = [x for x in self if x.state.st_is_ok_to_analyze()] processed_certs = cert_processing.process_parallel( - CommonCriteriaCert.extract_st_pdf_frontpage, + CCCertificate.extract_st_pdf_frontpage, certs_to_process, config.n_threads, use_threading=False, @@ -658,7 +657,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali logger.info("Extracting report keywords") certs_to_process = [x for x in self if x.state.report_is_ok_to_analyze()] processed_certs = cert_processing.process_parallel( - CommonCriteriaCert.extract_report_pdf_keywords, + CCCertificate.extract_report_pdf_keywords, certs_to_process, config.n_threads, use_threading=False, @@ -670,7 +669,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali logger.info("Extracting target keywords") certs_to_process = [x for x in self if x.state.st_is_ok_to_analyze()] processed_certs = cert_processing.process_parallel( - CommonCriteriaCert.extract_st_pdf_keywords, + CCCertificate.extract_st_pdf_keywords, certs_to_process, config.n_threads, use_threading=False, @@ -801,7 +800,7 @@ class CCDataset(Dataset[CommonCriteriaCert, CCAuxillaryDatasets], ComplexSeriali self.mu_dataset_dir.mkdir(parents=True, exist_ok=True) if to_download or not self.mu_dataset_path.exists(): - maintained_certs: list[CommonCriteriaCert] = [x for x in self if x.maintenance_updates] + maintained_certs: list[CCCertificate] = [x for x in self if x.maintenance_updates] updates = list( itertools.chain.from_iterable( CommonCriteriaMaintenanceUpdate.get_updates_from_cc_cert(x) for x in maintained_certs @@ -894,7 +893,7 @@ class CCDatasetMaintenanceUpdates(CCDataset, ComplexSerializableType): def get_n_maintenances_df(self) -> pd.DataFrame: """ - Returns a DataFrame with CommonCriteriaCert digest as an index, and number of registered maintenances as a value + Returns a DataFrame with CCCertificate digest as an index, and number of registered maintenances as a value """ main_df = self.to_pandas() main_df.maintenance_date = main_df.maintenance_date.dt.date @@ -907,7 +906,7 @@ class CCDatasetMaintenanceUpdates(CCDataset, ComplexSerializableType): def get_maintenance_dates_df(self) -> pd.DataFrame: """ - Returns a DataFrame with CommonCriteriaCert digest as an index, and all the maintenance dates as a value. + Returns a DataFrame with CCCertificate digest as an index, and all the maintenance dates as a value. """ main_dates = self.to_pandas() main_dates.maintenance_date = main_dates.maintenance_date.map(lambda x: [x]) diff --git a/src/sec_certs/dataset/dataset.py b/src/sec_certs/dataset/dataset.py index 1c89e771..40ea5611 100644 --- a/src/sec_certs/dataset/dataset.py +++ b/src/sec_certs/dataset/dataset.py @@ -565,7 +565,7 @@ class Dataset(Generic[CertSubType, AuxillaryDatasetsSubType], ComplexSerializabl def update_with_certs(self, certs: list[CertSubType]) -> None: """ Enriches the dataset with `certs` - :param List[CommonCriteriaCert] certs: new certs to include into the dataset. + :param List[Certificate] certs: new certs to include into the dataset. """ if any([x not in self for x in certs]): logger.warning("Updating dataset with certificates outside of the dataset!") diff --git a/src/sec_certs/model/evaluation.py b/src/sec_certs/model/evaluation.py index d464c1b7..4d0243f6 100644 --- a/src/sec_certs/model/evaluation.py +++ b/src/sec_certs/model/evaluation.py @@ -8,7 +8,7 @@ import numpy as np import sec_certs.utils.helpers as helpers from sec_certs.dataset.cpe import CPEDataset -from sec_certs.sample.cc import CommonCriteriaCert +from sec_certs.sample.cc import CCCertificate from sec_certs.sample.fips import FIPSCertificate from sec_certs.serialization.json import CustomJSONEncoder @@ -33,7 +33,7 @@ def compute_precision(y: np.ndarray, y_pred: np.ndarray, **kwargs) -> float: def evaluate( - x_valid: list[CommonCriteriaCert | FIPSCertificate], + x_valid: list[CCCertificate | FIPSCertificate], y_valid: list[set[str] | None], outpath: Path | str | None, cpe_dset: CPEDataset, @@ -56,8 +56,8 @@ def evaluate( predicted_cpes = set() predicted_cpes_dict = {x: cpe_dset[x].title if cpe_dset[x].title else x for x in predicted_cpes} - cert_name = cert.name if isinstance(cert, CommonCriteriaCert) else cert.web_data.module_name - vendor = cert.manufacturer if isinstance(cert, CommonCriteriaCert) else cert.web_data.vendor + cert_name = cert.name if isinstance(cert, CCCertificate) else cert.web_data.module_name + vendor = cert.manufacturer if isinstance(cert, CCCertificate) else cert.web_data.vendor should_be_removed = {x: cpe_dset[x].title if cpe_dset[x].title else x for x in predicted_cpes - verified_cpes} should_be_added = {x: cpe_dset[x].title if cpe_dset[x].title else x for x in verified_cpes - predicted_cpes} diff --git a/src/sec_certs/model/sar_transformer.py b/src/sec_certs/model/sar_transformer.py index 1e05358f..45c4f7d5 100644 --- a/src/sec_certs/model/sar_transformer.py +++ b/src/sec_certs/model/sar_transformer.py @@ -5,7 +5,7 @@ from typing import Dict, Iterable, cast from sklearn.base import BaseEstimator, TransformerMixin -from sec_certs.sample.cc import CommonCriteriaCert +from sec_certs.sample.cc import CCCertificate from sec_certs.sample.sar import SAR, SAR_DICT_KEY logger = logging.getLogger(__name__) @@ -18,39 +18,39 @@ class SARTransformer(BaseEstimator, TransformerMixin): This class implements sklearn transformer interface, so fit_transform() can be called on it. """ - def fit(self, certificates: Iterable[CommonCriteriaCert]) -> SARTransformer: + def fit(self, certificates: Iterable[CCCertificate]) -> SARTransformer: """ Just returns self, no fitting needed - :param Iterable[CommonCriteriaCert] certificates: Unused parameter + :param Iterable[CCCertificate] certificates: Unused parameter :return SARTransformer: return self """ return self - def transform(self, certificates: Iterable[CommonCriteriaCert]) -> list[set[SAR] | None]: + def transform(self, certificates: Iterable[CCCertificate]) -> list[set[SAR] | None]: """ - Just a wrapper around transform_single_cert() called on an iterable of CommonCriteriaCert. + Just a wrapper around transform_single_cert() called on an iterable of CCCertificate. - :param Iterable[CommonCriteriaCert] certificates: Iterable of CommonCriteriaCert objects to perform the extraction on. + :param Iterable[CCCertificate] certificates: Iterable of CCCertificate objects to perform the extraction on. :return List[Optional[Set[SAR]]]: Returns List of results from transform_single_cert(). """ return [self.transform_single_cert(cert) for cert in certificates] - def transform_single_cert(self, cert: CommonCriteriaCert) -> set[SAR] | None: + def transform_single_cert(self, cert: CCCertificate) -> set[SAR] | None: """ - Given CommonCriteriaCert, will transform SAR keywords extracted from txt files + Given CCCertificate, will transform SAR keywords extracted from txt files into a set of SAR objects. Also handles extractin of correct SAR levels, duplicities and filtering. Uses three sources: CSV scan, security target, and certification report. The caller should assure that the certificates have the keywords extracted. - :param CommonCriteriaCert cert: Certificate to extract SARs from + :param CCCertificate cert: Certificate to extract SARs from :return Optional[Set[SAR]]: Set of SARs, None if none were identified. """ sec_level_candidates, st_candidates, report_candidates = self._collect_sar_candidates_from_all_sources(cert) return self._resolve_candidate_conflicts(sec_level_candidates, st_candidates, report_candidates, cert.dgst) @staticmethod - def _collect_sar_candidates_from_all_sources(cert: CommonCriteriaCert) -> tuple[set[SAR], set[SAR], set[SAR]]: + def _collect_sar_candidates_from_all_sources(cert: CCCertificate) -> tuple[set[SAR], set[SAR], set[SAR]]: """ Parses SARs from three distinct sources and returns the results as a three tuple: - Security level from CSV scan @@ -58,10 +58,10 @@ class SARTransformer(BaseEstimator, TransformerMixin): - Keywords from Certification report """ - def st_keywords_may_have_sars(sample: CommonCriteriaCert): + def st_keywords_may_have_sars(sample: CCCertificate): return sample.pdf_data.st_keywords and SAR_DICT_KEY in sample.pdf_data.st_keywords - def report_keywords_may_have_sars(sample: CommonCriteriaCert): + def report_keywords_may_have_sars(sample: CCCertificate): return sample.pdf_data.report_keywords and SAR_DICT_KEY in sample.pdf_data.report_keywords sec_level_sars = SARTransformer._parse_sars_from_security_level_list(cert.security_level) diff --git a/src/sec_certs/sample/__init__.py b/src/sec_certs/sample/__init__.py index e86c415e..f5f2130c 100644 --- a/src/sec_certs/sample/__init__.py +++ b/src/sec_certs/sample/__init__.py @@ -2,7 +2,7 @@ like CPE, CVE, etc. The objects mostly hold data and allow for serialization, but can also perform some basic transformations. """ -from sec_certs.sample.cc import CommonCriteriaCert +from sec_certs.sample.cc import CCCertificate from sec_certs.sample.cc_certificate_id import CertificateId from sec_certs.sample.cc_maintenance_update import CommonCriteriaMaintenanceUpdate from sec_certs.sample.cpe import CPE, cached_cpe @@ -17,7 +17,7 @@ from sec_certs.sample.sar import SAR __all__ = [ "CertificateId", "CommonCriteriaMaintenanceUpdate", - "CommonCriteriaCert", + "CCCertificate", "CPE", "cached_cpe", "CVE", diff --git a/src/sec_certs/sample/cc.py b/src/sec_certs/sample/cc.py index acd54178..603c29f2 100644 --- a/src/sec_certs/sample/cc.py +++ b/src/sec_certs/sample/cc.py @@ -45,8 +45,8 @@ class ReferenceType(Enum): INDIRECT = "indirect" -class CommonCriteriaCert( - Certificate["CommonCriteriaCert", "CommonCriteriaCert.Heuristics", "CommonCriteriaCert.PdfData"], +class CCCertificate( + Certificate["CCCertificate", "CCCertificate.Heuristics", "CCCertificate.PdfData"], PandasSerializableType, ComplexSerializableType, ): @@ -84,7 +84,7 @@ class CommonCriteriaCert( super().__setattr__("maintenance_date", sec_certs.utils.sanitization.sanitize_date(self.maintenance_date)) @classmethod - def from_dict(cls, dct: dict) -> CommonCriteriaCert.MaintenanceReport: + def from_dict(cls, dct: dict) -> CCCertificate.MaintenanceReport: new_dct = dct.copy() new_dct["maintenance_date"] = ( date.fromisoformat(dct["maintenance_date"]) @@ -384,7 +384,7 @@ class CommonCriteriaCert( @dataclass class Heuristics(BaseHeuristics, ComplexSerializableType): """ - Class for various heuristics related to CommonCriteriaCert + Class for various heuristics related to CCCertificate """ extracted_versions: set[str] | None = field(default=None) @@ -474,7 +474,7 @@ class CommonCriteriaCert( self.maintenance_updates = maintenance_updates self.state = self.InternalState() if not state else state self.pdf_data = self.PdfData() if not pdf_data else pdf_data - self.heuristics: CommonCriteriaCert.Heuristics = self.Heuristics() if not heuristics else heuristics + self.heuristics: CCCertificate.Heuristics = self.Heuristics() if not heuristics else heuristics @property def dgst(self) -> str: @@ -560,7 +560,7 @@ class CommonCriteriaCert( printed_manufacturer = self.manufacturer if self.manufacturer else "Unknown manufacturer" return str(printed_manufacturer) + " " + str(self.name) + " dgst: " + self.dgst - def merge(self, other: CommonCriteriaCert, other_source: str | None = None) -> None: + def merge(self, other: CCCertificate, other_source: str | None = None) -> None: """ Merges with other CC sample. Assuming they come from different sources, e.g., csv and html. Assuming that html source has better protection profiles, they overwrite CSV info @@ -587,9 +587,9 @@ class CommonCriteriaCert( ) @classmethod - def from_dict(cls, dct: dict) -> CommonCriteriaCert: + def from_dict(cls, dct: dict) -> CCCertificate: """ - Deserializes dictionary into `CommonCriteriaCert` + Deserializes dictionary into `CCCertificate` """ new_dct = dct.copy() new_dct["maintenance_updates"] = set(dct["maintenance_updates"]) @@ -604,7 +604,7 @@ class CommonCriteriaCert( if isinstance(dct["not_valid_after"], str) else dct["not_valid_after"] ) - return super(cls, CommonCriteriaCert).from_dict(new_dct) + return super(cls, CCCertificate).from_dict(new_dct) @staticmethod def _html_row_get_name(cell: Tag) -> str: @@ -639,7 +639,7 @@ class CommonCriteriaCert( if link.get("href") is not None and "/ppfiles/" in link.get("href"): protection_profiles.add( ProtectionProfile( - pp_name=str(link.contents[0]), pp_eal=None, pp_link=CommonCriteriaCert.cc_url + link.get("href") + pp_name=str(link.contents[0]), pp_eal=None, pp_link=CCCertificate.cc_url + link.get("href") ) ) return protection_profiles @@ -656,15 +656,15 @@ class CommonCriteriaCert( assert links[1].get("title").startswith("Certification Report") assert links[2].get("title").startswith("Security Target") - report_link = CommonCriteriaCert.cc_url + links[1].get("href") - security_target_link = CommonCriteriaCert.cc_url + links[2].get("href") + report_link = CCCertificate.cc_url + links[1].get("href") + security_target_link = CCCertificate.cc_url + links[2].get("href") return report_link, security_target_link @staticmethod def _html_row_get_cert_link(cell: Tag) -> str | None: links = cell.find_all("a") - return CommonCriteriaCert.cc_url + links[0].get("href") if links else None + return CCCertificate.cc_url + links[0].get("href") if links else None @staticmethod def _html_row_get_maintenance_div(cell: Tag) -> Tag | None: @@ -675,7 +675,7 @@ class CommonCriteriaCert( return None @staticmethod - def _html_row_get_maintenance_updates(main_div: Tag) -> set[CommonCriteriaCert.MaintenanceReport]: + def _html_row_get_maintenance_updates(main_div: Tag) -> set[CCCertificate.MaintenanceReport]: possible_updates = list(main_div.find_all("li")) maintenance_updates = set() for u in possible_updates: @@ -687,18 +687,18 @@ class CommonCriteriaCert( links = u.find_all("a") for link in links: if link.get("title").startswith("Maintenance Report:"): - main_report_link = CommonCriteriaCert.cc_url + link.get("href") + main_report_link = CCCertificate.cc_url + link.get("href") elif link.get("title").startswith("Maintenance ST"): - main_st_link = CommonCriteriaCert.cc_url + link.get("href") + main_st_link = CCCertificate.cc_url + link.get("href") else: logger.error("Unknown link in Maintenance part!") maintenance_updates.add( - CommonCriteriaCert.MaintenanceReport(main_date, main_title, main_report_link, main_st_link) + CCCertificate.MaintenanceReport(main_date, main_title, main_report_link, main_st_link) ) return maintenance_updates @classmethod - def from_html_row(cls, row: Tag, status: str, category: str) -> CommonCriteriaCert: + def from_html_row(cls, row: Tag, status: str, category: str) -> CCCertificate: """ Creates a CC sample from html row of commoncriteria.org webpage. """ @@ -707,20 +707,18 @@ class CommonCriteriaCert( if len(cells) != 7: raise ValueError(f"Unexpected number of <td> elements in CC html row. Expected: 7, actual: {len(cells)}") - name = CommonCriteriaCert._html_row_get_name(cells[0]) - manufacturer = CommonCriteriaCert._html_row_get_manufacturer(cells[1]) - manufacturer_web = CommonCriteriaCert._html_row_get_manufacturer_web(cells[1]) - scheme = CommonCriteriaCert._html_row_get_scheme(cells[6]) - security_level = CommonCriteriaCert._html_row_get_security_level(cells[5]) - protection_profiles = CommonCriteriaCert._html_row_get_protection_profiles(cells[0]) - not_valid_before = CommonCriteriaCert._html_row_get_date(cells[3]) - not_valid_after = CommonCriteriaCert._html_row_get_date(cells[4]) - report_link, st_link = CommonCriteriaCert._html_row_get_report_st_links(cells[0]) - cert_link = CommonCriteriaCert._html_row_get_cert_link(cells[2]) - maintenance_div = CommonCriteriaCert._html_row_get_maintenance_div(cells[0]) - maintenances = ( - CommonCriteriaCert._html_row_get_maintenance_updates(maintenance_div) if maintenance_div else set() - ) + name = CCCertificate._html_row_get_name(cells[0]) + manufacturer = CCCertificate._html_row_get_manufacturer(cells[1]) + manufacturer_web = CCCertificate._html_row_get_manufacturer_web(cells[1]) + scheme = CCCertificate._html_row_get_scheme(cells[6]) + security_level = CCCertificate._html_row_get_security_level(cells[5]) + protection_profiles = CCCertificate._html_row_get_protection_profiles(cells[0]) + not_valid_before = CCCertificate._html_row_get_date(cells[3]) + not_valid_after = CCCertificate._html_row_get_date(cells[4]) + report_link, st_link = CCCertificate._html_row_get_report_st_links(cells[0]) + cert_link = CCCertificate._html_row_get_cert_link(cells[2]) + maintenance_div = CCCertificate._html_row_get_maintenance_div(cells[0]) + maintenances = CCCertificate._html_row_get_maintenance_updates(maintenance_div) if maintenance_div else set() return cls( status, @@ -767,12 +765,12 @@ class CommonCriteriaCert( self.state.st_txt_path = Path(st_txt_dir) / (self.dgst + ".txt") @staticmethod - def download_pdf_report(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def download_pdf_report(cert: CCCertificate) -> CCCertificate: """ Downloads pdf of certification report given the certificate. Staticmethod to allow for parallelization. - :param CommonCriteriaCert cert: cert to download the pdf report for - :return CommonCriteriaCert: returns the modified certificate with updated state + :param CCCertificate cert: cert to download the pdf report for + :return CCCertificate: returns the modified certificate with updated state """ exit_code: str | int if not cert.report_link: @@ -790,12 +788,12 @@ class CommonCriteriaCert( return cert @staticmethod - def download_pdf_st(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def download_pdf_st(cert: CCCertificate) -> CCCertificate: """ Downloads pdf of security target given the certificate. Staticmethod to allow for parallelization. - :param CommonCriteriaCert cert: cert to download the pdf security target for - :return CommonCriteriaCert: returns the modified certificate with updated state + :param CCCertificate cert: cert to download the pdf security target for + :return CCCertificate: returns the modified certificate with updated state """ exit_code: str | int if not cert.st_link: @@ -813,12 +811,12 @@ class CommonCriteriaCert( return cert @staticmethod - def convert_report_pdf(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def convert_report_pdf(cert: CCCertificate) -> CCCertificate: """ Converts the pdf certification report to txt, given the certificate. Staticmethod to allow for parallelization. - :param CommonCriteriaCert cert: cert to download the pdf report for - :return CommonCriteriaCert: the modified certificate with updated state + :param CCCertificate cert: cert to download the pdf report for + :return CCCertificate: the modified certificate with updated state """ ocr_done, ok_result = sec_certs.utils.pdf.convert_pdf_file( cert.state.report_pdf_path, cert.state.report_txt_path @@ -835,12 +833,12 @@ class CommonCriteriaCert( return cert @staticmethod - def convert_st_pdf(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def convert_st_pdf(cert: CCCertificate) -> CCCertificate: """ Converts the pdf security target to txt, given the certificate. Staticmethod to allow for parallelization. - :param CommonCriteriaCert cert: cert to download the pdf security target for - :return CommonCriteriaCert: the modified certificate with updated state + :param CCCertificate cert: cert to download the pdf security target for + :return CCCertificate: the modified certificate with updated state """ ocr_done, ok_result = sec_certs.utils.pdf.convert_pdf_file(cert.state.st_pdf_path, cert.state.st_txt_path) # If OCR was done the result was garbage @@ -855,12 +853,12 @@ class CommonCriteriaCert( return cert @staticmethod - def extract_st_pdf_metadata(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def extract_st_pdf_metadata(cert: CCCertificate) -> CCCertificate: """ Extracts metadata from security target pdf given the certificate. Staticmethod to allow for parallelization. - :param CommonCriteriaCert cert: cert to extract the metadata for. - :return CommonCriteriaCert: the modified certificate with updated state + :param CCCertificate cert: cert to extract the metadata for. + :return CCCertificate: the modified certificate with updated state """ response, cert.pdf_data.st_metadata = sec_certs.utils.pdf.extract_pdf_metadata(cert.state.st_pdf_path) if response != constants.RETURNCODE_OK: @@ -870,12 +868,12 @@ class CommonCriteriaCert( return cert @staticmethod - def extract_report_pdf_metadata(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def extract_report_pdf_metadata(cert: CCCertificate) -> CCCertificate: """ Extracts metadata from certification report pdf given the certificate. Staticmethod to allow for parallelization. - :param CommonCriteriaCert cert: cert to extract the metadata for. - :return CommonCriteriaCert: the modified certificate with updated state + :param CCCertificate cert: cert to extract the metadata for. + :return CCCertificate: the modified certificate with updated state """ response, cert.pdf_data.report_metadata = sec_certs.utils.pdf.extract_pdf_metadata(cert.state.report_pdf_path) if response != constants.RETURNCODE_OK: @@ -885,12 +883,12 @@ class CommonCriteriaCert( return cert @staticmethod - def extract_st_pdf_frontpage(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def extract_st_pdf_frontpage(cert: CCCertificate) -> CCCertificate: """ Extracts data from security target pdf frontpage given the certificate. Staticmethod to allow for parallelization. - :param CommonCriteriaCert cert: cert to extract the frontpage data for. - :return CommonCriteriaCert: the modified certificate with updated state + :param CCCertificate cert: cert to extract the frontpage data for. + :return CCCertificate: the modified certificate with updated state """ cert.pdf_data.st_frontpage = {} @@ -902,12 +900,12 @@ class CommonCriteriaCert( return cert @staticmethod - def extract_report_pdf_frontpage(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def extract_report_pdf_frontpage(cert: CCCertificate) -> CCCertificate: """ Extracts data from certification report pdf frontpage given the certificate. Staticmethod to allow for parallelization. - :param CommonCriteriaCert cert: cert to extract the frontpage data for. - :return CommonCriteriaCert: the modified certificate with updated state + :param CCCertificate cert: cert to extract the frontpage data for. + :return CCCertificate: the modified certificate with updated state """ cert.pdf_data.report_frontpage = {} @@ -919,13 +917,13 @@ class CommonCriteriaCert( return cert @staticmethod - def extract_report_pdf_keywords(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def extract_report_pdf_keywords(cert: CCCertificate) -> CCCertificate: """ Matches regular expresions in txt obtained from certification report and extracts the matches into attribute. Static method to allow for parallelization - :param CommonCriteriaCert cert: certificate to extract the keywords for. - :return CommonCriteriaCert: the modified certificate with extracted keywords. + :param CCCertificate cert: certificate to extract the keywords for. + :return CCCertificate: the modified certificate with extracted keywords. """ report_keywords = sec_certs.utils.extract.extract_keywords(cert.state.report_txt_path, cc_rules) if report_keywords is None: @@ -935,13 +933,13 @@ class CommonCriteriaCert( return cert @staticmethod - def extract_st_pdf_keywords(cert: CommonCriteriaCert) -> CommonCriteriaCert: + def extract_st_pdf_keywords(cert: CCCertificate) -> CCCertificate: """ Matches regular expresions in txt obtained from security target and extracts the matches into attribute. Static method to allow for parallelization - :param CommonCriteriaCert cert: certificate to extract the keywords for. - :return CommonCriteriaCert: the modified certificate with extracted keywords. + :param CCCertificate cert: certificate to extract the keywords for. + :return CCCertificate: the modified certificate with extracted keywords. """ st_keywords = sec_certs.utils.extract.extract_keywords(cert.state.st_txt_path, cc_rules) if st_keywords is None: diff --git a/src/sec_certs/sample/cc_maintenance_update.py b/src/sec_certs/sample/cc_maintenance_update.py index 2cab2830..5399dde1 100644 --- a/src/sec_certs/sample/cc_maintenance_update.py +++ b/src/sec_certs/sample/cc_maintenance_update.py @@ -5,13 +5,13 @@ from datetime import date from typing import ClassVar import sec_certs.utils.helpers as helpers -from sec_certs.sample.cc import CommonCriteriaCert +from sec_certs.sample.cc import CCCertificate from sec_certs.serialization.json import ComplexSerializableType logger = logging.getLogger(__name__) -class CommonCriteriaMaintenanceUpdate(CommonCriteriaCert, ComplexSerializableType): +class CommonCriteriaMaintenanceUpdate(CCCertificate, ComplexSerializableType): pandas_columns: ClassVar[list[str]] = [ "dgst", "name", @@ -26,9 +26,9 @@ class CommonCriteriaMaintenanceUpdate(CommonCriteriaCert, ComplexSerializableTyp name: str, report_link: str, st_link: str, - state: CommonCriteriaCert.InternalState | None, - pdf_data: CommonCriteriaCert.PdfData | None, - heuristics: CommonCriteriaCert.Heuristics | None, + state: CCCertificate.InternalState | None, + pdf_data: CCCertificate.PdfData | None, + heuristics: CCCertificate.Heuristics | None, related_cert_digest: str, maintenance_date: date, ): @@ -74,7 +74,7 @@ class CommonCriteriaMaintenanceUpdate(CommonCriteriaCert, ComplexSerializableTyp return cls(*(tuple(dct.values()))) @classmethod - def get_updates_from_cc_cert(cls, cert: CommonCriteriaCert) -> list[CommonCriteriaMaintenanceUpdate]: + def get_updates_from_cc_cert(cls, cert: CCCertificate) -> list[CommonCriteriaMaintenanceUpdate]: if cert.maintenance_updates is None: raise RuntimeError("Dataset was probably not built correctly - this should not be happening.") diff --git a/tests/cc/test_cc_analysis.py b/tests/cc/test_cc_analysis.py index 08cd91e1..ff9fe3c0 100644 --- a/tests/cc/test_cc_analysis.py +++ b/tests/cc/test_cc_analysis.py @@ -10,7 +10,7 @@ from sec_certs.cert_rules import SARS_IMPLIED_FROM_EAL from sec_certs.dataset import CCDataset from sec_certs.dataset.cpe import CPEDataset from sec_certs.dataset.cve import CVEDataset -from sec_certs.sample.cc import CommonCriteriaCert +from sec_certs.sample.cc import CCCertificate from sec_certs.sample.cpe import CPE from sec_certs.sample.cve import CVE from sec_certs.sample.protection_profile import ProtectionProfile @@ -105,26 +105,26 @@ def transitive_vulnerability_dataset(data_dir) -> CCDataset: @pytest.fixture -def random_certificate(cc_dset: CCDataset) -> CommonCriteriaCert: +def random_certificate(cc_dset: CCDataset) -> CCCertificate: return cc_dset["ebd276cca70fd723"] -def test_match_cpe(cpe_single_sign_on: CPE, random_certificate: CommonCriteriaCert): +def test_match_cpe(cpe_single_sign_on: CPE, random_certificate: CCCertificate): assert {cpe_single_sign_on.uri} == random_certificate.heuristics.cpe_matches def test_find_related_cves( - cc_dset: CCDataset, cpe_single_sign_on: CPE, cves: set[CVE], random_certificate: CommonCriteriaCert + cc_dset: CCDataset, cpe_single_sign_on: CPE, cves: set[CVE], random_certificate: CCCertificate ): random_certificate.heuristics.cpe_matches = {cpe_single_sign_on.uri} cc_dset.compute_related_cves() assert {x.cve_id for x in cves} == random_certificate.heuristics.related_cves -def test_version_extraction(random_certificate: CommonCriteriaCert): +def test_version_extraction(random_certificate: CCCertificate): assert random_certificate.heuristics.extracted_versions == {"8.2"} - new_cert = CommonCriteriaCert( + new_cert = CCCertificate( "", "", "IDOneClassIC Card : ID-One Cosmo 64 RSA v5.4 and applet IDOneClassIC v1.0 embedded on P5CT072VOP", @@ -147,15 +147,15 @@ def test_version_extraction(random_certificate: CommonCriteriaCert): assert new_cert.heuristics.extracted_versions == {"5.4", "1.0"} -def test_cert_lab_heuristics(random_certificate: CommonCriteriaCert): +def test_cert_lab_heuristics(random_certificate: CCCertificate): assert random_certificate.heuristics.cert_lab == ["BSI"] -def test_cert_id_heuristics(random_certificate: CommonCriteriaCert): +def test_cert_id_heuristics(random_certificate: CCCertificate): assert random_certificate.heuristics.cert_id == "BSI-DSZ-CC-0683-2014" -def test_keywords_heuristics(random_certificate: CommonCriteriaCert): +def test_keywords_heuristics(random_certificate: CCCertificate): assert random_certificate.pdf_data.st_keywords extracted_keywords: dict = random_certificate.pdf_data.st_keywords @@ -174,7 +174,7 @@ def test_keywords_heuristics(random_certificate: CommonCriteriaCert): assert extracted_keywords["cipher_mode"]["CBC"]["CBC"] == 2 -def test_protection_profile_matching(cc_dset: CCDataset, random_certificate: CommonCriteriaCert): +def test_protection_profile_matching(cc_dset: CCDataset, random_certificate: CCCertificate): artificial_pp: ProtectionProfile = ProtectionProfile( "Korean National Protection Profile for Single Sign On V1.0", "EAL1+", @@ -194,7 +194,7 @@ def test_protection_profile_matching(cc_dset: CCDataset, random_certificate: Com assert random_certificate.protection_profiles == {expected_pp} -def test_single_record_references_heuristics(random_certificate: CommonCriteriaCert): +def test_single_record_references_heuristics(random_certificate: CCCertificate): # Single record in daset is not affecting nor affected by other records assert not random_certificate.heuristics.report_references.directly_referenced_by assert not random_certificate.heuristics.report_references.indirectly_referenced_by @@ -242,7 +242,7 @@ def test_sar_object(): SAR.from_string("XALC_FLR") -def test_sar_transformation(random_certificate: CommonCriteriaCert): +def test_sar_transformation(random_certificate: CCCertificate): assert random_certificate.heuristics.extracted_sars # This one should be taken from security level and not overwritten by stronger SARs in ST @@ -254,7 +254,7 @@ def test_sar_transformation(random_certificate: CommonCriteriaCert): assert SAR("ADV_FSP", 6) not in random_certificate.heuristics.extracted_sars -def test_eal_implied_sar_inference(random_certificate: CommonCriteriaCert): +def test_eal_implied_sar_inference(random_certificate: CCCertificate): assert random_certificate.actual_sars actual_sars = random_certificate.actual_sars diff --git a/tests/cc/test_cc_certificate.py b/tests/cc/test_cc_certificate.py index e11e5f43..2234ee11 100644 --- a/tests/cc/test_cc_certificate.py +++ b/tests/cc/test_cc_certificate.py @@ -8,7 +8,7 @@ import pytest import tests.data.cc.analysis import tests.data.cc.certificate from sec_certs.dataset import CCDataset -from sec_certs.sample import CommonCriteriaCert +from sec_certs.sample import CCCertificate from sec_certs.sample.protection_profile import ProtectionProfile @@ -18,7 +18,7 @@ def data_dir() -> Path: @pytest.fixture(scope="module") -def vulnerable_certificate(tmp_path_factory) -> CommonCriteriaCert: +def vulnerable_certificate(tmp_path_factory) -> CCCertificate: tmp_dir = tmp_path_factory.mktemp("dset") dset_json_path = Path(tests.data.cc.analysis.__path__[0]) / "vulnerable_dataset.json" data_dir_path = dset_json_path.parent @@ -31,8 +31,8 @@ def vulnerable_certificate(tmp_path_factory) -> CommonCriteriaCert: @pytest.fixture(scope="module") -def cert_one() -> CommonCriteriaCert: - return CommonCriteriaCert( +def cert_one() -> CCCertificate: + return CCCertificate( "active", "Access Control Devices and Systems", "NetIQ Identity Manager 4.7", @@ -54,13 +54,13 @@ def cert_one() -> CommonCriteriaCert: @pytest.fixture(scope="module") -def cert_two() -> CommonCriteriaCert: +def cert_two() -> CCCertificate: pp = ProtectionProfile("sample_pp", None, pp_link="https://sample.pp") - update = CommonCriteriaCert.MaintenanceReport( + update = CCCertificate.MaintenanceReport( date(1900, 1, 1), "Sample maintenance", "https://maintenance.up", "https://maintenance.up" ) - return CommonCriteriaCert( + return CCCertificate( "archived", "Sample category", "Sample certificate name", @@ -81,44 +81,44 @@ def cert_two() -> CommonCriteriaCert: ) -def test_extract_metadata(vulnerable_certificate: CommonCriteriaCert): +def test_extract_metadata(vulnerable_certificate: CCCertificate): vulnerable_certificate.state.st_extract_ok = True - CommonCriteriaCert.extract_st_pdf_metadata(vulnerable_certificate) + CCCertificate.extract_st_pdf_metadata(vulnerable_certificate) assert vulnerable_certificate.state.st_extract_ok vulnerable_certificate.state.report_extract_ok = True - CommonCriteriaCert.extract_report_pdf_metadata(vulnerable_certificate) + CCCertificate.extract_report_pdf_metadata(vulnerable_certificate) assert vulnerable_certificate.state.report_extract_ok -def test_extract_frontpage(vulnerable_certificate: CommonCriteriaCert): +def test_extract_frontpage(vulnerable_certificate: CCCertificate): vulnerable_certificate.state.st_extract_ok = True - CommonCriteriaCert.extract_st_pdf_frontpage(vulnerable_certificate) + CCCertificate.extract_st_pdf_frontpage(vulnerable_certificate) assert vulnerable_certificate.state.st_extract_ok vulnerable_certificate.state.report_extract_ok = True - CommonCriteriaCert.extract_report_pdf_frontpage(vulnerable_certificate) + CCCertificate.extract_report_pdf_frontpage(vulnerable_certificate) assert vulnerable_certificate.state.report_extract_ok -def test_keyword_extraction(vulnerable_certificate: CommonCriteriaCert): +def test_keyword_extraction(vulnerable_certificate: CCCertificate): vulnerable_certificate.state.st_extract_ok = True - CommonCriteriaCert.extract_st_pdf_keywords(vulnerable_certificate) + CCCertificate.extract_st_pdf_keywords(vulnerable_certificate) assert vulnerable_certificate.state.st_extract_ok vulnerable_certificate.state.report_extract_ok = True - CommonCriteriaCert.extract_report_pdf_keywords(vulnerable_certificate) + CCCertificate.extract_report_pdf_keywords(vulnerable_certificate) assert vulnerable_certificate.state.report_extract_ok -def test_cert_link_escaping(cert_one: CommonCriteriaCert): +def test_cert_link_escaping(cert_one: CCCertificate): assert ( cert_one.report_link == "https://www.commoncriteriaportal.org/files/epfiles/Certification%20Report%20-%20NetIQ®%20Identity%20Manager%204.7.pdf" ) -def test_cert_to_json(cert_two: CommonCriteriaCert, tmp_path: Path, data_dir: Path): +def test_cert_to_json(cert_two: CCCertificate, tmp_path: Path, data_dir: Path): cert_two.to_json(tmp_path / "crt_two.json") with (tmp_path / "crt_two.json").open("r") as handle: @@ -130,6 +130,6 @@ def test_cert_to_json(cert_two: CommonCriteriaCert, tmp_path: Path, data_dir: Pa assert data == template_data -def test_cert_from_json(cert_two: CommonCriteriaCert, data_dir: Path): - crt = CommonCriteriaCert.from_json(data_dir / "fictional_cert.json") +def test_cert_from_json(cert_two: CCCertificate, data_dir: Path): + crt = CCCertificate.from_json(data_dir / "fictional_cert.json") assert cert_two == crt diff --git a/tests/cc/test_cc_dataset.py b/tests/cc/test_cc_dataset.py index 0355143b..5d0b8fc5 100644 --- a/tests/cc/test_cc_dataset.py +++ b/tests/cc/test_cc_dataset.py @@ -9,7 +9,7 @@ import pytest import tests.data.cc.dataset from sec_certs import constants from sec_certs.dataset import CCDataset -from sec_certs.sample.cc import CommonCriteriaCert +from sec_certs.sample.cc import CCCertificate @pytest.fixture(scope="module") @@ -18,8 +18,8 @@ def data_dir() -> Path: @pytest.fixture(scope="module") -def crt() -> CommonCriteriaCert: - return CommonCriteriaCert( +def crt() -> CCCertificate: + return CCCertificate( "active", "Access Control Devices and Systems", "NetIQ Identity Manager 4.7", @@ -128,7 +128,7 @@ def test_build_empty_dataset(): assert not dset.state.certs_analyzed -def test_build_dataset(data_dir: Path, crt: CommonCriteriaCert, toy_dataset: CCDataset): +def test_build_dataset(data_dir: Path, crt: CCCertificate, toy_dataset: CCDataset): with TemporaryDirectory() as tmp_dir: dataset_path = Path(tmp_dir) (dataset_path / "web").mkdir() @@ -170,6 +170,6 @@ def test_download_csv_html_files(): def test_to_pandas(toy_dataset: CCDataset): df = toy_dataset.to_pandas() - assert df.shape == (len(toy_dataset), len(CommonCriteriaCert.pandas_columns)) + assert df.shape == (len(toy_dataset), len(CCCertificate.pandas_columns)) assert df.index.name == "dgst" - assert set(df.columns) == (set(CommonCriteriaCert.pandas_columns).union({"year_from"})) - {"dgst"} + assert set(df.columns) == (set(CCCertificate.pandas_columns).union({"year_from"})) - {"dgst"} diff --git a/tests/data/cc/analysis/cc_full_dataset.json b/tests/data/cc/analysis/cc_full_dataset.json index a7b3c834..d12a9456 100644 --- a/tests/data/cc/analysis/cc_full_dataset.json +++ b/tests/data/cc/analysis/cc_full_dataset.json @@ -15,7 +15,7 @@ "n_certs": 1, "certs": [ { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "ebd276cca70fd723", "status": "active", "category": "Access Control Devices and Systems", @@ -54,7 +54,7 @@ "elements": [] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": true, "report_download_ok": true, "st_convert_garbage": false, @@ -69,7 +69,7 @@ "report_txt_hash": "35627594d3806ac3926ec47f466503fe27781533da12beb6f8705882fccf125e" }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": { "pdf_file_size_bytes": 1174271, "pdf_is_encrypted": false, @@ -512,7 +512,7 @@ "st_filename": "0683b_pdf.pdf" }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": { "_type": "Set", "elements": [ diff --git a/tests/data/cc/analysis/reference_dataset.json b/tests/data/cc/analysis/reference_dataset.json index d05826a3..57ae81f1 100644 --- a/tests/data/cc/analysis/reference_dataset.json +++ b/tests/data/cc/analysis/reference_dataset.json @@ -14,7 +14,7 @@ "n_certs": 3, "certs": [ { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "c30de3192d2e8ec2", "status": "archived", "category": "Other Devices and Systems", @@ -43,7 +43,7 @@ "elements": [] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": true, "report_download_ok": true, "st_convert_ok": true, @@ -56,7 +56,7 @@ "report_txt_hash": "460e8010dbc8f5de5b87bf96fd45c71cfd9f3869f34ca6ac1ab02cbd70d2523f" }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": { "pdf_file_size_bytes": 393439, "pdf_is_encrypted": false, @@ -468,7 +468,7 @@ } }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": { "_type": "Set", "elements": [ @@ -573,7 +573,7 @@ } }, { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "53fe111411edfa45", "status": "archived", "category": "Other Devices and Systems", @@ -602,7 +602,7 @@ "elements": [] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": true, "report_download_ok": true, "st_convert_ok": true, @@ -615,7 +615,7 @@ "report_txt_hash": "0535df1c56fb4f87153cbffee51ba4d77fac47a6f17f024aa7d9df461028bc65" }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": { "pdf_file_size_bytes": 296713, "pdf_is_encrypted": false, @@ -1056,7 +1056,7 @@ } }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": { "_type": "Set", "elements": [ @@ -1210,7 +1210,7 @@ } }, { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "692e91451741ef49", "status": "archived", "category": "Other Devices and Systems", @@ -1239,7 +1239,7 @@ "elements": [] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": true, "report_download_ok": true, "st_convert_ok": true, @@ -1252,7 +1252,7 @@ "report_txt_hash": "11e1262fd8f5df1b140f5e8813883b71447503781399427b35adbbecd00b4d63" }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": { "pdf_file_size_bytes": 628533, "pdf_is_encrypted": false, @@ -1687,7 +1687,7 @@ } }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": { "_type": "Set", "elements": [ diff --git a/tests/data/cc/analysis/transitive_vulnerability_dataset.json b/tests/data/cc/analysis/transitive_vulnerability_dataset.json index bd20bf90..da2348bf 100644 --- a/tests/data/cc/analysis/transitive_vulnerability_dataset.json +++ b/tests/data/cc/analysis/transitive_vulnerability_dataset.json @@ -14,7 +14,7 @@ "n_certs": 3, "certs": [ { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "d0705c9e6fbaeba3", "status": "active", "category": "Operating Systems", @@ -53,7 +53,7 @@ "elements": [] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": true, "report_download_ok": true, "st_convert_ok": true, @@ -66,7 +66,7 @@ "report_txt_hash": "9d360141a98e764b15855f519b456c4e4639f993c4f8b5ab67e9c8ae7fbfc9e4" }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": { "pdf_file_size_bytes": 1235750, "pdf_is_encrypted": false, @@ -1061,7 +1061,7 @@ } }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": { "_type": "Set", "elements": [ @@ -1329,7 +1329,7 @@ } }, { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "011796336c7b94de", "status": "archived", "category": "Operating Systems", @@ -1358,7 +1358,7 @@ "elements": [] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": true, "report_download_ok": true, "st_convert_ok": true, @@ -1371,7 +1371,7 @@ "report_txt_hash": "dd120ba7667c2385839c96ee70c56f2a4d464fc95e3ea2818d31b3347d06fd4f" }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": { "pdf_file_size_bytes": 1178202, "pdf_is_encrypted": false, @@ -2014,7 +2014,7 @@ } }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": { "_type": "Set", "elements": [ @@ -2269,7 +2269,7 @@ } }, { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "ebc77980250ee68f", "status": "active", "category": "Operating Systems", @@ -2308,7 +2308,7 @@ "elements": [] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": true, "report_download_ok": true, "st_convert_ok": true, @@ -2321,7 +2321,7 @@ "report_txt_hash": "0a7c65e3d11f082c8f75aba7de0079c0b1aa5e67bb28d4635cbcaa4cd200d1c2" }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": { "pdf_file_size_bytes": 1932018, "pdf_is_encrypted": false, @@ -3380,7 +3380,7 @@ } }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": { "_type": "Set", "elements": [ diff --git a/tests/data/cc/analysis/vulnerable_dataset.json b/tests/data/cc/analysis/vulnerable_dataset.json index 5fe3dee6..d433fac1 100644 --- a/tests/data/cc/analysis/vulnerable_dataset.json +++ b/tests/data/cc/analysis/vulnerable_dataset.json @@ -15,7 +15,7 @@ "n_certs": 1, "certs": [ { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "ebd276cca70fd723", "status": "active", "category": "Access Control Devices and Systems", @@ -38,7 +38,7 @@ "protection_profiles": [], "maintenance_updates": [], "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": true, "report_download_ok": true, "st_convert_ok": true, @@ -47,7 +47,7 @@ "report_extract_ok": true }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": null, "st_metadata": null, "report_frontpage": null, @@ -58,7 +58,7 @@ "st_filename": null }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": [ "8.2" ], diff --git a/tests/data/cc/certificate/fictional_cert.json b/tests/data/cc/certificate/fictional_cert.json index 32e78b32..5d5a0499 100644 --- a/tests/data/cc/certificate/fictional_cert.json +++ b/tests/data/cc/certificate/fictional_cert.json @@ -1,5 +1,5 @@ { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "a9ccb81a92e547dc", "status": "archived", "category": "Sample category", @@ -31,7 +31,7 @@ "_type": "Set", "elements": [ { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.MaintenanceReport", + "_type": "sec_certs.sample.cc.CCCertificate.MaintenanceReport", "maintenance_date": "1900-01-01", "maintenance_title": "Sample maintenance", "maintenance_report_link": "https://maintenance.up", @@ -40,7 +40,7 @@ ] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": false, "report_download_ok": false, "st_convert_garbage": false, @@ -55,7 +55,7 @@ "report_txt_hash": null }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": null, "st_metadata": null, "report_frontpage": null, @@ -66,7 +66,7 @@ "st_filename": null }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": null, "cpe_matches": null, "verified_cpe_matches": null, diff --git a/tests/data/cc/dataset/auxillary_datasets/maintenances/maintenance_updates.json b/tests/data/cc/dataset/auxillary_datasets/maintenances/maintenance_updates.json index ed72b631..09e52395 100644 --- a/tests/data/cc/dataset/auxillary_datasets/maintenances/maintenance_updates.json +++ b/tests/data/cc/dataset/auxillary_datasets/maintenances/maintenance_updates.json @@ -21,7 +21,7 @@ "report_link": "https://www.commoncriteriaportal.org/files/epfiles/383-7-159%20MR%20v1.0e.pdf", "st_link": "https://www.commoncriteriaportal.org/files/epfiles/383-7-159%20ST%20v1.4%20CCRA.pdf", "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": true, "report_download_ok": true, "st_convert_garbage": false, @@ -36,7 +36,7 @@ "report_txt_hash": null }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": null, "st_metadata": null, "report_frontpage": null, @@ -47,7 +47,7 @@ "st_filename": "383-7-159 ST v1.4 CCRA.pdf" }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": null, "cpe_matches": null, "verified_cpe_matches": null, diff --git a/tests/data/cc/dataset/toy_dataset.json b/tests/data/cc/dataset/toy_dataset.json index 42531e2c..bd674311 100644 --- a/tests/data/cc/dataset/toy_dataset.json +++ b/tests/data/cc/dataset/toy_dataset.json @@ -15,7 +15,7 @@ "n_certs": 3, "certs": [ { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "309ac2fd7f2dcf17", "status": "active", "category": "Access Control Devices and Systems", @@ -44,7 +44,7 @@ "elements": [] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": false, "report_download_ok": false, "st_convert_garbage": false, @@ -59,7 +59,7 @@ "report_txt_hash": null }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": null, "st_metadata": null, "report_frontpage": null, @@ -70,7 +70,7 @@ "st_filename": null }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": null, "cpe_matches": null, "verified_cpe_matches": null, @@ -97,7 +97,7 @@ } }, { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "8cf86948f02f047d", "status": "active", "category": "Access Control Devices and Systems", @@ -131,7 +131,7 @@ "elements": [] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": false, "report_download_ok": false, "st_convert_garbage": false, @@ -146,7 +146,7 @@ "report_txt_hash": null }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": null, "st_metadata": null, "report_frontpage": null, @@ -157,7 +157,7 @@ "st_filename": null }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": null, "cpe_matches": null, "verified_cpe_matches": null, @@ -184,7 +184,7 @@ } }, { - "_type": "sec_certs.sample.cc.CommonCriteriaCert", + "_type": "sec_certs.sample.cc.CCCertificate", "dgst": "8a5e6bcda602920c", "status": "active", "category": "Boundary Protection Devices and Systems", @@ -217,7 +217,7 @@ "_type": "Set", "elements": [ { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.MaintenanceReport", + "_type": "sec_certs.sample.cc.CCCertificate.MaintenanceReport", "maintenance_date": "2019-08-26", "maintenance_title": "Fortinet FortiGate w/ FortiOS v5.6.7 Build 6022", "maintenance_report_link": "https://www.commoncriteriaportal.org/files/epfiles/383-7-159%20MR%20v1.0e.pdf", @@ -226,7 +226,7 @@ ] }, "state": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.InternalState", + "_type": "sec_certs.sample.cc.CCCertificate.InternalState", "st_download_ok": false, "report_download_ok": false, "st_convert_garbage": false, @@ -241,7 +241,7 @@ "report_txt_hash": null }, "pdf_data": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.PdfData", + "_type": "sec_certs.sample.cc.CCCertificate.PdfData", "report_metadata": null, "st_metadata": null, "report_frontpage": null, @@ -252,7 +252,7 @@ "st_filename": null }, "heuristics": { - "_type": "sec_certs.sample.cc.CommonCriteriaCert.Heuristics", + "_type": "sec_certs.sample.cc.CCCertificate.Heuristics", "extracted_versions": null, "cpe_matches": null, "verified_cpe_matches": null, |
