]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix for release blocker 3910, 2.6 regression in socket.ssl method
authorBill Janssen <janssen@parc.com>
Mon, 29 Sep 2008 18:56:38 +0000 (18:56 +0000)
committerBill Janssen <janssen@parc.com>
Mon, 29 Sep 2008 18:56:38 +0000 (18:56 +0000)
Lib/ssl.py
Lib/test/test_ssl.py

index 8a799bcc56743ba6d80209189e374812f55ff15b..21ae4053750f0cf84d24783d6e2864a30961f34d 100644 (file)
@@ -434,7 +434,18 @@ def sslwrap_simple (sock, keyfile=None, certfile=None):
     for compability with Python 2.5 and earlier.  Will disappear in
     Python 3.0."""
 
-    ssl_sock = _ssl.sslwrap(sock._sock, 0, keyfile, certfile, CERT_NONE,
+    if hasattr(sock, "_sock"):
+        sock = sock._sock
+
+    ssl_sock = _ssl.sslwrap(sock, 0, keyfile, certfile, CERT_NONE,
                             PROTOCOL_SSLv23, None)
-    ssl_sock.do_handshake()
+    try:
+        sock.getpeername()
+    except:
+        # no, no connection yet
+        pass
+    else:
+        # yes, do the handshake
+        ssl_sock.do_handshake()
+
     return ssl_sock
index 98681f4fe13b7169aba755f47f8391da1933d2e3..5cfe7f14dbc6937ec448fb492ab71941144b246c 100644 (file)
@@ -34,6 +34,21 @@ def handle_error(prefix):
     if test_support.verbose:
         sys.stdout.write(prefix + exc_format)
 
+    def testSimpleSSLwrap(self):
+        try:
+            ssl.sslwrap_simple(socket.socket(socket.AF_INET))
+        except IOError, e:
+            if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that
+                pass
+            else:
+                raise
+        try:
+            ssl.sslwrap_simple(socket.socket(socket.AF_INET)._sock)
+        except IOError, e:
+            if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that
+                pass
+            else:
+                raise
 
 class BasicTests(unittest.TestCase):
 
@@ -58,7 +73,6 @@ class BasicTests(unittest.TestCase):
         finally:
             s.close()
 
-
     def testCrucialConstants(self):
         ssl.PROTOCOL_SSLv2
         ssl.PROTOCOL_SSLv23