Skip to content

Commit e6fd19a

Browse files
authored
Implement Context constructor in terms of new OpenSSL APIs (#1109)
1 parent 382e5e0 commit e6fd19a

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ The third digit is only for regressions.
1010
Backward-incompatible changes:
1111
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13+
- Remove support for SSLv2 and SSLv3.
14+
1315
Deprecations:
1416
^^^^^^^^^^^^^
1517

src/OpenSSL/SSL.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
"SSLEAY_BUILT_ON",
3535
"SENT_SHUTDOWN",
3636
"RECEIVED_SHUTDOWN",
37-
"SSLv2_METHOD",
38-
"SSLv3_METHOD",
3937
"SSLv23_METHOD",
4038
"TLSv1_METHOD",
4139
"TLSv1_1_METHOD",
@@ -135,8 +133,6 @@
135133
SENT_SHUTDOWN = _lib.SSL_SENT_SHUTDOWN
136134
RECEIVED_SHUTDOWN = _lib.SSL_RECEIVED_SHUTDOWN
137135

138-
SSLv2_METHOD = 1
139-
SSLv3_METHOD = 2
140136
SSLv23_METHOD = 3
141137
TLSv1_METHOD = 4
142138
TLSv1_1_METHOD = 5
@@ -680,31 +676,24 @@ class Context:
680676
"""
681677

682678
_methods = {
683-
SSLv2_METHOD: "SSLv2_method",
684-
SSLv3_METHOD: "SSLv3_method",
685-
SSLv23_METHOD: "SSLv23_method",
686-
TLSv1_METHOD: "TLSv1_method",
687-
TLSv1_1_METHOD: "TLSv1_1_method",
688-
TLSv1_2_METHOD: "TLSv1_2_method",
689-
TLS_METHOD: "TLS_method",
690-
TLS_SERVER_METHOD: "TLS_server_method",
691-
TLS_CLIENT_METHOD: "TLS_client_method",
692-
DTLS_METHOD: "DTLS_method",
693-
DTLS_SERVER_METHOD: "DTLS_server_method",
694-
DTLS_CLIENT_METHOD: "DTLS_client_method",
679+
SSLv23_METHOD: (_lib.TLS_method, None),
680+
TLSv1_METHOD: (_lib.TLS_method, TLS1_VERSION),
681+
TLSv1_1_METHOD: (_lib.TLS_method, TLS1_1_VERSION),
682+
TLSv1_2_METHOD: (_lib.TLS_method, TLS1_2_VERSION),
683+
TLS_METHOD: (_lib.TLS_method, None),
684+
TLS_SERVER_METHOD: (_lib.TLS_server_method, None),
685+
TLS_CLIENT_METHOD: (_lib.TLS_client_method, None),
686+
DTLS_METHOD: (_lib.DTLS_method, None),
687+
DTLS_SERVER_METHOD: (_lib.DTLS_server_method, None),
688+
DTLS_CLIENT_METHOD: (_lib.DTLS_client_method, None),
695689
}
696-
_methods = dict(
697-
(identifier, getattr(_lib, name))
698-
for (identifier, name) in _methods.items()
699-
if getattr(_lib, name, None) is not None
700-
)
701690

702691
def __init__(self, method):
703692
if not isinstance(method, int):
704693
raise TypeError("method must be an integer")
705694

706695
try:
707-
method_func = self._methods[method]
696+
method_func, version = self._methods[method]
708697
except KeyError:
709698
raise ValueError("No such protocol")
710699

@@ -734,6 +723,9 @@ def __init__(self, method):
734723
self._cookie_verify_helper = None
735724

736725
self.set_mode(_lib.SSL_MODE_ENABLE_PARTIAL_WRITE)
726+
if version is not None:
727+
self.set_min_proto_version(version)
728+
self.set_max_proto_version(version)
737729

738730
def set_min_proto_version(self, version):
739731
"""

tests/test_ssl.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@
9393
SSL_ST_MASK,
9494
SSLeay_version,
9595
SSLv23_METHOD,
96-
SSLv2_METHOD,
97-
SSLv3_METHOD,
9896
Session,
9997
SysCallError,
10098
TLS1_1_VERSION,
@@ -591,7 +589,7 @@ def test_method(self):
591589
for meth in methods:
592590
Context(meth)
593591

594-
maybe = [SSLv2_METHOD, SSLv3_METHOD, TLSv1_1_METHOD, TLSv1_2_METHOD]
592+
maybe = [TLSv1_1_METHOD, TLSv1_2_METHOD]
595593
for meth in maybe:
596594
try:
597595
Context(meth)

0 commit comments

Comments
 (0)