diff --git a/dss-asic-cades/pom.xml b/dss-asic-cades/pom.xml index a3d5ae3bb5..4268f4dc4d 100644 --- a/dss-asic-cades/pom.xml +++ b/dss-asic-cades/pom.xml @@ -25,11 +25,5 @@ dss-test test - - eu.europa.ec.joinup.sd-dss - dss-document - test-jar - test - \ No newline at end of file diff --git a/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCECAdESLevelBMultiFilesParallelTest.java b/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCECAdESLevelBMultiFilesParallelTest.java index 45075de7fc..6ab692b9dc 100644 --- a/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCECAdESLevelBMultiFilesParallelTest.java +++ b/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCECAdESLevelBMultiFilesParallelTest.java @@ -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; @@ -26,17 +25,13 @@ 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 { @@ -44,39 +39,33 @@ public void test() throws Exception { 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(); @@ -118,4 +107,9 @@ public void test() throws Exception { } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCECAdESLevelBSignFourTimeTest.java b/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCECAdESLevelBSignFourTimeTest.java index d9163add9d..b1d19ac73b 100644 --- a/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCECAdESLevelBSignFourTimeTest.java +++ b/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCECAdESLevelBSignFourTimeTest.java @@ -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(); @@ -109,4 +94,9 @@ public void test() throws Exception { } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSCAdESLevelBMultiFilesParallelTest.java b/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSCAdESLevelBMultiFilesParallelTest.java index f8dd31fc2e..cca53dd1bb 100644 --- a/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSCAdESLevelBMultiFilesParallelTest.java +++ b/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSCAdESLevelBMultiFilesParallelTest.java @@ -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; @@ -26,17 +25,13 @@ 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 { @@ -44,39 +39,33 @@ public void test() throws Exception { 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(); @@ -116,4 +105,9 @@ public void test() throws Exception { } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSCAdESLevelBSignFourTimeTest.java b/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSCAdESLevelBSignFourTimeTest.java index 9fc9839aba..48201486fb 100644 --- a/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSCAdESLevelBSignFourTimeTest.java +++ b/dss-asic-cades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSCAdESLevelBSignFourTimeTest.java @@ -12,89 +12,74 @@ 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 ASiCSCAdESLevelBSignFourTimeTest { +public class ASiCSCAdESLevelBSignFourTimeTest 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_S); - 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_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); - 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(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_S); - 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); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(resignedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); @@ -106,4 +91,9 @@ public void test() throws Exception { assertNotEquals(Indication.FAILED, reports.getSimpleReport().getIndication(sigId)); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-asic-xades/pom.xml b/dss-asic-xades/pom.xml index 365c96d88b..8d0bb97df9 100644 --- a/dss-asic-xades/pom.xml +++ b/dss-asic-xades/pom.xml @@ -20,17 +20,10 @@ dss-xades - eu.europa.ec.joinup.sd-dss dss-test test - - eu.europa.ec.joinup.sd-dss - dss-document - test-jar - test - \ No newline at end of file diff --git a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/CertificatePoolSharingTest.java b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/CertificatePoolSharingTest.java deleted file mode 100644 index 0f3c53016b..0000000000 --- a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/CertificatePoolSharingTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package eu.europa.esig.dss.asic.signature; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.Date; -import java.util.List; - -import org.junit.Test; - -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.ASiCWithXAdESSignatureParameters; -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.utils.Utils; -import eu.europa.esig.dss.validation.AdvancedSignature; -import eu.europa.esig.dss.validation.CertificateVerifier; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; -import eu.europa.esig.dss.validation.SignedDocumentValidator; -import eu.europa.esig.dss.validation.reports.Reports; - -public class CertificatePoolSharingTest { - - @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); - - ASiCWithXAdESSignatureParameters signatureParameters = new ASiCWithXAdESSignatureParameters(); - signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); - signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E); - - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - ASiCWithXAdESService service = new ASiCWithXAdESService(certificateVerifier); - - ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); - DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); - - SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); - - List signatures = validator.getSignatures(); - assertTrue(Utils.isCollectionNotEmpty(signatures)); - - Reports reports = validator.validateDocument(); - assertNotNull(reports); - } - -} diff --git a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCEXAdESLevelBMultiFilesParallelTest.java b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCEXAdESLevelBMultiFilesParallelTest.java index ee8d3bc087..38a01a6993 100644 --- a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCEXAdESLevelBMultiFilesParallelTest.java +++ b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCEXAdESLevelBMultiFilesParallelTest.java @@ -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; @@ -26,17 +25,13 @@ import eu.europa.esig.dss.asic.ASiCWithXAdESSignatureParameters; import eu.europa.esig.dss.asic.AbstractASiCContainerExtractor; import eu.europa.esig.dss.asic.signature.ASiCWithXAdESService; -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 ASiCEXAdESLevelBMultiFilesParallelTest { +public class ASiCEXAdESLevelBMultiFilesParallelTest extends PKIFactoryAccess { @Test public void test() throws Exception { @@ -44,39 +39,33 @@ public void test() throws Exception { 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); - ASiCWithXAdESSignatureParameters signatureParameters = new ASiCWithXAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - ASiCWithXAdESService service = new ASiCWithXAdESService(certificateVerifier); + ASiCWithXAdESService service = new ASiCWithXAdESService(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.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E); - certificateVerifier = new CommonCertificateVerifier(); - service = new ASiCWithXAdESService(certificateVerifier); + service = new ASiCWithXAdESService(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(); @@ -116,4 +105,9 @@ public void test() throws Exception { } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCEXAdESLevelBSignFourTimeTest.java b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCEXAdESLevelBSignFourTimeTest.java index a94b34f491..63b5875247 100644 --- a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCEXAdESLevelBSignFourTimeTest.java +++ b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asice/ASiCEXAdESLevelBSignFourTimeTest.java @@ -12,17 +12,12 @@ 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.ASiCWithXAdESSignatureParameters; import eu.europa.esig.dss.asic.signature.ASiCWithXAdESService; -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; @@ -32,73 +27,63 @@ * @author axel.abinet * */ -public class ASiCEXAdESLevelBSignFourTimeTest { +public class ASiCEXAdESLevelBSignFourTimeTest 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); - ASiCWithXAdESSignatureParameters signatureParameters = new ASiCWithXAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - ASiCWithXAdESService service = new ASiCWithXAdESService(certificateVerifier); + ASiCWithXAdESService service = new ASiCWithXAdESService(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.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E); - certificateVerifier = new CommonCertificateVerifier(); - service = new ASiCWithXAdESService(certificateVerifier); + service = new ASiCWithXAdESService(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.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E); - certificateVerifier = new CommonCertificateVerifier(); - service = new ASiCWithXAdESService(certificateVerifier); + service = new ASiCWithXAdESService(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.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_E); - certificateVerifier = new CommonCertificateVerifier(); - service = new ASiCWithXAdESService(certificateVerifier); + service = new ASiCWithXAdESService(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); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(resignedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); @@ -110,4 +95,9 @@ public void test() throws Exception { assertNotEquals(Indication.FAILED, reports.getSimpleReport().getIndication(sigId)); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSXAdESLevelBMultiFilesParallelTest.java b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSXAdESLevelBMultiFilesParallelTest.java index 8cdff9b0ed..b0839455e6 100644 --- a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSXAdESLevelBMultiFilesParallelTest.java +++ b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSXAdESLevelBMultiFilesParallelTest.java @@ -20,7 +20,6 @@ import eu.europa.esig.dss.FileDocument; 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; @@ -29,17 +28,13 @@ import eu.europa.esig.dss.asic.ASiCWithXAdESSignatureParameters; import eu.europa.esig.dss.asic.AbstractASiCContainerExtractor; import eu.europa.esig.dss.asic.signature.ASiCWithXAdESService; -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 ASiCSXAdESLevelBMultiFilesParallelTest { +public class ASiCSXAdESLevelBMultiFilesParallelTest extends PKIFactoryAccess { @Test public void test() throws Exception { @@ -47,35 +42,29 @@ public void test() throws Exception { 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); - ASiCWithXAdESSignatureParameters signatureParameters = new ASiCWithXAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_S); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - ASiCWithXAdESService service = new ASiCWithXAdESService(certificateVerifier); + ASiCWithXAdESService service = new ASiCWithXAdESService(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.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_S); - certificateVerifier = new CommonCertificateVerifier(); - service = new ASiCWithXAdESService(certificateVerifier); + service = new ASiCWithXAdESService(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); resignedDocument.writeTo(new FileOutputStream(new File("target/resigned.asics"))); @@ -83,7 +72,7 @@ public void test() throws Exception { DSSDocument docToCheck = new FileDocument(new File("target/resigned.asics")); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(docToCheck); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); @@ -124,4 +113,9 @@ public void test() throws Exception { } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSXAdESLevelBSignFourTimeTest.java b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSXAdESLevelBSignFourTimeTest.java index 4ecf95c418..db58f45394 100644 --- a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSXAdESLevelBSignFourTimeTest.java +++ b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/signature/asics/ASiCSXAdESLevelBSignFourTimeTest.java @@ -12,17 +12,12 @@ 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.ASiCWithXAdESSignatureParameters; import eu.europa.esig.dss.asic.signature.ASiCWithXAdESService; -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; @@ -32,73 +27,63 @@ * @author axel.abinet * */ -public class ASiCSXAdESLevelBSignFourTimeTest { +public class ASiCSXAdESLevelBSignFourTimeTest 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); - ASiCWithXAdESSignatureParameters signatureParameters = new ASiCWithXAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_S); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - ASiCWithXAdESService service = new ASiCWithXAdESService(certificateVerifier); + ASiCWithXAdESService service = new ASiCWithXAdESService(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.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_S); - certificateVerifier = new CommonCertificateVerifier(); - service = new ASiCWithXAdESService(certificateVerifier); + service = new ASiCWithXAdESService(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.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_S); - certificateVerifier = new CommonCertificateVerifier(); - service = new ASiCWithXAdESService(certificateVerifier); + service = new ASiCWithXAdESService(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.XAdES_BASELINE_B); signatureParameters.aSiC().setContainerType(ASiCContainerType.ASiC_S); - certificateVerifier = new CommonCertificateVerifier(); - service = new ASiCWithXAdESService(certificateVerifier); + service = new ASiCWithXAdESService(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); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(resignedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); // reports.print(); @@ -111,4 +96,9 @@ public void test() throws Exception { assertNotEquals(Indication.FAILED, reports.getSimpleReport().getIndication(sigId)); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/validation/ASiCE_XAdESLTACheckTimeStampIDTest.java b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/validation/ASiCE_XAdESLTACheckTimeStampIDTest.java index c25849681d..33639fff4e 100644 --- a/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/validation/ASiCE_XAdESLTACheckTimeStampIDTest.java +++ b/dss-asic-xades/src/test/java/eu/europa/esig/dss/asic/validation/ASiCE_XAdESLTACheckTimeStampIDTest.java @@ -8,15 +8,12 @@ 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.ASiCWithXAdESSignatureParameters; import eu.europa.esig.dss.asic.signature.ASiCWithXAdESService; import eu.europa.esig.dss.signature.PKIFactoryAccess; -import eu.europa.esig.dss.test.gen.CertificateService; -import eu.europa.esig.dss.test.mock.MockPrivateKeyEntry; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; @@ -28,9 +25,6 @@ public class ASiCE_XAdESLTACheckTimeStampIDTest extends PKIFactoryAccess { 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); - ASiCWithXAdESSignatureParameters signatureParameters = new ASiCWithXAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); signatureParameters.setSigningCertificate(getSigningCert()); diff --git a/dss-cades/pom.xml b/dss-cades/pom.xml index 20f28eb26c..67a4b17625 100644 --- a/dss-cades/pom.xml +++ b/dss-cades/pom.xml @@ -24,17 +24,5 @@ dss-test test - - eu.europa.ec.joinup.sd-dss - dss-service - test - - - eu.europa.ec.joinup.sd-dss - dss-document - test-jar - test - - \ No newline at end of file diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/extension/ExtendToCAdESLtaTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/extension/ExtendToCAdESLtaTest.java index 532168bdb6..ef004ff177 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/extension/ExtendToCAdESLtaTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/extension/ExtendToCAdESLtaTest.java @@ -12,13 +12,10 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.DSSException; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.cades.CAdESSignatureParameters; import eu.europa.esig.dss.cades.signature.CAdESService; -import eu.europa.esig.dss.test.gen.CertificateService; -import eu.europa.esig.dss.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; @@ -26,7 +23,7 @@ /** * Unit test to fix issue https://esig-dss.atlassian.net/browse/DSS-646 */ -public class ExtendToCAdESLtaTest { +public class ExtendToCAdESLtaTest extends PKIFactoryAccess { private static final String SIGNED_DOC_PATH = "src/test/resources/validation/dss-646/CAdES_A_DETACHED.csig"; private static final String DETACHED_DOC_PATH = "src/test/resources/validation/dss-646/document.pdf"; @@ -34,7 +31,7 @@ public class ExtendToCAdESLtaTest { @Test public void testValidation() { SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(new FileDocument(SIGNED_DOC_PATH)); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); List detachedContents = new ArrayList(); detachedContents.add(new FileDocument(DETACHED_DOC_PATH)); validator.setDetachedContents(detachedContents); @@ -51,10 +48,8 @@ public void testValidation() { @Test(expected = DSSException.class) public void testExtend() throws Exception { - CertificateService certificateService = new CertificateService(); - - CAdESService service = new CAdESService(new CommonCertificateVerifier()); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA256))); + CAdESService service = new CAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); CAdESSignatureParameters parameters = new CAdESSignatureParameters(); parameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_LTA); @@ -64,4 +59,10 @@ public void testExtend() throws Exception { assertNotNull(extendDocument); } + @Override + protected String getSigningAlias() { + // not for signing + return null; + } + } diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESDoubleSignatureDetachedTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESDoubleSignatureDetachedTest.java index 53af19bb0e..92197e8eda 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESDoubleSignatureDetachedTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESDoubleSignatureDetachedTest.java @@ -11,64 +11,53 @@ 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.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.cades.CAdESSignatureParameters; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; -public class CAdESDoubleSignatureDetachedTest { +public class CAdESDoubleSignatureDetachedTest 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); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); + CAdESService service = new CAdESService(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.setSignaturePackaging(SignaturePackaging.DETACHED); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); List detachedContents = new ArrayList(); detachedContents.add(documentToSign); signatureParameters.setDetachedContents(detachedContents); - certificateVerifier = new CommonCertificateVerifier(); - service = new CAdESService(certificateVerifier); + service = new CAdESService(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.setDetachedContents(detachedContents); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); @@ -80,4 +69,9 @@ public void test() throws Exception { assertTrue(diagnosticData.isBLevelTechnicallyValid(id)); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESDoubleSignatureTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESDoubleSignatureTest.java index f9639666f4..5f1b09d603 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESDoubleSignatureTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESDoubleSignatureTest.java @@ -9,17 +9,12 @@ 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.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.cades.CAdESSignatureParameters; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; @@ -28,45 +23,39 @@ * @author axel.abinet * */ -public class CAdESDoubleSignatureTest { +public class CAdESDoubleSignatureTest 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); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); + CAdESService service = new CAdESService(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.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); - certificateVerifier = new CommonCertificateVerifier(); - service = new CAdESService(certificateVerifier); + service = new CAdESService(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(); @@ -78,4 +67,10 @@ public void test() throws Exception { assertTrue(diagnosticData.isBLevelTechnicallyValid(id)); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedDigestDocumentTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedDigestDocumentTest.java index df7252c32b..02448a9249 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedDigestDocumentTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedDigestDocumentTest.java @@ -39,7 +39,6 @@ import eu.europa.esig.dss.signature.AbstractPkiFactoryTestDocumentSignatureService; import eu.europa.esig.dss.signature.DocumentSignatureService; import eu.europa.esig.dss.utils.Utils; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; @@ -66,7 +65,7 @@ public void init() throws Exception { @Override protected Reports getValidationReport(final DSSDocument signedDocument) { SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); InMemoryDocument inMemoryDocument = new InMemoryDocument("Hello World !".getBytes(), "test.text"); byte[] bytes; diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedTest.java index dc72d59d03..18d639cd26 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedTest.java @@ -33,7 +33,6 @@ import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.cades.CAdESSignatureParameters; import eu.europa.esig.dss.signature.DocumentSignatureService; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; @@ -61,7 +60,7 @@ public void init() throws Exception { @Override protected Reports getValidationReport(final DSSDocument signedDocument) { SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); List detachedContents = new ArrayList(); detachedContents.add(documentToSign); validator.setDetachedContents(detachedContents); diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedWithContentTimestampTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedWithContentTimestampTest.java index 28f5459821..076a09eb9f 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedWithContentTimestampTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBDetachedWithContentTimestampTest.java @@ -38,7 +38,6 @@ import eu.europa.esig.dss.cades.CAdESSignatureParameters; import eu.europa.esig.dss.client.tsp.OnlineTSPSource; import eu.europa.esig.dss.signature.DocumentSignatureService; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.TimestampToken; import eu.europa.esig.dss.validation.reports.Reports; @@ -74,7 +73,7 @@ public void init() throws Exception { @Override protected Reports getValidationReport(final DSSDocument signedDocument) { SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); List detachedContents = new ArrayList(); detachedContents.add(documentToSign); validator.setDetachedContents(detachedContents); diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBWithTwoContentTimestampsTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBWithTwoContentTimestampsTest.java index 10e0d3e68f..85b634bf0f 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBWithTwoContentTimestampsTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/CAdESLevelBWithTwoContentTimestampsTest.java @@ -36,8 +36,6 @@ import eu.europa.esig.dss.cades.CAdESSignatureParameters; import eu.europa.esig.dss.client.tsp.OnlineTSPSource; import eu.europa.esig.dss.signature.DocumentSignatureService; -import eu.europa.esig.dss.validation.CertificateVerifier; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.TimestampToken; import eu.europa.esig.dss.x509.CertificatePool; import eu.europa.esig.dss.x509.TimestampType; @@ -70,8 +68,7 @@ public void init() throws Exception { signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); signatureParameters.setContentTimestamps(Arrays.asList(contentTimestamp1, contentTimestamp2)); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - service = new CAdESService(certificateVerifier); + service = new CAdESService(getCompleteCertificateVerifier()); } @Override diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/DSS798Test.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/DSS798Test.java index 48941f7a0f..d5d4e8a248 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/DSS798Test.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/signature/DSS798Test.java @@ -12,51 +12,40 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.DSSException; import eu.europa.esig.dss.InMemoryDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.cades.CAdESSignatureParameters; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.SimpleReport; -public class DSS798Test { +public class DSS798Test extends PKIFactoryAccess { @Test(expected = DSSException.class) public void testExtendDetachedWithoutFile() throws Exception { DSSDocument documentToSign = new InMemoryDocument("Hello".getBytes(Charsets.UTF_8), "bin.bin"); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); + CAdESService service = new CAdESService(getCompleteCertificateVerifier()); // Level B ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); // Level T without detached document - CertificateVerifier certificateVerifierExtend = new CommonCertificateVerifier(); - CAdESService serviceExtend = new CAdESService(certificateVerifierExtend); - serviceExtend.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA256))); + CAdESService serviceExtend = new CAdESService(getCompleteCertificateVerifier()); + serviceExtend.setTspSource(getGoodTsa()); CAdESSignatureParameters parametersExtend = new CAdESSignatureParameters(); parametersExtend.setSignatureLevel(SignatureLevel.CAdES_BASELINE_T); @@ -68,28 +57,23 @@ public void testExtendDetachedWithFile() throws Exception { DSSDocument documentToSign = new InMemoryDocument("Hello".getBytes(Charsets.UTF_8), "bin.bin"); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); + CAdESService service = new CAdESService(getCompleteCertificateVerifier()); // Level B ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); // Level T with detached document - CertificateVerifier certificateVerifierExtend = new CommonCertificateVerifier(); - CAdESService serviceExtend = new CAdESService(certificateVerifierExtend); - serviceExtend.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA256))); + CAdESService serviceExtend = new CAdESService(getCompleteCertificateVerifier()); + serviceExtend.setTspSource(getGoodTsa()); CAdESSignatureParameters parametersExtend = new CAdESSignatureParameters(); parametersExtend.setSignatureLevel(SignatureLevel.CAdES_BASELINE_T); @@ -97,7 +81,7 @@ public void testExtendDetachedWithFile() throws Exception { DSSDocument extendedDocument = serviceExtend.extendDocument(signedDocument, parametersExtend); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(extendedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); validator.setDetachedContents(Arrays.asList(documentToSign)); Reports reports = validator.validateDocument(); reports.print(); @@ -106,4 +90,9 @@ public void testExtendDetachedWithFile() throws Exception { assertEquals(SignatureLevel.CAdES_BASELINE_T.toString(), simpleReport.getSignatureFormat(simpleReport.getFirstSignatureId())); } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESBExtendToLTACheckTimeStampIDTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESBExtendToLTACheckTimeStampIDTest.java index 312d0653fd..d06a6d7e8b 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESBExtendToLTACheckTimeStampIDTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESBExtendToLTACheckTimeStampIDTest.java @@ -7,46 +7,36 @@ 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.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.cades.CAdESSignatureParameters; import eu.europa.esig.dss.cades.signature.CAdESService; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; import eu.europa.esig.dss.validation.reports.wrapper.TimestampWrapper; -public class CAdESBExtendToLTACheckTimeStampIDTest { +public class CAdESBExtendToLTACheckTimeStampIDTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new InMemoryDocument("Hello World".getBytes()); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + CAdESService service = new CAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); + SignatureValue signatureValue = getToken().sign(toBeSigned, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_LTA); @@ -54,7 +44,7 @@ public void test() throws Exception { signedDocument = service.extendDocument(signedDocument, signatureParameters); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); @@ -64,4 +54,10 @@ public void test() throws Exception { Assert.assertEquals(signatureId, wrapper.getSignedObjects().getSignedSignature().get(0).getId()); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESLTACheckTimeStampIDTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESLTACheckTimeStampIDTest.java index 78c0c86b59..4fe9d9bb38 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESLTACheckTimeStampIDTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESLTACheckTimeStampIDTest.java @@ -7,50 +7,40 @@ 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.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.cades.CAdESSignatureParameters; import eu.europa.esig.dss.cades.signature.CAdESService; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; import eu.europa.esig.dss.validation.reports.wrapper.TimestampWrapper; -public class CAdESLTACheckTimeStampIDTest { +public class CAdESLTACheckTimeStampIDTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new InMemoryDocument("Hello World".getBytes()); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_LTA); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + CAdESService service = new CAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); + SignatureValue signatureValue = getToken().sign(toBeSigned, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); @@ -60,4 +50,9 @@ public void test() throws Exception { Assert.assertEquals(signatureId, wrapper.getSignedObjects().getSignedSignature().get(0).getId()); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESLTACheckTimeStampedTimestampIDTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESLTACheckTimeStampedTimestampIDTest.java index 5f48cb9c25..ae9038d9fc 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESLTACheckTimeStampedTimestampIDTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CAdESLTACheckTimeStampedTimestampIDTest.java @@ -7,51 +7,41 @@ 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.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.cades.CAdESSignatureParameters; import eu.europa.esig.dss.cades.signature.CAdESService; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; import eu.europa.esig.dss.validation.reports.wrapper.TimestampWrapper; import eu.europa.esig.dss.x509.TimestampType; -public class CAdESLTACheckTimeStampedTimestampIDTest { +public class CAdESLTACheckTimeStampedTimestampIDTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new InMemoryDocument("Hello World".getBytes()); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_LTA); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + CAdESService service = new CAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); + SignatureValue signatureValue = getToken().sign(toBeSigned, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); @@ -63,4 +53,9 @@ public void test() throws Exception { } } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CMSTimestampValidatorTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CMSTimestampValidatorTest.java index ad212ab5f2..f322289e00 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CMSTimestampValidatorTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/CMSTimestampValidatorTest.java @@ -9,26 +9,24 @@ import eu.europa.esig.dss.DSSUtils; import eu.europa.esig.dss.DigestAlgorithm; import eu.europa.esig.dss.InMemoryDocument; -import eu.europa.esig.dss.SignatureAlgorithm; -import eu.europa.esig.dss.test.gen.CertificateService; -import eu.europa.esig.dss.test.mock.MockTSPSource; +import eu.europa.esig.dss.signature.PKIFactoryAccess; import eu.europa.esig.dss.utils.Utils; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.TimestampToken; +import eu.europa.esig.dss.x509.tsp.TSPSource; -public class CMSTimestampValidatorTest { +public class CMSTimestampValidatorTest extends PKIFactoryAccess { @Test public void testValidator() throws Exception { - CertificateService certificateService = new CertificateService(); - MockTSPSource mockTSPSource = new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA256)); + + TSPSource tspSource = getGoodTsa(); byte[] data = new byte[] { 1, 2, 3 }; - TimeStampToken timeStampResponse = mockTSPSource.getTimeStampResponse(DigestAlgorithm.SHA256, DSSUtils.digest(DigestAlgorithm.SHA256, data)); + TimeStampToken timeStampResponse = tspSource.getTimeStampResponse(DigestAlgorithm.SHA256, DSSUtils.digest(DigestAlgorithm.SHA256, data)); CMSTimestampValidator validator = new CMSTimestampValidator(new InMemoryDocument(timeStampResponse.getEncoded())); validator.setTimestampedData(new InMemoryDocument(data)); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); assertTrue(Utils.isCollectionEmpty(validator.getSignatures())); @@ -38,4 +36,10 @@ public void testValidator() throws Exception { assertTrue(timestamp.isMessageImprintDataIntact()); } + @Override + protected String getSigningAlias() { + // not for signing + return null; + } + } diff --git a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/GetOriginalDocumentTest.java b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/GetOriginalDocumentTest.java index f72cf9cf1c..931685ce98 100644 --- a/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/GetOriginalDocumentTest.java +++ b/dss-cades/src/test/java/eu/europa/esig/dss/cades/validation/GetOriginalDocumentTest.java @@ -10,23 +10,18 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.DSSException; import eu.europa.esig.dss.InMemoryDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.cades.CAdESSignatureParameters; import eu.europa.esig.dss.cades.signature.CAdESService; -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.signature.PKIFactoryAccess; import eu.europa.esig.dss.utils.Utils; -import eu.europa.esig.dss.validation.CertificateVerifier; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; -public class GetOriginalDocumentTest { +public class GetOriginalDocumentTest extends PKIFactoryAccess { private static String HELLO_WORLD = "HELLO WORLD !"; @@ -34,25 +29,21 @@ public class GetOriginalDocumentTest { public final void getOriginalDocumentFromEnvelopingSignature() throws Exception { DSSDocument document = new InMemoryDocument(HELLO_WORLD.getBytes()); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); + CAdESService service = new CAdESService(getCompleteCertificateVerifier()); ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); List results = validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId()); @@ -67,25 +58,21 @@ public final void getOriginalDocumentFromEnvelopingSignature() throws Exception public final void getOriginalDocumentFromEnvelopingSignatureWithBase64EncodedContent() throws Exception { DSSDocument document = new InMemoryDocument(Base64.encode(HELLO_WORLD.getBytes())); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); + CAdESService service = new CAdESService(getCompleteCertificateVerifier()); ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); List results = validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId()); @@ -100,27 +87,28 @@ public final void getOriginalDocumentFromEnvelopingSignatureWithBase64EncodedCon public final void getOriginalDocumentFromDetachedSignature() throws Exception { DSSDocument document = new InMemoryDocument(HELLO_WORLD.getBytes()); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - CAdESSignatureParameters signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - CAdESService service = new CAdESService(certificateVerifier); + CAdESService service = new CAdESService(getCompleteCertificateVerifier()); ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId()); } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/Cookbook.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/Cookbook.java index c357773164..0eabdab062 100644 --- a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/Cookbook.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/Cookbook.java @@ -27,8 +27,8 @@ import eu.europa.esig.dss.DSSException; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.SignatureAlgorithm; +import eu.europa.esig.dss.cookbook.mock.MockTSPSource; import eu.europa.esig.dss.test.gen.CertificateService; -import eu.europa.esig.dss.test.mock.MockTSPSource; import eu.europa.esig.dss.token.AbstractSignatureTokenConnection; import eu.europa.esig.dss.token.DSSPrivateKeyEntry; import eu.europa.esig.dss.token.Pkcs12SignatureToken; diff --git a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/sign/SignXmlXadesBAllDataObjectsTimestamp.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/sign/SignXmlXadesBAllDataObjectsTimestamp.java index acd8e58b82..baa03a278c 100644 --- a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/sign/SignXmlXadesBAllDataObjectsTimestamp.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/sign/SignXmlXadesBAllDataObjectsTimestamp.java @@ -35,8 +35,8 @@ import eu.europa.esig.dss.TimestampParameters; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.cookbook.example.Cookbook; +import eu.europa.esig.dss.cookbook.mock.MockTSPSource; import eu.europa.esig.dss.cookbook.timestamp.TimestampService; -import eu.europa.esig.dss.test.mock.MockTSPSource; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.TimestampToken; import eu.europa.esig.dss.x509.CertificatePool; diff --git a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateDetached.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateDetached.java index 97fe83fac3..9696181f6e 100644 --- a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateDetached.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateDetached.java @@ -27,7 +27,7 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.cookbook.example.Cookbook; -import eu.europa.esig.dss.test.mock.MockServiceInfo; +import eu.europa.esig.dss.cookbook.mock.MockServiceInfo; import eu.europa.esig.dss.tsl.ServiceInfo; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; diff --git a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateExtendedSignedXmlXadesBtoT.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateExtendedSignedXmlXadesBtoT.java index 7ebe0d5331..ddee0d7e5b 100644 --- a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateExtendedSignedXmlXadesBtoT.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateExtendedSignedXmlXadesBtoT.java @@ -25,9 +25,9 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.cookbook.example.Cookbook; +import eu.europa.esig.dss.cookbook.mock.MockServiceInfo; import eu.europa.esig.dss.cookbook.mock.MockTSLCertificateSource; import eu.europa.esig.dss.cookbook.sources.AlwaysValidOCSPSource; -import eu.europa.esig.dss.test.mock.MockServiceInfo; import eu.europa.esig.dss.tsl.ServiceInfo; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; diff --git a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedPdfPadesB.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedPdfPadesB.java index aa67f403ab..b9964a9e4c 100644 --- a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedPdfPadesB.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedPdfPadesB.java @@ -25,9 +25,9 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.cookbook.example.Cookbook; +import eu.europa.esig.dss.cookbook.mock.MockServiceInfo; import eu.europa.esig.dss.cookbook.mock.MockTSLCertificateSource; import eu.europa.esig.dss.cookbook.sources.AlwaysValidOCSPSource; -import eu.europa.esig.dss.test.mock.MockServiceInfo; import eu.europa.esig.dss.tsl.ServiceInfo; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; diff --git a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlCadesB.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlCadesB.java index 8ba0de6cdd..21b99bd8a5 100644 --- a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlCadesB.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlCadesB.java @@ -25,9 +25,9 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.cookbook.example.Cookbook; +import eu.europa.esig.dss.cookbook.mock.MockServiceInfo; import eu.europa.esig.dss.cookbook.mock.MockTSLCertificateSource; import eu.europa.esig.dss.cookbook.sources.AlwaysValidOCSPSource; -import eu.europa.esig.dss.test.mock.MockServiceInfo; import eu.europa.esig.dss.tsl.ServiceInfo; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; diff --git a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesBWithCustomPolicy.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesBWithCustomPolicy.java index 6e62aceae7..de6957a31f 100644 --- a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesBWithCustomPolicy.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesBWithCustomPolicy.java @@ -25,9 +25,9 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.cookbook.example.Cookbook; +import eu.europa.esig.dss.cookbook.mock.MockServiceInfo; import eu.europa.esig.dss.cookbook.mock.MockTSLCertificateSource; import eu.europa.esig.dss.cookbook.sources.AlwaysValidOCSPSource; -import eu.europa.esig.dss.test.mock.MockServiceInfo; import eu.europa.esig.dss.tsl.ServiceInfo; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; diff --git a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesLT.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesLT.java index 5fd0254ea7..41711f79e0 100644 --- a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesLT.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesLT.java @@ -25,9 +25,9 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.cookbook.example.Cookbook; +import eu.europa.esig.dss.cookbook.mock.MockServiceInfo; import eu.europa.esig.dss.cookbook.mock.MockTSLCertificateSource; import eu.europa.esig.dss.cookbook.sources.AlwaysValidOCSPSource; -import eu.europa.esig.dss.test.mock.MockServiceInfo; import eu.europa.esig.dss.tsl.ServiceInfo; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; diff --git a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockCRLSource.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockCRLSource.java similarity index 98% rename from dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockCRLSource.java rename to dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockCRLSource.java index f2ec3c2ea1..8661ba7b2e 100644 --- a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockCRLSource.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockCRLSource.java @@ -18,7 +18,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -package eu.europa.esig.dss.test.mock; +package eu.europa.esig.dss.cookbook.mock; import java.io.IOException; import java.io.InputStream; diff --git a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockEmptyTSLCertificateSource.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockEmptyTSLCertificateSource.java similarity index 98% rename from dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockEmptyTSLCertificateSource.java rename to dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockEmptyTSLCertificateSource.java index b4aa1471f1..3a6b494fc4 100644 --- a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockEmptyTSLCertificateSource.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockEmptyTSLCertificateSource.java @@ -18,7 +18,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -package eu.europa.esig.dss.test.mock; +package eu.europa.esig.dss.cookbook.mock; import java.util.Calendar; import java.util.Collections; diff --git a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockOCSPSource.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockOCSPSource.java similarity index 98% rename from dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockOCSPSource.java rename to dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockOCSPSource.java index 6ae838ea7c..12a45c83e9 100644 --- a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockOCSPSource.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockOCSPSource.java @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -package eu.europa.esig.dss.test.mock; +package eu.europa.esig.dss.cookbook.mock; import java.io.InputStream; import java.util.ArrayList; diff --git a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockServiceInfo.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockServiceInfo.java similarity index 98% rename from dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockServiceInfo.java rename to dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockServiceInfo.java index 4eda23e893..83eb38438b 100644 --- a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockServiceInfo.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockServiceInfo.java @@ -18,7 +18,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -package eu.europa.esig.dss.test.mock; +package eu.europa.esig.dss.cookbook.mock; import java.util.Calendar; import java.util.Collections; diff --git a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockSignatureTokenConnection.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockSignatureTokenConnection.java similarity index 96% rename from dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockSignatureTokenConnection.java rename to dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockSignatureTokenConnection.java index 063f08d489..c3dac1d945 100644 --- a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockSignatureTokenConnection.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockSignatureTokenConnection.java @@ -18,7 +18,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -package eu.europa.esig.dss.test.mock; +package eu.europa.esig.dss.cookbook.mock; import java.security.Signature; import java.util.List; @@ -29,6 +29,7 @@ import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; +import eu.europa.esig.dss.test.mock.MockPrivateKeyEntry; import eu.europa.esig.dss.token.AbstractSignatureTokenConnection; import eu.europa.esig.dss.token.DSSPrivateKeyEntry; diff --git a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockTSPSource.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockTSPSource.java similarity index 98% rename from dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockTSPSource.java rename to dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockTSPSource.java index 199420a44e..2375ec736f 100644 --- a/dss-test/src/main/java/eu/europa/esig/dss/test/mock/MockTSPSource.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/mock/MockTSPSource.java @@ -18,7 +18,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -package eu.europa.esig.dss.test.mock; +package eu.europa.esig.dss.cookbook.mock; import java.math.BigInteger; import java.security.PrivateKey; @@ -62,6 +62,7 @@ import eu.europa.esig.dss.DSSException; import eu.europa.esig.dss.DSSRevocationUtils; import eu.europa.esig.dss.DigestAlgorithm; +import eu.europa.esig.dss.test.mock.MockPrivateKeyEntry; import eu.europa.esig.dss.x509.CertificateToken; import eu.europa.esig.dss.x509.tsp.TSPSource; diff --git a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/sources/CheckCertificate.java b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/sources/CheckCertificate.java index 2e9a3e3d7b..3eacda7e4d 100644 --- a/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/sources/CheckCertificate.java +++ b/dss-cookbook/src/main/java/eu/europa/esig/dss/cookbook/sources/CheckCertificate.java @@ -26,9 +26,9 @@ import eu.europa.esig.dss.client.crl.OnlineCRLSource; import eu.europa.esig.dss.client.ocsp.OnlineOCSPSource; import eu.europa.esig.dss.cookbook.example.Cookbook; -import eu.europa.esig.dss.test.mock.MockCRLSource; -import eu.europa.esig.dss.test.mock.MockEmptyTSLCertificateSource; -import eu.europa.esig.dss.test.mock.MockOCSPSource; +import eu.europa.esig.dss.cookbook.mock.MockCRLSource; +import eu.europa.esig.dss.cookbook.mock.MockEmptyTSLCertificateSource; +import eu.europa.esig.dss.cookbook.mock.MockOCSPSource; import eu.europa.esig.dss.validation.CertificateVerifier; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignatureValidationContext; diff --git a/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/CookbookTools.java b/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/CookbookTools.java index 8c66fea174..1fd1407db9 100644 --- a/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/CookbookTools.java +++ b/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/CookbookTools.java @@ -10,8 +10,8 @@ import eu.europa.esig.dss.DSSUtils; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.SignatureAlgorithm; +import eu.europa.esig.dss.cookbook.mock.MockTSPSource; import eu.europa.esig.dss.test.gen.CertificateService; -import eu.europa.esig.dss.test.mock.MockTSPSource; import eu.europa.esig.dss.token.AbstractSignatureTokenConnection; import eu.europa.esig.dss.token.DSSPrivateKeyEntry; import eu.europa.esig.dss.token.Pkcs12SignatureToken; diff --git a/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/sign/SignXmlXadesTTest.java b/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/sign/SignXmlXadesTTest.java index 97a9906542..25e255a894 100644 --- a/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/sign/SignXmlXadesTTest.java +++ b/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/sign/SignXmlXadesTTest.java @@ -33,8 +33,8 @@ import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.cookbook.example.CookbookTools; +import eu.europa.esig.dss.cookbook.mock.MockTSPSource; import eu.europa.esig.dss.test.gen.CertificateService; -import eu.europa.esig.dss.test.mock.MockTSPSource; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.xades.XAdESSignatureParameters; import eu.europa.esig.dss.xades.signature.XAdESService; diff --git a/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesBTest.java b/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesBTest.java index 598c112a00..c67df0df4d 100644 --- a/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesBTest.java +++ b/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/validate/ValidateSignedXmlXadesBTest.java @@ -30,9 +30,9 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.cookbook.example.CookbookTools; +import eu.europa.esig.dss.cookbook.mock.MockServiceInfo; import eu.europa.esig.dss.cookbook.mock.MockTSLCertificateSource; import eu.europa.esig.dss.cookbook.sources.AlwaysValidOCSPSource; -import eu.europa.esig.dss.test.mock.MockServiceInfo; import eu.europa.esig.dss.tsl.ServiceInfo; import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; diff --git a/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/validate/ValidateXmlXadesLTWithOnlineSourcesTest.java b/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/validate/ValidateXmlXadesLTWithOnlineSourcesTest.java index 2cc2b66fcc..48a34c4b00 100644 --- a/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/validate/ValidateXmlXadesLTWithOnlineSourcesTest.java +++ b/dss-cookbook/src/test/java/eu/europa/esig/dss/cookbook/example/validate/ValidateXmlXadesLTWithOnlineSourcesTest.java @@ -34,7 +34,7 @@ import eu.europa.esig.dss.client.http.commons.FileCacheDataLoader; import eu.europa.esig.dss.client.ocsp.OnlineOCSPSource; import eu.europa.esig.dss.cookbook.example.CookbookTools; -import eu.europa.esig.dss.test.mock.MockServiceInfo; +import eu.europa.esig.dss.cookbook.mock.MockServiceInfo; import eu.europa.esig.dss.tsl.TrustedListsCertificateSource; import eu.europa.esig.dss.tsl.service.TSLRepository; import eu.europa.esig.dss.tsl.service.TSLValidationJob; diff --git a/dss-document/pom.xml b/dss-document/pom.xml index 2580660118..7cfaa37c1a 100644 --- a/dss-document/pom.xml +++ b/dss-document/pom.xml @@ -11,25 +11,38 @@ dss-document DSS Document - DSS Document contains the code for the creation and validation of XAdES, CAdES, PAdES and ASiC signatures._ + DSS Document contains the code for the creation and validation of XAdES, CAdES, PAdES and ASiC signatures. eu.europa.ec.joinup.sd-dss dss-spi - - eu.europa.ec.joinup.sd-dss - dss-reports - eu.europa.ec.joinup.sd-dss validation-policy - + + + ch.qos.logback + logback-classic + test + + + junit + junit + test + + + + + + + + eu.europa.ec.joinup.sd-dss - dss-test + dss-utils-google-guava test diff --git a/dss-document/src/main/java/eu/europa/esig/dss/validation/SignatureValidationContext.java b/dss-document/src/main/java/eu/europa/esig/dss/validation/SignatureValidationContext.java index b26e9bbeb8..4298f3d50c 100644 --- a/dss-document/src/main/java/eu/europa/esig/dss/validation/SignatureValidationContext.java +++ b/dss-document/src/main/java/eu/europa/esig/dss/validation/SignatureValidationContext.java @@ -413,15 +413,18 @@ private List getRevocationData(final CertificateToken certToken List revocations = new ArrayList(); // ALL Embedded revocation data - OCSPAndCRLCertificateVerifier offlineVerifier = new OCSPAndCRLCertificateVerifier(signatureCRLSource, signatureOCSPSource, validationCertificatePool); - RevocationToken ocspToken = offlineVerifier.checkOCSP(certToken); - if (ocspToken != null) { - revocations.add(ocspToken); - } + if (signatureCRLSource != null || signatureOCSPSource != null) { + OCSPAndCRLCertificateVerifier offlineVerifier = new OCSPAndCRLCertificateVerifier(signatureCRLSource, signatureOCSPSource, + validationCertificatePool); + RevocationToken ocspToken = offlineVerifier.checkOCSP(certToken); + if (ocspToken != null) { + revocations.add(ocspToken); + } - RevocationToken crlToken = offlineVerifier.checkCRL(certToken); - if (crlToken != null) { - revocations.add(crlToken); + RevocationToken crlToken = offlineVerifier.checkCRL(certToken); + if (crlToken != null) { + revocations.add(crlToken); + } } if (revocations.isEmpty()) { diff --git a/dss-document/src/main/resources/custom-content-types.properties b/dss-document/src/main/resources/custom-content-types.properties deleted file mode 100644 index 76c74f5278..0000000000 --- a/dss-document/src/main/resources/custom-content-types.properties +++ /dev/null @@ -1,274 +0,0 @@ -#sun.net.www MIME content-types table; version %I%, %G% -# -# Property fields: -# -# ::= 'description' '=' -# ::= 'file_extensions' '=' -# ::= 'icon' '=' -# ::= 'browser' | 'application' | 'save' | 'unknown' -# ::= 'application' '=' -# - -# -# The "we don't know anything about this data" type(s). -# Used internally to mark unrecognized types. -# -content/unknown: description=Unknown Content -unknown/unknown: description=Unknown Data Type - -# -# The template we should use for temporary files when launching an application -# to view a document of given type. -# -temp.file.template: c:\\temp\\%s - -# -# The "real" types. -# -application/octet-stream: \ - description=Generic Binary Stream;\ - file_extensions=.saveme,.dump,.hqx,.arc,.obj,.lib,.bin,.exe,.zip,.gz - -application/oda: \ - description=ODA Document;\ - file_extensions=.oda - -application/pdf: \ - description=Adobe PDF Format;\ - file_extensions=.pdf - -application/postscript: \ - description=Postscript File;\ - file_extensions=.eps,.ai,.ps;\ - icon=ps - -application/rtf: \ - description=Wordpad Document;\ - file_extensions=.rtf;\ - action=application;\ - application=wordpad.exe %s - -application/x-dvi: \ - description=TeX DVI File;\ - file_extensions=.dvi - -application/x-hdf: \ - description=Hierarchical Data Format;\ - file_extensions=.hdf;\ - action=save - -application/x-latex: \ - description=LaTeX Source;\ - file_extensions=.latex - -application/x-netcdf: \ - description=Unidata netCDF Data Format;\ - file_extensions=.nc,.cdf;\ - action=save - -application/x-tex: \ - description=TeX Source;\ - file_extensions=.tex - -application/x-texinfo: \ - description=Gnu Texinfo;\ - file_extensions=.texinfo,.texi - -application/x-troff: \ - description=Troff Source;\ - file_extensions=.t,.tr,.roff - -application/x-troff-man: \ - description=Troff Manpage Source;\ - file_extensions=.man - -application/x-troff-me: \ - description=Troff ME Macros;\ - file_extensions=.me - -application/x-troff-ms: \ - description=Troff MS Macros;\ - file_extensions=.ms - -application/x-wais-source: \ - description=Wais Source;\ - file_extensions=.src,.wsrc - -application/zip: \ - description=Zip File;\ - file_extensions=.zip;\ - icon=zip;\ - action=save - -application/x-bcpio: \ - description=Old Binary CPIO Archive;\ - file_extensions=.bcpio;\ - action=save - -application/x-cpio: \ - description=Unix CPIO Archive;\ - file_extensions=.cpio;\ - action=save - -application/x-gtar: \ - description=Gnu Tar Archive;\ - file_extensions=.gtar;\ - icon=tar;\ - action=save - -application/x-shar: \ - description=Shell Archive;\ - file_extensions=.sh,.shar;\ - action=save - -application/x-sv4cpio: \ - description=SVR4 CPIO Archive;\ - file_extensions=.sv4cpio;\ - action=save - -application/x-sv4crc: \ - description=SVR4 CPIO with CRC;\ - file_extensions=.sv4crc;\ - action=save - -application/x-tar: \ - description=Tar Archive;\ - file_extensions=.tar;\ - icon=tar;\ - action=save - -application/x-ustar: \ - description=US Tar Archive;\ - file_extensions=.ustar;\ - action=save - -audio/basic: \ - description=Basic Audio;\ - file_extensions=.snd,.au;\ - icon=audio - -audio/x-aiff: \ - description=Audio Interchange Format File;\ - file_extensions=.aifc,.aif,.aiff;\ - icon=aiff - -audio/x-wav: \ - description=Wav Audio;\ - file_extensions=.wav;\ - icon=wav;\ - action=application;\ - application=mplayer.exe %s - -image/gif: \ - description=GIF Image;\ - file_extensions=.gif;\ - icon=gif;\ - action=browser - -image/ief: \ - description=Image Exchange Format;\ - file_extensions=.ief - -image/jpeg: \ - description=JPEG Image;\ - file_extensions=.jfif,.jfif-tbnl,.jpe,.jpg,.jpeg;\ - icon=jpeg;\ - action=browser - -image/tiff: \ - description=TIFF Image;\ - file_extensions=.tif,.tiff;\ - icon=tiff - -image/vnd.fpx: \ - description=FlashPix Image;\ - file_extensions=.fpx,.fpix - -image/x-cmu-rast: \ - description=CMU Raster Image;\ - file_extensions=.ras - -image/x-portable-anymap: \ - description=PBM Anymap Image;\ - file_extensions=.pnm - -image/x-portable-bitmap: \ - description=PBM Bitmap Image;\ - file_extensions=.pbm - -image/x-portable-graymap: \ - description=PBM Graymap Image;\ - file_extensions=.pgm - -image/x-portable-pixmap: \ - description=PBM Pixmap Image;\ - file_extensions=.ppm - -image/x-rgb: \ - description=RGB Image;\ - file_extensions=.rgb - -image/x-xbitmap: \ - description=X Bitmap Image;\ - file_extensions=.xbm,.xpm - -image/x-xwindowdump: \ - description=X Window Dump Image;\ - file_extensions=.xwd - -image/png: \ - description=PNG Image;\ - file_extensions=.png;\ - icon=png;\ - action=browser - -text/html: \ - description=HTML Document;\ - file_extensions=.htm,.html;\ - icon=html - -text/plain: \ - description=Plain Text;\ - file_extensions=.text,.c,.cc,.c++,.h,.pl,.txt,.java,.el;\ - icon=text;\ - action=browser - -text/tab-separated-values: \ - description=Tab Separated Values Text;\ - file_extensions=.tsv - -text/x-setext: \ - description=Structure Enhanced Text;\ - file_extensions=.etx - -video/mpeg: \ - description=MPEG Video Clip;\ - file_extensions=.mpg,.mpe,.mpeg;\ - icon=mpeg - -video/quicktime: \ - description=QuickTime Video Clip;\ - file_extensions=.mov,.qt - -application/x-troff-msvideo: \ - description=AVI Video;\ - file_extensions=.avi;\ - icon=avi;\ - action=application;\ - application=mplayer.exe %s - -video/x-sgi-movie: \ - description=SGI Movie;\ - file_extensions=.movie,.mv - -message/rfc822: \ - description=Internet Email Message;\ - file_extensions=.mime - -application/xml: \ - description=XML document;\ - file_extensions=.xml - -application/vnd.etsi.asic-s+zip: \ - description=ASiC-S container;\ - file_extensions=.asics \ No newline at end of file diff --git a/dss-document/src/test/java/eu/europa/esig/dss/DeterministicIdGenerationTest.java b/dss-document/src/test/java/eu/europa/esig/dss/DeterministicIdGenerationTest.java index a492c5b4a3..c17ef29e99 100644 --- a/dss-document/src/test/java/eu/europa/esig/dss/DeterministicIdGenerationTest.java +++ b/dss-document/src/test/java/eu/europa/esig/dss/DeterministicIdGenerationTest.java @@ -22,24 +22,22 @@ import static org.junit.Assert.assertNotEquals; +import java.io.FileInputStream; import java.util.Arrays; import java.util.List; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import eu.europa.esig.dss.test.gen.CertificateService; -import eu.europa.esig.dss.token.DSSPrivateKeyEntry; +import eu.europa.esig.dss.x509.CertificateToken; @RunWith(Parameterized.class) public class DeterministicIdGenerationTest { - private static SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.RSA_SHA256; - - private static DSSPrivateKeyEntry privateKeyEntry; + private CertificateToken signingCert; @Parameters public static List data() { @@ -49,23 +47,22 @@ public static List data() { public DeterministicIdGenerationTest() { } - @BeforeClass - public static void setUp() throws Exception { - CertificateService certificateService = new CertificateService(); - privateKeyEntry = certificateService.generateCertificateChain(signatureAlgorithm); + @Before + public void setUp() throws Exception { + signingCert = DSSUtils.loadCertificate(new FileInputStream("src/test/resources/ec.europa.eu.crt")); } @Test public void testDifferentDeterministicId() throws InterruptedException { SignatureParameters params = new SignatureParameters(); - params.setSigningCertificate(privateKeyEntry.getCertificate()); + params.setSigningCertificate(signingCert); String deterministicId1 = params.getDeterministicId(); Thread.sleep(1); // 1 millisecond params = new SignatureParameters(); - params.setSigningCertificate(privateKeyEntry.getCertificate()); + params.setSigningCertificate(signingCert); String deterministicId2 = params.getDeterministicId(); assertNotEquals(deterministicId1, deterministicId2); @@ -75,4 +72,5 @@ public void testDifferentDeterministicId() throws InterruptedException { private class SignatureParameters extends AbstractSignatureParameters { } + } diff --git a/dss-document/src/test/java/eu/europa/esig/dss/validation/MockDocumentValidator.java b/dss-document/src/test/java/eu/europa/esig/dss/validation/MockDocumentValidator.java deleted file mode 100644 index e27f79aed9..0000000000 --- a/dss-document/src/test/java/eu/europa/esig/dss/validation/MockDocumentValidator.java +++ /dev/null @@ -1,34 +0,0 @@ -package eu.europa.esig.dss.validation; - -import java.util.Collections; -import java.util.List; - -import eu.europa.esig.dss.DSSDocument; -import eu.europa.esig.dss.DSSException; - -public class MockDocumentValidator extends SignedDocumentValidator { - - public MockDocumentValidator() { - super(null); - } - - protected MockDocumentValidator(SignatureScopeFinder signatureScopeFinder) { - super(signatureScopeFinder); - } - - @Override - public List getSignatures() { - return Collections.emptyList(); - } - - @Override - public List getOriginalDocuments(String signatureId) throws DSSException { - return Collections.emptyList(); - } - - @Override - public boolean isSupported(DSSDocument dssDocument) { - return true; - } - -} diff --git a/dss-pades/pom.xml b/dss-pades/pom.xml index 6b429e9aa6..20c0f0d860 100644 --- a/dss-pades/pom.xml +++ b/dss-pades/pom.xml @@ -14,18 +14,10 @@ DSS PAdES contains the code for the creation and validation of PAdES signatures. - - eu.europa.ec.joinup.sd-dss - dss-document - eu.europa.ec.joinup.sd-dss dss-cades - - eu.europa.ec.joinup.sd-dss - dss-spi - org.apache.pdfbox @@ -44,12 +36,6 @@ dss-test test - - eu.europa.ec.joinup.sd-dss - dss-document - test-jar - test - \ No newline at end of file diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/DigestStabilityTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/DigestStabilityTest.java index 9b704ecac8..2839bb3fa7 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/DigestStabilityTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/DigestStabilityTest.java @@ -27,35 +27,38 @@ import java.security.MessageDigest; import java.util.Date; +import org.junit.Before; import org.junit.Test; import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.DigestAlgorithm; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.pades.signature.PAdESService; import eu.europa.esig.dss.signature.DocumentSignatureService; -import eu.europa.esig.dss.test.gen.CertificateService; +import eu.europa.esig.dss.signature.PKIFactoryAccess; import eu.europa.esig.dss.token.DSSPrivateKeyEntry; import eu.europa.esig.dss.utils.Utils; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; /** * This class checks if the getDataToSign result is equals when passing the same * parameters * */ -public class DigestStabilityTest { +public class DigestStabilityTest extends PKIFactoryAccess { + + private DSSPrivateKeyEntry privateKeyEntry; + + @Before + public void init() { + privateKeyEntry = getPrivateKeyEntry(); + } @Test public void testTwiceGetDataToSignReturnsSameDigest() throws Exception { DSSDocument toBeSigned = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - DSSPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - Date signingDate = new Date(); ToBeSigned dataToSign1 = getDataToSign(toBeSigned, privateKeyEntry, signingDate); @@ -73,9 +76,6 @@ public void differentDocumentGetDifferentDigest() throws Exception { DSSDocument toBeSigned1 = new FileDocument(new File("src/test/resources/sample.pdf")); DSSDocument toBeSigned2 = new FileDocument(new File("src/test/resources/validation/pades-5-signatures-and-1-document-timestamp.pdf")); - CertificateService certificateService = new CertificateService(); - DSSPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - Date signingDate = new Date(); ToBeSigned dataToSign1 = getDataToSign(toBeSigned1, privateKeyEntry, signingDate); @@ -92,9 +92,6 @@ public void differentDocumentGetDifferentDigest() throws Exception { public void differentSigningDateGetDifferentDigest() throws Exception { DSSDocument toBeSigned = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - DSSPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - Date signingDate = new Date(); ToBeSigned dataToSign1 = getDataToSign(toBeSigned, privateKeyEntry, signingDate); @@ -110,7 +107,7 @@ public void differentSigningDateGetDifferentDigest() throws Exception { private ToBeSigned getDataToSign(DSSDocument toBeSigned, DSSPrivateKeyEntry privateKeyEntry, Date signingDate) { - DocumentSignatureService service = new PAdESService(new CommonCertificateVerifier()); + DocumentSignatureService service = new PAdESService(getCompleteCertificateVerifier()); PAdESSignatureParameters signatureParameters = new PAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(signingDate); @@ -121,4 +118,9 @@ private ToBeSigned getDataToSign(DSSDocument toBeSigned, DSSPrivateKeyEntry priv return service.getDataToSign(toBeSigned, signatureParameters); } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/GetOriginalDocumentTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/GetOriginalDocumentTest.java index fe55165f16..f532041094 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/GetOriginalDocumentTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/GetOriginalDocumentTest.java @@ -14,53 +14,43 @@ import eu.europa.esig.dss.DSSUtils; import eu.europa.esig.dss.DigestAlgorithm; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; import eu.europa.esig.dss.pades.signature.PAdESService; -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.signature.PKIFactoryAccess; import eu.europa.esig.dss.utils.Utils; -import eu.europa.esig.dss.validation.CertificateVerifier; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; -public class GetOriginalDocumentTest { +public class GetOriginalDocumentTest extends PKIFactoryAccess { private static final Logger LOG = LoggerFactory.getLogger(GetOriginalDocumentTest.class); - //TODO. (Re-enable when fixed: https://esig-dss.atlassian.net/browse/DSS-969) + // TODO. (Re-enable when fixed: https://esig-dss.atlassian.net/browse/DSS-969) @Ignore @Test public final void getOriginalDocumentFromEnvelopedSignature() throws Exception { DSSDocument document = new FileDocument("src/test/resources/sample.pdf"); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - PAdESSignatureParameters signatureParameters = new PAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); - signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPED); - signatureParameters.setDigestAlgorithm(DigestAlgorithm.SHA256); + signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPED); + signatureParameters.setDigestAlgorithm(DigestAlgorithm.SHA256); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - PAdESService service = new PAdESService(certificateVerifier); + PAdESService service = new PAdESService(getCompleteCertificateVerifier()); ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); - List results = validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId()); @@ -72,4 +62,9 @@ public final void getOriginalDocumentFromEnvelopedSignature() throws Exception { assertEquals(document.getDigest(DigestAlgorithm.SHA256), results.get(0).getDigest(DigestAlgorithm.SHA256)); } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESBExtendToLTACheckTimeStampIDTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESBExtendToLTACheckTimeStampIDTest.java index 6cbcc1d1e3..0f34dbd03f 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESBExtendToLTACheckTimeStampIDTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESBExtendToLTACheckTimeStampIDTest.java @@ -8,43 +8,33 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -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.pades.signature.PAdESService; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; import eu.europa.esig.dss.validation.reports.wrapper.TimestampWrapper; -public class PAdESBExtendToLTACheckTimeStampIDTest { +public class PAdESBExtendToLTACheckTimeStampIDTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - PAdESSignatureParameters signatureParameters = new PAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - PAdESService service = new PAdESService(certificateVerifier); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + PAdESService service = new PAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); + SignatureValue signatureValue = getToken().sign(toBeSigned, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_LTA); @@ -52,7 +42,7 @@ public void test() throws Exception { signedDocument = service.extendDocument(signedDocument, signatureParameters); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); @@ -62,4 +52,9 @@ public void test() throws Exception { Assert.assertEquals(signatureId, wrapper.getSignedObjects().getSignedSignature().get(0).getId()); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESDoubleSignatureTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESDoubleSignatureTest.java index c229e9f0f0..70bdcb335d 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESDoubleSignatureTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESDoubleSignatureTest.java @@ -27,7 +27,6 @@ import java.util.Arrays; import java.util.List; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -35,28 +34,17 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -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.pades.signature.PAdESService; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; @RunWith(Parameterized.class) -public class PAdESDoubleSignatureTest { - - private static SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.RSA_SHA256; - - private static DSSDocument toBeSigned; - - private static MockPrivateKeyEntry privateKeyEntry; +public class PAdESDoubleSignatureTest extends PKIFactoryAccess { @Parameters public static List data() { @@ -66,40 +54,33 @@ public static List data() { public PAdESDoubleSignatureTest() { } - @BeforeClass - public static void setUp() throws Exception { - toBeSigned = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - privateKeyEntry = certificateService.generateCertificateChain(signatureAlgorithm); - } - @Test public void testDoubleSignature() throws Exception { - CommonCertificateVerifier verifier = new CommonCertificateVerifier(); - PAdESService service = new PAdESService(verifier); - CertificateService certificateService = new CertificateService(); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + DSSDocument toBeSigned = new FileDocument(new File("src/test/resources/sample.pdf")); + + PAdESService service = new PAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); PAdESSignatureParameters params = new PAdESSignatureParameters(); params.setSignatureLevel(SignatureLevel.PAdES_BASELINE_LTA); - params.setSigningCertificate(privateKeyEntry.getCertificate()); + params.setSigningCertificate(getSigningCert()); ToBeSigned dataToSign = service.getDataToSign(toBeSigned, params); - SignatureValue signatureValue = TestUtils.sign(signatureAlgorithm, privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, params.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(toBeSigned, params, signatureValue); params = new PAdESSignatureParameters(); params.setSignatureLevel(SignatureLevel.PAdES_BASELINE_LTA); - params.setSigningCertificate(privateKeyEntry.getCertificate()); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + params.setSigningCertificate(getSigningCert()); + service.setTspSource(getAlternateGoodTsa()); dataToSign = service.getDataToSign(signedDocument, params); - signatureValue = TestUtils.sign(signatureAlgorithm, privateKeyEntry, dataToSign); + signatureValue = getToken().sign(dataToSign, params.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument doubleSignedDocument = service.signDocument(signedDocument, params, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(doubleSignedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); @@ -115,4 +96,9 @@ public void testDoubleSignature() throws Exception { } } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLTACheckTimeStampIDTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLTACheckTimeStampIDTest.java index 2d8b2b8db8..cbb88667eb 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLTACheckTimeStampIDTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLTACheckTimeStampIDTest.java @@ -8,47 +8,37 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -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.pades.signature.PAdESService; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; import eu.europa.esig.dss.validation.reports.wrapper.TimestampWrapper; -public class PAdESLTACheckTimeStampIDTest { +public class PAdESLTACheckTimeStampIDTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - PAdESSignatureParameters signatureParameters = new PAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_LTA); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - PAdESService service = new PAdESService(certificateVerifier); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + PAdESService service = new PAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); + SignatureValue signatureValue = getToken().sign(toBeSigned, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); @@ -58,4 +48,9 @@ public void test() throws Exception { Assert.assertEquals(signatureId, wrapper.getSignedObjects().getSignedSignature().get(0).getId()); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLTACheckTimeStampedTimestampIDTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLTACheckTimeStampedTimestampIDTest.java index 296c21fd6a..dc41c262ae 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLTACheckTimeStampedTimestampIDTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLTACheckTimeStampedTimestampIDTest.java @@ -8,48 +8,38 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -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.pades.signature.PAdESService; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; import eu.europa.esig.dss.validation.reports.wrapper.TimestampWrapper; import eu.europa.esig.dss.x509.TimestampType; -public class PAdESLTACheckTimeStampedTimestampIDTest { +public class PAdESLTACheckTimeStampedTimestampIDTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - PAdESSignatureParameters signatureParameters = new PAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_LTA); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - PAdESService service = new PAdESService(certificateVerifier); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + PAdESService service = new PAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); + SignatureValue signatureValue = getToken().sign(toBeSigned, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); @@ -61,4 +51,10 @@ public void test() throws Exception { } } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLevelBNotEnoughSpaceForSignatureTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLevelBNotEnoughSpaceForSignatureTest.java index df07c1dfd9..6080fd3d40 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLevelBNotEnoughSpaceForSignatureTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/PAdESLevelBNotEnoughSpaceForSignatureTest.java @@ -3,47 +3,36 @@ import static org.junit.Assert.fail; import java.io.File; -import java.util.Date; import org.junit.Test; import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.DSSException; import eu.europa.esig.dss.FileDocument; -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.pades.signature.PAdESService; import eu.europa.esig.dss.signature.DocumentSignatureService; -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.CommonCertificateVerifier; +import eu.europa.esig.dss.signature.PKIFactoryAccess; -public class PAdESLevelBNotEnoughSpaceForSignatureTest { +public class PAdESLevelBNotEnoughSpaceForSignatureTest extends PKIFactoryAccess { @Test public void testException() throws Exception { DSSDocument toBeSigned = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - - Date signingDate = new Date(); - PAdESSignatureParameters signatureParameters = new PAdESSignatureParameters(); - signatureParameters.bLevel().setSigningDate(signingDate); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); signatureParameters.setSignatureSize(2); // 2 bytes - DocumentSignatureService service = new PAdESService(new CommonCertificateVerifier()); + DocumentSignatureService service = new PAdESService(getCompleteCertificateVerifier()); try { ToBeSigned dataToSign = service.getDataToSign(toBeSigned, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); service.signDocument(toBeSigned, signatureParameters, signatureValue); fail("Not enough space"); } catch (DSSException e) { @@ -51,4 +40,9 @@ public void testException() throws Exception { } } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } \ No newline at end of file diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/TwoPAdESSigniatureMustHaveDifferentIdTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/TwoPAdESSigniatureMustHaveDifferentIdTest.java index ce91ee5ed9..e54d04d6a5 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/TwoPAdESSigniatureMustHaveDifferentIdTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/TwoPAdESSigniatureMustHaveDifferentIdTest.java @@ -10,56 +10,47 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -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.pades.signature.PAdESService; import eu.europa.esig.dss.signature.DocumentSignatureService; -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.reports.Reports; -public class TwoPAdESSigniatureMustHaveDifferentIdTest { +public class TwoPAdESSigniatureMustHaveDifferentIdTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - PAdESSignatureParameters signatureParameters = new PAdESSignatureParameters(); - signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); signatureParameters.setLocation("Luxembourg"); signatureParameters.setReason("DSS testing"); signatureParameters.setContactInfo("Jira"); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - DocumentSignatureService service = new PAdESService(certificateVerifier); + DocumentSignatureService service = new PAdESService(getCompleteCertificateVerifier()); ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument firstSignedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(firstSignedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); signatureParameters.bLevel().setSigningDate(new Date()); + dataToSign = service.getDataToSign(firstSignedDocument, signatureParameters); - signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument secondSignedDocument = service.signDocument(firstSignedDocument, signatureParameters, signatureValue); validator = SignedDocumentValidator.fromDocument(secondSignedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); reports = validator.validateDocument(); List signatureIdList = reports.getSimpleReport().getSignatureIdList(); @@ -68,4 +59,9 @@ public void test() throws Exception { Assert.assertNotEquals(signatureIdList.get(0), signatureIdList.get(1)); } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/AbstractPAdESTestSignature.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/AbstractPAdESTestSignature.java index 1b5eff12ee..edd61c3ba5 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/AbstractPAdESTestSignature.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/AbstractPAdESTestSignature.java @@ -21,7 +21,6 @@ import eu.europa.esig.dss.signature.AbstractPkiFactoryTestDocumentSignatureService; import eu.europa.esig.dss.utils.Utils; import eu.europa.esig.dss.validation.AdvancedSignature; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; public abstract class AbstractPAdESTestSignature extends AbstractPkiFactoryTestDocumentSignatureService { @@ -34,7 +33,7 @@ protected void onDocumentSigned(byte[] byteArray) { protected void checkSignedAttributesOrder(byte[] encoded) { SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(new InMemoryDocument(encoded)); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); List signatures = validator.getSignatures(); assertEquals(1, signatures.size()); diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESSignatureFieldTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESSignatureFieldTest.java index 5e40008a8e..6f909eed82 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESSignatureFieldTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESSignatureFieldTest.java @@ -34,7 +34,6 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.DSSException; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; @@ -42,31 +41,23 @@ import eu.europa.esig.dss.pades.SignatureFieldParameters; import eu.europa.esig.dss.pades.SignatureImageParameters; import eu.europa.esig.dss.pades.SignatureImageTextParameters; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; -public class PAdESSignatureFieldTest { +public class PAdESSignatureFieldTest extends PKIFactoryAccess { private PAdESService service; private PAdESSignatureParameters signatureParameters; - private MockPrivateKeyEntry privateKeyEntry; @Before public void init() throws Exception { - CertificateService certificateService = new CertificateService(); - privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - signatureParameters = new PAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); SignatureImageParameters imageParameters = new SignatureImageParameters(); @@ -76,8 +67,7 @@ public void init() throws Exception { imageParameters.setTextParameters(textParameters); signatureParameters.setSignatureImageParameters(imageParameters); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - service = new PAdESService(certificateVerifier); + service = new PAdESService(getCompleteCertificateVerifier()); } @Test @@ -140,13 +130,13 @@ public void testFieldNotFound() throws IOException { private DSSDocument signAndValidate(DSSDocument documentToSign) throws IOException { 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); // signedDocument.save("target/test.pdf"); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); DiagnosticData diagnosticData = reports.getDiagnosticData(); @@ -155,4 +145,9 @@ private DSSDocument signAndValidate(DSSDocument documentToSign) throws IOExcepti return signedDocument; } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESVisibleSignaturePositionTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESVisibleSignaturePositionTest.java index fe074aa7f8..3913b3cca5 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESVisibleSignaturePositionTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESVisibleSignaturePositionTest.java @@ -20,21 +20,17 @@ */ package eu.europa.esig.dss.pades.signature; -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.pades.PAdESSignatureParameters; -import eu.europa.esig.dss.pades.SignatureImageParameters; -import eu.europa.esig.dss.pades.SignatureImageTextParameters; -import eu.europa.esig.dss.signature.DocumentSignatureService; -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 java.awt.Color; +import java.awt.Font; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPageTree; @@ -46,18 +42,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.awt.Color; -import java.awt.Font; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import eu.europa.esig.dss.DSSDocument; +import eu.europa.esig.dss.InMemoryDocument; +import eu.europa.esig.dss.SignatureLevel; +import eu.europa.esig.dss.SignatureValue; +import eu.europa.esig.dss.ToBeSigned; +import eu.europa.esig.dss.pades.PAdESSignatureParameters; +import eu.europa.esig.dss.pades.SignatureImageParameters; +import eu.europa.esig.dss.pades.SignatureImageTextParameters; +import eu.europa.esig.dss.signature.DocumentSignatureService; +import eu.europa.esig.dss.signature.PKIFactoryAccess; -public class PAdESVisibleSignaturePositionTest { +public class PAdESVisibleSignaturePositionTest extends PKIFactoryAccess { private static final Color TRANSPARENT = new Color(0, 0, 0, 0.25f); private static final int DPI = 144; @@ -71,253 +67,254 @@ public class PAdESVisibleSignaturePositionTest { */ private static final int CHECK_RESOLUTION = 1; - private DocumentSignatureService service; - private PAdESSignatureParameters signatureParameters; - private MockPrivateKeyEntry privateKeyEntry; - private DSSDocument signitureImage; - /** - * PDF-s rotated by pdftk on Ubuntu (pdftk Ubuntu packages)
- * Tool site: pdftk - */ - private Map signablePdfs = new HashMap<>(); - - @Before - public void init() throws Exception { - CertificateService certificateService = new CertificateService(); - privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - - certificateService = new CertificateService(); - privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - - signatureParameters = new PAdESSignatureParameters(); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); - signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); - - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - service = new PAdESService(certificateVerifier); - - signitureImage = new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/signature.png")); - - signablePdfs.put("normal", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test.pdf"))); - signablePdfs.put("90", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_90.pdf"))); - signablePdfs.put("180", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_180.pdf"))); - signablePdfs.put("270", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_270.pdf"))); - signablePdfs.put("-90", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_-90.pdf"))); - signablePdfs.put("-180", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_-180.pdf"))); - signablePdfs.put("-270", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_-270.pdf"))); - signablePdfs.put("minoltaScan", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/sun.pdf"))); //scanner type from pdf - signablePdfs.put("minoltaScan90", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/sun_90.pdf"))); //scanner type from pdf - } - - @Test - public void pdfRotateDegreeTest() throws IOException { - checkRotation(signablePdfs.get("normal").openStream(), 0); - checkRotation(signablePdfs.get("90").openStream(), 90); - checkRotation(signablePdfs.get("180").openStream(), 180); - checkRotation(signablePdfs.get("270").openStream(), 270); - checkRotation(signablePdfs.get("-90").openStream(), 270); - checkRotation(signablePdfs.get("-180").openStream(), 180); - checkRotation(signablePdfs.get("-270").openStream(), 90); - } - - @Test - public void doTest() throws Exception { - SignatureImageParameters signatureImageParameters = createSignatureImageParameters(); - - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE); //default - checkImageSimilarityPdf("normal", "check_custom_10_20.pdf"); - checkImageSimilarityPdf("90", "check_custom_rotate_none_90_10_20.pdf"); - checkImageSimilarityPdf("180", "check_custom_rotate_none_180_10_20.pdf"); - checkImageSimilarityPdf("270", "check_custom_rotate_none_270_10_20.pdf"); - checkImageSimilarityPdf("-270", "check_custom_rotate_none_90_10_20.pdf"); - checkImageSimilarityPdf("-180", "check_custom_rotate_none_180_10_20.pdf"); - checkImageSimilarityPdf("-90", "check_custom_rotate_none_270_10_20.pdf"); - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); - checkImageSimilarityPdf("normal", "check_custom_10_20.pdf"); - checkImageSimilarityPdf("90", "check_custom_rotate_automatic_90_10_20.pdf"); - checkImageSimilarityPdf("180", "check_custom_rotate_automatic_180_10_20.pdf"); - checkImageSimilarityPdf("270", "check_custom_rotate_automatic_270_10_20.pdf"); - checkImageSimilarityPdf("-270", "check_custom_rotate_automatic_90_10_20.pdf"); - checkImageSimilarityPdf("-180", "check_custom_rotate_automatic_180_10_20.pdf"); - checkImageSimilarityPdf("-90", "check_custom_rotate_automatic_270_10_20.pdf"); - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.ROTATE_270); - checkImageSimilarityPdf("normal", "check_custom_rotate270_10_20.pdf"); - checkImageSimilarityPdf("90", "check_custom_rotate270_90_10_20.pdf"); - checkImageSimilarityPdf("180", "check_custom_rotate270_180_10_20.pdf"); - checkImageSimilarityPdf("270", "check_custom_rotate270_270_10_20.pdf"); - checkImageSimilarityPdf("-270", "check_custom_rotate270_90_10_20.pdf"); - checkImageSimilarityPdf("-180", "check_custom_rotate270_180_10_20.pdf"); - checkImageSimilarityPdf("-90", "check_custom_rotate270_270_10_20.pdf"); - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.ROTATE_180); - checkImageSimilarityPdf("normal", "check_custom_rotate180_10_20.pdf"); - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.ROTATE_90); - checkImageSimilarityPdf("normal", "check_custom_rotate90_10_20.pdf"); - - //check minolta scanner - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); - checkImageSimilarityPdf("minoltaScan", "check_sun.pdf"); - /** - * sun.pdf and sun90.pdf not equal, when convert it to image (two scanning and the scanner can not scan equal twice). - * So we need the similarity of the sun.pdf and sun90.pdf. - * After the signing the visual signature does not have to change the similarity. - */ - float sunSimilarity = checkImageSimilarity(pdfToBufferedImage( - signablePdfs.get("minoltaScan").openStream()), - pdfToBufferedImage(signablePdfs.get("minoltaScan90").openStream()), - CHECK_RESOLUTION); - checkImageSimilarityPdf("minoltaScan90", "check_sun.pdf", sunSimilarity); - } - - @Test - @Ignore("for generation and manual testing") - public void rotateTest() throws Exception { - SignatureImageParameters signatureImageParameters = createSignatureImageParameters(); - - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); - DSSDocument document = sign(signablePdfs.get("minoltaScan90")); - File checkPdfFile = new File("target/pdf/check.pdf"); - checkPdfFile.getParentFile().mkdirs(); - IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); - } - - @Test - @Ignore("for generation and manual testing") - public void bigGeneratorTest() throws Exception { - SignatureImageParameters signatureImageParameters = createSignatureImageParameters(); - - for(SignatureImageParameters.VisualSignatureRotation rotation : SignatureImageParameters.VisualSignatureRotation.values()) { - for (SignatureImageParameters.VisualSignatureAlignmentHorizontal horizontal : SignatureImageParameters.VisualSignatureAlignmentHorizontal.values()) { - for (SignatureImageParameters.VisualSignatureAlignmentVertical vertical : SignatureImageParameters.VisualSignatureAlignmentVertical.values()) { - signatureImageParameters.setRotation(rotation); - signatureImageParameters.setAlignmentHorizontal(horizontal); - signatureImageParameters.setAlignmentVertical(vertical); - String[] pdfs = new String[]{"normal", "90", "180", "270"}; - for (String pdf : pdfs) { - DSSDocument document = sign(signablePdfs.get(pdf)); - File checkPdfFile = new File("target/pdf/check_" + rotation.name() + "_" + pdf + "_" + horizontal.name() + "_" + vertical.name() + ".pdf"); - checkPdfFile.getParentFile().mkdirs(); - IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); - } - } - } - } - } - - @Test - @Ignore("for pull request #71") - public void rotatePullRequest71Test() throws Exception { - Logger logger = LoggerFactory.getLogger(getClass()); - /** - * minolta scanner normal(not rotated) pdf and rotation none. - * - * You can check the pdf rotation by this code: - * PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf")); - * System.out.println("rotation: " + inputPDF.getPage(0).getRotation()); - * - * result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes line - * - * comment: this is the original working - */ - PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf")); - logger.info("rotation sun.pdf: " + inputPDF.getPage(0).getRotation()); - - SignatureImageParameters signatureImageParameters = createSignatureImageParameters(); - - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE); - DSSDocument document = sign(signablePdfs.get("minoltaScan")); - File checkPdfFile = new File("target/pdf/check_normal_none.pdf"); - checkPdfFile.getParentFile().mkdirs(); - IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); - - /** - * minolta scanner rotated pdf and rotation none (in pdf view the rotated and normal pdf seem equal) - * you can check the pdf rotation by this code: - * PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf")); - * System.out.println("rotation: " + inputPDF.getPage(0).getRotation()); - * - * result in pdf viewer: signature is top right corner and the sign image line is perpendicular with the sun eyes line - * - * comment: this is the original working - */ - inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf")); - logger.info("rotation sun_90.pdf: " + inputPDF.getPage(0).getRotation()); - - signatureImageParameters = createSignatureImageParameters(); - - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE); - document = sign(signablePdfs.get("minoltaScan90")); - checkPdfFile = new File("target/pdf/check_90_none.pdf"); - checkPdfFile.getParentFile().mkdirs(); - IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); - - /** - * minolta scanner rotated pdf and rotation automatic (in pdf view the rotated and normal pdf seem equal) - * - * result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes line, - * it will be same as with sun.pdf (not rotated) and rotation none - */ - signatureImageParameters = createSignatureImageParameters(); - - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); - document = sign(signablePdfs.get("minoltaScan90")); - checkPdfFile = new File("target/pdf/check_90_automatic.pdf"); - checkPdfFile.getParentFile().mkdirs(); - IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); - - /** - * minolta scanner normal(not rotated) pdf and rotation none. - * - * result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes line, - * it will be same as with sun.pdf (not rotated) and rotation none - */ - signatureImageParameters = createSignatureImageParameters(); - - signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); - document = sign(signablePdfs.get("minoltaScan")); - checkPdfFile = new File("target/pdf/check_normal_automatic.pdf"); - checkPdfFile.getParentFile().mkdirs(); - IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); - } - - private DSSDocument sign(DSSDocument document) { - ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(SignatureAlgorithm.RSA_SHA256, privateKeyEntry, dataToSign); - return service.signDocument(document, signatureParameters, signatureValue); - } - - private void checkRotation(InputStream inputStream, int rotate) throws IOException { - PDDocument document = PDDocument.load(inputStream); - - Assert.assertEquals(rotate, document.getPages().get(0).getRotation()); - } - - private void checkImageSimilarityPdf(String samplePdf, String checkPdf, float similarity) throws IOException { - DSSDocument document = sign(signablePdfs.get(samplePdf)); - PDDocument sampleDocument = PDDocument.load(document.openStream()); - PDDocument checkDocument = PDDocument.load(getClass().getResourceAsStream("/visualSignature/check/" + checkPdf)); - - PDPageTree samplePageTree = sampleDocument.getPages(); - PDPageTree checkPageTree = checkDocument.getPages(); - - Assert.assertEquals(checkPageTree.getCount(), samplePageTree.getCount()); - - PDFRenderer sampleRenderer = new PDFRenderer(sampleDocument); - PDFRenderer checkRenderer = new PDFRenderer(checkDocument); - - for(int pageNumber = 0; pageNumber < checkPageTree.getCount(); pageNumber++) { - BufferedImage sampleImage = sampleRenderer.renderImageWithDPI(pageNumber, DPI); - BufferedImage checkImage = checkRenderer.renderImageWithDPI(pageNumber, DPI); - - float checkSimilarity = checkImageSimilarity(sampleImage, checkImage, CHECK_RESOLUTION); - float calculatedSimilarity = (float)((int)( similarity *100f))/100f; //calulate rotated position has about 1 pixel position difference - Assert.assertTrue(checkSimilarity >= calculatedSimilarity); - } - } - - private void checkImageSimilarityPdf(String samplePdf, String checkPdf) throws IOException { - checkImageSimilarityPdf(samplePdf, checkPdf, SIMILARITY_LIMIT); - } + private DocumentSignatureService service; + private PAdESSignatureParameters signatureParameters; + private DSSDocument signitureImage; + /** + * PDF-s rotated by pdftk on Ubuntu (pdftk Ubuntu + * packages)
+ * Tool site: pdftk + */ + private Map signablePdfs = new HashMap<>(); + + @Before + public void init() throws Exception { + + signatureParameters = new PAdESSignatureParameters(); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); + signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); + + service = new PAdESService(getCompleteCertificateVerifier()); + + signitureImage = new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/signature.png")); + + signablePdfs.put("normal", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test.pdf"))); + signablePdfs.put("90", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_90.pdf"))); + signablePdfs.put("180", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_180.pdf"))); + signablePdfs.put("270", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_270.pdf"))); + signablePdfs.put("-90", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_-90.pdf"))); + signablePdfs.put("-180", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_-180.pdf"))); + signablePdfs.put("-270", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/test_-270.pdf"))); + signablePdfs.put("minoltaScan", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/sun.pdf"))); // scanner + // type + signablePdfs.put("minoltaScan90", new InMemoryDocument(getClass().getResourceAsStream("/visualSignature/sun_90.pdf"))); // scanner + // type + } + + @Test + public void pdfRotateDegreeTest() throws IOException { + checkRotation(signablePdfs.get("normal").openStream(), 0); + checkRotation(signablePdfs.get("90").openStream(), 90); + checkRotation(signablePdfs.get("180").openStream(), 180); + checkRotation(signablePdfs.get("270").openStream(), 270); + checkRotation(signablePdfs.get("-90").openStream(), 270); + checkRotation(signablePdfs.get("-180").openStream(), 180); + checkRotation(signablePdfs.get("-270").openStream(), 90); + } + + @Test + public void doTest() throws Exception { + SignatureImageParameters signatureImageParameters = createSignatureImageParameters(); + + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE); // default + checkImageSimilarityPdf("normal", "check_custom_10_20.pdf"); + checkImageSimilarityPdf("90", "check_custom_rotate_none_90_10_20.pdf"); + checkImageSimilarityPdf("180", "check_custom_rotate_none_180_10_20.pdf"); + checkImageSimilarityPdf("270", "check_custom_rotate_none_270_10_20.pdf"); + checkImageSimilarityPdf("-270", "check_custom_rotate_none_90_10_20.pdf"); + checkImageSimilarityPdf("-180", "check_custom_rotate_none_180_10_20.pdf"); + checkImageSimilarityPdf("-90", "check_custom_rotate_none_270_10_20.pdf"); + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); + checkImageSimilarityPdf("normal", "check_custom_10_20.pdf"); + checkImageSimilarityPdf("90", "check_custom_rotate_automatic_90_10_20.pdf"); + checkImageSimilarityPdf("180", "check_custom_rotate_automatic_180_10_20.pdf"); + checkImageSimilarityPdf("270", "check_custom_rotate_automatic_270_10_20.pdf"); + checkImageSimilarityPdf("-270", "check_custom_rotate_automatic_90_10_20.pdf"); + checkImageSimilarityPdf("-180", "check_custom_rotate_automatic_180_10_20.pdf"); + checkImageSimilarityPdf("-90", "check_custom_rotate_automatic_270_10_20.pdf"); + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.ROTATE_270); + checkImageSimilarityPdf("normal", "check_custom_rotate270_10_20.pdf"); + checkImageSimilarityPdf("90", "check_custom_rotate270_90_10_20.pdf"); + checkImageSimilarityPdf("180", "check_custom_rotate270_180_10_20.pdf"); + checkImageSimilarityPdf("270", "check_custom_rotate270_270_10_20.pdf"); + checkImageSimilarityPdf("-270", "check_custom_rotate270_90_10_20.pdf"); + checkImageSimilarityPdf("-180", "check_custom_rotate270_180_10_20.pdf"); + checkImageSimilarityPdf("-90", "check_custom_rotate270_270_10_20.pdf"); + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.ROTATE_180); + checkImageSimilarityPdf("normal", "check_custom_rotate180_10_20.pdf"); + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.ROTATE_90); + checkImageSimilarityPdf("normal", "check_custom_rotate90_10_20.pdf"); + + // check minolta scanner + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); + checkImageSimilarityPdf("minoltaScan", "check_sun.pdf"); + /** + * sun.pdf and sun90.pdf not equal, when convert it to image (two scanning and the scanner can not scan equal + * twice). + * So we need the similarity of the sun.pdf and sun90.pdf. + * After the signing the visual signature does not have to change the similarity. + */ + float sunSimilarity = checkImageSimilarity(pdfToBufferedImage(signablePdfs.get("minoltaScan").openStream()), + pdfToBufferedImage(signablePdfs.get("minoltaScan90").openStream()), CHECK_RESOLUTION); + checkImageSimilarityPdf("minoltaScan90", "check_sun.pdf", sunSimilarity); + } + + @Test + @Ignore("for generation and manual testing") + public void rotateTest() throws Exception { + SignatureImageParameters signatureImageParameters = createSignatureImageParameters(); + + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); + DSSDocument document = sign(signablePdfs.get("minoltaScan90")); + File checkPdfFile = new File("target/pdf/check.pdf"); + checkPdfFile.getParentFile().mkdirs(); + IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); + } + + @Test + @Ignore("for generation and manual testing") + public void bigGeneratorTest() throws Exception { + SignatureImageParameters signatureImageParameters = createSignatureImageParameters(); + + for (SignatureImageParameters.VisualSignatureRotation rotation : SignatureImageParameters.VisualSignatureRotation.values()) { + for (SignatureImageParameters.VisualSignatureAlignmentHorizontal horizontal : SignatureImageParameters.VisualSignatureAlignmentHorizontal + .values()) { + for (SignatureImageParameters.VisualSignatureAlignmentVertical vertical : SignatureImageParameters.VisualSignatureAlignmentVertical.values()) { + signatureImageParameters.setRotation(rotation); + signatureImageParameters.setAlignmentHorizontal(horizontal); + signatureImageParameters.setAlignmentVertical(vertical); + String[] pdfs = new String[] { "normal", "90", "180", "270" }; + for (String pdf : pdfs) { + DSSDocument document = sign(signablePdfs.get(pdf)); + File checkPdfFile = new File( + "target/pdf/check_" + rotation.name() + "_" + pdf + "_" + horizontal.name() + "_" + vertical.name() + ".pdf"); + checkPdfFile.getParentFile().mkdirs(); + IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); + } + } + } + } + } + + @Test + @Ignore("for pull request #71") + public void rotatePullRequest71Test() throws Exception { + Logger logger = LoggerFactory.getLogger(getClass()); + /** + * minolta scanner normal(not rotated) pdf and rotation none. + * + * You can check the pdf rotation by this code: + * PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf")); + * System.out.println("rotation: " + inputPDF.getPage(0).getRotation()); + * + * result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes line + * + * comment: this is the original working + */ + PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf")); + logger.info("rotation sun.pdf: " + inputPDF.getPage(0).getRotation()); + + SignatureImageParameters signatureImageParameters = createSignatureImageParameters(); + + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE); + DSSDocument document = sign(signablePdfs.get("minoltaScan")); + File checkPdfFile = new File("target/pdf/check_normal_none.pdf"); + checkPdfFile.getParentFile().mkdirs(); + IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); + + /** + * minolta scanner rotated pdf and rotation none (in pdf view the rotated and normal pdf seem equal) + * you can check the pdf rotation by this code: + * PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf")); + * System.out.println("rotation: " + inputPDF.getPage(0).getRotation()); + * + * result in pdf viewer: signature is top right corner and the sign image line is perpendicular with the sun + * eyes line + * + * comment: this is the original working + */ + inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf")); + logger.info("rotation sun_90.pdf: " + inputPDF.getPage(0).getRotation()); + + signatureImageParameters = createSignatureImageParameters(); + + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE); + document = sign(signablePdfs.get("minoltaScan90")); + checkPdfFile = new File("target/pdf/check_90_none.pdf"); + checkPdfFile.getParentFile().mkdirs(); + IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); + + /** + * minolta scanner rotated pdf and rotation automatic (in pdf view the rotated and normal pdf seem equal) + * + * result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes + * line, + * it will be same as with sun.pdf (not rotated) and rotation none + */ + signatureImageParameters = createSignatureImageParameters(); + + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); + document = sign(signablePdfs.get("minoltaScan90")); + checkPdfFile = new File("target/pdf/check_90_automatic.pdf"); + checkPdfFile.getParentFile().mkdirs(); + IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); + + /** + * minolta scanner normal(not rotated) pdf and rotation none. + * + * result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes + * line, + * it will be same as with sun.pdf (not rotated) and rotation none + */ + signatureImageParameters = createSignatureImageParameters(); + + signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC); + document = sign(signablePdfs.get("minoltaScan")); + checkPdfFile = new File("target/pdf/check_normal_automatic.pdf"); + checkPdfFile.getParentFile().mkdirs(); + IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile)); + } + + private DSSDocument sign(DSSDocument document) { + ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); + return service.signDocument(document, signatureParameters, signatureValue); + } + + private void checkRotation(InputStream inputStream, int rotate) throws IOException { + PDDocument document = PDDocument.load(inputStream); + + Assert.assertEquals(rotate, document.getPages().get(0).getRotation()); + } + + private void checkImageSimilarityPdf(String samplePdf, String checkPdf, float similarity) throws IOException { + DSSDocument document = sign(signablePdfs.get(samplePdf)); + PDDocument sampleDocument = PDDocument.load(document.openStream()); + PDDocument checkDocument = PDDocument.load(getClass().getResourceAsStream("/visualSignature/check/" + checkPdf)); + + PDPageTree samplePageTree = sampleDocument.getPages(); + PDPageTree checkPageTree = checkDocument.getPages(); + + Assert.assertEquals(checkPageTree.getCount(), samplePageTree.getCount()); + + PDFRenderer sampleRenderer = new PDFRenderer(sampleDocument); + PDFRenderer checkRenderer = new PDFRenderer(checkDocument); + + for (int pageNumber = 0; pageNumber < checkPageTree.getCount(); pageNumber++) { + BufferedImage sampleImage = sampleRenderer.renderImageWithDPI(pageNumber, DPI); + BufferedImage checkImage = checkRenderer.renderImageWithDPI(pageNumber, DPI); + + float checkSimilarity = checkImageSimilarity(sampleImage, checkImage, CHECK_RESOLUTION); + float calculatedSimilarity = ((int) (similarity * 100f)) / 100f; // calulate rotated position has about 1 + // pixel position difference + Assert.assertTrue(checkSimilarity >= calculatedSimilarity); + } + } + + private void checkImageSimilarityPdf(String samplePdf, String checkPdf) throws IOException { + checkImageSimilarityPdf(samplePdf, checkPdf, SIMILARITY_LIMIT); + } private float checkImageSimilarity(BufferedImage sampleImage, BufferedImage checkImage, int resolution) { try { @@ -326,10 +323,10 @@ private float checkImageSimilarity(BufferedImage sampleImage, BufferedImage chec int checkWidth = checkImage.getWidth(); int checkHeight = checkImage.getHeight(); if (width == 0 || height == 0 || checkWidth == 0 || checkHeight == 0) { - Assert.fail(String.format("invalid image size: sample(%dx%d) vs check(%dx%d)", width, height, checkWidth, checkHeight)); + Assert.fail(String.format("invalid image size: sample(%dx%d) vs check(%dx%d)", width, height, checkWidth, checkHeight)); } if (width != checkWidth || height != checkHeight) { - Assert.fail(String.format("images size not equal: sample(%dx%d) vs check(%dx%d)", width, height, checkWidth, checkHeight)); + Assert.fail(String.format("images size not equal: sample(%dx%d) vs check(%dx%d)", width, height, checkWidth, checkHeight)); } int matchingPixels = 0; @@ -342,8 +339,8 @@ private float checkImageSimilarity(BufferedImage sampleImage, BufferedImage chec if (sampleRGB == checkRGB) { matchingPixels++; } else { - checkImage.setRGB(x, y, Color.RED.getRGB()); - } + checkImage.setRGB(x, y, Color.RED.getRGB()); + } checkedPixels++; } @@ -355,31 +352,36 @@ private float checkImageSimilarity(BufferedImage sampleImage, BufferedImage chec } } - private SignatureImageParameters createSignatureImageParameters() throws Exception { - SignatureImageParameters imageParameters = new SignatureImageParameters(); - imageParameters.setImage(signitureImage); - SignatureImageTextParameters textParameters = new SignatureImageTextParameters(); - textParameters.setText("My signature\nsecond line\nlong line is very long line with long text example this"); - textParameters.setSignerNamePosition(SignatureImageTextParameters.SignerPosition.LEFT); - textParameters.setBackgroundColor(TRANSPARENT); - textParameters.setTextColor(Color.MAGENTA); - textParameters.setFont(new Font("Arial", Font.BOLD, 8)); - imageParameters.setTextParameters(textParameters); - - imageParameters.setBackgroundColor(TRANSPARENT); - imageParameters.setxAxis(10); - imageParameters.setyAxis(20); - - signatureParameters.bLevel().setSigningDate(new Date()); - - signatureParameters.setSignatureImageParameters(imageParameters); - - return imageParameters; - } - - private BufferedImage pdfToBufferedImage(InputStream inputStream) throws IOException { - PDDocument document = PDDocument.load(inputStream); - PDFRenderer renderer = new PDFRenderer(document); - return renderer.renderImageWithDPI(0, DPI); - } + private SignatureImageParameters createSignatureImageParameters() throws Exception { + SignatureImageParameters imageParameters = new SignatureImageParameters(); + imageParameters.setImage(signitureImage); + SignatureImageTextParameters textParameters = new SignatureImageTextParameters(); + textParameters.setText("My signature\nsecond line\nlong line is very long line with long text example this"); + textParameters.setSignerNamePosition(SignatureImageTextParameters.SignerPosition.LEFT); + textParameters.setBackgroundColor(TRANSPARENT); + textParameters.setTextColor(Color.MAGENTA); + textParameters.setFont(new Font("Arial", Font.BOLD, 8)); + imageParameters.setTextParameters(textParameters); + + imageParameters.setBackgroundColor(TRANSPARENT); + imageParameters.setxAxis(10); + imageParameters.setyAxis(20); + + signatureParameters.bLevel().setSigningDate(new Date()); + + signatureParameters.setSignatureImageParameters(imageParameters); + + return imageParameters; + } + + private BufferedImage pdfToBufferedImage(InputStream inputStream) throws IOException { + PDDocument document = PDDocument.load(inputStream); + PDFRenderer renderer = new PDFRenderer(document); + return renderer.renderImageWithDPI(0, DPI); + } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESVisibleSignatureTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESVisibleSignatureTest.java index 3b825921a5..0e6fc85e9b 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESVisibleSignatureTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PAdESVisibleSignatureTest.java @@ -35,7 +35,6 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; 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; @@ -44,37 +43,28 @@ import eu.europa.esig.dss.pades.SignatureImageTextParameters; import eu.europa.esig.dss.pades.SignatureImageTextParameters.SignerPosition; import eu.europa.esig.dss.signature.DocumentSignatureService; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; -public class PAdESVisibleSignatureTest { +public class PAdESVisibleSignatureTest extends PKIFactoryAccess { private DocumentSignatureService service; private PAdESSignatureParameters signatureParameters; private DSSDocument documentToSign; - private MockPrivateKeyEntry privateKeyEntry; @Before public void init() throws Exception { documentToSign = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - signatureParameters = new PAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - service = new PAdESService(certificateVerifier); + service = new PAdESService(getCompleteCertificateVerifier()); } @Test @@ -255,17 +245,22 @@ private SignatureImageParameters createSignatureImageParameters() { private void signAndValidate() throws IOException { 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); // signedDocument.save("target/test.pdf"); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); DiagnosticData diagnosticData = reports.getDiagnosticData(); assertTrue(diagnosticData.isBLevelTechnicallyValid(diagnosticData.getFirstSignatureId())); } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PDFAVisibleSignatureTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PDFAVisibleSignatureTest.java index daa7a00cf4..561b85eea6 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PDFAVisibleSignatureTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PDFAVisibleSignatureTest.java @@ -33,7 +33,6 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; @@ -42,37 +41,28 @@ import eu.europa.esig.dss.pades.SignatureImageParameters; import eu.europa.esig.dss.pades.SignatureImageTextParameters; import eu.europa.esig.dss.signature.DocumentSignatureService; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; -public class PDFAVisibleSignatureTest { +public class PDFAVisibleSignatureTest extends PKIFactoryAccess { private DocumentSignatureService service; private PAdESSignatureParameters signatureParameters; private DSSDocument documentToSign; - private MockPrivateKeyEntry privateKeyEntry; @Before public void init() throws Exception { documentToSign = new FileDocument(new File("src/test/resources/not_signed_pdfa.pdf")); - CertificateService certificateService = new CertificateService(); - privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - signatureParameters = new PAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - service = new PAdESService(certificateVerifier); + service = new PAdESService(getCompleteCertificateVerifier()); } @Test @@ -124,7 +114,7 @@ public void testGeneratedImageOnlyPNG() throws IOException { private void signAndValidate(boolean expectedValidPDFA) throws IOException { 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); // signedDocument.save("target/test.pdf"); @@ -132,11 +122,16 @@ private void signAndValidate(boolean expectedValidPDFA) throws IOException { assertEquals(expectedValidPDFA, PDFAUtils.validatePDFAStructure(signedDocument)); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); DiagnosticData diagnosticData = reports.getDiagnosticData(); assertTrue(diagnosticData.isBLevelTechnicallyValid(diagnosticData.getFirstSignatureId())); } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PDFOverrideFiltersTest.java b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PDFOverrideFiltersTest.java index e2a6640e35..4960909393 100644 --- a/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PDFOverrideFiltersTest.java +++ b/dss-pades/src/test/java/eu/europa/esig/dss/pades/signature/PDFOverrideFiltersTest.java @@ -30,39 +30,30 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -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.pades.PAdESSignatureParameters; import eu.europa.esig.dss.signature.DocumentSignatureService; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; -public class PDFOverrideFiltersTest { +public class PDFOverrideFiltersTest extends PKIFactoryAccess { private DocumentSignatureService service; private PAdESSignatureParameters signatureParameters; private DSSDocument documentToSign; - private MockPrivateKeyEntry privateKeyEntry; @Test public void test() throws Exception { documentToSign = new FileDocument(new File("src/test/resources/sample.pdf")); - CertificateService certificateService = new CertificateService(); - privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - signatureParameters = new PAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B); signatureParameters.setSignatureFilter("SigFilter"); @@ -70,15 +61,14 @@ public void test() throws Exception { signatureParameters.setTimestampFilter("tspFilter"); signatureParameters.setTimestampSubFilter("tspSubFilter"); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - service = new PAdESService(certificateVerifier); + service = new PAdESService(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); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); DiagnosticData diagnosticData = reports.getDiagnosticData(); @@ -86,4 +76,9 @@ public void test() throws Exception { assertEquals(SignatureLevel.PDF_NOT_ETSI.toString(), diagnosticData.getSignatureFormat(diagnosticData.getFirstSignatureId())); } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-service/pom.xml b/dss-service/pom.xml index 9d7bb8e09a..046e908652 100644 --- a/dss-service/pom.xml +++ b/dss-service/pom.xml @@ -34,6 +34,11 @@ jcl-over-slf4j + + ch.qos.logback + logback-classic + test + junit junit diff --git a/dss-service/src/test/resources/logback.xml b/dss-service/src/test/resources/logback.xml new file mode 100644 index 0000000000..a5b9874809 --- /dev/null +++ b/dss-service/src/test/resources/logback.xml @@ -0,0 +1,16 @@ + + + + + %d %5p | %t | %-55logger{55} | %m %n + + + + + + + + + + + \ No newline at end of file diff --git a/dss-test/pom.xml b/dss-test/pom.xml index 29189c40e8..2986daaebf 100644 --- a/dss-test/pom.xml +++ b/dss-test/pom.xml @@ -16,7 +16,7 @@ eu.europa.ec.joinup.sd-dss - dss-spi + dss-document eu.europa.ec.joinup.sd-dss diff --git a/dss-document/src/test/java/eu/europa/esig/dss/extension/AbstractTestExtension.java b/dss-test/src/main/java/eu/europa/esig/dss/extension/AbstractTestExtension.java similarity index 100% rename from dss-document/src/test/java/eu/europa/esig/dss/extension/AbstractTestExtension.java rename to dss-test/src/main/java/eu/europa/esig/dss/extension/AbstractTestExtension.java diff --git a/dss-document/src/test/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestDocumentSignatureService.java b/dss-test/src/main/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestDocumentSignatureService.java similarity index 100% rename from dss-document/src/test/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestDocumentSignatureService.java rename to dss-test/src/main/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestDocumentSignatureService.java diff --git a/dss-document/src/test/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestMultipleDocumentsSignatureService.java b/dss-test/src/main/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestMultipleDocumentsSignatureService.java similarity index 100% rename from dss-document/src/test/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestMultipleDocumentsSignatureService.java rename to dss-test/src/main/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestMultipleDocumentsSignatureService.java diff --git a/dss-document/src/test/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestSignature.java b/dss-test/src/main/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestSignature.java similarity index 100% rename from dss-document/src/test/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestSignature.java rename to dss-test/src/main/java/eu/europa/esig/dss/signature/AbstractPkiFactoryTestSignature.java diff --git a/dss-document/src/test/java/eu/europa/esig/dss/signature/PKIFactoryAccess.java b/dss-test/src/main/java/eu/europa/esig/dss/signature/PKIFactoryAccess.java similarity index 96% rename from dss-document/src/test/java/eu/europa/esig/dss/signature/PKIFactoryAccess.java rename to dss-test/src/main/java/eu/europa/esig/dss/signature/PKIFactoryAccess.java index ca4d001dec..d29ee63ae1 100644 --- a/dss-document/src/test/java/eu/europa/esig/dss/signature/PKIFactoryAccess.java +++ b/dss-test/src/main/java/eu/europa/esig/dss/signature/PKIFactoryAccess.java @@ -36,7 +36,7 @@ public abstract class PKIFactoryAccess { PKI_FACTORY_HOST = props.getProperty("pki.factory.host"); PKI_FACTORY_KEYSTORE_PASSWORD = props.getProperty("pki.factory.keystore.password"); } catch (Exception e) { - throw new RuntimeException("Unable to initialize", e); + throw new RuntimeException("Unable to initialize from pki-factory.properties", e); } } @@ -48,6 +48,7 @@ public abstract class PKIFactoryAccess { private static final String GOOD_TSA_CROSS_CERTIF = "cc-good-tsa-crossed"; private static final String KEYSTORE_TYPE = "PKCS12"; + // JDK-7 + PKCS12 is not allowed for trust-store private static final String TRUSTSTORE_TYPE = "JKS"; protected static final String GOOD_USER = "good-user"; @@ -146,7 +147,7 @@ protected OnlineTSPSource getAlternateGoodTsa() { } protected OnlineTSPSource getGoodTsaCrossCertification() { - OnlineTSPSource tspSource = new OnlineTSPSource(getTsaUrl(EE_GOOD_TSA)); + OnlineTSPSource tspSource = new OnlineTSPSource(getTsaUrl(GOOD_TSA_CROSS_CERTIF)); TimestampDataLoader dataLoader = new TimestampDataLoader(); dataLoader.setProxyConfig(getProxyConfig()); tspSource.setDataLoader(dataLoader); diff --git a/dss-test/src/main/java/eu/europa/esig/dss/test/gen/CRLGenerator.java b/dss-test/src/main/java/eu/europa/esig/dss/test/gen/CRLGenerator.java deleted file mode 100644 index 995f163879..0000000000 --- a/dss-test/src/main/java/eu/europa/esig/dss/test/gen/CRLGenerator.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * DSS - Digital Signature Services - * Copyright (C) 2015 European Commission, provided under the CEF programme - * - * This file is part of the "DSS - Digital Signature Services" project. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -package eu.europa.esig.dss.test.gen; - -import java.security.Security; -import java.security.cert.X509CRL; -import java.security.cert.X509Certificate; -import java.util.Date; - -import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x509.Extension; -import org.bouncycastle.cert.X509CRLHolder; -import org.bouncycastle.cert.X509v2CRLBuilder; -import org.bouncycastle.cert.jcajce.JcaX509CRLConverter; -import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder; -import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; - -import eu.europa.esig.dss.test.mock.MockPrivateKeyEntry; - -public class CRLGenerator { - - private static final BouncyCastleProvider SECURITY_PROVIDER = new BouncyCastleProvider(); - - static { - Security.addProvider(SECURITY_PROVIDER); - } - - public X509CRL generateCRL(X509Certificate certToRevoke, MockPrivateKeyEntry issuerEntry, Date dateOfRevoke, int reason) throws Exception { - - Date now = new Date(); - X500Name x500nameIssuer = new JcaX509CertificateHolder(issuerEntry.getCertificate().getCertificate()).getSubject(); - X509v2CRLBuilder crlGen = new X509v2CRLBuilder(x500nameIssuer, now); - - crlGen.setNextUpdate(new Date(now.getTime() + (60 * 60 * 1000))); - - crlGen.addCRLEntry(certToRevoke.getSerialNumber(), dateOfRevoke, reason); - - JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils(); - - crlGen.addExtension(Extension.authorityKeyIdentifier, false, - extUtils.createAuthorityKeyIdentifier(issuerEntry.getCertificate().getPublicKey())); - - X509CRLHolder crlHolder = crlGen.build(new JcaContentSignerBuilder(issuerEntry.getCertificate().getCertificate().getSigAlgName()).setProvider( - BouncyCastleProvider.PROVIDER_NAME).build(issuerEntry.getPrivateKey())); - - JcaX509CRLConverter converter = new JcaX509CRLConverter(); - return converter.getCRL(crlHolder); - } - -} diff --git a/dss-test/src/main/java/eu/europa/esig/dss/test/gen/CertificateService.java b/dss-test/src/main/java/eu/europa/esig/dss/test/gen/CertificateService.java index d33730b0af..f681e1511c 100644 --- a/dss-test/src/main/java/eu/europa/esig/dss/test/gen/CertificateService.java +++ b/dss-test/src/main/java/eu/europa/esig/dss/test/gen/CertificateService.java @@ -71,7 +71,7 @@ public class CertificateService { Security.addProvider(SECURITY_PROVIDER); } - public KeyPair generateKeyPair(final EncryptionAlgorithm algorithm) throws GeneralSecurityException { + private KeyPair generateKeyPair(final EncryptionAlgorithm algorithm) throws GeneralSecurityException { if (algorithm == EncryptionAlgorithm.ECDSA) { return generateECDSAKeyPair(); } else if (algorithm == EncryptionAlgorithm.RSA) { @@ -93,7 +93,7 @@ private KeyPair generateECDSAKeyPair() throws GeneralSecurityException { return generator.generateKeyPair(); } - public MockPrivateKeyEntry generateCertificateChain(final SignatureAlgorithm algorithm, final MockPrivateKeyEntry rootEntry, Date notBefore, Date notAfter) + private MockPrivateKeyEntry generateCertificateChain(final SignatureAlgorithm algorithm, final MockPrivateKeyEntry rootEntry, Date notBefore, Date notAfter) throws Exception { X500Name rootName = new JcaX509CertificateHolder(rootEntry.getCertificate().getCertificate()).getSubject(); KeyPair childKeyPair = generateKeyPair(algorithm.getEncryptionAlgorithm()); @@ -106,7 +106,7 @@ public MockPrivateKeyEntry generateCertificateChain(final SignatureAlgorithm alg return new MockPrivateKeyEntry(algorithm.getEncryptionAlgorithm(), child, chain, childKeyPair.getPrivate()); } - public MockPrivateKeyEntry generateCertificateChain(final SignatureAlgorithm algorithm, boolean rootCrl) throws Exception { + private MockPrivateKeyEntry generateCertificateChain(final SignatureAlgorithm algorithm, boolean rootCrl) throws Exception { MockPrivateKeyEntry rootEntry = generateSelfSignedCertificate(algorithm, rootCrl); Date notBefore = new Date(System.currentTimeMillis() - (24 * 60 * 60 * 1000)); // yesterday @@ -119,23 +119,7 @@ public MockPrivateKeyEntry generateCertificateChain(final SignatureAlgorithm alg return generateCertificateChain(algorithm, true); } - public MockPrivateKeyEntry generateCertificateChain(final SignatureAlgorithm algorithm, MockPrivateKeyEntry rootEntry) throws Exception { - Date notBefore = new Date(System.currentTimeMillis() - (24 * 60 * 60 * 1000)); // yesterday - Date notAfter = new Date(System.currentTimeMillis() + MAX); // 1000d - - return generateCertificateChain(algorithm, rootEntry, notBefore, notAfter); - } - - public MockPrivateKeyEntry generateExpiredCertificateChain(final SignatureAlgorithm algorithm, boolean rootCrl) throws Exception { - MockPrivateKeyEntry rootEntry = generateSelfSignedCertificate(algorithm, rootCrl); - - Date notBefore = new Date(System.currentTimeMillis() - (10 * 24 * 60 * 60 * 1000)); // -10d - Date notAfter = new Date(System.currentTimeMillis() - (24 * 60 * 60 * 1000)); // yesterday - - return generateCertificateChain(algorithm, rootEntry, notBefore, notAfter); - } - - public MockPrivateKeyEntry generateSelfSignedCertificate(final SignatureAlgorithm algorithm, boolean rootCrl) throws Exception { + private MockPrivateKeyEntry generateSelfSignedCertificate(final SignatureAlgorithm algorithm, boolean rootCrl) throws Exception { KeyPair keyPair = generateKeyPair(algorithm.getEncryptionAlgorithm()); X500Name issuer = new X500Name("CN=RootSelfSignedFake,O=DSS-test"); @@ -179,8 +163,8 @@ public MockPrivateKeyEntry generateTspCertificate(final SignatureAlgorithm algor * @throws CertificateException * @throws IOException */ - public CertificateToken generateTspCertificate(final SignatureAlgorithm algorithm, KeyPair keyPair, X500Name issuer, X500Name subject, final Date notBefore, - final Date notAfter) throws OperatorCreationException, CertificateException, IOException { + private CertificateToken generateTspCertificate(final SignatureAlgorithm algorithm, KeyPair keyPair, X500Name issuer, X500Name subject, + final Date notBefore, final Date notAfter) throws OperatorCreationException, CertificateException, IOException { final SubjectPublicKeyInfo keyInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded()); final X509v3CertificateBuilder certBuilder = new X509v3CertificateBuilder(issuer, @@ -198,7 +182,7 @@ public CertificateToken generateTspCertificate(final SignatureAlgorithm algorith return new CertificateToken(cert); } - public CertificateToken generateRootCertificateWithCrl(SignatureAlgorithm algorithm, X500Name subject, X500Name issuer, PrivateKey issuerPrivateKey, + private CertificateToken generateRootCertificateWithCrl(SignatureAlgorithm algorithm, X500Name subject, X500Name issuer, PrivateKey issuerPrivateKey, PublicKey publicKey, Date notBefore, Date notAfter) throws Exception { // generate certificate @@ -219,7 +203,7 @@ public CertificateToken generateRootCertificateWithCrl(SignatureAlgorithm algori return new CertificateToken(cert); } - public CertificateToken generateRootCertificateWithoutCrl(SignatureAlgorithm algorithm, X500Name subject, X500Name issuer, PrivateKey issuerPrivateKey, + private CertificateToken generateRootCertificateWithoutCrl(SignatureAlgorithm algorithm, X500Name subject, X500Name issuer, PrivateKey issuerPrivateKey, PublicKey publicKey, Date notBefore, Date notAfter) throws Exception { // generate certificate diff --git a/dss-document/src/test/resources/pki-factory.properties b/dss-test/src/main/resources/pki-factory.properties similarity index 100% rename from dss-document/src/test/resources/pki-factory.properties rename to dss-test/src/main/resources/pki-factory.properties diff --git a/dss-test/src/test/java/eu/europa/esig/dss/test/gen/CRLGeneratorTest.java b/dss-test/src/test/java/eu/europa/esig/dss/test/gen/CRLGeneratorTest.java deleted file mode 100644 index 5433275333..0000000000 --- a/dss-test/src/test/java/eu/europa/esig/dss/test/gen/CRLGeneratorTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * DSS - Digital Signature Services - * Copyright (C) 2015 European Commission, provided under the CEF programme - * - * This file is part of the "DSS - Digital Signature Services" project. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -package eu.europa.esig.dss.test.gen; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.security.cert.X509CRL; -import java.security.cert.X509CRLEntry; -import java.util.Date; - -import org.bouncycastle.asn1.x509.CRLReason; -import org.junit.Test; - -import eu.europa.esig.dss.SignatureAlgorithm; -import eu.europa.esig.dss.test.mock.MockPrivateKeyEntry; - -public class CRLGeneratorTest { - - private CertificateService certificateService = new CertificateService(); - private CRLGenerator crlGenerator = new CRLGenerator(); - - @Test - public void test() throws Exception { - MockPrivateKeyEntry issuerKeyEntry = certificateService.generateSelfSignedCertificate(SignatureAlgorithm.RSA_SHA256, true); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256, issuerKeyEntry); - X509CRL generatedCRL = crlGenerator.generateCRL(privateKeyEntry.getCertificate().getCertificate(), issuerKeyEntry, new Date(), CRLReason.privilegeWithdrawn); - assertNotNull(generatedCRL); - - assertEquals(issuerKeyEntry.getCertificate().getSubjectX500Principal(), generatedCRL.getIssuerX500Principal()); - - X509CRLEntry revokedCertificate = generatedCRL.getRevokedCertificate(privateKeyEntry.getCertificate().getSerialNumber()); - assertNotNull(revokedCertificate); - } - -} diff --git a/dss-test/src/test/java/eu/europa/esig/dss/test/gen/CertificateServiceTest.java b/dss-test/src/test/java/eu/europa/esig/dss/test/gen/CertificateServiceTest.java index d60fb0ec52..83e27e464f 100644 --- a/dss-test/src/test/java/eu/europa/esig/dss/test/gen/CertificateServiceTest.java +++ b/dss-test/src/test/java/eu/europa/esig/dss/test/gen/CertificateServiceTest.java @@ -37,14 +37,6 @@ public class CertificateServiceTest { private CertificateService service = new CertificateService(); - @Test - public void isSelfSigned() throws Exception { - DSSPrivateKeyEntry entry = service.generateSelfSignedCertificate(SignatureAlgorithm.RSA_SHA256, true); - - CertificateToken certificate = entry.getCertificate(); - certificate.isSignedBy(certificate); - } - @Test(expected = SignatureException.class) public void isChildCertificateNotSelfSigned() throws Exception { DSSPrivateKeyEntry entryChain = service.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); diff --git a/dss-utils-apache-commons/pom.xml b/dss-utils-apache-commons/pom.xml index bbfcd298fd..24472e86e5 100644 --- a/dss-utils-apache-commons/pom.xml +++ b/dss-utils-apache-commons/pom.xml @@ -18,7 +18,7 @@ org.apache.commons commons-lang3 - 3.4 + 3.6 org.apache.commons diff --git a/dss-xades/pom.xml b/dss-xades/pom.xml index 35fef8ff12..fa18c1d820 100644 --- a/dss-xades/pom.xml +++ b/dss-xades/pom.xml @@ -33,12 +33,6 @@ dss-test test - - eu.europa.ec.joinup.sd-dss - dss-document - test-jar - test - \ No newline at end of file diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/requirements/XAdESBaselineBTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/requirements/XAdESBaselineBTest.java index 6b5e168b20..cf3126c938 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/requirements/XAdESBaselineBTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/requirements/XAdESBaselineBTest.java @@ -6,15 +6,10 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; -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.xades.XAdESSignatureParameters; import eu.europa.esig.dss.xades.signature.XAdESService; @@ -24,17 +19,13 @@ public class XAdESBaselineBTest extends AbstractRequirementChecks { protected DSSDocument getSignedDocument() throws Exception { DSSDocument documentToSign = new FileDocument(new File("src/test/resources/sample.xml")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters); SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/DSS798Test.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/DSS798Test.java index d8951be1bc..1b99a7f569 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/DSS798Test.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/DSS798Test.java @@ -12,51 +12,40 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.DSSException; import eu.europa.esig.dss.InMemoryDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.SimpleReport; import eu.europa.esig.dss.xades.XAdESSignatureParameters; -public class DSS798Test { +public class DSS798Test extends PKIFactoryAccess { @Test(expected = DSSException.class) public void testExtendDetachedWithoutFile() throws Exception { DSSDocument documentToSign = new InMemoryDocument("Hello".getBytes(Charsets.UTF_8), "bin.bin"); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); // Level B ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); // Level T without detached document - CertificateVerifier certificateVerifierExtend = new CommonCertificateVerifier(); - XAdESService serviceExtend = new XAdESService(certificateVerifierExtend); - serviceExtend.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA256))); + XAdESService serviceExtend = new XAdESService(getCompleteCertificateVerifier()); + serviceExtend.setTspSource(getGoodTsa()); XAdESSignatureParameters parametersExtend = new XAdESSignatureParameters(); parametersExtend.setSignatureLevel(SignatureLevel.XAdES_BASELINE_T); @@ -68,28 +57,23 @@ public void testExtendDetachedWithFile() throws Exception { DSSDocument documentToSign = new InMemoryDocument("Hello".getBytes(Charsets.UTF_8), "bin.bin"); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); // Level B ToBeSigned dataToSign = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); // Level T with detached document - CertificateVerifier certificateVerifierExtend = new CommonCertificateVerifier(); - XAdESService serviceExtend = new XAdESService(certificateVerifierExtend); - serviceExtend.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA256))); + XAdESService serviceExtend = new XAdESService(getCompleteCertificateVerifier()); + serviceExtend.setTspSource(getGoodTsa()); XAdESSignatureParameters parametersExtend = new XAdESSignatureParameters(); parametersExtend.setSignatureLevel(SignatureLevel.XAdES_BASELINE_T); @@ -97,7 +81,7 @@ public void testExtendDetachedWithFile() throws Exception { DSSDocument extendedDocument = serviceExtend.extendDocument(signedDocument, parametersExtend); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(extendedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); validator.setDetachedContents(Arrays.asList(documentToSign)); Reports reports = validator.validateDocument(); reports.print(); @@ -106,4 +90,9 @@ public void testExtendDetachedWithFile() throws Exception { assertEquals(SignatureLevel.XAdES_BASELINE_T.toString(), simpleReport.getSignatureFormat(simpleReport.getFirstSignatureId())); } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESDoubleSignatureTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESDoubleSignatureTest.java index 4c04fddcbb..9b92365809 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESDoubleSignatureTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESDoubleSignatureTest.java @@ -27,7 +27,6 @@ import java.util.Arrays; import java.util.List; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -35,28 +34,18 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; -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.CommonCertificateVerifier; +import eu.europa.esig.dss.signature.PKIFactoryAccess; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; import eu.europa.esig.dss.xades.XAdESSignatureParameters; @RunWith(Parameterized.class) -public class XAdESDoubleSignatureTest { - - private static SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.RSA_SHA256; - - private static DSSDocument toBeSigned; - - private static MockPrivateKeyEntry privateKeyEntry; +public class XAdESDoubleSignatureTest extends PKIFactoryAccess { // Run 10 times this test @Parameters @@ -67,39 +56,33 @@ public static List data() { public XAdESDoubleSignatureTest() { } - @BeforeClass - public static void setUp() throws Exception { - toBeSigned = new FileDocument(new File("src/test/resources/sample.xml")); - CertificateService certificateService = new CertificateService(); - privateKeyEntry = certificateService.generateCertificateChain(signatureAlgorithm); - } - @Test public void testDoubleSignature() { - CommonCertificateVerifier verifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(verifier); + DSSDocument toBeSigned = new FileDocument(new File("src/test/resources/sample.xml")); + + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); XAdESSignatureParameters params = new XAdESSignatureParameters(); params.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); params.setSignaturePackaging(SignaturePackaging.ENVELOPED); - params.setSigningCertificate(privateKeyEntry.getCertificate()); + params.setSigningCertificate(getSigningCert()); ToBeSigned dataToSign = service.getDataToSign(toBeSigned, params); - SignatureValue signatureValue = TestUtils.sign(signatureAlgorithm, privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, params.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(toBeSigned, params, signatureValue); params = new XAdESSignatureParameters(); params.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); params.setSignaturePackaging(SignaturePackaging.ENVELOPED); - params.setSigningCertificate(privateKeyEntry.getCertificate()); + params.setSigningCertificate(getSigningCert()); dataToSign = service.getDataToSign(signedDocument, params); - signatureValue = TestUtils.sign(signatureAlgorithm, privateKeyEntry, dataToSign); + signatureValue = getToken().sign(dataToSign, params.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument doubleSignedDocument = service.signDocument(signedDocument, params, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(doubleSignedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); DiagnosticData diagnosticData = reports.getDiagnosticData(); @@ -111,4 +94,9 @@ public void testDoubleSignature() { } } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBEnvelopingWithReferencesWithoutTransformationsTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBEnvelopingWithReferencesWithoutTransformationsTest.java index 83a054d9c2..9957bf3d2b 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBEnvelopingWithReferencesWithoutTransformationsTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBEnvelopingWithReferencesWithoutTransformationsTest.java @@ -39,7 +39,6 @@ import eu.europa.esig.dss.signature.AbstractPkiFactoryTestDocumentSignatureService; import eu.europa.esig.dss.signature.DocumentSignatureService; import eu.europa.esig.dss.utils.Utils; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; import eu.europa.esig.dss.xades.DSSReference; @@ -96,7 +95,7 @@ private DSSReference createReference(DSSDocument fileDocument) { @Override protected Reports getValidationReport(DSSDocument signedDocument) { SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); List detachedContents = new ArrayList(); detachedContents.add(attachment1); diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBIndividualDataObjectTimeStampTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBIndividualDataObjectTimeStampTest.java index a031e6b3af..de561645a2 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBIndividualDataObjectTimeStampTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBIndividualDataObjectTimeStampTest.java @@ -15,16 +15,11 @@ import eu.europa.esig.dss.DigestAlgorithm; import eu.europa.esig.dss.FileDocument; import eu.europa.esig.dss.MimeType; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.TimestampParameters; import eu.europa.esig.dss.signature.AbstractPkiFactoryTestDocumentSignatureService; import eu.europa.esig.dss.signature.DocumentSignatureService; -import eu.europa.esig.dss.test.gen.CertificateService; -import eu.europa.esig.dss.test.mock.MockTSPSource; -import eu.europa.esig.dss.validation.CertificateVerifier; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.TimestampToken; import eu.europa.esig.dss.validation.reports.Reports; @@ -75,9 +70,7 @@ public void init() throws Exception { signatureParameters.setContentTimestampParameters(contentTimestampParameters); try { - CertificateService certificateService = new CertificateService(); - MockTSPSource mockTsp = new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA256)); - TimestampService timestampService = new TimestampService(mockTsp, new CertificatePool()); + TimestampService timestampService = new TimestampService(getGoodTsa(), new CertificatePool()); TimestampToken timestampToken = timestampService.generateXAdESContentTimestampAsTimestampToken(documentToSign, signatureParameters, TimestampType.INDIVIDUAL_DATA_OBJECTS_TIMESTAMP); List contentTimestamps = new ArrayList(); @@ -87,14 +80,13 @@ public void init() throws Exception { throw new DSSException("Error during MockTspSource", e); } - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - service = new XAdESService(certificateVerifier); + service = new XAdESService(getCompleteCertificateVerifier()); } @Override protected Reports getValidationReport(final DSSDocument signedDocument) { SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); List detachedContents = new ArrayList(); detachedContents.add(documentToSign); validator.setDetachedContents(detachedContents); diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBWith2ReferencesTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBWith2ReferencesTest.java index 2ee4d3e467..604059fba8 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBWith2ReferencesTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESLevelBWith2ReferencesTest.java @@ -13,17 +13,12 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.DigestAlgorithm; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; -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.signature.PKIFactoryAccess; import eu.europa.esig.dss.utils.Utils; -import eu.europa.esig.dss.validation.CertificateVerifier; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; @@ -32,7 +27,7 @@ import eu.europa.esig.dss.xades.DSSTransform; import eu.europa.esig.dss.xades.XAdESSignatureParameters; -public class XAdESLevelBWith2ReferencesTest { +public class XAdESLevelBWith2ReferencesTest extends PKIFactoryAccess { private static String FILE1 = "src/test/resources/sample.xml"; private static String FILE2 = "src/test/resources/sampleISO.xml"; @@ -67,27 +62,23 @@ public void test1() throws Exception { refs.add(ref1); refs.add(ref2); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); signatureParameters.setReferences(refs); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); ToBeSigned toSign1 = service.getDataToSign(new FileDocument("src/test/resources/empty.xml"), signatureParameters); - SignatureValue value = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toSign1); + SignatureValue value = getToken().sign(toSign1, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument result = service.signDocument(doc1, signatureParameters, value); // result.save("src/test/resources/test.xml"); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(result); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); // reports.print(); @@ -100,7 +91,7 @@ public void test1() throws Exception { assertEquals(2, Utils.collectionSize(signatureWrapper.getSignatureScopes())); List signatureCertificateChain = diagnosticData.getSignatureCertificateChain(diagnosticData.getFirstSignatureId()); - assertEquals(privateKeyEntry.getCertificateChain().length, signatureCertificateChain.size() - 1); + assertEquals(getCertificateChain().length, signatureCertificateChain.size()); assertEquals(signatureParameters.getSignatureLevel().toString(), diagnosticData.getSignatureFormat(diagnosticData.getFirstSignatureId())); } @@ -110,25 +101,20 @@ public void multiDocsEnveloping() throws Exception { docs.add(new FileDocument(FILE1)); docs.add(new FileDocument(FILE2)); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); - + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); ToBeSigned toSign1 = service.getDataToSign(docs, signatureParameters); - SignatureValue value = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toSign1); + SignatureValue value = getToken().sign(toSign1, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument result = service.signDocument(docs, signatureParameters, value); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(result); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); // reports.print(); @@ -141,7 +127,7 @@ public void multiDocsEnveloping() throws Exception { assertEquals(2, Utils.collectionSize(signatureWrapper.getSignatureScopes())); List signatureCertificateChain = diagnosticData.getSignatureCertificateChain(diagnosticData.getFirstSignatureId()); - assertEquals(privateKeyEntry.getCertificateChain().length, signatureCertificateChain.size() - 1); + assertEquals(getCertificateChain().length, signatureCertificateChain.size()); assertEquals(signatureParameters.getSignatureLevel().toString(), diagnosticData.getSignatureFormat(diagnosticData.getFirstSignatureId())); } @@ -151,25 +137,20 @@ public void multiDocsDetached() throws Exception { docs.add(new FileDocument(FILE1)); docs.add(new FileDocument(FILE2)); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); - + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); ToBeSigned toSign1 = service.getDataToSign(docs, signatureParameters); - SignatureValue value = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toSign1); + SignatureValue value = getToken().sign(toSign1, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument result = service.signDocument(docs, signatureParameters, value); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(result); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); validator.setDetachedContents(docs); Reports reports = validator.validateDocument(); // reports.print(); @@ -183,7 +164,7 @@ public void multiDocsDetached() throws Exception { assertEquals(2, Utils.collectionSize(signatureWrapper.getSignatureScopes())); List signatureCertificateChain = diagnosticData.getSignatureCertificateChain(diagnosticData.getFirstSignatureId()); - assertEquals(privateKeyEntry.getCertificateChain().length, signatureCertificateChain.size() - 1); + assertEquals(getCertificateChain().length, signatureCertificateChain.size()); assertEquals(signatureParameters.getSignatureLevel().toString(), diagnosticData.getSignatureFormat(diagnosticData.getFirstSignatureId())); } @@ -191,25 +172,21 @@ public void multiDocsDetached() throws Exception { public void test2() throws Exception { DSSDocument doc1 = new FileDocument(FILE1); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); ToBeSigned toSign1 = service.getDataToSign(doc1, signatureParameters); - SignatureValue value = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toSign1); + SignatureValue value = getToken().sign(toSign1, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument result = service.signDocument(doc1, signatureParameters, value); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(result); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); DiagnosticData diagnosticData = reports.getDiagnosticData(); @@ -221,7 +198,12 @@ public void test2() throws Exception { assertEquals(1, Utils.collectionSize(signatureWrapper.getSignatureScopes())); List signatureCertificateChain = diagnosticData.getSignatureCertificateChain(diagnosticData.getFirstSignatureId()); - assertEquals(privateKeyEntry.getCertificateChain().length, signatureCertificateChain.size() - 1); + assertEquals(getCertificateChain().length, signatureCertificateChain.size()); assertEquals(signatureParameters.getSignatureLevel().toString(), diagnosticData.getSignatureFormat(diagnosticData.getFirstSignatureId())); } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESManifestLevelBTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESManifestLevelBTest.java index db7471de2d..69b89e1c79 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESManifestLevelBTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/signature/XAdESManifestLevelBTest.java @@ -14,8 +14,6 @@ import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.signature.AbstractPkiFactoryTestDocumentSignatureService; import eu.europa.esig.dss.signature.DocumentSignatureService; -import eu.europa.esig.dss.validation.CertificateVerifier; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; import eu.europa.esig.dss.xades.XAdESSignatureParameters; public class XAdESManifestLevelBTest extends AbstractPkiFactoryTestDocumentSignatureService { @@ -43,8 +41,7 @@ public void init() throws Exception { signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); signatureParameters.setManifestSignature(true); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - service = new XAdESService(certificateVerifier); + service = new XAdESService(getCompleteCertificateVerifier()); } @Override diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/DSS920ValidationWithDigest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/DSS920ValidationWithDigestTest.java similarity index 75% rename from dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/DSS920ValidationWithDigest.java rename to dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/DSS920ValidationWithDigestTest.java index 0ac428d053..0fa8d7211f 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/DSS920ValidationWithDigest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/DSS920ValidationWithDigestTest.java @@ -13,15 +13,11 @@ import eu.europa.esig.dss.DigestAlgorithm; import eu.europa.esig.dss.DigestDocument; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; -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.CommonCertificateVerifier; +import eu.europa.esig.dss.signature.PKIFactoryAccess; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; @@ -29,34 +25,28 @@ import eu.europa.esig.dss.xades.XAdESSignatureParameters; import eu.europa.esig.dss.xades.signature.XAdESService; -public class DSS920ValidationWithDigest { +public class DSS920ValidationWithDigestTest extends PKIFactoryAccess { @Test public void testValidationWithDigest() throws Exception { - SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.RSA_SHA256; - DSSDocument toBeSigned = new FileDocument(new File("src/test/resources/sample.xml")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(signatureAlgorithm); - - CommonCertificateVerifier verifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(verifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); XAdESSignatureParameters params = new XAdESSignatureParameters(); params.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); params.setSignaturePackaging(SignaturePackaging.DETACHED); - params.setSigningCertificate(privateKeyEntry.getCertificate()); + params.setSigningCertificate(getSigningCert()); ToBeSigned dataToSign = service.getDataToSign(toBeSigned, params); - SignatureValue signatureValue = TestUtils.sign(signatureAlgorithm, privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, params.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(toBeSigned, params, signatureValue); // PROVIDE WRONG DIGEST WITH WRONG ALGO SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); // Provide only the digest value List detachedContents = new ArrayList(); @@ -75,7 +65,7 @@ public void testValidationWithDigest() throws Exception { // PROVIDE CORRECT DIGEST WITH CORRECT ALGO validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); // Provide only the digest value detachedContents = new ArrayList(); @@ -90,6 +80,11 @@ public void testValidationWithDigest() throws Exception { diagnosticData = reports.getDiagnosticData(); signatureById = diagnosticData.getSignatureById(diagnosticData.getFirstSignatureId()); assertTrue(signatureById.isBLevelTechnicallyValid()); + } + @Override + protected String getSigningAlias() { + return GOOD_USER; } + } diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/GetOriginalDocumentTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/GetOriginalDocumentTest.java index 4f46645c1d..3f73216bde 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/GetOriginalDocumentTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/GetOriginalDocumentTest.java @@ -14,16 +14,11 @@ import eu.europa.esig.dss.DSSUtils; import eu.europa.esig.dss.DigestAlgorithm; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; -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.reports.Reports; import eu.europa.esig.dss.xades.DSSReference; @@ -31,31 +26,27 @@ import eu.europa.esig.dss.xades.XAdESSignatureParameters; import eu.europa.esig.dss.xades.signature.XAdESService; -public class GetOriginalDocumentTest { +public class GetOriginalDocumentTest extends PKIFactoryAccess { @Test public final void getOneOriginalDocumentFromEnvelopedSignature() throws Exception { DSSDocument document = new FileDocument("src/test/resources/sample.xml"); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPED); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); List originals = validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId()); @@ -73,25 +64,21 @@ public final void getOneOriginalDocumentFromEnvelopedSignature() throws Exceptio public final void getOneOriginalDocumentFromEnvelopingSignature() throws Exception { DSSDocument document = new FileDocument("src/test/resources/sample.xml"); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); List results = validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId()); @@ -109,25 +96,21 @@ public final void getOneOriginalDocumentFromEnvelopingSignature() throws Excepti public final void getOneOriginalDocumentFromDetachedSignature() throws Exception { DSSDocument document = new FileDocument("src/test/resources/sample.xml"); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.DETACHED); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, dataToSign); + SignatureValue signatureValue = getToken().sign(dataToSign, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId()); @@ -163,26 +146,22 @@ public final void getTwoOriginalDocumentFromEnvelopingSignature() throws Excepti refs.add(ref1); refs.add(ref2); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); signatureParameters.setReferences(refs); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); ToBeSigned toSign1 = service.getDataToSign(new FileDocument("src/test/resources/empty.xml"), signatureParameters); - SignatureValue value = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toSign1); + SignatureValue value = getToken().sign(toSign1, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(doc1, signatureParameters, value); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); List results = validator.getOriginalDocuments(reports.getDiagnosticData().getFirstSignatureId()); @@ -200,4 +179,9 @@ public final void getTwoOriginalDocumentFromEnvelopingSignature() throws Excepti secondDocument = new String(canon.canonicalize(DSSUtils.toByteArray(orig2))); Assert.assertEquals(firstDocument, secondDocument); } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESBExtendToLTACheckTimeStampIDTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESBExtendToLTACheckTimeStampIDTest.java index 4fcbc64b8e..96c015b523 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESBExtendToLTACheckTimeStampIDTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESBExtendToLTACheckTimeStampIDTest.java @@ -8,17 +8,11 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; @@ -26,28 +20,24 @@ import eu.europa.esig.dss.xades.XAdESSignatureParameters; import eu.europa.esig.dss.xades.signature.XAdESService; -public class XAdESBExtendToLTACheckTimeStampIDTest { +public class XAdESBExtendToLTACheckTimeStampIDTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new FileDocument(new File("src/test/resources/sample.xml")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); + SignatureValue signatureValue = getToken().sign(toBeSigned, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_LTA); @@ -55,7 +45,7 @@ public void test() throws Exception { signedDocument = service.extendDocument(signedDocument, signatureParameters); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); @@ -65,4 +55,9 @@ public void test() throws Exception { Assert.assertEquals(signatureId, wrapper.getSignedObjects().getSignedSignature().get(0).getId()); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESLTACheckTimeStampIDTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESLTACheckTimeStampIDTest.java index f10e369bfb..d86170a153 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESLTACheckTimeStampIDTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESLTACheckTimeStampIDTest.java @@ -8,17 +8,11 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; @@ -26,32 +20,28 @@ import eu.europa.esig.dss.xades.XAdESSignatureParameters; import eu.europa.esig.dss.xades.signature.XAdESService; -public class XAdESLTACheckTimeStampIDTest { +public class XAdESLTACheckTimeStampIDTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new FileDocument(new File("src/test/resources/sample.xml")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_LTA); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); + SignatureValue signatureValue = getToken().sign(toBeSigned, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); @@ -61,4 +51,9 @@ public void test() throws Exception { Assert.assertEquals(signatureId, wrapper.getSignedObjects().getSignedSignature().get(0).getId()); } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESLTACheckTimeStampedTimestampIDTest.java b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESLTACheckTimeStampedTimestampIDTest.java index 48697ef3c7..292476369c 100644 --- a/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESLTACheckTimeStampedTimestampIDTest.java +++ b/dss-xades/src/test/java/eu/europa/esig/dss/xades/validation/XAdESLTACheckTimeStampedTimestampIDTest.java @@ -8,17 +8,11 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; import eu.europa.esig.dss.SignatureValue; import eu.europa.esig.dss.ToBeSigned; -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.test.mock.MockTSPSource; -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.reports.Reports; import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData; @@ -27,32 +21,28 @@ import eu.europa.esig.dss.xades.XAdESSignatureParameters; import eu.europa.esig.dss.xades.signature.XAdESService; -public class XAdESLTACheckTimeStampedTimestampIDTest { +public class XAdESLTACheckTimeStampedTimestampIDTest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument documentToSign = new FileDocument(new File("src/test/resources/sample.xml")); - CertificateService certificateService = new CertificateService(); - MockPrivateKeyEntry privateKeyEntry = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); - signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); - signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); + signatureParameters.setSigningCertificate(getSigningCert()); + signatureParameters.setCertificateChain(getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_LTA); - CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); - XAdESService service = new XAdESService(certificateVerifier); - service.setTspSource(new MockTSPSource(certificateService.generateTspCertificate(SignatureAlgorithm.RSA_SHA1))); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); - SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); + SignatureValue signatureValue = getToken().sign(toBeSigned, signatureParameters.getDigestAlgorithm(), getPrivateKeyEntry()); final DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); - validator.setCertificateVerifier(new CommonCertificateVerifier()); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); @@ -64,4 +54,9 @@ public void test() throws Exception { } } } + + @Override + protected String getSigningAlias() { + return GOOD_USER; + } } diff --git a/dss-xades/src/test/java/known/issues/XAdESBWithoutSignedDataObjectPropertiesToLTATest.java b/dss-xades/src/test/java/known/issues/XAdESBWithoutSignedDataObjectPropertiesToLTATest.java index 6be07ae474..bceeb1415f 100644 --- a/dss-xades/src/test/java/known/issues/XAdESBWithoutSignedDataObjectPropertiesToLTATest.java +++ b/dss-xades/src/test/java/known/issues/XAdESBWithoutSignedDataObjectPropertiesToLTATest.java @@ -9,13 +9,9 @@ import eu.europa.esig.dss.DSSDocument; import eu.europa.esig.dss.DigestAlgorithm; import eu.europa.esig.dss.FileDocument; -import eu.europa.esig.dss.SignatureAlgorithm; import eu.europa.esig.dss.SignatureLevel; import eu.europa.esig.dss.SignaturePackaging; -import eu.europa.esig.dss.test.gen.CertificateService; -import eu.europa.esig.dss.test.mock.MockPrivateKeyEntry; -import eu.europa.esig.dss.test.mock.MockTSPSource; -import eu.europa.esig.dss.validation.CommonCertificateVerifier; +import eu.europa.esig.dss.signature.PKIFactoryAccess; import eu.europa.esig.dss.validation.SignaturePolicyProvider; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; @@ -24,22 +20,20 @@ import eu.europa.esig.dss.xades.XAdESSignatureParameters; import eu.europa.esig.dss.xades.signature.XAdESService; -public class XAdESBWithoutSignedDataObjectPropertiesToLTATest { +public class XAdESBWithoutSignedDataObjectPropertiesToLTATest extends PKIFactoryAccess { @Test public void test() throws Exception { DSSDocument toSignDocument = new FileDocument("src/test/resources/XAdESBWithoutSignedDataObjectProperties.xml"); - CertificateService certService = new CertificateService(); - MockPrivateKeyEntry signerEntry = certService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256); - XAdESService service = new XAdESService(new CommonCertificateVerifier()); - service.setTspSource(new MockTSPSource(new CertificateService().generateTspCertificate(SignatureAlgorithm.RSA_SHA256))); + XAdESService service = new XAdESService(getCompleteCertificateVerifier()); + service.setTspSource(getGoodTsa()); XAdESSignatureParameters parameters = new XAdESSignatureParameters(); parameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_LTA); parameters.setSignaturePackaging(SignaturePackaging.ENVELOPED); - parameters.setSigningCertificate(signerEntry.getCertificate()); - parameters.setCertificateChain(signerEntry.getCertificateChain()); + parameters.setSigningCertificate(getSigningCert()); + parameters.setCertificateChain(getCertificateChain()); parameters.setDigestAlgorithm(DigestAlgorithm.SHA256); DSSDocument extendDocument = service.extendDocument(toSignDocument, parameters); @@ -47,7 +41,6 @@ public void test() throws Exception { SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(extendDocument); - CommonCertificateVerifier certificateVerifier = new CommonCertificateVerifier(); // certificateVerifier.setDataLoader(new CommonsDataLoader()); SignaturePolicyProvider signaturePolicyProvider = new SignaturePolicyProvider(); Map signaturePoliciesByUrl = new HashMap(); @@ -55,7 +48,7 @@ public void test() throws Exception { new FileDocument("src/test/resources/validation/dss1135/politica_de_firma.pdf")); signaturePolicyProvider.setSignaturePoliciesByUrl(signaturePoliciesByUrl); validator.setSignaturePolicyProvider(signaturePolicyProvider); - validator.setCertificateVerifier(certificateVerifier); + validator.setCertificateVerifier(getCompleteCertificateVerifier()); Reports reports = validator.validateDocument(); SimpleReport simpleReport = reports.getSimpleReport(); @@ -63,4 +56,9 @@ public void test() throws Exception { Assert.assertEquals(SignatureLevel.XAdES_BASELINE_LTA.toString(), diagnosticData.getSignatureFormat(simpleReport.getFirstSignatureId())); } + @Override + protected String getSigningAlias() { + return GOOD_USER; + } + } diff --git a/pom.xml b/pom.xml index a4af1c1180..f64003a47a 100644 --- a/pom.xml +++ b/pom.xml @@ -147,13 +147,14 @@ org.apache.maven.plugins maven-surefire-plugin - 2.19.1 + 2.20 true commons-logging:commons-logging + 1 @@ -318,12 +319,6 @@ dss-document ${project.version} - - eu.europa.ec.joinup.sd-dss - dss-document - test-jar - ${project.version} - eu.europa.ec.joinup.sd-dss dss-asic-common diff --git a/validation-policy/pom.xml b/validation-policy/pom.xml index 11d91f6c6b..4bf1b34270 100644 --- a/validation-policy/pom.xml +++ b/validation-policy/pom.xml @@ -16,11 +16,28 @@ org.slf4j slf4j-api - + + + ch.qos.logback + logback-classic + test + + + junit + junit + test + + + + + + + + eu.europa.ec.joinup.sd-dss - dss-test - test + dss-utils-google-guava + test \ No newline at end of file