Skip to content

Commit

Permalink
Improve scheme parsing.
Browse files Browse the repository at this point in the history
Only match if category matches.
Disregard unwanted warnings.
Add progress bars everywhere.
  • Loading branch information
J08nY committed Nov 4, 2024
1 parent 8919021 commit e303b6f
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 90 deletions.
6 changes: 4 additions & 2 deletions src/sec_certs/dataset/cc_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ def from_dict(cls, dct: Mapping) -> CCSchemeDataset:
return cls(dct["schemes"])

@classmethod
def from_web(cls, only_schemes: set[str] | None = None) -> CCSchemeDataset:
def from_web(
cls, only_schemes: set[str] | None = None, enhanced: bool | None = None, artifacts: bool | None = None
) -> CCSchemeDataset:
schemes = {}
for scheme, sources in CCScheme.methods.items():
if only_schemes is not None and scheme not in only_schemes:
continue
try:
schemes[scheme] = CCScheme.from_web(scheme, sources.keys())
schemes[scheme] = CCScheme.from_web(scheme, sources.keys(), enhanced=enhanced, artifacts=artifacts)
except Exception as e:
logger.warning(f"Could not download CC scheme: {scheme} due to error {e}.")
return cls(schemes)
23 changes: 23 additions & 0 deletions src/sec_certs/model/cc_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@
from sec_certs.sample.cc_certificate_id import CertificateId
from sec_certs.utils.strings import fully_sanitize_string

CATEGORIES = {
"ICs, Smart Cards and Smart Card-Related Devices and Systems",
"Other Devices and Systems",
"Network and Network-Related Devices and Systems",
"Multi-Function Devices",
"Boundary Protection Devices and Systems",
"Data Protection",
"Operating Systems",
"Products for Digital Signatures",
"Access Control Devices and Systems",
"Mobility",
"Databases",
"Trusted Computing",
"Detection Devices and Systems",
"Key Management Systems",
"Biometric Systems and Devices",
}


class CCSchemeMatcher(AbstractMatcher[CCCertificate]):
"""
Expand Down Expand Up @@ -46,6 +64,8 @@ def _prepare(self):
if vendor_name := self._get_from_entry("vendor", "developer", "manufacturer", "supplier"):
self._vendor = fully_sanitize_string(vendor_name)

self._category = self._get_from_entry("category")

self._report_hash = self._get_from_entry("report_hash")
self._target_hash = self._get_from_entry("target_hash")

Expand All @@ -69,6 +89,9 @@ def match(self, cert: CCCertificate) -> float:
# We need to have something to match to.
if self._product is None or self._vendor is None or cert.name is None or cert.manufacturer is None:
return 0
# It is a correctly parsed category but the wrong one.
if self._category in CATEGORIES and self._category != cert.category:
return 0

Check warning on line 94 in src/sec_certs/model/cc_matching.py

View check run for this annotation

Codecov / codecov/patch

src/sec_certs/model/cc_matching.py#L94

Added line #L94 was not covered by tests
cert_name = fully_sanitize_string(cert.name)
cert_manufacturer = fully_sanitize_string(cert.manufacturer)
# If we match exactly, return early.
Expand Down
Loading

0 comments on commit e303b6f

Please sign in to comment.