Giter Club home page Giter Club logo

pyverificac19's Introduction

VerificaC19 Python SDK

🐍 VerificaC19 SDK implementation for Python.

Latest Version CI codecov Supported Python versions Downloads Code style: black

Requirements

  • Python version >= 3.7
  • MongoDB version >= 5.x (used to store CRL)

Make sure zbar is installed in your system. Source.

  • For Mac OS X, it can be installed via brew install zbar
  • Debian systems via apt install libzbar0
  • Fedora / Red Hat dnf install zbar

Install

pip install verificac19

Usage

Download and cache rules, CRL data and DSCs

You can download and cache rules, CRL Data and DSCs using service.

from verificac19 import service

service.update_all()

update_all may rise VerificaC19Error

from verificac19.exceptions import VerificaC19Error

⚠️ By default rules and DSCs will be cached in local folder, to change it please set VC19_CACHE_FOLDER env variable.

⚠️ CRL data will be stored in a MongoDB database. By default the connection string is mongodb://root:example@localhost:27017/VC19?authSource=admin, if you want to change it, set VC19_MONGODB_URL env variable.

Verify a DCC

You can verify a DCC using verifier. You can verify a DCC using verify_image for images and verify_raw for raw data.

from verificac19 import verifier

result = verifier.verify_image("my_dcc.png")
result = verifier.verify_raw("HC1:GH.....1GH")

verify_image and verify_raw return a dictionary containing person name, date_of_birth, code and a message alongside the result

{
  'code': verifier.Codes.NOT_VALID, 
  'result': False, 
  'message': 'Certificate is not valid', 
  'person': 'Sčasný Svätozár', 
  'date_of_birth': '1984-09-27'
}

you can compare the resulting code with verifier.Codes values

Code Description Result
VALID Certificate is valid True
⚠️ TEST_NEEDED Test needed if verification mode is BOOSTER_DGP False
NOT_VALID Certificate is not valid False
NOT_VALID_YET Certificate is not valid yet False
REVOKED Certificate is revoked False
NOT_EU_DCC Certificate is not an EU DCC False

for example

result = verifier.verify_image("my_dcc.png")
assert result['code'] == verifier.Codes.NOT_VALID

⚠️ verify_image and verify_raw may rise VerificaC19Error in case you cache is not initialized. You need to call service.update_all() at least once!

Verification mode

If you want to change verification mode and verify whether a certificate is a Super Green Pass or not, you need to pass verifier.Mode.SUPER_DGP to verify_image and verify_raw methods.

from verificac19 import verifier

result = verifier.verify_image("my_dcc.png", verifier.Mode.SUPER_DGP)

verifier.Mode exposes 2 possible values

Code Description
NORMAL_DGP Normal verification (default value)
SUPER_DGP Super Green Pass verification
BOOSTER_DGP Booster verification mode

Details

  • SUPER_DGP Mode: VerificaC19 SDK considers a green certificate valid only for people who have been vaccinated against or who have recovered from Covid19, and will prevent all the others from entering bars, restaurants, cinemas, gyms, theatres, discos and stadiums.

  • BOOSTER_DGP Mode: VerificaC19 SDK considers green certificates generated after a booster dose to be valid. Furthermore, green certificates generated after the first vaccination cycle or recovery with the simultaneous presentation of a digital document certifying the negative result of a SARS-CoV-2 test are considered valid.

Development

Install dev dependencies

pip install -r requirements-dev.txt

Make sure zbar is installed in your system. Source.

  • For Mac OS X, it can be installed via brew install zbar
  • Debian systems via apt install libzbar0
  • Fedora / Red Hat dnf install zbar

CRL data will be stored in a MongoDB database. This repository provides a simple docker-compose.yml file (dev instance) with a replica set. By default the connection string is mongodb://root:example@localhost:27017/VC19?authSource=admin, if you want to change it, set VC19_MONGODB_URL env variable.

Run tests

make test

Run examples

python -m examples.<example_name>

Authors

Copyright (c) 2022 - Lotrèk Digital Agency

Contributors

Thank you to everyone involved for improving this project, day by day.

License

This library is available under the MIT license.

pyverificac19's People

Contributors

b0tero avatar bnznamco avatar edoardo7 avatar edoaxyz avatar freder211 avatar mino89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pyverificac19's Issues

Creare metodo per esporre i settings e la blacklist

  • Creare un metodo per esporre i settings in modo che sia facile per gli sviluppatori trovare gli elementi

Ad esempio

get_setting_value('vaccine_end_day_complete', 'Sputnik-V')
  • Creare un metodo per chiedere se un elemento è presente o meno in blacklist

Ad esempio

is_blacklisted('il mio UVCI')

Creare un metodo per catalogare il DCC

  • Creare un metodo che riceverà in input un DCC e deciderà se si tratta di

  • Vaccino

  • Recovery

  • Test rapido/molecolare

Reference Technical Specifications
for EU Digital COVID Certificates
JSON Schema Specification

  • Definire una struttura di ritorno del risultato di verifica, ricordarsi che i codici di ritorno devono variare a seconda del risultato
Code Description
VALID Certificate is valid
NOT_VALID Certificate is not valid
NOT_VALID_YET Certificate is not valid yet
NOT_EU_DCC Certificate is not an EU DCC

Un possibile esempio di valore di ritorno è

{
   code: NOT_VALID,
   result: False
   message: 'Invalid signature',
}
  • Implementare il fatto che se si tratta di Test rapido/molecolare e la modalità super green pass è attiva, allora il certificato non è valido (NOT_VALID)
  • Implementare il fatto che se il Vaccino è Sputnik-V e non è stato fatto a San Marino 🇸🇲 allora bisogna rifiutarlo (NOT_VALID)

Creare un metodo per esporre i DSC

  • Creare un metodo che dato un KID ritorna il DSC corrispondente
my_dsc = get_dsc_by_kid(dcc.kid)
# A seguire, verifica firma DCC

Questo metodo verrà usato dal team di Verifica per prendere un DSC per verificare il certificato

Creare un metodo per scaricare i DSC

  • Creare un metodo richiamabile dall'utente per scaricare i DSC

I DSC vengono scaricati attraverso una API che deve essere richiamata ciclicamente per scaricare i DSC

https://get.dgc.gov.it/v1/dgc/signercertificate/update

In risposta oltre al DSC si ottengono negli header il KID corrispondente e il token necessario per ottenere il prossimo DSC

X-KID: 25QCxBrBJvA=
X-RESUME-TOKEN: 1

Un esempio semplice: ministero-salute/dcc-utils#1 (comment)

  • Memorizzare i DSC in un file JSON in memoria, indicizzando i DSC con il relativo KID
{
  "5EiHqlAm4=": "-----BEGIN CERTIFICATE-----\nMIIH9jCQA...jkYBBgIpdw=\n-----END CERTIFICATE-----",
  "nJkLGpT68=": "-----BEGIN CERTIFICATE-----\nMIIDpqHbd...IIxA==\n-----END CERTIFICATE-----",
  "TmDTMuL6E=": "-----BEGIN CERTIFICATE-----\nMIIDJTCCAsy...nrDq+NRUg=\n-----END CERTIFICATE-----",
}

Inserire l'apposito header User-agent nelle richieste verso le API

Inserire all'interno delle richieste verso le API l'apposito header User-Agent nella forma

User-Agent: <sdk>-<sdk-technology>/<sdk-version>

È possibile omettere -<sdk-technology> se la tecnologia è già specificata nel nome (ad esempio verificac19-sdk-php).

Ad esempio nel caso verificac19-sdk per Node.js lo User-Agent sarà

User-Agent: verificac19-sdk-node/0.9.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.