private static String toString(Set<ASN1ObjectIdentifier> oids) { if (oids == null) { return "null"; } StringBuilder sb = new StringBuilder(); sb.append("["); for (ASN1ObjectIdentifier oid : oids) { String name = ObjectIdentifiers.getName(oid); if (name != null) { sb.append(name); sb.append(" (").append(oid.getId()).append(")"); } else { sb.append(oid.getId()); } sb.append(", "); } if (CollectionUtil.isNonEmpty(oids)) { int len = sb.length(); sb.delete(len - 2, len); } sb.append("]"); return sb.toString(); } // method toString
private static String oidToDisplayName(ASN1ObjectIdentifier type) { return ObjectIdentifiers.oidToDisplayName(type); }
String name = ObjectIdentifiers.getName(oid); if (StringUtil.isBlank(name)) { name = oid.getId();
throw new BadCertTemplateException( String.format("invalid subject %s '%s' against regex '%s'", ObjectIdentifiers.oidToDisplayName(type), tmpText, pattern.pattern())); throw new BadCertTemplateException( String.format("subject %s '%s' is too short (length (%d) < minLen (%d))", ObjectIdentifiers.oidToDisplayName(type), tmpText, len, minLen)); throw new BadCertTemplateException( String.format("subject %s '%s' is too long (length (%d) > maxLen (%d))", ObjectIdentifiers.oidToDisplayName(type), tmpText, len, maxLen));
public static String oidToDisplayName(final ASN1ObjectIdentifier type) { ParamUtil.requireNonNull("type", type); String name = getName(type); return (name == null) ? type.getId() : type.getId() + " (" + name + ")"; }
private static Object getExtensionValue(ASN1ObjectIdentifier type, ExtensionsType extensionsType, Class<?> expectedClass) throws CertprofileException { for (ExtensionType m : extensionsType.getExtension()) { if (!m.getType().getValue().equals(type.getId())) { continue; } if (m.getValue() == null || m.getValue().getAny() == null) { return null; } Object obj = m.getValue().getAny(); if (expectedClass.isAssignableFrom(obj.getClass())) { return obj; } else if (ConstantExtValue.class.isAssignableFrom(obj.getClass())) { // will be processed later return null; } else { String displayName = ObjectIdentifiers.oidToDisplayName(type); throw new CertprofileException("the extension configuration for " + displayName + " is not of the expected type " + expectedClass.getName() + ", but " + obj.getClass().getName()); } } throw new RuntimeException("should not reach here: undefined extension " + ObjectIdentifiers.oidToDisplayName(type)); } // method getExtensionValue
public static String oidToDisplayName(ASN1ObjectIdentifier type) { Args.notNull(type, "type"); String name = getName(type); return (name == null) ? type.getId() : type.getId() + " (" + name + ")"; }
private static Object getExtensionValue(final ASN1ObjectIdentifier type, final ExtensionsType extensionsType, final Class<?> expectedClass) throws CertprofileException { for (ExtensionType m : extensionsType.getExtension()) { if (!m.getType().getValue().equals(type.getId())) { continue; } if (m.getValue() == null || m.getValue().getAny() == null) { return null; } Object obj = m.getValue().getAny(); if (expectedClass.isAssignableFrom(obj.getClass())) { return obj; } else if (ConstantExtValue.class.isAssignableFrom(obj.getClass())) { // will be processed later return null; } else { String displayName = ObjectIdentifiers.oidToDisplayName(type); throw new CertprofileException("the extension configuration for " + displayName + " is not of the expected type " + expectedClass.getName()); } } throw new RuntimeException("should not reach here: undefined extension " + ObjectIdentifiers.oidToDisplayName(type)); } // method getExtensionValue
private static void addExtension(ExtensionValues values, ASN1ObjectIdentifier extType, ExtensionValue extValue, ExtensionControl extControl, Set<ASN1ObjectIdentifier> neededExtensionTypes, Set<ASN1ObjectIdentifier> wantedExtensionTypes) throws CertprofileException { if (extValue != null) { values.addExtension(extType, extValue); neededExtensionTypes.remove(extType); wantedExtensionTypes.remove(extType); } else if (extControl.isRequired()) { String description = ObjectIdentifiers.getName(extType); if (description == null) { description = extType.getId(); } throw new CertprofileException("could not add required extension " + description); } } // method addExtension
private Object getExtensionValue(final ASN1ObjectIdentifier type, final ExtensionsType extensionsType, final Class<?> expectedClass) throws CertprofileException { for (ExtensionType m : extensionsType.getExtension()) { if (!m.getType().getValue().equals(type.getId())) { continue; } if (m.getValue() == null || m.getValue().getAny() == null) { return null; } Object obj = m.getValue().getAny(); if (expectedClass.isAssignableFrom(obj.getClass())) { return obj; } else if (ConstantExtValue.class.isAssignableFrom(obj.getClass())) { // will be processed later return null; } else { String displayName = ObjectIdentifiers.oidToDisplayName(type); throw new CertprofileException("the extension configuration for " + displayName + " is not of the expected type " + expectedClass.getName()); } } throw new RuntimeException("should not reach here: undefined extension " + ObjectIdentifiers.oidToDisplayName(type)); } // method getExtensionValue
private static void addExtension(ExtensionValues values, ASN1ObjectIdentifier extType, ASN1Encodable extValue, ExtensionControl extControl, Set<ASN1ObjectIdentifier> neededExtensionTypes, Set<ASN1ObjectIdentifier> wantedExtensionTypes) throws CertprofileException { if (extValue != null) { values.addExtension(extType, extControl.isCritical(), extValue); neededExtensionTypes.remove(extType); wantedExtensionTypes.remove(extType); } else if (extControl.isRequired()) { String description = ObjectIdentifiers.getName(extType); if (description == null) { description = extType.getId(); } throw new CertprofileException("could not add required extension " + description); } } // method addExtension
private ValidationIssue createExtensionIssue(final ASN1ObjectIdentifier extId) { ValidationIssue issue; String extName = ObjectIdentifiers.getName(extId); if (extName == null) { extName = extId.getId().replace('.', '_'); issue = new ValidationIssue("X509.EXT." + extName, "extension " + extId.getId()); } else { issue = new ValidationIssue("X509.EXT." + extName, "extension " + extName + " (" + extId.getId() + ")"); } return issue; } // method createExtensionIssue
private static ValidationIssue createSubjectIssue(final ASN1ObjectIdentifier subjectAttrType) { ValidationIssue issue; String attrName = ObjectIdentifiers.getName(subjectAttrType); if (attrName == null) { attrName = subjectAttrType.getId().replace('.', '_'); issue = new ValidationIssue("X509.SUBJECT." + attrName, "attribute " + subjectAttrType.getId()); } else { issue = new ValidationIssue("X509.SUBJECT." + attrName, "attribute " + attrName + " (" + subjectAttrType.getId() + ")"); } return issue; }