[attributs.certificat] Belle erreur sur les certificats mal formaté
This commit is contained in:
parent
99d864b81c
commit
79149ebb4f
1 changed files with 8 additions and 5 deletions
13
attributs.py
13
attributs.py
|
@ -1517,13 +1517,16 @@ class certificat(Attr):
|
||||||
|
|
||||||
def _format_cert(self, certificat):
|
def _format_cert(self, certificat):
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
if certificat.startswith('-----BEGIN CERTIFICATE-----'):
|
|
||||||
certificat = ssl.PEM_cert_to_DER_cert(certificat)
|
|
||||||
try:
|
try:
|
||||||
|
if certificat.startswith('-----BEGIN CERTIFICATE-----'):
|
||||||
|
certificat = ssl.PEM_cert_to_DER_cert(certificat)
|
||||||
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, certificat)
|
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, certificat)
|
||||||
except:
|
except Exception:
|
||||||
certificat = base64.b64decode(certificat)
|
try:
|
||||||
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, certificat)
|
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 = {}
|
||||||
data['subject'] = dict(x509.get_subject().get_components())
|
data['subject'] = dict(x509.get_subject().get_components())
|
||||||
data['issuer'] = dict(x509.get_issuer().get_components())
|
data['issuer'] = dict(x509.get_issuer().get_components())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue