|
5 | 5 | """ Functions connected to signing and verifying.
|
6 | 6 | Based on the use of xmlsec1 binaries and not the python xmlsec module.
|
7 | 7 | """
|
| 8 | +from OpenSSL import crypto |
8 | 9 |
|
9 | 10 | import base64
|
| 11 | +from base64 import b64decode |
10 | 12 | import hashlib
|
11 | 13 | import logging
|
12 | 14 | import os
|
@@ -382,20 +384,25 @@ def active_cert(key):
|
382 | 384 | :param key: The Key
|
383 | 385 | :return: True if the key is active else False
|
384 | 386 | """
|
385 |
| - cert_str = pem_format(key) |
386 |
| - certificate = importKey(cert_str) |
387 | 387 | 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 |
393 | 401 | except AssertionError:
|
394 | 402 | return False
|
395 | 403 | except AttributeError:
|
396 | 404 | return False
|
397 | 405 |
|
398 |
| - |
399 | 406 | def cert_from_key_info(key_info, ignore_age=False):
|
400 | 407 | """ Get all X509 certs from a KeyInfo instance. Care is taken to make sure
|
401 | 408 | that the certs are continues sequences of bytes.
|
|
0 commit comments