commit ca31a7f701ad28c36138715caec56e9299cead17
Author: Stanislav Král <stanislav.kral3@gmail.com>
Date:   Tue Apr 20 10:34:07 2021 +0200

    Re #8575 - Fixed an issue where when creating an index file the valid_to field was passed instead of the revocation_date field

diff --git a/src/services/crl/crl_service.py b/src/services/crl/crl_service.py
index 7476bed..01f2c64 100644
--- a/src/services/crl/crl_service.py
+++ b/src/services/crl/crl_service.py
@@ -1,9 +1,8 @@
-import time
+from datetime import datetime
 
 from injector import inject
 
 from src.dao.certificate_repository import CertificateRepository
-from src.services.certificate_service import VALID_FROM_TO_DATE_FORMAT
 from src.services.crl.ca_index_file_line_generator import create_index_file_revoked_line
 from src.services.cryptography import CryptographyService
 
@@ -31,10 +30,11 @@ class CrlService:
         for certificate in self.certificate_repository.get_all_revoked_by(ca_id):
             # extract the complete subject information and not_after date field
             subject, _, not_after = self.cryptography_service.parse_cert_pem(certificate.pem_data)
+
             line = create_index_file_revoked_line(certificate,
                                                   subject,
-                                                  # parse valid_to date to a date struct
-                                                  time.strptime(certificate.valid_to, VALID_FROM_TO_DATE_FORMAT),
+                                                  # parse revocation date from unix timestamp to struct_time
+                                                  datetime.utcfromtimestamp(int(certificate.revocation_date)).timetuple(),
                                                   not_after)
 
             # append it to the list of lines
diff --git a/tests/integration_tests/services/crl_service_test.py b/tests/integration_tests/services/crl_service_test.py
index b0d42d0..e9190db 100644
--- a/tests/integration_tests/services/crl_service_test.py
+++ b/tests/integration_tests/services/crl_service_test.py
@@ -1,4 +1,5 @@
 import time
+from datetime import datetime
 
 from src.model.subject import Subject
 from src.services.certificate_service import VALID_FROM_TO_DATE_FORMAT
@@ -35,7 +36,7 @@ def test_set_certificate_revoked(certificate_service_unique, private_key_service
                                                   root_ca_private_key)
 
     # create another CA
-    bar_baz_ca = certificate_service_unique.create_ca(inter_ca_private_key, Subject(common_name="BarBaz CA"),
+    certificate_service_unique.create_ca(inter_ca_private_key, Subject(common_name="BarBaz CA"),
                                                       root_ca_cert,
                                                       root_ca_private_key)
 
@@ -56,11 +57,16 @@ def test_set_certificate_revoked(certificate_service_unique, private_key_service
     # create index of revoked certificates
     out = crl_service_unique.create_revoked_index(root_ca_cert.certificate_id)
 
+    # fetch certificates in order to update the revocation_date fields
+    foo_ca = certificate_service_unique.get_certificate(foo_ca.certificate_id)
+    bar_ca = certificate_service_unique.get_certificate(bar_ca.certificate_id)
+    baz_cert = certificate_service_unique.get_certificate(baz_cert.certificate_id)
+
     # convert revoked date fields (revoked date fields change with each test run)
     revoked_dates = [
-        convert_date_to_ca_index_format(cryptography_service.parse_cert_pem(foo_ca.pem_data)[2]),
-        convert_date_to_ca_index_format(cryptography_service.parse_cert_pem(bar_ca.pem_data)[2]),
-        convert_date_to_ca_index_format(cryptography_service.parse_cert_pem(baz_cert.pem_data)[2]),
+        convert_date_to_ca_index_format(datetime.utcfromtimestamp(int(foo_ca.revocation_date)).timetuple()),
+        convert_date_to_ca_index_format(datetime.utcfromtimestamp(int(bar_ca.revocation_date)).timetuple()),
+        convert_date_to_ca_index_format(datetime.utcfromtimestamp(int(baz_cert.revocation_date)).timetuple()),
     ]
 
     # convert valid_to date fields (expiration date fields change with each test run)
