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<AdvancedSignature> signatures = validator.getSignatures(); assertTrue(Utils.isCollectionNotEmpty(signatures)); Reports reports = validator.validateDocument(); assertNotNull(reports); } }