Skip to content

Commit

Permalink
update hcert kotlin to 1.2.0 (#87)
Browse files Browse the repository at this point in the history
Co-authored-by: slaurenz <[email protected]>
  • Loading branch information
a-trzewik and slaurenz authored Jul 22, 2021
1 parent a5cfe25 commit 707bc48
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<spring.security.version>5.4.6</spring.security.version>
<lombok.version>1.18.20</lombok.version>
<liquibase.version>4.3.3</liquibase.version>
<hcert-kotlin.version>1.0.1</hcert-kotlin.version>
<hcert-kotlin.version>1.2.0</hcert-kotlin.version>
<kotlin.version>1.5.10</kotlin.version>
<springdoc.version>1.5.7</springdoc.version>
<junit.version>5.7.1</junit.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import ehn.techiop.hcert.kotlin.chain.CompressorService;
import ehn.techiop.hcert.kotlin.chain.ContextIdentifierService;
import ehn.techiop.hcert.kotlin.chain.CoseService;
import ehn.techiop.hcert.kotlin.chain.HigherOrderValidationService;
import ehn.techiop.hcert.kotlin.chain.SchemaValidationService;
import ehn.techiop.hcert.kotlin.chain.impl.DefaultBase45Service;
import ehn.techiop.hcert.kotlin.chain.impl.DefaultCborService;
import ehn.techiop.hcert.kotlin.chain.impl.DefaultCompressorService;
import ehn.techiop.hcert.kotlin.chain.impl.DefaultContextIdentifierService;
import ehn.techiop.hcert.kotlin.chain.impl.DefaultCoseService;
import ehn.techiop.hcert.kotlin.chain.impl.DefaultHigherOrderValidationService;
import ehn.techiop.hcert.kotlin.chain.impl.DefaultSchemaValidationService;
import eu.europa.ec.dgc.issuance.service.EhdCryptoService;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -52,4 +54,9 @@ SchemaValidationService schemaValidationService() {
return new DefaultSchemaValidationService();
}

@Bean
HigherOrderValidationService higherOrderValidationService() {
return new DefaultHigherOrderValidationService();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ehn.techiop.hcert.kotlin.chain.CwtService;
import ehn.techiop.hcert.kotlin.chain.VerificationResult;
import ehn.techiop.hcert.kotlin.crypto.CwtHeaderKeys;
import ehn.techiop.hcert.kotlin.data.CborObject;
import ehn.techiop.hcert.kotlin.data.GreenCertificate;
import eu.europa.ec.dgc.issuance.config.IssuanceConfigProperties;
import kotlinx.serialization.json.Json;
Expand All @@ -19,7 +20,7 @@ public class ConfigurableCwtService implements CwtService {

@NotNull
@Override
public byte[] decode(@NotNull byte[] bytes, @NotNull VerificationResult verificationResult) {
public CborObject decode(@NotNull byte[] bytes, @NotNull VerificationResult verificationResult) {
throw new UnsupportedOperationException("decoding not supported");
}

Expand All @@ -40,4 +41,6 @@ public byte[] encode(@NotNull byte[] bytes) {
cwtMap.Add(CwtHeaderKeys.HCERT.getIntVal(), hcertMap);
return cwtMap.EncodeToBytes();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import ehn.techiop.hcert.kotlin.chain.ContextIdentifierService;
import ehn.techiop.hcert.kotlin.chain.CoseService;
import ehn.techiop.hcert.kotlin.chain.CwtService;
import ehn.techiop.hcert.kotlin.chain.HigherOrderValidationService;
import ehn.techiop.hcert.kotlin.chain.SchemaValidationService;
import ehn.techiop.hcert.kotlin.data.GreenCertificate;
import eu.europa.ec.dgc.issuance.config.IssuanceConfigProperties;
Expand Down Expand Up @@ -96,6 +97,7 @@ public enum DgciStatus {
private final CertificateService certificateService;
private final IssuanceConfigProperties issuanceConfigProperties;
private final DgciGenerator dgciGenerator;
private final HigherOrderValidationService higherOrderValidationService;
private final CborService cborService;
private final CoseService coseService;
private final CwtService cwtService;
Expand Down Expand Up @@ -403,8 +405,8 @@ public EgdcCodeData createEdgc(String dccJson) {
}
}
Chain cborProcessingChain =
new Chain(cborService, cwtService, coseService,
contextIdentifierService, compressorService, base45Service, schemaValidationService);
new Chain(higherOrderValidationService, schemaValidationService, cborService, cwtService, coseService,
compressorService, base45Service, contextIdentifierService);
ChainResult chainResult = cborProcessingChain.encode(eudgc);

EgdcCodeData egdcCodeData = new EgdcCodeData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ public CwtTimeFields calculateCwtExpiration(GreenCertificate eudgc) {
long issueTime = Instant.now().getEpochSecond();
long expirationStartTime = issueTime;

if (eudgc.getTests() != null && !eudgc.getTests().isEmpty()) {
if (eudgc.getTests() != null && eudgc.getTests().length > 0) {
greenCertificateType = GreenCertificateType.Test;
expirationStartTime = extractTimesSec(eudgc.getTests().get(0).getDateTimeSample(),expirationStartTime);
expirationStartTime = extractTimesSec(eudgc.getTests()[0].getDateTimeSample(),expirationStartTime);
expirationTime = expirationStartTime + expirationForType(greenCertificateType).get(ChronoUnit.SECONDS);
} else if (eudgc.getRecoveryStatements() != null && !eudgc.getRecoveryStatements().isEmpty()) {
} else if (eudgc.getRecoveryStatements() != null && eudgc.getRecoveryStatements().length > 0) {
greenCertificateType = GreenCertificateType.Recovery;
expirationTime = expirationStartTime + expirationForType(greenCertificateType).get(ChronoUnit.SECONDS);
expirationTime = extractTimesSec(eudgc.getRecoveryStatements().get(0).getCertificateValidUntil(),
expirationTime = extractTimesSec(eudgc.getRecoveryStatements()[0].getCertificateValidUntil(),
expirationTime);
} else if (eudgc.getVaccinations() != null && !eudgc.getVaccinations().isEmpty()) {
} else if (eudgc.getVaccinations() != null && eudgc.getVaccinations().length > 0) {
greenCertificateType = GreenCertificateType.Vaccination;
expirationStartTime = extractTimesSec(eudgc.getVaccinations().get(0).getDate(),expirationStartTime);
expirationStartTime = extractTimesSec(eudgc.getVaccinations()[0].getDate(),expirationStartTime);
expirationTime = expirationStartTime + expirationForType(greenCertificateType).get(ChronoUnit.SECONDS);
} else {
greenCertificateType = GreenCertificateType.Vaccination;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import COSE.CoseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import ehn.techiop.hcert.kotlin.chain.SampleData;
import eu.europa.ec.dgc.issuance.config.IssuanceConfigProperties;
import eu.europa.ec.dgc.issuance.entity.DgciEntity;
import eu.europa.ec.dgc.issuance.entity.GreenCertificateType;
Expand Down Expand Up @@ -97,7 +96,7 @@ void testDGCISign() throws Exception {

@Test
void testCreateEdgcBackend() throws Exception {
String vacDataJson = SampleData.Companion.getVaccination();
String vacDataJson = SampleData.vaccination;
EgdcCodeData egdcCodeData = dgciService.createEdgc(vacDataJson);
assertNotNull(egdcCodeData);
assertNotNull(egdcCodeData.getQrCode());
Expand All @@ -124,7 +123,7 @@ void testCreateEdgcBackend() throws Exception {

@Test
void testWalletClaim() throws Exception {
String vacDataJson = SampleData.Companion.getVaccination();
String vacDataJson = SampleData.vaccination;
EgdcCodeData egdcCodeData = dgciService.createEdgc(vacDataJson);
assertNotNull(egdcCodeData);
assertNotNull(egdcCodeData.getQrCode());
Expand Down Expand Up @@ -174,7 +173,7 @@ private String sha256(String toHash) throws NoSuchAlgorithmException {

@Test
void testWalletClaimEC() throws Exception {
String vacDataJson = SampleData.Companion.getVaccination();
String vacDataJson = SampleData.vaccination;
EgdcCodeData egdcCodeData = dgciService.createEdgc(vacDataJson);
assertNotNull(egdcCodeData);
assertNotNull(egdcCodeData.getQrCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eu.europa.ec.dgc.issuance.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import ehn.techiop.hcert.kotlin.chain.SampleData;
import ehn.techiop.hcert.kotlin.data.GreenCertificate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
Expand All @@ -20,15 +19,15 @@ class ExpirationServiceTest {

@Test
void testExpriationCalculation() throws Exception {
String vacDataJson = SampleData.Companion.getVaccination();
String vacDataJson = SampleData.vaccination;
GreenCertificate eudgc = testCalculation("vactination",vacDataJson);
System.out.println(eudgc.getVaccinations().get(0).getDate());
String recoveryDataJson = SampleData.Companion.getRecovery();
System.out.println(eudgc.getVaccinations()[0].getDate());
String recoveryDataJson = SampleData.recovery;
eudgc = testCalculation("recovery",recoveryDataJson);
System.out.println(eudgc.getRecoveryStatements().get(0).getCertificateValidUntil());
String testDataJson = SampleData.Companion.getTestNaa();
System.out.println(eudgc.getRecoveryStatements()[0].getCertificateValidUntil());
String testDataJson = SampleData.testNaa;
eudgc = testCalculation("test",testDataJson);
System.out.println(eudgc.getTests().get(0).getDateTimeSample());
System.out.println(eudgc.getTests()[0].getDateTimeSample());
assertNotNull(eudgc);

}
Expand Down
95 changes: 95 additions & 0 deletions src/test/java/eu/europa/ec/dgc/issuance/service/SampleData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package eu.europa.ec.dgc.issuance.service;

public class SampleData {
public static final String recovery = "{\n" +
" \"ver\": \"1.2.1\",\n" +
" \"nam\": {\n" +
" \"fn\": \"Musterfrau-G\\u00f6\\u00dfinger\",\n" +
" \"gn\": \"Gabriele\",\n" +
" \"fnt\": \"MUSTERFRAU<GOESSINGER\",\n" +
" \"gnt\": \"GABRIELE\"\n" +
" },\n" +
" \"dob\": \"1998-02-26\",\n" +
" \"r\": [\n" +
" {\n" +
" \"tg\": \"840539006\",\n" +
" \"fr\": \"2021-02-20\",\n" +
" \"co\": \"AT\",\n" +
" \"is\": \"Ministry of Health, Austria\",\n" +
" \"df\": \"2021-04-04\",\n" +
" \"du\": \"2021-10-04\",\n" +
" \"ci\": \"URN:UVCI:01:AT:858CC18CFCF5965EF82F60E493349AA5#K\"\n" +
" }\n" +
" ]\n" +
"}\n";
public static final String vaccination = "{\n" +
" \"ver\": \"1.2.1\",\n" +
" \"nam\": {\n" +
" \"fn\": \"Musterfrau-G\\u00f6\\u00dfinger\",\n" +
" \"gn\": \"Gabriele\",\n" +
" \"fnt\": \"MUSTERFRAU<GOESSINGER\",\n" +
" \"gnt\": \"GABRIELE\"\n" +
" },\n" +
" \"dob\": \"1998-02-26\",\n" +
" \"v\": [\n" +
" {\n" +
" \"tg\": \"840539006\",\n" +
" \"vp\": \"1119349007\",\n" +
" \"mp\": \"EU\\/1\\/20\\/1528\",\n" +
" \"ma\": \"ORG-100030215\",\n" +
" \"dn\": 1,\n" +
" \"sd\": 2,\n" +
" \"dt\": \"2021-02-18\",\n" +
" \"co\": \"AT\",\n" +
" \"is\": \"Ministry of Health, Austria\",\n" +
" \"ci\": \"URN:UVCI:01:AT:10807843F94AEE0EE5093FBC254BD813#B\"\n" +
" }\n" +
" ]\n" +
"}\n";
public static final String testRat = "{\n" +
" \"ver\": \"1.2.1\",\n" +
" \"nam\": {\n" +
" \"fn\": \"Musterfrau-G\\u00f6\\u00dfinger\",\n" +
" \"gn\": \"Gabriele\",\n" +
" \"fnt\": \"MUSTERFRAU<GOESSINGER\",\n" +
" \"gnt\": \"GABRIELE\"\n" +
" },\n" +
" \"dob\": \"1998-02-26\",\n" +
" \"t\": [\n" +
" {\n" +
" \"tg\": \"840539006\",\n" +
" \"tt\": \"LP217198-3\",\n" +
" \"ma\": \"1232\",\n" +
" \"sc\": \"2021-02-20T12:34:56+00:00\",\n" +
" \"tr\": \"260415000\",\n" +
" \"tc\": \"Testing center Vienna 1\",\n" +
" \"co\": \"AT\",\n" +
" \"is\": \"Ministry of Health, Austria\",\n" +
" \"ci\": \"URN:UVCI:01:AT:71EE2559DE38C6BF7304FB65A1A451EC#3\"\n" +
" }\n" +
" ]\n" +
"}\n";
public static final String testNaa = "{\n" +
" \"ver\": \"1.2.1\",\n" +
" \"nam\": {\n" +
" \"fn\": \"Musterfrau-G\\u00f6\\u00dfinger\",\n" +
" \"gn\": \"Gabriele\",\n" +
" \"fnt\": \"MUSTERFRAU<GOESSINGER\",\n" +
" \"gnt\": \"GABRIELE\"\n" +
" },\n" +
" \"dob\": \"1998-02-26\",\n" +
" \"t\": [\n" +
" {\n" +
" \"tg\": \"840539006\",\n" +
" \"tt\": \"LP6464-4\",\n" +
" \"nm\": \"Roche LightCycler qPCR\",\n" +
" \"sc\": \"2021-02-20T12:34:56+00:00\",\n" +
" \"tr\": \"260415000\",\n" +
" \"tc\": \"Testing center Vienna 1\",\n" +
" \"co\": \"AT\",\n" +
" \"is\": \"Ministry of Health, Austria\",\n" +
" \"ci\": \"URN:UVCI:01:AT:B5921A35D6A0D696421B3E2462178297#I\"\n" +
" }\n" +
" ]\n" +
"}\n";
}

0 comments on commit 707bc48

Please sign in to comment.