aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Janovsky2025-01-27 16:11:32 +0100
committerJ08nY2025-02-01 22:57:38 +0100
commitbcbb31e609c1f03f8b66b9e0bc0c27ce9cd7e562 (patch)
tree35ab0ecb0a3c2fad7a62827e9eb51b5ebd2bb284
parentd0619fa3c71f78455cbcc0220af71f94ac1fef90 (diff)
downloadsec-certs-bcbb31e609c1f03f8b66b9e0bc0c27ce9cd7e562.tar.gz
sec-certs-bcbb31e609c1f03f8b66b9e0bc0c27ce9cd7e562.tar.zst
sec-certs-bcbb31e609c1f03f8b66b9e0bc0c27ce9cd7e562.zip
forbid empty PP links in ProtectionProfile objects
-rw-r--r--src/sec_certs/dataset/protection_profile.py18
-rw-r--r--src/sec_certs/sample/protection_profile.py20
2 files changed, 23 insertions, 15 deletions
diff --git a/src/sec_certs/dataset/protection_profile.py b/src/sec_certs/dataset/protection_profile.py
index 1bb2e3f1..4a938d1c 100644
--- a/src/sec_certs/dataset/protection_profile.py
+++ b/src/sec_certs/dataset/protection_profile.py
@@ -226,16 +226,14 @@ class ProtectionProfileDataset(Dataset[ProtectionProfile], ComplexSerializableTy
return {}
body = list(tables[0].find_all("tr"))[1:]
- try:
- table_certs = {
- x.dgst: x
- for x in [
- ProtectionProfile.from_html_row(row, cert_status, category_string, is_collaborative)
- for row in body
- ]
- }
- except ValueError as e:
- raise ValueError(f"Bad html file: {file.name} ({str(e)})") from e
+ table_certs = {}
+ for row in body:
+ try:
+ pp = ProtectionProfile.from_html_row(row, cert_status, category_string, is_collaborative)
+ table_certs[pp.dgst] = pp
+ except ValueError as e:
+ logger.error(f"Error when creating ProtectionProfile object: {e}")
+
return table_certs
cert_status: Literal["active", "archived"] = "active" if "active" in file.name else "archived"
diff --git a/src/sec_certs/sample/protection_profile.py b/src/sec_certs/sample/protection_profile.py
index 36f13130..079c9319 100644
--- a/src/sec_certs/sample/protection_profile.py
+++ b/src/sec_certs/sample/protection_profile.py
@@ -19,7 +19,7 @@ from sec_certs.sample.certificate import Heuristics as BaseHeuristics
from sec_certs.sample.certificate import PdfData as BasePdfData
from sec_certs.sample.document_state import DocumentState
from sec_certs.serialization.json import ComplexSerializableType
-from sec_certs.utils import helpers
+from sec_certs.utils import helpers, sanitization
class ProtectionProfile(
@@ -83,18 +83,23 @@ class ProtectionProfile(
f"Unexpected number of <td> elements in PP html row. Expected: 6, actual: {len(cells)}"
)
+ pp_link = cls._html_row_get_link(cells[0])
+ pp_name = cls._html_row_get_name(cells[0])
+ if not sanitization.sanitize_cc_link(pp_link):
+ raise ValueError(f"pp_link for PP {pp_name} is empty, cannot create PP record")
+
# TODO: Parse maintenance div here. See CC parsing.
return cls(
category,
status,
False,
- cls._html_row_get_name(cells[0]),
+ pp_name,
cls._html_row_get_version(cells[1]),
cls._html_row_get_security_level(cells[2]),
cls._html_row_get_date(cells[3]),
None if status == "active" else cls._html_row_get_date(cells[4]),
cls._html_row_get_link(cells[-1]),
- cls._html_row_get_link(cells[0]),
+ pp_link,
cls._html_row_get_scheme(cells[-2]),
[],
)
@@ -107,17 +112,22 @@ class ProtectionProfile(
f"Unexpected number of <td> elements in collaborative PP html row. Expected: 5, actual: {len(cells)}"
)
+ pp_link = cls._html_row_get_collaborative_pp_link(cells[0])
+ pp_name = cls._html_row_get_collaborative_name(cells[0])
+ if not sanitization.sanitize_cc_link(pp_link):
+ raise ValueError(f"pp_link for PP {pp_name} is empty, cannot create PP record")
+
return cls(
category,
"active",
True,
- cls._html_row_get_collaborative_name(cells[0]),
+ pp_name,
cls._html_row_get_version(cells[1]),
cls._html_row_get_security_level(cells[2]),
cls._html_row_get_date(cells[3]),
None,
cls._html_row_get_link(cells[-1]),
- cls._html_row_get_collaborative_pp_link(cells[0]),
+ pp_link,
None,
[],
)