List of usage examples for org.bouncycastle.asn1 DEROctetString DEROctetString
public DEROctetString(ASN1Encodable obj) throws IOException
From source file:org.glite.slcs.pki.CertificateExtensionFactory.java
License:eu-egee.org license
/** * /*from ww w . ja v a 2s. c o m*/ * @param keyPurposeId * @param keyPurposeName * @return */ static protected CertificateExtension createExtendedKeyUsageExtension(KeyPurposeId keyPurposeId, String keyPurposeName) { DERSequence keyPurposeIds = new DERSequence(keyPurposeId); ExtendedKeyUsage extendedKeyUsage = new ExtendedKeyUsage(keyPurposeIds); X509Extension extendedKeyUsageExtension = new X509Extension(false, new DEROctetString(extendedKeyUsage)); return new CertificateExtension(X509Extensions.ExtendedKeyUsage, "ExtendedKeyUsage", extendedKeyUsageExtension, keyPurposeName); }
From source file:org.glite.slcs.pki.CertificateExtensionFactory.java
License:eu-egee.org license
/** * Creates a RFC882 Subject Alternative Name: email:johndoe@example.com * extension.// ww w . ja v a 2 s.co m * * @param emailAddress * The email address to be included as alternative name. * @return The subject alternative name CertificateExtension. */ static protected CertificateExtension createSubjectAltNameExtension(String emailAddress) { GeneralName subjectAltName = new GeneralName(GeneralName.rfc822Name, emailAddress); GeneralNames subjectAltNames = new GeneralNames(subjectAltName); X509Extension subjectAltNameExtension = new X509Extension(false, new DEROctetString(subjectAltNames)); return new CertificateExtension(X509Extensions.SubjectAlternativeName, "SubjectAltName", subjectAltNameExtension, emailAddress); }
From source file:org.glite.slcs.pki.CertificateExtensionFactory.java
License:eu-egee.org license
/** * /* w w w .j a v a 2 s . c o m*/ * @param prefixedAltNames * @param values * @return */ static protected CertificateExtension createSubjectAltNameExtension(Vector prefixedAltNames, String values) { ASN1EncodableVector altNames = new ASN1EncodableVector(); Enumeration typeAndNames = prefixedAltNames.elements(); while (typeAndNames.hasMoreElements()) { String typeAndName = (String) typeAndNames.nextElement(); typeAndName = typeAndName.trim(); if (typeAndName.startsWith("email:")) { String emailAddress = typeAndName.substring("email:".length()); GeneralName altName = new GeneralName(GeneralName.rfc822Name, emailAddress); altNames.add(altName); } else if (typeAndName.startsWith("dns:")) { String hostname = typeAndName.substring("dns:".length()); GeneralName altName = new GeneralName(GeneralName.dNSName, hostname); altNames.add(altName); } else { LOG.error("Unsupported subjectAltName: " + typeAndName); } } DERSequence subjectAltNames = new DERSequence(altNames); GeneralNames generalNames = new GeneralNames(subjectAltNames); X509Extension subjectAltNameExtension = new X509Extension(false, new DEROctetString(generalNames)); return new CertificateExtension(X509Extensions.SubjectAlternativeName, "SubjectAltName", subjectAltNameExtension, values); }
From source file:org.glite.slcs.pki.CertificateExtensionFactory.java
License:eu-egee.org license
/** * Creates a Cerificate Policies: policyOID extension with the given policy * OID./*from w w w. ja v a 2s. co m*/ * * @param policyOID * The policy OID (2.16.756.1.2.*) * @return The certificate policies CertificateExtension. */ static protected CertificateExtension createCertificatePoliciesExtension(String policyOID) { DERObjectIdentifier policyIdentifier = new DERObjectIdentifier(policyOID); PolicyInformation policyInformation = new PolicyInformation(policyIdentifier); DERSequence certificatePolicies = new DERSequence(policyInformation); X509Extension certificatePoliciesExtension = new X509Extension(false, new DEROctetString(certificatePolicies)); return new CertificateExtension(X509Extensions.CertificatePolicies, "CertificatePolicies", certificatePoliciesExtension, policyOID); }
From source file:org.glite.slcs.pki.CertificateExtensionFactory.java
License:eu-egee.org license
/** * //from w w w .ja v a2 s. c o m * @param policyOIDs * @param values * @return */ static protected CertificateExtension createCertificatePoliciesExtension(Vector policyOIDs, String values) { ASN1EncodableVector policyInformations = new ASN1EncodableVector(); Enumeration pOids = policyOIDs.elements(); while (pOids.hasMoreElements()) { String policyOid = (String) pOids.nextElement(); DERObjectIdentifier policyIdentifier = new DERObjectIdentifier(policyOid); PolicyInformation policyInformation = new PolicyInformation(policyIdentifier); policyInformations.add(policyInformation); } DERSequence certificatePolicies = new DERSequence(policyInformations); X509Extension certificatePoliciesExtension = new X509Extension(false, new DEROctetString(certificatePolicies)); return new CertificateExtension(X509Extensions.CertificatePolicies, "CertificatePolicies", certificatePoliciesExtension, values); }
From source file:org.glite.slcs.pki.CertificateExtensionFactory.java
License:eu-egee.org license
/** * Creates a Key Usage extension for the given usage. This extension is * critical./*from w w w.ja v a 2 s.co m*/ * * @param usage * The usage is the sum of all KeyUsage values. * @param value * The formal value of the usage. Example: * KeyEncipherment,DigitalSignature * @return The KeyUsage certificate extension. * @see org.bouncycastle.asn1.x509.KeyUsage */ static protected CertificateExtension createKeyUsageExtension(int usage, String value) { KeyUsage keyUsage = new KeyUsage(usage); // KeyUsage is critical X509Extension keyUsageExtension = new X509Extension(true, new DEROctetString(keyUsage)); return new CertificateExtension(X509Extensions.KeyUsage, "KeyUsage", keyUsageExtension, value, true); }
From source file:org.glite.voms.ac.AttributeCertificateInfo.java
License:eu-egee.org license
/** * Produce an object suitable for an ASN1OutputStream. * * <pre>//from w w w . j a v a 2s .c om * * * * 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.GenericAttribute.java
License:Open Source License
/** * Makes a DERObject representation.//www. j ava 2 s. c om * * @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.PKIUtils.java
License:Open Source License
/** * Gets the AuthorityKeyIdentifier extension form the passed certificate. * * @param cert The certificate from which to get the extension. * * @return the extension if present, or null if not present. *///from ww w. j a va 2s . c om static public AuthorityKeyIdentifier getAKID(X509Certificate cert) { if (cert != null) { byte[] akid = cert.getExtensionValue(AUTHORITY_KEY_IDENTIFIER); int i = 0; // if (akid != null) // for (i = 0; i < akid.length; i++) // System.out.print(akid[i] + " "); // System.out.println(""); if (akid != null) { ASN1OctetString string = new DEROctetString(akid); org.bouncycastle.asn1.x509.X509Extension ex = new org.bouncycastle.asn1.x509.X509Extension(false, string); // byte[] list = ex.getValue().getOctets(); // for (i = 0; i < list.length; i++) // System.out.print(list[i] + " "); // System.out.println("EXAMINED"); byte[] llist2 = string.getOctets(); // for (i = 0; i < llist2.length; i++) // System.out.print(llist2[i] + " "); // System.out.println(""); ASN1Primitive dobj = null; try { dobj = new ASN1InputStream(new ByteArrayInputStream(llist2)).readObject(); dobj = new ASN1InputStream(new ByteArrayInputStream(((DEROctetString) dobj).getOctets())) .readObject(); } catch (ClassCastException e) { throw new IllegalArgumentException( "Erroneous encoding in Authority Key Identifier " + e.getMessage()); } catch (Exception e) { throw new IllegalArgumentException( "While extracting Authority Key Identifier " + e.getMessage()); } // System.out.println("dobj is: " + dobj.getClass()); // System.out.println("dobj is also: " + dobj); // byte[] list2 = ((DEROctetString)dobj).getOctets(); // for (i = 0; i < list2.length; i++) // System.out.print(list2[i] + " "); // System.out.println(""); return AuthorityKeyIdentifier.getInstance(ASN1Sequence.getInstance(dobj)); } } return null; }
From source file:org.globus.gsi.proxy.ext.ProxyPolicy.java
License:Apache License
/** * Creates a new instance of the ProxyPolicy object. * * @param policyLanguage the language policy Oid. * @param policy the policy.//from w w w . ja v a 2s.co m */ public ProxyPolicy(ASN1ObjectIdentifier policyLanguage, byte[] policy) { if (policyLanguage == null) { throw new IllegalArgumentException(); } this.policyLanguage = policyLanguage; if (policy != null) { this.policy = new DEROctetString(policy); } checkConstraints(); }