Example usage for org.bouncycastle.asn1.isismtt.x509 Admissions Admissions

List of usage examples for org.bouncycastle.asn1.isismtt.x509 Admissions Admissions

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.isismtt.x509 Admissions Admissions.

Prototype

public Admissions(GeneralName admissionAuthority, NamingAuthority namingAuthority,
        ProfessionInfo[] professionInfos) 

Source Link

Document

Constructor from a given details.

Usage

From source file:org.xipki.ca.certprofile.XmlX509Certprofile.java

License:Open Source License

private ExtensionValue createAdmission(final boolean critical, final List<ASN1ObjectIdentifier> professionOIDs,
        final List<String> professionItems, final String registrationNumber, final byte[] addProfessionInfo)
        throws CertprofileException {
    if (CollectionUtil.isEmpty(professionItems) && CollectionUtil.isEmpty(professionOIDs)
            && StringUtil.isBlank(registrationNumber)
            && (addProfessionInfo == null || addProfessionInfo.length == 0)) {
        return null;
    }/*www . j  av a2 s  .  com*/

    DirectoryString[] _professionItems = null;
    if (professionItems != null && professionItems.size() > 0) {
        int n = professionItems.size();
        _professionItems = new DirectoryString[n];
        for (int i = 0; i < n; i++) {
            _professionItems[i] = new DirectoryString(professionItems.get(i));
        }
    }

    ASN1ObjectIdentifier[] _professionOIDs = null;
    if (professionOIDs != null && professionOIDs.size() > 0) {
        _professionOIDs = professionOIDs.toArray(new ASN1ObjectIdentifier[0]);
    }

    ASN1OctetString _addProfessionInfo = null;
    if (addProfessionInfo != null && addProfessionInfo.length > 0) {
        _addProfessionInfo = new DEROctetString(addProfessionInfo);
    }

    ProfessionInfo professionInfo = new ProfessionInfo(null, _professionItems, _professionOIDs,
            registrationNumber, _addProfessionInfo);

    Admissions admissions = new Admissions(null, null, new ProfessionInfo[] { professionInfo });

    ASN1EncodableVector vector = new ASN1EncodableVector();
    vector.add(admissions);

    AdmissionSyntax value = new AdmissionSyntax(null, new DERSequence(vector));
    return new ExtensionValue(critical, value);
}

From source file:org.xipki.commons.security.shell.p12.P12ComplexCertRequestGenCmd.java

License:Open Source License

@Override
protected List<Extension> getAdditionalExtensions() throws BadInputException {
    List<Extension> extensions = new LinkedList<>();

    // extension admission (Germany standard commonpki)
    ASN1EncodableVector vec = new ASN1EncodableVector();

    DirectoryString[] dummyItems = new DirectoryString[] { new DirectoryString("dummy") };
    ProfessionInfo pi = new ProfessionInfo(null, dummyItems, null, "aaaab", null);
    Admissions admissions = new Admissions(null, null, new ProfessionInfo[] { pi });
    vec.add(admissions);/*from w  ww.  j a  v a 2s .  c  o m*/

    AdmissionSyntax adSyn = new AdmissionSyntax(null, new DERSequence(vec));

    try {
        extensions.add(new Extension(ObjectIdentifiers.id_extension_admission, false, adSyn.getEncoded()));
    } catch (IOException ex) {
        throw new BadInputException(ex.getMessage(), ex);
    }

    // extension subjectDirectoryAttributes (RFC 3739)
    Vector<Attribute> attrs = new Vector<>();
    ASN1GeneralizedTime dateOfBirth = new ASN1GeneralizedTime("19800122120000Z");
    attrs.add(new Attribute(ObjectIdentifiers.DN_DATE_OF_BIRTH, new DERSet(dateOfBirth)));

    DERPrintableString gender = new DERPrintableString("M");
    attrs.add(new Attribute(ObjectIdentifiers.DN_GENDER, new DERSet(gender)));

    DERUTF8String placeOfBirth = new DERUTF8String("Berlin");
    attrs.add(new Attribute(ObjectIdentifiers.DN_PLACE_OF_BIRTH, new DERSet(placeOfBirth)));

    String[] countryOfCitizenshipList = new String[] { "DE", "FR" };
    for (String country : countryOfCitizenshipList) {
        DERPrintableString val = new DERPrintableString(country);
        attrs.add(new Attribute(ObjectIdentifiers.DN_COUNTRY_OF_CITIZENSHIP, new DERSet(val)));
    }

    String[] countryOfResidenceList = new String[] { "DE" };
    for (String country : countryOfResidenceList) {
        DERPrintableString val = new DERPrintableString(country);
        attrs.add(new Attribute(ObjectIdentifiers.DN_COUNTRY_OF_RESIDENCE, new DERSet(val)));
    }

    SubjectDirectoryAttributes subjectDirAttrs = new SubjectDirectoryAttributes(attrs);
    try {
        extensions
                .add(new Extension(Extension.subjectDirectoryAttributes, false, subjectDirAttrs.getEncoded()));
    } catch (IOException ex) {
        throw new BadInputException(ex.getMessage(), ex);
    }

    return extensions;
}

From source file:org.xipki.pki.ca.certprofile.commonpki.AdmissionSyntaxOption.java

License:Open Source License

public AdmissionSyntaxOption(final boolean critical, final GeneralName admissionAuthority,
        final List<AdmissionsOption> admissionsList) {
    this.critical = critical;
    this.admissionAuthority = admissionAuthority;
    this.admissionsList = ParamUtil.requireNonEmpty("admissionsList", admissionsList);

    boolean bo = false;
    for (AdmissionsOption ao : admissionsList) {
        for (ProfessionInfoOption pio : ao.getProfessionInfos()) {
            if (pio.getRegistrationNumberOption() != null
                    && pio.getRegistrationNumberOption().getRegex() != null) {
                bo = true;/* w ww  . j  a  v  a  2  s. c o  m*/
                break;
            }
        }
        if (bo) {
            break;
        }
    }
    this.inputFromRequestRequired = bo;
    if (this.inputFromRequestRequired) {
        extensionValue = null;
        return;
    }

    ASN1EncodableVector vec = new ASN1EncodableVector();
    for (AdmissionsOption ao : admissionsList) {
        List<ProfessionInfoOption> piList = ao.getProfessionInfos();
        ProfessionInfo[] pis = new ProfessionInfo[piList.size()];

        for (int i = 0; i < pis.length; i++) {
            ProfessionInfoOption pio = piList.get(i);
            DirectoryString[] professionItems = null;
            int size = pio.getProfessionItems().size();
            professionItems = new DirectoryString[size];
            for (int j = 0; j < size; j++) {
                professionItems[j] = new DirectoryString(pio.getProfessionItems().get(j));
            }

            ASN1OctetString addProfessionInfo = null;
            if (pio.getAddProfessionalInfo() != null) {
                addProfessionInfo = new DEROctetString(pio.getAddProfessionalInfo());
            }

            String registrationNumber = null;
            if (pio.getRegistrationNumberOption() != null) {
                registrationNumber = pio.getRegistrationNumberOption().getConstant();
            }
            pis[i] = new ProfessionInfo(pio.getNamingAuthority(), professionItems,
                    pio.getProfessionOids().toArray(new ASN1ObjectIdentifier[0]), registrationNumber,
                    addProfessionInfo);
        }

        vec.add(new Admissions(ao.getAdmissionAuthority(), ao.getNamingAuthority(), pis));
    }

    extensionValue = new ExtensionValue(critical,
            new AdmissionSyntax(admissionAuthority, new DERSequence(vec)));
}

From source file:org.xipki.pki.ca.certprofile.commonpki.AdmissionSyntaxOption.java

License:Open Source License

public ExtensionValue getExtensionValue(final List<List<String>> registrationNumbersList)
        throws BadCertTemplateException {
    if (!this.inputFromRequestRequired) {
        return this.extensionValue;
    }//from  w  ww . j  av  a2  s  .  c  om

    if (CollectionUtil.isEmpty(registrationNumbersList)) {
        throw new BadCertTemplateException("registrationNumbersList must not be empty");
    }

    final int n = registrationNumbersList.size();
    if (n != this.admissionsList.size()) {
        throw new BadCertTemplateException("invalid size of Admissions in AdmissionSyntax: " + "is=" + n
                + ", expected=" + this.admissionsList.size());
    }

    // check registrationNumbers
    List<List<String>> newRegNumbersList = new ArrayList<>(this.admissionsList.size());
    for (int i = 0; i < n; i++) {
        AdmissionsOption ao = this.admissionsList.get(i);
        List<ProfessionInfoOption> pi = ao.getProfessionInfos();
        List<String> registrationNumbers = registrationNumbersList.get(i);
        final int k = registrationNumbers.size();
        if (k != pi.size()) {
            throw new BadCertTemplateException("invalid size of ProfessionInfo in Admissions[" + i + "], is="
                    + k + ", expected=" + pi.size());
        }

        List<String> newRegNumbers = new ArrayList<>(k);
        newRegNumbersList.add(newRegNumbers);
        for (int j = 0; j < k; j++) {
            RegistrationNumberOption option = pi.get(j).getRegistrationNumberOption();
            if (option == null || option.getConstant() != null) {
                continue;
            }

            Pattern regex = option.getRegex();
            String regNum = registrationNumbers.get(j);
            if (regNum == null || !regex.matcher(regNum).matches()) {
                throw new BadCertTemplateException(
                        "invalid registrationNumber[" + i + "][" + j + "]: '" + regNum + "'");
            }
            newRegNumbers.add(regNum);
        }
    }

    ASN1EncodableVector vec = new ASN1EncodableVector();
    for (int i = 0; i < this.admissionsList.size(); i++) {
        AdmissionsOption ao = this.admissionsList.get(i);
        List<ProfessionInfoOption> piList = ao.getProfessionInfos();
        ProfessionInfo[] pis = new ProfessionInfo[piList.size()];

        for (int j = 0; j < pis.length; j++) {
            ProfessionInfoOption pio = piList.get(j);
            DirectoryString[] professionItems = null;
            int size = pio.getProfessionItems().size();
            professionItems = new DirectoryString[size];
            for (int k = 0; k < size; k++) {
                professionItems[k] = new DirectoryString(pio.getProfessionItems().get(k));
            }

            ASN1OctetString addProfessionInfo = null;
            if (pio.getAddProfessionalInfo() != null) {
                addProfessionInfo = new DEROctetString(pio.getAddProfessionalInfo());
            }

            RegistrationNumberOption regNumOption = pio.getRegistrationNumberOption();
            String registrationNumber = null;
            if (regNumOption != null) {
                if (regNumOption.getConstant() != null) {
                    registrationNumber = regNumOption.getConstant();
                } else {
                    registrationNumber = newRegNumbersList.get(i).get(j);
                }
            }

            pis[i] = new ProfessionInfo(pio.getNamingAuthority(), professionItems,
                    pio.getProfessionOids().toArray(new ASN1ObjectIdentifier[0]), registrationNumber,
                    addProfessionInfo);
        }

        vec.add(new Admissions(ao.getAdmissionAuthority(), ao.getNamingAuthority(), pis));
    }

    return new ExtensionValue(critical, new AdmissionSyntax(admissionAuthority, new DERSequence(vec)));
}