Skip to content

Commit 1cafac4

Browse files
authored
Add support for X509_V_FLAG_PARTIAL_CHAIN (#1166)
* Add support for X509_V_FLAG_PARTIAL_CHAIN * Remove unneeded import * Update changelog to add PR number. * Fix whitespace issue identified by black
1 parent 81c9eb1 commit 1cafac4

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Deprecations:
1616
Changes:
1717
^^^^^^^^
1818

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

2023
22.1.0 (2022-09-25)
2124
-------------------

doc/api/crypto.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ X509StoreFlags constants
149149
.. data:: INHIBIT_MAP
150150
.. data:: NOTIFY_POLICY
151151
.. data:: CHECK_SS_SIGNATURE
152+
.. data:: PARTIAL_CHAIN
152153

153154
.. _openssl-x509storeflags:
154155

src/OpenSSL/crypto.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,7 @@ class X509StoreFlags:
16111611
INHIBIT_MAP: int = _lib.X509_V_FLAG_INHIBIT_MAP
16121612
NOTIFY_POLICY: int = _lib.X509_V_FLAG_NOTIFY_POLICY
16131613
CHECK_SS_SIGNATURE: int = _lib.X509_V_FLAG_CHECK_SS_SIGNATURE
1614+
PARTIAL_CHAIN: int = _lib.X509_V_FLAG_PARTIAL_CHAIN
16141615

16151616

16161617
class X509Store:

tests/test_crypto.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4285,6 +4285,19 @@ def test_verify_failure_with_empty_ca_directory(self, tmpdir):
42854285

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

4288+
def test_verify_with_partial_chain(self):
4289+
store = X509Store()
4290+
store.add_cert(self.intermediate_cert)
4291+
4292+
store_ctx = X509StoreContext(store, self.intermediate_server_cert)
4293+
with pytest.raises(X509StoreContextError):
4294+
store_ctx.verify_certificate()
4295+
4296+
# Now set the partial verification flag for verification.
4297+
store.set_flags(X509StoreFlags.PARTIAL_CHAIN)
4298+
store_ctx = X509StoreContext(store, self.intermediate_server_cert)
4299+
assert store_ctx.verify_certificate() is None
4300+
42884301

42894302
class TestSignVerify:
42904303
"""

0 commit comments

Comments
 (0)