From 1aee33f3f15d2e7d8c8e8e82ffb3baa119ce5d51 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Wed, 14 Jul 2021 10:54:55 -0700 Subject: [PATCH 1/2] add example of using password callback --- examples/client.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/client.py b/examples/client.py index 5608883..f04dd3d 100755 --- a/examples/client.py +++ b/examples/client.py @@ -100,6 +100,14 @@ def get_method(index): )[index] +# Callback for wolfssl/certs/client-keyEnc.pem (yassl123 password) +# sz is the max size of password allowed +# rw is type i.e PEM_PASS_READ +# userdata is a void pointer potentially set by user +def password_cb(sz, rw, userdata): + return "yassl123" + + def main(): args = build_arg_parser().parse_args() @@ -110,6 +118,7 @@ def main(): context = wolfssl.SSLContext(get_method(args.v)) + context.set_passwd_cb(password_cb) context.load_cert_chain(args.c, args.k) if args.d: From adac2b98f5e54b0a0530aafcab2f78ee21760650 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Fri, 16 Jul 2021 08:19:04 -0700 Subject: [PATCH 2/2] try to convert a string to byte for python3 --- src/wolfssl/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wolfssl/__init__.py b/src/wolfssl/__init__.py index 27d1f2c..1c0e78d 100644 --- a/src/wolfssl/__init__.py +++ b/src/wolfssl/__init__.py @@ -942,6 +942,14 @@ def callback(self): def _get_passwd(self, passwd, sz, rw, userdata): try: result = self._passwd_wrapper(sz, rw, userdata) + + # if the result returned is a string then try to convert it + try: + if isinstance(result, str): + result = str.encode(result) + except Exception as e: + pass + if not isinstance(result, bytes): raise ValueError("Problem, expected String, not bytes") if len(result) > sz: