diff options
| author | J08nY | 2022-09-21 17:02:52 +0200 |
|---|---|---|
| committer | J08nY | 2022-09-21 17:02:52 +0200 |
| commit | 8ad9afb71643b8606a9030b53f3c080487ec4545 (patch) | |
| tree | 3d9c6d54d929c2a91ab69690b82a4a0539c72119 | |
| parent | d7e9c562bdc0b6bad83d7fecc25eec26833cf538 (diff) | |
| download | sec-certs-8ad9afb71643b8606a9030b53f3c080487ec4545.tar.gz sec-certs-8ad9afb71643b8606a9030b53f3c080487ec4545.tar.zst sec-certs-8ad9afb71643b8606a9030b53f3c080487ec4545.zip | |
Add canonicalization for UK, CA, JP.
| -rw-r--r-- | notebooks/cert_id_eval.ipynb | 24 | ||||
| -rw-r--r-- | sec_certs/sample/cc_certificate_id.py | 38 | ||||
| -rw-r--r-- | sec_certs/sample/common_criteria.py | 5 |
3 files changed, 45 insertions, 22 deletions
diff --git a/notebooks/cert_id_eval.ipynb b/notebooks/cert_id_eval.ipynb index 0b359a84..db46625d 100644 --- a/notebooks/cert_id_eval.ipynb +++ b/notebooks/cert_id_eval.ipynb @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "pycharm": { "name": "#%%\n" @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "pycharm": { "name": "#%%\n" @@ -410,8 +410,24 @@ }, { "cell_type": "code", - "execution_count": null, - "outputs": [], + "execution_count": 3, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "afcf5263d97159f8 Certificate Number: 2019/125 None certificate.pdf y\n", + "f73d08f8cdfe276d ANSSI-CC-2003/28 Rapport de certification 2003/28 frontpage y\n", + "7d3546a4000b5b75 ANSSI-CC-2004/08 Rapport de certification 2004/08 frontpage y\n", + "0dcc691ea04d1b52 383-4-351 None certificate.docx n\n", + "9c6440ecec046cc0 Certification Report 2012/79 None frontpage y\n", + "205dba83d0a6e46c 2011-8-INF-835 2011-08-INF-835 frontpage y\n", + "afcf5263d97159f8 Certificate Number: 2019/125 None certificate.pdf y\n", + "c24c5157e8af96d4 ANSSI-CC-2005/21 Rapport de certification 2005/21 frontpage y\n", + "92 6 1\n" + ] + } + ], "source": [ "correct = set()\n", "possible = set()\n", diff --git a/sec_certs/sample/cc_certificate_id.py b/sec_certs/sample/cc_certificate_id.py index ade12bc9..8732bd27 100644 --- a/sec_certs/sample/cc_certificate_id.py +++ b/sec_certs/sample/cc_certificate_id.py @@ -1,3 +1,4 @@ +import re from dataclasses import dataclass from typing import List, Tuple @@ -54,19 +55,9 @@ class CertificateId: return cert_num, cert_version, cert_year - # start_year = 1996 - # limit_year = datetime.now().year + 1 bsi_parts = self.clean.split("-") cert_num, cert_version, cert_year = extract_parts(bsi_parts) - # if cert_year is None: - # for year in range(start_year, limit_year): - # cert_id_possible = cert_id + "-" + str(year) - # - # if cert_id_possible in all_cert_ids: - # # we found version with year - # cert_year = str(year) - # break # reconstruct BSI number again new_cert_id = "BSI-DSZ-CC" @@ -108,6 +99,25 @@ class CertificateId: def _canonical_se(self): return self.clean.replace(" ", "") + def _canonical_uk(self): + new_cert_id = self.clean + if match := re.match("CERTIFICATION REPORT No. P([0-9]+)", new_cert_id): + new_cert_id = "CRP" + match.group(1) + return new_cert_id + + def _canonical_ca(self): + new_cert_id = self.clean + if new_cert_id.endswith("-CR"): + new_cert_id = new_cert_id[:-3] + return new_cert_id + + def _canonical_jp(self): + new_cert_id = self.clean + if match := re.match("Certification No. (C[0-9]+)", new_cert_id): + return match.group(1) + if match := re.search("CRP-(C[0-9]+)-", new_cert_id): + return match.group(1) + @property def clean(self) -> str: """ @@ -128,11 +138,9 @@ class CertificateId: "IT": self._canonical_it, "IN": self._canonical_in, "SE": self._canonical_se, - # TODO: Unify UK CRP... vs Certification REPORT No. - # TODO: Unify JP C0000 vs JISEC-... - # TODO: Unify US (-CR and no -CR) - # TODO: Unify CA (-CR and no -CR) - # TODO: Unify NL (-CR??) + "UK": self._canonical_uk, + "CA": self._canonical_ca, + "JP": self._canonical_jp, } if self.scheme in schemes: diff --git a/sec_certs/sample/common_criteria.py b/sec_certs/sample/common_criteria.py index 53afd9e2..bb7788c9 100644 --- a/sec_certs/sample/common_criteria.py +++ b/sec_certs/sample/common_criteria.py @@ -25,7 +25,7 @@ from sec_certs.cert_rules import ( rules, security_level_csv_scan, ) -from sec_certs.sample.cc_certificate_id import CertificateId +from sec_certs.sample.cc_certificate_id import canonicalize from sec_certs.sample.certificate import Certificate from sec_certs.sample.certificate import Heuristics as BaseHeuristics from sec_certs.sample.certificate import References, logger @@ -989,5 +989,4 @@ class CommonCriteriaCert( if candidates: candidate = max(candidates, key=candidates.get) # And finally make it canonical, but only if we have it - cert_id = CertificateId(self.scheme, candidate) - self.heuristics.cert_id = cert_id.canonical + self.heuristics.cert_id = canonicalize(candidate, self.scheme) |
