[POC][WIP] Use cryptography cert validation instead of PyOpenSSL #246
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.
The cryptography package in version 42 added support for certificate validation. I had in mind to use it in py_webauthn to replace the pyOpenSSL dependency, which seems beneficial to me given py_webauthn already depends on cryptography.
However it turned out that the initial support wasn't sufficient. But in current git (not yet released), cryptography extended the API to allow for custom extension policies, which make it possible to use in py_webauthn. This PR is a proof of concept of this.
Some notes:
This will only be usable once cryptography makes the next release. For now, I've used the wheel from here for testing.
Even then, the cert verification API is still marked experimental so is subject to change.
I haven't looked closely at hardening the verification policy. We should at least match what pyOpenSSL checks. I think that py_webauthn does verify the extensions itself though.
A lot of the tests rely on monkeypatching to mock out the verification because the certificates in the test had expired. But the cryptograhpy API accepts a time parameter, allowing to fix the time for the test and have the verification succeed without monkeypatching. I have added a
time
parameter to the public API (with default now) as it seems very useful to me.There is a problem with one of the tests,
tests/test_verify_registration_response_android_safetynet.py::TestVerifyRegistrationResponseAndroidSafetyNet::test_verify_attestation_android_safetynet_basic_integrity_true_cts_profile_match_false
. This test is using an X509 v1 certificate, but cryptography only supports v3 certificates. I am not sure if this cert is realistic or was generated just for the test.Here is the cert:
Details