@@ -42,9 +42,16 @@ source product.
42
42
*/
43
43
using System ;
44
44
using System . Collections . Generic ;
45
+ using Org . BouncyCastle . Asn1 ;
46
+ using Org . BouncyCastle . Asn1 . Cms ;
47
+ using Org . BouncyCastle . Crypto ;
48
+ using Org . BouncyCastle . Tsp ;
45
49
using Org . BouncyCastle . X509 ;
50
+ using iText . Commons . Utils ;
46
51
using iText . Signatures ;
52
+ using iText . Signatures . Testutils . Client ;
47
53
using iText . Test ;
54
+ using iText . Test . Attributes ;
48
55
using iText . Test . Signutils ;
49
56
50
57
namespace iText . Signatures . Verify {
@@ -72,5 +79,39 @@ public virtual void ValidCertificateChain01() {
72
79
, caKeyStore ) ;
73
80
NUnit . Framework . Assert . IsTrue ( verificationExceptions . IsEmpty ( ) ) ;
74
81
}
82
+
83
+ [ NUnit . Framework . Test ]
84
+ public virtual void TimestampCertificateAndKeyStoreCorrespondTest ( ) {
85
+ String tsaCertFileName = certsSrc + "tsCertRsa.p12" ;
86
+ List < X509Certificate > caKeyStore = Pkcs12FileHelper . InitStore ( tsaCertFileName , password ) ;
87
+ NUnit . Framework . Assert . IsTrue ( VerifyTimestampCertificates ( tsaCertFileName , caKeyStore ) ) ;
88
+ }
89
+
90
+ [ NUnit . Framework . Test ]
91
+ [ LogMessage ( "certificate hash does not match certID hash." ) ]
92
+ public virtual void TimestampCertificateAndKeyStoreDoNotCorrespondTest ( ) {
93
+ String tsaCertFileName = certsSrc + "tsCertRsa.p12" ;
94
+ String notTsaCertFileName = certsSrc + "rootRsa.p12" ;
95
+ List < X509Certificate > caKeyStore = Pkcs12FileHelper . InitStore ( notTsaCertFileName , password ) ;
96
+ NUnit . Framework . Assert . IsFalse ( VerifyTimestampCertificates ( tsaCertFileName , caKeyStore ) ) ;
97
+ }
98
+
99
+ [ NUnit . Framework . Test ]
100
+ [ LogMessage ( "Unexpected exception was thrown during keystore processing" ) ]
101
+ public virtual void KeyStoreWithoutCertificatesTest ( ) {
102
+ String tsaCertFileName = certsSrc + "tsCertRsa.p12" ;
103
+ NUnit . Framework . Assert . IsFalse ( VerifyTimestampCertificates ( tsaCertFileName , null ) ) ;
104
+ }
105
+
106
+ private static bool VerifyTimestampCertificates ( String tsaClientCertificate , List < X509Certificate > caKeyStore
107
+ ) {
108
+ X509Certificate [ ] tsaChain = Pkcs12FileHelper . ReadFirstChain ( tsaClientCertificate , password ) ;
109
+ ICipherParameters tsaPrivateKey = Pkcs12FileHelper . ReadFirstKey ( tsaClientCertificate , password , password ) ;
110
+ TestTsaClient testTsaClient = new TestTsaClient ( JavaUtil . ArraysAsList ( tsaChain ) , tsaPrivateKey ) ;
111
+ byte [ ] tsaCertificateBytes = testTsaClient . GetTimeStampToken ( testTsaClient . GetMessageDigest ( ) . Digest ( ) ) ;
112
+ TimeStampToken timeStampToken = new TimeStampToken ( ContentInfo . GetInstance ( Asn1Sequence . GetInstance ( tsaCertificateBytes
113
+ ) ) ) ;
114
+ return CertificateVerification . VerifyTimestampCertificates ( timeStampToken , caKeyStore ) ;
115
+ }
75
116
}
76
117
}
0 commit comments