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: 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: