org.bouncycastle.asn1.x509.SubjectDirectoryAttributes Java Examples

The following examples show how to use org.bouncycastle.asn1.x509.SubjectDirectoryAttributes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: X509Ext.java    From keystore-explorer with GNU General Public License v3.0 4 votes vote down vote up
private 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();
}
 
Example #2
Source File: CertificateModel.java    From Spark with Apache License 2.0 4 votes vote down vote up
private String subjectDirectoryAttributesExtractor(ASN1Primitive primitive) {
	SubjectDirectoryAttributes sub = SubjectDirectoryAttributes.getInstance(primitive);
	return sub.toString();
}