Search in sources :

Example 6 with CertRequest

use of com.github.zhenwei.pkix.util.asn1.crmf.CertRequest in project LinLong-Java by zhenwei1108.

the class CertificateRequestMessageBuilder method build.

public CertificateRequestMessage build() throws CRMFException {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(new ASN1Integer(certReqId));
    if (!extGenerator.isEmpty()) {
        templateBuilder.setExtensions(extGenerator.generate());
    }
    v.add(templateBuilder.build());
    if (!controls.isEmpty()) {
        ASN1EncodableVector controlV = new ASN1EncodableVector();
        for (Iterator it = controls.iterator(); it.hasNext(); ) {
            Control control = (Control) it.next();
            controlV.add(new AttributeTypeAndValue(control.getType(), control.getValue()));
        }
        v.add(new DERSequence(controlV));
    }
    CertRequest request = CertRequest.getInstance(new DERSequence(v));
    v = new ASN1EncodableVector();
    v.add(request);
    if (popSigner != null) {
        CertTemplate template = request.getCertTemplate();
        if (template.getSubject() == null || template.getPublicKey() == null) {
            SubjectPublicKeyInfo pubKeyInfo = request.getCertTemplate().getPublicKey();
            ProofOfPossessionSigningKeyBuilder builder = new ProofOfPossessionSigningKeyBuilder(pubKeyInfo);
            if (sender != null) {
                builder.setSender(sender);
            } else {
                PKMACValueGenerator pkmacGenerator = new PKMACValueGenerator(pkmacBuilder);
                builder.setPublicKeyMac(pkmacGenerator, password);
            }
            v.add(new ProofOfPossession(builder.build(popSigner)));
        } else {
            ProofOfPossessionSigningKeyBuilder builder = new ProofOfPossessionSigningKeyBuilder(request);
            v.add(new ProofOfPossession(builder.build(popSigner)));
        }
    } else if (popoPrivKey != null) {
        v.add(new ProofOfPossession(popoType, popoPrivKey));
    } else if (agreeMAC != null) {
        v.add(new ProofOfPossession(ProofOfPossession.TYPE_KEY_AGREEMENT, POPOPrivKey.getInstance(new DERTaggedObject(false, POPOPrivKey.agreeMAC, agreeMAC))));
    } else if (popRaVerified != null) {
        v.add(new ProofOfPossession());
    }
    return new CertificateRequestMessage(CertReqMsg.getInstance(new DERSequence(v)));
}
Also used : DERTaggedObject(com.github.zhenwei.core.asn1.DERTaggedObject) ProofOfPossession(com.github.zhenwei.pkix.util.asn1.crmf.ProofOfPossession) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) SubjectPublicKeyInfo(com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo) AttributeTypeAndValue(com.github.zhenwei.pkix.util.asn1.crmf.AttributeTypeAndValue) DERSequence(com.github.zhenwei.core.asn1.DERSequence) CertRequest(com.github.zhenwei.pkix.util.asn1.crmf.CertRequest) Iterator(java.util.Iterator) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) CertTemplate(com.github.zhenwei.pkix.util.asn1.crmf.CertTemplate)

Aggregations

CertRequest (org.bouncycastle.asn1.crmf.CertRequest)4 CertTemplateBuilder (org.bouncycastle.asn1.crmf.CertTemplateBuilder)4 EnrollCertRequest (org.xipki.ca.client.api.dto.EnrollCertRequest)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CertTemplate (org.bouncycastle.asn1.crmf.CertTemplate)2 POPOSigningKey (org.bouncycastle.asn1.crmf.POPOSigningKey)2 ProofOfPossession (org.bouncycastle.asn1.crmf.ProofOfPossession)2 X500Name (org.bouncycastle.asn1.x500.X500Name)2 ProofOfPossessionSigningKeyBuilder (org.bouncycastle.cert.crmf.ProofOfPossessionSigningKeyBuilder)2 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)1 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)1 DERBitString (com.github.zhenwei.core.asn1.DERBitString)1 DERSequence (com.github.zhenwei.core.asn1.DERSequence)1 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)1 SubjectPublicKeyInfo (com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo)1 AttributeTypeAndValue (com.github.zhenwei.pkix.util.asn1.crmf.AttributeTypeAndValue)1 CertRequest (com.github.zhenwei.pkix.util.asn1.crmf.CertRequest)1 CertTemplate (com.github.zhenwei.pkix.util.asn1.crmf.CertTemplate)1 POPOSigningKey (com.github.zhenwei.pkix.util.asn1.crmf.POPOSigningKey)1