List of usage examples for org.bouncycastle.asn1 DERApplicationSpecific getApplicationTag
public int getApplicationTag()
From source file:au.com.nullpointer.gp.der.CardData.java
License:Open Source License
public CardData(byte[] encoded) throws DecodingException { try {/*from w w w .j ava 2 s. co m*/ DERApplicationSpecific cardRecData = (DERApplicationSpecific) ASN1Sequence.fromByteArray(encoded); if (cardRecData.getApplicationTag() != TAG_CARD_RECOGNITION_DATA) { throw new DecodingException(TAG_CARD_RECOGNITION_DATA, cardRecData.getApplicationTag()); } cardRecData.getDERObject(); ASN1StreamParser parse = new ASN1StreamParser(cardRecData.getContents()); DEREncodable der = null; while ((der = parse.readObject()) != null) { if (der instanceof ASN1ObjectIdentifier) { if (!GP_OID.branch("1").equals(der)) { throw new DecodingException("Not GlobalPlatform card recognition data: " + der); } } if (der instanceof DERApplicationSpecific) { DERApplicationSpecific as = (DERApplicationSpecific) der; int tag = as.getApplicationTag(); ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) ASN1Object.fromByteArray(as.getContents()); switch (tag) { case 0: gpVersion = oid.getId().replace(GP_OID.branch("2").toString() + ".", ""); break; case 3: break; case 4: String[] vals = oid.getId().replace(GP_OID.branch("4").toString() + ".", "").split("\\."); scpVersion = Integer.parseInt(vals[0]); scpIValue = Integer.parseInt(vals[1]); break; case 5: cardConfig = oid.getId(); break; case 6: chip = oid.getId(); break; default: throw new DecodingException("Unknow card recognition data tag: " + tag); } } } } catch (IOException e) { throw new DecodingException("Unable to decode card recognition data", e); } }
From source file:au.com.nullpointer.gp.der.CardRecognitionData.java
License:Open Source License
private static byte[] getCardData(byte[] encoded) throws DecodingException { try {/*from w ww.j a v a 2 s . com*/ DERApplicationSpecific cardData = (DERApplicationSpecific) ASN1Object.fromByteArray(encoded); if (cardData.getApplicationTag() != CardData.TAG_CARD_DATA) { throw new DecodingException(CardData.TAG_CARD_DATA, cardData.getApplicationTag()); } return cardData.getContents(); } catch (IOException e) { throw new DecodingException("Unable to decode card recognition data", e); } }
From source file:com.awcoleman.BouncyCastleGenericCDRHadoop.CallDetailRecord.java
License:Apache License
public CallDetailRecord(ASN1Sequence inSeq) throws UnsupportedEncodingException { cdr = inSeq;/*from ww w. j a v a 2 s . co m*/ for (Enumeration<ASN1Encodable> en = cdr.getObjects(); en.hasMoreElements();) { ASN1Encodable em = en.nextElement(); ASN1Primitive emp = em.toASN1Primitive(); DERApplicationSpecific emt = (DERApplicationSpecific) emp; //System.out.println("emt.getApplicationTag(): "+emt.getApplicationTag()); switch (emt.getApplicationTag()) { case 2: recordNumber = emt.getContents()[0]; break; case 8: callingNumber = new String(emt.getContents(), "UTF-8"); break; case 9: calledNumber = new String(emt.getContents(), "UTF-8"); break; case 16: startDate = new String(emt.getContents(), "UTF-8"); break; case 18: startTime = new String(emt.getContents(), "UTF-8"); break; case 19: duration = emt.getContents()[0]; break; default: //Unknown application number. In production would either log or error. break; } } }
From source file:com.awcoleman.BouncyCastleGenericCDRHadoopWithWritable.CallDetailRecord.java
License:Apache License
public CallDetailRecord(ASN1Sequence inSeq) throws UnsupportedEncodingException { cdr = inSeq;/*from www . j a va 2s .co m*/ for (@SuppressWarnings("unchecked") Enumeration<ASN1Encodable> en = cdr.getObjects(); en.hasMoreElements();) { ASN1Encodable em = en.nextElement(); ASN1Primitive emp = em.toASN1Primitive(); DERApplicationSpecific emt = (DERApplicationSpecific) emp; //System.out.println("emt.getApplicationTag(): "+emt.getApplicationTag()); switch (emt.getApplicationTag()) { case 2: recordNumber = emt.getContents()[0]; break; case 8: callingNumber = new String(emt.getContents(), "UTF-8"); break; case 9: calledNumber = new String(emt.getContents(), "UTF-8"); break; case 16: startDate = new String(emt.getContents(), "UTF-8"); break; case 18: startTime = new String(emt.getContents(), "UTF-8"); break; case 19: duration = emt.getContents()[0]; break; default: //Unknown application number. In production would either log or error. break; } } }
From source file:com.github.horrorho.inflatabledonkey.data.der.DER.java
License:Open Source License
static ASN1Primitive asApplicationSpecific(int tag, ASN1Encodable encodable) { try {/*from w w w.ja v a 2s. com*/ DERApplicationSpecific specific = as(DERApplicationSpecific.class, encodable); if (specific.getApplicationTag() == tag) { return specific.getObject(); } else { throw new IllegalArgumentException( "tag mismatch, expected " + tag + " got " + specific.getApplicationTag()); } } catch (IOException ex) { throw new IllegalArgumentException(ex); } }
From source file:de.tsenger.animamea.asn1.CVCertBody.java
License:Open Source License
public CVCertBody(DERApplicationSpecific derApp) throws IllegalArgumentException, IOException { if (derApp.getApplicationTag() != 0x4E) throw new IllegalArgumentException("contains no Certifcate Body with tag 0x7F4E"); else/*from w w w . j av a2 s . c om*/ cvcbody = derApp; ASN1Sequence bodySeq = (ASN1Sequence) cvcbody.getObject(BERTags.SEQUENCE); profileIdentifier = (ASN1Integer) ((DERApplicationSpecific) bodySeq.getObjectAt(0)) .getObject(BERTags.INTEGER); authorityReference = (DERIA5String) ((DERApplicationSpecific) bodySeq.getObjectAt(1)) .getObject(BERTags.IA5_STRING); ASN1Sequence pkSeq = (ASN1Sequence) ((DERApplicationSpecific) bodySeq.getObjectAt(2)) .getObject(BERTags.SEQUENCE); ASN1ObjectIdentifier pkOid = (ASN1ObjectIdentifier) pkSeq.getObjectAt(0); if (pkOid.toString().startsWith("0.4.0.127.0.7.2.2.2.2")) { publicKey = new AmECPublicKey(pkSeq); } else if (pkOid.toString().startsWith("0.4.0.127.0.7.2.2.2.1")) { publicKey = new AmRSAPublicKey(pkSeq); } chr = (DERIA5String) ((DERApplicationSpecific) bodySeq.getObjectAt(3)).getObject(BERTags.IA5_STRING); ASN1Sequence chatSeq = (ASN1Sequence) ((DERApplicationSpecific) bodySeq.getObjectAt(4)) .getObject(BERTags.SEQUENCE); chat = new CertificateHolderAuthorizationTemplate(chatSeq); effectiveDate = (DEROctetString) ((DERApplicationSpecific) bodySeq.getObjectAt(5)) .getObject(BERTags.OCTET_STRING); expirationDate = (DEROctetString) ((DERApplicationSpecific) bodySeq.getObjectAt(6)) .getObject(BERTags.OCTET_STRING); if (bodySeq.size() > 7) { extensions = (ASN1Sequence) ((DERApplicationSpecific) bodySeq.getObjectAt(7)) .getObject(BERTags.SEQUENCE); } }
From source file:de.tsenger.animamea.asn1.CVCertificate.java
License:Open Source License
public CVCertificate(byte[] in) throws IllegalArgumentException, IOException { ASN1StreamParser asn1Parser = new ASN1StreamParser(in); DERApplicationSpecific cvcert = (DERApplicationSpecific) asn1Parser.readObject(); if (cvcert.getApplicationTag() != 0x21) throw new IllegalArgumentException("Can't find a CV Certificate"); ASN1Sequence derCert = (ASN1Sequence) cvcert.getObject(BERTags.SEQUENCE); // Das CV Cerificate ist eine Sequence DERApplicationSpecific body = (DERApplicationSpecific) derCert.getObjectAt(0); //Das erste Objekt des Certificates ist der Cert-Body if (body.getApplicationTag() != 0x4E) throw new IllegalArgumentException("Can't find a Body in the CV Certificate"); certBody = new CVCertBody(body); DERApplicationSpecific signature = (DERApplicationSpecific) derCert.getObjectAt(1); //Das zweite Objekt des Certificates ist die Signatur if (signature.getApplicationTag() != 0x37) throw new IllegalArgumentException("Can't find a Signature in the CV Certificate"); certSignature = new CVCertSignature(signature.getContents()); }
From source file:de.tsenger.animamea.asn1.CVCertSignature.java
License:Open Source License
public CVCertSignature(DERApplicationSpecific derApp) throws IllegalArgumentException { if (derApp.getApplicationTag() != 0x37) throw new IllegalArgumentException("Contains no Signature with tag 0x5F37"); else//w ww . java2 s. co m cvcsig = derApp; }
From source file:jcifs.spnego.NegTokenInit.java
License:Open Source License
@Override protected void parse(byte[] token) throws IOException { try (ASN1InputStream is = new ASN1InputStream(token)) { DERApplicationSpecific constructed = (DERApplicationSpecific) is.readObject(); if (constructed == null || !constructed.isConstructed()) throw new IOException("Malformed SPNEGO token " + constructed + (constructed != null ? " " + constructed.isConstructed() + " " + constructed.getApplicationTag() : "")); try (ASN1InputStream der = new ASN1InputStream(constructed.getContents())) { ASN1ObjectIdentifier spnego = (ASN1ObjectIdentifier) der.readObject(); if (!SPNEGO_OID.equals(spnego)) { throw new IOException("Malformed SPNEGO token, OID " + spnego); }//from ww w .j av a2 s. co m ASN1TaggedObject tagged = (ASN1TaggedObject) der.readObject(); if (tagged.getTagNo() != 0) { throw new IOException("Malformed SPNEGO token: tag " + tagged.getTagNo() + " " + tagged); } ASN1Sequence sequence = ASN1Sequence.getInstance(tagged, true); Enumeration<ASN1Object> fields = sequence.getObjects(); while (fields.hasMoreElements()) { tagged = (ASN1TaggedObject) fields.nextElement(); switch (tagged.getTagNo()) { case 0: sequence = ASN1Sequence.getInstance(tagged, true); Oid[] mechs = new Oid[sequence.size()]; for (int i = mechs.length - 1; i >= 0; i--) { ASN1ObjectIdentifier mechanism = (ASN1ObjectIdentifier) sequence.getObjectAt(i); mechs[i] = new Oid(mechanism.getId()); } setMechanisms(mechs); break; case 1: DERBitString ctxFlags = DERBitString.getInstance(tagged, true); setContextFlags(ctxFlags.getBytes()[0] & 0xff); break; case 2: ASN1OctetString mechanismToken = ASN1OctetString.getInstance(tagged, true); setMechanismToken(mechanismToken.getOctets()); break; case 3: if (!(tagged.getObject() instanceof DEROctetString)) { break; } case 4: ASN1OctetString mechanismListMIC = ASN1OctetString.getInstance(tagged, true); setMechanismListMIC(mechanismListMIC.getOctets()); break; default: throw new IOException("Malformed token field."); } } } catch (GSSException e) { throw new IOException("Failed to read OID", e); } } }
From source file:org.opensc.pkcs15.asn1.ISO7816ApplicationTemplate.java
License:Apache License
/** * @param o An ASN.1 sequence.//from w w w. jav a 2 s . c om */ public ISO7816ApplicationTemplate(DERApplicationSpecific o) { ASN1InputStream ais = new ASN1InputStream(o.getContents()); DERObject obj; try { while ((obj = ais.readObject()) != null) { if (!(obj instanceof DERApplicationSpecific)) throw new IllegalArgumentException( "Item of an application template is not an application specific ASN1 object."); DERApplicationSpecific to = (DERApplicationSpecific) obj; switch (to.getApplicationTag()) { case AID_TAG_NO: this.aid = to.getContents(); break; case APPLICATION_DESCRIPTION_TAG_NO: this.description = new String(to.getContents(), utf8Encoding); break; case PATH_TAG_NO: this.path = to.getContents(); break; case DISCRETIONARY_DATA_TAG_NO: this.discretionaryData = to.getContents(); break; } } } catch (IOException e) { throw new IllegalArgumentException("I/O error parsing ASN1 object.", e); } }