forked from pipeline-foundation/itext7-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into devsecops
- Loading branch information
Showing
8 changed files
with
228 additions
and
28 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
itext.tests/itext.kernel.tests/itext/kernel/actions/events/AddFingerPrintEventTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
This file is part of the iText (R) project. | ||
Copyright (c) 1998-2024 Apryse Group NV | ||
Authors: Apryse Software. | ||
This program is offered under a commercial and under the AGPL license. | ||
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. | ||
AGPL licensing: | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
using iText.Commons.Actions.Data; | ||
using iText.IO.Source; | ||
using iText.Kernel.Logs; | ||
using iText.Kernel.Pdf; | ||
using iText.Test; | ||
using iText.Test.Attributes; | ||
|
||
namespace iText.Kernel.Actions.Events { | ||
[NUnit.Framework.Category("UnitTest")] | ||
public class AddFingerPrintEventTest : ExtendedITextTest { | ||
[NUnit.Framework.Test] | ||
public virtual void NullDocumentTest() { | ||
AddFingerPrintEvent addFingerPrintEvent = new AddFingerPrintEvent(null); | ||
NUnit.Framework.Assert.DoesNotThrow(() => addFingerPrintEvent.DoAction()); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
[LogMessage(KernelLogMessageConstant.FINGERPRINT_DISABLED_BUT_NO_REQUIRED_LICENCE)] | ||
public virtual void DisableFingerPrintAGPLTest() { | ||
using (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { | ||
using (PdfDocument doc = new PdfDocument(new PdfWriter(outputStream))) { | ||
doc.GetFingerPrint().DisableFingerPrint(); | ||
NUnit.Framework.Assert.DoesNotThrow(() => doc.Close()); | ||
} | ||
} | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void EnabledFingerPrintAGPLTest() { | ||
using (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { | ||
using (PdfDocument doc = new PdfDocument(new PdfWriter(outputStream))) { | ||
NUnit.Framework.Assert.DoesNotThrow(() => doc.Close()); | ||
} | ||
} | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void DisableFingerPrintNoProcessorForProductTest() { | ||
using (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { | ||
using (PdfDocument doc = new PdfDocument(new PdfWriter(outputStream))) { | ||
ProductData productData = new ProductData("public product name", "product name", "1", 2000, 2024); | ||
doc.GetFingerPrint().RegisterProduct(productData); | ||
NUnit.Framework.Assert.DoesNotThrow(() => doc.Close()); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
itext/itext.kernel/itext/kernel/actions/events/AddFingerPrintEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
This file is part of the iText (R) project. | ||
Copyright (c) 1998-2024 Apryse Group NV | ||
Authors: Apryse Software. | ||
This program is offered under a commercial and under the AGPL license. | ||
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. | ||
AGPL licensing: | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Logging; | ||
using iText.Commons; | ||
using iText.Commons.Actions; | ||
using iText.Commons.Actions.Data; | ||
using iText.Commons.Actions.Processors; | ||
using iText.Commons.Utils; | ||
using iText.Kernel.Actions.Data; | ||
using iText.Kernel.Logs; | ||
using iText.Kernel.Pdf; | ||
|
||
namespace iText.Kernel.Actions.Events { | ||
/// <summary>This class is responsible for adding a fingerprint.</summary> | ||
public sealed class AddFingerPrintEvent : AbstractITextConfigurationEvent { | ||
private readonly WeakReference document; | ||
|
||
private static readonly ILogger LOGGER = ITextLogManager.GetLogger(typeof(iText.Kernel.Actions.Events.AddFingerPrintEvent | ||
)); | ||
|
||
private const String AGPL_MODE = "AGPL"; | ||
|
||
/// <summary>Creates a new instance of the AddFingerPrintEvent.</summary> | ||
/// <param name="document">document in which the fingerprint will be added</param> | ||
public AddFingerPrintEvent(PdfDocument document) | ||
: base() { | ||
this.document = new WeakReference(document); | ||
} | ||
|
||
/// <summary>Adds fingerprint to the document.</summary> | ||
protected internal override void DoAction() { | ||
PdfDocument pdfDocument = (PdfDocument)document.Target; | ||
if (pdfDocument == null) { | ||
return; | ||
} | ||
FingerPrint fingerPrint = pdfDocument.GetFingerPrint(); | ||
ICollection<ProductData> products = fingerPrint.GetProducts(); | ||
//if fingerprint is disabled and all licence types isn't AGPL then no actions required | ||
if (!fingerPrint.IsFingerPrintEnabled()) { | ||
bool nonAGPLMode = true; | ||
foreach (ProductData productData in products) { | ||
ITextProductEventProcessor processor = GetActiveProcessor(productData.GetProductName()); | ||
if (processor == null) { | ||
continue; | ||
} | ||
if (AGPL_MODE.Equals(processor.GetUsageType())) { | ||
nonAGPLMode = false; | ||
break; | ||
} | ||
} | ||
if (nonAGPLMode) { | ||
return; | ||
} | ||
LOGGER.LogWarning(KernelLogMessageConstant.FINGERPRINT_DISABLED_BUT_NO_REQUIRED_LICENCE); | ||
} | ||
PdfWriter writer = pdfDocument.GetWriter(); | ||
if (products.IsEmpty()) { | ||
writer.WriteString(MessageFormatUtil.Format("%iText-{0}-no-registered-products\n", ITextCoreProductData.GetInstance | ||
().GetVersion())); | ||
return; | ||
} | ||
foreach (ProductData productData in products) { | ||
writer.WriteString(MessageFormatUtil.Format("%iText-{0}-{1}\n", productData.GetPublicProductName(), productData | ||
.GetVersion())); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
d5b02fbcfb969e96fbe636524ab8f440426f99d7 | ||
c3c3b73f49c22e127f2047cf7b76862df3a75d75 |