Skip to content

Commit ff5f1b8

Browse files
committed
add support for Context.set_cert_store
1 parent 24ad5be commit ff5f1b8

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- {VERSION: "3.9", TOXENV: "py39-cryptographyMain"}
2626
- {VERSION: "3.10", TOXENV: "py310-cryptographyMain"}
2727
- {VERSION: "3.11", TOXENV: "py311-cryptographyMain"}
28+
- {VERSION: "3.11", TOXENV: "py311-cryptography40"}
2829
- {VERSION: "pypy-3.8", TOXENV: "pypy3-cryptographyMain"}
2930
- {VERSION: "pypy-3.9", TOXENV: "pypy3-cryptographyMain"}
3031
# -cryptographyMinimum

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Changes:
1717
^^^^^^^^
1818

1919
- Invalid versions are now rejected in ``OpenSSL.crypto.X509Req.set_version``.
20+
- Added ``Context.set_cert_store`` `#1210 <https://github.com/pyca/pyopenssl/pull/1210>`_.
2021

2122
23.1.1 (2023-03-28)
2223
-------------------

src/OpenSSL/SSL.py

+18
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,24 @@ def get_cert_store(self):
13991399
pystore._store = store
14001400
return pystore
14011401

1402+
def set_cert_store(self, store):
1403+
"""
1404+
Set the certificate store for the context.
1405+
:param store: A X509Store object.
1406+
:return: None
1407+
"""
1408+
try:
1409+
_lib.SSL_CTX_set_cert_store(self._context, store._store)
1410+
# The store is now owned by the context, so we need to
1411+
# remove the gc free in the object. We do this after the
1412+
# set since set may not exist.
1413+
_ffi.gc(store._store, None)
1414+
except AttributeError:
1415+
# This can be removed when we depend on >= 40.0.2
1416+
raise NotImplementedError(
1417+
"cryptography must be updated to call this method"
1418+
)
1419+
14021420
def set_options(self, options):
14031421
"""
14041422
Add options. Options set before are not cleared!

tests/test_ssl.py

+9
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,15 @@ def test_get_cert_store(self):
17161716
store = context.get_cert_store()
17171717
assert isinstance(store, X509Store)
17181718

1719+
def test_set_cert_store(self):
1720+
context = Context(SSLv23_METHOD)
1721+
try:
1722+
store = X509Store()
1723+
context.set_cert_store(store)
1724+
assert store._store == context.get_cert_store()._store
1725+
except NotImplementedError:
1726+
pass
1727+
17191728
def test_set_tlsext_use_srtp_not_bytes(self):
17201729
"""
17211730
`Context.set_tlsext_use_srtp' enables negotiating SRTP keying material.

tox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ extras =
1919
deps =
2020
coverage>=4.2
2121
cryptographyMinimum: cryptography==38.0.0
22+
# special version to test paths for bindings we temporarily removed
23+
cryptography40: cryptography==40.0.1
2224
randomorder: pytest-randomly
2325
setenv =
2426
# Do not allow the executing environment to pollute the test environment

0 commit comments

Comments
 (0)