Skip to content

Commit 5f46403

Browse files
authored
Added OpenSSL.SSL.Connection.set_info_callback (#1438)
1 parent 95cf8fa commit 5f46403

File tree

5 files changed

+57
-17
lines changed

5 files changed

+57
-17
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,24 @@ Changelog
33

44
Versions are year-based with a strict backward-compatibility policy.
55
The third digit is only for regressions.
6-
UNRELEASED
7-
----------
8-
9-
Backward-incompatible changes:
10-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11-
12-
Deprecations:
13-
^^^^^^^^^^^^^
14-
15-
Changes:
16-
^^^^^^^^
17-
18-
- Added ``OpenSSL.SSL.Context.set_tls13_ciphersuites`` that allows the allowed TLS 1.3 ciphers.
196

207
25.2.0 (UNRELEASED)
218
-------------------
229

2310
Backward-incompatible changes:
2411
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2512

26-
pyOpenSSL now sets SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER by default, matching CPython's behavior. #1287.
27-
The minimum cryptography version is now 42.0.0.
13+
- The minimum ``cryptography`` version is now 45.0.7.
2814

2915
Deprecations:
3016
^^^^^^^^^^^^^
3117

3218
Changes:
3319
^^^^^^^^
3420

21+
- pyOpenSSL now sets ``SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER`` by default, matching CPython's behavior.
22+
- Added ``OpenSSL.SSL.Context.set_tls13_ciphersuites`` that allows the allowed TLS 1.3 ciphers.
23+
- Added ``OpenSSL.SSL.Connection.set_info_callback``
3524

3625
25.1.0 (2025-05-17)
3726
-------------------

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
nox.options.reuse_existing_virtualenvs = True
44
nox.options.default_venv_backend = "uv|virtualenv"
55

6-
MINIMUM_CRYPTOGRAPHY_VERSION = "41.0.5"
6+
MINIMUM_CRYPTOGRAPHY_VERSION = "45.0.7"
77

88

99
@nox.session

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def find_meta(meta):
9494
packages=find_packages(where="src"),
9595
package_dir={"": "src"},
9696
install_requires=[
97-
"cryptography>=42.0.0,<46",
97+
"cryptography>=45.0.7,<46",
9898
(
9999
"typing-extensions>=4.9; "
100100
"python_version < '3.13' and python_version >= '3.8'"

src/OpenSSL/SSL.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,3 +3213,27 @@ def request_ocsp(self) -> None:
32133213
self._ssl, _lib.TLSEXT_STATUSTYPE_ocsp
32143214
)
32153215
_openssl_assert(rc == 1)
3216+
3217+
def set_info_callback(
3218+
self, callback: Callable[[Connection, int, int], None]
3219+
) -> None:
3220+
"""
3221+
Set the information callback to *callback*. This function will be
3222+
called from time to time during SSL handshakes.
3223+
3224+
:param callback: The Python callback to use. This should take three
3225+
arguments: a Connection object and two integers. The first integer
3226+
specifies where in the SSL handshake the function was called, and
3227+
the other the return code from a (possibly failed) internal
3228+
function call.
3229+
:return: None
3230+
"""
3231+
3232+
@wraps(callback)
3233+
def wrapper(ssl, where, return_code): # type: ignore[no-untyped-def]
3234+
callback(Connection._reverse_mapping[ssl], where, return_code)
3235+
3236+
self._info_callback = _ffi.callback(
3237+
"void (*)(const SSL *, int, int)", wrapper
3238+
)
3239+
_lib.SSL_set_info_callback(self._ssl, self._info_callback)

tests/test_ssl.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3473,6 +3473,33 @@ def test_buffer_size(self) -> None:
34733473
data = conn.bio_read(2)
34743474
assert 2 == len(data)
34753475

3476+
def test_connection_set_info_callback(self) -> None:
3477+
(server_sock, client_sock) = socket_pair()
3478+
3479+
context = Context(SSLv23_METHOD)
3480+
context.use_certificate(load_certificate(FILETYPE_PEM, root_cert_pem))
3481+
context.use_privatekey(load_privatekey(FILETYPE_PEM, root_key_pem))
3482+
server = Connection(context, server_sock)
3483+
server.set_accept_state()
3484+
3485+
client = Connection(Context(SSLv23_METHOD), client_sock)
3486+
client.set_connect_state()
3487+
3488+
called = []
3489+
3490+
def info(conn: Connection, where: int, ret: int) -> None:
3491+
assert conn is client
3492+
called.append(where)
3493+
3494+
client.set_info_callback(info)
3495+
3496+
handshake(client, server)
3497+
3498+
# Verify that the callback was actually called during handshake
3499+
assert len(called) > 0
3500+
assert SSL_CB_HANDSHAKE_START in called
3501+
assert SSL_CB_HANDSHAKE_DONE in called
3502+
34763503

34773504
class TestConnectionGetCipherList:
34783505
"""

0 commit comments

Comments
 (0)