@@ -85,5 +85,41 @@ public virtual void SequentialSignOfFileWithAnnots() {
8585 signer . SignDetached ( pks , signChain , null , null , null , 0 , PdfSigner . CryptoStandard . CADES ) ;
8686 PadesSigTest . BasicCheckSignedDoc ( outFileName , signatureName ) ;
8787 }
88+
89+ [ NUnit . Framework . Test ]
90+ public virtual void SecondSignOfTaggedDocTest ( ) {
91+ String signCertFileName = certsSrc + "signCertRsa01.p12" ;
92+ String outFileName = destinationFolder + "secondSignOfTagged.pdf" ;
93+ String srcFileName = sourceFolder + "taggedAndSignedDoc.pdf" ;
94+ X509Certificate [ ] signChain = Pkcs12FileHelper . ReadFirstChain ( signCertFileName , password ) ;
95+ ICipherParameters signPrivateKey = Pkcs12FileHelper . ReadFirstKey ( signCertFileName , password , password ) ;
96+ IExternalSignature pks = new PrivateKeySignature ( signPrivateKey , DigestAlgorithms . SHA256 ) ;
97+ String signatureName = "Signature2" ;
98+ PdfSigner signer = new PdfSigner ( new PdfReader ( srcFileName ) , new FileStream ( outFileName , FileMode . Create ) ,
99+ new StampingProperties ( ) . UseAppendMode ( ) ) ;
100+ PdfDocument document = signer . GetDocument ( ) ;
101+ document . GetWriter ( ) . SetCompressionLevel ( CompressionConstants . NO_COMPRESSION ) ;
102+ signer . SetFieldName ( signatureName ) ;
103+ PdfSignatureAppearance appearance = signer . GetSignatureAppearance ( ) ;
104+ appearance . SetPageNumber ( 1 ) ;
105+ signer . GetSignatureAppearance ( ) . SetPageRect ( new Rectangle ( 50 , 550 , 200 , 100 ) ) . SetReason ( "Test2" ) . SetLocation
106+ ( "TestCity2" ) . SetLayer2Text ( "Approval test signature #2.\n Created by iText7." ) ;
107+ signer . SignDetached ( pks , signChain , null , null , null , 0 , PdfSigner . CryptoStandard . CADES ) ;
108+ PadesSigTest . BasicCheckSignedDoc ( outFileName , "Signature1" ) ;
109+ PadesSigTest . BasicCheckSignedDoc ( outFileName , "Signature2" ) ;
110+ using ( PdfDocument twiceSigned = new PdfDocument ( new PdfReader ( outFileName ) ) ) {
111+ using ( PdfDocument resource = new PdfDocument ( new PdfReader ( srcFileName ) ) ) {
112+ float resourceStrElemNumber = resource . GetStructTreeRoot ( ) . GetPdfObject ( ) . GetAsArray ( PdfName . K ) . GetAsDictionary
113+ ( 0 ) . GetAsArray ( PdfName . K ) . Size ( ) ;
114+ float outStrElemNumber = twiceSigned . GetStructTreeRoot ( ) . GetPdfObject ( ) . GetAsArray ( PdfName . K ) . GetAsDictionary
115+ ( 0 ) . GetAsArray ( PdfName . K ) . Size ( ) ;
116+ // Here we assert the amount of objects in StructTreeRoot in resource file and twice signed file
117+ // as the original signature validation failed by Adobe because of struct tree change. If the fix
118+ // would make this tree unchanged, then the assertion should be adjusted with comparing the tree of
119+ // objects in StructTreeRoot to ensure that it won't be changed.
120+ NUnit . Framework . Assert . AreNotEqual ( resourceStrElemNumber , outStrElemNumber ) ;
121+ }
122+ }
123+ }
88124 }
89125}
0 commit comments