pyas2-lib icon indicating copy to clipboard operation
pyas2-lib copied to clipboard

Error importing public certificate

Open JamesInform opened this issue 4 years ago • 0 comments

Hi!

Importing a valid public key ".cer" file, I run into a server 500 error your django pyas2 (v1.2.0)

I switched to debug and found that you do a plain item.decode("utf8").

In utils.py function "extract_certificate_info" you do this e.g. in line 248 cert_info["subject"] = [ tuple(item.decode("utf8") for item in sets) for sets in certificate.get_subject().get_components() ]

If there is a non valid utf8 token in the subject, the function crashes.

The easy fix is to instruct the decode function to escape all non utf8 characters with a simple and convenient parameter in Python 3+:

item.decode("utf8","backslashreplace")

Maybe this can be used for all relevant utf8 decodings

Cheers James

JamesInform avatar Jan 20 '21 13:01 JamesInform