Figure out how to specify a datetime during attestation verification tests #247
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'sX509Store
. After some trial and error, I settled on a pattern to enable specifying a datetime in the past, to a time between all cert'snotBefore
andnotAfter
values.This PR adds a new
webauthn.helpers.validate_certificate_chain._generate_new_cert_store
method that can be patched usingunittest.mock.patch
to return a customX509Store
instance with a fixeddatetime.datetime
. Related TODOs in unittests have been updated to leverage this new-found capability and ultimately increase confidence in existing attestation tests.