@@ -24,8 +24,12 @@ You should have received a copy of the GNU Affero General Public License
2424using System . Collections . Generic ;
2525using iText . Bouncycastleconnector ;
2626using iText . Commons . Bouncycastle ;
27+ using iText . Commons . Bouncycastle . Asn1 . X500 ;
28+ using iText . Commons . Bouncycastle . Cert ;
2729using iText . Commons . Utils ;
2830using iText . Kernel . Exceptions ;
31+ using iText . Kernel . Pdf ;
32+ using iText . Signatures . Testutils ;
2933using iText . Test ;
3034
3135namespace 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}
0 commit comments