New submission from Vincent Pelletier <vinc...@nexedi.com>:

>From ssl.py, both on 2.7.15 and 3.6.6:
class SSLSocket(...):
...
    @context.setter
    def context(self, ctx):
        self._context = ctx
        self._sslobj.context = ctx

_sslobj is only set when socket is connected. While this is not a big issue for 
client sockets as user could just wrap the socket with correct context to begin 
with, and not a big issue for server sockets for the same reason, it is an 
issue for listening sockets: they are never connected, by definition, and do 
not care about _sslobj: upon accept() they only use self._context to wrap 
created socket.

Suggested fix:
    @context.setter
    def context(self, ctx):
        self._context = ctx
        if self._sslobj:
            self._sslobj.context = ctx
(consistently with how _sslobj is evaluated as a boolean elsewhere in the same 
class)

Suggested workaround (ex: if this fix is not backported to 2.7):
    try:
        ssl_socket.context = new_context
    except AttributeError:
        pass
as _context is changed first, and it's all that matters.

----------
messages: 325847
nosy: vincent-nexedi
priority: normal
severity: normal
status: open
title: SSLSocket.context cannot be changed on non-connected sockets
type: behavior
versions: Python 2.7, Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34747>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to