Search in sources :

Example 11 with AttributeTypeAndValue

use of org.bouncycastle.asn1.crmf.AttributeTypeAndValue in project xipki by xipki.

the class SubjectChecker method getAtvValueString.

private static String getAtvValueString(String name, AttributeTypeAndValue atv, StringType stringType, StringBuilder failureMsg) {
    ASN1ObjectIdentifier type = atv.getType();
    ASN1Encodable atvValue = atv.getValue();
    if (ObjectIdentifiers.DN_DATE_OF_BIRTH.equals(type)) {
        if (!(atvValue instanceof ASN1GeneralizedTime)) {
            failureMsg.append(name).append(" is not of type GeneralizedTime; ");
            return null;
        }
        return ((ASN1GeneralizedTime) atvValue).getTimeString();
    } else if (ObjectIdentifiers.DN_POSTAL_ADDRESS.equals(type)) {
        if (!(atvValue instanceof ASN1Sequence)) {
            failureMsg.append(name).append(" is not of type Sequence; ");
            return null;
        }
        ASN1Sequence seq = (ASN1Sequence) atvValue;
        final int n = seq.size();
        StringBuilder sb = new StringBuilder();
        boolean validEncoding = true;
        for (int i = 0; i < n; i++) {
            ASN1Encodable obj = seq.getObjectAt(i);
            if (!matchStringType(obj, stringType)) {
                failureMsg.append(name).append(".[").append(i).append("] is not of type ").append(stringType.name()).append("; ");
                validEncoding = false;
                break;
            }
            String textValue = X509Util.rdnValueToString(obj);
            sb.append("[").append(i).append("]=").append(textValue).append(",");
        }
        if (!validEncoding) {
            return null;
        }
        return sb.toString();
    } else {
        if (!matchStringType(atvValue, stringType)) {
            failureMsg.append(name).append(" is not of type " + stringType.name()).append("; ");
            return null;
        }
        return X509Util.rdnValueToString(atvValue);
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1GeneralizedTime(org.bouncycastle.asn1.ASN1GeneralizedTime) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERT61String(org.bouncycastle.asn1.DERT61String) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 12 with AttributeTypeAndValue

use of org.bouncycastle.asn1.crmf.AttributeTypeAndValue in project keystore-explorer by kaikramer.

the class RdnPanelList method getRdns.

public List<RDN> getRdns(boolean noEmptyRdns) {
    List<RDN> rdns = new ArrayList<RDN>();
    for (RdnPanel rdnPanel : entries) {
        ASN1ObjectIdentifier attrType = OidDisplayNameMapping.getOidForDisplayName(rdnPanel.getAttributeName());
        if (noEmptyRdns && StringUtils.trimAndConvertEmptyToNull(rdnPanel.getAttributeValue()) == null) {
            continue;
        }
        ASN1Encodable attrValue = KseX500NameStyle.INSTANCE.stringToValue(attrType, rdnPanel.getAttributeValue());
        rdns.add(new RDN(new AttributeTypeAndValue(attrType, attrValue)));
    }
    return rdns;
}
Also used : ArrayList(java.util.ArrayList) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) RDN(org.bouncycastle.asn1.x500.RDN) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AttributeTypeAndValue(org.bouncycastle.asn1.x500.AttributeTypeAndValue)

Example 13 with AttributeTypeAndValue

use of org.bouncycastle.asn1.crmf.AttributeTypeAndValue in project xipki by xipki.

the class X509CmpRequestor method buildPkiMessage.

private PKIMessage buildPkiMessage(EnrollCertRequest req) {
    PKIHeader header = buildPkiHeader(implicitConfirm, null);
    List<EnrollCertRequestEntry> reqEntries = req.getRequestEntries();
    CertReqMsg[] certReqMsgs = new CertReqMsg[reqEntries.size()];
    for (int i = 0; i < reqEntries.size(); i++) {
        EnrollCertRequestEntry reqEntry = reqEntries.get(i);
        CmpUtf8Pairs utf8Pairs = new CmpUtf8Pairs(CmpUtf8Pairs.KEY_CERTPROFILE, reqEntry.getCertprofile());
        AttributeTypeAndValue certprofileInfo = CmpUtil.buildAttributeTypeAndValue(utf8Pairs);
        AttributeTypeAndValue[] atvs = (certprofileInfo == null) ? null : new AttributeTypeAndValue[] { certprofileInfo };
        certReqMsgs[i] = new CertReqMsg(reqEntry.getCertReq(), reqEntry.getPopo(), atvs);
    }
    int bodyType;
    switch(req.getType()) {
        case CERT_REQ:
            bodyType = PKIBody.TYPE_CERT_REQ;
            break;
        case KEY_UPDATE:
            bodyType = PKIBody.TYPE_KEY_UPDATE_REQ;
            break;
        default:
            bodyType = PKIBody.TYPE_CROSS_CERT_REQ;
    }
    PKIBody body = new PKIBody(bodyType, new CertReqMessages(certReqMsgs));
    return new PKIMessage(header, body);
}
Also used : PKIHeader(org.bouncycastle.asn1.cmp.PKIHeader) PKIMessage(org.bouncycastle.asn1.cmp.PKIMessage) PKIBody(org.bouncycastle.asn1.cmp.PKIBody) CertReqMessages(org.bouncycastle.asn1.crmf.CertReqMessages) CmpUtf8Pairs(org.xipki.cmp.CmpUtf8Pairs) CertReqMsg(org.bouncycastle.asn1.crmf.CertReqMsg) EnrollCertRequestEntry(org.xipki.ca.client.api.dto.EnrollCertRequestEntry) AttributeTypeAndValue(org.bouncycastle.asn1.crmf.AttributeTypeAndValue)

Example 14 with AttributeTypeAndValue

use of org.bouncycastle.asn1.crmf.AttributeTypeAndValue in project xipki by xipki.

the class X509CmpRequestor method buildPkiMessage.

// method buildPkiMessage
private PKIMessage buildPkiMessage(CertRequest req, ProofOfPossession pop, String profileName) {
    PKIHeader header = buildPkiHeader(implicitConfirm, null);
    CmpUtf8Pairs utf8Pairs = new CmpUtf8Pairs(CmpUtf8Pairs.KEY_CERTPROFILE, profileName);
    AttributeTypeAndValue certprofileInfo = CmpUtil.buildAttributeTypeAndValue(utf8Pairs);
    CertReqMsg[] certReqMsgs = new CertReqMsg[1];
    certReqMsgs[0] = new CertReqMsg(req, pop, new AttributeTypeAndValue[] { certprofileInfo });
    PKIBody body = new PKIBody(PKIBody.TYPE_CERT_REQ, new CertReqMessages(certReqMsgs));
    return new PKIMessage(header, body);
}
Also used : PKIHeader(org.bouncycastle.asn1.cmp.PKIHeader) PKIMessage(org.bouncycastle.asn1.cmp.PKIMessage) PKIBody(org.bouncycastle.asn1.cmp.PKIBody) CertReqMessages(org.bouncycastle.asn1.crmf.CertReqMessages) CmpUtf8Pairs(org.xipki.cmp.CmpUtf8Pairs) CertReqMsg(org.bouncycastle.asn1.crmf.CertReqMsg) AttributeTypeAndValue(org.bouncycastle.asn1.crmf.AttributeTypeAndValue)

Example 15 with AttributeTypeAndValue

use of org.bouncycastle.asn1.crmf.AttributeTypeAndValue in project jruby-openssl by jruby.

the class X509Name method fromRDNElement.

private void fromRDNElement(final RDN rdn) {
    final Ruby runtime = getRuntime();
    for (AttributeTypeAndValue tv : rdn.getTypesAndValues()) {
        oids.add(tv.getType());
        final ASN1Encodable val = tv.getValue();
        addValue(val);
        addType(runtime, val);
    }
}
Also used : ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) Ruby(org.jruby.Ruby) AttributeTypeAndValue(org.bouncycastle.asn1.x500.AttributeTypeAndValue)

Aggregations

AttributeTypeAndValue (org.bouncycastle.asn1.x500.AttributeTypeAndValue)13 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)12 RDN (org.bouncycastle.asn1.x500.RDN)12 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)8 DERIA5String (org.bouncycastle.asn1.DERIA5String)7 X500Name (org.bouncycastle.asn1.x500.X500Name)7 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)6 ASN1String (org.bouncycastle.asn1.ASN1String)6 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)6 DERUniversalString (org.bouncycastle.asn1.DERUniversalString)6 ArrayList (java.util.ArrayList)5 DERBMPString (org.bouncycastle.asn1.DERBMPString)4 LinkedList (java.util.LinkedList)3 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)3 DEROctetString (org.bouncycastle.asn1.DEROctetString)3 DERT61String (org.bouncycastle.asn1.DERT61String)3 PKIBody (org.bouncycastle.asn1.cmp.PKIBody)3 PKIMessage (org.bouncycastle.asn1.cmp.PKIMessage)3 AttributeTypeAndValue (org.bouncycastle.asn1.crmf.AttributeTypeAndValue)3 CertReqMessages (org.bouncycastle.asn1.crmf.CertReqMessages)3