|
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
|
@@ -381,20 +383,25 @@ def active_cert(key):
|
381 | 383 | :param key: The Key
|
382 | 384 | :return: True if the key is active else False
|
383 | 385 | """
|
384 |
| - cert_str = pem_format(key) |
385 |
| - certificate = importKey(cert_str) |
386 | 386 | try:
|
387 |
| - not_before = to_time(str(certificate.get_not_before())) |
388 |
| - not_after = to_time(str(certificate.get_not_after())) |
389 |
| - assert not_before < utc_now() |
390 |
| - assert not_after > utc_now() |
391 |
| - return True |
| 387 | + cert_str = pem_format(key) |
| 388 | + try: |
| 389 | + certificate = importKey(cert_str) |
| 390 | + not_before = to_time(str(certificate.get_not_before())) |
| 391 | + not_after = to_time(str(certificate.get_not_after())) |
| 392 | + assert not_before < utc_now() |
| 393 | + assert not_after > utc_now() |
| 394 | + return True |
| 395 | + except: |
| 396 | + cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_str) |
| 397 | + assert cert.has_expired() == 0 |
| 398 | + assert not OpenSSLWrapper().certificate_not_valid_yet(cert) |
| 399 | + return True |
392 | 400 | except AssertionError:
|
393 | 401 | return False
|
394 | 402 | except AttributeError:
|
395 | 403 | return False
|
396 | 404 |
|
397 |
| - |
398 | 405 | def cert_from_key_info(key_info, ignore_age=False):
|
399 | 406 | """ Get all X509 certs from a KeyInfo instance. Care is taken to make sure
|
400 | 407 | that the certs are continues sequences of bytes.
|
|
0 commit comments