New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSL handshake fails after TCP connection in getpeername() #48421
Comments
If I connect a TCP socket s using regular s.connect(), then wrap it AttributeError: 'NoneType' object has no attribute 'do_handshake' The problem is that when TCP socket is being wrapped in ssl.py:116, it [Errno 10057] A request to send or receive data was disallowed because This is awkward, because synchronous s.connect() has just returned 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. |
I'm unable to reproduce the bug on Python 3.0 svn trunk. Can you retry |
(I tried your code on Linux and no exception is raised) |
Same thing on Python 3.0rc2: C:\TEMP>python test.py
worked so far
Traceback (most recent call last):
File "1.py", line 23, in <module>
test_handshake(address, False)
File "1.py", line 17, in test_handshake
ssl.do_handshake()
File "C:\Python30\lib\ssl.py", line 327, in do_handshake
self._sslobj.do_handshake()
AttributeError: 'NoneType' object has no attribute 'do_handshake' |
1.py == test.py obviously :) |
What happens if you remove the call to settimeout()? |
The problem does not reproduce in 3.1.1 nor in 3.1.2 Antoine Pitrou пишет:
|
Ok, so I think we can close the issue then. Thank you! |
Well, I'm sorry to bring this up again, but the problem persists worked so far and some other time I may get worked so far
Traceback (most recent call last):
File "test.py", line 23, in <module>
test_handshake(address, False)
File "test.py", line 17, in test_handshake
ssl.do_handshake()
File "C:\Python31\lib\ssl.py", line 327, in do_handshake
self._sslobj.do_handshake()
AttributeError: 'NoneType' object has no attribute 'do_handshake' and the outcome is unpredictable. It may work many times in a row If this is of any relevance, I've had pywin32-2.14 installed since. |
Are you able to compile a fresh checkout of either the py3k or release3.1-maint branch? A bunch of fixes have been committed recently, some of which may (or even should) address your issue. |
Checked out and built revision 80956 of py3k against OpenSSL 0.9.8n. Here is the banner: Python 3.2a0 (py3k:80956, May 8 2010, 11:31:45) [MSC v.1500 32 bit (Intel)] on win32 Now, the breaking script appears not to be breaking any more, even though I tried it in a loop, a 1000 attempts to execute were all successful. It seems to be fine now, thank you for your help. |
Thank you! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: