diff options
| author | J08nY | 2024-02-14 13:26:56 +0100 |
|---|---|---|
| committer | J08nY | 2024-02-14 13:26:56 +0100 |
| commit | 4592f97f15104968c1c49b9a04fe74f799b4039b (patch) | |
| tree | 757302733aa0628cc6506d18268ac3a0ceff7071 | |
| parent | d73ddbcdfcd0768c9e594f627947eac87f1d561b (diff) | |
| download | sec-certs-4592f97f15104968c1c49b9a04fe74f799b4039b.tar.gz sec-certs-4592f97f15104968c1c49b9a04fe74f799b4039b.tar.zst sec-certs-4592f97f15104968c1c49b9a04fe74f799b4039b.zip | |
Cleanup PdfData attributes.
| -rw-r--r-- | src/sec_certs/sample/cc.py | 103 | ||||
| -rw-r--r-- | src/sec_certs/utils/extract.py | 9 | ||||
| -rw-r--r-- | tests/data/cc/analysis/cc_full_dataset.json | 13 | ||||
| -rw-r--r-- | tests/data/cc/analysis/reference_dataset.json | 39 | ||||
| -rw-r--r-- | tests/data/cc/analysis/transitive_vulnerability_dataset.json | 39 |
5 files changed, 46 insertions, 157 deletions
diff --git a/src/sec_certs/sample/cc.py b/src/sec_certs/sample/cc.py index bb4b0c7c..28099f58 100644 --- a/src/sec_certs/sample/cc.py +++ b/src/sec_certs/sample/cc.py @@ -27,15 +27,7 @@ from sec_certs.sample.sar import SAR from sec_certs.serialization.json import ComplexSerializableType from sec_certs.serialization.pandas import PandasSerializableType from sec_certs.utils import helpers -from sec_certs.utils.extract import normalize_match_string - -HEADERS = { - "anssi": sec_certs.utils.extract.search_only_headers_anssi, - "bsi": sec_certs.utils.extract.search_only_headers_bsi, - "nscib": sec_certs.utils.extract.search_only_headers_nscib, - "niap": sec_certs.utils.extract.search_only_headers_niap, - "canada": sec_certs.utils.extract.search_only_headers_canada, -} +from sec_certs.utils.extract import normalize_match_string, scheme_frontpage_functions class CCCertificate( @@ -181,8 +173,12 @@ class CCCertificate( st_metadata: dict[str, Any] | None = field(default=None) cert_metadata: dict[str, Any] | None = field(default=None) report_frontpage: dict[str, dict[str, Any]] | None = field(default=None) - st_frontpage: dict[str, dict[str, Any]] | None = field(default=None) - cert_frontpage: dict[str, dict[str, Any]] | None = field(default=None) + st_frontpage: dict[str, dict[str, Any]] | None = field( + default=None + ) # TODO: Unused, we have no frontpage matching for targets + cert_frontpage: dict[str, dict[str, Any]] | None = field( + default=None + ) # TODO: Unused, we have no frontpage matching for certs report_keywords: dict[str, Any] | None = field(default=None) st_keywords: dict[str, Any] | None = field(default=None) cert_keywords: dict[str, Any] | None = field(default=None) @@ -194,86 +190,33 @@ class CCCertificate( return any(x is not None for x in vars(self)) @property - def bsi_data(self) -> dict[str, Any] | None: - """ - Returns frontpage data related to BSI-provided information - """ - return self.report_frontpage.get("bsi", None) if self.report_frontpage else None - - @property - def niap_data(self) -> dict[str, Any] | None: - """ - Returns frontpage data related to niap-provided information - """ - return self.report_frontpage.get("niap", None) if self.report_frontpage else None - - @property - def nscib_data(self) -> dict[str, Any] | None: - """ - Returns frontpage data related to nscib-provided information - """ - return self.report_frontpage.get("nscib", None) if self.report_frontpage else None - - @property - def canada_data(self) -> dict[str, Any] | None: - """ - Returns frontpage data related to canada-provided information - """ - return self.report_frontpage.get("canada", None) if self.report_frontpage else None - - @property - def anssi_data(self) -> dict[str, Any] | None: - """ - Returns frontpage data related to ANSSI-provided information - """ - return self.report_frontpage.get("anssi", None) if self.report_frontpage else None - - @property def cert_lab(self) -> list[str] | None: """ Returns labs for which certificate data was parsed. """ + if not self.report_frontpage: + return None labs = [ data["cert_lab"].split(" ")[0].upper() - for data in [self.bsi_data, self.anssi_data, self.niap_data, self.nscib_data, self.canada_data] + for scheme, data in self.report_frontpage.items() if data and "cert_lab" in data ] return labs if labs else None - @property - def bsi_cert_id(self) -> str | None: - return self.bsi_data.get("cert_id", None) if self.bsi_data else None - - @property - def niap_cert_id(self) -> str | None: - return self.niap_data.get("cert_id", None) if self.niap_data else None - - @property - def nscib_cert_id(self) -> str | None: - return self.nscib_data.get("cert_id", None) if self.nscib_data else None - - @property - def canada_cert_id(self) -> str | None: - return self.canada_data.get("cert_id", None) if self.canada_data else None - - @property - def anssi_cert_id(self) -> str | None: - return self.anssi_data.get("cert_id", None) if self.anssi_data else None - def frontpage_cert_id(self, scheme: str) -> dict[str, float]: """ Get cert_id candidate from the frontpage of the report. """ - scheme_map = { - "DE": self.bsi_cert_id, - "US": self.niap_cert_id, - "NL": self.nscib_cert_id, - "CA": self.canada_cert_id, - "FR": self.anssi_cert_id, - } - if scheme in scheme_map and (candidate := scheme_map[scheme]): - return {candidate: 1.0} - return {} + if not self.report_frontpage: + return {} + data = self.report_frontpage.get(scheme) + if not data: + return {} + cert_id = data.get("cert_id") + if not cert_id: + return {} + else: + return {cert_id: 1.0} def filename_cert_id(self, scheme: str) -> dict[str, float]: """ @@ -982,9 +925,9 @@ class CCCertificate( """ cert.pdf_data.report_frontpage = {} - for header_type, associated_header_func in HEADERS.items(): - response, cert.pdf_data.report_frontpage[header_type] = associated_header_func(cert.state.report.txt_path) - + if cert.scheme in scheme_frontpage_functions: + header_func = scheme_frontpage_functions[cert.scheme] + response, cert.pdf_data.report_frontpage[cert.scheme] = header_func(cert.state.report.txt_path) if response != constants.RETURNCODE_OK: cert.state.report.extract_ok = False return cert diff --git a/src/sec_certs/utils/extract.py b/src/sec_certs/utils/extract.py index e6312b8d..669cbcfc 100644 --- a/src/sec_certs/utils/extract.py +++ b/src/sec_certs/utils/extract.py @@ -818,3 +818,12 @@ def get_sums_for_rules_subset(dct: dict | None, path: str) -> dict[str, float]: cc_rules_subset_to_search = rules_get_subset(path) paths_to_search = extract_key_paths(cc_rules_subset_to_search, path) return {x: get_sum_of_values_from_dict_path(dct, x, np.nan) for x in paths_to_search} + + +scheme_frontpage_functions = { + "FR": search_only_headers_anssi, + "DE": search_only_headers_bsi, + "NL": search_only_headers_nscib, + "US": search_only_headers_niap, + "CA": search_only_headers_canada, +} diff --git a/tests/data/cc/analysis/cc_full_dataset.json b/tests/data/cc/analysis/cc_full_dataset.json index 4baf4758..64ef38e4 100644 --- a/tests/data/cc/analysis/cc_full_dataset.json +++ b/tests/data/cc/analysis/cc_full_dataset.json @@ -130,8 +130,7 @@ } }, "report_frontpage": { - "anssi": {}, - "bsi": { + "DE": { "match_rules": [ "(BSI-DSZ-CC-.+?) (?:for|For) (.+?) from (.*)" ], @@ -142,17 +141,9 @@ "ref_protection_profiles": "None", "cc_version": "Product specific Security Target Common Criteria Part 2 conformant", "cc_security_level": "Common Criteria Part 3 conformant EAL 3 augmented by ALC_FLR.1 SOGIS Recognition Agreement" - }, - "nscib": {}, - "niap": {}, - "canada": {} + } }, "st_frontpage": { - "anssi": {}, - "bsi": {}, - "nscib": {}, - "niap": {}, - "canada": {} }, "report_keywords": { "cc_cert_id": { diff --git a/tests/data/cc/analysis/reference_dataset.json b/tests/data/cc/analysis/reference_dataset.json index b0ef6683..38fb7fd0 100644 --- a/tests/data/cc/analysis/reference_dataset.json +++ b/tests/data/cc/analysis/reference_dataset.json @@ -101,8 +101,7 @@ "/Title": "Security Target The Océ Digital Access Controller (DAC) R10.1.5, as used in the Océ VarioPrint 1055, 1055 BC, 1055 DP, 1065, 1075, 2062, 2075, 2075 DP printer/copier/scanner products" }, "report_frontpage": { - "anssi": {}, - "bsi": { + "DE": { "match_rules": [ "(BSI-DSZ-CC-.+?) (?:for|For) (.+?) from (.*)" ], @@ -110,17 +109,9 @@ "cert_item": "Océ Digital Access Controller (DAC) R10.1.5 for use in the Océ VarioPrint 1055, 1055 BC, 1055 DP, 1065, 1075, 2062, 2075, 2075 DP printer/copier/scanner products", "developer": "Océ Technologies B.V", "cert_lab": "BSI" - }, - "nscib": {}, - "niap": {}, - "canada": {} + } }, "st_frontpage": { - "anssi": {}, - "bsi": {}, - "nscib": {}, - "niap": {}, - "canada": {} }, "report_keywords": { "cc_cert_id": { @@ -678,8 +669,7 @@ "/Title": "Microsoft Word - Oce Venlo DAC Security Target 2.4.doc" }, "report_frontpage": { - "anssi": {}, - "bsi": { + "DE": { "match_rules": [ "(BSI-DSZ-CC-.+?) (?:for|For) (.+?) from (.*)" ], @@ -687,17 +677,9 @@ "cert_item": "Océ Digital Access Controller (DAC) R9.1.6", "developer": "Océ Technologies B.V", "cert_lab": "BSI" - }, - "nscib": {}, - "niap": {}, - "canada": {} + } }, "st_frontpage": { - "anssi": {}, - "bsi": {}, - "nscib": {}, - "niap": {}, - "canada": {} }, "report_keywords": { "cc_cert_id": { @@ -1333,8 +1315,7 @@ "/Title": "Microsoft Word - Oce Venlo DAC Security Target 1.9.doc" }, "report_frontpage": { - "anssi": {}, - "bsi": { + "DE": { "match_rules": [ "(BSI-DSZ-CC-.+?) (?:for|For) (.+?) from (.*)" ], @@ -1342,17 +1323,9 @@ "cert_item": "Océ Digital Access Controller (DAC) R 8.1.10", "developer": "Océ Technologies B.V", "cert_lab": "BSI" - }, - "nscib": {}, - "niap": {}, - "canada": {} + } }, "st_frontpage": { - "anssi": {}, - "bsi": {}, - "nscib": {}, - "niap": {}, - "canada": {} }, "report_keywords": { "cc_cert_id": { diff --git a/tests/data/cc/analysis/transitive_vulnerability_dataset.json b/tests/data/cc/analysis/transitive_vulnerability_dataset.json index 21391a12..abd4c7a3 100644 --- a/tests/data/cc/analysis/transitive_vulnerability_dataset.json +++ b/tests/data/cc/analysis/transitive_vulnerability_dataset.json @@ -108,8 +108,7 @@ "/CreationDate": "D:20140828154014+02'00'" }, "report_frontpage": { - "anssi": {}, - "bsi": { + "DE": { "match_rules": [ "(BSI-DSZ-CC-.+?) (?:for|For) (.+?) from (.*)" ], @@ -117,17 +116,9 @@ "cert_item": "IBM z/OS Version 2 Release 1", "developer": "IBM Corporation", "cert_lab": "BSI" - }, - "nscib": {}, - "niap": {}, - "canada": {} + } }, "st_frontpage": { - "anssi": {}, - "bsi": {}, - "nscib": {}, - "niap": {}, - "canada": {} }, "report_keywords": { "cc_cert_id": { @@ -1432,8 +1423,7 @@ "/CreationDate": "D:20150508083715+02'00'" }, "report_frontpage": { - "anssi": {}, - "bsi": { + "DE": { "match_rules": [ "(BSI-DSZ-CC-.+?) (?:for|For) (.+?) from (.*)" ], @@ -1441,17 +1431,9 @@ "cert_item": "RACF Element of z/OS Version 2, Release 1", "developer": "IBM Corporation", "cert_lab": "BSI" - }, - "nscib": {}, - "niap": {}, - "canada": {} + } }, "st_frontpage": { - "anssi": {}, - "bsi": {}, - "nscib": {}, - "niap": {}, - "canada": {} }, "report_keywords": { "cc_cert_id": { @@ -2399,8 +2381,7 @@ "/CreationDate": "D:20170503171742+02'00'" }, "report_frontpage": { - "anssi": {}, - "bsi": { + "DE": { "match_rules": [ "(BSI-DSZ-CC-.+?) (?:for|For) (.+?) from (.*)" ], @@ -2411,17 +2392,9 @@ "ref_protection_profiles": "Operating System Protection Profile, Version 2.0, 01 June 2010, BSI-CC-PP-0067-2010, OSPP Extended Packages: Extended Identification and Authentication and Labeled Security, both Version 2.0, 28 May 2010", "cc_version": "PP conformant Common Criteria Part 2 extended", "cc_security_level": "Common Criteria Part 3 conformant EAL 4 augmented by ALC_FLR.3" - }, - "nscib": {}, - "niap": {}, - "canada": {} + } }, "st_frontpage": { - "anssi": {}, - "bsi": {}, - "nscib": {}, - "niap": {}, - "canada": {} }, "report_keywords": { "cc_cert_id": { |
