Nathaniel Smith <n...@pobox.com> added the comment:

The ssl module's unwrap() method is intended to do a clean shutdown of TLS 
encryption on a socket (or memory BIO or whatever). The idea is that it sends a 
"close notify" frame (i.e., tells the peer that we're shutting down), and then 
it waits for the peer to send a "close notify" back, and then the TLS layer is 
cleanly shut down.

If you have a non-blocking socket or memory BIO, of course, it can't actually 
wait for the peer to send the "close notify" back. So in this case its 
semantics are: the first time you call it, it sends a "close notify", and then 
if it hasn't seen a "close notify", it raises SSLWantReadError to tell you 
that, and that you need to keep calling it.

In the current 3.7 branch, however, it never raises SSLWantReadError, so 
there's no way for calling code to figure out whether the other side has sent a 
"close notify". So in the current 3.7 branch, it's impossible to do a clean 
shutdown of the TLS layer on a non-blocking socket or memory BIO, and this is a 
regression from 3.7.0.

The attached script demonstrates this -- on 3.7.0 it completes successfully, 
but on the 3.7 branch it fails.

Impact: This is maybe not as bad as it sounds, because 'unwrap' is *very* 
rarely used? (Lots of protocols have STARTTLS, but not many have STOPTLS!) But 
I'm still going to mark it as a release blocker for now because:

- it is a genuine regression, that makes a rare-but-intentional-and-documented 
feature unusable

- while I haven't fully understood why the thread-safety patch causes this 
problem, the changes that patch makes to 'unwrap' are very similar to the 
changes it makes to much more important functions like 'do_handshake' and 
'send' and 'recv', so I'm nervous that the underlying issue might affect those 
as well.

- I figure if Ned doesn't think it's a release blocker, he can always remove 
the tag :-)

----------
priority: normal -> release blocker
Added file: https://bugs.python.org/file47817/ssl-unwrap-regression-example.py

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

Reply via email to