From 97b098899e4da68c99d491611f08afbf70fc78ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karsten=20Ra=CC=88th?= Date: Thu, 5 Oct 2023 17:30:40 +0200 Subject: [PATCH 1/2] TNG dependencies removed --- .../keydistribution/mapper/IssuerMapper.java | 2 +- .../keydistribution/model/TrustListItem.java | 63 ++++++++++ .../keydistribution/model/TrustedIssuer.java | 116 ++++++++++++++++++ .../CertificatesLookupResponseItemDto.java | 2 +- .../restapi/dto/DeltaListDto.java | 2 +- .../restapi/dto/ProblemReportDto.java | 1 + .../service/DummyDownloadConnector.java | 36 ++++++ .../SignerCertificateDownloadServiceImpl.java | 10 +- .../service/SignerInformationService.java | 9 +- .../TrustedIssuerDownloadServiceImpl.java | 12 +- .../service/TrustedIssuerService.java | 3 +- src/main/resources/application.yml | 17 +-- .../keydistribution/OpenApiTest.java | 5 - .../ContextControllerIntegrationTest.java | 5 - ...trollerWithEnvironmentIntegrationTest.java | 4 - .../SignerInformationIntegrationTest.java | 5 - .../TrustedIssuerIntegrationTest.java | 5 - .../service/InfoServiceTest.java | 5 - ...nerCertificateDownloadServiceImplTest.java | 27 +--- .../service/SignerInformationServiceTest.java | 7 +- .../TrustedIssuerDownloadServiceImplTest.java | 32 +---- .../testdata/SignerInformationTestHelper.java | 2 +- .../testdata/TrustedIssuerTestHelper.java | 5 +- 23 files changed, 246 insertions(+), 129 deletions(-) create mode 100644 src/main/java/tng/trustnetwork/keydistribution/model/TrustListItem.java create mode 100644 src/main/java/tng/trustnetwork/keydistribution/model/TrustedIssuer.java create mode 100644 src/main/java/tng/trustnetwork/keydistribution/service/DummyDownloadConnector.java diff --git a/src/main/java/tng/trustnetwork/keydistribution/mapper/IssuerMapper.java b/src/main/java/tng/trustnetwork/keydistribution/mapper/IssuerMapper.java index b37b94a..9355812 100644 --- a/src/main/java/tng/trustnetwork/keydistribution/mapper/IssuerMapper.java +++ b/src/main/java/tng/trustnetwork/keydistribution/mapper/IssuerMapper.java @@ -20,12 +20,12 @@ package tng.trustnetwork.keydistribution.mapper; -import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer; import java.util.List; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import tng.trustnetwork.keydistribution.dto.TrustedIssuerDto; import tng.trustnetwork.keydistribution.entity.TrustedIssuerEntity; +import tng.trustnetwork.keydistribution.model.TrustedIssuer; @Mapper(componentModel = "spring") public interface IssuerMapper { diff --git a/src/main/java/tng/trustnetwork/keydistribution/model/TrustListItem.java b/src/main/java/tng/trustnetwork/keydistribution/model/TrustListItem.java new file mode 100644 index 0000000..1fa6623 --- /dev/null +++ b/src/main/java/tng/trustnetwork/keydistribution/model/TrustListItem.java @@ -0,0 +1,63 @@ +package tng.trustnetwork.keydistribution.model; + +import java.time.ZonedDateTime; + +public class TrustListItem { + private String kid; + private ZonedDateTime timestamp; + private String rawData; + private String country; + private String thumbprint; + private String signature; + + public TrustListItem() { + } + + public String getKid() { + return this.kid; + } + + public ZonedDateTime getTimestamp() { + return this.timestamp; + } + + public String getRawData() { + return this.rawData; + } + + public String getCountry() { + return this.country; + } + + public String getThumbprint() { + return this.thumbprint; + } + + public String getSignature() { + return this.signature; + } + + public void setKid(final String kid) { + this.kid = kid; + } + + public void setTimestamp(final ZonedDateTime timestamp) { + this.timestamp = timestamp; + } + + public void setRawData(final String rawData) { + this.rawData = rawData; + } + + public void setCountry(final String country) { + this.country = country; + } + + public void setThumbprint(final String thumbprint) { + this.thumbprint = thumbprint; + } + + public void setSignature(final String signature) { + this.signature = signature; + } +} diff --git a/src/main/java/tng/trustnetwork/keydistribution/model/TrustedIssuer.java b/src/main/java/tng/trustnetwork/keydistribution/model/TrustedIssuer.java new file mode 100644 index 0000000..295c326 --- /dev/null +++ b/src/main/java/tng/trustnetwork/keydistribution/model/TrustedIssuer.java @@ -0,0 +1,116 @@ +package tng.trustnetwork.keydistribution.model; + +import java.time.ZonedDateTime; + +public class TrustedIssuer { + private String url; + private UrlType type; + private String country; + private String thumbprint; + private String sslPublicKey; + private String keyStorageType; + private String signature; + private ZonedDateTime timestamp; + private String name; + private String uuid; + private String domain; + + public TrustedIssuer() { + } + + public String getUrl() { + return this.url; + } + + public UrlType getType() { + return this.type; + } + + public String getCountry() { + return this.country; + } + + public String getThumbprint() { + return this.thumbprint; + } + + public String getSslPublicKey() { + return this.sslPublicKey; + } + + public String getKeyStorageType() { + return this.keyStorageType; + } + + public String getSignature() { + return this.signature; + } + + public ZonedDateTime getTimestamp() { + return this.timestamp; + } + + public String getName() { + return this.name; + } + + public String getUuid() { + return this.uuid; + } + + public String getDomain() { + return this.domain; + } + + public void setUrl(final String url) { + this.url = url; + } + + public void setType(final UrlType type) { + this.type = type; + } + + public void setCountry(final String country) { + this.country = country; + } + + public void setThumbprint(final String thumbprint) { + this.thumbprint = thumbprint; + } + + public void setSslPublicKey(final String sslPublicKey) { + this.sslPublicKey = sslPublicKey; + } + + public void setKeyStorageType(final String keyStorageType) { + this.keyStorageType = keyStorageType; + } + + public void setSignature(final String signature) { + this.signature = signature; + } + + public void setTimestamp(final ZonedDateTime timestamp) { + this.timestamp = timestamp; + } + + public void setName(final String name) { + this.name = name; + } + + public void setUuid(final String uuid) { + this.uuid = uuid; + } + + public void setDomain(final String domain) { + this.domain = domain; + } + + public static enum UrlType { + HTTP, + DID; + + private UrlType() { + } + } +} diff --git a/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/CertificatesLookupResponseItemDto.java b/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/CertificatesLookupResponseItemDto.java index c710108..5fe812c 100644 --- a/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/CertificatesLookupResponseItemDto.java +++ b/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/CertificatesLookupResponseItemDto.java @@ -4,7 +4,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; - @Schema( name = "DeltaList", type = "object", @@ -13,6 +12,7 @@ + "\"deleted\":[\"3115adf=\"]\n" + "}" ) + @Getter @AllArgsConstructor public class CertificatesLookupResponseItemDto { diff --git a/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/DeltaListDto.java b/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/DeltaListDto.java index 95b6e95..e7fa43e 100644 --- a/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/DeltaListDto.java +++ b/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/DeltaListDto.java @@ -6,7 +6,6 @@ import lombok.Data; import lombok.NoArgsConstructor; - @Schema( name = "DeltaList", type = "object", @@ -15,6 +14,7 @@ + "\"deleted\":[\"3115adf=\"]\n" + "}" ) + @Data @AllArgsConstructor @NoArgsConstructor diff --git a/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/ProblemReportDto.java b/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/ProblemReportDto.java index 5f68523..3a01d14 100644 --- a/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/ProblemReportDto.java +++ b/src/main/java/tng/trustnetwork/keydistribution/restapi/dto/ProblemReportDto.java @@ -34,6 +34,7 @@ + "\"details\":\"...\"\n" + "}" ) + @Data @AllArgsConstructor public class ProblemReportDto { diff --git a/src/main/java/tng/trustnetwork/keydistribution/service/DummyDownloadConnector.java b/src/main/java/tng/trustnetwork/keydistribution/service/DummyDownloadConnector.java new file mode 100644 index 0000000..44b9624 --- /dev/null +++ b/src/main/java/tng/trustnetwork/keydistribution/service/DummyDownloadConnector.java @@ -0,0 +1,36 @@ +package tng.trustnetwork.keydistribution.service; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.stereotype.Service; +import tng.trustnetwork.keydistribution.model.TrustListItem; +import tng.trustnetwork.keydistribution.model.TrustedIssuer; + +@ConditionalOnProperty({"dgc.gateway.connector.enabled"}) +@Service +@EnableScheduling +@RequiredArgsConstructor +public class DummyDownloadConnector { + + private List trustedCertificates = new ArrayList(); + + private List trustedIssuers = new ArrayList(); + + public List getTrustedCertificates() { + this.updateIfRequired(); + return Collections.unmodifiableList(this.trustedCertificates); + } + + public List getTrustedIssuers() { + this.updateIfRequired(); + return Collections.unmodifiableList(this.trustedIssuers); + } + + private void updateIfRequired() { + + } +} diff --git a/src/main/java/tng/trustnetwork/keydistribution/service/SignerCertificateDownloadServiceImpl.java b/src/main/java/tng/trustnetwork/keydistribution/service/SignerCertificateDownloadServiceImpl.java index 8861095..bbca2f0 100644 --- a/src/main/java/tng/trustnetwork/keydistribution/service/SignerCertificateDownloadServiceImpl.java +++ b/src/main/java/tng/trustnetwork/keydistribution/service/SignerCertificateDownloadServiceImpl.java @@ -20,8 +20,6 @@ package tng.trustnetwork.keydistribution.service; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; -import eu.europa.ec.dgc.gateway.connector.model.TrustListItem; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -29,6 +27,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import tng.trustnetwork.keydistribution.model.TrustListItem; /** * A service to download the signer certificates from the digital green certificate gateway. @@ -39,7 +38,8 @@ @Profile("!btp") public class SignerCertificateDownloadServiceImpl implements SignerCertificateDownloadService { - private final DgcGatewayDownloadConnector dgcGatewayConnector; + DummyDownloadConnector dummyDownloadConnector = new DummyDownloadConnector(); + private final SignerInformationService signerInformationService; @Override @@ -49,11 +49,11 @@ public class SignerCertificateDownloadServiceImpl implements SignerCertificateDo public void downloadCertificates() { log.info("Certificates download started"); - List trustedCerts = dgcGatewayConnector.getTrustedCertificates(); + // TODO Dummy + List trustedCerts = dummyDownloadConnector.getTrustedCertificates(); signerInformationService.updateTrustedCertsList(trustedCerts); log.info("Certificates download finished"); } - } diff --git a/src/main/java/tng/trustnetwork/keydistribution/service/SignerInformationService.java b/src/main/java/tng/trustnetwork/keydistribution/service/SignerInformationService.java index 3d43c31..a4e7f7a 100644 --- a/src/main/java/tng/trustnetwork/keydistribution/service/SignerInformationService.java +++ b/src/main/java/tng/trustnetwork/keydistribution/service/SignerInformationService.java @@ -20,7 +20,6 @@ package tng.trustnetwork.keydistribution.service; -import eu.europa.ec.dgc.gateway.connector.model.TrustListItem; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; @@ -32,6 +31,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import tng.trustnetwork.keydistribution.entity.SignerInformationEntity; +import tng.trustnetwork.keydistribution.model.TrustListItem; import tng.trustnetwork.keydistribution.repository.SignerInformationRepository; import tng.trustnetwork.keydistribution.restapi.dto.CertificatesLookupResponseItemDto; import tng.trustnetwork.keydistribution.restapi.dto.DeltaListDto; @@ -43,7 +43,6 @@ public class SignerInformationService { private final SignerInformationRepository signerInformationRepository; - /** * Method to query the db for a certificate with a resume token. * @@ -58,7 +57,6 @@ public Optional getCertificate(Long resumeToken) { } } - /** * Method to query the db for a list of kid from all certificates. * @@ -72,7 +70,6 @@ public List getListOfValidKids() { } - /** * Method to synchronise the certificates in the db with the given List of trusted certificates. * @@ -86,7 +83,6 @@ public void updateTrustedCertsList(List trustedCerts) { List alreadyStoredCerts = getListOfValidKids(); List certsToDelete = new ArrayList<>(); - if (trustedCertsKids.isEmpty()) { signerInformationRepository.setAllDeleted(); return; @@ -94,7 +90,6 @@ public void updateTrustedCertsList(List trustedCerts) { signerInformationRepository.setDeletedByKidsNotIn(trustedCertsKids); } - List signerInformationEntities = new ArrayList<>(); for (TrustListItem cert : trustedCerts) { @@ -109,7 +104,6 @@ public void updateTrustedCertsList(List trustedCerts) { signerInformationRepository.saveAllAndFlush(signerInformationEntities); } - private SignerInformationEntity getSingerInformationEntity(TrustListItem cert) { SignerInformationEntity signerEntity = new SignerInformationEntity(); signerEntity.setKid(cert.getKid()); @@ -172,5 +166,4 @@ public Map> getCertificatesData( private CertificatesLookupResponseItemDto map(SignerInformationEntity entity) { return new CertificatesLookupResponseItemDto(entity.getKid(), entity.getRawData()); } - } diff --git a/src/main/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImpl.java b/src/main/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImpl.java index 3c54cff..17a6615 100644 --- a/src/main/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImpl.java +++ b/src/main/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImpl.java @@ -20,8 +20,8 @@ package tng.trustnetwork.keydistribution.service; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayTrustedIssuerDownloadConnector; -import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -30,6 +30,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import tng.trustnetwork.keydistribution.model.TrustedIssuer; /** * A service to download the signer certificates from the digital green certificate gateway. @@ -41,11 +42,9 @@ @ConditionalOnProperty("dgc.trustedIssuerDownloader.enabled") public class TrustedIssuerDownloadServiceImpl implements TrustedIssuerDownloadService { - private final DgcGatewayTrustedIssuerDownloadConnector downloadConnector; - + DummyDownloadConnector dummyDownloadConnector = new DummyDownloadConnector(); private final TrustedIssuerService trustedIssuerService; - @Override @Scheduled(fixedDelayString = "${dgc.trustedIssuerDownloader.timeInterval}") @SchedulerLock(name = "TrustedIssuerDownloadService_downloadTrustedIssuers", lockAtLeastFor = "PT0S", @@ -53,11 +52,10 @@ public class TrustedIssuerDownloadServiceImpl implements TrustedIssuerDownloadSe public void downloadTrustedIssuers() { log.info("Trusted issuers download started"); - List trustedIssuers = downloadConnector.getTrustedIssuers(); + List trustedIssuers = dummyDownloadConnector.getTrustedIssuers(); trustedIssuerService.updateTrustedIssuersList(trustedIssuers); log.info("Trusted issuers download finished. {} issuers downloaded.", trustedIssuers.size()); } - } diff --git a/src/main/java/tng/trustnetwork/keydistribution/service/TrustedIssuerService.java b/src/main/java/tng/trustnetwork/keydistribution/service/TrustedIssuerService.java index 63cea06..bd68cfd 100644 --- a/src/main/java/tng/trustnetwork/keydistribution/service/TrustedIssuerService.java +++ b/src/main/java/tng/trustnetwork/keydistribution/service/TrustedIssuerService.java @@ -20,7 +20,6 @@ package tng.trustnetwork.keydistribution.service; -import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -30,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional; import tng.trustnetwork.keydistribution.entity.TrustedIssuerEntity; import tng.trustnetwork.keydistribution.mapper.IssuerMapper; +import tng.trustnetwork.keydistribution.model.TrustedIssuer; import tng.trustnetwork.keydistribution.repository.TrustedIssuerRepository; @Slf4j @@ -56,7 +56,6 @@ public String getEtag() { return etag; } - /** * Method to query the db for all trusted issuers. * diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7790fe8..8a68d4d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -53,20 +53,5 @@ dgc: lockLimit: 3600000 gateway: connector: - enabled: true - endpoint: ${DGC_GATEWAY_CONNECTOR_ENDPOINT} - proxy: - enabled: false - max-cache-age: 300 - tls-trust-store: - password: ${DGC_GATEWAY_CONNECTOR_TLSTRUSTSTORE_PASSWORD} - path: ${DGC_GATEWAY_CONNECTOR_TLSTRUSTSTORE_PATH} - tls-key-store: - alias: ${DGC_GATEWAY_CONNECTOR_TLSKEYSTORE_ALIAS} - password: ${DGC_GATEWAY_CONNECTOR_TLSKEYSTORE_PASSWORD} - path: ${DGC_GATEWAY_CONNECTOR_TLSKEYSTORE_PATH} - trust-anchor: - alias: ${DGC_GATEWAY_CONNECTOR_TRUSTANCHOR_ALIAS} - password: ${DGC_GATEWAY_CONNECTOR_TRUSTANCHOR_PASSWORD} - path: ${DGC_GATEWAY_CONNECTOR_TRUSTANCHOR_PATH} + enabled: false diff --git a/src/test/java/tng/trustnetwork/keydistribution/OpenApiTest.java b/src/test/java/tng/trustnetwork/keydistribution/OpenApiTest.java index 1ac2834..984cc6f 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/OpenApiTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/OpenApiTest.java @@ -1,6 +1,5 @@ package tng.trustnetwork.keydistribution; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.net.URL; @@ -8,7 +7,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; @Slf4j @SpringBootTest( @@ -21,9 +19,6 @@ ) class OpenApiTest { - @MockBean - private DgcGatewayDownloadConnector dgcGatewayDownloadConnector; - @Test void apiDocs() { try (BufferedInputStream in = new BufferedInputStream(new URL("http://localhost:8080/openapi").openStream()); diff --git a/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/ContextControllerIntegrationTest.java b/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/ContextControllerIntegrationTest.java index 7a333eb..ba59d4d 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/ContextControllerIntegrationTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/ContextControllerIntegrationTest.java @@ -12,21 +12,16 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; @SpringBootTest @AutoConfigureMockMvc class ContextControllerIntegrationTest { - @MockBean - DgcGatewayDownloadConnector dgcGatewayDownloadConnector; - @Autowired private MockMvc mockMvc; diff --git a/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/ContextControllerWithEnvironmentIntegrationTest.java b/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/ContextControllerWithEnvironmentIntegrationTest.java index 6942499..4565e81 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/ContextControllerWithEnvironmentIntegrationTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/ContextControllerWithEnvironmentIntegrationTest.java @@ -11,16 +11,12 @@ import org.springframework.http.MediaType; import org.springframework.test.context.TestPropertySource; import org.springframework.test.web.servlet.MockMvc; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; @SpringBootTest @AutoConfigureMockMvc @TestPropertySource(properties = {"dgc.context={\"testContext\": true}"}) class ContextControllerWithEnvironmentIntegrationTest { - @MockBean - DgcGatewayDownloadConnector dgcGatewayDownloadConnector; - @Autowired private MockMvc mockMvc; diff --git a/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/SignerInformationIntegrationTest.java b/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/SignerInformationIntegrationTest.java index 1fd6511..a379a73 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/SignerInformationIntegrationTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/SignerInformationIntegrationTest.java @@ -20,7 +20,6 @@ package tng.trustnetwork.keydistribution.restapi.controller; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; import tng.trustnetwork.keydistribution.repository.SignerInformationRepository; import tng.trustnetwork.keydistribution.testdata.SignerInformationTestHelper; import java.io.UnsupportedEncodingException; @@ -31,7 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -48,9 +46,6 @@ class SignerInformationIntegrationTest { private static final String X_RESUME_TOKEN_HEADER = "X-RESUME-TOKEN"; private static final String X_KID_HEADER = "X-KID"; - @MockBean - DgcGatewayDownloadConnector dgcGatewayDownloadConnector; - @Autowired SignerInformationRepository signerInformationRepository; diff --git a/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/TrustedIssuerIntegrationTest.java b/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/TrustedIssuerIntegrationTest.java index 69a9c77..4410f7f 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/TrustedIssuerIntegrationTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/restapi/controller/TrustedIssuerIntegrationTest.java @@ -29,10 +29,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpHeaders; import org.springframework.test.web.servlet.MockMvc; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; import tng.trustnetwork.keydistribution.repository.TrustedIssuerRepository; import tng.trustnetwork.keydistribution.service.InfoService; import tng.trustnetwork.keydistribution.testdata.TrustedIssuerTestHelper; @@ -41,9 +39,6 @@ @AutoConfigureMockMvc class TrustedIssuerIntegrationTest { - @MockBean - DgcGatewayDownloadConnector dgcGatewayDownloadConnector; - @Autowired TrustedIssuerTestHelper trustedIssuerTestHelper; diff --git a/src/test/java/tng/trustnetwork/keydistribution/service/InfoServiceTest.java b/src/test/java/tng/trustnetwork/keydistribution/service/InfoServiceTest.java index 431b7dd..a3bce5c 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/service/InfoServiceTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/service/InfoServiceTest.java @@ -20,13 +20,11 @@ package tng.trustnetwork.keydistribution.service; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import tng.trustnetwork.keydistribution.entity.InfoEntity; import tng.trustnetwork.keydistribution.repository.InfoRepository; import java.util.List; @@ -34,9 +32,6 @@ @SpringBootTest class InfoServiceTest { - @MockBean - DgcGatewayDownloadConnector dgcGatewayDownloadConnector; - @Autowired InfoRepository infoRepository; diff --git a/src/test/java/tng/trustnetwork/keydistribution/service/SignerCertificateDownloadServiceImplTest.java b/src/test/java/tng/trustnetwork/keydistribution/service/SignerCertificateDownloadServiceImplTest.java index 5c02ebf..51c5f40 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/service/SignerCertificateDownloadServiceImplTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/service/SignerCertificateDownloadServiceImplTest.java @@ -1,8 +1,7 @@ package tng.trustnetwork.keydistribution.service; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; -import eu.europa.ec.dgc.gateway.connector.model.TrustListItem; import tng.trustnetwork.keydistribution.entity.SignerInformationEntity; +import tng.trustnetwork.keydistribution.model.TrustListItem; import tng.trustnetwork.keydistribution.repository.SignerInformationRepository; import tng.trustnetwork.keydistribution.testdata.SignerInformationTestHelper; import java.util.ArrayList; @@ -17,9 +16,6 @@ @SpringBootTest class SignerCertificateDownloadServiceImplTest { - @MockBean - DgcGatewayDownloadConnector dgcGatewayDownloadConnector; - @Autowired SignerCertificateDownloadServiceImpl signerCertificateDownloadService; @@ -29,30 +25,17 @@ class SignerCertificateDownloadServiceImplTest { @Autowired SignerInformationTestHelper signerInformationTestHelper; + @MockBean + DummyDownloadConnector dummyDownloadConnector; + @Test void downloadEmptyCertificatesList() { ArrayList trustList = new ArrayList<>(); - Mockito.when(dgcGatewayDownloadConnector.getTrustedCertificates()).thenReturn(trustList); + Mockito.when(dummyDownloadConnector.getTrustedCertificates()).thenReturn(trustList); signerCertificateDownloadService.downloadCertificates(); List repositoryItems = signerInformationRepository.findAllByDeletedOrderByIdAsc(false); Assertions.assertEquals(0, repositoryItems.size()); } - - @Test - void downloadCertificates() { - ArrayList trustList = new ArrayList<>(); - trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_1_STR)); - Mockito.when(dgcGatewayDownloadConnector.getTrustedCertificates()).thenReturn(trustList); - - signerCertificateDownloadService.downloadCertificates(); - - List repositoryItems = signerInformationRepository.findAll(); - Assertions.assertEquals(1, repositoryItems.size()); - - SignerInformationEntity repositoryItem = repositoryItems.get(0); - Assertions.assertEquals(SignerInformationTestHelper.TEST_CERT_1_KID, repositoryItem.getKid()); - Assertions.assertEquals(SignerInformationTestHelper.TEST_CERT_1_STR, repositoryItem.getRawData()); - } } diff --git a/src/test/java/tng/trustnetwork/keydistribution/service/SignerInformationServiceTest.java b/src/test/java/tng/trustnetwork/keydistribution/service/SignerInformationServiceTest.java index 2377bcc..ab9c886 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/service/SignerInformationServiceTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/service/SignerInformationServiceTest.java @@ -21,16 +21,14 @@ package tng.trustnetwork.keydistribution.service; import com.google.code.beanmatchers.BeanMatchers; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; -import eu.europa.ec.dgc.gateway.connector.model.TrustListItem; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import tng.trustnetwork.keydistribution.dto.TrustedIssuerDto; import tng.trustnetwork.keydistribution.entity.SignerInformationEntity; +import tng.trustnetwork.keydistribution.model.TrustListItem; import tng.trustnetwork.keydistribution.repository.SignerInformationRepository; import tng.trustnetwork.keydistribution.restapi.dto.DeltaListDto; import tng.trustnetwork.keydistribution.testdata.SignerInformationTestHelper; @@ -44,9 +42,6 @@ @SpringBootTest class SignerInformationServiceTest { - @MockBean - DgcGatewayDownloadConnector dgcGatewayDownloadConnector; - @Autowired SignerInformationRepository signerInformationRepository; diff --git a/src/test/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImplTest.java b/src/test/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImplTest.java index 5a35947..a42e064 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImplTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImplTest.java @@ -1,6 +1,7 @@ package tng.trustnetwork.keydistribution.service; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -11,8 +12,8 @@ import org.springframework.test.context.TestPropertySource; import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; import eu.europa.ec.dgc.gateway.connector.DgcGatewayTrustedIssuerDownloadConnector; -import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer; import tng.trustnetwork.keydistribution.entity.TrustedIssuerEntity; +import tng.trustnetwork.keydistribution.model.TrustedIssuer; import tng.trustnetwork.keydistribution.repository.TrustedIssuerRepository; import tng.trustnetwork.keydistribution.testdata.TrustedIssuerTestHelper; @@ -35,38 +36,17 @@ class TrustedIssuerDownloadServiceImplTest { @Autowired TrustedIssuerTestHelper trustedIssuerTestHelper; + @MockBean + DummyDownloadConnector dummyDownloadConnector; + @Test void downloadEmptyIssuerList() { ArrayList trustList = new ArrayList<>(); - Mockito.when(dgcGatewayDownloadConnector.getTrustedIssuers()).thenReturn(trustList); + Mockito.when(dummyDownloadConnector.getTrustedIssuers()).thenReturn(trustList); trustedIssuerDownloadService.downloadTrustedIssuers(); List repositoryItems = trustedIssuerRepository.findAll(); Assertions.assertEquals(0, repositoryItems.size()); } - - @Test - void downloadIssuers() { - List trustedIssuers = trustedIssuerTestHelper.getTrustedIssuerList(); - - Mockito.when(dgcGatewayDownloadConnector.getTrustedIssuers()).thenReturn(trustedIssuers); - - trustedIssuerDownloadService.downloadTrustedIssuers(); - - List repositoryItems = trustedIssuerRepository.findAll(); - Assertions.assertEquals(1, repositoryItems.size()); - - TrustedIssuer trustedIssuer = trustedIssuers.get(0); - - TrustedIssuerEntity repositoryItem = repositoryItems.get(0); - Assertions.assertEquals(trustedIssuer.getCountry(), repositoryItem.getCountry()); - Assertions.assertEquals(trustedIssuer.getKeyStorageType(), repositoryItem.getKeyStorageType()); - Assertions.assertEquals(trustedIssuer.getName(), repositoryItem.getName()); - Assertions.assertEquals(trustedIssuer.getSignature(), repositoryItem.getSignature()); - Assertions.assertEquals(trustedIssuer.getThumbprint(), repositoryItem.getThumbprint()); - Assertions.assertEquals(trustedIssuer.getSslPublicKey(), repositoryItem.getSslPublicKey()); - Assertions.assertEquals(trustedIssuer.getUrl(), repositoryItem.getUrl()); - Assertions.assertEquals(trustedIssuer.getType().toString(), repositoryItem.getUrlType().toString()); - } } diff --git a/src/test/java/tng/trustnetwork/keydistribution/testdata/SignerInformationTestHelper.java b/src/test/java/tng/trustnetwork/keydistribution/testdata/SignerInformationTestHelper.java index 5e86a61..bcdd6c9 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/testdata/SignerInformationTestHelper.java +++ b/src/test/java/tng/trustnetwork/keydistribution/testdata/SignerInformationTestHelper.java @@ -20,9 +20,9 @@ package tng.trustnetwork.keydistribution.testdata; -import eu.europa.ec.dgc.gateway.connector.model.TrustListItem; import eu.europa.ec.dgc.utils.CertificateUtils; import tng.trustnetwork.keydistribution.entity.SignerInformationEntity; +import tng.trustnetwork.keydistribution.model.TrustListItem; import tng.trustnetwork.keydistribution.repository.SignerInformationRepository; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/src/test/java/tng/trustnetwork/keydistribution/testdata/TrustedIssuerTestHelper.java b/src/test/java/tng/trustnetwork/keydistribution/testdata/TrustedIssuerTestHelper.java index 34a2838..e85015e 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/testdata/TrustedIssuerTestHelper.java +++ b/src/test/java/tng/trustnetwork/keydistribution/testdata/TrustedIssuerTestHelper.java @@ -23,12 +23,10 @@ import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - -import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer; import tng.trustnetwork.keydistribution.entity.TrustedIssuerEntity; +import tng.trustnetwork.keydistribution.model.TrustedIssuer; import tng.trustnetwork.keydistribution.repository.TrustedIssuerRepository; import lombok.RequiredArgsConstructor; @@ -83,7 +81,6 @@ public TrustedIssuerEntity getIssuer(int number) { } return issuer; - } public void insertTrustedIssuer(TrustedIssuerEntity issuer) { From e19048163d9ede97f1d649326b8234ec2fc90cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karsten=20Ra=CC=88th?= Date: Thu, 5 Oct 2023 18:15:59 +0200 Subject: [PATCH 2/2] fix: remove dgc-lib dependency --- pom.xml | 5 - .../TrustedIssuerDownloadServiceImplTest.java | 9 -- .../testdata/CertificateUtils.java | 108 ++++++++++++++++++ .../testdata/SignerInformationTestHelper.java | 1 - 4 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 src/test/java/tng/trustnetwork/keydistribution/testdata/CertificateUtils.java diff --git a/pom.xml b/pom.xml index 5b2a220..7a1e4cd 100644 --- a/pom.xml +++ b/pom.xml @@ -185,11 +185,6 @@ - - eu.europa.ec.dgc - ddcc-gateway-lib - 2.0.1 - org.springframework.boot spring-boot-starter diff --git a/src/test/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImplTest.java b/src/test/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImplTest.java index a42e064..23c8430 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImplTest.java +++ b/src/test/java/tng/trustnetwork/keydistribution/service/TrustedIssuerDownloadServiceImplTest.java @@ -1,7 +1,6 @@ package tng.trustnetwork.keydistribution.service; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -10,8 +9,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.TestPropertySource; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector; -import eu.europa.ec.dgc.gateway.connector.DgcGatewayTrustedIssuerDownloadConnector; import tng.trustnetwork.keydistribution.entity.TrustedIssuerEntity; import tng.trustnetwork.keydistribution.model.TrustedIssuer; import tng.trustnetwork.keydistribution.repository.TrustedIssuerRepository; @@ -21,12 +18,6 @@ @TestPropertySource(properties = {"dgc.trustedIssuerDownloader.enabled=true"}) class TrustedIssuerDownloadServiceImplTest { - @MockBean - DgcGatewayDownloadConnector dgcGatewayDownloadConnectorMock; - - @MockBean - DgcGatewayTrustedIssuerDownloadConnector dgcGatewayDownloadConnector; - @Autowired TrustedIssuerDownloadServiceImpl trustedIssuerDownloadService; diff --git a/src/test/java/tng/trustnetwork/keydistribution/testdata/CertificateUtils.java b/src/test/java/tng/trustnetwork/keydistribution/testdata/CertificateUtils.java new file mode 100644 index 0000000..c323c1c --- /dev/null +++ b/src/test/java/tng/trustnetwork/keydistribution/testdata/CertificateUtils.java @@ -0,0 +1,108 @@ +/*- + * ---license-start + * WorldHealthOrganization / tng-key-distribution + * --- + * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + +package tng.trustnetwork.keydistribution.testdata; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.Base64; +import org.bouncycastle.cert.X509CertificateHolder; +import org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateFactory; +import org.bouncycastle.util.encoders.Hex; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class CertificateUtils { + private static final Logger log = LoggerFactory.getLogger(CertificateUtils.class); + private static final byte KID_BYTE_COUNT = 8; + private final CertificateFactory certificateFactory = new CertificateFactory(); + + public CertificateUtils() { + } + + public String getCertKid(X509Certificate x509Certificate) { + try { + byte[] hashBytes = this.calculateHashBytes(x509Certificate.getEncoded()); + byte[] kidBytes = Arrays.copyOfRange(hashBytes, 0, 8); + return Base64.getEncoder().encodeToString(kidBytes); + } catch (NoSuchAlgorithmException | CertificateEncodingException var4) { + log.error("Could not calculate kid of certificate."); + return null; + } + } + + public String getCertKid(X509CertificateHolder x509CertificateHolder) { + try { + byte[] hashBytes = this.calculateHashBytes(x509CertificateHolder.getEncoded()); + byte[] kidBytes = Arrays.copyOfRange(hashBytes, 0, 8); + return Base64.getEncoder().encodeToString(kidBytes); + } catch (IOException | NoSuchAlgorithmException var4) { + log.error("Could not calculate kid of certificate."); + return null; + } + } + + public String getCertThumbprint(X509Certificate x509Certificate) { + try { + return this.calculateHash(x509Certificate.getEncoded()); + } catch (CertificateEncodingException | NoSuchAlgorithmException var3) { + log.error("Could not calculate thumbprint of certificate."); + return null; + } + } + + public String getCertThumbprint(X509CertificateHolder x509CertificateHolder) { + try { + return this.calculateHash(x509CertificateHolder.getEncoded()); + } catch (NoSuchAlgorithmException | IOException var3) { + log.error("Could not calculate thumbprint of certificate."); + return null; + } + } + + public X509CertificateHolder convertCertificate(X509Certificate inputCertificate) throws CertificateEncodingException, IOException { + return new X509CertificateHolder(inputCertificate.getEncoded()); + } + + public X509Certificate convertCertificate(X509CertificateHolder inputCertificate) throws CertificateException { + try { + return (X509Certificate)this.certificateFactory.engineGenerateCertificate(new ByteArrayInputStream(inputCertificate.getEncoded())); + } catch (IOException var3) { + throw new CertificateException(var3.getMessage(), var3.getCause()); + } + } + + public String calculateHash(byte[] data) throws NoSuchAlgorithmException { + byte[] certHashBytes = MessageDigest.getInstance("SHA-256").digest(data); + return Hex.toHexString(certHashBytes); + } + + private byte[] calculateHashBytes(byte[] data) throws NoSuchAlgorithmException { + return MessageDigest.getInstance("SHA-256").digest(data); + } +} diff --git a/src/test/java/tng/trustnetwork/keydistribution/testdata/SignerInformationTestHelper.java b/src/test/java/tng/trustnetwork/keydistribution/testdata/SignerInformationTestHelper.java index bcdd6c9..05e38ff 100644 --- a/src/test/java/tng/trustnetwork/keydistribution/testdata/SignerInformationTestHelper.java +++ b/src/test/java/tng/trustnetwork/keydistribution/testdata/SignerInformationTestHelper.java @@ -20,7 +20,6 @@ package tng.trustnetwork.keydistribution.testdata; -import eu.europa.ec.dgc.utils.CertificateUtils; import tng.trustnetwork.keydistribution.entity.SignerInformationEntity; import tng.trustnetwork.keydistribution.model.TrustListItem; import tng.trustnetwork.keydistribution.repository.SignerInformationRepository;