Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nursix/eden-core
Browse files Browse the repository at this point in the history
  • Loading branch information
nursix committed Aug 19, 2021
2 parents 0144d08 + d68ede4 commit 3427fb1
Show file tree
Hide file tree
Showing 6 changed files with 655 additions and 531 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ addons:
packages:
- python3-pip
- python3-setuptools
- postgresql-client-10
- postgresql-10-postgis-2.5
- postgresql-10-postgis-2.5-scripts
- postgresql-client-11
- postgresql-11-postgis-2.5
- postgresql-11-postgis-2.5-scripts
Expand All @@ -23,8 +20,6 @@ addons:
env:
- DB=mysql
- DB=sqlite3
- DB=postgres-10
- DB=postgres-10+postgis
- DB=postgres-11
- DB=postgres-11+postgis

Expand Down
12 changes: 6 additions & 6 deletions modules/templates/RLPPTM/cwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
s3_date, s3_mark_required, s3_qrcode_represent, \
JSONERRORS

from .dcc import DCC
from .vouchers import RLPCardLayout

CWA = {"system": "RKI / Corona-Warn-App",
Expand Down Expand Up @@ -292,7 +293,6 @@ def register(self, r, **attr):
# Store DCC data
if dcc_option:
cwa_data = cwa_report.data
from .dcc import DCC
try:
hcert = DCC.from_result(cwa_data.get("hash"),
record_id,
Expand Down Expand Up @@ -434,7 +434,7 @@ def certify(r, **attr):
first_name = cwadata.get("fn"),
last_name = cwadata.get("ln"),
dob = cwadata.get("dob"),
dcc = cwadata.get("dcc", False),
dcc = post_vars.get("dcc") == "1",
salt = cwadata.get("salt"),
dhash = cwadata.get("hash"),
)
Expand Down Expand Up @@ -533,7 +533,7 @@ def cwaretry(r, **attr):
first_name = cwadata.get("fn"),
last_name = cwadata.get("ln"),
dob = cwadata.get("dob"),
dcc = cwadata.get("dgc", False),
dcc = options.get("dcc") == "1",
salt = cwadata.get("salt"),
dhash = cwadata.get("hash"),
)
Expand Down Expand Up @@ -613,7 +613,7 @@ def __init__(self,

# Determine the testid and timestamp
testid = result.uuid
timestamp = int(result.probe_date.replace(microsecond=0).timestamp())
timestamp = int(DCC.utc_timestamp(result.probe_date))

if not anonymous:
if not all(value for value in (first_name, last_name, dob)):
Expand Down Expand Up @@ -651,7 +651,7 @@ def get_salt():
@returns: the token as str
"""
return secrets.token_hex(16)
return secrets.token_hex(16).upper()

# -------------------------------------------------------------------------
@staticmethod
Expand Down Expand Up @@ -829,6 +829,7 @@ def formatted(self, retry=False):
),
hidden = {"formurl": formurl,
"cwadata": json.dumps(self.data),
"dcc": "1" if self.dcc else "0",
"_formkey": formkey,
},
)
Expand Down Expand Up @@ -905,7 +906,6 @@ def send(self):
result_list = {"testResults": [testresult]}
if self.dcc:
# Look up the LabID
from .dcc import DCC
lab_id = DCC.get_issuer_id(self.site_id)
if not lab_id:
raise RuntimeError("Point-of-Care ID for test station not found")
Expand Down
22 changes: 19 additions & 3 deletions modules/templates/RLPPTM/dcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def from_result(cls, test_id, result_id, first_name, last_name, dob):
"disease": result.disease_id,
"site": facility.site_id,
"device": device.code,
"timestamp": int(probe_date.replace(microsecond=0).timestamp()),
"expires": int(expires.replace(microsecond=0).timestamp()),
"timestamp": int(cls.utc_timestamp(probe_date)),
"expires": int(cls.utc_timestamp(expires)),
"result": result.result,
}

Expand Down Expand Up @@ -434,7 +434,8 @@ def encode(self, dcci, public_key):
# Convert timestamp into datetime
timestamp = data.get("timestamp")
expires = data.get("expires")
sc = "%sZ" % datetime.datetime.fromtimestamp(timestamp).isoformat()
dt = datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc)
sc = "%sZ" % dt.replace(tzinfo=None).isoformat()

# Convert test result to code
result_codes = {"NEG": "260415000",
Expand Down Expand Up @@ -776,6 +777,21 @@ def get_dcc_credentials():

return cert, key, verify

# -------------------------------------------------------------------------
@staticmethod
def utc_timestamp(dt):
"""
Convert a tz-naive datetime instance into a UTC timestamp
@param dt: the datetime
@returns: timestamp (int)
"""

return dt.replace(microsecond = 0,
tzinfo = datetime.timezone.utc,
).timestamp()

# -------------------------------------------------------------------------
@staticmethod
def format_name(name):
Expand Down
Loading

0 comments on commit 3427fb1

Please sign in to comment.