Skip to content

Commit

Permalink
Merge pull request #25 from WorldHealthOrganization/feature/add-domai…
Browse files Browse the repository at this point in the history
…n-to-trustlist

feat(domain): added domain to signer information (DSC)
  • Loading branch information
tence authored May 10, 2024
2 parents 91d500c + 4450371 commit 4dca96c
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public class SignerInformationEntity {
private String country;

/**
* The thumbprint of the cert.
* The domain of the cert.
*/
@Column(name = "thumbprint")
private String thumbprint;
@Column(name = "domain")
private String domain;

/**
* Timestamp of the last record update.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector;
import eu.europa.ec.dgc.gateway.connector.model.TrustListItem;
import eu.europa.ec.dgc.gateway.connector.model.TrustedCertificateTrustListItem;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void downloadCertificates() {

log.info("Certificates download started");

List<TrustListItem> trustedCerts = dgcGatewayConnector.getTrustedCertificates();
List<TrustedCertificateTrustListItem> trustedCerts = dgcGatewayConnector.getDdccTrustedCertificates();
signerInformationService.updateTrustedCertsList(trustedCerts);

List<TrustListItem> trustedCsca = dgcGatewayConnector.getTrustedCscaCertificates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

package tng.trustnetwork.keydistribution.service;

import eu.europa.ec.dgc.gateway.connector.model.TrustListItem;
import eu.europa.ec.dgc.gateway.connector.model.TrustedCertificateTrustListItem;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -77,9 +77,10 @@ public List<String> getListOfValidKids() {
* @param trustedCerts defines the list of trusted certificates.
*/
@Transactional
public void updateTrustedCertsList(List<TrustListItem> trustedCerts) {
public void updateTrustedCertsList(List<TrustedCertificateTrustListItem> trustedCerts) {

List<String> trustedCertsKids = trustedCerts.stream().map(TrustListItem::getKid).collect(Collectors.toList());
List<String> trustedCertsKids = trustedCerts.stream().map(
TrustedCertificateTrustListItem::getKid).collect(Collectors.toList());
List<String> alreadyStoredCerts = getListOfValidKids();
List<String> certsToDelete = new ArrayList<>();

Expand All @@ -92,7 +93,7 @@ public void updateTrustedCertsList(List<TrustListItem> trustedCerts) {

List<SignerInformationEntity> signerInformationEntities = new ArrayList<>();

for (TrustListItem cert : trustedCerts) {
for (TrustedCertificateTrustListItem cert : trustedCerts) {
if (!alreadyStoredCerts.contains(cert.getKid())) {
signerInformationEntities.add(getSignerInformationEntity(cert));
certsToDelete.add(cert.getKid());
Expand All @@ -104,14 +105,14 @@ public void updateTrustedCertsList(List<TrustListItem> trustedCerts) {
signerInformationRepository.saveAllAndFlush(signerInformationEntities);
}

private SignerInformationEntity getSignerInformationEntity(TrustListItem cert) {
private SignerInformationEntity getSignerInformationEntity(TrustedCertificateTrustListItem cert) {

SignerInformationEntity signerEntity = new SignerInformationEntity();
signerEntity.setKid(cert.getKid());
signerEntity.setCreatedAt(cert.getTimestamp() == null ? ZonedDateTime.now() : cert.getTimestamp());
signerEntity.setCreatedAt(ZonedDateTime.now());
signerEntity.setCountry(cert.getCountry());
signerEntity.setThumbprint((cert.getThumbprint()));
signerEntity.setRawData(cert.getRawData());
signerEntity.setRawData(cert.getCertificate());
signerEntity.setDomain(cert.getDomain());

return signerEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private String generateTrustList(List<String> countries) throws Exception {

} else {
log.error("Public Key is not RSA or EC Public Key for cert {} of country {}",
signerInformationEntity.getThumbprint(),
signerInformationEntity.getKid(),
signerInformationEntity.getCountry());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ databaseChangeLog:
name: country
type: varchar(2)
- column:
name: thumbprint
name: domain
type: varchar(512)
- column:
name: updated_at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import eu.europa.ec.dgc.gateway.connector.model.TrustListItem;
import java.util.ArrayList;
import java.util.List;
import eu.europa.ec.dgc.gateway.connector.model.TrustedCertificateTrustListItem;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand Down Expand Up @@ -62,9 +63,9 @@ void downloadEmptyCertificatesList() {

@Test
void downloadCertificates() {
ArrayList<TrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_1_STR));
Mockito.when(dgcGatewayDownloadConnector.getTrustedCertificates()).thenReturn(trustList);
ArrayList<TrustedCertificateTrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_1_STR));
Mockito.when(dgcGatewayDownloadConnector.getDdccTrustedCertificates()).thenReturn(trustList);

signerCertificateDownloadService.downloadCertificates();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
package tng.trustnetwork.keydistribution.service;

import eu.europa.ec.dgc.gateway.connector.DgcGatewayDownloadConnector;
import eu.europa.ec.dgc.gateway.connector.model.TrustListItem;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import eu.europa.ec.dgc.gateway.connector.model.TrustedCertificateTrustListItem;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -60,7 +60,7 @@ void clearRepositoryData() {

@Test
void updateEmptyRepositoryWithEmptyCertList() {
ArrayList<TrustListItem> trustList = new ArrayList<>();
ArrayList<TrustedCertificateTrustListItem> trustList = new ArrayList<>();

signerInformationService.updateTrustedCertsList(trustList);

Expand All @@ -72,8 +72,8 @@ void updateEmptyRepositoryWithEmptyCertList() {

@Test
void updateEmptyRepositoryWithOneCert() {
ArrayList<TrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_1_STR));
ArrayList<TrustedCertificateTrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_1_STR));

signerInformationService.updateTrustedCertsList(trustList);

Expand All @@ -90,10 +90,10 @@ void updateEmptyRepositoryWithOneCert() {

@Test
void updateEmptyRepositoryWithCerts() {
ArrayList<TrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_1_STR));
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_2_STR));
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_3_STR));
ArrayList<TrustedCertificateTrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_1_STR));
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_2_STR));
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_3_STR));

signerInformationService.updateTrustedCertsList(trustList);

Expand All @@ -115,10 +115,10 @@ void updateEmptyRepositoryWithCerts() {

@Test
void updateEmptyRepositoryWithSameCertsTwice() {
ArrayList<TrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_1_STR));
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_2_STR));
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_3_STR));
ArrayList<TrustedCertificateTrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_1_STR));
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_2_STR));
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_3_STR));

signerInformationService.updateTrustedCertsList(trustList);

Expand Down Expand Up @@ -150,9 +150,9 @@ void updateRepositoryWithOneNewCertAndOneRevoked() {
signerInformationTestHelper.insertCertString(SignerInformationTestHelper.TEST_CERT_2_STR);


ArrayList<TrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_2_STR));
trustList.add(signerInformationTestHelper.createTrustListItem(SignerInformationTestHelper.TEST_CERT_3_STR));
ArrayList<TrustedCertificateTrustListItem> trustList = new ArrayList<>();
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_2_STR));
trustList.add(signerInformationTestHelper.createTrustedCertificateTrustListItem(SignerInformationTestHelper.TEST_CERT_3_STR));

signerInformationService.updateTrustedCertsList(trustList);

Expand All @@ -176,7 +176,7 @@ void updateRepositoryWithEmptyCertList() {
signerInformationTestHelper.insertCertString(SignerInformationTestHelper.TEST_CERT_2_STR);
signerInformationTestHelper.insertCertString(SignerInformationTestHelper.TEST_CERT_3_STR);

ArrayList<TrustListItem> trustList = new ArrayList<>();
ArrayList<TrustedCertificateTrustListItem> trustList = new ArrayList<>();

signerInformationService.updateTrustedCertsList(trustList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package tng.trustnetwork.keydistribution.testdata;

import eu.europa.ec.dgc.gateway.connector.model.TrustListItem;
import eu.europa.ec.dgc.gateway.connector.model.TrustedCertificateTrustListItem;
import eu.europa.ec.dgc.utils.CertificateUtils;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -167,4 +168,20 @@ public TrustListItem createTrustListItem(String certStr) {
return item;
}

public TrustedCertificateTrustListItem createTrustedCertificateTrustListItem(String certStr) {
String kid;
try {
kid = certificateUtils.getCertKid(convertStringToX509Cert(certStr));
}catch (CertificateException e) {
kid = "kid_"+ ZonedDateTime.now();
}

//TrustListItem item = new TrustListItem();
TrustedCertificateTrustListItem item = new TrustedCertificateTrustListItem();
item.setKid(kid);
item.setCertificate(certStr);

return item;
}

}

0 comments on commit 4dca96c

Please sign in to comment.