aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJ08nY2025-02-01 21:04:45 +0100
committerJ08nY2025-02-01 22:58:29 +0100
commit3173ff97ed4439b83b90f490a0b92c99c0dd375b (patch)
treeb309840cac7eef7c3b3cdaa2eb83581a1f0a10c0 /src
parentd7ccc163ed1afa9e93c91f4a49443525185be424 (diff)
downloadsec-certs-3173ff97ed4439b83b90f490a0b92c99c0dd375b.tar.gz
sec-certs-3173ff97ed4439b83b90f490a0b92c99c0dd375b.tar.zst
sec-certs-3173ff97ed4439b83b90f490a0b92c99c0dd375b.zip
Revert the FIPS IUT and MIP from_web methods.
Diffstat (limited to 'src')
-rw-r--r--src/sec_certs/sample/fips_iut.py24
-rw-r--r--src/sec_certs/sample/fips_mip.py21
2 files changed, 31 insertions, 14 deletions
diff --git a/src/sec_certs/sample/fips_iut.py b/src/sec_certs/sample/fips_iut.py
index c1c2900b..6d979dde 100644
--- a/src/sec_certs/sample/fips_iut.py
+++ b/src/sec_certs/sample/fips_iut.py
@@ -143,21 +143,31 @@ class IUTSnapshot(ComplexSerializableType):
return cls.from_page(content, snapshot_date)
@classmethod
- def from_web(cls) -> IUTSnapshot:
+ def from_nist_web(cls) -> IUTSnapshot:
"""
Get an IUT snapshot from the FIPS website right now.
"""
- if config.preferred_source_remote_datasets == "origin":
- iut_resp = requests.get(constants.FIPS_IUT_URL)
- else:
- iut_resp = requests.get(config.fips_iut_dataset)
+ iut_resp = requests.get(constants.FIPS_IUT_URL)
if iut_resp.status_code != 200:
raise ValueError(f"Getting IUT snapshot failed: {iut_resp.status_code}")
+ snapshot_date = to_utc(datetime.now())
+ return cls.from_page(iut_resp.content, snapshot_date)
+
+ @classmethod
+ def from_web(cls) -> IUTSnapshot:
+ """
+ Fetch a fresh snapshot from sec-certs.org, if the `preferred_source_remote_datasets` config
+ entry is equal to "sec-certs".
+
+ Otherwise, the same as `from_nist_web`.
+ """
if config.preferred_source_remote_datasets == "origin":
- snapshot_date = to_utc(datetime.now())
- return cls.from_page(iut_resp.content, snapshot_date)
+ return cls.from_nist_web()
else:
+ iut_resp = requests.get(config.fips_iut_latest_snapshot)
+ if iut_resp.status_code != 200:
+ raise ValueError(f"Getting IUT snapshot failed: {iut_resp.status_code}")
with NamedTemporaryFile() as tmpfile:
tmpfile.write(iut_resp.content)
return cls.from_json(tmpfile.name)
diff --git a/src/sec_certs/sample/fips_mip.py b/src/sec_certs/sample/fips_mip.py
index 875f0464..c7d84ad1 100644
--- a/src/sec_certs/sample/fips_mip.py
+++ b/src/sec_certs/sample/fips_mip.py
@@ -246,21 +246,28 @@ class MIPSnapshot(ComplexSerializableType):
return cls.from_page(content, snapshot_date)
@classmethod
- def from_web(cls) -> MIPSnapshot:
+ def from_nist_web(cls) -> MIPSnapshot:
"""
Get a MIP snapshot from the FIPS website right now.
"""
- if config.preferred_source_remote_datasets == "origin":
- mip_resp = requests.get(constants.FIPS_MIP_URL)
- else:
- mip_resp = requests.get(config.fips_mip_dataset)
+ mip_resp = requests.get(constants.FIPS_MIP_URL)
if mip_resp.status_code != 200:
raise ValueError(f"Getting MIP snapshot failed: {mip_resp.status_code}")
+ snapshot_date = to_utc(datetime.now())
+ return cls.from_page(mip_resp.content, snapshot_date)
+
+ @classmethod
+ def from_web(cls) -> MIPSnapshot:
+ """
+ Get a MIP snapshot from the FIPS website right now.
+ """
if config.preferred_source_remote_datasets == "origin":
- snapshot_date = to_utc(datetime.now())
- return cls.from_page(mip_resp.content, snapshot_date)
+ return cls.from_nist_web()
else:
+ mip_resp = requests.get(config.fips_mip_latest_snapshot)
+ if mip_resp.status_code != 200:
+ raise ValueError(f"Getting MIP snapshot failed: {mip_resp.status_code}")
with NamedTemporaryFile() as tmpfile:
tmpfile.write(mip_resp.content)
return cls.from_json(tmpfile.name)