Search in sources :

Example 1 with X509ProfileType

use of org.xipki.ca.certprofile.x509.jaxb.X509ProfileType in project xipki by xipki.

the class ProfileConfCreatorDemo method certprofileExtended.

// method certprofileMaxTime
private static X509ProfileType certprofileExtended() throws Exception {
    X509ProfileType profile = getBaseProfile("certprofile extended", X509CertLevel.EndEntity, "5y", false);
    profile.setDuplicateKey(true);
    // Subject
    Subject subject = profile.getSubject();
    subject.setDuplicateSubjectPermitted(true);
    subject.setIncSerialNumber(false);
    List<RdnType> rdnControls = subject.getRdn();
    rdnControls.add(createRdn(ObjectIdentifiers.DN_C, 1, 1, new String[] { "DE|FR" }, null, null));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_O, 1, 1));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_OU, 0, 1));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_SN, 0, 1, new String[] { REGEX_SN }, null, null));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_CN, 1, 1, new String[] { REGEX_FQDN }, null, null));
    // Extensions
    // Extensions - general
    ExtensionsType extensions = profile.getExtensions();
    // SubjectToSubjectAltName
    extensions.setSubjectToSubjectAltNames(new SubjectToSubjectAltNamesType());
    SubjectToSubjectAltNameType s2sType = new SubjectToSubjectAltNameType();
    extensions.getSubjectToSubjectAltNames().getSubjectToSubjectAltName().add(s2sType);
    s2sType.setSource(createOidType(ObjectIdentifiers.DN_CN));
    s2sType.setTarget(new Target());
    s2sType.getTarget().setDnsName("");
    // Extensions - controls
    List<ExtensionType> list = extensions.getExtension();
    list.add(createExtension(Extension.subjectKeyIdentifier, true, false, null));
    list.add(createExtension(Extension.cRLDistributionPoints, false, false, null));
    list.add(createExtension(Extension.freshestCRL, false, false, null));
    // Extensions - SubjectAltNames
    SubjectAltName subjectAltNameMode = new SubjectAltName();
    subjectAltNameMode.setDnsName("");
    subjectAltNameMode.setIpAddress("");
    ExtensionValueType extensionValue = createExtensionValueType(subjectAltNameMode);
    list.add(createExtension(Extension.subjectAlternativeName, true, false, extensionValue));
    // Extensions - basicConstraints
    extensionValue = null;
    list.add(createExtension(Extension.basicConstraints, true, true, extensionValue));
    // Extensions - AuthorityInfoAccess
    extensionValue = createAuthorityInfoAccess();
    list.add(createExtension(Extension.authorityInfoAccess, true, false, extensionValue));
    // Extensions - AuthorityKeyIdentifier
    extensionValue = createAuthorityKeyIdentifier(true);
    list.add(createExtension(Extension.authorityKeyIdentifier, true, false, extensionValue));
    // Extensions - keyUsage
    extensionValue = createKeyUsages(new KeyUsageEnum[] { KeyUsageEnum.DIGITAL_SIGNATURE, KeyUsageEnum.DATA_ENCIPHERMENT, KeyUsageEnum.KEY_ENCIPHERMENT }, null);
    list.add(createExtension(Extension.keyUsage, true, true, extensionValue));
    // Extensions - extenedKeyUsage
    extensionValue = createExtendedKeyUsage(new ASN1ObjectIdentifier[] { ObjectIdentifiers.id_kp_serverAuth }, new ASN1ObjectIdentifier[] { ObjectIdentifiers.id_kp_clientAuth });
    list.add(createExtension(Extension.extendedKeyUsage, true, false, extensionValue));
    // Extensions - tlsFeature
    extensionValue = createTlsFeature(new TlsExtensionType[] { TlsExtensionType.STATUS_REQUEST, TlsExtensionType.CLIENT_CERTIFICATE_URL });
    list.add(createExtension(ObjectIdentifiers.id_pe_tlsfeature, true, true, extensionValue));
    // Extensions - SMIMECapabilities
    extensionValue = createSmimeCapabilities();
    list.add(createExtension(ObjectIdentifiers.id_smimeCapabilities, true, false, extensionValue));
    // Extensions - 1.2.3.4.1 (demo-ca-extraInfo)
    list.add(createExtension(new ASN1ObjectIdentifier("1.2.3.4.1"), true, false, null, "demo-ca-extraInfo"));
    // Extensions - 1.2.3.4.2 (demo-other-namespace)
    String xmlBlock = "<sequence xmlns='urn:extra'>" + "\n          <text>aaa</text>" + "\n          <text>bbb</text>" + "\n        </sequence>";
    Element element;
    try {
        element = XmlUtil.getDocumentElment(xmlBlock.getBytes());
    } catch (IOException | SAXException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
    ExtensionValueType extnValue = new ExtensionValueType();
    extnValue.setAny(element);
    list.add(createExtension(new ASN1ObjectIdentifier("1.2.3.4.2"), true, false, extnValue, "demo-other-namespace"));
    return profile;
}
Also used : TlsExtensionType(org.xipki.security.TlsExtensionType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) SubjectToSubjectAltNamesType(org.xipki.ca.certprofile.x509.jaxb.SubjectToSubjectAltNamesType) X509ProfileType(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType) ExtensionValueType(org.xipki.ca.certprofile.x509.jaxb.ExtensionValueType) IOException(java.io.IOException) Subject(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType.Subject) RdnType(org.xipki.ca.certprofile.x509.jaxb.RdnType) KeyUsageEnum(org.xipki.ca.certprofile.x509.jaxb.KeyUsageEnum) SAXException(org.xml.sax.SAXException) Target(org.xipki.ca.certprofile.x509.jaxb.SubjectToSubjectAltNameType.Target) SubjectToSubjectAltNameType(org.xipki.ca.certprofile.x509.jaxb.SubjectToSubjectAltNameType) SubjectAltName(org.xipki.ca.certprofile.x509.jaxb.SubjectAltName) ExtensionsType(org.xipki.ca.certprofile.x509.jaxb.ExtensionsType) ExtensionType(org.xipki.ca.certprofile.x509.jaxb.ExtensionType) TlsExtensionType(org.xipki.security.TlsExtensionType) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 2 with X509ProfileType

use of org.xipki.ca.certprofile.x509.jaxb.X509ProfileType in project xipki by xipki.

the class ProfileConfCreatorDemo method certprofileMultipleValuedRdn.

// method certprofileMultipleOus
/*
   * O and OU in one RDN
   */
private static X509ProfileType certprofileMultipleValuedRdn() throws Exception {
    X509ProfileType profile = getBaseProfile("certprofile multiple-valued-rdn", X509CertLevel.EndEntity, "5y", false);
    // Subject
    Subject subject = profile.getSubject();
    subject.setIncSerialNumber(false);
    List<RdnType> rdnControls = subject.getRdn();
    rdnControls.add(createRdn(ObjectIdentifiers.DN_C, 1, 1, new String[] { "DE|FR" }, null, null));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_O, 1, 1, null, null, null, "group1"));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_OU, 1, 1, null, null, null, "group1"));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_SN, 0, 1, new String[] { REGEX_SN }, null, null));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_CN, 1, 1));
    // Extensions
    // Extensions - general
    ExtensionsType extensions = profile.getExtensions();
    List<ExtensionType> list = extensions.getExtension();
    list.add(createExtension(Extension.subjectKeyIdentifier, true, false, null));
    list.add(createExtension(Extension.cRLDistributionPoints, false, false, null));
    list.add(createExtension(Extension.freshestCRL, false, false, null));
    // Extensions - basicConstraints
    ExtensionValueType extensionValue = null;
    list.add(createExtension(Extension.basicConstraints, true, true, extensionValue));
    // Extensions - AuthorityInfoAccess
    extensionValue = createAuthorityInfoAccess();
    list.add(createExtension(Extension.authorityInfoAccess, true, false, extensionValue));
    // Extensions - AuthorityKeyIdentifier
    extensionValue = createAuthorityKeyIdentifier(true);
    list.add(createExtension(Extension.authorityKeyIdentifier, true, false, extensionValue));
    // Extensions - keyUsage
    extensionValue = createKeyUsages(new KeyUsageEnum[] { KeyUsageEnum.CONTENT_COMMITMENT }, null);
    list.add(createExtension(Extension.keyUsage, true, true, extensionValue));
    return profile;
}
Also used : ExtensionsType(org.xipki.ca.certprofile.x509.jaxb.ExtensionsType) ExtensionType(org.xipki.ca.certprofile.x509.jaxb.ExtensionType) TlsExtensionType(org.xipki.security.TlsExtensionType) X509ProfileType(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType) ExtensionValueType(org.xipki.ca.certprofile.x509.jaxb.ExtensionValueType) Subject(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType.Subject) RdnType(org.xipki.ca.certprofile.x509.jaxb.RdnType) KeyUsageEnum(org.xipki.ca.certprofile.x509.jaxb.KeyUsageEnum)

Example 3 with X509ProfileType

use of org.xipki.ca.certprofile.x509.jaxb.X509ProfileType in project xipki by xipki.

the class ProfileConfCreatorDemo method certprofileQc.

// method certprofileMultipleValuedRdn
private static X509ProfileType certprofileQc() throws Exception {
    X509ProfileType profile = getBaseProfile("certprofile qc", X509CertLevel.EndEntity, "5y", false);
    // Subject
    Subject subject = profile.getSubject();
    subject.setIncSerialNumber(false);
    List<RdnType> rdnControls = subject.getRdn();
    rdnControls.add(createRdn(ObjectIdentifiers.DN_C, 1, 1, new String[] { "DE|FR" }, null, null));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_O, 1, 1));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_organizationIdentifier, 0, 1));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_OU, 0, 1));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_SN, 0, 1, new String[] { REGEX_SN }, null, null));
    rdnControls.add(createRdn(ObjectIdentifiers.DN_CN, 1, 1));
    // Extensions
    // Extensions - general
    ExtensionsType extensions = profile.getExtensions();
    // Extensions - controls
    List<ExtensionType> list = extensions.getExtension();
    list.add(createExtension(Extension.subjectKeyIdentifier, true, false, null));
    list.add(createExtension(Extension.cRLDistributionPoints, false, false, null));
    list.add(createExtension(Extension.freshestCRL, false, false, null));
    // Extensions - basicConstraints
    ExtensionValueType extensionValue = null;
    list.add(createExtension(Extension.basicConstraints, true, false, extensionValue));
    // Extensions - AuthorityInfoAccess
    extensionValue = createAuthorityInfoAccess();
    list.add(createExtension(Extension.authorityInfoAccess, true, false, extensionValue));
    // Extensions - AuthorityKeyIdentifier
    extensionValue = createAuthorityKeyIdentifier(true);
    list.add(createExtension(Extension.authorityKeyIdentifier, true, false, extensionValue));
    // Extensions - keyUsage
    extensionValue = createKeyUsages(new KeyUsageEnum[] { KeyUsageEnum.CONTENT_COMMITMENT }, null);
    list.add(createExtension(Extension.keyUsage, true, true, extensionValue));
    // Extensions - extenedKeyUsage
    extensionValue = createExtendedKeyUsage(new ASN1ObjectIdentifier[] { ObjectIdentifiers.id_kp_timeStamping }, null);
    list.add(createExtension(Extension.extendedKeyUsage, true, true, extensionValue));
    // privateKeyUsagePeriod
    extensionValue = createPrivateKeyUsagePeriod("3y");
    list.add(createExtension(Extension.privateKeyUsagePeriod, true, false, extensionValue));
    // QcStatements
    extensionValue = createQcStatements(false);
    list.add(createExtension(Extension.qCStatements, true, false, extensionValue));
    return profile;
}
Also used : ExtensionsType(org.xipki.ca.certprofile.x509.jaxb.ExtensionsType) ExtensionType(org.xipki.ca.certprofile.x509.jaxb.ExtensionType) TlsExtensionType(org.xipki.security.TlsExtensionType) X509ProfileType(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType) ExtensionValueType(org.xipki.ca.certprofile.x509.jaxb.ExtensionValueType) Subject(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType.Subject) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) RdnType(org.xipki.ca.certprofile.x509.jaxb.RdnType) KeyUsageEnum(org.xipki.ca.certprofile.x509.jaxb.KeyUsageEnum)

Example 4 with X509ProfileType

use of org.xipki.ca.certprofile.x509.jaxb.X509ProfileType in project xipki by xipki.

the class ProfileConfCreatorDemo method marshall.

// method main
private static void marshall(Marshaller marshaller, X509ProfileType profile, String filename) throws Exception {
    File file = new File("tmp", filename);
    file.getParentFile().mkdirs();
    JAXBElement<X509ProfileType> root = new ObjectFactory().createX509Profile(profile);
    FileOutputStream out = new FileOutputStream(file);
    try {
        marshaller.marshal(root, out);
    } catch (JAXBException ex) {
        throw XmlUtil.convert(ex);
    } finally {
        out.close();
    }
    System.out.println("Generated certprofile in " + filename);
}
Also used : ObjectFactory(org.xipki.ca.certprofile.x509.jaxb.ObjectFactory) FileOutputStream(java.io.FileOutputStream) JAXBException(javax.xml.bind.JAXBException) X509ProfileType(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType) File(java.io.File)

Example 5 with X509ProfileType

use of org.xipki.ca.certprofile.x509.jaxb.X509ProfileType in project xipki by xipki.

the class ProfileConfCreatorDemo method main.

public static void main(String[] args) {
    try {
        Marshaller ms = JAXBContext.newInstance(ObjectFactory.class).createMarshaller();
        final SchemaFactory schemaFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
        URL url = ProfileConfCreatorDemo.class.getResource("/xsd/certprofile.xsd");
        ms.setSchema(schemaFact.newSchema(url));
        ms.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        ms.setProperty("com.sun.xml.internal.bind.indentString", "  ");
        int year = Calendar.getInstance().get(Calendar.YEAR);
        ms.setProperty("com.sun.xml.internal.bind.xmlHeaders", "\n" + "<!--\n" + "  Copyright (c) 2013 - " + year + " Lijun Liao\n" + "\n" + "  Licensed under the Apache License, Version 2.0 (the \"License\");\n" + "  you may not use this file except in compliance with the License.\n" + "  You may obtain a copy of the License at\n" + "\n" + "  http://www.apache.org/licenses/LICENSE-2.0\n" + "\n" + "  Unless required by applicable law or agreed to in writing, software\n" + "  distributed under the License is distributed on an \"AS IS\" BASIS,\n" + "  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + "  See the License for the specific language governing permissions and\n" + "  limitations under the License.\n" + "-->");
        X509ProfileType profile = certprofileRootCa();
        marshall(ms, profile, "certprofile-rootca.xml");
        profile = certprofileCross();
        marshall(ms, profile, "certprofile-cross.xml");
        profile = certprofileSubCa();
        marshall(ms, profile, "certprofile-subca.xml");
        profile = certprofileSubCaComplex();
        marshall(ms, profile, "certprofile-subca-complex.xml");
        profile = certprofileOcsp();
        marshall(ms, profile, "certprofile-ocsp.xml");
        profile = certprofileScep();
        marshall(ms, profile, "certprofile-scep.xml");
        profile = certprofileEeComplex();
        marshall(ms, profile, "certprofile-ee-complex.xml");
        profile = certprofileQc();
        marshall(ms, profile, "certprofile-qc.xml");
        profile = certprofileTls();
        marshall(ms, profile, "certprofile-tls.xml");
        profile = certprofileTlsC();
        marshall(ms, profile, "certprofile-tls-c.xml");
        profile = certprofileTlsWithIncSerial();
        marshall(ms, profile, "certprofile-tls-inc-sn.xml");
        profile = certprofileGsmcK();
        marshall(ms, profile, "certprofile-gsmc-k.xml");
        profile = certprofileMultipleOus();
        marshall(ms, profile, "certprofile-multiple-ous.xml");
        profile = certprofileMultipleValuedRdn();
        marshall(ms, profile, "certprofile-multi-valued-rdn.xml");
        profile = certprofileMaxTime();
        marshall(ms, profile, "certprofile-max-time.xml");
        profile = certprofileExtended();
        marshall(ms, profile, "certprofile-extended.xml");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Marshaller(javax.xml.bind.Marshaller) ObjectFactory(org.xipki.ca.certprofile.x509.jaxb.ObjectFactory) X509ProfileType(org.xipki.ca.certprofile.x509.jaxb.X509ProfileType) URL(java.net.URL) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException)

Aggregations

X509ProfileType (org.xipki.ca.certprofile.x509.jaxb.X509ProfileType)21 ExtensionsType (org.xipki.ca.certprofile.x509.jaxb.ExtensionsType)18 Subject (org.xipki.ca.certprofile.x509.jaxb.X509ProfileType.Subject)18 RdnType (org.xipki.ca.certprofile.x509.jaxb.RdnType)17 ExtensionType (org.xipki.ca.certprofile.x509.jaxb.ExtensionType)16 ExtensionValueType (org.xipki.ca.certprofile.x509.jaxb.ExtensionValueType)16 KeyUsageEnum (org.xipki.ca.certprofile.x509.jaxb.KeyUsageEnum)16 TlsExtensionType (org.xipki.security.TlsExtensionType)16 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)11 IOException (java.io.IOException)3 JAXBException (javax.xml.bind.JAXBException)3 CertprofileException (org.xipki.ca.api.profile.CertprofileException)3 SubjectAltName (org.xipki.ca.certprofile.x509.jaxb.SubjectAltName)3 SAXException (org.xml.sax.SAXException)3 URL (java.net.URL)2 LinkedList (java.util.LinkedList)2 SchemaFactory (javax.xml.validation.SchemaFactory)2 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)2 AdmissionSyntax (org.xipki.ca.certprofile.x509.jaxb.AdmissionSyntax)2 AdmissionsType (org.xipki.ca.certprofile.x509.jaxb.AdmissionsType)2