[attributs.certificat] Belle erreur sur les certificats mal formaté

This commit is contained in:
Valentin Samir 2014-03-02 01:17:24 +01:00
parent 99d864b81c
commit 79149ebb4f

View file

@ -1517,13 +1517,16 @@ class certificat(Attr):
def _format_cert(self, certificat):
import OpenSSL
try:
if certificat.startswith('-----BEGIN CERTIFICATE-----'):
certificat = ssl.PEM_cert_to_DER_cert(certificat)
try:
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, certificat)
except:
except Exception:
try:
certificat = base64.b64decode(certificat)
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, certificat)
except Exception:
raise ValueError("Format du certificat invalide, est-il bien au format DER ou PEM ?")
data = {}
data['subject'] = dict(x509.get_subject().get_components())
data['issuer'] = dict(x509.get_issuer().get_components())