mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
(Merge 3.1) Issue #12012: ssl.PROTOCOL_SSLv2 becomes optional
OpenSSL is now compiled with OPENSSL_NO_SSL2 defined (without the SSLv2 protocol) on Debian: fix the ssl module on Debian Testing and Debian Sid. Optimize also ssl.get_protocol_name(): speed does matter!
This commit is contained in:
parent
2c585f607e
commit
b1241f9619
5 changed files with 52 additions and 34 deletions
|
@ -58,32 +58,35 @@ class BasicTests(unittest.TestCase):
|
|||
|
||||
# Issue #9415: Ubuntu hijacks their OpenSSL and forcefully disables SSLv2
|
||||
def skip_if_broken_ubuntu_ssl(func):
|
||||
# We need to access the lower-level wrapper in order to create an
|
||||
# implicit SSL context without trying to connect or listen.
|
||||
try:
|
||||
import _ssl
|
||||
except ImportError:
|
||||
# The returned function won't get executed, just ignore the error
|
||||
pass
|
||||
@functools.wraps(func)
|
||||
def f(*args, **kwargs):
|
||||
if hasattr(ssl, 'PROTOCOL_SSLv2'):
|
||||
# We need to access the lower-level wrapper in order to create an
|
||||
# implicit SSL context without trying to connect or listen.
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET)
|
||||
_ssl.sslwrap(s._sock, 0, None, None,
|
||||
ssl.CERT_NONE, ssl.PROTOCOL_SSLv2, None, None)
|
||||
except ssl.SSLError as e:
|
||||
if (ssl.OPENSSL_VERSION_INFO == (0, 9, 8, 15, 15) and
|
||||
platform.linux_distribution() == ('debian', 'squeeze/sid', '')
|
||||
and 'Invalid SSL protocol variant specified' in str(e)):
|
||||
raise unittest.SkipTest("Patched Ubuntu OpenSSL breaks behaviour")
|
||||
return func(*args, **kwargs)
|
||||
return f
|
||||
import _ssl
|
||||
except ImportError:
|
||||
# The returned function won't get executed, just ignore the error
|
||||
pass
|
||||
@functools.wraps(func)
|
||||
def f(*args, **kwargs):
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET)
|
||||
_ssl.sslwrap(s._sock, 0, None, None,
|
||||
ssl.CERT_NONE, ssl.PROTOCOL_SSLv2, None, None)
|
||||
except ssl.SSLError as e:
|
||||
if (ssl.OPENSSL_VERSION_INFO == (0, 9, 8, 15, 15) and
|
||||
platform.linux_distribution() == ('debian', 'squeeze/sid', '')
|
||||
and 'Invalid SSL protocol variant specified' in str(e)):
|
||||
raise unittest.SkipTest("Patched Ubuntu OpenSSL breaks behaviour")
|
||||
return func(*args, **kwargs)
|
||||
return f
|
||||
else:
|
||||
return func
|
||||
|
||||
|
||||
class BasicSocketTests(unittest.TestCase):
|
||||
|
||||
def test_constants(self):
|
||||
ssl.PROTOCOL_SSLv2
|
||||
#ssl.PROTOCOL_SSLv2
|
||||
ssl.PROTOCOL_SSLv23
|
||||
ssl.PROTOCOL_SSLv3
|
||||
ssl.PROTOCOL_TLSv1
|
||||
|
@ -1008,7 +1011,8 @@ else:
|
|||
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, True)
|
||||
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, True, ssl.CERT_OPTIONAL)
|
||||
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, True, ssl.CERT_REQUIRED)
|
||||
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv2, False)
|
||||
if hasattr(ssl, 'PROTOCOL_SSLv2'):
|
||||
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv2, False)
|
||||
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv23, False)
|
||||
try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_TLSv1, False)
|
||||
|
||||
|
@ -1020,7 +1024,8 @@ else:
|
|||
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1, True)
|
||||
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1, True, ssl.CERT_OPTIONAL)
|
||||
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1, True, ssl.CERT_REQUIRED)
|
||||
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv2, False)
|
||||
if hasattr(ssl, 'PROTOCOL_SSLv2'):
|
||||
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv2, False)
|
||||
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv3, False)
|
||||
try_protocol_combo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv23, False)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue