public virtual void LtvEnabledTest01() { String tsaCertFileName = certsSrc + "tsCertRsa.p12"; String caCertFileName = certsSrc + "rootRsa.p12"; String srcFileName = sourceFolder + "signedDoc.pdf"; String ltvFileName = destinationFolder + "ltvEnabledTest01.pdf"; String ltvTsFileName = destinationFolder + "ltvEnabledTsTest01.pdf"; X509Certificate[] tsaChain = Pkcs12FileHelper.ReadFirstChain(tsaCertFileName, password); ICipherParameters tsaPrivateKey = Pkcs12FileHelper.ReadFirstKey(tsaCertFileName, password, password); X509Certificate caCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(caCertFileName, password)[0]; ICipherParameters caPrivateKey = Pkcs12FileHelper.ReadFirstKey(caCertFileName, password, password); TestTsaClient testTsa = new TestTsaClient(JavaUtil.ArraysAsList(tsaChain), tsaPrivateKey); TestOcspClient testOcspClient = new TestOcspClient().AddBuilderForCertIssuer(caCert, caPrivateKey); TestCrlClient testCrlClient = new TestCrlClient(caCert, caPrivateKey); PdfDocument document = new PdfDocument(new PdfReader(srcFileName), new PdfWriter(ltvFileName), new StampingProperties ().UseAppendMode()); LtvVerification ltvVerification = new LtvVerification(document); ltvVerification.AddVerification("Signature1", testOcspClient, testCrlClient, LtvVerification.CertificateOption .SIGNING_CERTIFICATE, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.YES); ltvVerification.Merge(); document.Close(); PdfSigner signer = new PdfSigner(new PdfReader(ltvFileName), new FileStream(ltvTsFileName, FileMode.Create ), new StampingProperties().UseAppendMode()); signer.Timestamp(testTsa, "timestampSig1"); BasicCheckLtvDoc("ltvEnabledTsTest01.pdf", "timestampSig1"); }
/// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/> /// <exception cref="System.IO.IOException"/> private bool VerifyTest(TestCrlBuilder crlBuilder) { String caCertFileName = certsSrc + "rootRsa.p12"; X509Certificate caCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(caCertFileName, password)[0]; ICipherParameters caPrivateKey = Pkcs12FileHelper.ReadFirstKey(caCertFileName, password, password); String checkCertFileName = certsSrc + "signCertRsa01.p12"; X509Certificate checkCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(checkCertFileName, password)[ 0]; TestCrlClient crlClient = new TestCrlClient(crlBuilder, caPrivateKey); ICollection <byte[]> crlBytesCollection = crlClient.GetEncoded(checkCert, null); bool verify = false; foreach (byte[] crlBytes in crlBytesCollection) { X509Crl crl = (X509Crl)SignTestPortUtil.ParseCrlFromStream(new MemoryStream(crlBytes)); CRLVerifier verifier = new CRLVerifier(null, null); verify = verifier.Verify(crl, checkCert, caCert, DateTimeUtil.GetCurrentUtcTime()); break; } return(verify); }
public virtual void AddLtvInfo() { String caCertFileName = certsSrc + "rootRsa.p12"; String interCertFileName = certsSrc + "intermediateRsa.p12"; String srcFileName = sourceFolder + "signedTwice.pdf"; String ltvFileName = destinationFolder + "ltvEnabledTest01.pdf"; String ltvFileName2 = destinationFolder + "ltvEnabledTest02.pdf"; X509Certificate caCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(caCertFileName, password)[0]; ICipherParameters caPrivateKey = Pkcs12FileHelper.ReadFirstKey(caCertFileName, password, password); X509Certificate interCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(interCertFileName, password)[ 0]; ICipherParameters interPrivateKey = Pkcs12FileHelper.ReadFirstKey(interCertFileName, password, password); TestOcspClient testOcspClient = new TestOcspClient().AddBuilderForCertIssuer(interCert, interPrivateKey).AddBuilderForCertIssuer (caCert, caPrivateKey); TestCrlClient testCrlClient = new TestCrlClient(caCert, caPrivateKey); AddLtvInfo(srcFileName, ltvFileName, "Signature1", testOcspClient, testCrlClient); AddLtvInfo(ltvFileName, ltvFileName2, "Signature2", testOcspClient, testCrlClient); PdfReader reader = new PdfReader(ltvFileName2); PdfDocument document = new PdfDocument(reader); PdfDictionary catalogDictionary = document.GetCatalog().GetPdfObject(); PdfDictionary dssDictionary = catalogDictionary.GetAsDictionary(PdfName.DSS); PdfDictionary vri = dssDictionary.GetAsDictionary(PdfName.VRI); NUnit.Framework.Assert.IsNotNull(vri); NUnit.Framework.Assert.AreEqual(2, vri.Size()); PdfArray ocsps = dssDictionary.GetAsArray(PdfName.OCSPs); NUnit.Framework.Assert.IsNotNull(ocsps); NUnit.Framework.Assert.AreEqual(5, ocsps.Size()); PdfArray certs = dssDictionary.GetAsArray(PdfName.Certs); NUnit.Framework.Assert.IsNotNull(certs); NUnit.Framework.Assert.AreEqual(5, certs.Size()); PdfArray crls = dssDictionary.GetAsArray(PdfName.CRLs); NUnit.Framework.Assert.IsNotNull(crls); NUnit.Framework.Assert.AreEqual(2, crls.Size()); }
public virtual void AddLtvInfo() { String tsaCertFileName = certsSrc + "tsCertRsa.p12"; String caCertFileName = certsSrc + "rootRsa.p12"; String srcFileName = sourceFolder + "signedDoc.pdf"; String ltvFileName = destinationFolder + "ltvEnabledTest01.pdf"; String ltvFileName2 = destinationFolder + "ltvEnabledTest02.pdf"; X509Certificate[] tsaChain = Pkcs12FileHelper.ReadFirstChain(tsaCertFileName, password); ICipherParameters tsaPrivateKey = Pkcs12FileHelper.ReadFirstKey(tsaCertFileName, password, password); X509Certificate caCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(caCertFileName, password)[0]; ICipherParameters caPrivateKey = Pkcs12FileHelper.ReadFirstKey(caCertFileName, password, password); TestTsaClient testTsa = new TestTsaClient(iText.IO.Util.JavaUtil.ArraysAsList(tsaChain), tsaPrivateKey); TestOcspClient testOcspClient = new TestOcspClient(caCert, caPrivateKey); TestCrlClient testCrlClient = new TestCrlClient(caCert, caPrivateKey); AddLtvInfo(srcFileName, ltvFileName, "sig", testOcspClient, testCrlClient); AddLtvInfo(ltvFileName, ltvFileName2, "sig2", testOcspClient, testCrlClient); PdfReader reader = new PdfReader(ltvFileName2); PdfDocument document = new PdfDocument(reader); PdfDictionary catalogDictionary = document.GetCatalog().GetPdfObject(); PdfDictionary dssDictionary = catalogDictionary.GetAsDictionary(PdfName.DSS); PdfDictionary vri = dssDictionary.GetAsDictionary(PdfName.VRI); NUnit.Framework.Assert.IsNotNull(vri); NUnit.Framework.Assert.AreEqual(2, vri.Size()); PdfArray ocsps = dssDictionary.GetAsArray(PdfName.OCSPs); NUnit.Framework.Assert.IsNotNull(ocsps); NUnit.Framework.Assert.AreEqual(2, ocsps.Size()); PdfArray certs = dssDictionary.GetAsArray(PdfName.Certs); NUnit.Framework.Assert.IsNotNull(certs); NUnit.Framework.Assert.AreEqual(2, certs.Size()); PdfArray crls = dssDictionary.GetAsArray(PdfName.CRLs); NUnit.Framework.Assert.IsNotNull(crls); NUnit.Framework.Assert.AreEqual(1, crls.Size()); }
public virtual void PadesSignatureLevelLTTest01() { String outFileName = destinationFolder + "padesSignatureLevelLTTest01.pdf"; String srcFileName = sourceFolder + "signedPAdES-T.pdf"; String tsaCertFileName = certsSrc + "tsCertRsa.p12"; String caCertFileName = certsSrc + "rootRsa.p12"; X509Certificate[] tsaChain = Pkcs12FileHelper.ReadFirstChain(tsaCertFileName, password); ICipherParameters tsaPrivateKey = Pkcs12FileHelper.ReadFirstKey(tsaCertFileName, password, password); X509Certificate caCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(caCertFileName, password)[0]; ICipherParameters caPrivateKey = Pkcs12FileHelper.ReadFirstKey(caCertFileName, password, password); ICrlClient crlClient = new TestCrlClient(caCert, caPrivateKey); TestOcspClient ocspClient = new TestOcspClient().AddBuilderForCertIssuer(caCert, caPrivateKey); TestTsaClient testTsa = new TestTsaClient(JavaUtil.ArraysAsList(tsaChain), tsaPrivateKey); PdfDocument document = new PdfDocument(new PdfReader(srcFileName), new PdfWriter(outFileName), new StampingProperties ().UseAppendMode()); LtvVerification ltvVerification = new LtvVerification(document); ltvVerification.AddVerification("Signature1", ocspClient, crlClient, LtvVerification.CertificateOption.SIGNING_CERTIFICATE , LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.YES); ltvVerification.Merge(); document.Close(); BasicCheckDssDict("padesSignatureLevelLTTest01.pdf"); }
private void AddLtvInfo(String src, String dest, String sigName, TestOcspClient testOcspClient, TestCrlClient testCrlClient) { PdfDocument document = new PdfDocument(new PdfReader(src), new PdfWriter(dest), new StampingProperties().UseAppendMode ()); LtvVerification ltvVerification = new LtvVerification(document); ltvVerification.AddVerification(sigName, testOcspClient, testCrlClient, LtvVerification.CertificateOption. WHOLE_CHAIN, LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.YES); ltvVerification.Merge(); document.Close(); }