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 Context.set_cert_store #1210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Deprecations:
Changes:
^^^^^^^^

- Added ``Context.set_cert_store`` `#1210 <https://github.com/pyca/pyopenssl/pull/1210>`_.

23.2.0 (2023-05-30)
-------------------

Expand Down
10 changes: 10 additions & 0 deletions src/OpenSSL/SSL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,16 @@ def get_cert_store(self):
pystore._store = store
return pystore

def set_cert_store(self, store):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we added type annotations? Seems like we should start adding them as we go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for type annotations :)

"""
Set the certificate store for the context.
:param store: A X509Store object.
:return: None
"""
rc = _lib.X509_STORE_up_ref(store._store)
_openssl_assert(rc == 1)
_lib.SSL_CTX_set_cert_store(self._context, store._store)

def set_options(self, options):
"""
Add options. Options set before are not cleared!
Expand Down
6 changes: 6 additions & 0 deletions tests/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,12 @@ def test_get_cert_store(self):
store = context.get_cert_store()
assert isinstance(store, X509Store)

def test_set_cert_store(self):
context = Context(SSLv23_METHOD)
store = X509Store()
context.set_cert_store(store)
assert store._store == context.get_cert_store()._store
Comment on lines +1719 to +1723
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this test actually verify what we want?


def test_set_tlsext_use_srtp_not_bytes(self):
"""
`Context.set_tlsext_use_srtp' enables negotiating SRTP keying material.
Expand Down