Patchwork ssl: handle a difference in SSLError with pypy (issue5348)

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 13, 2016, 3:57 p.m.
Message ID <e3584d7c9ea3516bd8ea.1473782270@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16600/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 13, 2016, 3:57 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1473781589 -7200
#      Tue Sep 13 17:46:29 2016 +0200
# Node ID e3584d7c9ea3516bd8eaac3735ae8a468b9ca770
# Parent  be16091ac14d03f3cc038b2fb26efe46f785f8d7
# EXP-Topic pypy.https
ssl: handle a difference in SSLError with pypy (issue5348)

The SSLError exception is a bit different with pypy (message is the first
argument, not the second) This led the certificate error handling to crash when
trying to extract the ssl error message. We now handle this different and
'test-https.t' is green again.
Augie Fackler - Sept. 13, 2016, 5:41 p.m.
On Tue, Sep 13, 2016 at 05:57:50PM +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1473781589 -7200
> #      Tue Sep 13 17:46:29 2016 +0200
> # Node ID e3584d7c9ea3516bd8eaac3735ae8a468b9ca770
> # Parent  be16091ac14d03f3cc038b2fb26efe46f785f8d7
> # EXP-Topic pypy.https
> ssl: handle a difference in SSLError with pypy (issue5348)

Queued with some english tweaks in the comments, thanks

>
> The SSLError exception is a bit different with pypy (message is the first
> argument, not the second) This led the certificate error handling to crash when
> trying to extract the ssl error message. We now handle this different and
> 'test-https.t' is green again.
>
> diff --git a/mercurial/sslutil.py b/mercurial/sslutil.py
> --- a/mercurial/sslutil.py
> +++ b/mercurial/sslutil.py
> @@ -390,8 +390,12 @@ def wrapsocket(sock, keyfile, certfile,
>          try:
>              sslcontext.load_verify_locations(cafile=settings['cafile'])
>          except ssl.SSLError as e:
> +            if len(e.args) == 1: # pypy have different SSLError args:
> +                msg = e.args[0]
> +            else:
> +                msg = e.args[1]
>              raise error.Abort(_('error loading CA file %s: %s') % (
> -                              settings['cafile'], e.args[1]),
> +                              settings['cafile'], msg),
>                                hint=_('file is empty or malformed?'))
>          caloaded = True
>      elif settings['allowloaddefaultcerts']:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/sslutil.py b/mercurial/sslutil.py
--- a/mercurial/sslutil.py
+++ b/mercurial/sslutil.py
@@ -390,8 +390,12 @@  def wrapsocket(sock, keyfile, certfile, 
         try:
             sslcontext.load_verify_locations(cafile=settings['cafile'])
         except ssl.SSLError as e:
+            if len(e.args) == 1: # pypy have different SSLError args:
+                msg = e.args[0]
+            else:
+                msg = e.args[1]
             raise error.Abort(_('error loading CA file %s: %s') % (
-                              settings['cafile'], e.args[1]),
+                              settings['cafile'], msg),
                               hint=_('file is empty or malformed?'))
         caloaded = True
     elif settings['allowloaddefaultcerts']: