Giter VIP home page Giter VIP logo

dcc-utils's Introduction

DCC Utils


Table of contents

Context

This NPM package contains a set of utilities to read EU Digital COVID Certificates, verify signatures and rules.

Installation

npm install dcc-utils

Usage

Get a DCC from an image

const { DCC } = require('dcc-utils');

const dcc = await DCC.fromImage('/data/QRCodeDCC.png');

or raw data

const dcc = await DCC.fromRaw('HC1:6BF+70790T9WJWG.FKY*4GO0.O1CV2 O5 N2FBBRW1*70HS8WY04AC*WIFN0AHCD8KD97TK0F90KECTHGWJC0FDC:5AIA%G7X+AQB9746HS80:54IBQF60R6$A80X6S1BTYACG6M+9XG8KIAWNA91AY%67092L4WJCT3EHS8XJC$+DXJCCWENF6OF63W5NW6WF6%JC QE/IAYJC5LEW34U3ET7DXC9 QE-ED8%E.JCBECB1A-:8$96646AL60A60S6Q$D.UDRYA 96NF6L/5QW6307KQEPD09WEQDD+Q6TW6FA7C466KCN9E%961A6DL6FA7D46JPCT3E5JDLA7$Q6E464W5TG6..DX%DZJC6/DTZ9 QE5$CB$DA/D JC1/D3Z8WED1ECW.CCWE.Y92OAGY8MY9L+9MPCG/D5 C5IA5N9$PC5$CUZCY$5Y$527B+A4KZNQG5TKOWWD9FL%I8U$F7O2IBM85CWOC%LEZU4R/BXHDAHN 11$CA5MRI:AONFN7091K9FKIGIY%VWSSSU9%01FO2*FTPQ3C3F');

See get_dcc_from_raw_and_image.js example.

With dcc-utils you can also verify its signature

const verified = await dcc.checkSignatureWithCertificate(myCert);
if (verified) {
  console.log(dcc.payload);
}

If you need to use different types of key, use checkSignature method (see verify_signature_raw.js example).

See verify_signature.jsand verify_signature_from_list.js examples. Signature verification uses CoseJS library under the hood, see CoseJS documentation for more details.

To load te cerficates from https://get.dgc.gov.it you can use fetch_certificates.js The exported format is compatible with the method dcc.checkSignatureWithKeysList

With dcc-utils you can evaluate business rules against a DCC

const { DCC, Rule } = require('dcc-utils');

const dcc = await DCC.fromImage('/data/QRCodeDCC.png');
const rule = Rule.fromFile('de_v0001_rule.json', {
  validationClock: new Date().toISOString(),
});

rule.evaluateDCC(dcc)

You can also get rules from API

const { DCC, Rule } = require('dcc-utils');

const dcc = await DCC.fromImage('/data/QRCodeDCC.png');
const VR_DE_0001_RULE_URL = "https://dgca-businessrule-service.cfapps.eu10.hana.ondemand.com/rules/de/bc092f8000606c57a8fd80bc7a31ff720a4c4428510d88c774bed2f839c76b66";
const response = await fetch(VR_DE_0001_RULE_URL);
const ruleJSON = await response.json();
const rule = Rule.fromJSON(ruleJSON, {
  validationClock: new Date().toISOString(),
});

rule.evaluateDCC(dcc)

See check_rules.js and check_rules_from_api.js examples.

Contributing

Contributions are most welcome. Before proceeding, please read the Code of Conduct for guidance on how to approach the community and create a positive environment. Additionally, please read our CONTRIBUTING file, which contains guidance on ensuring a smooth contribution process.

Contributors

Here is a list of contributors. Thank you to everyone involved for improving this project, day by day.

Licence

Authors / Copyright

Copyright 2021 (c) Ministero della Salute.

Please check the AUTHORS file for extended reference.

Licence details

The licence for this repository is a GNU Affero General Public Licence version 3 (SPDX: AGPL-3.0). Please see the LICENSE file for full reference.

dcc-utils's People

Contributors

astagi avatar dependabot[bot] avatar dnldsht avatar elgorditosalsero avatar lucadentella avatar rebuglio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dcc-utils's Issues

Negative Test QR doesn't work

Hi, i have a green pass issued due to negative test that dcc-utils and covid-pass-verifier.com can't validate. It gives error on this two while VerificaC19 is working.

Please let me know, thanks

Can't verify any QR

Issue content

Hey there, first of all, thank you for the repo.

I am trying to use this library but it seems that besides the provided QR I can't veirfy any other one. All the QR I am trying are taken from the IO italian app.

The cose library keep returning this error: "Signature missmatch". To do the verification I have tried to use the provided cert and the one from the government (https://get.dgc.gov.it/v1/dgc/signercertificate/update) with the same result.

I am also having problem using the tool provided in the EU repo to check the DCC (https://github.pathcheck.org/debug.html), with the QR provided in this repo it validates, but it doesn't with any one I have tried.

The only visible difference in the provided QR and the one I am trying it's the "ver" property in the payload. The provided one has '1.2.1', all the others have '1.0.0'.

The issue is on the IO side with a malformed or non standard QR generation? To note that all my QR are valid with the official italian app (VerificaC19).

Thanks in advance,
Matteo.

invalid CertLogic expression: undefined

    const dcc = await DCC.fromRaw(code.data);
    var myCert = require("./certificates.json")
    const verified = await dcc.checkSignatureWithKeysList(myCert);
    if (verified) {

        const VR_DE_0001_RULE_URL = "https://get.dgc.gov.it/v1/dgc/settings";
        const response = await fetch(VR_DE_0001_RULE_URL);
        const ruleJSON = await response.json();
        const rule = Rule.fromJSON(ruleJSON, {
            validationClock: new Date().toISOString(),
        });

        rule.evaluateDCC(dcc)
    }

la verifica del certificato funziona, ma restituisce questo errore nel momento in cui provo ad applicare le rules:

image

sto utilizzando node.js 14

green pass in black list

Issue content

I wanted to know how to check if the green pass is valid by checking with the black list.

Can anyone tell me how and where to get the updated black list?

List of Certificates

Hello, my issue is a question.

In the example verify_signature_from_list.js I have seen that is used this url
https://raw.githubusercontent.com/bcsongor/covid-pass-verifier/35336fd3c0ff969b5b4784d7763c64ead6305615/src/data/certificates.json

for get the certificates, but I can use this list and it is always valid or it is only for example purpose?

In this case, Is there a url where we can get the valid certificates?

Thankyou.

How to verify German covid certificate

Hi,

I'm a bit lost here. I need to verify in our mobile app the covid certificate. Is there an step by step tutorial or an how to?

What I have to do, do verify German covid certificate?

Signing Certificate

Issue content

I would now if the file signing_certificate.crt is generic for check all Green Pass or needed a specific one.

Thanks.

Angular bug

Angular CLI: 12.0.5
Node: 14.17.1
Package Manager: npm 6.14.13
OS: win32 x64

Description

Hi, i'm trying to use dcc-utils with new empty Angular app, but i get this error :
inherits_browser.js:5 --> Uncaught TypeError: Object prototype may only be an Object or null: undefined
image
image

To Reproduce

  • ng new testangular
  • cd testangular
  • npm install dcc-utils
  • in app.component.ts include library on top of file with
    const { DCC } = require('dcc-utils');
    // and add
    constructor(){ console.log(DCC.fromRaw('dcc sample test string')); }

// ng serve now will produce first errors, that you can solve editing compiling options

  • npm i -D @angular-builders/custom-webpack
  • edit angular.json file in the root folder:

into architect.build --->

 "builder": "@angular-builders/custom-webpack:browser",
  "options": {
	  "customWebpackConfig": {
			  "path": "./custom-webpack.config.js"
	  },
  }

into architect.serve --->

 "builder": "@angular-builders/custom-webpack:dev-server",
  "options": {
    "browserTarget": "app:build"
  },
  • create a file in the root of angular folder, named custom-webpack.config.js containing this code
const webpack = require('webpack');
const path = require('path');

module.exports = {
    plugins: [
        new webpack.ProvidePlugin({
            process: 'process/browser',
        }),
    ],
    resolve: {
        alias: { util$: path.resolve(__dirname, 'node_modules/util') },
        //mainFields: ['browser', 'module', 'main'],
        fallback: {
            "fs": false,
            "stream": false,
            "path": false,
            "crypto": false,
            "assert": false,
            "http": false,
            "https": false,
            "zlib": false,
            "util": false,
            "node-inspect-extracted": false,
        }
    }
}
  • run npm i --save-dev @types/node
  • in tsconfig.app -> compiler options -> "types":["node"]
  • run ng serve to reproduce my error

I need help to be able to use this library in an Angular project,
let me know if you need extra info, i will keep this issue update

Thank you for your precious help,
Ciao

Renderlo un SDK ufficiale?

Stiamo testando da tempo in azienda un sistema di verifica green pass basato su dcc-utils.

Lo abbiamo integrato con la verifica della signatures e delle rules, il tutto incapsulato in un webservice che gira con express.

Node mi sembra la piattaforma più integrabile di tutte, è un bel problema cercare di integrare solo la versione Android.
Sarebbe bello rendere anche questo dcc-utils un SDK ufficiale da utilizzare in linea col DPCM del 12/10.

Get specific country rules

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Get the specific country rules

Hi :)
First of all, great work with this utils!
Is there a way to fetch a valid set of rules for a specific country?
It could be useful to implement this feature.
The rules system is not very intuitive and the possibility to have access to official rule sets .
Am I missing something and there is a way? Or, for some reason, is not possible?

Thanks :)

zlib decompression fails with 'third dose' green passes

DESCRIPTION:
On decryption of the embedded zlib archive of green passes of people who has had their QR code re-emitted after their third dose of vaccine, the call on zlib fails to decompress the package, blocking the successive process of validation.

Steps to reproduce the behavior:

  • Cloned the repo of official italian SDK from https://github.com/italia/verificac19-sdk/; ran npm i and started my personal validator server wrote following literal instructions** of the SDK [view README.md];
  • Passed a raw GP to the validator server formatted as required [ see lucadentella's https://github.com/lucadentella/raspberry-dgc/blob/main/cameraClient/cameraClient.py ], as json {dgc: raw_gp_string}

Expected behavior
As per usual working behavior, i usually received the values i requested from my validator server: an object from where i extract name (obj.person), surname (same), DoB (obj.date_of_birth) and GP validity (obj.code). Here an example without personal info:

Is this DCC valid? true
Details:
VALID
true
string 

when decrypting a 'third dose' greenpass, i get this:

CertificateParsingError: certificate can't be parsed, incorrect data check
    at Object.fromRaw (/home/user/greenpass-sdk/src/certificate.js:121:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Server.<anonymous> (/home/user/greenpass-sdk/validatorServer.js:49:19) {
  data: {
    error: Error: incorrect data check
        at Zlib.zlibOnError [as onerror] (node:zlib:190:17)
        at processChunkSync (node:zlib:456:12)
        at zlibBufferSync (node:zlib:178:12)
        at Object.syncBufferWrapper [as inflateSync] (node:zlib:791:14)
        at Function.fromRaw (/home/user/greenpass-sdk/node_modules/dcc-utils/src/dcc.js:17:25)
        at Object.fromRaw (/home/user/greenpass-sdk/src/certificate.js:118:27)
        at Server.<anonymous> (/home/user/greenpass-sdk/validatorServer.js:49:37)
        at Server.emit (node:events:520:28)
        at parserOnIncoming (node:_http_server:951:12)
        at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17) {
      errno: -3,
      code: 'Z_DATA_ERROR'
    }
  }
}

Screenshots
error
code

Food for Thoughts
It looks like a zlib decompressing error, but as I'm not directly involved in the green pass creation I can't figure out what exactly changes in a newly-emitted GP. The error, i think, resides in the line 17 - dcc._coseRaw = zlib.inflateSync(base45Data);
It looks like, by printing out the variable base45data in dcc.js the new GPs are longer byte strings, so it may be related to that, but can't tell for sure The process breaks right on that line and does not go on. Tried on amd64 and aarch64, same issue. I've seen zlib compilation issues on Apple M1 but experimenting on 64bit it seems like the issue remains the same. Perhaps passing an option to the method zlib.inflateSync as per https://nodejs.org/api/zlib.html#zlibinflatesyncbuffer-options might fix the problem, but i only managed to try unsuccessfully.

Please let me know if this is the wrong place to open the issue, but i was really unsure about where to post it, and this seemed the most reasonable place. Thanks for eventual aid fixing this.
Also, a huge thanks to all developers i am using code from!

Validity Certificate

Hi, but with this code can i get if a covid19 certificate is expired? if yes, how?

Question about the content of CI on Green Pass

Issue content

Hello I've a question on content of GreenPass.
In my Green Pass, i can see an Unique Certificate Identifier, that I can see also after decoding with key "CI".
But what does it contain?

I have read this https://ec.europa.eu/health/sites/default/files/ehealth/docs/vaccination-proof_interoperability-guidelines_en.pdf and I can see that there are 3 versions.

But did all countries choose one of these or each country choose their own?
In this case, Which one did Italy choose?

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.