List of usage examples for org.bouncycastle.asn1 ASN1InputStream readObject
public ASN1Primitive readObject() throws IOException
From source file:it.trento.comune.j4sign.cms.ExternalSignatureCMSSignedDataGenerator.java
License:Open Source License
/** * Used internally by {@link #makeAlgId(String, byte[])} */// www. ja v a2s .c o m private DERObject makeObj(byte[] encoding) throws IOException { if (encoding == null) { return null; } ByteArrayInputStream bIn = new ByteArrayInputStream(encoding); ASN1InputStream aIn = new ASN1InputStream(bIn); return aIn.readObject(); }
From source file:it.trento.comune.j4sign.cms.ExternalSignatureSignerInfoGenerator.java
License:Open Source License
/** * Generates the SignerInfo CMS structure information for a single signer. * This method has to be called after setting {@link #cert} * {@link #signedBytes}.//from ww w. jav a2s . c om * * @return the <code>org.bouncycastle.asn1.cms.SignerInfo</code> object for * a signer. * @throws CertificateEncodingException * @throws IOException */ SignerInfo generate() throws CertificateEncodingException, IOException { AlgorithmIdentifier digAlgId = null; AlgorithmIdentifier encAlgId = null; digAlgId = new AlgorithmIdentifier(new DERObjectIdentifier(this.getDigestAlgOID()), new DERNull()); if (this.getEncryptionAlgOID().equals(CMSSignedDataGenerator.ENCRYPTION_DSA)) { encAlgId = new AlgorithmIdentifier(new DERObjectIdentifier(this.getEncryptionAlgOID())); } else { encAlgId = new AlgorithmIdentifier(new DERObjectIdentifier(this.getEncryptionAlgOID()), new DERNull()); } ASN1OctetString encDigest = new DEROctetString(this.signedBytes); X509Certificate cert = this.getCertificate(); ByteArrayInputStream bIn = new ByteArrayInputStream(cert.getTBSCertificate()); ASN1InputStream aIn = new ASN1InputStream(bIn); TBSCertificateStructure tbs = TBSCertificateStructure.getInstance(aIn.readObject()); IssuerAndSerialNumber encSid = new IssuerAndSerialNumber(tbs.getIssuer(), cert.getSerialNumber()); return new SignerInfo(new SignerIdentifier(encSid), digAlgId, signedAttr, encAlgId, encDigest, unsignedAttr); }
From source file:it.trento.comune.j4sign.cms.utils.CMSBuilder.java
License:Open Source License
private Date parseSigningTime(byte[] bytes, PrintWriter pw) { Date parsedSigningTime = null; try {/* w ww. jav a2s . c o m*/ ASN1InputStream aIn = new ASN1InputStream(bytes); ASN1Set signedAttributes = (ASN1Set) aIn.readObject(); AttributeTable attr = new AttributeTable(signedAttributes); Iterator iter = attr.toHashtable().values().iterator(); pw.println("Listing authenticated attributes:"); int count = 1; while (iter.hasNext()) { Attribute a = (Attribute) iter.next(); pw.println("Attribute " + count + ":"); if (a.getAttrType().getId().equals(CMSAttributes.signingTime.getId())) { Time time = Time.getInstance(a.getAttrValues().getObjectAt(0)); pw.println("Authenticated time (SERVER local time): " + time.getDate()); parsedSigningTime = time.getDate(); } if (a.getAttrType().getId().equals(CMSAttributes.contentType.getId())) { if (CMSObjectIdentifiers.data.getId() .equals(DERObjectIdentifier.getInstance(a.getAttrValues().getObjectAt(0)).getId())) pw.println("Content Type: PKCS7_DATA"); } if (a.getAttrType().getId().equals(CMSAttributes.messageDigest.getId())) { byte[] md = DEROctetString.getInstance(a.getAttrValues().getObjectAt(0)).getOctets(); pw.println("Message Digest (hash of data content): " + formatAsString(md, " ", 16)); } pw.println("\nAttribute dump follows:"); pw.println(ASN1Dump.dumpAsString(a) + "\n"); count++; } } catch (Exception e) { pw.println(e); return null; } pw.flush(); return parsedSigningTime; }
From source file:it.treviso.provincia.freesigner.applet.FreesignerConfFrame.java
License:Open Source License
/** * Returns DERObject extension if the certificate corresponding to given OID<br> * <br>/*from w w w.ja v a 2 s.c om*/ * Restituisce un estensione DERObject dal certificato, corrispoendente * all'OID * * @param cert * certificate * @param oid * String * @throws IOException * @return l'estensione */ private static DERObject getExtensionValue(X509Certificate cert, String oid) throws IOException { byte[] bytes = cert.getExtensionValue(oid); if (bytes == null) { return null; } ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(bytes)); ASN1OctetString otteti = (ASN1OctetString) aIn.readObject(); aIn = new ASN1InputStream(new ByteArrayInputStream(otteti.getOctets())); return aIn.readObject(); }
From source file:jcifs.pac.ASN1Util.java
License:Open Source License
/** * /*ww w . ja v a2 s.co m*/ * @param type * @param stream * @return next object from stream cast to type * @throws PACDecodingException * @throws IOException */ public static <T extends ASN1Primitive> T as(Class<T> type, ASN1InputStream stream) throws PACDecodingException, IOException { return as(type, stream.readObject()); }
From source file:me.it_result.ca.X509Assertions.java
License:Open Source License
public X509Assertions extensionValue(DERObjectIdentifier id, ASN1Encodable value) throws Exception { ASN1InputStream asn1Parser = new ASN1InputStream(cert.getExtensionValue(id.getId())); DEROctetString actualExtension = (DEROctetString) asn1Parser.readObject(); assertTrue(Arrays.equals(value.getDERObject().getDEREncoded(), actualExtension.getOctets())); return this; }
From source file:mitm.common.security.asn1.ASN1Utils.java
License:Open Source License
private static ASN1Object getObject(String oid, byte[] extension) throws IOException { ASN1InputStream aIn = new ASN1InputStream(extension); ASN1OctetString octs = (ASN1OctetString) aIn.readObject(); aIn.close();/*from ww w. j av a2s. c o m*/ aIn = new ASN1InputStream(octs.getOctets()); ASN1Object obj = aIn.readObject(); aIn.close(); return obj; }
From source file:mitm.common.security.asn1.ASN1Utils.java
License:Open Source License
public static ASN1EncodableVector toASN1EncodableVector(X500Principal principal) throws IOException { final ASN1InputStream stream = new ASN1InputStream(principal.getEncoded()); final ASN1Object der = stream.readObject(); Enumeration<?> e = ASN1Sequence.getInstance(der).getObjects(); ASN1EncodableVector v = new ASN1EncodableVector(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (o instanceof ASN1Encodable) { v.add((ASN1Encodable) o);/*from w w w . j ava 2 s . c o m*/ } } stream.close(); return v; }
From source file:mitm.common.security.asn1.DERUtils.java
License:Open Source License
public static ASN1Primitive toDERObject(Certificate certificate) throws CertificateEncodingException, IOException { final ASN1InputStream stream = new ASN1InputStream(certificate.getEncoded()); ASN1Primitive p = stream.readObject(); stream.close();// w w w.j a va 2 s .c om return p; }
From source file:mitm.common.security.asn1.DERUtils.java
License:Open Source License
public static ASN1Primitive toDERObject(X509CRL crl) throws CRLException, IOException { final ASN1InputStream stream = new ASN1InputStream(crl.getEncoded()); ASN1Primitive p = stream.readObject(); stream.close();//from ww w .j av a 2 s. co m return p; }