@Before public void init() throws Exception { documentToSign = new InMemoryDocument("Hello World".getBytes()); CertificateService certificateService = new CertificateService(); privateKeyEntry = certificateService.generateExpiredCertificateChain(SignatureAlgorithm.RSA_SHA512, false); signatureParameters = new CAdESSignatureParameters(); signatureParameters.bLevel().setSigningDate(new Date()); signatureParameters.setSigningCertificate(privateKeyEntry.getCertificate()); signatureParameters.setCertificateChain(privateKeyEntry.getCertificateChain()); signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING); signatureParameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B); signatureParameters.setDigestAlgorithm(DigestAlgorithm.SHA512); signatureParameters.setSignWithExpiredCertificate(true); CertificateVerifier certificateVerifier = new CommonCertificateVerifier(); service = new CAdESService(certificateVerifier); }
@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.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))); ToBeSigned toBeSigned = service.getDataToSign(documentToSign, signatureParameters); SignatureValue signatureValue = TestUtils.sign(signatureParameters.getSignatureAlgorithm(), privateKeyEntry, toBeSigned); final DSSDocument signedDocument = service.signDocument(documentToSign, signatureParameters, signatureValue); SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(signedDocument); validator.setCertificateVerifier(new CommonCertificateVerifier()); Reports report = validator.validateDocument(); // report.print(); DiagnosticData diagnostic = report.getDiagnosticData(); String timestampId = diagnostic.getSignatures().get(0).getTimestampList().get(0).getId(); for (TimestampWrapper wrapper : diagnostic.getTimestampList(diagnostic.getFirstSignatureId())) { if (wrapper.getType().equals(TimestampType.ARCHIVE_TIMESTAMP.toString())) { Assert.assertEquals( timestampId, wrapper.getSignedObjects().getTimestampedTimestamp().get(0).getId()); } } }