Message256299
With the current tip, starttls uses ._host when calling wrap_socket [1], but ._host is only setup in SMTP.__init__ [2]. Before #22921 [3] starttls would ignore ._host when SNI wasn't available locally. But as far as I can tell, starttls has never used _host when connection happens via an explicit connect() call. This leads to errors like [4]:
>>> smtp = smtplib.SMTP()
>>> smtp.connect(host="smtp.gmail.com", port=587)
>>> smtp.ehlo()
>>> smtp.starttls()
File "smtp_test.py", line 10, in <module>
smtp.starttls()
File "/usr/lib/python3.4/smtplib.py", line 676, in starttls
server_hostname=server_hostname)
File "/usr/lib/python3.4/ssl.py", line 344, in wrap_socket
_context=self)
File "/usr/lib/python3.4/ssl.py", line 540, in __init__
self.do_handshake()
File "/usr/lib/python3.4/ssl.py", line 767, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: TLSV1_ALERT_DECODE_ERROR] tlsv1 alert decode error (_ssl.c:598)
I think a better approach would be to move the ._host set into .connect (patch attached). It would still happen in SMTP(host=…) because [5], but would also allow starttls when users use SMTP() and then call connect(host=…) explicitly.
I've formatted the patch with Git, but its simple enough that it should be easy to apply in Mercurial. Still, let me know if I can make applying it easier by rerolling the patch.
[1]: https://hg.python.org/cpython/file/323c10701e5d/Lib/smtplib.py#l766
[2]: https://hg.python.org/cpython/file/323c10701e5d/Lib/smtplib.py#l244
[3]: http://bugs.python.org/issue22921
[4]: http://stackoverflow.com/questions/23616803/smtplib-smtp-starttls-fails-with-tlsv1-alert-decode-error
[5]: https://hg.python.org/cpython/file/323c10701e5d/Lib/smtplib.py#l251 |
|
Date |
User |
Action |
Args |
2015-12-12 22:59:22 | labrat | set | recipients:
+ labrat |
2015-12-12 22:59:22 | labrat | set | messageid: <1449961162.47.0.978986314472.issue25852@psf.upfronthosting.co.za> |
2015-12-12 22:59:22 | labrat | link | issue25852 messages |
2015-12-12 22:59:22 | labrat | create | |
|