cwa-quicktest-onboarding icon indicating copy to clipboard operation
cwa-quicktest-onboarding copied to clipboard

Be aware: Python example contains bugs on timestamps

Open dh3wr opened this issue 3 years ago • 0 comments

Describe the bug

The calculation of the expiration timestamp is wrong in https://github.com/corona-warn-app/cwa-quicktest-onboarding/blob/master/src/testcenter_simulator/labsimulator.py starting line 86.

def dcc_cbor(self, certData, issuedAtTimestamp=None, expiredAfterSeconds=None ):
        if issuedAtTimestamp is None:
            issuedAtTimestamp = int(time())     # Wenn nichts angegeben, dann jetziger Zeitpunkt
        if expiredAfterSeconds is None:
            expiredAfterSeconds = 60 * 60 * 24  # Wenn nichts angegeben, 1 Tag Gültigkeit

Expected behaviour

  1. The expiration duration is 48 h, so 2 days. Not 1 day as in the example given
  2. The expiration time is not issuedTime expirationDuration , but sc + expirationDuration, so related to the sample collection

Steps to reproduce the issue

Implement the given example

Possible Fix

def dcc_cbor(certData, TestresultAtTimestamp=None, SCAtTimestamp=None, expiredAfterSeconds=None):
    if TestresultAtTimestamp is None:
        TestresultAtTimestamp = int(time.time())  # Wenn nichts angegeben, dann jetziger Zeitpunkt
    if SCAtTimestamp is None:
        SCAtTimestamp = int(time.time()) - (60 * 15)  # Wenn nichts angegeben, dann jetziger Zeitpunkt - 15 min
    if expiredAfterSeconds is None:
        expiredAfterSeconds = 60 * 60 * 24 * 2 # Wenn nichts angegeben, 2 Tage Gültigkeit

    ExpirationAtTimestamp = SCAtTimestamp + expiredAfterSeconds

    cborMap = {}
    cborMap[4] = ExpirationAtTimestamp # Ablaufzeitstempel
    cborMap[6] = TestresultAtTimestamp # Ausstellungszeitstempel = Zeitpunkt des Ergebnis-Eintragens

Additional context

The wiki is correct on this topic.

dh3wr avatar Jan 18 '22 22:01 dh3wr