Python script to decode the EU Covid-19 vaccine certificate

Overview

vacdec

Python script to decode the EU Covid-19 vaccine certificate

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.

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. 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.

author

Written by Hanno Böck.

Comments
  • Hey

    Hey

    Hey

    i was wondering if there is any reverse process .

    i have the json built in and I would like to convert it to QR

    would be awesome if you could provide me any tutorial or other github links . Couldnt find any

    opened by qq5678 6
  • Index out of range

    Index out of range

    Hey!

    I have a question to this beautiful peace of software ... I don't know if its an issue with Jaris Fork or in the main branch but as i am lacking python knowledge i humble ask anyways:

    /vacdec/vacdec --image-file /tmp/gettinger_v3.png

    Traceback (most recent call last): File "/vacdec/vacdec", line 241, in main() File "/vacdec/vacdec", line 228, in main covid_cert_data = data[0].data.decode() IndexError: list index out of range

    Can anyone give me a hint why this certificate shows that error please?

    Kind regards Martin

    opened by idefixgallier 5
  • Unicode characters in QR code displays below error

    Unicode characters in QR code displays below error

    {-260: {1: {'dob': 'xxxx-xx-xx', 'nam': {'fn': Traceback (most recent call last): File "vacdec.py", line 19, in pprint.pprint(cbor2.loads(decoded.value[2])) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 53, in pprint printer.pprint(object) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 139, in pprint self._format(object, self._stream, 0, 0, {}, 0) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 167, in _format p(self, object, stream, indent, allowance, context, level + 1) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 189, in _pprint_dict context, level) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 346, in _format_dict_items context, level) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 167, in _format p(self, object, stream, indent, allowance, context, level + 1) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 189, in _pprint_dict context, level) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 346, in _format_dict_items context, level) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 167, in _format p(self, object, stream, indent, allowance, context, level + 1) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 189, in _pprint_dict context, level) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 346, in _format_dict_items context, level) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 167, in _format p(self, object, stream, indent, allowance, context, level + 1) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 189, in _pprint_dict context, level) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 346, in _format_dict_items context, level) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\pprint.py", line 176, in _format stream.write(rep) File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-9: character maps to

    opened by giorgos83b 5
  • IndexError: list index out of range when trying to decode a cert

    IndexError: list index out of range when trying to decode a cert

    Hello, I get this when I try to decode a covid certificate:

    Traceback (most recent call last):
      File "vacdec", line 13, in <module>
        cert = data[0].data.decode()
    IndexError: list index out of range
    

    It works with the test certificate image here.

    opened by adrianharabula 4
  • Use requirements.txt for dependencies

    Use requirements.txt for dependencies

    I created a dependencies file requirements.txt which includes the current versions of the required files. I also updated the README file, to use this.

    opened by guerda 2
  • Can you please make a video tutorial ?

    Can you please make a video tutorial ?

    So sir can you please make a video tutorial for me, because i don't understand it perfectly. I live in the Netherlands so it would be very nice if you can show how to make that vaccination qr code.

    opened by dstouthamer 1
  • additional param to decode straight from HC1 string

    additional param to decode straight from HC1 string

    I like the script, but the QR decoding process is most of the time done already at earlier stage (e.g. an integrate app library). Could there be an option to pass the HC1 string as parameter?

    opened by marinobresciani 1
  • Termux errors

    Termux errors

    `import:` unable to open X server `' @ error/import.c/ImportImageCommand/348. import: unable to open X server `' @ error/import.c/ImportImageCommand/348. import: unable to open X server `' @ error/import.c/ImportImageCommand/348. import: unable to open X server `' @ error/import.c/ImportImageCommand/348. import: unable to open X server `' @ error/import.c/ImportImageCommand/348. import: unable to open X server `' @ error/import.c/ImportImageCommand/348. import: unable to open X server `' @ error/import.c/ImportImageCommand/348. vacdec: line 12: syntax error near unexpected token `(' vacdec: line 12: `data = pyzbar.pyzbar.decode(PIL.Image.open(sys.argv[1]))'

    opened by KanekiLeChomeur 1
  • Added signature verification

    Added signature verification

    Re-did the whole thing. Added COSE signature verification from known public ECDSA certificate.

    Proper Python logging. Proper argument handling with possibility of parsing raw data instead of a QR-code.

    opened by Cap-JaTu 1
  • Pyzbar Issue

    Pyzbar Issue

    Hi there!

    When running the script I am getting the following errors: Traceback (most recent call last): File "vacdec.py", line 8, in <module> import pyzbar.pyzbar File "/usr/local/lib/python3.7/dist-packages/pyzbar/pyzbar.py", line 7, in <module> from .wrapper import ( File "/usr/local/lib/python3.7/dist-packages/pyzbar/wrapper.py", line 143, in <module> c_uint_p, # minor File "/usr/local/lib/python3.7/dist-packages/pyzbar/wrapper.py", line 136, in zbar_function return prototype((fname, load_libzbar())) File "/usr/local/lib/python3.7/dist-packages/pyzbar/wrapper.py", line 115, in load_libzbar libzbar, dependencies = zbar_library.load() File "/usr/local/lib/python3.7/dist-packages/pyzbar/zbar_library.py", line 65, in load raise ImportError('Unable to find zbar shared library') ImportError: Unable to find zbar shared library

    Any ideas what could be happenning?

    Thanks!

    opened by ilyesm 1
  • To everyone who wants a faked QR certificate

    To everyone who wants a faked QR certificate

    Since there have been many questions on that, I think some education on the subject is in order.

    @hannob If you think this is not the right place, please feel free to close the issue.

    TLDR Faking a QR code without the private key doesn't work and will not work. If it would, all security regarding computers would be destroyed.

    Why? The QR code is cryptographically signed, using a private/public keypair. Cryptographic signatures can be generated if you have the private key (which, as the name says, is kept private). They can be validated using the public key, which is public. Since it is only signed and not encrypted, it is possible to read the message without any key at all. This is what this project does.

    Encryption vs Signature In a public/private key system, every user has a private key (which they have to keep private, so not share with anyone) and a public key. The public key is public, meaning, it is shared with everyone.

    Using these keys, there are two main things you can do: encrypt a message or sign a message (or both at once).

    To encrypt something, you use the public key of the user that should be able to read the message. This returns a message, that looks like random garbage. Only using that user's private key, you can restore the message to it's original form.

    To sign something, you use your own private key. This creates a signature, that can be attached to the message. The message itself is not modified and thus still legible (as if you would put a signature under a letter). Using the sender's public key (which everyone else has), other users can verify, that the message came from the sender and that it wasn't modified.

    What does this project do? It reads the QR code's data, without even checking the signature. So, basically, it doesn't touch the security of the QR code at all.

    What would it mean if you could just create valid QR codes without the private key? That would, literally, mean, that all security that exists in regards to digital communications would be gone. That would mean, no online banking, no online shopping, not even safe use of messaging apps or social networks. It would be close to a digital apocalypse.

    So how do I get a valid QR code? The only way to get a valid QR code is to get it from someone who has the private key. Which, to my knowledge, are only the authorities responsible for vaccinations. So go, get your shot.

    By the way: in many countries documentation regarding vaccinations count as official documents. Forging those can lead to (depending on the country) pretty substantial fines and even jail sentences of over a year. Is that really worth it?

    opened by Dakkaron 0
  • Support decode for recovery information

    Support decode for recovery information

    Some QR codes should contain recovery information per this document

    https://ec.europa.eu/health/system/files/2021-06/covid-certificate_json_specification_en_0.pdf

    opened by the-mentor 0
  • Add verbose mode

    Add verbose mode

    Changes

    Added a verbose mode -v that translates the issue and expiration dates of the certificate from Unix timestamp to UTC in the format YYYY-MM-DD HH:MM:SS.

    The verbose mode also decodes the json values for:

    • Disease agent targeted
    • Vaccine prophylaxis
    • Vaccine medicinal product
    • Vaccine manufacturer
    • Test type
    • Test manufacturer
    • Test result

    Although it shows the original encoded value too.

    In general, it gives more information to the reader in a more structured way.

    Code Structure

    I didn't want to modify the original structure of the code, so I just added the new functionality at the end of the file while preserving the original organization and functionality.

    opened by Algafix 0
  • strip spaces and strip 2D coding prefix if it conforms to eHealth Network Version 1.3, section 2.3

    strip spaces and strip 2D coding prefix if it conforms to eHealth Network Version 1.3, section 2.3

    Per specs https://ec.europa.eu/health/sites/default/files/ehealth/docs/digital-green-certificates_v3_en.pdf

    1. strips spaces around the string (typical issue when pasting base45 data through emails, ...)
    2. strip prefix, validated by regex, if it conforms with spec section "2.3 2D Code Versioning" (support for NL1, CZ1, HC2, ...)

    This might result in trying to parse unsupported data (newer version of certificate) but the basics (b45+zlib) won't ever imho change, cbor will only contain different document

    This should fix at least #15

    opened by smarek 2
  • I get ValueError(

    I get ValueError("Invalid base45 string")

    Hello, i've try with the exemple string and it working well but with my personnal string i get ValueError("Invalid base45 string"), any idea ?

    opened by Mindrix95 16
Owner
Hanno Böck
Hanno Böck
VaccineAlarm is a simple python script that allows user to get notified when their desired vaccine doses are available at vaccine centers near them.

Introduction VaccineAlarm is a simple python script that allows user to get notified when their desired vaccine doses are available at vaccine centers

Ankit Tripathi 5 Nov 26, 2021
Get Notified about vaccine availability in your location on email & sms ✉️! Vaccinator Octocat tracks & sends personalised vaccine info everday. Go get your shot ! 💉

Vaccinater Get Notified about vaccine availability in your location on email & sms ✉️ ! Vaccinator Octocat tracks & sends personalised vaccine info ev

Mayukh Pankaj 6 Apr 28, 2022
Telegram Bot to check covid vaccine slot availability on CoWin site

Cowin Assist Telegram Bot Check the bot here @cowinassistbot. This is a simple Telegram bot to Check slots availability Get an alert when slots become

null 32 Jun 21, 2022
Light weight Scripts and Apps for checking availability of Covid Vaccines in India. Notifies when vaccine becomes avialable in your area.

vaccine-checker Light weight Scripts and Apps for checking availability of Covid Vaccines in India. Notifies when vaccine becomes avialable in your ar

Abishek V Ashok 8 Jun 16, 2021
An analysis of the efficiency of the COVID-19 vaccine

VaccineEfficiency ?? An analysis of the efficiency of the COVID-19 vaccine 3 Methods 1️⃣ Compare country's vaccination data to number of day- to-day c

Stephanie Younes 1 Dec 10, 2021
Script to automatically book a vaccine slot on Doctolib for today or tomorrow, following rules from the French Government.

DOCTOSHOTGUN This script lets you automatically book a vaccine slot on Doctolib for today or tomorrow, following rules from the French Government. Pyt

Romain Bignon 560 Dec 19, 2022
Ini Hanya Shortcut Untuk Menambahkan Kunci Tambahan Pada Termux & Membantu Para Nub Yang Decode Script Orang:v

Ini Hanya Shortcut Untuk Menambahkan Kunci Tambahan Pada Termux & Membantu Para Nub Yang Decode Script Orang:v

Lord_Ammar 1 Jan 23, 2022
Automatically searching for vaccine appointments

Vaccine Appointments Automatically searching for vaccine appointments Usage To copy this package, run: git clone https://github.com/TheIronicCurtain/v

null 58 Apr 13, 2021
Bot to notify when vaccine appointments are available

Vaccine Watch Bot to notify when vaccine appointments are available. Supports checking Hy-Vee, Walgreens, CVS, Walmart, Cosentino's stores (KC), and B

Peter Carnesciali 37 Aug 13, 2022
A telegram bot that messages you available vaccine appointments in the Veneto region

Serenissimo, domande frequenti Chi sei? Sono Alberto Granzotto, libero professionista a Berlino. Mi occupo di servizi software, privacy, decentralizza

vrde 31 Sep 30, 2022
Pls give vaccine.

Pls Give Vaccine A script to spam yourself with vaccine notifications. Explore the docs » View Demo · Report Bug · Request Feature Table of Contents A

Rohan Mukherjee 3 Oct 27, 2021
A Telegram Bot which notifies the user when a vaccine is available on CoWin Platform.

Cowin Vaccine Availability Notifier Telegram Bot A bot that notifies the available vaccines at given district in realtime. Introduction • Requirements

Arham Shah 7 Jul 31, 2021
Decode the Ontario proof of vaccination QR code

Decode the contents of the Ontario Proof of Vaccination (the "Smart Health Card QR Code") Output This is from my QR code, hopefully fully redacted alt

Wesley Ellis 4 Oct 22, 2021
This very basic script can be used to automate COVID-19 vaccination slot booking on India's Co-WIN Platform.

COVID-19 Vaccination Slot Booking Script This very basic CLI based script can be used to automate covid vaccination slot booking on Co-WIN Platform. I

null 605 Dec 14, 2022
A simple script & container to pull COVID data from covidlive.com.au and post a summary to a slack channel

CovidLive AU Summary Slackbot This bot is a very simple slackbot that pulls data, summarises and posts up to date AU COVID stats to a provided slack c

James 3 Dec 18, 2021
A python api to get info on covid-19

A python api to get info on covid-19

roof 2 Sep 18, 2022
Tracker to check the covid shot slot availability in India and send mobile alerts via Twilio Messaging Service.

Cowin-Slot-Tracker Tracker to check the covid vaccine slot availability in India and send mobile notifications through Twilio Messaging Service. Requi

invalid username 27 Nov 12, 2022
Bot per controllare la disponibilità di appuntamenti per la vaccinazione Covid-19 in Veneto

VaxBot9000 Prerequisites Python 3.9 Poetry latest version of geckodriver Firefox Setup poetry install Copy config.sample.toml to config.toml and edit

Augusto Zanellato 5 Jun 13, 2021
An open source API to validate the EU Covid Certificates / Green Certificates

Open Covid Certificate Validator This an open source API to validate EU Digital COVID Certificates. It receives a COVID certificate and validates it u

Merlin Schumacher 47 May 30, 2022