aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGeogeFI2022-01-27 08:18:28 +0100
committerGeogeFI2022-01-27 08:18:28 +0100
commit92f8d4d416692ca9efe019f680b731e527ab0a0d (patch)
treee2ed53e261964155eba5a5a5e2c33ff94c802095
parent06ae452a8663e1d4600fa7747f611a780df0cdb4 (diff)
downloadsec-certs-92f8d4d416692ca9efe019f680b731e527ab0a0d.tar.gz
sec-certs-92f8d4d416692ca9efe019f680b731e527ab0a0d.tar.zst
sec-certs-92f8d4d416692ca9efe019f680b731e527ab0a0d.zip
feat: Nscib parsing header function from old-api, untested
-rw-r--r--sec_certs/cert_rules.py4
-rw-r--r--sec_certs/helpers.py93
2 files changed, 97 insertions, 0 deletions
diff --git a/sec_certs/cert_rules.py b/sec_certs/cert_rules.py
index 8d0637b8..9856c71d 100644
--- a/sec_certs/cert_rules.py
+++ b/sec_certs/cert_rules.py
@@ -8,6 +8,7 @@ rules_cert_id = [
"BSI-DSZ-CC-[0-9]+?-[0-9]+", # German BSI
"BSI-DSZ-CC-[0-9]+?-(?:V|v)[0-9]+-[0-9]+", # German BSI
"BSI-DSZ-CC-[0-9]+?-(?:V|v)[0-9]+", # German BSI
+ "BSI-DSZ-CC-[0-9]+-(?:V|v)[0-9]+(-[0-9][0-9][0-9][0-9])*", # German BSI (number + version + year or without year)
# 'CC-Zert-.+?',
"ANSSI(?:-|-CC-)[0-9]+?/[0-9]+", # French
# 'ANSSI-CC-CER-F-.+?', # French
@@ -17,12 +18,14 @@ rules_cert_id = [
"NSCIB-CC-[0-9][0-9][0-9][0-9].+?", # Netherlands
"NSCIB-CC-[0-9][0-9][0-9][0-9][0-9]*-CR", # Netherlands
"NSCIB-CC-[0-9][0-9]-[0-9]+?-CR[0-9]+?", # Netherlands
+ 'NSCIB-CC-[0-9][0-9]-[0-9]+(-CR[0-9]+)*', # Netherlands (old number NSCIB-CC-05-6609 or NSCIB-CC-05-6609-CR)
"SERTIT-[0-9]+?", # Norway
"CCEVS-VR-(?:|VID)[0-9]+?-[0-9]+?", # US NSA
# '[0-9][0-9\-]+?-CR', # Canada
"CRP[0-9][0-9][0-9][0-9]*?", # UK CESG
"CERTIFICATION REPORT No. P[0-9]+?", # UK CESG
"20[0-9][0-9]-[0-9]+-INF-[0-9]+?", # Spain
+ "20[0-9][0-9]-[0-9]+-INF-[0-9]+(.(?:V|v)[0-9]+)*", # Spain (2006-4-INF-98 v2 or (2006-4-INF-98-v2))
"KECS-CR-[0-9]+?-[0-9]+?", # Korea
"KECS-ISIS-[0-9]+?-[0-9][0-9][0-9][0-9]", # Korea
"CRP-C[0-9]+?-[0-9]+?", # Japan
@@ -30,6 +33,7 @@ rules_cert_id = [
"OCSI/CERT/.+?", # Italia
"[0-9\\.]+?/TSE-CCCS-[0-9]+?", # Turkis CCCS
"BTBD-.+?", # Turkis CCCS
+ "[0-9][0-9][0-9]-[47]-[0-9][0-9][0-9](-CR)*", # Canada xxx-{47}-xxx (383-4-438, 383-4-82-CR)
]
rules_vendor = [
diff --git a/sec_certs/helpers.py b/sec_certs/helpers.py
index 90e250d8..d989f254 100644
--- a/sec_certs/helpers.py
+++ b/sec_certs/helpers.py
@@ -598,6 +598,99 @@ def search_only_headers_bsi(filepath: Path): # noqa: C901
return constants.RETURNCODE_OK, items_found
+# Port from old-api branch
+def search_only_headers_nscib(filepath: Path):
+ LINE_SEPARATOR_STRICT = ' '
+ NUM_LINES_TO_INVESTIGATE = 60
+ items_found_all = {}
+ items_found = {}
+ files_without_match = []
+
+ if not 'NSCIB-CC-' in filepath:
+ return constants.RETURNCODE_NOK
+
+ #
+ # Process front page with info: cert_id, certified_item and developer
+ #
+ whole_text, whole_text_with_newlines, was_unicode_decode_error = load_cert_file(
+ filepath, NUM_LINES_TO_INVESTIGATE, LINE_SEPARATOR_STRICT)
+
+ certified_item = ''
+ developer = ''
+ cert_lab = ''
+ cert_id = ''
+ sponsor = ''
+
+ lines = whole_text_with_newlines.splitlines()
+ no_match_yet = True
+ item_offset = -1
+
+ for line_index in range(0, len(lines)):
+ line = lines[line_index]
+
+ if 'Certification Report' in line:
+ item_offset = line_index + 1
+ if 'Assurance Continuity Maintenance Report' in line:
+ item_offset = line_index + 1
+
+ SPONSORDEVELOPER_STR = 'Sponsor and developer:'
+
+ if SPONSORDEVELOPER_STR in line:
+ if no_match_yet:
+ items_found_all[file_name] = {}
+ items_found = items_found_all[file_name]
+ no_match_yet = False
+
+ # all lines above till 'Certification Report' or 'Assurance Continuity Maintenance Report'
+ certified_item = ''
+ for name_index in range(item_offset, line_index):
+ certified_item += lines[name_index] + ' '
+ developer = line[line.find(SPONSORDEVELOPER_STR) + len(SPONSORDEVELOPER_STR):]
+
+ SPONSOR_STR = 'Sponsor:'
+
+ if SPONSOR_STR in line:
+ if no_match_yet:
+ items_found_all[file_name] = {}
+ items_found = items_found_all[file_name]
+ no_match_yet = False
+
+ # all lines above till 'Certification Report' or 'Assurance Continuity Maintenance Report'
+ certified_item = ''
+ for name_index in range(item_offset, line_index):
+ certified_item += lines[name_index] + ' '
+ sponsor = line[line.find(SPONSOR_STR) + len(SPONSOR_STR):]
+
+ DEVELOPER_STR = 'Developer:'
+ if DEVELOPER_STR in line:
+ developer = line[line.find(DEVELOPER_STR) + len(DEVELOPER_STR):]
+
+ CERTLAB_STR = 'Evaluation facility:'
+ if CERTLAB_STR in line:
+ cert_lab = line[line.find(CERTLAB_STR) + len(CERTLAB_STR):]
+
+ REPORTNUM_STR = 'Report number:'
+ if REPORTNUM_STR in line:
+ cert_id = line[line.find(REPORTNUM_STR) + len(REPORTNUM_STR):]
+
+ if no_match_yet:
+ files_without_match.append(filepath)
+ else:
+ items_found[TAG_CERT_ID] = normalize_match_string(cert_id)
+ items_found[TAG_CERT_ITEM] = normalize_match_string(
+ certified_item)
+ items_found[TAG_DEVELOPER] = normalize_match_string(developer)
+ items_found[TAG_CERT_LAB] = cert_lab
+
+ #return items_found_all, files_without_match
+
+ return constants.RETURNCODE_OK, items_found_all
+
+
+
+
+
+
def extract_keywords(filepath: Path) -> Tuple[str, Optional[Dict[str, Dict[str, int]]]]:
try: