[
  {
    "path": "LICENSE",
    "content": "This is free and unencumbered software released into the public domain.\n\nAnyone is free to copy, modify, publish, use, compile, sell, or\ndistribute this software, either in source code form or as a compiled\nbinary, for any purpose, commercial or non-commercial, and by any\nmeans.\n\nIn jurisdictions that recognize copyright laws, the author or authors\nof this software dedicate any and all copyright interest in the\nsoftware to the public domain. We make this dedication for the benefit\nof the public at large and to the detriment of our heirs and\nsuccessors. We intend this dedication to be an overt act of\nrelinquishment in perpetuity of all present and future rights to this\nsoftware under copyright law.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR\nOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\nFor more information, please refer to <https://unlicense.org>\n"
  },
  {
    "path": "README.md",
    "content": "# vacdec\nPython script to decode the EU Covid-19 vaccine certificate, as [specified by the EU](https://ec.europa.eu/health/ehealth/covid-19_en).\n\nThis script takes an image with a QR code of a vaccine certificate as\nthe parameter and will show the certificate's content.\n**It will not validate the signature.**\n\nA [fork of this script with signature verification exists](https://github.com/HQJaTu/vacdec/tree/signature-verification).\n\nThe code is very short and should provide an easy way to understand\nhow these certificates are encoded:\n\n* The QR code encodes a string starting with \"HC1:\".\n* The string following \"HC1:\" is base45 encoded.\n* Decoding the base45 leads to zlib-compressed data.\n* Decompression leads to a CBOR Web Token structure.\n\n## setup\n\nYou 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/)\nIf 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`.\n\nYou can install them via your distribution or via pip:\n\n```\npip install base45 cbor2 pillow pyzbar\n```\n\n## usage\n\nRun:\n\n```\n./vacdec [image]\n```\n\n[image] can be an image in any format pillow supports, including of\ncourse PNG and JPG.\n\nA test certificate can be found [here](https://github.com/Digitaler-Impfnachweis/certification-apis/tree/master/examples).\n\n## author\n\nWritten by [Hanno Böck](https://hboeck.de/).\n"
  },
  {
    "path": "setup.py",
    "content": "#!/usr/bin/env python3\n\nimport os\nimport setuptools\n\npackage_name = 'vacdec'\n\nf = open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md'), encoding='utf-8')\nreadme = f.read()\nf.close()\n\nsetuptools.setup(\n    name=package_name,\n    version=\"0.0.2\",\n    description=\"Decode the EU Covid-19 vaccine certificate\",\n    long_description=readme,\n    long_description_content_type='text/markdown',\n    author=\"Hanno Böck\",\n    author_email='hanno@hboeck.de',\n    url='https://github.com/hannob/vacdec',\n    packages=[],\n    scripts=['vacdec'],\n    python_requires='>=3',\n    install_requires=[\n        'base45',\n        'cbor2',\n        'pillow',\n        'pyzbar'\n    ],\n    license=\"CC0\",\n    zip_safe=True,\n    keywords=['vaccine'],\n    classifiers=[\n        'Development Status :: 4 - Beta',\n        'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',\n        'Natural Language :: English',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3 :: Only',\n        'Programming Language :: Python :: 3.8',\n        'Programming Language :: Python :: 3.9',\n        'Programming Language :: Python :: 3.10',\n    ],\n)\n"
  },
  {
    "path": "vacdec",
    "content": "#!/usr/bin/env python3\n\nimport sys\nimport zlib\nimport pprint\nimport argparse\n\nimport PIL.Image\nimport pyzbar.pyzbar\nimport base45\nimport cbor2\n\nap = argparse.ArgumentParser()\nap.add_argument(\"input\", nargs=1,\n                help=\"Filename (default: image file, e.g. png/jpg)\")\nap.add_argument(\"-t\", \"--textfile\", action=\"store_true\",\n                help=\"Input as text file\")\nap.add_argument(\"-c\", \"--commandline\", action=\"store_true\",\n                help=\"Input via command line\")\nargs = ap.parse_args()\n\nif args.textfile:\n    with open(args.input[0]) as f:\n        cert = f.read()\nelif args.commandline:\n    cert = args.input[0]\nelse:\n    data = pyzbar.pyzbar.decode(PIL.Image.open(args.input[0]))\n    if data == []:\n        sys.stderr.write(\"Error: Unable to decode QR code\\n\")\n        sys.exit(1)\n    cert = data[0].data.decode()\n\nb45data = cert.replace(\"HC1:\", \"\")\n\nzlibdata = base45.b45decode(b45data)\n\ncbordata = zlib.decompress(zlibdata)\n\ndecoded = cbor2.loads(cbordata)\n\npprint.pprint(cbor2.loads(decoded.value[2]))\n"
  }
]