@@ -23,16 +23,21 @@ This file is part of the iText (R) project.
23
23
package com .itextpdf .signatures .sign ;
24
24
25
25
import com .itextpdf .bouncycastleconnector .BouncyCastleFactoryCreator ;
26
+ import com .itextpdf .commons .actions .data .ProductData ;
26
27
import com .itextpdf .commons .bouncycastle .IBouncyCastleFactory ;
27
28
import com .itextpdf .commons .bouncycastle .operator .AbstractOperatorCreationException ;
28
29
import com .itextpdf .commons .bouncycastle .pkcs .AbstractPKCSException ;
29
30
import com .itextpdf .commons .utils .FileUtil ;
30
31
import com .itextpdf .commons .utils .MessageFormatUtil ;
31
32
import com .itextpdf .forms .form .element .SignatureFieldAppearance ;
33
+ import com .itextpdf .io .source .ByteArrayOutputStream ;
34
+ import com .itextpdf .kernel .actions .data .ITextCoreProductData ;
32
35
import com .itextpdf .kernel .crypto .DigestAlgorithms ;
33
36
import com .itextpdf .kernel .exceptions .PdfException ;
34
37
import com .itextpdf .kernel .geom .Rectangle ;
38
+ import com .itextpdf .kernel .pdf .PdfDocument ;
35
39
import com .itextpdf .kernel .pdf .PdfReader ;
40
+ import com .itextpdf .kernel .pdf .PdfWriter ;
36
41
import com .itextpdf .signatures .ICrlClient ;
37
42
import com .itextpdf .signatures .IExternalSignature ;
38
43
import com .itextpdf .signatures .PdfPadesSigner ;
@@ -48,6 +53,7 @@ This file is part of the iText (R) project.
48
53
import com .itextpdf .test .ExtendedITextTest ;
49
54
import com .itextpdf .test .TestUtil ;
50
55
56
+ import java .io .ByteArrayInputStream ;
51
57
import java .io .IOException ;
52
58
import java .security .GeneralSecurityException ;
53
59
import java .security .PrivateKey ;
@@ -56,6 +62,7 @@ This file is part of the iText (R) project.
56
62
import java .security .cert .CertificateException ;
57
63
import java .security .cert .X509Certificate ;
58
64
import java .util .Arrays ;
65
+
59
66
import org .junit .jupiter .api .Assertions ;
60
67
import org .junit .jupiter .api .Assumptions ;
61
68
import org .junit .jupiter .api .BeforeAll ;
@@ -298,6 +305,58 @@ private SignerProperties createSignerProperties() {
298
305
return signerProperties ;
299
306
}
300
307
308
+ @ Test
309
+ public void producerLineWithMetaInfoUsedTest ()
310
+ throws IOException , GeneralSecurityException , AbstractOperatorCreationException , AbstractPKCSException {
311
+ String fileName = "producerLineWithMetaInfoUsed.pdf" ;
312
+ String outFileName = destinationFolder + fileName ;
313
+ String srcFileName = sourceFolder + "helloWorldDoc.pdf" ;
314
+ String signCertFileName = certsSrc + "signCertRsa01.pem" ;
315
+ String tsaCertFileName = certsSrc + "tsCertRsa.pem" ;
316
+ String caCertFileName = certsSrc + "rootRsa.pem" ;
317
+
318
+ Certificate [] signRsaChain = PemFileHelper .readFirstChain (signCertFileName );
319
+ PrivateKey signRsaPrivateKey = PemFileHelper .readFirstKey (signCertFileName , password );
320
+ IExternalSignature pks =
321
+ new PrivateKeySignature (signRsaPrivateKey , DigestAlgorithms .SHA256 , FACTORY .getProviderName ());
322
+ Certificate [] tsaChain = PemFileHelper .readFirstChain (tsaCertFileName );
323
+ PrivateKey tsaPrivateKey = PemFileHelper .readFirstKey (tsaCertFileName , password );
324
+ X509Certificate caCert = (X509Certificate ) PemFileHelper .readFirstChain (caCertFileName )[0 ];
325
+ PrivateKey caPrivateKey = PemFileHelper .readFirstKey (caCertFileName , password );
326
+
327
+ SignerProperties signerProperties = new SignerProperties ();
328
+
329
+ PdfPadesSigner padesSigner = createPdfPadesSigner (srcFileName , outFileName );
330
+
331
+ TestTsaClient testTsa = new TestTsaClient (Arrays .asList (tsaChain ), tsaPrivateKey );
332
+ ICrlClient crlClient = new TestCrlClient ().addBuilderForCertIssuer (caCert , caPrivateKey );
333
+ TestOcspClient ocspClient = new TestOcspClient ().addBuilderForCertIssuer (caCert , caPrivateKey );
334
+
335
+ padesSigner .setOcspClient (ocspClient ).setCrlClient (crlClient );
336
+
337
+ padesSigner .signWithBaselineLTAProfile (signerProperties , signRsaChain , pks , testTsa );
338
+
339
+ byte [] docBytes ;
340
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream ()) {
341
+ new PdfDocument (new PdfReader (srcFileName ) ,new PdfWriter (outputStream )).close ();
342
+ docBytes = outputStream .toByteArray ();
343
+ }
344
+
345
+ try (PdfDocument signedPdf = new PdfDocument (new PdfReader (outFileName ))) {
346
+ try (PdfDocument regularPdf = new PdfDocument (new PdfReader (new ByteArrayInputStream (docBytes )))) {
347
+ ProductData productData = ITextCoreProductData .getInstance ();
348
+ String newlyAddedProducer = "iText\u00ae " + productData .getPublicProductName () + " " +
349
+ productData .getVersion () + " \u00a9 " + productData .getSinceCopyrightYear () + "-"
350
+ + productData .getToCopyrightYear () + " Apryse Group NV" ;
351
+ String actualProducerLine = signedPdf .getDocumentInfo ().getProducer ();
352
+ String regularProducerLine = regularPdf .getDocumentInfo ().getProducer ();
353
+
354
+ Assertions .assertTrue (actualProducerLine .contains (regularProducerLine ));
355
+ Assertions .assertTrue (actualProducerLine .contains (newlyAddedProducer ));
356
+ }
357
+ }
358
+ }
359
+
301
360
private PdfPadesSigner createPdfPadesSigner (String srcFileName , String outFileName ) throws IOException {
302
361
return new PdfPadesSigner (new PdfReader (FileUtil .getInputStreamForFile (srcFileName )),
303
362
FileUtil .getFileOutputStream (outFileName ));
0 commit comments