diff --git a/src/main/java/eu/europa/ec/dgc/issuance/config/HcertLibConfig.java b/src/main/java/eu/europa/ec/dgc/issuance/config/HcertLibConfig.java index 431e8de..81ee537 100644 --- a/src/main/java/eu/europa/ec/dgc/issuance/config/HcertLibConfig.java +++ b/src/main/java/eu/europa/ec/dgc/issuance/config/HcertLibConfig.java @@ -16,7 +16,6 @@ @Configuration @RequiredArgsConstructor public class HcertLibConfig { - private final EhdCryptoService ehdCryptoService; @Bean diff --git a/src/main/java/eu/europa/ec/dgc/issuance/restapi/controller/DgciController.java b/src/main/java/eu/europa/ec/dgc/issuance/restapi/controller/DgciController.java index 0119248..4031ce0 100644 --- a/src/main/java/eu/europa/ec/dgc/issuance/restapi/controller/DgciController.java +++ b/src/main/java/eu/europa/ec/dgc/issuance/restapi/controller/DgciController.java @@ -52,34 +52,6 @@ public class DgciController { private final DgciService dgciService; - - @Operation( - summary = "Creates new dgci (deprecated)", - description = "Creates new dgci and return meta data for certificate creation" - ) - @PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE) - @Deprecated - public ResponseEntity initDgciDepr(@Valid @RequestBody DgciInit dgciInit) { - return ResponseEntity.ok(dgciService.initDgci(dgciInit)); - } - - @Operation( - summary = "calculate cose signature for edgc (deprecated)", - description = "calculate cose signature for given certificate hash, " - + "generate TAN and update DGCI Registry database" - ) - @ApiResponses(value = { - @ApiResponse(responseCode = "201", description = "signature created"), - @ApiResponse(responseCode = "404", description = "dgci with related id not found"), - @ApiResponse(responseCode = "400", description = "wrong issue data")}) - @PutMapping(value = "/{id}", consumes = MediaType.APPLICATION_JSON_VALUE) - @Deprecated - public ResponseEntity finalizeDgciDepr(@PathVariable long id, - @Valid @RequestBody IssueData issueData) - throws Exception { - return ResponseEntity.ok(dgciService.finishDgci(id, issueData)); - } - @Operation( summary = "Prepares an DGCI for the Code Generation in Frontend", description = "Creates new dgci and return meta data for certificate creation" diff --git a/src/main/java/eu/europa/ec/dgc/issuance/restapi/dto/DgciInit.java b/src/main/java/eu/europa/ec/dgc/issuance/restapi/dto/DgciInit.java index b51268b..808111c 100644 --- a/src/main/java/eu/europa/ec/dgc/issuance/restapi/dto/DgciInit.java +++ b/src/main/java/eu/europa/ec/dgc/issuance/restapi/dto/DgciInit.java @@ -21,9 +21,11 @@ package eu.europa.ec.dgc.issuance.restapi.dto; import eu.europa.ec.dgc.issuance.entity.GreenCertificateType; +import javax.validation.constraints.NotNull; import lombok.Data; @Data public class DgciInit { + @NotNull private GreenCertificateType greenCertificateType; } diff --git a/src/main/java/eu/europa/ec/dgc/issuance/service/ConfigurableCborService.java b/src/main/java/eu/europa/ec/dgc/issuance/service/ConfigurableCborService.java index 84df6d0..bdbb877 100644 --- a/src/main/java/eu/europa/ec/dgc/issuance/service/ConfigurableCborService.java +++ b/src/main/java/eu/europa/ec/dgc/issuance/service/ConfigurableCborService.java @@ -11,7 +11,6 @@ import java.time.temporal.ChronoUnit; import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -27,10 +26,8 @@ public class ConfigurableCborService extends DefaultCborService { public static final int EXPIRATION = 4; public static final int HCERT = -260; public static final int HCERT_VERSION = 1; - // Need autowired because there is circular reference - @Autowired - private DgciService dgciService; + private final ExpirationService expirationService; private final IssuanceConfigProperties issuanceConfigProperties; @Override @@ -50,7 +47,8 @@ public byte[] encode(@NotNull Eudgc input) { greenCertificateType = GreenCertificateType.Vaccination; } long issueTime = Instant.now().getEpochSecond(); - long expirationTime = issueTime + dgciService.expirationForType(greenCertificateType).get(ChronoUnit.SECONDS); + long expirationTime = issueTime + + expirationService.expirationForType(greenCertificateType).get(ChronoUnit.SECONDS); CBORObject coseContainer = CBORObject.NewMap(); coseContainer.set(CBORObject.FromObject(ISSUER), CBORObject.FromObject(issuanceConfigProperties.getCountryCode())); diff --git a/src/main/java/eu/europa/ec/dgc/issuance/service/DgciService.java b/src/main/java/eu/europa/ec/dgc/issuance/service/DgciService.java index 32ea8f7..71ffb89 100644 --- a/src/main/java/eu/europa/ec/dgc/issuance/service/DgciService.java +++ b/src/main/java/eu/europa/ec/dgc/issuance/service/DgciService.java @@ -61,10 +61,8 @@ import java.security.interfaces.RSAPublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.X509EncodedKeySpec; -import java.time.Duration; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Base64; import java.util.List; @@ -94,6 +92,7 @@ public enum DgciStatus { private final ContextIdentifierService contextIdentifierService; private final CompressorService compressorService; private final Base45Service base45Service; + private final ExpirationService expirationService; private static final int MAX_CLAIM_RETRY_TAN = 3; @@ -114,7 +113,7 @@ public DgciIdentifier initDgci(DgciInit dgciInit) { log.info("init dgci: {} id: {}", dgci, dgciEntity.getId()); ZonedDateTime now = ZonedDateTime.now(); - ZonedDateTime expiration = now.plus(expirationForType(dgciInit.getGreenCertificateType())); + ZonedDateTime expiration = now.plus(expirationService.expirationForType(dgciInit.getGreenCertificateType())); long expirationSec = expiration.toInstant().getEpochSecond(); dgciEntity.setExpiresAt(expiration); @@ -140,36 +139,6 @@ private String dgciHash(String dgci) { } } - /** - * expiration duration for given edgc type. - * @param greenCertificateType edgc type - * @return Duration - */ - public Duration expirationForType(GreenCertificateType greenCertificateType) { - Duration duration; - if (issuanceConfigProperties.getExpiration() != null) { - switch (greenCertificateType) { - case Test: - duration = issuanceConfigProperties.getExpiration().getTest(); - break; - case Vaccination: - duration = issuanceConfigProperties.getExpiration().getVaccination(); - break; - case Recovery: - duration = issuanceConfigProperties.getExpiration().getRecovery(); - break; - default: - throw new IllegalArgumentException("unsupported cert type for expiration: " + greenCertificateType); - } - } else { - duration = null; - } - if (duration == null) { - duration = Duration.of(365, ChronoUnit.DAYS); - } - return duration; - } - @NotNull private String generateDgci() { return dgciGenerator.newDgci(); @@ -417,7 +386,7 @@ public EgdcCodeData createEdgc(Eudgc eudgc) { dgciEntity.setHashedTan(tanService.hashTan(tan)); dgciEntity.setGreenCertificateType(greenCertificateType); dgciEntity.setCreatedAt(ZonedDateTime.now()); - dgciEntity.setExpiresAt(ZonedDateTime.now().plus(expirationForType(greenCertificateType))); + dgciEntity.setExpiresAt(ZonedDateTime.now().plus(expirationService.expirationForType(greenCertificateType))); dgciRepository.saveAndFlush(dgciEntity); return egdcCodeData; diff --git a/src/main/java/eu/europa/ec/dgc/issuance/service/ExpirationService.java b/src/main/java/eu/europa/ec/dgc/issuance/service/ExpirationService.java new file mode 100644 index 0000000..9264569 --- /dev/null +++ b/src/main/java/eu/europa/ec/dgc/issuance/service/ExpirationService.java @@ -0,0 +1,45 @@ +package eu.europa.ec.dgc.issuance.service; + +import eu.europa.ec.dgc.issuance.config.IssuanceConfigProperties; +import eu.europa.ec.dgc.issuance.entity.GreenCertificateType; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ExpirationService { + + private final IssuanceConfigProperties issuanceConfigProperties; + + /** + * expiration duration for given edgc type. + * @param greenCertificateType edgc type + * @return Duration + */ + public Duration expirationForType(GreenCertificateType greenCertificateType) { + Duration duration; + if (issuanceConfigProperties.getExpiration() != null) { + switch (greenCertificateType) { + case Test: + duration = issuanceConfigProperties.getExpiration().getTest(); + break; + case Vaccination: + duration = issuanceConfigProperties.getExpiration().getVaccination(); + break; + case Recovery: + duration = issuanceConfigProperties.getExpiration().getRecovery(); + break; + default: + throw new IllegalArgumentException("unsupported cert type for expiration: " + greenCertificateType); + } + } else { + duration = null; + } + if (duration == null) { + duration = Duration.of(365, ChronoUnit.DAYS); + } + return duration; + } +}