py3: fix csrgen error handling

csrgen error handling marshalls an error string from libcrypto.
This is not handled correctly under python3.  Fix the error
handling.

Part of: https://pagure.io/freeipa/issue/7496

Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
Fraser Tweedale 2018-04-16 15:06:16 +10:00 committed by Christian Heimes
parent 13b9608d5c
commit 53f87ee5cd

View File

@ -182,8 +182,12 @@ def _raise_openssl_errors():
code = ERR_get_error()
while code != 0:
msg = ERR_error_string(code, NULL)
msgs.append(_ffi.string(msg))
msg = _ffi.string(ERR_error_string(code, NULL))
try:
strmsg = msg.decode('utf-8')
except UnicodeDecodeError:
strmsg = repr(msg)
msgs.append(strmsg)
code = ERR_get_error()
raise errors.CSRTemplateError(reason='\n'.join(msgs))