Пример #1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.BouncyCastle.Operator.OperatorCreationException"/>
        /// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/>
        public virtual bool VerifyAuthorizedOCSPResponderTest(DateTime ocspResponderCertStartDate, DateTime ocspResponderCertEndDate
                                                              , DateTime checkDate)
        {
            X509Certificate caCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(certsSrc + "intermediateRsa.p12"
                                                                                      , password)[0];
            ICipherParameters caPrivateKey = Pkcs12FileHelper.ReadFirstKey(certsSrc + "intermediateRsa.p12", password,
                                                                           password);
            String          checkCertFileName = certsSrc + "signCertRsaWithChain.p12";
            X509Certificate checkCert         = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(checkCertFileName, password)[
                0];
            RsaKeyPairGenerator     keyGen             = SignTestPortUtil.BuildRSA2048KeyPairGenerator();
            AsymmetricCipherKeyPair key                = keyGen.GenerateKeyPair();
            ICipherParameters       ocspRespPrivateKey = key.Private;
            AsymmetricKeyParameter  ocspRespPublicKey  = key.Public;
            TestCertificateBuilder  certBuilder        = new TestCertificateBuilder(ocspRespPublicKey, caCert, caPrivateKey, "CN=iTextTestOCSPResponder, OU=test, O=iText"
                                                                                    );

            certBuilder.SetStartDate(ocspResponderCertStartDate);
            certBuilder.SetEndDate(ocspResponderCertEndDate);
            X509Certificate         ocspResponderCert = certBuilder.BuildAuthorizedOCSPResponderCert();
            TestOcspResponseBuilder builder           = new TestOcspResponseBuilder(ocspResponderCert, ocspRespPrivateKey);
            TestOcspClient          ocspClient        = new TestOcspClient().AddBuilderForCertIssuer(caCert, builder);

            byte[]        basicOcspRespBytes = ocspClient.GetEncoded(checkCert, caCert, null);
            Asn1Object    var2          = Asn1Object.FromByteArray(basicOcspRespBytes);
            BasicOcspResp basicOCSPResp = new BasicOcspResp(BasicOcspResponse.GetInstance(var2));
            OCSPVerifier  ocspVerifier  = new OCSPVerifier(null, null);

            return(ocspVerifier.Verify(basicOCSPResp, checkCert, caCert, checkDate));
        }
Пример #2
0
        private void CheckRevocation(PdfPKCS7 pkcs7, X509Certificate signCert, X509Certificate issuerCert,
                                     DateTime date)
        {
            IList <BasicOcspResp> ocsps = new List <BasicOcspResp>();

            if (pkcs7.GetOcsp() != null)
            {
                ocsps.Add(pkcs7.GetOcsp());
            }

            OCSPVerifier           ocspVerifier = new OCSPVerifier(null, ocsps);
            IList <VerificationOK> verification = ocspVerifier.Verify(signCert, issuerCert, date);

            if (verification.Count == 0)
            {
                IList <X509Crl> crls = new List <X509Crl>();
                if (pkcs7.GetCRLs() != null)
                {
                    foreach (X509Crl crl in pkcs7.GetCRLs())
                    {
                        crls.Add((X509Crl)crl);
                    }
                }

                CRLVerifier crlVerifier = new CRLVerifier(null, crls);
                var         verOks      = crlVerifier.Verify(signCert, issuerCert, date);
                foreach (VerificationOK verOk in verOks)
                {
                    verification.Add(verOk);
                }
            }
        }
Пример #3
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/>
        private bool VerifyTest(TestOcspResponseBuilder rootRsaOcspBuilder, String checkCertFileName, DateTime checkDate
                                )
        {
            X509Certificate checkCert = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(checkCertFileName, password)[
                0];
            X509Certificate rootCert   = rootRsaOcspBuilder.GetIssuerCert();
            TestOcspClient  ocspClient = new TestOcspClient().AddBuilderForCertIssuer(rootCert, rootRsaOcspBuilder);

            byte[]        basicOcspRespBytes = ocspClient.GetEncoded(checkCert, rootCert, null);
            Asn1Object    var2          = Asn1Object.FromByteArray(basicOcspRespBytes);
            BasicOcspResp basicOCSPResp = new BasicOcspResp(BasicOcspResponse.GetInstance(var2));
            OCSPVerifier  ocspVerifier  = new OCSPVerifier(null, null);

            return(ocspVerifier.Verify(basicOCSPResp, checkCert, rootCert, checkDate));
        }
        private static void CheckRevocation(PdfPKCS7 pkcs7, X509Certificate signCert, X509Certificate issuerCert,
                                            DateTime date)
        {
            IList <BasicOcspResp> ocsps = new List <BasicOcspResp>();

            if (pkcs7.GetOcsp() != null)
            {
                ocsps.Add(pkcs7.GetOcsp());
            }

            // Check if the OCSP responses in the list were valid for the certificate on a specific date.
            OCSPVerifier           ocspVerifier = new OCSPVerifier(null, ocsps);
            IList <VerificationOK> verification = ocspVerifier.Verify(signCert, issuerCert, date);

            // If that list is empty, we can’t verify using OCSP, and we need to look for CRLs.
            if (verification.Count == 0)
            {
                IList <X509Crl> crls = new List <X509Crl>();
                if (pkcs7.GetCRLs() != null)
                {
                    foreach (X509Crl crl in pkcs7.GetCRLs())
                    {
                        crls.Add((X509Crl)crl);
                    }
                }

                // Check if the CRLs in the list were valid on a specific date.
                CRLVerifier            crlVerifier     = new CRLVerifier(null, crls);
                IList <VerificationOK> verificationOks = crlVerifier.Verify(signCert, issuerCert, date);
                foreach (VerificationOK verOK in verificationOks)
                {
                    verification.Add(verOK);
                }
            }

            if (verification.Count == 0)
            {
                OUT_STREAM.WriteLine("The signing certificate couldn't be verified");
            }
            else
            {
                foreach (VerificationOK v in verification)
                {
                    OUT_STREAM.WriteLine(v);
                }
            }
        }
Пример #5
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/>
        private bool VerifyTest(TestOcspResponseBuilder builder)
        {
            String            caCertFileName    = certsSrc + "rootRsa.p12";
            String            checkCertFileName = certsSrc + "signCertRsa01.p12";
            X509Certificate   caCert            = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(caCertFileName, password)[0];
            ICipherParameters caPrivateKey      = Pkcs12FileHelper.ReadFirstKey(caCertFileName, password, password);
            X509Certificate   checkCert         = (X509Certificate)Pkcs12FileHelper.ReadFirstChain(checkCertFileName, password)[
                0];
            TestOcspClient ocspClient = new TestOcspClient(builder, caPrivateKey);

            byte[]        basicOcspRespBytes = ocspClient.GetEncoded(checkCert, caCert, null);
            Asn1Object    var2          = Asn1Object.FromByteArray(basicOcspRespBytes);
            BasicOcspResp basicOCSPResp = new BasicOcspResp(BasicOcspResponse.GetInstance(var2));
            OCSPVerifier  ocspVerifier  = new OCSPVerifier(null, null);

            return(ocspVerifier.Verify(basicOCSPResp, checkCert, caCert, DateTimeUtil.GetCurrentUtcTime()));
        }