Search in sources :

Example 1 with X509ExtensionType

use of org.xipki.security.X509ExtensionType in project xipki by xipki.

the class ExtensionsConfCreatorDemo method createConstantExtension.

// method createConstantExtensions
private static X509ExtensionType createConstantExtension(ASN1ObjectIdentifier type, Tag tag, FieldType fieldType, String value) {
    X509ExtensionType ret = new X509ExtensionType();
    // children
    String desc = "custom constant extension " + fieldType.getText();
    if (tag != null) {
        desc += " (" + tag.getValue() + ", " + (tag.isExplicit() ? "EXPLICIT)" : "IMPLICIT)");
    }
    ret.setType(createOidType(type, desc));
    ret.setConstant(new ConstantExtnValue(fieldType));
    if (value != null) {
        ret.getConstant().setValue(value);
    }
    if (tag != null) {
        ret.getConstant().setTag(tag);
    }
    return ret;
}
Also used : X509ExtensionType(org.xipki.security.X509ExtensionType)

Example 2 with X509ExtensionType

use of org.xipki.security.X509ExtensionType in project xipki by xipki.

the class ExtensionsConfCreatorDemo method createConstantExtensions.

// method extensionsSyntaxExt
private static List<X509ExtensionType> createConstantExtensions(ASN1ObjectIdentifier oidPrefix, Tag tag) {
    List<X509ExtensionType> list = new LinkedList<>();
    // Custom Constant Extension Value
    list.add(createConstantExtension(oidPrefix.branch("1"), tag, FieldType.BIT_STRING, Base64.encodeToString(new byte[] { 1, 2 })));
    list.add(createConstantExtension(oidPrefix.branch("2"), tag, FieldType.BMPString, "A BMP string"));
    list.add(createConstantExtension(oidPrefix.branch("3"), tag, FieldType.BOOLEAN, Boolean.TRUE.toString()));
    list.add(createConstantExtension(oidPrefix.branch("4"), tag, FieldType.IA5String, "An IA5 string"));
    list.add(createConstantExtension(oidPrefix.branch("5"), tag, FieldType.INTEGER, "10"));
    list.add(createConstantExtension(oidPrefix.branch("6"), tag, FieldType.NULL, null));
    list.add(createConstantExtension(oidPrefix.branch("7"), tag, FieldType.OCTET_STRING, Base64.encodeToString(new byte[] { 3, 4 })));
    list.add(createConstantExtension(oidPrefix.branch("8"), tag, FieldType.OID, "2.3.4.5"));
    list.add(createConstantExtension(oidPrefix.branch("9"), tag, FieldType.PrintableString, "A printable string"));
    list.add(createConstantExtension(oidPrefix.branch("10"), tag, FieldType.NULL, null));
    list.add(createConstantExtension(oidPrefix.branch("11"), tag, FieldType.TeletexString, "A teletax string"));
    list.add(createConstantExtension(oidPrefix.branch("12"), tag, FieldType.UTF8String, "A UTF8 string"));
    list.add(createConstantExtension(oidPrefix.branch("13"), tag, FieldType.ENUMERATED, "2"));
    list.add(createConstantExtension(oidPrefix.branch("14"), tag, FieldType.GeneralizedTime, new ASN1GeneralizedTime("20180314130102Z").getTimeString()));
    list.add(createConstantExtension(oidPrefix.branch("15"), tag, FieldType.UTCTime, "190314130102Z"));
    list.add(createConstantExtension(oidPrefix.branch("16"), tag, FieldType.Name, "CN=abc,C=DE"));
    list.add(createConstantExtension(oidPrefix.branch("17"), tag, FieldType.SEQUENCE, null));
    last(list).getConstant().setListValue(createConstantSequenceOrSet());
    list.add(createConstantExtension(oidPrefix.branch("18"), tag, FieldType.SEQUENCE_OF, null));
    last(list).getConstant().setListValue(createConstantSequenceOfOrSetOf());
    list.add(createConstantExtension(oidPrefix.branch("19"), tag, FieldType.SET, null));
    last(list).getConstant().setListValue(createConstantSequenceOrSet());
    list.add(createConstantExtension(oidPrefix.branch("20"), tag, FieldType.SET_OF, null));
    last(list).getConstant().setListValue(createConstantSequenceOfOrSetOf());
    return list;
}
Also used : X509ExtensionType(org.xipki.security.X509ExtensionType) ASN1GeneralizedTime(org.bouncycastle.asn1.ASN1GeneralizedTime)

Example 3 with X509ExtensionType

use of org.xipki.security.X509ExtensionType in project xipki by xipki.

the class ExtensionsConfCreatorDemo method extensionsAppleWwdr.

// method createConstantSequenceOfOrSetOf
private static void extensionsAppleWwdr(String destFilename) throws Exception {
    ExtensionsType extensions = new ExtensionsType();
    List<X509ExtensionType> list = new LinkedList<>();
    extensions.setExtensions(list);
    /*
     *  1. SEQUENCE or SET {
     *  2.   UTF8String abc.def.myBlog EXPLICIT
     *  3.   SEQUENCE
     *  4.     UTF8String app
     *  5.   UTF8String abc.def.myBlog.voip EXPLICIT
     *  6.   SEQUENCE EXPLICIT
     *  7.     UTF8String voip
     *  8.   UTF8String abc.def.myBlog.complication IMPLICIT
     *  9.   SEQUENCE IMPLICIT
     * 10.     UTF8String complication
     * 11. }
     */
    List<ConstantExtnValue> subFields = new LinkedList<>();
    // Line 2
    ConstantExtnValue subField = new ConstantExtnValue(FieldType.UTF8String);
    subFields.add(subField);
    subField.setValue("abc.def.myBlog");
    // Line 3-4
    subField = new ConstantExtnValue(FieldType.SEQUENCE);
    subFields.add(subField);
    ConstantExtnValue subsubField = new ConstantExtnValue(FieldType.UTF8String);
    subsubField.setValue("app");
    subField.setListValue(Arrays.asList(subsubField));
    // Line 5
    subField = new ConstantExtnValue(FieldType.UTF8String);
    subFields.add(subField);
    subField.setValue("abc.def.myBlog.voip");
    // Line 6-7
    subField = new ConstantExtnValue(FieldType.SEQUENCE);
    subFields.add(subField);
    subsubField = new ConstantExtnValue(FieldType.UTF8String);
    subsubField.setValue("void");
    subField.setListValue(Arrays.asList(subsubField));
    // Line 8
    subField = new ConstantExtnValue(FieldType.UTF8String);
    subFields.add(subField);
    subField.setValue("abc.def.myBlog.complication");
    // Line 9-10
    subField = new ConstantExtnValue(FieldType.SEQUENCE);
    subFields.add(subField);
    subsubField = new ConstantExtnValue(FieldType.UTF8String);
    subsubField.setValue("complication");
    subField.setListValue(Arrays.asList(subsubField));
    X509ExtensionType extn = new X509ExtensionType();
    list.add(extn);
    // children
    extn.setType(createOidType(new ASN1ObjectIdentifier("1.2.840.113635.100.6.3.6"), "custom apple extension"));
    ConstantExtnValue extnValue = new ConstantExtnValue(FieldType.SEQUENCE);
    extnValue.setListValue(subFields);
    extn.setConstant(extnValue);
    marshall(extensions, destFilename);
}
Also used : X509ExtensionType(org.xipki.security.X509ExtensionType) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 4 with X509ExtensionType

use of org.xipki.security.X509ExtensionType in project xipki by xipki.

the class ExtensionsConfCreatorDemo method extensionsEeCompelx.

// method check
private static void extensionsEeCompelx(String destFilename) throws Exception {
    ExtensionsType extensions = new ExtensionsType();
    // Extensions
    // Extensions - general
    List<X509ExtensionType> list = new LinkedList<>();
    extensions.setExtensions(list);
    // extension subjectDirectoryAttributes (RFC 3739)
    /*
         SubjectDirectoryAttributes ::= Attributes
          Attributes ::= SEQUENCE SIZE (1..MAX) OF Attribute
          Attribute ::= SEQUENCE
          {
            type AttributeType
            values SET OF AttributeValue
          }

          AttributeType ::= OBJECT IDENTIFIER
          AttributeValue ::= ANY DEFINED BY AttributeType
    */
    X509ExtensionType sdaExt = new X509ExtensionType();
    list.add(sdaExt);
    sdaExt.setType(createOidType(Extension.subjectDirectoryAttributes, "subjectDirectoryAttributes"));
    ConstantExtnValue sdaSyntax = new ConstantExtnValue(FieldType.SEQUENCE_OF);
    sdaExt.setConstant(sdaSyntax);
    List<ConstantExtnValue> sdaSyntax_values = new LinkedList<>();
    sdaSyntax.setListValue(sdaSyntax_values);
    List<ASN1ObjectIdentifier> types = new LinkedList<>();
    List<FieldType> attrTypes = new LinkedList<>();
    List<String> attrValues = new LinkedList<>();
    // dateOfBirth
    types.add(ObjectIdentifiers.DN.dateOfBirth);
    attrTypes.add(FieldType.GeneralizedTime);
    attrValues.add("19800122120000Z");
    // Gender
    types.add(ObjectIdentifiers.DN.gender);
    attrTypes.add(FieldType.PrintableString);
    attrValues.add("M");
    // placeOfBirth
    types.add(ObjectIdentifiers.DN.placeOfBirth);
    attrTypes.add(FieldType.UTF8String);
    attrValues.add("Berlin");
    // placeOfBirth
    types.add(ObjectIdentifiers.DN.countryOfCitizenship);
    attrTypes.add(FieldType.PrintableString);
    attrValues.add("DE");
    types.add(ObjectIdentifiers.DN.countryOfCitizenship);
    attrTypes.add(FieldType.PrintableString);
    attrValues.add("FR");
    // countryOfResidence
    types.add(ObjectIdentifiers.DN.countryOfResidence);
    attrTypes.add(FieldType.PrintableString);
    attrValues.add("DE");
    for (int i = 0; i < types.size(); i++) {
        ConstantExtnValue attribute = new ConstantExtnValue(FieldType.SEQUENCE);
        sdaSyntax_values.add(attribute);
        List<ConstantExtnValue> attribute_values = new LinkedList<>();
        attribute.setListValue(attribute_values);
        ConstantExtnValue type = new ConstantExtnValue(FieldType.OID);
        attribute_values.add(type);
        type.setValue(types.get(i).getId());
        String desc = ObjectIdentifiers.getName(types.get(i));
        if (desc != null) {
            type.setDescription(desc);
        }
        ConstantExtnValue values = new ConstantExtnValue(FieldType.SET);
        attribute_values.add(values);
        List<ConstantExtnValue> values_values = new LinkedList<>();
        values.setListValue(values_values);
        ConstantExtnValue value = new ConstantExtnValue(attrTypes.get(i));
        values_values.add(value);
        value.setValue(attrValues.get(i));
    }
    marshall(extensions, destFilename);
}
Also used : X509ExtensionType(org.xipki.security.X509ExtensionType) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 5 with X509ExtensionType

use of org.xipki.security.X509ExtensionType in project xipki by xipki.

the class ExtensionsConfCreatorDemo method check.

// method marshal
private static void check(Path path) throws Exception {
    byte[] bytes = IoUtil.read(path.toFile());
    ExtensionsType extraExtensions = JSON.parseObject(bytes, ExtensionsType.class);
    extraExtensions.validate();
    List<X509ExtensionType> extnConfs = extraExtensions.getExtensions();
    if (CollectionUtil.isNotEmpty(extnConfs)) {
        for (X509ExtensionType m : extnConfs) {
            byte[] encodedExtnValue = m.getConstant().toASN1Encodable().toASN1Primitive().getEncoded(ASN1Encoding.DER);
            new Extension(new ASN1ObjectIdentifier(m.getType().getOid()), false, encodedExtnValue);
        }
    }
}
Also used : Extension(org.bouncycastle.asn1.x509.Extension) X509ExtensionType(org.xipki.security.X509ExtensionType) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

X509ExtensionType (org.xipki.security.X509ExtensionType)6 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)4 ASN1GeneralizedTime (org.bouncycastle.asn1.ASN1GeneralizedTime)1 Extension (org.bouncycastle.asn1.x509.Extension)1