Skip to content

Commit a185a9d

Browse files
author
Roland Hedberg
committed
Merge pull request #229 from HaToHo/master
In case pycrypto is not able to read the certificate file openssl is …
2 parents c4eac48 + 78422f2 commit a185a9d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/saml2/sigver.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
""" Functions connected to signing and verifying.
66
Based on the use of xmlsec1 binaries and not the python xmlsec module.
77
"""
8+
from OpenSSL import crypto
89

910
import base64
11+
from base64 import b64decode
1012
import hashlib
1113
import logging
1214
import os
@@ -382,20 +384,25 @@ def active_cert(key):
382384
:param key: The Key
383385
:return: True if the key is active else False
384386
"""
385-
cert_str = pem_format(key)
386-
certificate = importKey(cert_str)
387387
try:
388-
not_before = to_time(str(certificate.get_not_before()))
389-
not_after = to_time(str(certificate.get_not_after()))
390-
assert not_before < utc_now()
391-
assert not_after > utc_now()
392-
return True
388+
cert_str = pem_format(key)
389+
try:
390+
certificate = importKey(cert_str)
391+
not_before = to_time(str(certificate.get_not_before()))
392+
not_after = to_time(str(certificate.get_not_after()))
393+
assert not_before < utc_now()
394+
assert not_after > utc_now()
395+
return True
396+
except:
397+
cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_str)
398+
assert cert.has_expired() == 0
399+
assert not OpenSSLWrapper().certificate_not_valid_yet(cert)
400+
return True
393401
except AssertionError:
394402
return False
395403
except AttributeError:
396404
return False
397405

398-
399406
def cert_from_key_info(key_info, ignore_age=False):
400407
""" Get all X509 certs from a KeyInfo instance. Care is taken to make sure
401408
that the certs are continues sequences of bytes.

0 commit comments

Comments
 (0)