Skip to content

Commit a9dcdab

Browse files
committed
always set OP_NO_SSLv3 by default (closes #25530)
1 parent eda06c8 commit a9dcdab

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Lib/test/test_ssl.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,12 @@ def test_ciphers(self):
674674
@skip_if_broken_ubuntu_ssl
675675
def test_options(self):
676676
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
677-
# OP_ALL | OP_NO_SSLv2 is the default value
678-
self.assertEqual(ssl.OP_ALL | ssl.OP_NO_SSLv2,
679-
ctx.options)
680-
ctx.options |= ssl.OP_NO_SSLv3
677+
# OP_ALL | OP_NO_SSLv2 | OP_NO_SSLv3 is the default value
681678
self.assertEqual(ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3,
682679
ctx.options)
680+
ctx.options |= ssl.OP_NO_TLSv1
681+
self.assertEqual(ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_NO_TLSv1,
682+
ctx.options)
683683
if can_clear_options():
684684
ctx.options = (ctx.options & ~ssl.OP_NO_SSLv2) | ssl.OP_NO_TLSv1
685685
self.assertEqual(ssl.OP_ALL | ssl.OP_NO_TLSv1 | ssl.OP_NO_SSLv3,
@@ -2172,17 +2172,17 @@ def test_protocol_sslv23(self):
21722172
" SSL2 client to SSL23 server test unexpectedly failed:\n %s\n"
21732173
% str(x))
21742174
if hasattr(ssl, 'PROTOCOL_SSLv3'):
2175-
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv3, True)
2175+
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv3, False)
21762176
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv23, True)
21772177
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1, True)
21782178

21792179
if hasattr(ssl, 'PROTOCOL_SSLv3'):
2180-
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv3, True, ssl.CERT_OPTIONAL)
2180+
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv3, False, ssl.CERT_OPTIONAL)
21812181
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv23, True, ssl.CERT_OPTIONAL)
21822182
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1, True, ssl.CERT_OPTIONAL)
21832183

21842184
if hasattr(ssl, 'PROTOCOL_SSLv3'):
2185-
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv3, True, ssl.CERT_REQUIRED)
2185+
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv3, False, ssl.CERT_REQUIRED)
21862186
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv23, True, ssl.CERT_REQUIRED)
21872187
try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1, True, ssl.CERT_REQUIRED)
21882188

@@ -2214,8 +2214,8 @@ def test_protocol_sslv3(self):
22142214
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_TLSv1, False)
22152215
if no_sslv2_implies_sslv3_hello():
22162216
# No SSLv2 => client will use an SSLv3 hello on recent OpenSSLs
2217-
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv23, True,
2218-
client_options=ssl.OP_NO_SSLv2)
2217+
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv23,
2218+
False, client_options=ssl.OP_NO_SSLv2)
22192219

22202220
@skip_if_broken_ubuntu_ssl
22212221
def test_protocol_tlsv1(self):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ Library
107107
at the end if the FileInput was opened with binary mode.
108108
Patch by Ryosuke Ito.
109109

110+
- Issue #25530: Disable the vulnerable SSLv3 protocol by default when creating
111+
ssl.SSLContext.
112+
110113
- Issue #25569: Fix memory leak in SSLSocket.getpeercert().
111114

112115
- Issue #21827: Fixed textwrap.dedent() for the case when largest common

Modules/_ssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,8 @@ context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20372037
options = SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
20382038
if (proto_version != PY_SSL_VERSION_SSL2)
20392039
options |= SSL_OP_NO_SSLv2;
2040+
if (proto_version != PY_SSL_VERSION_SSL3)
2041+
options |= SSL_OP_NO_SSLv3;
20402042
SSL_CTX_set_options(self->ctx, options);
20412043

20422044
#ifndef OPENSSL_NO_ECDH

0 commit comments

Comments
 (0)