-
Notifications
You must be signed in to change notification settings - Fork 180
Use cryptography cert validation instead of PyOpenSSL #246
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
base: master
Are you sure you want to change the base?
Conversation
Hey @bluetech sorry to leave you hanging for so long. Thank you for the POC PR! I wonder, would using cryptography for X.509 validation mean this project could drop
Since you submitted this PR I managed to get rid of a lot of the mock cert validation in PR #247. It required writing a very bespoke decorator for any tests with expired certs, so if cryptography makes that easier too then I'd be interested to look more into this when it gets updated.
iirc that response was generated by an Android dev colleague internally. I had to test against it for #241 because I couldn't generate such responses on my own with the Android devices I have on hand. If this test (and probably |
Thanks for taking a look.
Yes!
Yes, the cryptography API allows passing the current time as a parameter so mocking isn't needed.
That would be helpful. The I am watching the cryptography repo. I will update the PR once they release this feature. |
It looks like custom extension policies have shipped with cryptography 45 last week. Would love to see this land 😃 |
Since cryptography version 45, there is sufficient support in cryptography itself to perform the needed certificate chain validation for attestations. This is preferable to using PyOpenSSL: - One less dependency - Can specify the verification time directly in tests without mocking or patching.
e6cfd95
to
c70d388
Compare
I updated the PR: rebased and updates the cryptography dependency. The two things remaining are:
|
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