Created
November 22, 2021 08:05
-
-
Save pagdot/60782f5c330f974157d365f194998ccf to your computer and use it in GitHub Desktop.
Greenpass Scripts
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 json | |
import zlib | |
import base64 | |
import cbor2 # type: ignore | |
import cose.algorithms # type: ignore | |
import cose.keys.curves # type: ignore | |
import cose.keys.keytype # type: ignore | |
import requests | |
def valueSetFormatter(valuesets): | |
for x in valuesets["v"]: | |
x["v"] = json.loads(x["v"]) | |
return valuesets | |
def rulesFormatter(rules): | |
for x in rules["r"]: | |
x["r"] = json.loads(x["r"]) | |
return rules | |
def trustlistFormatter(trustlist): | |
for x in trustlist["c"]: | |
x["i"] = base64.b64encode(x["i"]).decode('utf-8') | |
x["c"] = base64.b64encode(x["c"]).decode('utf-8') | |
return trustlist | |
items = [ | |
{ 'name': "trustlist", 'formatter': trustlistFormatter}, | |
{ 'name': "rules", 'formatter': rulesFormatter}, | |
{ 'name': "valuesets", 'formatter': valueSetFormatter}, | |
] | |
for i in items: | |
response = requests.get("https://dgc-trust.qr.gv.at/" + i['name']) | |
if not response.ok: | |
print("Download failed: status code {}\n{}".format(response.status_code, response.text)) | |
exit | |
cbor = cbor2.loads(response.content) | |
obj = i['formatter'](cbor) | |
with open(i['name'] + ".json", "w") as outfile: | |
json.dump(obj, outfile, indent=4) |
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 qrtools | |
import sys | |
import cbor2 | |
import base45 | |
import zlib | |
import json | |
from cose.messages import CoseMessage, Sign1Message # type: ignore | |
if len(sys.argv) != 2: | |
print("Usage: {} <image>".format(sys.argv[0])) | |
exit(1) | |
qr = qrtools.QR() | |
qr.decode(sys.argv[1]) | |
compressed = base45.b45decode(qr.data[4:]) | |
cose = zlib.decompress(compressed) | |
msg = CoseMessage.decode(cose) | |
obj = cbor2.loads(msg.payload) | |
print(json.dumps(obj, indent=4)) |
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
cose | |
base45 | |
cbor2 | |
qrtools |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment