diff options
| author | Adam Janovsky | 2020-10-28 12:36:07 +0100 |
|---|---|---|
| committer | Adam Janovsky | 2020-10-28 12:37:59 +0100 |
| commit | 60f2d226b9061b0ab2378b38c1e90022422bbd90 (patch) | |
| tree | eca502906a97e0b1b4a87102798d2f75a72a1f20 | |
| parent | 3806a43b0cea6cbd7e4fe719a6765dca13adb4ea (diff) | |
| download | sec-certs-60f2d226b9061b0ab2378b38c1e90022422bbd90.tar.gz sec-certs-60f2d226b9061b0ab2378b38c1e90022422bbd90.tar.zst sec-certs-60f2d226b9061b0ab2378b38c1e90022422bbd90.zip | |
progress on class hierarchy
| -rw-r--r-- | sec_certs/certificate.py | 27 | ||||
| -rw-r--r-- | sec_certs/constants.py | 27 | ||||
| -rw-r--r-- | sec_certs/dataset.py | 50 | ||||
| -rw-r--r-- | sec_certs/dataset_loader.py | 44 | ||||
| -rw-r--r-- | sec_certs/meta_parser.py | 28 |
5 files changed, 111 insertions, 65 deletions
diff --git a/sec_certs/certificate.py b/sec_certs/certificate.py index d00e1b05..14adf86a 100644 --- a/sec_certs/certificate.py +++ b/sec_certs/certificate.py @@ -1,47 +1,52 @@ from typing import Type import json +from abc import ABC, abstractmethod +from . import constants as constants -# TODO: Move me to appropriate place. I'm here just to demonstrate how we're going to serialize to json class CertificateJSONEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, Certificate): - return obj.asdict() + return obj.to_dict() return super().default(obj) -class Certificate: +class Certificate(ABC): def __init__(self): self.sha256 = None - self.framework = None # CC or FIPS or PP or whatever - self.product_name = None - self.vendor_name = None - self.pdf_path = None def __repr__(self): - return str(self.asdict()) + return str(self.to_dict()) def __str__(self): - return 'Not implemented' # TODO: Introduce some meaningful representation of the certificate + return 'Not implemented' - def asdict(self): - return {'not': 'implemented'} # TODO: Implement me, I'll be used for json serialization! + @abstractmethod + def to_dict(self): + raise NotImplementedError('Not meant to be implemented') def __eq__(self, other: 'Certificate') -> bool: return self.sha256 == other.sha256 @classmethod + @abstractmethod def from_dict(cls, dct): raise NotImplementedError('Mot meant to be implemented') class CommonCriteriaCert(Certificate): + def to_dict(self): + pass + @classmethod def from_dict(cls, dct): return CommonCriteriaCert() class FIPSCertificate(Certificate): + def to_dict(self): + pass + @classmethod def from_dict(cls, dct): return FIPSCertificate() diff --git a/sec_certs/constants.py b/sec_certs/constants.py index 8d2e0657..d4da75bd 100644 --- a/sec_certs/constants.py +++ b/sec_certs/constants.py @@ -5,6 +5,12 @@ 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' @@ -31,4 +37,23 @@ 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'
\ No newline at end of file +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'} diff --git a/sec_certs/dataset.py b/sec_certs/dataset.py index 4c008ba1..a05c6dba 100644 --- a/sec_certs/dataset.py +++ b/sec_certs/dataset.py @@ -1,6 +1,6 @@ -from .meta_parser import CCMetaParser from .certificate import CommonCriteriaCert from . import constants +from datetime import datetime class Dataset: @@ -8,9 +8,9 @@ class Dataset: self.certs = certs self.framework = framework self.data_dir = data_dir - - self.sha256_digest = 'not implemented' # TODO: Implement as hash of all certs - self.name = name # TODO: Allow for naming of the datasets + self.timestamp = datetime.now() + self.sha256_digest = 'not implemented' + self.name = name self.description = description # Allow for descriptions of the dataset # The idea is to iterate over dataset as: `for cert in Dataset: ... ` @@ -29,38 +29,38 @@ class Dataset: def __len__(self): return len(self.certs) - def dump_to_json(self): + def to_json(self): pass - # Not sure if we're going to implement - def dump_to_csv(self): + def to_csv(self): pass - # Not sure if we want such behaviour - def __eq__(self, other): - return self.certs == other.certs - - def __str__(self): - return 'Not implemented' # TODO: Prepare some meaningful representation of the dataset + def to_dataframe(self): + pass @classmethod - def init_from_meta(cls, data_dir, name, description): + def from_json(cls): pass + @classmethod + def from_csv(cls): + pass -class CCDataset(Dataset): @classmethod - def init_from_meta(cls, data_dir, name, description): - parser = CCMetaParser() - records = parser.parse_meta() - certs = {} + def from_dataframe(cls, df): + pass + + def merge(self, other): + return self + + # Not sure if we want such behaviour + def __eq__(self, other): + return self.certs == other.certs + + def __str__(self): + return 'Not implemented' + - 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/dataset_loader.py b/sec_certs/dataset_loader.py new file mode 100644 index 00000000..e6094336 --- /dev/null +++ b/sec_certs/dataset_loader.py @@ -0,0 +1,44 @@ +from abc import ABC, abstractmethod +from .dataset import Dataset +import pandas as pd + + +class CertLoader(ABC): + def __init__(self, download_pdfs, meta_dir, pdf_dir): + self.df = pd.DataFrame() + self.download_pdfs = download_pdfs + self.meta_dir = meta_dir + self.pdf_dir = pdf_dir + self.certs = {} + + @abstractmethod + def load(self): + pass + + +class CCCertLoader(CertLoader): + + def load_csv(self): + pass + + def load_html(self): + pass + + def load(self): + self.load_csv() + self.load_html() + return self.certs + + +class FIPSCertLoader(CertLoader): + def load_csv(self): + pass + + def load_html(self): + pass + + def load(self): + self.load_csv() + self.load_html() + return self.certs + diff --git a/sec_certs/meta_parser.py b/sec_certs/meta_parser.py deleted file mode 100644 index bd72bae7..00000000 --- a/sec_certs/meta_parser.py +++ /dev/null @@ -1,28 +0,0 @@ -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 |
