-
-
Save sghctoma/820de203d3af56ca633e434c50caa101 to your computer and use it in GitHub Desktop.
Scritpts to handle Digital Green Certificates
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
#!/usr/bin/env python3 | |
import binascii | |
import json | |
import sys | |
import zlib | |
import base45 | |
import base64 | |
import cbor2 | |
import PyPDF2 | |
from cose.messages import CoseMessage | |
from pyzbar import pyzbar | |
from PIL import Image | |
with open(sys.argv[1], 'rb') as f: | |
pdf = PyPDF2.PdfFileReader(f) | |
qrobject = pdf.getPage(0)['/Resources']['/XObject']['/Im5'] | |
qrimage = Image.frombytes('1', (qrobject['/Width'], qrobject['/Height']), qrobject.getData()) | |
qrdata = pyzbar.decode(qrimage) | |
decoded = base45.b45decode(qrdata[0].data[4:]) | |
decompressed = zlib.decompress(decoded) | |
cose_message = CoseMessage.decode(decompressed) | |
sig = cose_message.signature | |
r = int(binascii.hexlify(sig[:32]), 16) | |
s = int(binascii.hexlify(sig[32:]), 16) | |
print(f"signature: {base64.b64encode(sig).decode('utf-8')}\n\tr: {r}\n\ts: {s}") | |
payload = cbor2.loads(cose_message.payload) | |
print(f"payload: \n{json.dumps(payload, 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
#!/usr/bin/env python3 | |
import binascii | |
import json | |
import sys | |
import zlib | |
import base45 | |
import base64 | |
import cbor2 | |
from cose.messages import CoseMessage | |
from pyzbar import pyzbar | |
from PIL import Image | |
qrimage = Image.open(sys.argv[1]) | |
qrdata = pyzbar.decode(qrimage) | |
decoded = base45.b45decode(qrdata[0].data[4:]) | |
decompressed = zlib.decompress(decoded) | |
cose_message = CoseMessage.decode(decompressed) | |
sig = cose_message.signature | |
r = int(binascii.hexlify(sig[:32]), 16) | |
s = int(binascii.hexlify(sig[32:]), 16) | |
print(f"signature: {base64.b64encode(sig).decode('utf-8')}\n\tr: {r}\n\ts: {s}") | |
payload = cbor2.loads(cose_message.payload) | |
print(f"payload: \n{json.dumps(payload, 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
#!/usr/bin/env python3 | |
import json | |
import sys | |
import zlib | |
import base45 | |
import cbor2 | |
import PyPDF2 | |
import qrcode | |
from cose.messages import CoseMessage | |
from pyzbar import pyzbar | |
from PIL import Image | |
with open(sys.argv[1], 'rb') as f: | |
pdf = PyPDF2.PdfFileReader(f) | |
qrobject = pdf.getPage(0)['/Resources']['/XObject']['/Im5'] | |
qrimage = Image.frombytes('1', (qrobject['/Width'], qrobject['/Height']), qrobject.getData()) | |
qrdata = pyzbar.decode(qrimage) | |
decoded = base45.b45decode(qrdata[0].data[4:]) | |
decompressed = zlib.decompress(decoded) | |
decompressed = decompressed.replace(b'Budapest', b'xxxxxxxx') | |
compressed = zlib.compress(decompressed) | |
encoded = base45.b45encode(compressed) | |
qr = qrcode.QRCode( | |
version=1, | |
error_correction=qrcode.constants.ERROR_CORRECT_H, | |
box_size=10,border=4) | |
qr.add_data(b'HC1:' + encoded) | |
qr.make(fit=True) | |
img = qr.make_image(fill_color="black", back_color="white") | |
img.save("wrong.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment