Skip to content

Commit

Permalink
dispatch cookbook/test + remove document test-jar
Browse files Browse the repository at this point in the history
  • Loading branch information
pvandenbroucke committed Sep 7, 2017
1 parent 779149a commit 0ea3c10
Show file tree
Hide file tree
Showing 95 changed files with 1,056 additions and 1,848 deletions.
6 changes: 0 additions & 6 deletions dss-asic-cades/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,5 @@
<artifactId>dss-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>eu.europa.ec.joinup.sd-dss</groupId>
<artifactId>dss-document</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import eu.europa.esig.dss.DSSUtils;
import eu.europa.esig.dss.InMemoryDocument;
import eu.europa.esig.dss.MimeType;
import eu.europa.esig.dss.SignatureAlgorithm;
import eu.europa.esig.dss.SignatureLevel;
import eu.europa.esig.dss.SignatureValue;
import eu.europa.esig.dss.ToBeSigned;
Expand All @@ -26,57 +25,47 @@
import eu.europa.esig.dss.asic.ASiCWithCAdESSignatureParameters;
import eu.europa.esig.dss.asic.AbstractASiCContainerExtractor;
import eu.europa.esig.dss.asic.signature.ASiCWithCAdESService;
import eu.europa.esig.dss.test.TestUtils;
import eu.europa.esig.dss.test.gen.CertificateService;
import eu.europa.esig.dss.test.mock.MockPrivateKeyEntry;
import eu.europa.esig.dss.validation.CertificateVerifier;
import eu.europa.esig.dss.validation.CommonCertificateVerifier;
import eu.europa.esig.dss.signature.PKIFactoryAccess;
import eu.europa.esig.dss.validation.SignedDocumentValidator;
import eu.europa.esig.dss.validation.policy.rules.Indication;
import eu.europa.esig.dss.validation.reports.Reports;
import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData;

public class ASiCECAdESLevelBMultiFilesParallelTest {
public class ASiCECAdESLevelBMultiFilesParallelTest extends PKIFactoryAccess {

@Test
public void test() throws Exception {
List<DSSDocument> documentToSigns = new ArrayList<DSSDocument>();
documentToSigns.add(new InMemoryDocument("Hello World !".getBytes(), "test.text", MimeType.TEXT));
documentToSigns.add(new InMemoryDocument("Bye World !".getBytes(), "test2.text", MimeType.TEXT));

CertificateService certificateService = new CertificateService();
MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);

ASiCWithCAdESSignatureParameters signatureParameters = new ASiCWithCAdESSignatureParameters();
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate());
signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E);

CertificateVerifier certificateVerifier = new CommonCertificateVerifier();
ASiCWithCAdESService service = new ASiCWithCAdESService(certificateVerifier);
ASiCWithCAdESService service = new ASiCWithCAdESService(getCompleteCertificateVerifier());

ToBeSigned dataToSign = service.getDataToSign(documentToSigns, signatureParameters);
SignatureValue signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign);
SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
DSSDocument signedDocument = service.signDocument(documentToSigns, signatureParameters, signatureValue);

privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate());
signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E);

certificateVerifier = new CommonCertificateVerifier();
service = new ASiCWithCAdESService(certificateVerifier);
service = new ASiCWithCAdESService(getCompleteCertificateVerifier());

dataToSign = service.getDataToSign(signedDocument, signatureParameters);
signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign);
signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
DSSDocument resignedDocument = service.signDocument(signedDocument, signatureParameters, signatureValue);

SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(resignedDocument);
validator.setCertificateVerifier(new CommonCertificateVerifier());
validator.setCertificateVerifier(getCompleteCertificateVerifier());

Reports reports = validator.validateDocument();

Expand Down Expand Up @@ -118,4 +107,9 @@ public void test() throws Exception {
}

}

@Override
protected String getSigningAlias() {
return GOOD_USER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,91 +12,76 @@
import eu.europa.esig.dss.ASiCContainerType;
import eu.europa.esig.dss.DSSDocument;
import eu.europa.esig.dss.InMemoryDocument;
import eu.europa.esig.dss.SignatureAlgorithm;
import eu.europa.esig.dss.SignatureLevel;
import eu.europa.esig.dss.SignatureValue;
import eu.europa.esig.dss.ToBeSigned;
import eu.europa.esig.dss.asic.ASiCWithCAdESSignatureParameters;
import eu.europa.esig.dss.asic.signature.ASiCWithCAdESService;
import eu.europa.esig.dss.test.TestUtils;
import eu.europa.esig.dss.test.gen.CertificateService;
import eu.europa.esig.dss.test.mock.MockPrivateKeyEntry;
import eu.europa.esig.dss.validation.CertificateVerifier;
import eu.europa.esig.dss.validation.CommonCertificateVerifier;
import eu.europa.esig.dss.signature.PKIFactoryAccess;
import eu.europa.esig.dss.validation.SignedDocumentValidator;
import eu.europa.esig.dss.validation.policy.rules.Indication;
import eu.europa.esig.dss.validation.reports.Reports;
import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData;

public class ASiCECAdESLevelBSignFourTimeTest {
public class ASiCECAdESLevelBSignFourTimeTest extends PKIFactoryAccess {

@Test
public void test() throws Exception {
DSSDocument documentToSign = new InMemoryDocument("Hello World !".getBytes(), "test.text");

CertificateService certificateService = new CertificateService();
MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);

ASiCWithCAdESSignatureParameters signatureParameters = new ASiCWithCAdESSignatureParameters();
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate());
signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E);

CertificateVerifier certificateVerifier = new CommonCertificateVerifier();
ASiCWithCAdESService service = new ASiCWithCAdESService(certificateVerifier);
ASiCWithCAdESService service = new ASiCWithCAdESService(getCompleteCertificateVerifier());

ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters);
SignatureValue signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign);
SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue);

privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate());
signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E);

certificateVerifier = new CommonCertificateVerifier();
service = new ASiCWithCAdESService(certificateVerifier);
service = new ASiCWithCAdESService(getCompleteCertificateVerifier());

dataToSign = service.getDataToSign(signedDocument, signatureParameters);
signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign);
signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
DSSDocument resignedDocument = service.signDocument(signedDocument, signatureParameters, signatureValue);

privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate());
signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E);

certificateVerifier = new CommonCertificateVerifier();
service = new ASiCWithCAdESService(certificateVerifier);
service = new ASiCWithCAdESService(getCompleteCertificateVerifier());

dataToSign = service.getDataToSign(resignedDocument, signatureParameters);
signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign);
signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
resignedDocument = service.signDocument(resignedDocument, signatureParameters, signatureValue);

privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate());
signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E);

certificateVerifier = new CommonCertificateVerifier();
service = new ASiCWithCAdESService(certificateVerifier);
service = new ASiCWithCAdESService(getCompleteCertificateVerifier());

dataToSign = service.getDataToSign(resignedDocument, signatureParameters);
signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign);
signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
resignedDocument = service.signDocument(resignedDocument, signatureParameters, signatureValue);

resignedDocument.save("target/resigned.asice");

SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(resignedDocument);
validator.setCertificateVerifier(new CommonCertificateVerifier());
validator.setCertificateVerifier(getCompleteCertificateVerifier());

Reports reports = validator.validateDocument();

Expand All @@ -109,4 +94,9 @@ public void test() throws Exception {
}

}

@Override
protected String getSigningAlias() {
return GOOD_USER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import eu.europa.esig.dss.DSSUtils;
import eu.europa.esig.dss.InMemoryDocument;
import eu.europa.esig.dss.MimeType;
import eu.europa.esig.dss.SignatureAlgorithm;
import eu.europa.esig.dss.SignatureLevel;
import eu.europa.esig.dss.SignatureValue;
import eu.europa.esig.dss.ToBeSigned;
Expand All @@ -26,57 +25,47 @@
import eu.europa.esig.dss.asic.ASiCWithCAdESSignatureParameters;
import eu.europa.esig.dss.asic.AbstractASiCContainerExtractor;
import eu.europa.esig.dss.asic.signature.ASiCWithCAdESService;
import eu.europa.esig.dss.test.TestUtils;
import eu.europa.esig.dss.test.gen.CertificateService;
import eu.europa.esig.dss.test.mock.MockPrivateKeyEntry;
import eu.europa.esig.dss.validation.CertificateVerifier;
import eu.europa.esig.dss.validation.CommonCertificateVerifier;
import eu.europa.esig.dss.signature.PKIFactoryAccess;
import eu.europa.esig.dss.validation.SignedDocumentValidator;
import eu.europa.esig.dss.validation.policy.rules.Indication;
import eu.europa.esig.dss.validation.reports.Reports;
import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData;

public class ASiCSCAdESLevelBMultiFilesParallelTest {
public class ASiCSCAdESLevelBMultiFilesParallelTest extends PKIFactoryAccess {

@Test
public void test() throws Exception {
List<DSSDocument> documentToSigns = new ArrayList<DSSDocument>();
documentToSigns.add(new InMemoryDocument("Hello World !".getBytes(), "test.text", MimeType.TEXT));
documentToSigns.add(new InMemoryDocument("Bye World !".getBytes(), "test2.text", MimeType.TEXT));

CertificateService certificateService = new CertificateService();
MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);

ASiCWithCAdESSignatureParameters signatureParameters = new ASiCWithCAdESSignatureParameters();
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate());
signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_S);

CertificateVerifier certificateVerifier = new CommonCertificateVerifier();
ASiCWithCAdESService service = new ASiCWithCAdESService(certificateVerifier);
ASiCWithCAdESService service = new ASiCWithCAdESService(getCompleteCertificateVerifier());

ToBeSigned dataToSign = service.getDataToSign(documentToSigns, signatureParameters);
SignatureValue signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign);
SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
DSSDocument signedDocument = service.signDocument(documentToSigns, signatureParameters, signatureValue);

privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);
signatureParameters.bLevel().setSigningDate(new Date());
signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate());
signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain());
signatureParameters.setSigningCertificate(getSigningCert());
signatureParameters.setCertificateChain(getCertificateChain());
signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_S);

certificateVerifier = new CommonCertificateVerifier();
service = new ASiCWithCAdESService(certificateVerifier);
service = new ASiCWithCAdESService(getCompleteCertificateVerifier());

dataToSign = service.getDataToSign(signedDocument, signatureParameters);
signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign);
signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry());
DSSDocument resignedDocument = service.signDocument(signedDocument, signatureParameters, signatureValue);

SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(resignedDocument);
validator.setCertificateVerifier(new CommonCertificateVerifier());
validator.setCertificateVerifier(getCompleteCertificateVerifier());

Reports reports = validator.validateDocument();

Expand Down Expand Up @@ -116,4 +105,9 @@ public void test() throws Exception {
}

}

@Override
protected String getSigningAlias() {
return GOOD_USER;
}
}
Loading

0 comments on commit 0ea3c10

Please sign in to comment.