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

Add support for X509_V_FLAG_PARTIAL_CHAIN #1166

Merged
merged 4 commits into from Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -16,6 +16,9 @@ Deprecations:
Changes:
^^^^^^^^

- Add ``OpenSSL.SSL.X509StoreFlags.PARTIAL_CHAIN`` constant to allow for users
to perform certificate verification on partial certificate chains.
`#1166 <https://github.com/pyca/pyopenssl/pull/1166>`_

22.1.0 (2022-09-25)
-------------------
Expand Down
1 change: 1 addition & 0 deletions doc/api/crypto.rst
Expand Up @@ -149,6 +149,7 @@ X509StoreFlags constants
.. data:: INHIBIT_MAP
.. data:: NOTIFY_POLICY
.. data:: CHECK_SS_SIGNATURE
.. data:: PARTIAL_CHAIN

.. _openssl-x509storeflags:

Expand Down
1 change: 1 addition & 0 deletions src/OpenSSL/crypto.py
Expand Up @@ -1611,6 +1611,7 @@ class X509StoreFlags:
INHIBIT_MAP: int = _lib.X509_V_FLAG_INHIBIT_MAP
NOTIFY_POLICY: int = _lib.X509_V_FLAG_NOTIFY_POLICY
CHECK_SS_SIGNATURE: int = _lib.X509_V_FLAG_CHECK_SS_SIGNATURE
PARTIAL_CHAIN: int = _lib.X509_V_FLAG_PARTIAL_CHAIN


class X509Store:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_crypto.py
Expand Up @@ -4285,6 +4285,19 @@ def test_verify_failure_with_empty_ca_directory(self, tmpdir):

assert str(exc.value) == "unable to get local issuer certificate"

def test_verify_with_partial_chain(self):
store = X509Store()
store.add_cert(self.intermediate_cert)

store_ctx = X509StoreContext(store, self.intermediate_server_cert)
with pytest.raises(X509StoreContextError):
store_ctx.verify_certificate()

# Now set the partial verification flag for verification.
store.set_flags(X509StoreFlags.PARTIAL_CHAIN)
store_ctx = X509StoreContext(store, self.intermediate_server_cert)
assert store_ctx.verify_certificate() is None


class TestSignVerify:
"""
Expand Down