Skip to content

Commit

Permalink
OM-349 Added leeway in timestamp checks
Browse files Browse the repository at this point in the history
  • Loading branch information
malinowskikam committed Oct 22, 2024
1 parent febdab4 commit 92f9e4a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions msystems/xml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
created_xpath = f"./{{{ns_envelope}}}Header/{{{ns_wss_s}}}Security/{{{ns_wss_util}}}Timestamp/{{{ns_wss_util}}}Created"
expires_xpath = f"./{{{ns_envelope}}}Header/{{{ns_wss_s}}}Security/{{{ns_wss_util}}}Timestamp/{{{ns_wss_util}}}Expires"

# Amount of time allowed over the limit for timestamp checks
# Without it the check can fail when the client and server time doesn't align
allowed_dt_delta = datetime.datetimedelta(seconds=1)


def add_signature(root, key, cert):
key = _make_sign_key(key, cert, None)
Expand Down Expand Up @@ -64,9 +68,9 @@ def verify_timestamp(root):
raise ValueError('Expires timestamp not found')
dt_expires = datetime.datetime.fromisoformat(replace_utc_timezone_with_offset(expires.text))

if dt_created > dt_now:
if dt_created - allowed_dt_delta > dt_now:
logger.debug("Created timestamp is in the future: dt_created=%s dt_now=%s", dt_created, dt_now)
raise ValueError('Created timestamp is in the future')
if dt_expires < dt_now:
if dt_expires + allowed_dt_delta < dt_now:
logger.debug("Envelope has expired: dt_expires=%s dt_now=%s", dt_expires, dt_now)
raise ValueError('Envelope has expired')

0 comments on commit 92f9e4a

Please sign in to comment.