diff options
author | Martin Basti <mbasti@redhat.com> | 2017-01-19 16:11:08 +0100 |
---|---|---|
committer | Martin Basti <mbasti@redhat.com> | 2017-01-31 18:33:27 +0100 |
commit | 980c8a5f9e4ccbcd3c11def9cab33d0e61e945ae (patch) | |
tree | bc7787c00b78919328c73c7a76b848699a979bc5 /ipalib | |
parent | b8d6524d43dd0667184aebc79fb77a9b8a46939a (diff) | |
download | freeipa-980c8a5f9e4ccbcd3c11def9cab33d0e61e945ae.tar.gz freeipa-980c8a5f9e4ccbcd3c11def9cab33d0e61e945ae.tar.xz freeipa-980c8a5f9e4ccbcd3c11def9cab33d0e61e945ae.zip |
py3: normalize_certificate: support both bytes and unicode
https://fedorahosted.org/freeipa/ticket/4985
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/x509.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/ipalib/x509.py b/ipalib/x509.py index d883ac4e1..87d46ae6f 100644 --- a/ipalib/x509.py +++ b/ipalib/x509.py @@ -251,13 +251,22 @@ def normalize_certificate(rawcert): rawcert = strip_header(rawcert) - if util.isvalid_base64(rawcert): - try: - dercert = base64.b64decode(rawcert) - except Exception as e: - raise errors.Base64DecodeError(reason=str(e)) - else: + try: + if isinstance(rawcert, bytes): + # base64 must work with utf-8, otherwise it is raw bin certificate + decoded_cert = rawcert.decode('utf-8') + else: + decoded_cert = rawcert + except UnicodeDecodeError: dercert = rawcert + else: + if util.isvalid_base64(decoded_cert): + try: + dercert = base64.b64decode(decoded_cert) + except Exception as e: + raise errors.Base64DecodeError(reason=str(e)) + else: + dercert = rawcert # At this point we should have a DER certificate. # Attempt to decode it. |