Author: Amaury Forgeot d'Arc <amaur...@gmail.com>
Branch: stdlib-2.7.9
Changeset: r75742:0a58fd236ab2
Date: 2015-02-06 22:26 +0100
http://bitbucket.org/pypy/pypy/changeset/0a58fd236ab2/

Log:    ssl: fix error message in load_cert_chain() password.

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -1092,8 +1092,14 @@
     password = ""
     if pw_info.w_callable:
         try:
-            password = pw_info.space.str_w(
-                space.call_function(pw_info.w_callable))
+            w_result = space.call_function(pw_info.w_callable)
+            try:
+                password = pw_info.space.bufferstr_w(w_result)
+            except OperationError as e:
+                if not e.match(space, space.w_TypeError):
+                    raise
+                raise oefmt(space.w_TypeError, 
+                            "password callback must return a string")
         except OperationError as e:
             pw_info.operationerror = e
             return rffi.cast(rffi.INT, -1)
@@ -1328,14 +1334,19 @@
             if space.is_true(space.callable(w_password)):
                 pw_info.w_callable = w_password
             else:
-                pw_info.password = space.str_w(w_password)
+                try:
+                    pw_info.password = space.bufferstr_w(w_password)
+                except OperationError as e:
+                    if not e.match(space, space.w_TypeError):
+                        raise
+                    raise oefmt(space.w_TypeError, 
+                                "password should be a string or callable")
 
             libssl_SSL_CTX_set_default_passwd_cb(
                 self.ctx, _password_callback)
             libssl_SSL_CTX_set_default_passwd_cb_userdata(
                 self.ctx, rffi.cast(rffi.VOIDP, index))
 
-
         try:
             set_errno(0)
             ret = libssl_SSL_CTX_use_certificate_chain_file(self.ctx, certfile)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to