Skip to content

Commit 6cf8778

Browse files
Merge pull request #197 from alexanderjordanbaker/ValidityCheckingOfOCSPResponses
Updating Python to support validity with SKEW checking with cryptogra…
2 parents 8b5ccdc + ede8e17 commit 6cf8778

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

appstoreserverlibrary/signed_data_verifier.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def _decode_signed_object(self, signed_obj: str) -> dict:
179179
class _ChainVerifier:
180180
MAXIMUM_CACHE_SIZE = 32 # There are unlikely to be more than a couple keys at once
181181
CACHE_TIME_LIMIT = 15 * 60 # 15 minutes
182+
MAX_SKEW = datetime.timedelta(seconds=60) # Allowable clock skew when validating OCSP response dates
182183

183184
def __init__(self, root_certificates: List[bytes], enable_strict_checks=True):
184185
self.enable_strict_checks = enable_strict_checks
@@ -327,11 +328,16 @@ def check_ocsp_status(self, cert: crypto.X509, issuer: crypto.X509, root: crypto
327328
cert.to_cryptography(), issuer.to_cryptography(), single_response.hash_algorithm
328329
)
329330
req = builder.build()
331+
now = datetime.datetime.now(datetime.timezone.utc)
330332
if (
331333
single_response.certificate_status == ocsp.OCSPCertStatus.GOOD
332334
and single_response.serial_number == req.serial_number
333335
and single_response.issuer_key_hash == req.issuer_key_hash
334336
and single_response.issuer_name_hash == req.issuer_name_hash
337+
and single_response.this_update_utc is not None
338+
and now + _ChainVerifier.MAX_SKEW >= single_response.this_update_utc
339+
and single_response.next_update_utc is not None
340+
and single_response.next_update_utc >= now - _ChainVerifier.MAX_SKEW
335341
):
336342
# Success
337343
return

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies = [
1818
"attrs>=21.3.0",
1919
"PyJWT>=2.6.0,<3",
2020
"requests>=2.28.0,<3",
21-
"cryptography>=40.0.0",
21+
"cryptography>=43.0.0",
2222
"pyOpenSSL>=23.1.1",
2323
"asn1==3.2.0",
2424
"cattrs>=23.1.2",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
attrs >= 21.3.0
22
PyJWT >= 2.6.0, < 3
33
requests >= 2.28.0, < 3
4-
cryptography >= 40.0.0
4+
cryptography >= 43.0.0
55
pyOpenSSL >= 23.1.1
66
asn1==3.2.0
77
cattrs >= 23.1.2

0 commit comments

Comments
 (0)