From 1a3c9114c338c24e037448ad0ec72b9f11209ba3 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman <rjeffman@redhat.com> Date: Fri, 24 Jan 2020 23:34:44 -0300 Subject: [PATCH] Properly handle base64 enconding of certificates stored as bytes. This change is needed to properly handle base64 encoding of certificates stored as bytes, under Python 3, as used by IPA service. It does not affect Python 2.7 as bytes are identical to str in this version of the language. When retireving certificates stored by FreeIPA service data is returned as bytes, under Python 3, and encoding then breaks, as there is no bytes.public_bytes method. In Python 3, encoding with base64 will be the same for strings and bytes. --- plugins/module_utils/ansible_freeipa_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py index 8154a12c..1ea64346 100644 --- a/plugins/module_utils/ansible_freeipa_module.py +++ b/plugins/module_utils/ansible_freeipa_module.py @@ -268,7 +268,7 @@ def encode_certificate(cert): Encode a certificate using base64 with also taking FreeIPA and Python versions into account """ - if isinstance(cert, str) or isinstance(cert, unicode): + if isinstance(cert, (str, unicode, bytes)): encoded = base64.b64encode(cert) else: encoded = base64.b64encode(cert.public_bytes(Encoding.DER)) -- GitLab