Skip to content

Commit 6a44507

Browse files
committed
Fix for problem caused by SSL_WANT_READ or SSL_WANT_WRITE errors.
When SSL_WANT_READ or SSL_WANT_WRITE are encountered, it's typical to retry the call but this must be repeated with the exact same arguments. Without this change, openSSL requires that the address of the buffer passed is the same. However, buffers in python can change location in some circumstances which cause the retry to fail. By add the setting SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER, the requirement for the same buffer address is forgiven and the retry has a better chance of success. See cherrypy/cheroot#245 for discussion.
1 parent 1508c4b commit 6a44507

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

CHANGELOG.rst

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ Changelog
44
Versions are year-based with a strict backward-compatibility policy.
55
The third digit is only for regressions.
66

7+
24.1.0 (UNRELEASED)
8+
-------------------
9+
10+
Backward-incompatible changes:
11+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
- ``pyOpenSSL`` now sets ``SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER`` by default, matching CPython's behavior. `#1287 <https://github.com/pyca/pyopenssl/pull/1287>`_.
14+
- The minimum ``cryptography`` version is now 42.0.0.
15+
16+
Deprecations:
17+
^^^^^^^^^^^^^
18+
19+
Changes:
20+
^^^^^^^^
21+
22+
23+
724
24.0.0 (2024-01-22)
825
-------------------
926

setup.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ def find_meta(meta):
9393
packages=find_packages(where="src"),
9494
package_dir={"": "src"},
9595
install_requires=[
96-
"cryptography>=41.0.5,<43",
96+
<<<<<<< HEAD
97+
"cryptography>=42.0.0,<43",
98+
=======
99+
"cryptography>=41.0.5,<43",
100+
>>>>>>> 9208a11 (resolved conflicts)
97101
],
98102
extras_require={
99103
"test": ["flaky", "pretend", "pytest>=3.0.1"],

src/OpenSSL/SSL.py

+9-16
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,11 @@
163163
DTLS_SERVER_METHOD = 11
164164
DTLS_CLIENT_METHOD = 12
165165

166-
try:
167-
SSL3_VERSION = _lib.SSL3_VERSION
168-
TLS1_VERSION = _lib.TLS1_VERSION
169-
TLS1_1_VERSION = _lib.TLS1_1_VERSION
170-
TLS1_2_VERSION = _lib.TLS1_2_VERSION
171-
TLS1_3_VERSION = _lib.TLS1_3_VERSION
172-
except AttributeError:
173-
# Hardcode constants for cryptography < 3.4, see
174-
# https://github.com/pyca/pyopenssl/pull/985#issuecomment-775186682
175-
SSL3_VERSION = 768
176-
TLS1_VERSION = 769
177-
TLS1_1_VERSION = 770
178-
TLS1_2_VERSION = 771
179-
TLS1_3_VERSION = 772
166+
SSL3_VERSION = _lib.SSL3_VERSION
167+
TLS1_VERSION = _lib.TLS1_VERSION
168+
TLS1_1_VERSION = _lib.TLS1_1_VERSION
169+
TLS1_2_VERSION = _lib.TLS1_2_VERSION
170+
TLS1_3_VERSION = _lib.TLS1_3_VERSION
180171

181172
OP_NO_SSLv2 = _lib.SSL_OP_NO_SSLv2
182173
OP_NO_SSLv3 = _lib.SSL_OP_NO_SSLv3
@@ -864,8 +855,10 @@ def __init__(self, method):
864855
self._ocsp_data = None
865856
self._cookie_generate_helper = None
866857
self._cookie_verify_helper = None
867-
868-
self.set_mode(_lib.SSL_MODE_ENABLE_PARTIAL_WRITE)
858+
self.set_mode(
859+
_lib.SSL_MODE_ENABLE_PARTIAL_WRITE
860+
| _lib.SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
861+
)
869862
if version is not None:
870863
self.set_min_proto_version(version)
871864
self.set_max_proto_version(version)

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extras =
1818
test
1919
deps =
2020
coverage>=4.2
21-
cryptographyMinimum: cryptography==41.0.5
21+
cryptographyMinimum: cryptography==42.0.0
2222
randomorder: pytest-randomly
2323
setenv =
2424
# Do not allow the executing environment to pollute the test environment

0 commit comments

Comments
 (0)