From 79149ebb4fd38619554ed85dddf9db1cf5ad4072 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Sun, 2 Mar 2014 01:17:24 +0100 Subject: [PATCH] =?UTF-8?q?[attributs.certificat]=20Belle=20erreur=20sur?= =?UTF-8?q?=20les=20certificats=20mal=20format=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attributs.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/attributs.py b/attributs.py index 3aeffc6..c8173f6 100644 --- a/attributs.py +++ b/attributs.py @@ -1517,13 +1517,16 @@ class certificat(Attr): def _format_cert(self, certificat): import OpenSSL - if certificat.startswith('-----BEGIN CERTIFICATE-----'): - certificat = ssl.PEM_cert_to_DER_cert(certificat) try: + if certificat.startswith('-----BEGIN CERTIFICATE-----'): + certificat = ssl.PEM_cert_to_DER_cert(certificat) x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, certificat) - except: - certificat = base64.b64decode(certificat) - x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, certificat) + 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())