List of usage examples for org.bouncycastle.asn1 DERSequence DERSequence
public DERSequence(ASN1Encodable[] elements)
From source file:org.glite.voms.ac.AttributeCertificate.java
License:eu-egee.org license
/** * Produce an object suitable for an ASN1OutputStream. * <pre>/*from w w w . j a va 2 s. co m*/ * AttributeCertificate ::= SEQUENCE { * acinfo AttributeCertificateInfo, * signatureAlgorithm AlgorithmIdentifier, * signatureValue BIT STRING * } * </pre> */ public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(acInfo); v.add(signatureAlgorithm); v.add(signatureValue); return new DERSequence(v); }
From source file:org.glite.voms.ac.AttributeCertificateInfo.java
License:eu-egee.org license
public AttributeCertificateInfo(ASN1Sequence seq) throws IOException { DERObjectIdentifier AC_TARGET_OID_DER = new DERObjectIdentifier(AC_TARGET_OID); DERObjectIdentifier AC_CERTS_OID_DER = new DERObjectIdentifier(AC_CERTS_OID); DERObjectIdentifier AC_FULL_ATTRIBUTES_OID_DER = new DERObjectIdentifier(AC_FULL_ATTRIBUTES_OID); version = (DERInteger) seq.getObjectAt(0); holder = new Holder((ASN1Sequence) seq.getObjectAt(1)); issuer = new AttCertIssuer(seq.getObjectAt(2)); signature = new AlgorithmIdentifier((ASN1Sequence) seq.getObjectAt(3)); serialNumber = (DERInteger) seq.getObjectAt(4); // VOMS has encoding problems of attCertValidity (uses PrivateKeyUsagePeriod syntax instead) ASN1Sequence s2 = (ASN1Sequence) seq.getObjectAt(5); ASN1Sequence s3 = s2;//from w w w . j av a 2s.c o m if (s2.getObjectAt(0) instanceof ASN1TaggedObject) { badVomsEncoding = true; DEREncodableVector v = new DEREncodableVector(); for (int i = 0; i < 2; i++) { byte[] bb = ((DEROctetString) ((ASN1TaggedObject) s2.getObjectAt(i)).getObject()).getOctets(); v.add(new DERGeneralizedTime(new String(bb))); } s3 = (ASN1Sequence) new DERSequence(v); } attrCertValidityPeriod = AttCertValidityPeriod.getInstance(s3); attributes = (ASN1Sequence) seq.getObjectAt(6); // getting FQANs // System.out.println("Getting FQANs"); if (attributes != null && attributes.size() != 0) { for (Enumeration e = attributes.getObjects(); e.hasMoreElements();) { // DERObject o = (DERObject)e.nextElement(); // byte[] value = null; // try { // value = o.getEncoded(); // } // catch(Exception ex) {} // System.out.println("Class is: " + o.getClass()); // System.out.print("Value is: "); // for (int i =0; i < value.length; i++) // System.out.print(Integer.toHexString(value[i]) + " "); // System.out.println(); ASN1Sequence attribute = (ASN1Sequence) e.nextElement(); if (VOMS_ATTR_OID.equals(((DERObjectIdentifier) attribute.getObjectAt(0)).getId())) { DLSet set = (DLSet) attribute.getObjectAt(1); for (Enumeration s = set.getObjects(); s.hasMoreElements();) { IetfAttrSyntax attr = new IetfAttrSyntax((ASN1Sequence) s.nextElement()); String url = ((DERIA5String) GeneralName .getInstance( ((ASN1Sequence) attr.getPolicyAuthority().toASN1Primitive()).getObjectAt(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); idx = myHostPort.lastIndexOf(":"); if ((idx < 0) || (idx == (myHostPort.length() - 1))) { throw new IllegalArgumentException( "Bad encoding of VOMS policyAuthority : [" + url + "]"); } myHost = myHostPort.substring(0, idx); myPort = Integer.valueOf(myHostPort.substring(idx + 1)).intValue(); if (attr.getValueType() != IetfAttrSyntax.VALUE_OCTETS) { throw new IllegalArgumentException( "VOMS attribute values are not encoded as octet strings, policyAuthority = " + url); } for (Iterator j = attr.getValues().iterator(); j.hasNext();) { String fqan = new String(((ASN1OctetString) j.next()).getOctets()); FQAN f = new FQAN(fqan); // maybe requiring that the attributes start with vo is too much? if (!myStringList.contains(fqan) && (fqan.startsWith("/" + myVo + "/") || fqan.equals("/" + myVo))) { myStringList.add(fqan); myFQANs.add(f); } } } } } } // check if the following two can be detected better!!! // for example, is it possible to have only the extensions? how to detect this? if (seq.size() > 8) { issuerUniqueID = new DERBitString(seq.getObjectAt(7)); extensions = new X509Extensions((ASN1Sequence) seq.getObjectAt(8)); } else if (seq.size() > 7) { extensions = new X509Extensions((ASN1Sequence) seq.getObjectAt(7)); } // start parsing of known extensions // System.out.println("Getting AC_TARGET"); if (extensions.getExtension(AC_TARGET_OID_DER) != null) { byte[] data = (extensions.getExtension(AC_TARGET_OID_DER).getValue().getOctets()); ASN1Primitive dobj = null; try { dobj = new ASN1InputStream(new ByteArrayInputStream(data)).readObject(); // System.out.println("DOBJ Class: " + dobj.getClass()); acTargets = new ACTargets(ASN1Sequence.getInstance(dobj)); } catch (Exception e) { throw new IllegalArgumentException("DERO: " + e.getMessage(), e); } } // System.out.println("Getting AC_CERTS"); if (extensions.getExtension(AC_CERTS_OID_DER) != null) { byte[] data = (extensions.getExtension(AC_CERTS_OID_DER).getValue().getOctets()); ASN1Primitive dobj = null; try { dobj = new ASN1InputStream(new ByteArrayInputStream(data)).readObject(); // System.out.println("DOBJ Class: " + dobj.getClass()); acCerts = new ACCerts(ASN1Sequence.getInstance(dobj)); } catch (Exception e) { throw new IllegalArgumentException("DERO: " + e.getMessage(), e); } } // System.out.println("Getting FULL_ATTRIBUTES"); if (extensions.getExtension(AC_FULL_ATTRIBUTES_OID_DER) != null) { byte[] data = (extensions.getExtension(AC_FULL_ATTRIBUTES_OID_DER).getValue().getOctets()); ASN1Primitive dobj = null; try { dobj = new ASN1InputStream(new ByteArrayInputStream(data)).readObject(); // System.out.println("DOBJ Class: " + dobj.getClass()); fullAttributes = new FullAttributes(ASN1Sequence.getInstance(dobj)); } catch (Exception e) { throw new IllegalArgumentException("DERO: " + e.getMessage()); } } }
From source file:org.glite.voms.ac.AttributeCertificateInfo.java
License:eu-egee.org license
/** * Produce an object suitable for an ASN1OutputStream. * * <pre>//from ww w . j a v a 2 s . c o m * * * * AttributeCertificateInfo ::= SEQUENCE { * version AttCertVersion -- version is v2, * holder Holder, * issuer AttCertIssuer, * signature AlgorithmIdentifier, * serialNumber CertificateSerialNumber, * attrCertValidityPeriod AttCertValidityPeriod, * attributes SEQUENCE OF Attribute, * issuerUniqueID UniqueIdentifier OPTIONAL, * extensions Extensions OPTIONAL * } * * AttCertVersion ::= INTEGER { v2(1) } * * * * </pre> */ public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(version); v.add(holder); v.add(issuer); v.add(signature); v.add(serialNumber); if (!badVomsEncoding) { v.add(attrCertValidityPeriod); } else { DEREncodableVector v2 = new DEREncodableVector(); v2.add(new DERTaggedObject(false, 0, new DEROctetString( (attrCertValidityPeriod.getNotBeforeTime().getTime().substring(0, 14) + "Z").getBytes()))); v2.add(new DERTaggedObject(false, 1, new DEROctetString( (attrCertValidityPeriod.getNotAfterTime().getTime().substring(0, 14) + "Z").getBytes()))); v.add(new DERSequence(v2)); } v.add(attributes); if (issuerUniqueID != null) { v.add(issuerUniqueID); } if (extensions != null) { v.add(extensions); } return new DERSequence(v); }
From source file:org.glite.voms.ac.AttributeHolder.java
License:Open Source License
/** * Makes a DERObject representation./*from w ww. j a v a 2s . co m*/ * * @return the DERObject */ public ASN1Primitive toASN1Primitive() { DEREncodableVector v = new DEREncodableVector(); v.add(grantor); DEREncodableVector v2 = new DEREncodableVector(); for (ListIterator li = l.listIterator(); li.hasNext();) { GenericAttribute att = (GenericAttribute) li.next(); v2.add(att); } ASN1Sequence seq = (ASN1Sequence) new DERSequence(v2); v.add(seq); return new DERSequence(v); }
From source file:org.glite.voms.ac.FullAttributes.java
License:Open Source License
/** * Makes a DERObject representation.//ww w . j a v a 2 s.c o m * * @return the DERObject */ public ASN1Primitive toASN1Primitive() { DEREncodableVector v2 = new DEREncodableVector(); for (ListIterator li = l.listIterator(); li.hasNext();) { AttributeHolder holder = (AttributeHolder) li.next(); v2.add(holder); } ASN1Sequence seq = (ASN1Sequence) new DERSequence(v2); DEREncodableVector v = new DEREncodableVector(); v.add(seq); return new DERSequence(v); }
From source file:org.glite.voms.ac.GenericAttribute.java
License:Open Source License
/** * Makes a DERObject representation./*w w w . j a v a2 s. c o m*/ * * @return the DERObject */ public ASN1Primitive toASN1Primitive() { DEREncodableVector v = new DEREncodableVector(); v.add(new DEROctetString(name.getBytes())); v.add(new DEROctetString(value.getBytes())); v.add(new DEROctetString(qualifier.getBytes())); return new DERSequence(v); }
From source file:org.glite.voms.ac.Holder.java
License:eu-egee.org license
public Holder(X500Principal issuer, BigInteger serial) { DEREncodableVector v = new DEREncodableVector(); v.add(Util.x500nameToGeneralNames(issuer)); v.add(new DERInteger(serial)); baseCertificateID = IssuerSerial.getInstance(new DERSequence(v)); }
From source file:org.glite.voms.ac.Holder.java
License:eu-egee.org license
public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); if (baseCertificateID != null) { v.add(new DERTaggedObject(false, 0, baseCertificateID)); }//from w w w . j av a2s.c om if (entityName != null) { v.add(new DERTaggedObject(false, 1, entityName)); } if (objectDigestInfo != null) { v.add(new DERTaggedObject(false, 2, objectDigestInfo)); } return new DERSequence(v); }
From source file:org.glite.voms.ac.IetfAttrSyntax.java
License:eu-egee.org license
public ASN1Primitive toASN1Primitive() { DEREncodableVector v = new DEREncodableVector(); if (policyAuthority != null) { v.add(new DERTaggedObject(0, policyAuthority)); }//from w ww . j av a2s. c o m DEREncodableVector v2 = new DEREncodableVector(); for (Iterator i = values.iterator(); i.hasNext();) { v2.add((ASN1Encodable) i.next()); } v.add(new DERSequence(v2)); return new DERSequence(v); }
From source file:org.glite.voms.ac.ObjectDigestInfo.java
License:eu-egee.org license
/** * Produce an object suitable for an ASN1OutputStream. * <pre>/* w ww .jav a2 s . co m*/ * ObjectDigestInfo ::= SEQUENCE { * digestedObjectType ENUMERATED { * publicKey (0), * publicKeyCert (1), * otherObjectTypes (2) }, * -- otherObjectTypes MUST NOT * -- be used in this profile * otherObjectTypeID OBJECT IDENTIFIER OPTIONAL, * digestAlgorithm AlgorithmIdentifier, * objectDigest BIT STRING * } * </pre> */ public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(digestedObjectType); if (otherObjectTypeID != null) { v.add(otherObjectTypeID); } v.add(digestAlgorithm); v.add(objectDigest); return new DERSequence(v); }