use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.
the class ProfileConfCreatorDemo method certprofileTlsC.
// method certprofileTls
private static X509ProfileType certprofileTlsC() throws Exception {
X509ProfileType profile = getBaseProfile("certprofile tls-c", 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_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
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.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_clientAuth }, null);
list.add(createExtension(Extension.extendedKeyUsage, true, false, extensionValue));
return profile;
}
use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.
the class ProfileConfCreatorDemo method certprofileOcsp.
// method certprofileSubCaComplex
private static X509ProfileType certprofileOcsp() throws Exception {
X509ProfileType profile = getBaseProfile("certprofile ocsp", X509CertLevel.EndEntity, "5y", false);
// Subject
Subject subject = profile.getSubject();
subject.setIncSerialNumber(true);
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
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));
list.add(createExtension(ObjectIdentifiers.id_extension_pkix_ocsp_nocheck, 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));
// Extensions - extenedKeyUsage
extensionValue = createExtendedKeyUsage(new ASN1ObjectIdentifier[] { ObjectIdentifiers.id_kp_OCSPSigning }, null);
list.add(createExtension(Extension.extendedKeyUsage, true, false, extensionValue));
return profile;
}
use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.
the class ProfileConfCreatorDemo method createExtendedKeyUsage.
private static ExtensionValueType createExtendedKeyUsage(ASN1ObjectIdentifier[] requiredUsages, ASN1ObjectIdentifier[] optionalUsages) {
ExtendedKeyUsage extValue = new ExtendedKeyUsage();
if (requiredUsages != null) {
List<ASN1ObjectIdentifier> oids = Arrays.asList(requiredUsages);
oids = sortOidList(oids);
for (ASN1ObjectIdentifier usage : oids) {
extValue.getUsage().add(createSingleExtKeyUsage(usage, true));
}
}
if (optionalUsages != null) {
List<ASN1ObjectIdentifier> oids = Arrays.asList(optionalUsages);
oids = sortOidList(oids);
for (ASN1ObjectIdentifier usage : oids) {
extValue.getUsage().add(createSingleExtKeyUsage(usage, false));
}
}
return createExtensionValueType(extValue);
}
use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.
the class ProfileConfCreatorDemo method createCertificatePolicies.
private static ExtensionValueType createCertificatePolicies(ASN1ObjectIdentifier... policyOids) {
if (policyOids == null || policyOids.length == 0) {
return null;
}
CertificatePolicies extValue = new CertificatePolicies();
List<CertificatePolicyInformationType> pis = extValue.getCertificatePolicyInformation();
for (ASN1ObjectIdentifier oid : policyOids) {
CertificatePolicyInformationType single = new CertificatePolicyInformationType();
pis.add(single);
single.setPolicyIdentifier(createOidType(oid));
}
return createExtensionValueType(extValue);
}
use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.
the class XmlX509CertprofileUtil method convertKeyParametersOption.
private static KeyParametersOption convertKeyParametersOption(AlgorithmType type) throws CertprofileException {
ParamUtil.requireNonNull("type", type);
if (type.getParameters() == null || type.getParameters().getAny() == null) {
return KeyParametersOption.ALLOW_ALL;
}
Object paramsObj = type.getParameters().getAny();
if (paramsObj instanceof ECParameters) {
ECParameters params = (ECParameters) paramsObj;
KeyParametersOption.ECParamatersOption option = new KeyParametersOption.ECParamatersOption();
if (params.getCurves() != null) {
Curves curves = params.getCurves();
Set<ASN1ObjectIdentifier> curveOids = toOidSet(curves.getCurve());
option.setCurveOids(curveOids);
}
if (params.getPointEncodings() != null) {
List<Byte> bytes = params.getPointEncodings().getPointEncoding();
Set<Byte> pointEncodings = new HashSet<>(bytes);
option.setPointEncodings(pointEncodings);
}
return option;
} else if (paramsObj instanceof RSAParameters) {
RSAParameters params = (RSAParameters) paramsObj;
KeyParametersOption.RSAParametersOption option = new KeyParametersOption.RSAParametersOption();
Set<Range> modulusLengths = buildParametersMap(params.getModulusLength());
option.setModulusLengths(modulusLengths);
return option;
} else if (paramsObj instanceof RSAPSSParameters) {
RSAPSSParameters params = (RSAPSSParameters) paramsObj;
KeyParametersOption.RSAPSSParametersOption option = new KeyParametersOption.RSAPSSParametersOption();
Set<Range> modulusLengths = buildParametersMap(params.getModulusLength());
option.setModulusLengths(modulusLengths);
return option;
} else if (paramsObj instanceof DSAParameters) {
DSAParameters params = (DSAParameters) paramsObj;
KeyParametersOption.DSAParametersOption option = new KeyParametersOption.DSAParametersOption();
Set<Range> plengths = buildParametersMap(params.getPLength());
option.setPlengths(plengths);
Set<Range> qlengths = buildParametersMap(params.getQLength());
option.setQlengths(qlengths);
return option;
} else if (paramsObj instanceof DHParameters) {
DHParameters params = (DHParameters) paramsObj;
KeyParametersOption.DHParametersOption option = new KeyParametersOption.DHParametersOption();
Set<Range> plengths = buildParametersMap(params.getPLength());
option.setPlengths(plengths);
Set<Range> qlengths = buildParametersMap(params.getQLength());
option.setQlengths(qlengths);
return option;
} else if (paramsObj instanceof GostParameters) {
GostParameters params = (GostParameters) paramsObj;
KeyParametersOption.GostParametersOption option = new KeyParametersOption.GostParametersOption();
Set<ASN1ObjectIdentifier> set = toOidSet(params.getPublicKeyParamSet());
option.setPublicKeyParamSets(set);
set = toOidSet(params.getDigestParamSet());
option.setDigestParamSets(set);
set = toOidSet(params.getEncryptionParamSet());
option.setEncryptionParamSets(set);
return option;
} else {
throw new CertprofileException("unknown public key parameters type " + paramsObj.getClass().getName());
}
}
Aggregations