DgcReader 1.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package DgcReader --version 1.3.1                
NuGet\Install-Package DgcReader -Version 1.3.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DgcReader" Version="1.3.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DgcReader --version 1.3.1                
#r "nuget: DgcReader, 1.3.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DgcReader as a Cake Addin
#addin nuget:?package=DgcReader&version=1.3.1

// Install DgcReader as a Cake Tool
#tool nuget:?package=DgcReader&version=1.3.1                

DgcReader

Extensible .NET library for decoding and validating European Digital Green Certificates

NuGet version (DgcReader)

Summary

The library allows to decode and validate any EU Digital Green Certificate, providing some abstractions to easily implement specific providers for every country backend.

It supports any kind of project compatible with .NET Standard 2.0 and also legacy applications from .NET Framework 4.5.2 onwards.

Starting from version 1.3.0, the library has been included in the list of verified SDKs by Italian authorities (Ministero della salute).
The approval only refers to the main module DgcReader in combination with DgcReader.TrustListProviders.Italy and DgcReader.RuleValidators.Italy, using configuration parameters compliant with the current Italian regulations.

For usage in different countries, please refer to the disclaimer and to the specific documentation of each project.

Usage

The main entry point of the library is the DgcReaderService class.

You can simply register it as a service:

public void ConfigureServices(IServiceCollection services)
{
   ...
   services.AddDgcReader()                     // Add the DgcReaderService as singleton
       .AddItalianTrustListProvider(o =>       // Register the ItalianTrustListProvider service (or any other provider type)
       {
           // Optionally, configure the provider with custom options
           o.RefreshInterval = TimeSpan.FromHours(24);
           o.MinRefreshInterval = TimeSpan.FromHours(1);
           o.SaveCertificate = true;
           ...
       })
       .AddItalianBlacklistProvider()      // The blacklist provider service
       .AddItalianRulesValidator();        // Finally, the rules validator
}

then getting it from the DI ServiceCollection:


...
// Getting an instance by dependency injection (from .NET standard 2.0 onward)
var dgcReader = ServiceCollection.GetService<DgcReaderService>();

If you don't use the dependency injection, you can instantiate it directly:

a) Use a TrustListProviderand RulesValidator:
// Create an instance of the TrustListProvider (eg. ItalianTrustListProvider) and the other required services
var httpClient = new HttpClient();
var trustListProvider = new ItalianTrustListProvider(httpClient);
var rulesValidator = new DgcItalianRulesValidator(httpClient);  // Note: this implementation is both a IRulesValidator and a IBlacklistProvider

// Create an instance of the DgcReaderService
var dgcReader = new DgcReaderService(trustListProvider, rulesValidator, rulesValidator);

Once instantiated and configured with at least the ITrustListProvider service, you can simply call one of the methods shown in c)

b) Use the DgcReaderService without arguments (i.e. no TrustListProviderand RulesValidator):

This lets you decode all the QR code data without verification, but still gives you a quick idea about how the library works. You can use the open source EU Digital Green Test Certifactes or your personal certificate.

// Create the default instance of the `DgcReaderService` with an empty constructor
var dgcReader = new DgcReaderService();
c) Run the validation
...
string qrCodeData = "Raw qr code data staring with HC1:";

// Decode and validate the qr code data.
// The result will contain all the details of the validated object
var result = await dgcReader.GetValidationResult(qrCodeData);

var status = result.Status;
var signatureIsValid = result.HasValidSignature;
...

or

...
string qrCodeData = "Raw qr code data staring with HC1:";
try
{
    // Decode and validate the signature.
    // If anything fails, an exception is thrown containing the error details
    var result = await dgcReader.Verify(qrCodeData);
}
catch(Exception e)
{
    Console.WriteLine($"Error verifying DGC: {e.Message}");
}

Information about how to interprete the decoded values can be found in the Value Sets for Digital Green Certificates and the COVID-19 Data Reporting for Non-Lab-Based Testing.

Rules validation

Rules validation is an optional service and can be done by registering an IRulesValidator service, or by passing it to the constructor.

Once registered, the validator will be executed when calling DgcReader.Verify() or DgcReader.GetValidationResult().
If validation succeded, the result status will be set to Valid or PartiallyValid, otherwise another status will be returned when calling DgcReader.GetValidationResult(), or an exception will be thrown when using DgcReader.Verify().

While TrustList providers and BlackList providers are virtually interchangeable, the rules for determining if a certificate is valid are different for every country.
For this reason, a specific implementation of the IRulesValidator should be used in order to determine if the certificate is valid for a particular country.

Supported frameworks differences

The library supports a wide range of .NET and .NET Framework versions, trying to keep the dependencies to third party libraries at minimum. For this reason, the implementation of the cryptographic functionalities for signature validations and certificates parsing are implemented with the apis of the System.Security.Cryptography namespace.
These APIs were not fully implemented in previous versions of the framework, so the version compiled for .NET Framework 4.5.2 uses the BouncyCastle library instead.

Packages

Description Version
Main package, containing the DgcReaderService NuGet version (DgcReader)
TrustList implementation for the Italian backend NuGet version (DgcReader.TrustListProviders.Italy)
TrustList implementation for the Swedish backend NuGet version (DgcReader.TrustListProviders.Sweden)
Abstractions for building TrustList providers NuGet version (DgcReader.TrustListProviders.Abstractions)
Implementation for the Italian validation rules NuGet version (DgcReader.RuleValidators.Italy)

Extending the library

All you have to do in order to extend the library is to implement the interfaces exposed under the DgcReader.Interfaces.* namespace. You can use the implementations in the repository as an example, or you can code them from scratch.
If you are implementing a TrustList provider, the DgcReader.TrustListProviders.Abstractions package can results useful to simply implement a service optimized for multiple concurrent requests like a web application.
Any suggestion will be appreciated!

Requirements

In order to compile and run the solution, you will need the following tools:

  • Microsoft Visual Studio 2019 with the latest updates installed (16.11.7 at the moment of writing), or Microsoft Visual Studio 2022
  • Because some projects supports multiple version of the .NET framework, you should have installed the related targeting packs. At the moment, .NET Framework 4.5.2, .NET Framework 4.7 and .NET Standard 2.0 are supported

<a name="disclaimer">Disclaimer</a>

Some implementations in this repository may not have been approved by official authorities, or may be approved only by some countries.
Unless otherwise indicated, such implementations must be considered unofficial, and it is not assured in any way that they fully comply with dispositions of the reference countries.

The author assumes no responsibility for any unauthorized use of the library and no warranties about the correctness of the implementation, as better stated in the License.

Some code of the library is based on the DCCValidator App.
Many thanks to their authors for sharing their code!


Copyright © 2021 Davide Trevisan
Licensed under the Apache License, Version 2.0

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on DgcReader:

Package Downloads
DgcReader.TrustListProviders.Abstractions

Base classes for implementing trustlist providers for national backends

DgcReader.RuleValidators.Italy

Implementation of the Italian rules for validating Digital Green Certificates. This provider is included in the list of verified SDKs by Italian authorities

DgcReader.TrustListProviders.Italy

Trustlist provider implementation using certificates from the official Italian backend. This provider is included in the list of verified SDKs by Italian authorities

DgcReader.Deserializers.Italy

Deserializer for EuDGC certificates issued by Italy including custom entries

DgcReader.TrustListProviders.Sweden

Unofficial TrustList provider implementation using the Swedish backend endpoints

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.6.1 1,331 4/3/2023
2.6.0 1,367 4/2/2023
2.6.0-CI-20230402-140522 840 4/2/2023
2.5.5 2,894 6/14/2022
2.5.5-rc1 953 6/14/2022
2.5.4 2,789 5/4/2022
2.5.4-rc2 839 5/4/2022
2.5.4-rc1 843 5/4/2022
2.5.3 3,558 3/5/2022
2.5.3-rc1 918 3/5/2022
2.5.1 2,864 2/16/2022
2.5.1-rc1 874 2/15/2022
2.5.0 2,680 2/14/2022
2.5.0-rc3 848 2/14/2022
2.5.0-rc2 861 2/11/2022
2.5.0-rc1 815 2/11/2022
2.4.0 2,607 2/6/2022
2.3.0 2,650 1/28/2022
2.2.1 2,686 1/21/2022
2.2.0 1,841 1/16/2022
2.1.0 1,703 1/6/2022
2.0.0 1,419 12/27/2021
1.3.2 501 12/13/2021
1.3.1 562 12/11/2021
1.3.0 1,151 12/6/2021
1.2.0 1,420 11/4/2021
1.1.0 1,374 11/2/2021