sslutil: abort properly if no certificate received for https connection
authorMads Kiilerich <mads@kiilerich.com>
Mon, 09 Jan 2012 14:56:05 +0100
changeset 15817 8f377751b510
parent 15816 4bb59919c905
child 15818 57241845a4bb
sslutil: abort properly if no certificate received for https connection According to the documentation SSLSocket.getpeercert() can return None.
mercurial/sslutil.py
--- a/mercurial/sslutil.py	Mon Jan 09 14:43:25 2012 +0100
+++ b/mercurial/sslutil.py	Mon Jan 09 14:56:05 2012 +0100
@@ -113,6 +113,9 @@
         if not sock.cipher(): # work around http://bugs.python.org/issue13721
             raise util.Abort(_('%s ssl connection error') % host)
         peercert = sock.getpeercert(True)
+        if not peercert:
+            raise util.Abort(_('%s certificate error: '
+                               'no certificate received') % host)
         peerfingerprint = util.sha1(peercert).hexdigest()
         nicefingerprint = ":".join([peerfingerprint[x:x + 2]
             for x in xrange(0, len(peerfingerprint), 2)])