Search in sources :

Example 11 with DigestCalculatorProvider

use of org.bouncycastle.operator.DigestCalculatorProvider in project ddf by codice.

the class OcspChecker method generateOcspRequest.

/**
 * Creates an {@link OCSPReq} to send to the OCSP server for the given certificate.
 *
 * @param cert - the certificate to verify
 * @return the created OCSP request
 * @throws OcspCheckerException after posting an alert to the admin console, if any error occurs
 */
@VisibleForTesting
OCSPReq generateOcspRequest(Certificate cert) throws OcspCheckerException {
    try {
        X509CertificateHolder issuerCert = resolveIssuerCertificate(cert);
        JcaDigestCalculatorProviderBuilder digestCalculatorProviderBuilder = new JcaDigestCalculatorProviderBuilder();
        DigestCalculatorProvider digestCalculatorProvider = digestCalculatorProviderBuilder.build();
        DigestCalculator digestCalculator = digestCalculatorProvider.get(CertificateID.HASH_SHA1);
        CertificateID certId = new CertificateID(digestCalculator, issuerCert, cert.getSerialNumber().getValue());
        OCSPReqBuilder ocspReqGenerator = new OCSPReqBuilder();
        ocspReqGenerator.addRequest(certId);
        return ocspReqGenerator.build();
    } catch (OCSPException | OperatorCreationException e) {
        throw new OcspCheckerException("Unable to create an OCSP request." + NOT_VERIFIED_MSG, e);
    }
}
Also used : DigestCalculatorProvider(org.bouncycastle.operator.DigestCalculatorProvider) CertificateID(org.bouncycastle.cert.ocsp.CertificateID) OCSPException(org.bouncycastle.cert.ocsp.OCSPException) X509CertificateHolder(org.bouncycastle.cert.X509CertificateHolder) DigestCalculator(org.bouncycastle.operator.DigestCalculator) JcaDigestCalculatorProviderBuilder(org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder) OperatorCreationException(org.bouncycastle.operator.OperatorCreationException) OCSPReqBuilder(org.bouncycastle.cert.ocsp.OCSPReqBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

DigestCalculatorProvider (org.bouncycastle.operator.DigestCalculatorProvider)11 JcaDigestCalculatorProviderBuilder (org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder)10 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)7 X509Certificate (java.security.cert.X509Certificate)5 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)5 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)5 ArrayList (java.util.ArrayList)4 JcaCertStore (org.bouncycastle.cert.jcajce.JcaCertStore)4 CMSProcessableByteArray (org.bouncycastle.cms.CMSProcessableByteArray)4 CMSSignedData (org.bouncycastle.cms.CMSSignedData)4 CMSSignedDataGenerator (org.bouncycastle.cms.CMSSignedDataGenerator)4 JcaSignerInfoGeneratorBuilder (org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder)4 ContentSigner (org.bouncycastle.operator.ContentSigner)4 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 SignerInfoGenerator (org.bouncycastle.cms.SignerInfoGenerator)3 DigestCalculator (org.bouncycastle.operator.DigestCalculator)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 MessageDigest (java.security.MessageDigest)2