[issue27629] Cannot create ssl.SSLSocket without existing socket
nemunaire added the comment: The documentation already recommends to use SSLContext.wrap_socket(), but it didn't cover all use cases. Eg. I use multiple inheritance to handle both socket and SSLSocket inside a factory pattern, in order to override some methods defined in both classes. If I use SSLContext.wrap_socket(), it erases my overrides. As the patch add some tests on this feature, this is no more dead code; however I let you decide the future of this issue: I've updated my patch with your remarks if you want to include it (it applies from Python 3.3 to current Python 3.6). -- Added file: http://bugs.python.org/file45778/fix_sslsocket_init_without_socket_3_3-3_6.patch ___ Python tracker <http://bugs.python.org/issue27629> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27629] Cannot create ssl.SSLSocket without existing socket
Changes by nemunaire : Removed file: http://bugs.python.org/file43927/fix_sslsocket_init_without_socket_3_3-3_6.patch ___ Python tracker <http://bugs.python.org/issue27629> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27629] Cannot create raw ssl.SSLSocket
New submission from nemunaire: I got this stacktrace: File "test_ssl.py", line 3, in sock = ssl.SSLSocket(server_hostname="docs.python.org") File "/usr/lib/python3.4/ssl.py", line 536, in __init__ if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM: AttributeError: 'NoneType' object has no attribute 'getsockopt' with this minimal code: import ssl sock = ssl.SSLSocket(server_hostname="docs.python.org") sock.connect(("docs.python.org", 443)) sock.sendall(b"GET /3/library/ssl.html HTTP/1.0\r\nHost: docs.python.org\r\n\r\n") print(sock.recv(4096).decode()) Whereas the None socket is correctly handled a few lines later: https://hg.python.org/cpython/file/tip/Lib/ssl.py#l715 All Python >= 3.3 are affected (since https://hg.python.org/cpython/rev/a00842b783cf) and can be patched with the same file, attached to this issue. -- components: Library (Lib) files: fix_sslsocket_init_without_socket_3.3-3_6.patch keywords: patch messages: 271419 nosy: nemunaire priority: normal severity: normal status: open title: Cannot create raw ssl.SSLSocket type: behavior versions: Python 3.3, Python 3.4, Python 3.5, Python 3.6 Added file: http://bugs.python.org/file43900/fix_sslsocket_init_without_socket_3.3-3_6.patch ___ Python tracker <http://bugs.python.org/issue27629> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27629] Cannot create ssl.SSLSocket without existing socket
Changes by nemunaire : -- title: Cannot create raw ssl.SSLSocket -> Cannot create ssl.SSLSocket without existing socket ___ Python tracker <http://bugs.python.org/issue27629> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27629] Cannot create ssl.SSLSocket without existing socket
nemunaire added the comment: Here is a new patch with tests on constructor. The patch on the feature is quite different: instead of testing for None socket, I choose to delay the != SOCK_STREAM check in the later condition, when we know we treat a socket. Tests include different constructor forms: with a given socket, with a fileno (didn't work either, before this patch) and without socket nor file descriptor (as in my original test). I don't have sufficient background to judge if tests will work on all platform (eg. fileno and windows, ...). Here is the interesting diff of the tests on SSL (before/after applying the patch on the feature): 32c32 < test_constructor (__main__.BasicSocketTests) ... ERROR --- > test_constructor (__main__.BasicSocketTests) ... ok 519,528d518 < ERROR: test_constructor (__main__.BasicSocketTests) < -- < Traceback (most recent call last): < File "test_ssl.py", line 149, in test_constructor < ss = ssl.SSLSocket() < File "/usr/lib/python3.4/ssl.py", line 545, in __init__ < if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM: < AttributeError: 'NoneType' object has no attribute 'getsockopt' < < == -- Added file: http://bugs.python.org/file43927/fix_sslsocket_init_without_socket_3_3-3_6.patch ___ Python tracker <http://bugs.python.org/issue27629> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27629] Cannot create ssl.SSLSocket without existing socket
Changes by nemunaire : Removed file: http://bugs.python.org/file43900/fix_sslsocket_init_without_socket_3.3-3_6.patch ___ Python tracker <http://bugs.python.org/issue27629> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com