diff options
| author | Adam Janovsky | 2020-10-28 12:46:39 +0100 |
|---|---|---|
| committer | Adam Janovsky | 2020-10-28 12:46:39 +0100 |
| commit | 739fb4a6d8aa6002404bfc96fa8b066121571268 (patch) | |
| tree | 579f53c1e843c37d10d50bd09005ba3773f59c07 | |
| parent | 60f2d226b9061b0ab2378b38c1e90022422bbd90 (diff) | |
| parent | 86d0705e820d24ffa32e4da233c8d494c6e9a745 (diff) | |
| download | sec-certs-739fb4a6d8aa6002404bfc96fa8b066121571268.tar.gz sec-certs-739fb4a6d8aa6002404bfc96fa8b066121571268.tar.zst sec-certs-739fb4a6d8aa6002404bfc96fa8b066121571268.zip | |
Merge branch 'dataset_classes' of github.com:petrs/sec-certs into dataset_classes
| -rw-r--r-- | sec_certs/certificate.py | 1 | ||||
| -rw-r--r-- | sec_certs/constants.py | 27 | ||||
| -rw-r--r-- | sec_certs/dataset.py | 40 | ||||
| -rw-r--r-- | sec_certs/meta_parser.py | 28 |
4 files changed, 64 insertions, 32 deletions
diff --git a/sec_certs/certificate.py b/sec_certs/certificate.py index 14adf86a..a4ff8288 100644 --- a/sec_certs/certificate.py +++ b/sec_certs/certificate.py @@ -1,5 +1,6 @@ from typing import Type import json + from abc import ABC, abstractmethod from . import constants as constants diff --git a/sec_certs/constants.py b/sec_certs/constants.py index d4da75bd..8d2e0657 100644 --- a/sec_certs/constants.py +++ b/sec_certs/constants.py @@ -5,12 +5,6 @@ class CertFramework(Enum): CC = 'Common Criteria' FIPS = 'FIPS' -cc_active_csv_url = 'https://www.commoncriteriaportal.org/products/certified_products.csv' -cc_active_html_url = 'https://www.commoncriteriaportal.org/products/?expand&names' - -cc_archived_csv_url = 'https://www.commoncriteriaportal.org/products/certified_products-archived.csv' -cc_archived_html_url = 'https://www.commoncriteriaportal.org/products/?archived=1&expand&names' - TAG_MATCH_COUNTER = 'count' TAG_MATCH_MATCHES = 'matches' @@ -37,23 +31,4 @@ TAG_PP_REGISTRATOR_SIMPLIFIED = 'pp_registrator_simplified' TAG_PP_SPONSOR = 'pp_sponsor' TAG_PP_EDITOR = 'pp_editor' TAG_PP_REVIEWER = 'pp_reviewer' -TAG_KEYWORDS = 'keywords' - -cc_features = ['name', 'category', 'vendor', 'vendor_web', 'scheme', 'security_level', 'protection_profiles', - 'not_valid_before', 'not_valid_after', 'cert_link', 'cert_report_link', 'security_target_link', - 'maintenances'] - -cc_categories = {'AC': 'Access Control Devices and Systems', - 'BP': 'Boundary Protection Devices and Systems', - 'DP': 'Data Protection', - 'DB': 'Databases', - 'DD': 'Detection Devices and Systems', - 'IC': 'ICs, Smart Cards and Smart Card-Related Devices and Systems', - 'KM': 'Key Management Systems', - 'MD': 'Mobility', - 'MF': 'Multi-Function Devices', - 'NS': 'Network and Network-Related Devices and Systems', - 'OS': 'Operating Systems', - 'OD': 'Other Devices and Systems', - 'DG': 'Products for Digital Signatures', - 'TC': 'Trusted Computing'} +TAG_KEYWORDS = 'keywords'
\ No newline at end of file diff --git a/sec_certs/dataset.py b/sec_certs/dataset.py index a05c6dba..b77eb962 100644 --- a/sec_certs/dataset.py +++ b/sec_certs/dataset.py @@ -1,6 +1,9 @@ from .certificate import CommonCriteriaCert from . import constants from datetime import datetime +from .meta_parser import CCMetaParser +from .certificate import CommonCriteriaCert +from . import constants class Dataset: @@ -8,12 +11,16 @@ class Dataset: self.certs = certs self.framework = framework self.data_dir = data_dir + self.timestamp = datetime.now() self.sha256_digest = 'not implemented' self.name = name + + self.sha256_digest = 'not implemented' # TODO: Implement as hash of all certs + self.name = name # TODO: Allow for naming of the datasets self.description = description # Allow for descriptions of the dataset - # The idea is to iterate over dataset as: `for cert in Dataset: ... ` + # The idea is to iterate over dataset as: `for cert in Dataset: ... def __iter__(self): for cert in self.certs.values(): yield cert @@ -29,6 +36,13 @@ class Dataset: def __len__(self): return len(self.certs) + # Not sure if we want such behaviour + def __eq__(self, other): + return self.certs == other.certs + + def __str__(self): + return 'Not implemented' + def to_json(self): pass @@ -53,14 +67,28 @@ class Dataset: def merge(self, other): return self - # Not sure if we want such behaviour - def __eq__(self, other): - return self.certs == other.certs + def dump_to_json(self): + pass - def __str__(self): - return 'Not implemented' + @classmethod + def init_from_meta(cls, data_dir, name, description): + pass + + +class CCDataset(Dataset): + @classmethod + def init_from_meta(cls, data_dir, name, description): + parser = CCMetaParser() + records = parser.parse_meta() + certs = {} + for r in records: + cert = CommonCriteriaCert.from_dict(r) + certs[cert.sha256] = cert + return CCDataset(certs, constants.CertFramework.CC, data_dir, name, description) +class FIPSDataset(Dataset): + pass diff --git a/sec_certs/meta_parser.py b/sec_certs/meta_parser.py new file mode 100644 index 00000000..bd72bae7 --- /dev/null +++ b/sec_certs/meta_parser.py @@ -0,0 +1,28 @@ +class MetaParser: + def parse_certs_from_html(self): + raise NotImplementedError('Meant to be provided by child classes') + + def parse_certs_from_csv(self): + raise NotImplementedError('Meant to be provided by child classes') + + +class CCMetaParser(MetaParser): + def __init__(self): + self.records = {} + + def parse_meta(self): + self.parse_certs_from_csv() + self.parse_certs_from_html() + + return self.records + + def parse_certs_from_csv(self): + pass + + def parse_certs_from_html(self): + pass + + +class FIPSMetaParser(MetaParser): + def __init__(self): + pass
\ No newline at end of file |
