Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Jan 29, 2025
2 parents 813da9f + 76dafd5 commit 8d64b57
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 45 deletions.
72 changes: 72 additions & 0 deletions itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,78 @@ public virtual void PdtIndirectReferenceLateInitializing3() {
document.Close();
}

[NUnit.Framework.Test]
public virtual void ContainsIndirectReference1Test() {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
PdfDictionary testDict = GetTestPdfDictionary();
NUnit.Framework.Assert.IsFalse(testDict.ContainsIndirectReference());
testDict.Get(new PdfName("b")).MakeIndirect(pdfDoc);
NUnit.Framework.Assert.IsTrue(testDict.ContainsIndirectReference());
}

[NUnit.Framework.Test]
public virtual void ContainsIndirectReference2Test() {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
PdfDictionary testDict = GetTestPdfDictionary();
PdfObject arrValue = new PdfName("arrValue");
PdfArray pdfArr = new PdfArray();
pdfArr.Add(arrValue);
testDict.Put(new PdfName("array"), pdfArr);
NUnit.Framework.Assert.IsFalse(testDict.ContainsIndirectReference());
arrValue.MakeIndirect(pdfDoc);
NUnit.Framework.Assert.IsTrue(testDict.ContainsIndirectReference());
}

[NUnit.Framework.Test]
public virtual void ContainsIndirectReferenceFlushedDictValueTest() {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
PdfDictionary testDict = GetTestPdfDictionary();
NUnit.Framework.Assert.IsFalse(testDict.ContainsIndirectReference());
testDict.Get(new PdfName("b")).MakeIndirect(pdfDoc).Flush();
NUnit.Framework.Assert.IsTrue(testDict.ContainsIndirectReference());
}

[NUnit.Framework.Test]
public virtual void ContainsIndirectReferenceFlushedArrayTest() {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
PdfDictionary testDict = GetTestPdfDictionary();
PdfObject arrValue = new PdfName("arrValue");
PdfArray pdfArr = new PdfArray();
pdfArr.Add(arrValue);
pdfArr.MakeIndirect(pdfDoc);
pdfArr.Flush();
testDict.Put(new PdfName("array"), pdfArr);
NUnit.Framework.Assert.IsTrue(testDict.ContainsIndirectReference());
}

[NUnit.Framework.Test]
public virtual void ContainsIndirectReferenceFlushedArrayValueTest() {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
PdfDictionary testDict = GetTestPdfDictionary();
PdfObject arrValue = new PdfName("arrValue");
PdfArray pdfArr = new PdfArray();
pdfArr.Add(arrValue);
arrValue.MakeIndirect(pdfDoc);
arrValue.Flush();
testDict.Put(new PdfName("array"), pdfArr);
NUnit.Framework.Assert.IsTrue(testDict.ContainsIndirectReference());
}

[NUnit.Framework.Test]
public virtual void ContainsIndirectReferenceFlushedArrayAndArrayValueTest() {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
PdfDictionary testDict = GetTestPdfDictionary();
PdfObject arrValue = new PdfName("arrValue");
PdfArray pdfArr = new PdfArray();
pdfArr.Add(arrValue);
arrValue.MakeIndirect(pdfDoc);
arrValue.Flush();
pdfArr.MakeIndirect(pdfDoc);
pdfArr.Flush();
testDict.Put(new PdfName("array"), pdfArr);
NUnit.Framework.Assert.IsTrue(testDict.ContainsIndirectReference());
}

private static PdfDictionary GetTestPdfDictionary() {
Dictionary<PdfName, PdfObject> tmpMap = new Dictionary<PdfName, PdfObject>();
tmpMap.Put(new PdfName("b"), new PdfName("c"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class LtvVerificationTest : ExtendedITextTest {

private const String SIG_FIELD_NAME = "Signature1";

private const String CRL_DISTRIBUTION_POINT = "http://example.com";
private const String CRL_DISTRIBUTION_POINT = "https://example.com";

private static readonly String CERT_FOLDER_PATH = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/signatures/certs/";
Expand Down Expand Up @@ -311,136 +311,136 @@ public virtual void ValidateSigNameWithoutCrlAndOcspWholeChainOcspCrlNoTest() {
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameSigningOcspCrlYesTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.SIGNING_CERTIFICATE
, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.YES, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameSigningOcspYesTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.SIGNING_CERTIFICATE
, LtvVerification.Level.OCSP, LtvVerification.CertificateInclusion.YES, false);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameSigningCrlYesTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.SIGNING_CERTIFICATE
, LtvVerification.Level.CRL, LtvVerification.CertificateInclusion.YES, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameSigningOcspOptionalCrlYesTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.SIGNING_CERTIFICATE
, LtvVerification.Level.OCSP_OPTIONAL_CRL, LtvVerification.CertificateInclusion.YES, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameSigningOcspCrlNoTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.SIGNING_CERTIFICATE
, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.NO, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameSigningOcspNoTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.SIGNING_CERTIFICATE
, LtvVerification.Level.OCSP, LtvVerification.CertificateInclusion.NO, false);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameSigningCrlNoTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.SIGNING_CERTIFICATE
, LtvVerification.Level.CRL, LtvVerification.CertificateInclusion.NO, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameSigningOcspOptionalCrlNoTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.SIGNING_CERTIFICATE
, LtvVerification.Level.OCSP_OPTIONAL_CRL, LtvVerification.CertificateInclusion.NO, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
public virtual void ValidateSigNameWholeChainOcspCrlYesTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level
.OCSP_CRL, LtvVerification.CertificateInclusion.YES, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
public virtual void ValidateSigNameWholeChainOcspOptionalCrlYesTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level
.OCSP_OPTIONAL_CRL, LtvVerification.CertificateInclusion.YES, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameWholeChainOcspYesTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level
.OCSP, LtvVerification.CertificateInclusion.YES, false);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
public virtual void ValidateSigNameWholeChainCrlYesTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level
.CRL, LtvVerification.CertificateInclusion.YES, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
public virtual void ValidateSigNameWholeChainOcspCrlNoTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level
.OCSP_CRL, LtvVerification.CertificateInclusion.NO, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
public virtual void ValidateSigNameWholeChainOcspOptionalCrlNoTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level
.OCSP_OPTIONAL_CRL, LtvVerification.CertificateInclusion.NO, true);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
public virtual void ValidateSigNameWholeChainOcspNoTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level
.OCSP, LtvVerification.CertificateInclusion.NO, false);
}

[NUnit.Framework.Test]
[LogMessage("Added CRL url: http://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: http://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL url: https://example.com", LogLevel = LogLevelConstants.INFO)]
[LogMessage("Checking CRL: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
[LogMessage("Added CRL found at: https://example.com", LogLevel = LogLevelConstants.INFO, Count = 2)]
public virtual void ValidateSigNameWholeChainCrlNoTest() {
ValidateOptionLevelInclusion(CRL_DISTRIBUTION_POINT, LtvVerification.CertificateOption.WHOLE_CHAIN, LtvVerification.Level
.CRL, LtvVerification.CertificateInclusion.NO, true);
Expand Down
33 changes: 33 additions & 0 deletions itext/itext.kernel/itext/kernel/pdf/PdfObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,39 @@ public virtual PdfIndirectReference GetIndirectReference() {
return indirectReference;
}

/// <summary>Checks recursively whether the object contains indirect reference at any level.</summary>
/// <returns>
///
/// <see langword="true"/>
/// if indirect reference was found,
/// <see langword="false"/>
/// otherwise
/// </returns>
public virtual bool ContainsIndirectReference() {
if (IsIndirect()) {
return true;
}
if (IsDictionary()) {
PdfDictionary dict = (PdfDictionary)this;
foreach (PdfObject value in dict.Values()) {
if (value.ContainsIndirectReference()) {
return true;
}
}
}
else {
if (IsArray()) {
PdfArray arr = (PdfArray)this;
foreach (PdfObject value in arr) {
if (value.ContainsIndirectReference()) {
return true;
}
}
}
}
return false;
}

/// <summary>Checks if object is indirect.</summary>
/// <remarks>
/// Checks if object is indirect.
Expand Down
6 changes: 3 additions & 3 deletions itext/itext.kernel/itext/kernel/pdf/canvas/PdfCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1993,11 +1993,11 @@ public virtual iText.Kernel.Pdf.Canvas.PdfCanvas BeginMarkedContent(PdfName tag,
@out.WriteBytes(BMC);
}
else {
if (properties.GetIndirectReference() == null) {
@out.Write(properties).WriteSpace().WriteBytes(BDC);
if (properties.ContainsIndirectReference()) {
@out.Write(resources.AddProperties(properties)).WriteSpace().WriteBytes(BDC);
}
else {
@out.Write(resources.AddProperties(properties)).WriteSpace().WriteBytes(BDC);
@out.Write(properties).WriteSpace().WriteBytes(BDC);
}
}
Tuple2<PdfName, PdfDictionary> tuple2 = new Tuple2<PdfName, PdfDictionary>(tag, properties);
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8f1e347bd9ef1440d106ae7e1e6debf166387a75
f30448605fa9dd1829b16011c3962f1aba3233cf

0 comments on commit 8d64b57

Please sign in to comment.