From 520ce49b95c7f79481a68f23ec74bffbc93a80c1 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 5 Feb 2024 14:05:28 +0100 Subject: [PATCH] Improve Indian rules. --- src/sec_certs/rules.yaml | 10 +++++++--- src/sec_certs/sample/cc_certificate_id.py | 14 ++++++++++++-- tests/cc/test_cc_misc.py | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/sec_certs/rules.yaml b/src/sec_certs/rules.yaml index 5e000144..41357015 100644 --- a/src/sec_certs/rules.yaml +++ b/src/sec_certs/rules.yaml @@ -94,9 +94,13 @@ cc_cert_id: # CSEC2019015 # CSEC 2019012 IN: - # India (IC3S/DEL01/VALIANT/EAL1/0317/0007/CR STQC/CC/14-15/12/ETR/0017 IC3S/MUM01/CISCO/cPP/0119/0016/CR) - # will miss STQC/CC/14-15/12/ETR/0017 - - "(?:IC3S|STQC/CC)/[^ ]+? ?/CR" + - "IC3S/(?P[A-Z]+[0-9]+)/(?P[a-zA-Z_]+)/(?P[a-zA-Z0-9]+)/(?P[0-9]+)/(?P[0-9]+) ?(?:/CR)?" + # XXX: The cert IDs are often present only in the certificate and not in the report. + # The report often only has the report id, of the format "STQC/CC/1617/18/CR" + # Examples: + # IC3S/BG01/HALTDOS/EAL2/0317/0008/CR + # IC3S/KOL01/ADVA/EAL2/0520/0021/CR + # IC3S/MUM01/Symantec/NDcPP/0722/0032/CR SG: - "CSA_CC_(?P[0-9]{2})(?P[0-9]{3})" # Examples: diff --git a/src/sec_certs/sample/cc_certificate_id.py b/src/sec_certs/sample/cc_certificate_id.py index 5facf1a5..7997b846 100644 --- a/src/sec_certs/sample/cc_certificate_id.py +++ b/src/sec_certs/sample/cc_certificate_id.py @@ -117,7 +117,17 @@ def _canonical_es(self) -> str: return new_cert_id def _canonical_in(self): - return self.clean.replace(" ", "") + new_cert_id = self.clean + for rule in rules["cc_cert_id"]["IN"]: + if match := re.match(rule, new_cert_id): + groups = match.groupdict() + lab = groups["lab"] + vendor = groups["vendor"] + level = groups["level"] + number1, number2 = groups["number1"], groups["number2"] + new_cert_id = f"IC3S/{lab}/{vendor}/{level}/{number1}/{number2}" + break + return new_cert_id def _canonical_se(self): new_cert_id = self.clean @@ -232,7 +242,7 @@ def canonical(self) -> str: "AU": self._canonical_au, "KR": self._canonical_kr, # SG is canonical by default - # IT is canonucal by default + # IT is canonical by default } if self.scheme in schemes: diff --git a/tests/cc/test_cc_misc.py b/tests/cc/test_cc_misc.py index 50bd81c0..ca32fe91 100644 --- a/tests/cc/test_cc_misc.py +++ b/tests/cc/test_cc_misc.py @@ -31,7 +31,7 @@ def test_canonicalize_es(): def test_canonicalize_in(): - assert canonicalize("IC3S/KOL01/ADVA/EAL2/0520/0021 /CR", "IN") == "IC3S/KOL01/ADVA/EAL2/0520/0021/CR" + assert canonicalize("IC3S/KOL01/ADVA/EAL2/0520/0021 /CR", "IN") == "IC3S/KOL01/ADVA/EAL2/0520/0021" def test_canonicalize_se():