List of usage examples for org.bouncycastle.asn1 DERTaggedObject isExplicit
public boolean isExplicit()
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);/*from www . j a v a2 s. co 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:de.carne.certmgr.store.provider.bouncycastle.BouncyCastleASN1Decoder.java
License:Open Source License
@Override public TaggedObject<ASN1Decoder> asn1EncodeTaggedObject(int... validTagNos) throws IOException { DERTaggedObject taggedObject = ensureType(DERTaggedObject.class); boolean explicit = taggedObject.isExplicit(); int tagNo = taggedObject.getTagNo(); if (validTagNos.length > 0) { boolean tagNoInvalid = true; for (int validTagNo : validTagNos) { if (validTagNo == tagNo) { tagNoInvalid = false;/*from ww w.j av a2 s . co m*/ break; } } if (tagNoInvalid) { throw new IOException( "Unexpected tag no: " + tagNo + " expected one of: " + Arrays.toString(validTagNos)); } } ASN1Decoder objectDecoder = new BouncyCastleASN1Decoder(taggedObject.getObject().toASN1Primitive()); return new TaggedObject<>(explicit, tagNo, objectDecoder); }
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//from ww w. ja v a 2 s.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 /*from w w w . j a v a 2 s .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: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 w ww . j a va 2s . c om } } 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:org.aselect.authspserver.authsp.pki.PKIManager.java
License:Open Source License
/** * private Helper function for DER Decoding. <br> * <br>// ww w .j a v a2 s.c om * * @param derObject * the der object * @return a DER object * @throws ASelectException * the a select exception */ private Vector getOctetValues(DERObject derObject) throws ASelectException { String sMethod = "getOctetValues(DERObject derObject)"; Vector vDerValues = new Vector(); if (derObject == null) { _systemLogger.log(Level.WARNING, MODULE, sMethod, "Supplied derObject is null"); throw new ASelectException(Errors.PKI_INTERNAL_SERVER_ERROR); } else if (derObject instanceof DERSequence) { Enumeration enumDerObjects = ((DERSequence) derObject).getObjects(); while (enumDerObjects.hasMoreElements()) { DERObject nestedDerObject = (DERObject) enumDerObjects.nextElement(); vDerValues.addAll(getOctetValues(nestedDerObject)); } } else if (derObject instanceof DERTaggedObject) { DERTaggedObject derTaggedObject = (DERTaggedObject) derObject; if (derTaggedObject.isExplicit() && !derTaggedObject.isEmpty()) { DERObject nestedDerObject = derTaggedObject.getObject(); vDerValues = getOctetValues(nestedDerObject); } else { DEROctetString derOctetString = (DEROctetString) derTaggedObject.getObject(); byte[] octetValue = derOctetString.getOctets(); vDerValues = new Vector(); vDerValues.add(octetValue); } } return vDerValues; }
From source file:org.viafirma.nucleo.validacion.CRLUtil.java
License:Open Source License
/** * Parsea el objeto y devuelve un listado con las urls de punto de * distribucin de las CRLs/* w w w . j a v a 2 s. 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 { log.fatal("tipo de dato en ASN1 al recuperar las crls no es reconocido : " + derObj); } return null; }
From source file:org.viafirma.nucleo.X509.X509Handler.java
License:Open Source License
/** * Navega sobre los campos ASN.1 del certificado recuperando los pares valor * oid= valor/* w w w .j a va2 s. c o m*/ * * @param extensionType * @param propiedadesOid */ @SuppressWarnings("unchecked") public void readPropiedadesOid(String oidActual, DERObject extension, Map<String, String> propiedadesOid) { if (extension instanceof DERSequence) { // tengo un objeto de tipo secuence. DERSequence secuence = (DERSequence) extension; Enumeration enumObjetos = secuence.getObjects(); String oidUtilizadoNodo = oidActual; while (enumObjetos.hasMoreElements()) { DERObject objeto = (DERObject) enumObjetos.nextElement(); // si este objeto fuese un identificador quiere decir que el // siguiente seria un objeto que queremos guardar if (objeto instanceof DERObjectIdentifier) { DERObjectIdentifier objetoID = (DERObjectIdentifier) objeto; // este es el oid utilizado para los nodos que estan por // debajo del actual oidUtilizadoNodo = objetoID.getId(); } else { readPropiedadesOid(oidUtilizadoNodo, objeto, propiedadesOid); } } } else if (extension instanceof DERObjectIdentifier) { // el objeto es un identificador. DERObjectIdentifier objetoID = (DERObjectIdentifier) extension; String oid = objetoID.getId(); System.out.println("Valor perdido " + oid); } else if (extension instanceof DERIA5String) { // hemos localizado un par id-valor String valor = ((DERIA5String) extension).getString(); propiedadesOid.put(oidActual, valor); } else if (extension instanceof DERVisibleString) { // hemos localizado un par id-valor String valor = ((DERVisibleString) extension).getString(); propiedadesOid.put(oidActual, valor); } else if (extension instanceof DERPrintableString) { // hemos localizado un par id-valor String valor = ((DERPrintableString) extension).getString(); propiedadesOid.put(oidActual, valor); } else if (extension instanceof DERBitString) { String valor = "" + ((DERBitString) extension).getPadBits(); propiedadesOid.put(oidActual, valor); } else if (extension instanceof DERSet) { Enumeration enumSet = ((DERSet) extension).getObjects(); while (enumSet.hasMoreElements()) { readPropiedadesOid(oidActual, (DERObject) enumSet.nextElement(), propiedadesOid); } } else if (extension instanceof DERTaggedObject) { DERTaggedObject derTag = (DERTaggedObject) extension; if ((derTag.isExplicit() && !derTag.isEmpty()) || derTag.getObject() instanceof DERSequence) { DERObject nestedObj = derTag.getObject(); readPropiedadesOid(oidActual, nestedObj, propiedadesOid); } else { DEROctetString derOct = (DEROctetString) derTag.getObject(); readPropiedadesOid(oidActual, derOct, propiedadesOid); } } /* * else if(extension instanceof DERTaggedObject){ DERTaggedObject * tagged=((DERTaggedObject)extension); int tagNo=tagged.getTagNo(); * readPropiedadesOid(oidActual,tagged.getObject(),propiedadesOid); * * * //propiedadesOid.put(oidActual,valor); } */else if (extension instanceof DEROctetString) { DEROctetString oct = (DEROctetString) extension; // ASN1InputStream aIn= new ASN1InputStream(oct.getOctets()); ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(oct.getOctets())); try { DERObject extensionObj = aIn.readObject(); readPropiedadesOid(oidActual, extensionObj, propiedadesOid); } catch (IOException e) { // si no es un nuevo objeto codificado quizas sea un string(ej : // las crls se recuperan asi) propiedadesOid.put(oidActual, new String(oct.getOctets())); } catch (IllegalStateException e) { // Problema extrao detectado con los certificados corruptos. // OID: 2.5.29.14 :java.lang.IllegalStateException: DER length // more than 4 bytes // DER length more than 4 bytes log.warn(e.getMessage()); } catch (Exception e) { // Problema extrao detectado con los certificados corruptos. // OID: 2.5.29.14 :java.lang.IllegalStateException: DER length // more than 4 bytes e.printStackTrace(); } } else if (extension instanceof DERInteger) { String valor = "" + ((DERInteger) extension).getValue().longValue(); propiedadesOid.put(oidActual, valor); } else if (extension instanceof DERT61String) { String valor = ((DERT61String) extension).getString(); propiedadesOid.put(oidActual, valor); } else if (extension instanceof DERUTF8String) { String valor = ((DERUTF8String) extension).getString(); propiedadesOid.put(oidActual, valor); } else if (extension instanceof DERApplicationSpecific) { DERApplicationSpecific temp = (DERApplicationSpecific) extension; String valor = new String(temp.getContents()); propiedadesOid.put(oidActual, valor); } else { log.warn("Tipo de estructura ANS1 no soportada: " + extension); } // log.debug("tipo de dato en ASN1 parsear estructura : "+extension); }