/** * Return an array of attributes matching the passed in type OID. * * @param type the type of the attribute being looked for. * @return an array of Attribute of the requested type, zero length if none present. */ public Attribute[] getAttributes(ASN1ObjectIdentifier type) { ASN1Sequence seq = attrCert.getAcinfo().getAttributes(); List list = new ArrayList(); for (int i = 0; i != seq.size(); i++) { Attribute attr = Attribute.getInstance(seq.getObjectAt(i)); if (attr.getAttrType().equals(type)) { list.add(attr); } } if (list.size() == 0) { return EMPTY_ARRAY; } return (Attribute[])list.toArray(new Attribute[list.size()]); }
/** * * <pre> * SignerAttribute ::= SEQUENCE OF CHOICE { * claimedAttributes [0] ClaimedAttributes, * certifiedAttributes [1] CertifiedAttributes } * * ClaimedAttributes ::= SEQUENCE OF Attribute * CertifiedAttributes ::= AttributeCertificate -- as defined in RFC 3281: see clause 4.1. * </pre> */ 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 { v.add(new DERTaggedObject(1, (AttributeCertificate)values[i])); } } return new DERSequence(v); }
/** * Return the attributes, if any associated with this request. * * @return an array of Attribute, zero length if none present. */ public Attribute[] getAttributes() { ASN1Sequence seq = attrCert.getAcinfo().getAttributes(); Attribute[] attrs = new Attribute[seq.size()]; for (int i = 0; i != seq.size(); i++) { attrs[i] = Attribute.getInstance(seq.getObjectAt(i)); } return attrs; }
private SignerAttribute( 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] = AttributeCertificate.getInstance(ASN1Sequence.getInstance(taggedObject, true)); } else { throw new IllegalArgumentException("illegal tag: " + taggedObject.getTagNo()); } index++; } }
private String getSubjectDirectoryAttributesStringValue(byte[] value) throws IOException { // @formatter:off /* * SubjectDirectoryAttributes ::= ASN1Sequence SIZE (1..MAX) OF Attribute * * Attribute ::= ASN1Sequence * { * type AttributeType, * values SET OF AttributeValue * } */ // @formatter:on StringBuilder sb = new StringBuilder(); SubjectDirectoryAttributes subjectDirectoryAttributes = SubjectDirectoryAttributes.getInstance(value); for (Object attribute : subjectDirectoryAttributes.getAttributes()) { ASN1ObjectIdentifier attributeType = ((Attribute) attribute).getAttrType(); String attributeTypeStr = attributeType.getId(); 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(); }
/** * @param at an object representing an attribute. */ X509Attribute( ASN1Encodable at) { this.attr = Attribute.getInstance(at); }
/** * add an attribute */ public void addAttribute( X509Attribute attribute) { acInfoGen.addAttribute(Attribute.getInstance(attribute.toASN1Object())); }
public SignerAttribute( Attribute[] claimedAttributes) { this.values = new Object[1]; this.values[0] = claimedAttributes; }
/** * Parses the contents of an attribute certificate.<br> * <b>NOTE:</b> Cryptographic signatures, time stamps etc. will <b>not</b> be checked. * * @param ac the attribute certificate to parse for VOMS attributes */ public VOMSAttribute(X509AttributeCertificateHolder ac) { if (ac == null) { throw new IllegalArgumentException("VOMSAttribute: AttributeCertificate is NULL"); } myAC = ac; Attribute[] l = ac.getAttributes(new ASN1ObjectIdentifier(VOMS_ATTR_OID)); if (l == null) { return; } try { for (int i = 0; i != l.length; i++) { IetfAttrSyntax attr = IetfAttrSyntax.getInstance(l[i].getAttributeValues()[0]); // policyAuthority is on the format <vo>/<host>:<port> String url = ((DERIA5String)attr.getPolicyAuthority().getNames()[0].getName()).getString(); int idx = url.indexOf("://"); if ((idx < 0) || (idx == (url.length() - 1))) { throw new IllegalArgumentException("Bad encoding of VOMS policyAuthority : [" + url + "]"); } myVo = url.substring(0, idx); myHostPort = url.substring(idx + 3); if (attr.getValueType() != IetfAttrSyntax.VALUE_OCTETS) { throw new IllegalArgumentException( "VOMS attribute values are not encoded as octet strings, policyAuthority = " + url); } ASN1OctetString[] values = (ASN1OctetString[])attr.getValues(); for (int j = 0; j != values.length; j++) { String fqan = new String(values[j].getOctets()); FQAN f = new FQAN(fqan); if (!myStringList.contains(fqan) && fqan.startsWith("/" + myVo + "/")) { myStringList.add(fqan); myFQANs.add(f); } } } } catch (IllegalArgumentException ie) { throw ie; } catch (Exception e) { throw new IllegalArgumentException("Badly encoded VOMS extension in AC issued by " + ac.getIssuer()); } }
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(); }