org.bouncycastle.asn1.x509.Attribute Java Examples

The following examples show how to use org.bouncycastle.asn1.x509.Attribute. 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: SignerAttributeV2.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * <pre>
 *  SignerAttributeV2 ::= SEQUENCE {
 *	 	claimedAttributes [0] ClaimedAttributes OPTIONAL,
 * 		certifiedAttributesV2 [1] CertifiedAttributesV2 OPTIONAL,
 * 		signedAssertions [2] SignedAssertions OPTIONAL
 *	}
 * </pre>
 */
@Override
public ASN1Primitive toASN1Primitive() {
	ASN1EncodableVector v = new ASN1EncodableVector();

	for (int i = 0; i != values.length; i++) {
		if (values[i] instanceof Attribute[]) {
			v.add(new DERTaggedObject(0, new DERSequence((Attribute[]) values[i])));
		} else if (values[i] instanceof CertifiedAttributesV2) {
			v.add(new DERTaggedObject(1, (CertifiedAttributesV2) values[i]));
		} else if (values[i] instanceof SignedAssertions) {
			v.add(new DERTaggedObject(2, (SignedAssertions) values[i]));
		} else {
			LOG.warn("Unsupported type {}", values[i]);
		}
	}

	return new DERSequence(v);
}
 
Example #2
Source File: SignerAttributeV2.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private SignerAttributeV2(ASN1Sequence seq) {
	int index = 0;
	values = new Object[seq.size()];

	for (Enumeration e = seq.getObjects(); e.hasMoreElements();) {
		ASN1TaggedObject taggedObject = ASN1TaggedObject.getInstance(e.nextElement());

		if (taggedObject.getTagNo() == 0) {
			ASN1Sequence attrs = ASN1Sequence.getInstance(taggedObject, true);
			Attribute[] attributes = new Attribute[attrs.size()];

			for (int i = 0; i != attributes.length; i++) {
				attributes[i] = Attribute.getInstance(attrs.getObjectAt(i));
			}
			values[index] = attributes;
		} else if (taggedObject.getTagNo() == 1) {
			values[index] = CertifiedAttributesV2.getInstance(ASN1Sequence.getInstance(taggedObject, true));
		} else if (taggedObject.getTagNo() == 2) {
		    	LOG.info("SAML assertion detected");
			values[index] = SignedAssertions.getInstance(ASN1Sequence.getInstance(taggedObject, true));
		} else {
			throw new IllegalArgumentException("illegal tag: " + taggedObject.getTagNo());
		}
		index++;
	}
}
 
Example #3
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 #4
Source File: X509Ext.java    From keystore-explorer with GNU General Public License v3.0 4 votes vote down vote up
private String getVeriSignNonVerified(byte[] octets) throws IOException {

		/*
		    NonVerified ::= SET OF ATTRIBUTE
		 */

		StringBuilder sb = new StringBuilder();

		ASN1Set asn1Set = ASN1Set.getInstance(octets);
		for (ASN1Encodable attribute : asn1Set.toArray()) {

			ASN1ObjectIdentifier attributeId = ((Attribute) attribute).getAttrType();
			ASN1Set attributeValues = ((Attribute) attribute).getAttrValues();

			for (ASN1Encodable attributeValue : attributeValues.toArray()) {

				String attributeValueStr = getAttributeValueString(attributeId, attributeValue);

				sb.append(MessageFormat.format("{0}={1}", attributeId.getId(), attributeValueStr));
				sb.append(NEWLINE);
			}
		}

		return sb.toString();
	}
 
Example #5
Source File: SignerAttributeV2.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SignerAttributeV2(Attribute[] claimedAttributes) {
	this.values = new Object[1];
	this.values[0] = claimedAttributes;
}