Created
September 11, 2021 02:14
-
-
Save wabzqem/9e970f45cf6811ccf4c7d7b6e0015880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cbor2 | |
from cose.algorithms import Es256 | |
from cose.headers import Algorithm, KID | |
from cose.keys.keyparam import EC2KP, EC2KpCurve, EC2KpD, EC2KpX, EC2KpY, KpKeyOps, KpKty | |
from cose.keys.keytype import KtyEC2 | |
from cose.messages import Sign1Message | |
from cose.keys import CoseKey, keyops, curves | |
from binascii import unhexlify, hexlify | |
from pprint import pprint | |
import zlib | |
import base45 | |
import qrcode | |
import json | |
priv_key = { | |
KpKty: KtyEC2, | |
EC2KpCurve: curves.P256, | |
KpKeyOps: [keyops.SignOp, keyops.VerifyOp], | |
EC2KpX: unhexlify(b'fa5e3ee7ccf4b52056fba3f275a3c3a8867c9ffcccfac20f59e9db49bfccf26e'), | |
EC2KpY: unhexlify(b'6b278200cd45d22127525e9c7272b67b722f029e40ec55547886a1ae0ffde966'), | |
EC2KpD: unhexlify(b'<private redacted>') | |
} | |
with open("response.json") as jsonFile: | |
json_data = json.load(jsonFile) | |
jsonFile.close() | |
out_obj = { | |
1: "AU", | |
"4": json_data['immunisationRecordData']['immunisationRecordMetadata']['dateValidTo'], | |
"6": json_data['immunisationRecordData']['immunisationRecordMetadata']['dateGenerated'], | |
"-260": { | |
"1": { | |
"dob": json_data['immunisationRecordData']['individualDetails']['dateOfBirth'], | |
"nam": { | |
"fn": json_data['immunisationRecordData']['individualDetails']['lastName'], | |
"gn": "{} {}".format(json_data['immunisationRecordData']['individualDetails']['firstName'], json_data['immunisationRecordData']['individualDetails']['initial']).strip(), | |
"fnt": json_data['immunisationRecordData']['individualDetails']['lastName'].upper(), | |
"gnt": "{} {}".format(json_data['immunisationRecordData']['individualDetails']['firstName'], json_data['immunisationRecordData']['individualDetails']['initial']).strip().upper() | |
}, | |
"ver": "1.3.0" | |
}, | |
} | |
} | |
out_obj['-260']["1"]["v"] = [] | |
for k, v in enumerate(json_data['immunisationRecordData']['immunisationStatus']['vaccineInfo']): | |
pprint(k) | |
pprint(v) | |
entry = { | |
"tg": "840539006", # COVID-19 | |
"co": "AU", # State where administered | |
"is": "Australian Department of Health", # Certificate issuer | |
"ci": json_data['immunisationRecordData']['immunisationRecordMetadata']['immunisationRecordId'] | |
} | |
if (v['vaccineBrand'] == 'Pfizer Comirnaty'): | |
entry["vp"] = "1119349007" # a SARS-CoV-2 mRNA vaccine | |
entry["mp"] = "EU/1/20/1528" # Comirnaty | |
entry["ma"] = "ORG-100030215" # Biontech Manufacturing GmbH (is this what we get?) | |
entry["dn"] = k # number in series of doses | |
entry["sd"] = len(json_data['immunisationRecordData']['immunisationStatus']['vaccineInfo']) # overall number in series | |
entry["dt"] = v['immunisationDate'] | |
out_obj['-260']["1"]["v"].append(entry) | |
pay = cbor2.dumps(out_obj) | |
msg = Sign1Message(phdr = {Algorithm: Es256, KID: b'18abc89f54946a9e'}, payload = pay) | |
cose_key = CoseKey.from_dict(priv_key) | |
msg.key = cose_key | |
encoded = msg.encode() | |
compressed = zlib.compress(encoded) | |
string = "HC1:{}".format(base45.b45encode(compressed).decode()) | |
qrcode.make(string).save("some_file.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment