Repository: hannob/vacdec Branch: main Commit: ec06f1270a76 Files: 4 Total size: 5.0 KB Directory structure: gitextract_bf5j97i9/ ├── LICENSE ├── README.md ├── setup.py └── vacdec ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE ================================================ This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to ================================================ FILE: README.md ================================================ # vacdec Python script to decode the EU Covid-19 vaccine certificate, as [specified by the EU](https://ec.europa.eu/health/ehealth/covid-19_en). This script takes an image with a QR code of a vaccine certificate as the parameter and will show the certificate's content. **It will not validate the signature.** A [fork of this script with signature verification exists](https://github.com/HQJaTu/vacdec/tree/signature-verification). The code is very short and should provide an easy way to understand how these certificates are encoded: * The QR code encodes a string starting with "HC1:". * The string following "HC1:" is base45 encoded. * Decoding the base45 leads to zlib-compressed data. * Decompression leads to a CBOR Web Token structure. ## setup You will need the python pillow, pyzbar, cbor2 and base45 packages. Additionally, you need zbar. For Mac OS X, it can be installed via `brew install zbar`, on Debian systems via `apt install libzbar0`. [Source](https://pypi.org/project/pyzbar/) If you want to install `cbor2` on Windows, you might get an error that you need the Microsoft Visual C++ Extension installed. This is only required if you want to have the `cbor2` optional C extension installed. You can skip it by setting the environment variable `CBOR2_BUILD_C_EXTENSION=0` before installing it via `pip`. You can install them via your distribution or via pip: ``` pip install base45 cbor2 pillow pyzbar ``` ## usage Run: ``` ./vacdec [image] ``` [image] can be an image in any format pillow supports, including of course PNG and JPG. A test certificate can be found [here](https://github.com/Digitaler-Impfnachweis/certification-apis/tree/master/examples). ## author Written by [Hanno Böck](https://hboeck.de/). ================================================ FILE: setup.py ================================================ #!/usr/bin/env python3 import os import setuptools package_name = 'vacdec' f = open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md'), encoding='utf-8') readme = f.read() f.close() setuptools.setup( name=package_name, version="0.0.2", description="Decode the EU Covid-19 vaccine certificate", long_description=readme, long_description_content_type='text/markdown', author="Hanno Böck", author_email='hanno@hboeck.de', url='https://github.com/hannob/vacdec', packages=[], scripts=['vacdec'], python_requires='>=3', install_requires=[ 'base45', 'cbor2', 'pillow', 'pyzbar' ], license="CC0", zip_safe=True, keywords=['vaccine'], classifiers=[ 'Development Status :: 4 - Beta', 'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication', 'Natural Language :: English', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', ], ) ================================================ FILE: vacdec ================================================ #!/usr/bin/env python3 import sys import zlib import pprint import argparse import PIL.Image import pyzbar.pyzbar import base45 import cbor2 ap = argparse.ArgumentParser() ap.add_argument("input", nargs=1, help="Filename (default: image file, e.g. png/jpg)") ap.add_argument("-t", "--textfile", action="store_true", help="Input as text file") ap.add_argument("-c", "--commandline", action="store_true", help="Input via command line") args = ap.parse_args() if args.textfile: with open(args.input[0]) as f: cert = f.read() elif args.commandline: cert = args.input[0] else: data = pyzbar.pyzbar.decode(PIL.Image.open(args.input[0])) if data == []: sys.stderr.write("Error: Unable to decode QR code\n") sys.exit(1) cert = data[0].data.decode() b45data = cert.replace("HC1:", "") zlibdata = base45.b45decode(b45data) cbordata = zlib.decompress(zlibdata) decoded = cbor2.loads(cbordata) pprint.pprint(cbor2.loads(decoded.value[2]))