This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ddvoinikov
Recipients ddvoinikov
Date 2008-10-22.11:37:21
SpamBayes Score 1.4559591e-06
Marked as misclassified No
Message-id <1224675444.68.0.815389836032.issue4171@psf.upfronthosting.co.za>
In-reply-to
Content
If I connect a TCP socket s using regular s.connect(), then wrap it
using ssl.wrap_socket(s) and call do_handshake on the resulting SSL
socket, handshake fails in ssl.py:320 with 

AttributeError: 'NoneType' object has no attribute 'do_handshake'

The problem is that when TCP socket is being wrapped in ssl.py:116, it
is not recognized as connected by a call to getpeername(), the exception
thrown in ssl.py:116 and silenced is this:

[Errno 10057] A request to send or receive data was disallowed because
the socket is not connected and (when sending on a datagram socket using
a sendto call) no address was supplied

This is awkward, because synchronous s.connect() has just returned
successfully. Even more weird, if I insert s.getpeername() between TCP
connect() and SSL do_handshake() the latter works fine.

Here is a working sample:

-------------------------------

from socket import socket, AF_INET, SOCK_STREAM
from ssl import wrap_socket, PROTOCOL_TLSv1, CERT_NONE

def test_handshake(address, WORKAROUND):

    s = socket(AF_INET, SOCK_STREAM)
    s.settimeout(3.0)
    s.connect(address)

    if WORKAROUND:
        s.getpeername()

    ssl = wrap_socket(s, server_side = False,
                      ssl_version = PROTOCOL_TLSv1,
                      cert_reqs = CERT_NONE,
                      do_handshake_on_connect = False)
    ssl.do_handshake()

address = ("www.amazon.com", 443)

test_handshake(address, True) # with workaround
print("worked so far")
test_handshake(address, False)
print("but not here it didn't")

-------------------------------

I'm using Python 3.0rc1 under Windows.
History
Date User Action Args
2008-10-22 11:37:24ddvoinikovsetrecipients: + ddvoinikov
2008-10-22 11:37:24ddvoinikovsetmessageid: <1224675444.68.0.815389836032.issue4171@psf.upfronthosting.co.za>
2008-10-22 11:37:22ddvoinikovlinkissue4171 messages
2008-10-22 11:37:21ddvoinikovcreate