Skip to content

Commit 45c535f

Browse files
committed
Add support for X509_V_FLAG_PARTIAL_CHAIN
1 parent 6c0772a commit 45c535f

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ 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.
1921

2022
22.1.0 (2022-09-25)
2123
-------------------

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
@@ -10,6 +10,7 @@
1010
from subprocess import PIPE, Popen
1111
from warnings import simplefilter
1212

13+
import OpenSSL.crypto
1314
from cryptography import x509
1415
from cryptography.hazmat.primitives import serialization
1516
from cryptography.hazmat.primitives.asymmetric import ec, ed25519, ed448, rsa
@@ -4285,6 +4286,18 @@ def test_verify_failure_with_empty_ca_directory(self, tmpdir):
42854286

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

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

42894302
class TestSignVerify:
42904303
"""

0 commit comments

Comments
 (0)