diff options
| author | Benjamin Peterson <benjamin@python.org> | 2014-10-02 03:53:01 (GMT) |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2014-10-02 03:53:01 (GMT) |
| commit | 2f33456e41330abdd0e818802665a4e0091626a2 (patch) | |
| tree | 757d97b750e39b5e63f471cccf4a3beea3f86dbd /Lib | |
| parent | 0d377b371d8ec8bd538ed7325000e815d02cb03b (diff) | |
| download | cpython-2f33456e41330abdd0e818802665a4e0091626a2.zip cpython-2f33456e41330abdd0e818802665a4e0091626a2.tar.gz cpython-2f33456e41330abdd0e818802665a4e0091626a2.tar.bz2 | |
fix sslwrap_simple (closes #22523)
Thanks Alex Gaynor.
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/ssl.py | 8 | ||||
| -rw-r--r-- | Lib/test/test_ssl.py | 4 |
2 files changed, 7 insertions, 5 deletions
@@ -969,16 +969,16 @@ def get_protocol_name(protocol_code): # a replacement for the old socket.ssl function def sslwrap_simple(sock, keyfile=None, certfile=None): - """A replacement for the old socket.ssl function. Designed for compability with Python 2.5 and earlier. Will disappear in Python 3.0.""" - if hasattr(sock, "_sock"): sock = sock._sock - ssl_sock = _ssl.sslwrap(sock, 0, keyfile, certfile, CERT_NONE, - PROTOCOL_SSLv23, None) + ctx = SSLContext(PROTOCOL_SSLv23) + if keyfile or certfile: + ctx.load_cert_chain(certfile, keyfile) + ssl_sock = ctx._wrap_socket(sock, server_side=False) try: sock.getpeername() except socket_error: diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index eac994f..75bb1e0 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -94,6 +94,8 @@ class BasicTests(unittest.TestCase): pass else: raise + + def can_clear_options(): # 0.9.8m or higher return ssl._OPENSSL_API_VERSION >= (0, 9, 8, 13, 15) @@ -2944,7 +2946,7 @@ def test_main(verbose=False): if not os.path.exists(filename): raise support.TestFailed("Can't read certificate file %r" % filename) - tests = [ContextTests, BasicSocketTests, SSLErrorTests] + tests = [ContextTests, BasicTests, BasicSocketTests, SSLErrorTests] if support.is_resource_enabled('network'): tests.append(NetworkedTests) |
