use of com.github.zhenwei.core.asn1.ASN1Encodable in project keystore-explorer by kaikramer.
the class X509Ext method getSubjectDirectoryAttributesStringValue.
private static String getSubjectDirectoryAttributesStringValue(byte[] value) throws IOException {
// @formatter:off
/*
* SubjectDirectoryAttributes ::= ASN1Sequence SIZE (1..MAX) OF Attribute
*
* Attribute ::= ASN1Sequence
* {
* type AttributeType,
* values SET OF AttributeValue
* }
*
* RFC 3739: "Compliant implementations SHALL be able to interpret the following attributes:"
* DateOfBirth (1.3.6.1.5.5.7.9.1) ::= GeneralizedTime
* PlaceOfBirth (1.3.6.1.5.5.7.9.2) ::= DirectoryString
* Gender (1.3.6.1.5.5.7.9.3) ::= PrintableString (SIZE(1)) -- "M", "F", "m" or "f"
* CountryOfCitizenship (1.3.6.1.5.5.7.9.4) ::= PrintableString (SIZE (2)) -- ISO 3166 Country Code
* CountryOfResidence (1.3.6.1.5.5.7.9.5) ::= PrintableString (SIZE (2)) -- ISO 3166 Country Code
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
SubjectDirectoryAttributes subjectDirectoryAttributes = SubjectDirectoryAttributes.getInstance(value);
for (Object attribute : subjectDirectoryAttributes.getAttributes()) {
ASN1ObjectIdentifier attributeType = ((Attribute) attribute).getAttrType();
AttributeTypeType att = AttributeTypeType.resolveOid(attributeType.getId());
String attributeTypeStr = (att == AttributeTypeType.UNKNOWN) ? attributeType.getId() : att.friendly();
ASN1Encodable[] attributeValues = ((Attribute) attribute).getAttributeValues();
for (ASN1Encodable attributeValue : attributeValues) {
String attributeValueStr = getAttributeValueString(attributeType, attributeValue);
sb.append(MessageFormat.format("{0}: {1}", attributeTypeStr, attributeValueStr));
sb.append(NEWLINE);
}
}
return sb.toString();
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project keystore-explorer by kaikramer.
the class GeneralNameUtil method parseUPN.
/**
* Parse UPN/otherName
*
* @param generalName otherName object
* @return UPN as string
*/
public static String parseUPN(GeneralName generalName) {
// OtherName ::= SEQUENCE {
// type-id OBJECT IDENTIFIER,
// value [0] EXPLICIT ANY DEFINED BY type-id }
ASN1Sequence otherName = (ASN1Sequence) generalName.getName();
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) otherName.getObjectAt(0);
if (UPN_OID.equals(oid.getId())) {
ASN1TaggedObject asn1TaggedObject = (ASN1TaggedObject) otherName.getObjectAt(1);
ASN1UTF8String upn = ASN1UTF8String.getInstance(asn1TaggedObject.getTagClass());
return MessageFormat.format(res.getString("GeneralNameUtil.OtherGeneralName"), "UPN", upn.getString());
}
// fallback to generic handling
ASN1Encodable value = otherName.getObjectAt(1);
try {
return MessageFormat.format(res.getString("GeneralNameUtil.OtherGeneralName"), ObjectIdUtil.toString(oid), HexUtil.getHexString(value.toASN1Primitive().getEncoded(ASN1Encoding.DER)));
} catch (IOException e) {
return MessageFormat.format(res.getString("GeneralNameUtil.OtherGeneralName"), ObjectIdUtil.toString(oid), "");
}
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project keystore-explorer by kaikramer.
the class GeneralNameUtil method toString.
/**
* Get string representation for all General Names.
*
* @param generalName General name
* @return String representation of general name
* @throws IOException If general name is invalid
*/
public static String toString(GeneralName generalName) throws IOException {
if (generalName == null) {
return "";
}
switch(generalName.getTagNo()) {
case GeneralName.ediPartyName:
/* EDIPartyName ::= SEQUENCE {
* nameAssigner [0] DirectoryString OPTIONAL,
* partyName [1] DirectoryString }
*/
ASN1Sequence ediPartyName = (ASN1Sequence) generalName.getName();
DirectoryString nameAssigner = DirectoryString.getInstance(ediPartyName.getObjectAt(0));
DirectoryString partyName = DirectoryString.getInstance(ediPartyName.getObjectAt(1));
String nameAssignerStr = null;
if (nameAssigner != null) {
// Optional
nameAssignerStr = nameAssigner.getString();
}
String partyNameStr = partyName.getString();
if (nameAssignerStr != null) {
return MessageFormat.format(res.getString("GeneralNameUtil.EdiPartyGeneralName"), nameAssignerStr, partyNameStr);
} else {
return MessageFormat.format(res.getString("GeneralNameUtil.EdiPartyGeneralNameNoAssigner"), partyNameStr);
}
case GeneralName.otherName:
return parseUPN(generalName);
case GeneralName.x400Address:
/*
* No support for this at the moment - just get a hex dump
* The Oracle CertificateFactory blows up if a certificate extension contains this anyway
*/
ASN1Encodable x400Address = generalName.getName();
return MessageFormat.format(res.getString("GeneralNameUtil.X400AddressGeneralName"), HexUtil.getHexString(x400Address.toASN1Primitive().getEncoded(ASN1Encoding.DER)));
default:
return safeToString(generalName, true);
}
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project keystore-explorer by kaikramer.
the class PolicyInformationUtil method toString.
/**
* Get string representation of policy qualifier info.
*
* @param policyQualifierInfo Policy qualifier info
* @return String representation of policy qualifier info
* @throws IOException If policy qualifier info is invalid
*/
public static String toString(PolicyQualifierInfo policyQualifierInfo) throws IOException {
StringBuilder sbPolicyQualifier = new StringBuilder();
ASN1ObjectIdentifier policyQualifierId = policyQualifierInfo.getPolicyQualifierId();
CertificatePolicyQualifierType certificatePolicyQualifierType = CertificatePolicyQualifierType.resolveOid(policyQualifierId.getId());
if (certificatePolicyQualifierType == PKIX_CPS_POINTER_QUALIFIER) {
DERIA5String cpsPointer = ((DERIA5String) policyQualifierInfo.getQualifier());
sbPolicyQualifier.append(MessageFormat.format(res.getString("PolicyInformationUtil.CpsPointer"), cpsPointer));
} else if (certificatePolicyQualifierType == PKIX_USER_NOTICE_QUALIFIER) {
ASN1Encodable userNoticeObj = policyQualifierInfo.getQualifier();
UserNotice userNotice = UserNotice.getInstance(userNoticeObj);
sbPolicyQualifier.append(MessageFormat.format(res.getString("PolicyInformationUtil.UserNotice"), toString(userNotice)));
}
return sbPolicyQualifier.toString();
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.
the class X509Name method equals.
/**
* @param inOrder if true the order of both X509 names must be the same,
* as well as the values associated with each element.
*/
public boolean equals(Object obj, boolean inOrder) {
if (!inOrder) {
return this.equals(obj);
}
if (obj == this) {
return true;
}
if (!(obj instanceof X509Name || obj instanceof ASN1Sequence)) {
return false;
}
ASN1Primitive derO = ((ASN1Encodable) obj).toASN1Primitive();
if (this.toASN1Primitive().equals(derO)) {
return true;
}
X509Name other;
try {
other = X509Name.getInstance(obj);
} catch (IllegalArgumentException e) {
return false;
}
int orderingSize = ordering.size();
if (orderingSize != other.ordering.size()) {
return false;
}
for (int i = 0; i < orderingSize; i++) {
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) ordering.elementAt(i);
ASN1ObjectIdentifier oOid = (ASN1ObjectIdentifier) other.ordering.elementAt(i);
if (oid.equals(oOid)) {
String value = (String) values.elementAt(i);
String oValue = (String) other.values.elementAt(i);
if (!equivalentStrings(value, oValue)) {
return false;
}
} else {
return false;
}
}
return true;
}
Aggregations