List of usage examples for org.bouncycastle.asn1 DERSequence getObjects
public Enumeration getObjects()
From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java
License:Open Source License
@SuppressWarnings("unchecked") private static List<String> getDERValue(final DERObject derObj) { if (derObj instanceof DERSequence) { final List<String> ret = new LinkedList<String>(); final DERSequence seq = (DERSequence) derObj; final Enumeration<DERObject> enum1 = seq.getObjects(); while (enum1.hasMoreElements()) { final DERObject nestedObj = (DERObject) enum1.nextElement(); final List<String> appo = getDERValue(nestedObj); if (appo != null) { ret.addAll(appo);/* w w w.j a v a 2 s . c o m*/ } } return ret; } if (derObj instanceof DERTaggedObject) { final DERTaggedObject derTag = (DERTaggedObject) derObj; if (derTag.isExplicit() && !derTag.isEmpty()) { final DERObject nestedObj = derTag.getObject(); return getDERValue(nestedObj); } else { final DEROctetString derOct = (DEROctetString) derTag.getObject(); final String val = new String(derOct.getOctets()); return Collections.singletonList(val); } } return null; }
From source file:com.vmware.identity.idm.server.clientcert.IdmClientCertificateValidator.java
License:Open Source License
/** * Find any DER-encoded String inside a DER sequence * * @param derSeq//from ww w . j a v a 2s . c om * @return The first string value inside this sequence, or null if none is found */ private static String getStringFromSequence(DERSequence derSeq) { if (null == derSeq) return null; Enumeration<?> objects = derSeq.getObjects(); while (objects.hasMoreElements()) { ASN1Primitive o = (ASN1Primitive) objects.nextElement(); String retVal = getStringFromObject(o); if (null != retVal) { return retVal; } } return null; }
From source file:ec.gov.informatica.firmadigital.FirmaDigital.java
License:Open Source License
/** * para parsear el objeto y te devuelve el listado con las urls de los * puntos de distribucin// ww w . ja v a 2s .c o m * * @param derObj * @return */ @SuppressWarnings("unchecked") private List<String> getDERValue(DERObject derObj) { if (derObj instanceof DERSequence) { List<String> list = new LinkedList<String>(); DERSequence seq = (DERSequence) derObj; Enumeration enumeracion = seq.getObjects(); while (enumeracion.hasMoreElements()) { DERObject nestedObj = (DERObject) enumeracion.nextElement(); List<String> appo = getDERValue(nestedObj); if (appo != null) { list.addAll(appo); } } return list; } else if (derObj instanceof DERTaggedObject) { DERTaggedObject derTag = (DERTaggedObject) derObj; if ((derTag.isExplicit() && !derTag.isEmpty()) || derTag.getObject() instanceof DERSequence) { DERObject nestedObj = derTag.getObject(); List<String> ret = getDERValue(nestedObj); return ret; } else { DEROctetString derOct = (DEROctetString) derTag.getObject(); String val = new String(derOct.getOctets()); List<String> ret = new LinkedList<String>(); ret.add(val); return ret; } } else if (derObj instanceof DERSet) { Enumeration enumSet = ((DERSet) derObj).getObjects(); List<String> list = new LinkedList<String>(); while (enumSet.hasMoreElements()) { DERObject nestedObj = (DERObject) enumSet.nextElement(); List<String> appo = getDERValue(nestedObj); if (appo != null) { list.addAll(appo); } } return list; } else if (derObj instanceof DERObjectIdentifier) { DERObjectIdentifier derId = (DERObjectIdentifier) derObj; List<String> list = new LinkedList<String>(); list.add(derId.getId()); return list; } else if (derObj instanceof DERPrintableString) { // hemos localizado un par id-valor String valor = ((DERPrintableString) derObj).getString(); List<String> list = new LinkedList<String>(); list.add(valor); return list; } else { System.out.println("tipo de dato en ASN1 al recuperar las crls no es reconocido : " + derObj); } return null; }
From source file:ec.gov.informatica.firmadigital.signature.BouncyCastleSignatureProcessor.java
License:Open Source License
/** * para parsear el objeto y te devuelve el listado con las urls de los puntos de distribucin //www . j a v a 2s . co m * @param derObj * @return */ @SuppressWarnings("unchecked") private List<String> getDERValue(DERObject derObj) { if (derObj instanceof DERSequence) { List<String> list = new LinkedList<String>(); DERSequence seq = (DERSequence) derObj; Enumeration enumeracion = seq.getObjects(); while (enumeracion.hasMoreElements()) { DERObject nestedObj = (DERObject) enumeracion.nextElement(); List<String> appo = getDERValue(nestedObj); if (appo != null) { list.addAll(appo); } } return list; } else if (derObj instanceof DERTaggedObject) { DERTaggedObject derTag = (DERTaggedObject) derObj; if ((derTag.isExplicit() && !derTag.isEmpty()) || derTag.getObject() instanceof DERSequence) { DERObject nestedObj = derTag.getObject(); List<String> ret = getDERValue(nestedObj); return ret; } else { DEROctetString derOct = (DEROctetString) derTag.getObject(); String val = new String(derOct.getOctets()); List<String> ret = new LinkedList<String>(); ret.add(val); return ret; } } else if (derObj instanceof DERSet) { Enumeration enumSet = ((DERSet) derObj).getObjects(); List<String> list = new LinkedList<String>(); while (enumSet.hasMoreElements()) { DERObject nestedObj = (DERObject) enumSet.nextElement(); List<String> appo = getDERValue(nestedObj); if (appo != null) { list.addAll(appo); } } return list; } else if (derObj instanceof DERObjectIdentifier) { DERObjectIdentifier derId = (DERObjectIdentifier) derObj; List<String> list = new LinkedList<String>(); list.add(derId.getId()); return list; } else if (derObj instanceof DERPrintableString) { // hemos localizado un par id-valor String valor = ((DERPrintableString) derObj).getString(); List<String> list = new LinkedList<String>(); list.add(valor); return list; } else { System.out.println("tipo de dato en ASN1 al recuperar las crls no es reconocido : " + derObj); } return null; }
From source file:eu.betaas.taas.securitymanager.common.ec.ECKeyPairGen.java
License:Apache License
/** * A method to reconstruct an ECPublicKey from a SubjectPublicKeyInfo of a * certificate /*from w w w . j a v a 2s .c om*/ * @param info: SubjectPublicKeyInfo in a X509Certificate * @return: ECPublicKeyParameters */ public static ECPublicKeyParameters generateECPublicKey(SubjectPublicKeyInfo info) { X962Parameters as = (X962Parameters) info.getAlgorithm().getParameters(); DERSequence aa = (DERSequence) as.getParameters(); Enumeration en = aa.getObjects(); ECCurve curve = null; org.bouncycastle.math.ec.ECPoint g = null; byte[] seed = null; BigInteger h = null; BigInteger n = null; while (en.hasMoreElements()) { Object oen = en.nextElement(); if (oen instanceof X9Curve) { curve = ((X9Curve) oen).getCurve(); seed = ((X9Curve) oen).getSeed(); } else if (oen instanceof X9ECPoint) { g = ((X9ECPoint) oen).getPoint(); } else if (oen instanceof ASN1Integer) { BigInteger xoen = ((ASN1Integer) oen).getValue(); if (xoen.equals(BigInteger.ONE)) h = xoen; else n = xoen; } } ASN1OctetString key = new DEROctetString(info.getPublicKeyData().getBytes()); X9ECPoint derQ = new X9ECPoint(curve, key); ECDomainParameters dParams = new ECDomainParameters(curve, g, n, h, seed); return new ECPublicKeyParameters(derQ.getPoint(), dParams); }
From source file:eu.emi.security.authn.x509.helpers.proxy.ProxyAddressRestrictionData.java
License:Open Source License
/** * This method copies the contents of a generalSubtrees sequence into * the given vector. Static to protect the internal data structures from * access./*from ww w . jav a 2 s. c o m*/ * * @param subSeq * the subsequence to copy. * @param vector * The target to copy the parsed GeneralSubtree objects. */ private static void copyCondSequenceToVector(DERSequence subSeq, List<GeneralSubtree> vector) { Enumeration<?> subTreeEnum = subSeq.getObjects(); while (subTreeEnum.hasMoreElements()) { ASN1Primitive object = (ASN1Primitive) subTreeEnum.nextElement(); vector.add(GeneralSubtree.getInstance(object)); } }
From source file:net.sf.assinafacil.UtiICPBrasill.java
License:Open Source License
/** * Interpreta um dado do tipo otherName. * Obs. O JDK 5.0 no tem classes que lidem com um dado do tipo OtherName. * necessrio usar o BouncyCastle. //from w w w . ja v a 2 s. co m * @param encoded O dado em ASN.1. * @return Um par contendo o OID e o contedo. */ private static Pair<DERObjectIdentifier, String> getOtherName(byte[] encoded) throws IOException { // O JDK 5.0 no tem classes que lidem com um dado do tipo OtherName. // necessrio usar o BouncyCastle. ASN1InputStream inps = new ASN1InputStream(encoded); DERSequence seq = null; DERObjectIdentifier oid = null; String conteudo = ""; seq = (DERSequence) inps.readObject(); inps.close(); Enumeration en = seq.getObjects(); oid = (DERObjectIdentifier) en.nextElement(); DERObject obj = ((ASN1TaggedObject) ((ASN1TaggedObject) en.nextElement()).getObject()).getObject(); if (obj instanceof DERString) { // Certificados antigos SERASA - incorretos conteudo = ((DERString) obj).getString(); } else if (obj instanceof DEROctetString) { // Certificados corretos conteudo = new String(((DEROctetString) obj).getOctets(), "ISO-8859-1"); } return new Pair<DERObjectIdentifier, String>(oid, conteudo); }
From source file:net.sf.assinafacil.UtiICPBrasill.java
License:Open Source License
private static Vector getDERValue(DERObject derObj) { if (derObj instanceof DERSequence) { Vector ret = new Vector(); DERSequence seq = (DERSequence) derObj; Enumeration enume = seq.getObjects(); while (enume.hasMoreElements()) { DERObject nestedObj = (DERObject) enume.nextElement(); Vector appo = getDERValue(nestedObj); if (appo != null) { ret.addAll(appo);/*from www .j a va2s .c o m*/ } } return ret; } if (derObj instanceof DERTaggedObject) { DERTaggedObject derTag = (DERTaggedObject) derObj; if (derTag.isExplicit() && !derTag.isEmpty()) { DERObject nestedObj = derTag.getObject(); Vector ret = getDERValue(nestedObj); return ret; } else { DEROctetString derOct = (DEROctetString) derTag.getObject(); String val = new String(derOct.getOctets()); Vector ret = new Vector(); ret.add(val); return ret; } } return null; }
From source file:nl.uva.vlet.grid.voms.VOMSAttributeCertificate.java
License:Apache License
private String DERSequencetoDN(DERSequence this_sequence) throws Exception { String thisDN = ""; try {/* w w w . j a va2s . c o m*/ for (Enumeration n = this_sequence.getObjects(); n.hasMoreElements();) { DERSet this_set = (DERSet) n.nextElement(); DERSequence this_seq = (DERSequence) this_set.getObjectAt(0); try { DERPrintableString this_string = (DERPrintableString) this_seq.getObjectAt(1); thisDN = thisDN.concat("/" + Translate_OID.getStringFromOID("" + this_seq.getObjectAt(0)) + "=" + this_string.getString()); } catch (Exception notPS) { // email is encoded differently? DERIA5String this_string = (DERIA5String) this_seq.getObjectAt(1); thisDN = thisDN.concat("/" + Translate_OID.getStringFromOID("" + this_seq.getObjectAt(0)) + "=" + this_string.getString()); } } } catch (Exception e) { throw e; } return thisDN; }
From source file:org.candlepin.util.X509CRLStreamWriter.java
License:Open Source License
/** * This method updates the crlNumber and authorityKeyIdentifier extensions. Any * other extensions are copied over unchanged. * @param extensions/* w w w .j av a2 s. c o m*/ * @return * @throws IOException */ @SuppressWarnings("rawtypes") protected byte[] updateExtensions(byte[] obj) throws IOException { DERTaggedObject taggedExts = (DERTaggedObject) DERTaggedObject.fromByteArray(obj); DERSequence seq = (DERSequence) taggedExts.getObject(); ASN1EncodableVector modifiedExts = new ASN1EncodableVector(); // Now we need to read the extensions and find the CRL number and increment it, // and determine if its length changed. Enumeration objs = seq.getObjects(); while (objs.hasMoreElements()) { DERSequence ext = (DERSequence) objs.nextElement(); DERObjectIdentifier oid = (DERObjectIdentifier) ext.getObjectAt(0); if (X509Extension.cRLNumber.equals(oid)) { DEROctetString s = (DEROctetString) ext.getObjectAt(1); DERInteger i = (DERInteger) DERTaggedObject.fromByteArray(s.getOctets()); DERInteger newCrlNumber = new DERInteger(i.getValue().add(BigInteger.ONE)); X509Extension newNumberExt = new X509Extension(false, new DEROctetString(newCrlNumber.getDEREncoded())); ASN1EncodableVector crlNumber = new ASN1EncodableVector(); crlNumber.add(X509Extension.cRLNumber); crlNumber.add(newNumberExt.getValue()); modifiedExts.add(new DERSequence(crlNumber)); } else if (X509Extension.authorityKeyIdentifier.equals(oid)) { X509Extension newAuthorityKeyExt = new X509Extension(false, new DEROctetString(akiStructure.getDEREncoded())); ASN1EncodableVector aki = new ASN1EncodableVector(); aki.add(X509Extension.authorityKeyIdentifier); aki.add(newAuthorityKeyExt.getValue()); modifiedExts.add(new DERSequence(aki)); } else { modifiedExts.add(ext); } } DERSequence seqOut = new DERSequence(modifiedExts); DERTaggedObject out = new DERTaggedObject(true, 0, seqOut); return out.getDEREncoded(); }