Skip to content

Commit f8e5330

Browse files
Kate IvanovaiText-CI
authored andcommitted
Add test on second time signing document
DEVSIX-4769 Autoported commit. Original commit hash: [f810573aa]
1 parent 9521677 commit f8e5330

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

itext.tests/itext.sign.tests/itext/signatures/sign/SequentialSignaturesTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.\nCreated 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
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fd681f7b4221d0ca4d131d50335ab0b2e5971faf
1+
f810573aa4128c64bbead6982f1c1486cf572a73

0 commit comments

Comments
 (0)