List of usage examples for org.bouncycastle.asn1 ASN1Encodable toASN1Primitive
ASN1Primitive toASN1Primitive();
From source file:com.awcoleman.BouncyCastleGenericCDRHadoop.CallDetailRecord.java
License:Apache License
public CallDetailRecord(ASN1Sequence inSeq) throws UnsupportedEncodingException { cdr = inSeq;// ww w.j a v a 2s . 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 w ww. ja v a 2 s . c om 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 asPrimitive(ASN1Encodable encodable) { return encodable instanceof ASN1Primitive ? (ASN1Primitive) encodable : encodable.toASN1Primitive(); }
From source file:com.guardtime.asn1.TstInfo.java
License:Apache License
/** * Class constructor.// w w w . j ava2 s. c o m * * @param obj ASN.1 representation of TST info. * * @throws Asn1FormatException if provided ASN.1 object has invalid format. */ TstInfo(ASN1Encodable obj) throws Asn1FormatException { try { tstInfo = TSTInfo.getInstance(obj); // Extract and check version BigInteger ver = tstInfo.getVersion().getValue(); if (!ver.equals(BigInteger.valueOf(VERSION))) { throw new Asn1FormatException("invalid TST info version: " + ver); } version = ver.intValue(); // Extract policy policy = tstInfo.getPolicy().getId(); // Extract message imprint messageImprint = new MessageImprint(tstInfo.getMessageImprint().toASN1Primitive()); // Extract serial number // // As `DERInteger` can be constructed out of `ASN1OctetString` // without any error, here we have no option to determine // if the serial number is actually an INTEGER or OCTET STRING. // // Possible solutions is to rewrite BouncyCastle `TSTInfo` class // adding more strict checks. serialNumber = tstInfo.getSerialNumber().getValue(); // Extract request time // // Current BouncyCastle implementation can parse the time string // that does not omit trailing zeros in second fraction part. // RFC 3161 requires that such time string is labeled invalid. genTime = tstInfo.getGenTime().getDate(); // Extract optional fields ASN1Encodable acc = tstInfo.getAccuracy(); accuracy = ((acc == null) ? null : new Accuracy(acc.toASN1Primitive())); ASN1Boolean ord = tstInfo.getOrdering(); ordering = (ord != null && ord.isTrue()); ASN1Integer nnc = tstInfo.getNonce(); nonce = ((nnc == null) ? null : nnc.getValue()); GeneralName tsaName = tstInfo.getTsa(); tsa = ((tsaName == null) ? null : tsaName.toString()); Extensions exts = tstInfo.getExtensions(); if (exts != null) { // check for critical extensions Asn1Util.checkExtensions(exts); extensions = exts.getEncoded(ASN1Encoding.DER); } } catch (Asn1FormatException e) { throw e; } catch (Exception e) { throw new Asn1FormatException("TST info has invalid format", e); } }
From source file:com.vmware.identity.idm.server.clientcert.IdmClientCertificateValidator.java
License:Open Source License
/** * Parse DER-encoded bytes to locate a String object * * @param alterNameValue DER encoded data * @return First string found//from w w w . j a v a2 s .com * @throws Throwable */ private static String parseDERString(byte[] alterNameValue) throws Throwable { try { ASN1StreamParser p = new ASN1StreamParser(alterNameValue); ASN1Encodable d = p.readObject(); ASN1Primitive der = d.toASN1Primitive(); return getStringFromObject(der); } catch (Throwable e) { // Exception indicates parsing failed, skip this // value (most likely not UPN format) logger.error("Unable to extract User Principal Name: " + e.getMessage()); throw e; } }
From source file:de.carne.certmgr.store.provider.bouncycastle.BouncyCastleASN1Decoder.java
License:Open Source License
@Override public ASN1Decoder[] asn1DecodeSequence(int minSize, int maxSize) throws IOException { ASN1Decoder[] sequence;/* w ww. j a v a2s. c om*/ if (isType(ASN1Sequence.class)) { ASN1Sequence sequenceObject = ensureType(ASN1Sequence.class); ArrayList<ASN1Decoder> sequenceDecoders = new ArrayList<>(sequenceObject.size()); for (ASN1Encodable encodable : sequenceObject.toArray()) { sequenceDecoders.add(new BouncyCastleASN1Decoder(encodable.toASN1Primitive())); } sequence = sequenceDecoders.toArray(new ASN1Decoder[sequenceDecoders.size()]); } else { sequence = new ASN1Decoder[] { this }; } int sequenceSize = sequence.length; if (minSize >= 0 && sequenceSize < minSize) { throw new IOException( "Unexpected sequence size: " + sequenceSize + " expected minimum size: " + minSize); } if (maxSize >= 0 && sequenceSize > maxSize) { throw new IOException( "Unexpected sequence size: " + sequenceSize + " expected maximum size: " + maxSize); } return sequence; }
From source file:de.carne.certmgr.store.provider.bouncycastle.BouncyCastlePKCS10Object.java
License:Open Source License
@Override public Set<String> getExtensionOIDs() throws IOException { HashSet<String> oids = new HashSet<>(); Attribute[] attributes = this.pkcs10Object.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest); if (attributes != null) { for (Attribute attribute : attributes) { ASN1Encodable[] values = attribute.getAttributeValues(); if (values != null) { for (ASN1Encodable value : values) { ASN1Decoder decoder = new BouncyCastleASN1Decoder(value.toASN1Primitive()); ASN1Decoder[] entries = decoder.asn1DecodeSequence(-1, -1); for (ASN1Decoder entry : entries) { ASN1Decoder[] extensionEntries = entry.asn1DecodeSequence(2, 3); String extensionOID = extensionEntries[0].asn1DecodeOID(); oids.add(extensionOID); }/*ww w . j a v a2 s .c o m*/ } } } } return oids; }
From source file:de.carne.certmgr.store.provider.bouncycastle.BouncyCastlePKCS10Object.java
License:Open Source License
@Override public byte[] getExtensionValue(String oid) throws IOException { byte[] extensionValue = null; Attribute[] attributes = this.pkcs10Object.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest); if (attributes != null) { for (Attribute attribute : attributes) { if (extensionValue != null) { break; }// w w w. jav a2 s . c o m ASN1Encodable[] values = attribute.getAttributeValues(); if (values != null) { for (ASN1Encodable value : values) { if (extensionValue != null) { break; } ASN1Decoder decoder = new BouncyCastleASN1Decoder(value.toASN1Primitive()); ASN1Decoder[] entries = decoder.asn1DecodeSequence(-1, -1); for (ASN1Decoder entry : entries) { ASN1Decoder[] extensionEntries = entry.asn1DecodeSequence(2, 3); String extensionOID = extensionEntries[0].asn1DecodeOID(); if (oid.equals(extensionOID)) { extensionValue = extensionEntries[extensionEntries.length - 1].getEncoded(); break; } } } } } } return extensionValue; }
From source file:eu.europa.ec.markt.dss.DSSASN1Utils.java
License:Open Source License
/** * This method return DER encoded ASN1 attribute. The {@code IOException} is transformed in {@code DSSException}. * * @param asn1Encodable asn1Encodable to be DER encoded * @return array of bytes representing the DER encoded asn1Encodable *///from w w w. j a v a 2s .c o m public static byte[] getDEREncoded(ASN1Encodable asn1Encodable) { try { return asn1Encodable.toASN1Primitive().getEncoded(ASN1Encoding.DER); } catch (IOException e) { throw new DSSException(e); } }
From source file:eu.europa.ec.markt.dss.validation102853.cades.CAdESSignature.java
License:Open Source License
private List<TimestampToken> getTimestampList(final ASN1ObjectIdentifier attrType, final TimestampType timestampType, final ArchiveTimestampType archiveTimestampType) { final List<TimestampToken> list = new ArrayList<TimestampToken>(); final AttributeTable attributes; if (attrType.equals(PKCSObjectIdentifiers.id_aa_ets_contentTimestamp)) { attributes = signerInformation.getSignedAttributes(); } else {//from w w w.ja v a2 s .c o m attributes = signerInformation.getUnsignedAttributes(); } if (attributes == null) { return list; } final ASN1EncodableVector archiveList = attributes.getAll(attrType); for (int i = 0; i < archiveList.size(); i++) { final Attribute attribute = (Attribute) archiveList.get(i); final ASN1Set attrValues = attribute.getAttrValues(); for (final ASN1Encodable value : attrValues.toArray()) { try { TimeStampToken token = new TimeStampToken( new CMSSignedData(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))); final TimestampToken timestampToken = new TimestampToken(token, timestampType, certPool); timestampToken.setArchiveTimestampType(archiveTimestampType); list.add(timestampToken); } catch (Exception e) { throw new RuntimeException("Parsing error", e); } } } return list; }