Remove pyopenssl usage from certdir (SYN-7712)#4867
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4867 +/- ##
=======================================
Coverage 97.72% 97.73%
=======================================
Files 298 298
Lines 62831 62865 +34
=======================================
+ Hits 61404 61441 +37
+ Misses 1427 1424 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add coverage
invisig0th
requested changes
Apr 8, 2026
Contributor
invisig0th
left a comment
There was a problem hiding this comment.
Looks really solid. A couple of style nits ;)
MichaelSquires
requested changes
Apr 8, 2026
…ince a certificate without a CN would raise an IndexError. Update _verifyChain error messages to include the subject field for certificates presenting issues.
MichaelSquires
previously approved these changes
Apr 8, 2026
MichaelSquires
previously approved these changes
Apr 8, 2026
Cisphyx
previously approved these changes
Apr 8, 2026
vEpiphyte
commented
Apr 9, 2026
…itical extensions that we do not handle cause the certificate to be rejected.
invisig0th
approved these changes
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Remove the
pyOpenSSLdependency and replace all certificate chain verification with a custom_verifyChain()implementation using thecryptographylibrary directly. Thecryptographydependency has been updated to>=46.0.7,<47.0.0.pyOpenSSLX509Store/X509StoreContextusage inCrl._verify(),valCodeCert(), andvalUserCert()with_verifyChain()and_verifyCertSignature()_verifyCertSignature()usesCertificate.verify_directly_issued_by()for combined issuer name and signature verificationCertDir.valUserCert()API (no production callers)_getCertName()helper to guard against certificates missing a Common Name subject fieldVerification improvements over pyOpenSSL
_verifyChainare rejected. Handled critical extensions:BasicConstraints,ExtendedKeyUsage.verify_directly_issued_by--_verifyChainmatches issuers by both subject name AND cryptographic signature in one operation, improving robustness when multiple CAs share the same CN._verifyCertSignature()with a clear error for unsupported key typesBadCertBytesinstead of rawIndexErrorissuer != subjectis not treated as a root and fails chain verificationFiles changed
synapse/lib/certdir.py_verifyCertSignature(),_verifyChain(),_getCertName(), rewriteCrl._verify()andvalCodeCert(), removevalUserCert()and_unpackContextError()synapse/tests/test_lib_certdir.pybasic_assertions(), add 27 new adversarial/edge-case testssynapse/tests/test_tools_docker_validate.pycheckCRLwith invalid datasynapse/tools/docker/validate.pyrequirements.txtpyOpenSSL, updatecryptographyto>=46.0.7,<47.0.0pyproject.tomlTest plan
python -m pytest synapse/tests/test_lib_certdir.py -v-- 38 tests passpython -m pytest synapse/tests/test_tools_docker_validate.py -vvalUserCerthas no regressions.