Skip to content

Commit

Permalink
Merge pull request #83 from DevTrevi/develop
Browse files Browse the repository at this point in the history
Italian sdk version 1.1.5
  • Loading branch information
DevTrevi authored Feb 14, 2022
2 parents ade9166 + 65b7fd6 commit efce764
Show file tree
Hide file tree
Showing 45 changed files with 1,446 additions and 485 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/DevTrevi/DGCReader</RepositoryUrl>
<PackageTags>DGC DCC DigitalGreenCertificate DigitalCovidCertificate Greenpass VerificaC19 Blacklist DRL</PackageTags>
<Description>Blacklist provider implementation using the official Italian backend APIs. This provider is included in the list of verified SDKs by Italian authorities</Description>
<Version>2.4.0</Version>
<Version>2.5.0</Version>
<PackageLicenseExpression> Apache-2.0</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,18 @@ public async Task<bool> IsBlacklisted(string certificateIdentifier, Cancellation

var refreshTask = await RefreshBlacklistTaskRunner.RunSingleTask(cancellationToken);

// Wait for the task to complete
await refreshTask;
try
{
// Wait for the task to complete
await refreshTask;
}
catch (Exception e)
{
Logger?.LogError(e, $"Can not refresh ItalianDrlBlacklist from remote server. " +
$"Values from DRL version {status.CurrentVersion}, checked on {status.LastCheck} have reached MaxFileAge and can no longer be used.");
throw;
}

}
else if (status.LastCheck.Add(Options.RefreshInterval) < DateTime.Now ||
status.HasPendingDownload())
Expand All @@ -143,8 +153,17 @@ public async Task<bool> IsBlacklisted(string certificateIdentifier, Cancellation
var refreshTask = await RefreshBlacklistTaskRunner.RunSingleTask(cancellationToken);
if (!Options.UseAvailableValuesWhileRefreshing)
{
// Wait for the task to complete
await refreshTask;
try
{
// Wait for the task to complete
await refreshTask;
}
catch (Exception e)
{
// If refresh fail, continue until MaxFileAge
Logger?.LogWarning(e, $"Can not refresh ItalianDrlBlacklist from remote server: {e.Message}. Values from DRL version {status.CurrentVersion}, checked on {status.LastCheck} will be used");
}

}
}
}
Expand Down
21 changes: 21 additions & 0 deletions DgcReader.DgcTestData.Test/DgcDecoderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ public async Task TestDecodeMethod()

}


[TestMethod]
public async Task TestGetBirthDates()
{

foreach (var folder in TestEntries.Keys.Where(r => r != CertificatesTestsLoader.CommonTestDirName))
{
foreach (var entry in TestEntries[folder])
{

var result = await DgcReader.Decode(entry.PREFIX);

Assert.IsNotNull(result);
Assert.IsNotNull(result.Dgc);

Debug.WriteLine(result.Dgc.DateOfBirth);
}
}

}

[TestMethod]
public async Task TestVerifyMethod()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RepositoryUrl>https://github.com/DevTrevi/DGCReader</RepositoryUrl>
<PackageTags>DGC DCC DigitalGreenCertificate DigitalCovidCertificate Greenpass</PackageTags>
<Description>Base classes for implementing providers for DgcReader</Description>
<Version>2.4.0</Version>
<Version>2.5.0</Version>
<PackageLicenseExpression> Apache-2.0</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://github.com/DevTrevi/DgcReader</PackageProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,23 @@ protected ThreadsafeMultiValueSetProvider(ILogger? logger)
{
// If not UseAvailableRulesWhileRefreshing, always wait for the task to complete
Logger?.LogInformation($"Values for {GetValuesetName(key)} are expired, waiting for refresh to complete");
return await refreshTask;

try
{
valueSet = await refreshTask;
}
catch (Exception e)
{
if (valueSet != null)
{
var lastUpdate = GetLastUpdate(valueSet);
Logger?.LogWarning(e, $"Can not refresh {GetValuesetName(key)} from remote server: {e.Message}. Current values downloaded on {lastUpdate} will be used");
}
else
{
Logger?.LogError(e, $"Can not refresh {GetValuesetName(key)} from remote server. No values available to be used");
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions DgcReader.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ VisualStudioVersion = 17.0.31717.71
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5541974F-21E6-4B6E-AB62-1A78A34CB87C}"
ProjectSection(SolutionItems) = preProject
azure-pipelines-prerelease.yml = azure-pipelines-prerelease.yml
azure-pipelines.yml = azure-pipelines.yml
ItalianConfiguration.md = ItalianConfiguration.md
LICENSE = LICENSE
Expand Down
2 changes: 1 addition & 1 deletion DgcReader/DgcReader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RepositoryUrl>https://github.com/DevTrevi/DGCReader</RepositoryUrl>
<PackageTags>DGC DCC DigitalGreenCertificate DigitalCovidCertificate Greenpass</PackageTags>
<Description>Library for decoding and validating European Digital Green Certificates</Description>
<Version>2.4.0</Version>
<Version>2.5.0</Version>
<PackageLicenseExpression> Apache-2.0</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
40 changes: 27 additions & 13 deletions DgcReader/DgcReaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,26 +444,40 @@ private async Task<BlacklistValidationResult> GetBlacklistValidationResult(EuDGC

// Tracking the validated CertificateIdentifier
context.CertificateIdentifier = certEntry.CertificateIdentifier;

foreach (var blacklistProvider in BlackListProviders)
try
{
var blacklisted = await blacklistProvider.IsBlacklisted(certEntry.CertificateIdentifier, cancellationToken);
foreach (var blacklistProvider in BlackListProviders)
{
var blacklisted = await blacklistProvider.IsBlacklisted(certEntry.CertificateIdentifier, cancellationToken);

// At least one check performed
context.BlacklistVerified = true;
// At least one check performed
context.BlacklistVerified = true;

if (blacklisted)
{
context.IsBlacklisted = true;
context.BlacklistMatchProviderType = blacklistProvider.GetType();
if (blacklisted)
{
context.IsBlacklisted = true;
context.BlacklistMatchProviderType = blacklistProvider.GetType();

Logger?.LogWarning($"The certificate is blacklisted");
if (throwOnError)
throw new DgcBlackListException($"The certificate is blacklisted", context);
Logger?.LogWarning($"The certificate is blacklisted");
if (throwOnError)
throw new DgcBlackListException($"The certificate is blacklisted", context);

return context;
return context;
}
}
}
catch (Exception e)
{
// Technical failure, stop blacklist check and set as not verified
context.BlacklistVerified = false;
context.IsBlacklisted = null;
Logger?.LogError(e, $"Error while checking blacklist: {e.Message}");

if (throwOnError)
throw new DgcBlackListException($"Error while checking blacklist: {e.Message}", context, e);

return context;
}
context.IsBlacklisted = false;
}
else
Expand Down
19 changes: 13 additions & 6 deletions DgcReader/EuDGCExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,33 @@ public static class EuDGCExtensionMethods
/// Return the single certificate entry from the EuDGC (RecoveryEntry, Test or Vaccination)
/// </summary>
/// <param name="dgc"></param>
/// <param name="targetedDiseaseAgent">Restrict search to the specified disease agent</param>
/// <returns></returns>
public static ICertificateEntry GetCertificateEntry(this EuDGC dgc)
public static ICertificateEntry? GetCertificateEntry(this EuDGC dgc, string? targetedDiseaseAgent = null)
{
var empty = Enumerable.Empty<ICertificateEntry>();
return empty

var q = empty
.Union(dgc.Recoveries ?? empty)
.Union(dgc.Tests ?? empty)
.Union(dgc.Vaccinations ?? empty)
.Last();
.Union(dgc.Vaccinations ?? empty);

if (!string.IsNullOrEmpty(targetedDiseaseAgent))
q = q.Where(e => e.TargetedDiseaseAgent == targetedDiseaseAgent);

return q.LastOrDefault();
}

/// <summary>
/// Return the single certificate entry from the EuDGC (RecoveryEntry, Test or Vaccination)
/// </summary>
/// <param name="dgc"></param>
/// <param name="targetedDiseaseAgent">Restrict search to the specified disease agent</param>
/// <returns></returns>
public static TCertificate? GetCertificateEntry<TCertificate>(this EuDGC dgc)
public static TCertificate? GetCertificateEntry<TCertificate>(this EuDGC dgc, string? targetedDiseaseAgent = null)
where TCertificate : class, ICertificateEntry
{
return dgc.GetCertificateEntry() as TCertificate;
return dgc.GetCertificateEntry(targetedDiseaseAgent) as TCertificate;
}
}
}
8 changes: 8 additions & 0 deletions DgcReader/Exceptions/DgcBlackListException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public DgcBlackListException(string message,
{
Result = result;
}

public DgcBlackListException(string message,
BlacklistValidationResult result, Exception innerException) :
base(message, innerException)
{
Result = result;
}

#pragma warning disable CS8618
public DgcBlackListException(SerializationInfo info, StreamingContext context)
: base(info, context)
Expand Down
4 changes: 2 additions & 2 deletions DgcReader/Models/EuDGC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ public partial class EuDGC
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public static EuDGC? FromJson(string json) => JsonConvert.DeserializeObject<EuDGC>(json, Converter.Settings);
public static EuDGC? FromJson(string json) => JsonConvert.DeserializeObject<EuDGC>(json, EuDGCConverter.Settings);
}

/// <summary>
/// Json Converter settings to be used for deserializing EuDGC
/// </summary>
public static class Converter
public static class EuDGCConverter
{
/// <summary>
/// Json Converter settings to be used for deserializing EuDGC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public async Task<IRulesValidationResult> GetRulesValidationResult(EuDGC? dgc,


var certEntry = dgc.GetCertificateEntry();
if (certEntry == null)
throw new Exception("Unable to get the certificate entry");

var issuerCountryCode = certEntry.Country;
var certificateType = dgc.GetCertificateType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RepositoryUrl>https://github.com/DevTrevi/DGCReader</RepositoryUrl>
<PackageTags>DGC DCC DigitalGreenCertificate DigitalCovidCertificate Greenpass</PackageTags>
<Description>Unofficial implementation of the German rules for validating a Digital Green Certificate</Description>
<Version>2.4.0</Version>
<Version>2.5.0</Version>
<PackageLicenseExpression> Apache-2.0</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2021 Davide Trevisan
// Licensed under the Apache License, Version 2.0

namespace DgcReader.RuleValidators.Italy.Const
{
/// <summary>
/// Country codes for special behavior
/// </summary>
public static class CountryCodes
{
/// <summary>
/// Country code of Italy
/// </summary>
public const string Italy = "IT";

/// <summary>
/// Country code of San Marino
/// </summary>
public const string SanMarino = "SM";

/// <summary>
/// Country code for countries different from Italy
/// </summary>
public const string NotItaly = "NOT_IT";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public static class SettingNames
public const string VaccineEndDayBoosterNotIT = "vaccine_end_day_booster_NOT_IT";

public const string VaccineEndDaySchool = "vaccine_end_day_school";

public const string VaccineEndDayCompleteExtendedEMA = "vaccine_end_day_complete_extended_EMA";
public const string EMAVaccines = "EMA_vaccines";
#endregion

#region Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,35 @@ public static class VaccineProducts
/// Sputnik-V
/// </summary>
public const string Sputnik = "Sputnik-V";

/// <summary>
/// Moderna
/// </summary>
public const string Moderna = "EU/1/20/1507";

/// <summary>
/// Pfizer
/// </summary>
public const string Pfizer = "EU/1/20/1528";

/// <summary>
/// AstraZeneca
/// </summary>
public const string AstraZeneca = "EU/1/21/1529";

/// <summary>
/// Covishield
/// </summary>
public const string Covishield = "Covishield";

/// <summary>
/// R-Covi
/// </summary>
public const string R_Covi = "R-COVI";

/// <summary>
/// Covid-19-Recombinant
/// </summary>
public const string Covid19_Recombinant = "Covid-19-recombinant";
}
}
Loading

0 comments on commit efce764

Please sign in to comment.