org.bouncycastle.cert.cmp.CertificateConfirmationContentBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-lts8on Show documentation
Show all versions of bcpkix-lts8on Show documentation
The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.8 and up. The APIs are designed primarily to be used in conjunction with the BC LTS provider but may also be used with other providers providing cryptographic services.
package org.bouncycastle.cert.cmp;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.cmp.CMPCertificate;
import org.bouncycastle.asn1.cmp.CertConfirmContent;
import org.bouncycastle.asn1.cmp.CertStatus;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;
import org.bouncycastle.operator.DigestAlgorithmIdentifierFinder;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;
/**
* Builder class for a {@link CertConfirmContent} message.
*/
public class CertificateConfirmationContentBuilder
{
private DigestAlgorithmIdentifierFinder digestAlgFinder;
private List acceptedCerts = new ArrayList();
private List acceptedSignatureAlgorithms = new ArrayList();
private List acceptedReqIds = new ArrayList();
public CertificateConfirmationContentBuilder()
{
this(new DefaultDigestAlgorithmIdentifierFinder());
}
public CertificateConfirmationContentBuilder(DigestAlgorithmIdentifierFinder digestAlgFinder)
{
this.digestAlgFinder = digestAlgFinder;
}
public CertificateConfirmationContentBuilder addAcceptedCertificate(X509CertificateHolder certHolder, BigInteger certReqID)
{
return addAcceptedCertificate(certHolder, new ASN1Integer(certReqID));
}
public CertificateConfirmationContentBuilder addAcceptedCertificate(X509CertificateHolder certHolder, ASN1Integer certReqID)
{
return addAcceptedCertificate(new CMPCertificate(certHolder.toASN1Structure()), certHolder.getSignatureAlgorithm(), certReqID);
}
public CertificateConfirmationContentBuilder addAcceptedCertificate(CMPCertificate cmpCertificate, AlgorithmIdentifier sigAlg, ASN1Integer certReqID)
{
acceptedCerts.add(cmpCertificate);
acceptedSignatureAlgorithms.add(sigAlg);
acceptedReqIds.add(certReqID);
return this;
}
public CertificateConfirmationContent build(DigestCalculatorProvider digesterProvider)
throws CMPException
{
ASN1EncodableVector v = new ASN1EncodableVector(acceptedCerts.size());
for (int i = 0; i != acceptedCerts.size(); i++)
{
byte[] certHash = CMPUtil.calculateCertHash((CMPCertificate)acceptedCerts.get(i),
(AlgorithmIdentifier)acceptedSignatureAlgorithms.get(i), digesterProvider, digestAlgFinder);
ASN1Integer reqID = (ASN1Integer)acceptedReqIds.get(i);
v.add(new CertStatus(certHash, reqID));
}
CertConfirmContent content = CertConfirmContent.getInstance(new DERSequence(v));
return new CertificateConfirmationContent(content, digestAlgFinder);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy