mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-94199: Remove the ssl.wrap_socket() function (#94203)
Remove the ssl.wrap_socket() function, deprecated in Python 3.7: instead, create a ssl.SSLContext object and call its sl.SSLContext.wrap_socket() method. Any package that still uses ssl.wrap_socket() is broken and insecure. The function neither sends a SNI TLS extension nor validates server hostname. Code is subject to CWE-295 : Improper Certificate Validation.
This commit is contained in:
parent
23ee4a8067
commit
00464bbed6
4 changed files with 16 additions and 60 deletions
|
@ -629,36 +629,6 @@ class BasicSocketTests(unittest.TestCase):
|
|||
str(cm.warning)
|
||||
)
|
||||
|
||||
@ignore_deprecation
|
||||
def test_errors_sslwrap(self):
|
||||
sock = socket.socket()
|
||||
self.assertRaisesRegex(ValueError,
|
||||
"certfile must be specified",
|
||||
ssl.wrap_socket, sock, keyfile=CERTFILE)
|
||||
self.assertRaisesRegex(ValueError,
|
||||
"certfile must be specified for server-side operations",
|
||||
ssl.wrap_socket, sock, server_side=True)
|
||||
self.assertRaisesRegex(ValueError,
|
||||
"certfile must be specified for server-side operations",
|
||||
ssl.wrap_socket, sock, server_side=True, certfile="")
|
||||
with ssl.wrap_socket(sock, server_side=True, certfile=CERTFILE) as s:
|
||||
self.assertRaisesRegex(ValueError, "can't connect in server-side mode",
|
||||
s.connect, (HOST, 8080))
|
||||
with self.assertRaises(OSError) as cm:
|
||||
with socket.socket() as sock:
|
||||
ssl.wrap_socket(sock, certfile=NONEXISTINGCERT)
|
||||
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
||||
with self.assertRaises(OSError) as cm:
|
||||
with socket.socket() as sock:
|
||||
ssl.wrap_socket(sock,
|
||||
certfile=CERTFILE, keyfile=NONEXISTINGCERT)
|
||||
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
||||
with self.assertRaises(OSError) as cm:
|
||||
with socket.socket() as sock:
|
||||
ssl.wrap_socket(sock,
|
||||
certfile=NONEXISTINGCERT, keyfile=NONEXISTINGCERT)
|
||||
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
||||
|
||||
def bad_cert_test(self, certfile):
|
||||
"""Check that trying to use the given client certificate fails"""
|
||||
certfile = os.path.join(os.path.dirname(__file__) or os.curdir,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue