Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out how to specify a datetime during attestation verification tests #247

Merged
merged 7 commits into from
Feb 21, 2025

Conversation

MasterKale
Copy link
Collaborator

There's been a long-standing TODO within attestation-specific unittests to figure out how to specify the time so that x5c certificate validation can succeed even after a certificate in the chain has expired. To date the tests patched the actual "verify cert chain" call to simply return True because otherwise most tests would fail with "certificate expired"-like errors. This obscured detection of other potential issues with the X.509 certificates, though, and so I've always wanted to find a better solution.

This issue rose to the top recently while addressing #243. I decided to take another look at potential solutions when I stumbled upon pyca/pyopenssl#735. This called out the set_time() method available on instances of pyOpenSSL's X509Store. After some trial and error, I settled on a pattern to enable specifying a datetime in the past, to a time between all cert's notBefore and notAfter values.

This PR adds a new webauthn.helpers.validate_certificate_chain._generate_new_cert_store method that can be patched using unittest.mock.patch to return a custom X509Store instance with a fixed datetime.datetime. Related TODOs in unittests have been updated to leverage this new-found capability and ultimately increase confidence in existing attestation tests.

@MasterKale MasterKale merged commit f0be733 into master Feb 21, 2025
5 checks passed
@MasterKale MasterKale deleted the fix/frozen-datetimes-during-x509-checks branch February 21, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant