use of org.xipki.ca.api.profile.CertprofileException 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());
}
}
use of org.xipki.ca.api.profile.CertprofileException in project xipki by xipki.
the class XmlX509CertprofileUtil method parse.
public static X509ProfileType parse(InputStream xmlConfStream) throws CertprofileException {
ParamUtil.requireNonNull("xmlConfStream", xmlConfStream);
synchronized (JAXB_LOCK) {
JAXBElement<?> rootElement;
try {
if (jaxbUnmarshaller == null) {
JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
jaxbUnmarshaller = context.createUnmarshaller();
final SchemaFactory schemaFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL url = XmlX509CertprofileUtil.class.getResource("/xsd/certprofile.xsd");
jaxbUnmarshaller.setSchema(schemaFact.newSchema(url));
}
rootElement = (JAXBElement<?>) jaxbUnmarshaller.unmarshal(xmlConfStream);
} catch (SAXException ex) {
throw new CertprofileException("parse profile failed, message: " + ex.getMessage(), ex);
} catch (JAXBException ex) {
throw new CertprofileException("parse profile failed, message: " + XmlUtil.getMessage(ex), ex);
}
try {
xmlConfStream.close();
} catch (IOException ex) {
LOG.warn("could not close xmlConfStream: {}", ex.getMessage());
}
Object rootType = rootElement.getValue();
if (rootType instanceof X509ProfileType) {
return (X509ProfileType) rootElement.getValue();
} else {
throw new CertprofileException("invalid root element type");
}
}
}
use of org.xipki.ca.api.profile.CertprofileException in project xipki by xipki.
the class XmlX509CertprofileUtil method buildPolicyConstrains.
// method buildGeneralSubtree
public static ASN1Sequence buildPolicyConstrains(PolicyConstraints type) throws CertprofileException {
ParamUtil.requireNonNull("type", type);
Integer requireExplicitPolicy = type.getRequireExplicitPolicy();
if (requireExplicitPolicy != null && requireExplicitPolicy < 0) {
throw new CertprofileException("negative requireExplicitPolicy is not allowed: " + requireExplicitPolicy);
}
Integer inhibitPolicyMapping = type.getInhibitPolicyMapping();
if (inhibitPolicyMapping != null && inhibitPolicyMapping < 0) {
throw new CertprofileException("negative inhibitPolicyMapping is not allowed: " + inhibitPolicyMapping);
}
if (requireExplicitPolicy == null && inhibitPolicyMapping == null) {
return null;
}
final boolean explicit = false;
ASN1EncodableVector vec = new ASN1EncodableVector();
if (requireExplicitPolicy != null) {
vec.add(new DERTaggedObject(explicit, 0, new ASN1Integer(BigInteger.valueOf(requireExplicitPolicy))));
}
if (inhibitPolicyMapping != null) {
vec.add(new DERTaggedObject(explicit, 1, new ASN1Integer(BigInteger.valueOf(inhibitPolicyMapping))));
}
return new DERSequence(vec);
}
use of org.xipki.ca.api.profile.CertprofileException in project xipki by xipki.
the class XmlX509CertprofileUtil method buildKeyAlgorithms.
public static Map<ASN1ObjectIdentifier, KeyParametersOption> buildKeyAlgorithms(KeyAlgorithms keyAlgos) throws CertprofileException {
ParamUtil.requireNonNull("keyAlgos", keyAlgos);
Map<ASN1ObjectIdentifier, KeyParametersOption> keyAlgorithms = new HashMap<>();
for (AlgorithmType type : keyAlgos.getAlgorithm()) {
List<OidWithDescType> algIds = type.getAlgorithm();
List<ASN1ObjectIdentifier> oids = new ArrayList<>(algIds.size());
for (OidWithDescType algId : algIds) {
ASN1ObjectIdentifier oid = new ASN1ObjectIdentifier(algId.getValue());
if (keyAlgorithms.containsKey(oid)) {
throw new CertprofileException("duplicate definition of keyAlgorithm " + oid.getId());
}
oids.add(oid);
}
KeyParametersOption keyParamsOption = convertKeyParametersOption(type);
for (ASN1ObjectIdentifier oid : oids) {
keyAlgorithms.put(oid, keyParamsOption);
}
}
return CollectionUtil.unmodifiableMap(keyAlgorithms);
}
use of org.xipki.ca.api.profile.CertprofileException in project xipki by xipki.
the class SubjectDnSpec method fixRdnControl.
// static
public static void fixRdnControl(RdnControl control) throws CertprofileException {
ParamUtil.requireNonNull("control", control);
ASN1ObjectIdentifier type = control.getType();
StringType stringType = control.getStringType();
if (stringType != null) {
if (STRING_TYPE_SET.containsKey(type) && !STRING_TYPE_SET.get(type).contains(stringType)) {
throw new CertprofileException(String.format("%s is not allowed %s", stringType.name(), type.getId()));
}
} else {
StringType specStrType = DFLT_STRING_TYPES.get(type);
if (specStrType != null) {
control.setStringType(specStrType);
}
}
if (control.getPatterns() == null && PATTERNS.containsKey(type)) {
control.setPatterns(Arrays.asList(PATTERNS.get(type)));
}
Range specRange = RANGES.get(type);
if (specRange == null) {
control.setStringLengthRange(null);
return;
}
Range isRange = control.getStringLengthRange();
if (isRange == null) {
control.setStringLengthRange(specRange);
return;
}
boolean changed = false;
Integer specMin = specRange.getMin();
Integer min = isRange.getMin();
if (min == null) {
changed = true;
min = specMin;
} else if (specMin != null && specMin > min) {
changed = true;
min = specMin;
}
Integer specMax = specRange.getMax();
Integer max = isRange.getMax();
if (max == null) {
changed = true;
max = specMax;
} else if (specMax != null && specMax < max) {
changed = true;
max = specMax;
}
if (changed) {
isRange.setRange(min, max);
}
// isRange
}
Aggregations