aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJ08nY2024-02-01 16:26:39 +0100
committerJ08nY2024-02-01 16:26:39 +0100
commit8dd6b5b3ca7e99ce9c8750e881250d77fdeadd7f (patch)
treeaf517cb4bf0929e6c6b54e6b9a63f4a4123a5bdd
parentea830883eabb82f43275fa148ce754f9b2e3d184 (diff)
downloadsec-certs-8dd6b5b3ca7e99ce9c8750e881250d77fdeadd7f.tar.gz
sec-certs-8dd6b5b3ca7e99ce9c8750e881250d77fdeadd7f.tar.zst
sec-certs-8dd6b5b3ca7e99ce9c8750e881250d77fdeadd7f.zip
Add france archived list.
-rw-r--r--src/sec_certs/constants.py1
-rw-r--r--src/sec_certs/sample/cc_scheme.py128
-rw-r--r--tests/cc/test_cc_schemes.py3
3 files changed, 102 insertions, 30 deletions
diff --git a/src/sec_certs/constants.py b/src/sec_certs/constants.py
index 228a2b84..620f984f 100644
--- a/src/sec_certs/constants.py
+++ b/src/sec_certs/constants.py
@@ -84,6 +84,7 @@ CC_CANADA_CERTIFIED_URL = "/en/tools-services/common-criteria/certified-products
CC_CANADA_INEVAL_URL = "/en/tools-services/common-criteria/products-evaluation"
CC_ANSSI_BASE_URL = "https://cyber.gouv.fr"
CC_ANSSI_CERTIFIED_URL = CC_ANSSI_BASE_URL + "/produits-certifies"
+CC_ANSSI_ARCHIVED_URL = CC_ANSSI_BASE_URL + "/produits-certifies-archives"
CC_BSI_BASE_URL = "https://www.bsi.bund.de/"
CC_BSI_CERTIFIED_URL = (
CC_BSI_BASE_URL
diff --git a/src/sec_certs/sample/cc_scheme.py b/src/sec_certs/sample/cc_scheme.py
index 465d0dce..ee09c726 100644
--- a/src/sec_certs/sample/cc_scheme.py
+++ b/src/sec_certs/sample/cc_scheme.py
@@ -31,6 +31,7 @@ __all__ = [
"get_canada_certified",
"get_canada_in_evaluation",
"get_france_certified",
+ "get_france_archived",
"get_germany_certified",
"get_india_certified",
"get_india_archived",
@@ -68,7 +69,13 @@ def _get(url: str, session, **kwargs) -> Response:
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=InsecureRequestWarning)
conn = session if session else requests
- resp = conn.get(url, headers={"User-Agent": "seccerts.org"}, verify=False, **kwargs, timeout=10)
+ resp = conn.get(
+ url,
+ headers={"User-Agent": "seccerts.org"},
+ verify=False,
+ **kwargs,
+ timeout=10,
+ )
resp.raise_for_status()
return resp
@@ -85,7 +92,9 @@ def _get_hash(url: str, session=None) -> bytes:
return h.digest()
-def get_australia_in_evaluation(enhanced: bool = True) -> list[dict[str, Any]]: # noqa: C901
+def get_australia_in_evaluation( # noqa: C901
+ enhanced: bool = True,
+) -> list[dict[str, Any]]:
"""
Get Australia "products in evaluation" entries.
@@ -156,7 +165,10 @@ def get_canada_certified() -> list[dict[str, Any]]:
:return: The entries.
"""
- resp = _get(constants.CC_CANADA_API_URL + f"?lang=en&url={constants.CC_CANADA_CERTIFIED_URL}", None)
+ resp = _get(
+ constants.CC_CANADA_API_URL + f"?lang=en&url={constants.CC_CANADA_CERTIFIED_URL}",
+ None,
+ )
html_data = resp.json()["response"]["page"]["body"][0]
soup = BeautifulSoup(html_data, "html5lib")
tbody = soup.find("table").find("tbody")
@@ -181,7 +193,10 @@ def get_canada_in_evaluation() -> list[dict[str, Any]]:
:return: The entries.
"""
- resp = _get(constants.CC_CANADA_API_URL + f"?lang=en&url={constants.CC_CANADA_INEVAL_URL}", None)
+ resp = _get(
+ constants.CC_CANADA_API_URL + f"?lang=en&url={constants.CC_CANADA_INEVAL_URL}",
+ None,
+ )
html_data = resp.json()["response"]["page"]["body"][0]
soup = BeautifulSoup(html_data, "html5lib")
tbody = soup.find("table").find("tbody")
@@ -200,15 +215,8 @@ def get_canada_in_evaluation() -> list[dict[str, Any]]:
return results
-def get_france_certified(enhanced: bool = True, artifacts: bool = False) -> list[dict[str, Any]]: # noqa: C901
- """
- Get French "certified product" entries.
-
- :param enhanced: Whether to enhance the results by following links (slower, more data).
- :param artifacts: Whether to download and compute artifact hashes (way slower, even more data).
- :return: The entries.
- """
- base_soup = _get_page(constants.CC_ANSSI_CERTIFIED_URL)
+def _get_france(url, enhanced, artifacts) -> list[dict[str, Any]]: # noqa: C901
+ base_soup = _get_page(url)
pager = base_soup.find("nav", class_="pager")
last_page_a = re.search("[0-9]+", pager.find("a", title="Aller à la dernière page").text)
if not last_page_a:
@@ -216,13 +224,15 @@ def get_france_certified(enhanced: bool = True, artifacts: bool = False) -> list
pages = int(last_page_a.group())
results = []
for page in range(pages + 1):
- soup = _get_page(constants.CC_ANSSI_CERTIFIED_URL + f"?page={page}")
+ soup = _get_page(url + f"?page={page}")
for row in soup.find_all("article", class_="node--type-produit-certifie-cc"):
cert: dict[str, Any] = {
"product": sns(row.find("h3").text),
- "description": sns(row.find("p", class_="field-body")),
"url": urljoin(constants.CC_ANSSI_BASE_URL, row.find("a")["href"]),
}
+ description_para = row.find("p", class_="field-body")
+ if description_para:
+ cert["description"] = sns(description_para.text)
complement_info = row.find("div", class_="info-complement")
for li in complement_info.find_all("li"):
label = li.find("span").text
@@ -288,7 +298,31 @@ def get_france_certified(enhanced: bool = True, artifacts: bool = False) -> list
return results
-def get_germany_certified(enhanced: bool = True, artifacts: bool = False) -> list[dict[str, Any]]: # noqa: C901
+def get_france_certified(enhanced: bool = True, artifacts: bool = False) -> list[dict[str, Any]]: # noqa: C901
+ """
+ Get French "certified product" entries.
+
+ :param enhanced: Whether to enhance the results by following links (slower, more data).
+ :param artifacts: Whether to download and compute artifact hashes (way slower, even more data).
+ :return: The entries.
+ """
+ return _get_france(constants.CC_ANSSI_CERTIFIED_URL, enhanced, artifacts)
+
+
+def get_france_archived(enhanced: bool = True, artifacts: bool = False) -> list[dict[str, Any]]: # noqa: C901
+ """
+ Get French "archived product" entries.
+
+ :param enhanced: Whether to enhance the results by following links (slower, more data).
+ :param artifacts: Whether to download and compute artifact hashes (way slower, even more data).
+ :return: The entries.
+ """
+ return _get_france(constants.CC_ANSSI_ARCHIVED_URL, enhanced, artifacts)
+
+
+def get_germany_certified( # noqa: C901
+ enhanced: bool = True, artifacts: bool = False
+) -> list[dict[str, Any]]:
"""
Get German "certified product" entries.
@@ -736,7 +770,7 @@ def _get_malaysia(url, enhanced, artifacts) -> list[dict[str, Any]]: # noqa: C9
total_pages = int(pages_re.group(1))
results = []
for i in range(total_pages):
- soup = _get_page(url + f"?start={i*10}")
+ soup = _get_page(url + f"?start={i * 10}")
table = soup.find("table", class_="directoryTable")
for tr in table.find_all("tr", class_="directoryRow"):
tds = tr.find_all("td")
@@ -846,7 +880,9 @@ def get_malaysia_in_evaluation() -> list[dict[str, Any]]:
return results
-def get_netherlands_certified(artifacts: bool = False) -> list[dict[str, Any]]: # noqa: C901
+def get_netherlands_certified( # noqa: C901
+ artifacts: bool = False,
+) -> list[dict[str, Any]]:
"""
Get Dutch "certified product" entries.
@@ -916,7 +952,9 @@ def get_netherlands_in_evaluation() -> list[dict[str, Any]]:
return results
-def _get_norway(url: str, enhanced: bool, artifacts: bool) -> list[dict[str, Any]]: # noqa: C901
+def _get_norway( # noqa: C901
+ url: str, enhanced: bool, artifacts: bool
+) -> list[dict[str, Any]]:
soup = _get_page(url)
results = []
for tr in soup.find_all("tr", class_="certified-product"):
@@ -1013,7 +1051,9 @@ def get_norway_archived(enhanced: bool = True, artifacts: bool = False) -> list[
return _get_norway(constants.CC_NORWAY_ARCHIVED_URL, enhanced, artifacts)
-def _get_korea(product_class: int, enhanced: bool, artifacts: bool) -> list[dict[str, Any]]: # noqa: C901
+def _get_korea( # noqa: C901
+ product_class: int, enhanced: bool, artifacts: bool
+) -> list[dict[str, Any]]:
session = requests.session()
session.get(constants.CC_KOREA_EN_URL)
# Get base page
@@ -1177,7 +1217,10 @@ def _get_singapore(url: str, artifacts: bool) -> list[dict[str, Any]]:
"cert_title": obj["certificate"]["title"],
"cert_link": urljoin(constants.CC_SINGAPORE_BASE_URL, obj["certificate"]["mediaUrl"]),
"report_title": obj["certificationReport"]["title"],
- "report_link": urljoin(constants.CC_SINGAPORE_BASE_URL, obj["certificationReport"]["mediaUrl"]),
+ "report_link": urljoin(
+ constants.CC_SINGAPORE_BASE_URL,
+ obj["certificationReport"]["mediaUrl"],
+ ),
"target_title": obj["securityTarget"]["title"],
"target_link": urljoin(constants.CC_SINGAPORE_BASE_URL, obj["securityTarget"]["mediaUrl"]),
}
@@ -1269,7 +1312,9 @@ def get_spain_certified() -> list[dict[str, Any]]:
return results
-def _get_sweden(url: str, enhanced: bool, artifacts: bool) -> list[dict[str, Any]]: # noqa: C901
+def _get_sweden( # noqa: C901
+ url: str, enhanced: bool, artifacts: bool
+) -> list[dict[str, Any]]:
soup = _get_page(url)
nav = soup.find("main").find("nav", class_="component-nav-box__list")
results = []
@@ -1400,7 +1445,9 @@ def get_turkey_certified() -> list[dict[str, Any]]:
return results
-def get_usa_certified(enhanced: bool = True, artifacts: bool = False) -> list[dict[str, Any]]: # noqa: C901
+def get_usa_certified( # noqa: C901
+ enhanced: bool = True, artifacts: bool = False
+) -> list[dict[str, Any]]:
"""
Get American "certified product" entries.
@@ -1577,11 +1624,23 @@ class CCScheme(ComplexSerializableType):
methods: ClassVar[dict[str, dict[EntryType, Callable]]] = {
"AU": {EntryType.InEvaluation: get_australia_in_evaluation},
- "CA": {EntryType.InEvaluation: get_canada_in_evaluation, EntryType.Certified: get_canada_certified},
- "FR": {EntryType.Certified: get_france_certified},
+ "CA": {
+ EntryType.InEvaluation: get_canada_in_evaluation,
+ EntryType.Certified: get_canada_certified,
+ },
+ "FR": {
+ EntryType.Certified: get_france_certified,
+ EntryType.Archived: get_france_archived,
+ },
"DE": {EntryType.Certified: get_germany_certified},
- "IN": {EntryType.Certified: get_india_certified, EntryType.Archived: get_india_archived},
- "IT": {EntryType.Certified: get_italy_certified, EntryType.InEvaluation: get_italy_in_evaluation},
+ "IN": {
+ EntryType.Certified: get_india_certified,
+ EntryType.Archived: get_india_archived,
+ },
+ "IT": {
+ EntryType.Certified: get_italy_certified,
+ EntryType.InEvaluation: get_italy_in_evaluation,
+ },
"JP": {
EntryType.InEvaluation: get_japan_in_evaluation,
EntryType.Certified: get_japan_certified,
@@ -1592,9 +1651,18 @@ class CCScheme(ComplexSerializableType):
EntryType.Archived: get_malaysia_archived,
EntryType.InEvaluation: get_malaysia_in_evaluation,
},
- "NL": {EntryType.Certified: get_netherlands_certified, EntryType.InEvaluation: get_netherlands_in_evaluation},
- "NO": {EntryType.Certified: get_norway_certified, EntryType.Archived: get_norway_archived},
- "KO": {EntryType.Certified: get_korea_certified, EntryType.Archived: get_korea_archived},
+ "NL": {
+ EntryType.Certified: get_netherlands_certified,
+ EntryType.InEvaluation: get_netherlands_in_evaluation,
+ },
+ "NO": {
+ EntryType.Certified: get_norway_certified,
+ EntryType.Archived: get_norway_archived,
+ },
+ "KO": {
+ EntryType.Certified: get_korea_certified,
+ EntryType.Archived: get_korea_archived,
+ },
"SG": {
EntryType.InEvaluation: get_singapore_in_evaluation,
EntryType.Certified: get_singapore_certified,
diff --git a/tests/cc/test_cc_schemes.py b/tests/cc/test_cc_schemes.py
index 984666ef..a9e2105c 100644
--- a/tests/cc/test_cc_schemes.py
+++ b/tests/cc/test_cc_schemes.py
@@ -47,6 +47,9 @@ def test_anssi():
certified = CCSchemes.get_france_certified()
assert len(certified) != 0
assert absolute_urls(certified)
+ archived = CCSchemes.get_france_archived()
+ assert len(archived) != 0
+ assert absolute_urls(archived)
@pytest.mark.xfail(reason="May fail due to server errors.", raises=RequestException)