Patchwork mail: retrain hostname for sslutil.wrapsocket (issue5203)

login
register
mail settings
Submitter timeless
Date April 15, 2016, 6:18 p.m.
Message ID <67ba2a0619ae1d49a8aa.1460744326@gcc2-power8.osuosl.org>
Download mbox | patch
Permalink /patch/14650/
State Superseded
Headers show

Comments

timeless - April 15, 2016, 6:18 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1460742227 0
#      Fri Apr 15 17:43:47 2016 +0000
# Node ID 67ba2a0619ae1d49a8aa8957e2c6c481be816ac2
# Parent  531dea16f4f754fd76e2f6434662b7dc154e704a
# Available At bb://timeless/mercurial-crew
#              hg pull bb://timeless/mercurial-crew -r 67ba2a0619ae
mail: retrain hostname for sslutil.wrapsocket (issue5203)

SMTPS + STARTTLS need to provide serverhostname,
and we can't store it in sslkwargs because that breaks
something involving the https protocol.
timeless - April 15, 2016, 9:20 p.m.
discard this, i misspelled retain :(

Patch

diff -r 531dea16f4f7 -r 67ba2a0619ae mercurial/mail.py
--- a/mercurial/mail.py	Tue Apr 12 14:43:36 2016 +0000
+++ b/mercurial/mail.py	Fri Apr 15 17:43:47 2016 +0000
@@ -48,9 +48,10 @@ 
 
     This class allows to pass any keyword arguments to SSL socket creation.
     '''
-    def __init__(self, sslkwargs, **kwargs):
+    def __init__(self, sslkwargs, host=None, **kwargs):
         smtplib.SMTP.__init__(self, **kwargs)
         self._sslkwargs = sslkwargs
+        self._host = host
 
     def starttls(self, keyfile=None, certfile=None):
         if not self.has_extn("starttls"):
@@ -59,6 +60,7 @@ 
         (resp, reply) = self.docmd("STARTTLS")
         if resp == 220:
             self.sock = sslutil.wrapsocket(self.sock, keyfile, certfile,
+                                           serverhostname=self._host,
                                            **self._sslkwargs)
             self.file = smtplib.SSLFakeFile(self.sock)
             self.helo_resp = None
@@ -72,10 +74,12 @@ 
 
     This class allows to pass any keyword arguments to SSL socket creation.
     '''
-    def __init__(self, sslkwargs, keyfile=None, certfile=None, **kwargs):
+    def __init__(self, sslkwargs, keyfile=None, certfile=None, host=None,
+                 **kwargs):
         self.keyfile = keyfile
         self.certfile = certfile
         smtplib.SMTP.__init__(self, **kwargs)
+        self._host = host
         self.default_port = smtplib.SMTP_SSL_PORT
         self._sslkwargs = sslkwargs
 
@@ -85,6 +89,7 @@ 
         new_socket = socket.create_connection((host, port), timeout)
         new_socket = sslutil.wrapsocket(new_socket,
                                         self.keyfile, self.certfile,
+                                        serverhostname=self._host,
                                         **self._sslkwargs)
         self.file = smtplib.SSLFakeFile(new_socket)
         return new_socket
@@ -114,9 +119,9 @@ 
         sslkwargs = {'ui': ui}
     if smtps:
         ui.note(_('(using smtps)\n'))
-        s = SMTPS(sslkwargs, local_hostname=local_hostname)
+        s = SMTPS(sslkwargs, local_hostname=local_hostname, host=mailhost)
     elif starttls:
-        s = STARTTLS(sslkwargs, local_hostname=local_hostname)
+        s = STARTTLS(sslkwargs, local_hostname=local_hostname, host=mailhost)
     else:
         s = smtplib.SMTP(local_hostname=local_hostname)
     if smtps: