From 40099da3ce376c3528007254cb19123615925b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Haziza?= Date: Thu, 11 Jul 2024 12:17:25 +0200 Subject: [PATCH] Not converting timestamp to python dates helps --- crypt4gh/cli.py | 2 -- crypt4gh/header.py | 3 ++- crypt4gh/lib.py | 5 +++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crypt4gh/cli.py b/crypt4gh/cli.py index 6d26fa0..b974d48 100644 --- a/crypt4gh/cli.py +++ b/crypt4gh/cli.py @@ -134,8 +134,6 @@ def retrieve_private_key(args, generate=False): return get_private_key(seckeypath, cb) def make_timestamp(date): - # if date.startswith('+'): - # return int((datetime.datetime.now(datetime.UTC) + parse_deltatime(date[1:])).timestamp()) LOG.debug("expiration: %s", date) return int(datetime.datetime.fromisoformat(date).timestamp()) diff --git a/crypt4gh/header.py b/crypt4gh/header.py index 6a0a5a7..a396353 100644 --- a/crypt4gh/header.py +++ b/crypt4gh/header.py @@ -184,7 +184,8 @@ def make_packet_timestamp(timestamp): def parse_timestamp_packet(packet): if len(packet) != 8: raise ValueError('Invalid timestamp packet') - return datetime.datetime.fromtimestamp(int.from_bytes(packet, byteorder='little'), datetime.UTC) + # return datetime.datetime.fromtimestamp(int.from_bytes(packet, byteorder='little')) + return int.from_bytes(packet, byteorder='little') # ------------------------------------- # link packet diff --git a/crypt4gh/lib.py b/crypt4gh/lib.py index cad587b..a867e42 100644 --- a/crypt4gh/lib.py +++ b/crypt4gh/lib.py @@ -7,6 +7,7 @@ import collections from itertools import chain import datetime +import time from nacl.bindings import (crypto_aead_chacha20poly1305_ietf_encrypt, crypto_aead_chacha20poly1305_ietf_decrypt) @@ -397,8 +398,8 @@ def decrypt(keys, infile, outfile, sender_pubkey=None, offset=0, span=None): session_keys, edit_list, expiration, uri = header.deconstruct(infile, keys, sender_pubkey=sender_pubkey) - if expiration and (datetime.datetime.fromtimestamp(time.time()) > expiration): - raise ValueError(f'Expired on {expiration}') + if expiration and (time.time() > expiration): # now > expiration_timestamp + raise ValueError(f'Expired on {datetime.datetime.fromtimestamp(expiration)}') # Infile in now positioned at the beginning of the data portion # or we fetch the data portion from the URI.