Skip to content

Commit 00455b4

Browse files
committed
Merge branch 'develop' into devsecops
2 parents 550ea2e + fa35e9f commit 00455b4

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

itext.tests/itext.sign.tests/itext/signatures/CertificateInfoTest.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ You should have received a copy of the GNU Affero General Public License
2424
using System.Collections.Generic;
2525
using iText.Bouncycastleconnector;
2626
using iText.Commons.Bouncycastle;
27+
using iText.Commons.Bouncycastle.Asn1.X500;
28+
using iText.Commons.Bouncycastle.Cert;
2729
using iText.Commons.Utils;
2830
using iText.Kernel.Exceptions;
31+
using iText.Kernel.Pdf;
32+
using iText.Signatures.Testutils;
2933
using iText.Test;
3034

3135
namespace iText.Signatures {
@@ -36,6 +40,14 @@ public class CertificateInfoTest : ExtendedITextTest {
3640
private static readonly String EXPECTED_EXCEPTION_MESSAGE = FACTORY.GetBouncyCastleFactoryTestUtil().GetCertificateInfoTestConst
3741
();
3842

43+
private const String ENCODED_DN = "MD0xCzAJBgNVBAYMAkJFMQ4wDAYDVQQKDAVpVGV4dDEeMBwGA1UEAwwVaVRleHRUZXN0SW50ZXJtZWRpYXRl";
44+
45+
private static readonly String CERTS_SRC = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
46+
.CurrentContext.TestDirectory) + "/resources/itext/signatures/certs/";
47+
48+
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
49+
.CurrentContext.TestDirectory) + "/resources/itext/signatures" + "/CertificateInfoTest/";
50+
3951
[NUnit.Framework.Test]
4052
public virtual void X500InvalidDirectoryConstructorTest() {
4153
NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new CertificateInfo.X500Name("some_dir"));
@@ -86,5 +98,28 @@ public virtual void GetSubjectExceptionTest() {
8698
new byte[] { 4, 8, 15, 16, 23, 42 }));
8799
NUnit.Framework.Assert.AreEqual(EXPECTED_EXCEPTION_MESSAGE, exception.InnerException.Message);
88100
}
101+
102+
[NUnit.Framework.Test]
103+
public virtual void DistinguishedNameEncodingAndComparisonTest() {
104+
IX509Certificate cert = (IX509Certificate)PemFileHelper.ReadFirstChain(CERTS_SRC + "intermediate.pem")[0];
105+
IX500Name name = FACTORY.CreateX500Name(cert);
106+
IX500Name differentlyEncodedName = FACTORY.CreateX500Name(FACTORY.CreateASN1Sequence(Convert.FromBase64String
107+
(ENCODED_DN)));
108+
NUnit.Framework.Assert.IsTrue(differentlyEncodedName.Equals(name));
109+
NUnit.Framework.Assert.IsTrue(name.Equals(differentlyEncodedName));
110+
}
111+
112+
[NUnit.Framework.Test]
113+
public virtual void DistinguishedNameEncodingAndComparisonIntegrationTest() {
114+
NUnit.Framework.Assert.DoesNotThrow(() => {
115+
PdfDocument doc = new PdfDocument(new PdfReader(SOURCE_FOLDER + "signatureWithNameEncodingDifferences.pdf"
116+
));
117+
SignatureUtil signUtil = new SignatureUtil(doc);
118+
IList<String> signNames = signUtil.GetSignatureNames();
119+
PdfPKCS7 pkcs7 = signUtil.ReadSignatureData(signNames[0]);
120+
NUnit.Framework.Assert.IsNotNull(pkcs7);
121+
}
122+
);
123+
}
89124
}
90125
}

itext/itext.bouncy-castle-adapter/itext/bouncycastle/asn1/x509/X509NameBC.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,19 @@ public string GetName()
5656
{
5757
return GetX509Name().ToString();
5858
}
59+
60+
public override bool Equals(object o)
61+
{
62+
if (this == o)
63+
{
64+
return true;
65+
}
66+
if (o == null || !this.GetType().IsAssignableFrom(o.GetType()))
67+
{
68+
return false;
69+
}
70+
X509NameBC that = (X509NameBC)o;
71+
return GetX509Name().Equivalent(that.GetX509Name());
72+
}
5973
}
6074
}

itext/itext.bouncy-castle-fips-adapter/itext/bouncycastlefips/asn1/x500/X500NameBCFips.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ You should have received a copy of the GNU Affero General Public License
2323

2424
using iText.Commons.Bouncycastle.Asn1.X500;
2525
using Org.BouncyCastle.Asn1.X500;
26+
using System;
2627

2728
namespace iText.Bouncycastlefips.Asn1.X500 {
2829
/// <summary>
@@ -56,5 +57,19 @@ public string GetName()
5657
{
5758
return GetX500Name().ToString();
5859
}
60+
61+
public override bool Equals(object o)
62+
{
63+
if (this == o)
64+
{
65+
return true;
66+
}
67+
if (o == null || !this.GetType().IsAssignableFrom(o.GetType()))
68+
{
69+
return false;
70+
}
71+
X500NameBCFips that = (X500NameBCFips)o;
72+
return GetX500Name().Equivalent(that.GetX500Name());
73+
}
5974
}
6075
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0d8eb131608fed1576fd00603cfb4797f36a77fc
1+
a57dd49bf5d453f6e84783e27122aef1f9ceb483

0 commit comments

Comments
 (0)