mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
py3: normalize_certificate: support both bytes and unicode
https://fedorahosted.org/freeipa/ticket/4985 Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
parent
b8d6524d43
commit
980c8a5f9e
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user