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:
@@ -251,13 +251,22 @@ def normalize_certificate(rawcert):
|
|||||||
|
|
||||||
rawcert = strip_header(rawcert)
|
rawcert = strip_header(rawcert)
|
||||||
|
|
||||||
if util.isvalid_base64(rawcert):
|
try:
|
||||||
try:
|
if isinstance(rawcert, bytes):
|
||||||
dercert = base64.b64decode(rawcert)
|
# base64 must work with utf-8, otherwise it is raw bin certificate
|
||||||
except Exception as e:
|
decoded_cert = rawcert.decode('utf-8')
|
||||||
raise errors.Base64DecodeError(reason=str(e))
|
else:
|
||||||
else:
|
decoded_cert = rawcert
|
||||||
|
except UnicodeDecodeError:
|
||||||
dercert = rawcert
|
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.
|
# At this point we should have a DER certificate.
|
||||||
# Attempt to decode it.
|
# Attempt to decode it.
|
||||||
|
|||||||
Reference in New Issue
Block a user