Commit f0606a8f authored by Vincent Pelletier's avatar Vincent Pelletier

all: Use utils.timestamp2datetime .

datetime.datetime.fromtimestamp applies timezones, which is unintended.
Fixes a time drift on revoked certificates.
parent 849a7e37
Pipeline #13465 passed with stage
in 0 seconds
...@@ -760,9 +760,7 @@ class CertificateAuthority(object): ...@@ -760,9 +760,7 @@ class CertificateAuthority(object):
revoked_certificates=[ revoked_certificates=[
x509.RevokedCertificateBuilder( x509.RevokedCertificateBuilder(
serial_number=x['serial'], serial_number=x['serial'],
revocation_date=datetime.datetime.fromtimestamp( revocation_date=utils.timestamp2datetime(x['revocation_date']),
x['revocation_date'],
),
).build(_cryptography_backend) ).build(_cryptography_backend)
for x in self._storage.getRevocationList() for x in self._storage.getRevocationList()
], ],
......
...@@ -809,7 +809,7 @@ def main( ...@@ -809,7 +809,7 @@ def main(
backup_period = datetime.timedelta(args.backup_period, 0) backup_period = datetime.timedelta(args.backup_period, 0)
try: try:
next_backup = max( next_backup = max(
datetime.datetime.utcfromtimestamp(os.stat(x).st_ctime) utils.timestamp2datetime(os.stat(x).st_ctime)
for x in glob.iglob( for x in glob.iglob(
os.path.join(args.backup_directory, '*' + BACKUP_SUFFIX), os.path.join(args.backup_directory, '*' + BACKUP_SUFFIX),
) )
......
...@@ -553,6 +553,12 @@ def datetime2timestamp(value): ...@@ -553,6 +553,12 @@ def datetime2timestamp(value):
""" """
return int((value - EPOCH).total_seconds()) return int((value - EPOCH).total_seconds())
def timestamp2datetime(value):
"""
Convert given unix timestamp into a datetime.
"""
return EPOCH + datetime.timedelta(0, value)
def timestamp2IMFfixdate(value): def timestamp2IMFfixdate(value):
""" """
Convert a timestamp into an IMF-fixdate string following RFC7231. Convert a timestamp into an IMF-fixdate string following RFC7231.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment