From bb85c49ad0be48d5693df09d47746d3626fb69b4 Mon Sep 17 00:00:00 2001 From: Angelina Pavlovets Date: Thu, 26 Sep 2024 14:44:17 +0000 Subject: [PATCH] Add ability to set null values for SignedAppearanceText Autoported commit. Original commit hash: [dc76524bd] --- .../element/SignatureFieldAppearanceTest.cs | 38 ++++++++++++-- .../cmp_emptySigFieldAppearance.pdf | Bin 0 -> 1082 bytes ...mp_ignoreSignDateAndReasonInAppearance.pdf | Bin 0 -> 1297 bytes .../sign/SignedAppearanceTextTest.cs | 24 +++++++++ ...ReasonLocationSignDateInAppearanceText.pdf | Bin 0 -> 19062 bytes .../fields/properties/SignedAppearanceText.cs | 31 +++++++---- .../itext.sign/itext/signatures/PdfSigner.cs | 48 ++++++++++++------ .../itext/signatures/SignerProperties.cs | 7 +++ port-hash | 2 +- 9 files changed, 120 insertions(+), 30 deletions(-) create mode 100644 itext.tests/itext.forms.tests/resources/itext/forms/form/element/SignatureFieldAppearanceTest/cmp_emptySigFieldAppearance.pdf create mode 100644 itext.tests/itext.forms.tests/resources/itext/forms/form/element/SignatureFieldAppearanceTest/cmp_ignoreSignDateAndReasonInAppearance.pdf create mode 100644 itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignedAppearanceTextTest/cmp_noReasonLocationSignDateInAppearanceText.pdf diff --git a/itext.tests/itext.forms.tests/itext/forms/form/element/SignatureFieldAppearanceTest.cs b/itext.tests/itext.forms.tests/itext/forms/form/element/SignatureFieldAppearanceTest.cs index b6d208abf3..0c6ea92e59 100644 --- a/itext.tests/itext.forms.tests/itext/forms/form/element/SignatureFieldAppearanceTest.cs +++ b/itext.tests/itext.forms.tests/itext/forms/form/element/SignatureFieldAppearanceTest.cs @@ -124,6 +124,38 @@ public virtual void CustomizedSigFieldTest() { NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER)); } + [NUnit.Framework.Test] + public virtual void EmptySigFieldAppearanceTest() { + String outPdf = DESTINATION_FOLDER + "emptySigFieldAppearance.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_emptySigFieldAppearance.pdf"; + using (Document document = new Document(new PdfDocument(new PdfWriter(outPdf)))) { + SignedAppearanceText description = new SignedAppearanceText().SetSignedBy(null).SetLocationLine(null).SetReasonLine + (null); + SignatureFieldAppearance formSigField = new SignatureFieldAppearance("Signature1").SetContent(description); + formSigField.SetBackgroundColor(ColorConstants.LIGHT_GRAY); + formSigField.SetBorder(new SolidBorder(ColorConstants.GREEN, 2)); + formSigField.SetHeight(100).SetWidth(200); + document.Add(formSigField); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER)); + } + + [NUnit.Framework.Test] + public virtual void IgnoreSignDateAndReasonInAppearanceTest() { + String outPdf = DESTINATION_FOLDER + "ignoreSignDateAndReasonInAppearance.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_ignoreSignDateAndReasonInAppearance.pdf"; + using (Document document = new Document(new PdfDocument(new PdfWriter(outPdf)))) { + SignedAppearanceText description = new SignedAppearanceText().SetSignedBy("Signer Name").SetLocationLine("Test Location" + ).SetReasonLine(null); + SignatureFieldAppearance formSigField = new SignatureFieldAppearance("Signature1").SetContent(description); + formSigField.SetBackgroundColor(ColorConstants.LIGHT_GRAY); + formSigField.SetBorder(new SolidBorder(ColorConstants.GREEN, 2)); + formSigField.SetHeight(100).SetWidth(200); + document.Add(formSigField); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER)); + } + [NUnit.Framework.Test] [LogMessage(iText.IO.Logs.IoLogMessageConstant.CLIP_ELEMENT)] public virtual void SignatureFieldVerticalAlignmentTest() { @@ -341,7 +373,7 @@ public virtual void FontSizeTest() { [NUnit.Framework.Test] public virtual void FontNullCustomCheck() { String outPdf = DESTINATION_FOLDER + "fontNullCustomCheck.pdf"; - PdfDocument pdfDoc = new _PdfDocument_412(new PdfWriter(outPdf)); + PdfDocument pdfDoc = new _PdfDocument_450(new PdfWriter(outPdf)); Document document = new Document(pdfDoc); SignatureFieldAppearance sigField = new SignatureFieldAppearance("SigField"); sigField.SetContent("test"); @@ -352,8 +384,8 @@ public virtual void FontNullCustomCheck() { NUnit.Framework.Assert.AreEqual(LayoutExceptionMessageConstant.INVALID_FONT_PROPERTY_VALUE, e.Message); } - private sealed class _PdfDocument_412 : PdfDocument { - public _PdfDocument_412(PdfWriter baseArg1) + private sealed class _PdfDocument_450 : PdfDocument { + public _PdfDocument_450(PdfWriter baseArg1) : base(baseArg1) { } diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/form/element/SignatureFieldAppearanceTest/cmp_emptySigFieldAppearance.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/form/element/SignatureFieldAppearanceTest/cmp_emptySigFieldAppearance.pdf new file mode 100644 index 0000000000000000000000000000000000000000..9110617e77bb1ae75a5674301d0fe90aaea02899 GIT binary patch literal 1082 zcmc&yO=uHA7%hlM7tw=4FA75;v_+Dgnf)D&p)qM{?N36Q_L5XO*_};S(`?w?NGd{A z1o01l5ELuoRS`iDk1BYmo)oM1S`pMs5yW~>a5h9!Tkz_fX5PG+?|tukp-eIrMiEU2 zExmuaASeI=r+7$+M#Yp}_L(cD%G75`W;iAjhghZLPXQ!Jv6$z(j7|&no70yDw;TtX zlPi1s(vw2*+?L z^YYThi??<}CJ%SKy?1u(!QIYd-wu9l4;7x53Y}vo4}4EQJrSPYc4l_befQ$WqbDD) z&MrqvD|_bp7x3rTTR+h;V^jKZ?-hYn%%&c`3-rsaJ`zsFXBFQAL2p@cn3*=+=hX9% z9~GhiUB(k)hPs>saD$R%o>OxT=0&5in3!|z>2>_vOqKCRB^HYX#eCq-*zfV zZe4eBH-=b-1gj7sg77XVbwSwGBMv*}zX=)FF>3~MyX_pS`}aY@aTy>H7=hu@k$7fw ze>w*W-SPg+5IDkIj~6WTfIApM7!FE;c-5Wp80dGMS{00p_q4R4me!yNui1E`s|59F z*(tTifho;QB%B&|35kQY>E#2DvlHSUE4RAj5D7^;O;)54TWgoCT9HcD#cgh6M Rr>@@^szP)j6zWT-gkKYEK>do%OqhaHQ1w|Aa&>bCd8Z13RS?0n~(+?%;( zW^Gq6LXRZLJR*>;tgwGlp zibG&yQtj=7lV={MK`R?$>p_*B5_W z{OibkOV7`=>K?H@CrPrv)o%!hk^`g9ds*#Fpj zlh;0(tt|9BOQs%JoLE2d!%^$3^X3|_1-9=Sm|F4MszaZBImGrZoKe2IzU-Hi_Qlon zr4w^wZ=ApJ(rbe&p1CwPaPX~f(#J2C$c86t_x$;nldaGSjc^llDHHh3aVilA^|Ut7C(Y?VaxI(_lMrtT^ai8 z*aYi?tq7wv*D;suA&=$L{r&WMsIHy+j_ zKpVrLI*zssrklNzX0Kw1r~ySXRVRyCB^Yfw3n&_cb+8BoMsg2Sc0ufwncU^`E%f|R zd7J0w{K&g?@2lFeKuIJe$v1(wnODGn6R@Dl`5^LBo)eV>o5kUOB9iW!A+-=(2_r+| zGd2#=DOD+Q(M_F>EtJ@he@ka*yqGw*=`_{2OQ&L9{0=`%_$u9@)9Gz~amc(1gyMN_ z%A-;{H4W9aP1UBB>zd5Kx@m$%DAi1@Oo`)I;J8Eqhw0p+VFhc9Fq0^%>9`swhG`OA zFH;wr4x@&n>Sh^R8Zj*mbQ7ywc6E)JI;gh8z;-MPQ&zTArZEMBmHq!a7?wBrZh*v- sD9Xhk;M^u+pSK&3!TC%jE1eM=o%#1hOHs_iI3e1wR4J9}+S)Ds4Gx=}@&Et; literal 0 HcmV?d00001 diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/SignedAppearanceTextTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/SignedAppearanceTextTest.cs index fd9fc54149..a085ae28a4 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/SignedAppearanceTextTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/SignedAppearanceTextTest.cs @@ -101,6 +101,30 @@ public virtual void DefaultSignedAppearanceTextTest() { NUnit.Framework.Assert.IsNull(SignaturesCompareTool.CompareSignatures(outPdf, cmpPdf)); } + [NUnit.Framework.Test] + public virtual void NoReasonLocationSignDateInAppearanceTextTest() { + String srcFile = SOURCE_FOLDER + "simpleDocument.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_noReasonLocationSignDateInAppearanceText.pdf"; + String outPdf = DESTINATION_FOLDER + "noReasonLocationSignDateInAppearanceText.pdf"; + Rectangle rect = new Rectangle(36, 648, 200, 100); + String fieldName = "Signature1"; + SignatureFieldAppearance appearance = new SignatureFieldAppearance(SignerProperties.IGNORED_ID).SetContent + (new SignedAppearanceText().SetReasonLine(null).SetLocationLine(null)); + PdfSigner signer = new PdfSigner(new PdfReader(srcFile), FileUtil.GetFileOutputStream(outPdf), new StampingProperties + ()); + SignerProperties signerProperties = new SignerProperties().SetCertificationLevel(AccessPermissions.UNSPECIFIED + ).SetFieldName(fieldName).SetReason("Test 1").SetLocation("TestCity 1").SetSignatureAppearance(appearance + ).SetClaimedSignDate((DateTime)TimestampConstants.UNDEFINED_TIMESTAMP_DATE).SetPageRect(rect); + signer.SetSignerProperties(signerProperties); + // Creating the signature + IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); + signer.SignDetached(new BouncyCastleDigest(), pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES + ); + NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" + , GetTestMap(new Rectangle(36, 676, 200, 15)))); + NUnit.Framework.Assert.IsNull(SignaturesCompareTool.CompareSignatures(outPdf, cmpPdf)); + } + [NUnit.Framework.Test] public virtual void SignPDFADocumentWithoutSettingFont() { String srcFile = DESTINATION_FOLDER + "simplePDFA.pdf"; diff --git a/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignedAppearanceTextTest/cmp_noReasonLocationSignDateInAppearanceText.pdf b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/SignedAppearanceTextTest/cmp_noReasonLocationSignDateInAppearanceText.pdf new file mode 100644 index 0000000000000000000000000000000000000000..724bfc61826d36b4ebb25e911365abd826b13a92 GIT binary patch literal 19062 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 literal 0 HcmV?d00001 diff --git a/itext/itext.forms/itext/forms/fields/properties/SignedAppearanceText.cs b/itext/itext.forms/itext/forms/fields/properties/SignedAppearanceText.cs index 6d31c79006..8e2f0337d1 100644 --- a/itext/itext.forms/itext/forms/fields/properties/SignedAppearanceText.cs +++ b/itext/itext.forms/itext/forms/fields/properties/SignedAppearanceText.cs @@ -71,7 +71,10 @@ public virtual String GetReasonLine() { /// instance. /// public virtual iText.Forms.Fields.Properties.SignedAppearanceText SetReasonLine(String reason) { - this.reason = reason.Trim(); + if (reason != null) { + reason = reason.Trim(); + } + this.reason = reason; return this; } @@ -89,14 +92,17 @@ public virtual String GetLocationLine() { /// PdfSigner#setLocation /// will be used. /// - /// new signing location. + /// new signing location /// /// this same /// - /// instance. + /// instance /// public virtual iText.Forms.Fields.Properties.SignedAppearanceText SetLocationLine(String location) { - this.location = location.Trim(); + if (location != null) { + location = location.Trim(); + } + this.location = location; return this; } @@ -106,19 +112,22 @@ public virtual iText.Forms.Fields.Properties.SignedAppearanceText SetLocationLin /// /// Note, that the signer name will be replaced by the one from the signing certificate during the actual signing. /// - /// name of the signer. + /// name of the signer /// /// this same /// - /// instance. + /// instance /// public virtual iText.Forms.Fields.Properties.SignedAppearanceText SetSignedBy(String signedBy) { - this.signedBy = signedBy.Trim(); + if (signedBy != null) { + signedBy = signedBy.Trim(); + } + this.signedBy = signedBy; return this; } /// Gets the name of the signer from the certificate. - /// signedBy name of the signer. + /// signedBy name of the signer public virtual String GetSignedBy() { return signedBy; } @@ -137,11 +146,11 @@ public virtual DateTime GetSignDate() { /// PdfSigner /// during the signing. /// - /// new signature date. + /// new signature date /// /// this same /// - /// instance. + /// instance /// public virtual iText.Forms.Fields.Properties.SignedAppearanceText SetSignDate(DateTime signDate) { this.signDate = signDate; @@ -150,7 +159,7 @@ public virtual iText.Forms.Fields.Properties.SignedAppearanceText SetSignDate(Da } /// Generates the signature description text based on the provided parameters. - /// signature description. + /// signature description public virtual String GenerateDescriptionText() { StringBuilder buf = new StringBuilder(); if (signedBy != null && !String.IsNullOrEmpty(signedBy)) { diff --git a/itext/itext.sign/itext/signatures/PdfSigner.cs b/itext/itext.sign/itext/signatures/PdfSigner.cs index c69690a944..7130cead10 100644 --- a/itext/itext.sign/itext/signatures/PdfSigner.cs +++ b/itext/itext.sign/itext/signatures/PdfSigner.cs @@ -530,7 +530,10 @@ public virtual void SignDetached(IExternalDigest externalDigest, IExternalSignat dic.SetLocation(this.signerProperties.GetLocation()); dic.SetSignatureCreator(this.signerProperties.GetSignatureCreator()); dic.SetContact(this.signerProperties.GetContact()); - dic.SetDate(new PdfDate(this.signerProperties.GetClaimedSignDate())); + DateTime claimedSignDate = this.signerProperties.GetClaimedSignDate(); + if (claimedSignDate != TimestampConstants.UNDEFINED_TIMESTAMP_DATE) { + dic.SetDate(new PdfDate(claimedSignDate)); + } // time-stamp will over-rule this cryptoDictionary = dic; IDictionary exc = new Dictionary(); @@ -1254,8 +1257,9 @@ internal virtual PdfSignature CreateSignatureDictionary(bool includeDate) { dic.SetLocation(this.signerProperties.GetLocation()); dic.SetSignatureCreator(this.signerProperties.GetSignatureCreator()); dic.SetContact(this.signerProperties.GetContact()); - if (includeDate) { - dic.SetDate(new PdfDate(this.signerProperties.GetClaimedSignDate())); + DateTime claimedSignDate = this.signerProperties.GetClaimedSignDate(); + if (includeDate && claimedSignDate != TimestampConstants.UNDEFINED_TIMESTAMP_DATE) { + dic.SetDate(new PdfDate(claimedSignDate)); } // time-stamp will over-rule this return dic; @@ -1310,23 +1314,37 @@ private void SetContent() { } private SignedAppearanceText GenerateSignatureText() { - return new SignedAppearanceText().SetSignedBy(signerName).SetSignDate(this.signerProperties.GetClaimedSignDate - ()).SetReasonLine("Reason: " + this.signerProperties.GetReason()).SetLocationLine("Location: " + this. - signerProperties.GetLocation()); + SignedAppearanceText signedAppearanceText = new SignedAppearanceText(); + FillInAppearanceText(signedAppearanceText); + return signedAppearanceText; } private void PopulateExistingModelElement() { this.signerProperties.GetSignatureAppearance().SetSignerName(signerName); - SignedAppearanceText signedAppearanceText = this.signerProperties.GetSignatureAppearance().GetSignedAppearanceText + SignedAppearanceText appearanceText = this.signerProperties.GetSignatureAppearance().GetSignedAppearanceText (); - if (signedAppearanceText != null) { - signedAppearanceText.SetSignedBy(signerName).SetSignDate(this.signerProperties.GetClaimedSignDate()); - if (String.IsNullOrEmpty(signedAppearanceText.GetReasonLine())) { - signedAppearanceText.SetReasonLine("Reason: " + this.signerProperties.GetReason()); - } - if (String.IsNullOrEmpty(signedAppearanceText.GetLocationLine())) { - signedAppearanceText.SetLocationLine("Location: " + this.signerProperties.GetLocation()); - } + if (appearanceText != null) { + FillInAppearanceText(appearanceText); + } + } + + private void FillInAppearanceText(SignedAppearanceText appearanceText) { + appearanceText.SetSignedBy(signerName); + DateTime claimedSignDate = this.signerProperties.GetClaimedSignDate(); + if (claimedSignDate != TimestampConstants.UNDEFINED_TIMESTAMP_DATE) { + appearanceText.SetSignDate(claimedSignDate); + } + String reason = signerProperties.GetReason(); + bool setReason = appearanceText.GetReasonLine() != null && String.IsNullOrEmpty(appearanceText.GetReasonLine + ()); + if (setReason && reason != null && !String.IsNullOrEmpty(reason)) { + appearanceText.SetReasonLine("Reason: " + reason); + } + String location = signerProperties.GetLocation(); + bool setLocation = appearanceText.GetLocationLine() != null && String.IsNullOrEmpty(appearanceText.GetLocationLine + ()); + if (setLocation && location != null && !String.IsNullOrEmpty(location)) { + appearanceText.SetLocationLine("Location: " + location); } } diff --git a/itext/itext.sign/itext/signatures/SignerProperties.cs b/itext/itext.sign/itext/signatures/SignerProperties.cs index 23c786e6c3..adf97890e5 100644 --- a/itext/itext.sign/itext/signatures/SignerProperties.cs +++ b/itext/itext.sign/itext/signatures/SignerProperties.cs @@ -29,6 +29,13 @@ You should have received a copy of the GNU Affero General Public License namespace iText.Signatures { /// Properties to be used in signing operations. public class SignerProperties { + /// + /// This string could be used to create the + /// + /// instance which will be used for signing + /// since its ID will be ignored anyway in that case, and specified ID won't override the field name. + /// + /// public const String IGNORED_ID = ""; private PdfSigFieldLock fieldLock; diff --git a/port-hash b/port-hash index e5da40ac4b..a523416cfd 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -ad761fce7804db0efa8672f4fe236215a6c491d0 \ No newline at end of file +dc76524bdb9871dfcd4e2b6d156e42a653d2396d