Package org.bouncycastle.sasn1.cms

Examples of org.bouncycastle.sasn1.cms.SignedDataParser


        OutputStream            out)
        throws CMSException, IOException
    {
        ASN1StreamParser in = new ASN1StreamParser(original, CMSUtils.getMaximumMemory());
        ContentInfoParser contentInfo = new ContentInfoParser((ASN1SequenceParser)in.readObject());
        SignedDataParser signedData = SignedDataParser.getInstance(contentInfo.getContent(DERTags.SEQUENCE));

        BERSequenceGenerator sGen = new BERSequenceGenerator(out);

        sGen.addObject(CMSObjectIdentifiers.signedData);

        BERSequenceGenerator sigGen = new BERSequenceGenerator(sGen.getRawOutputStream(), 0, true);

        // version number
        sigGen.addObject(signedData.getVersion());

        // digests
        signedData.getDigestAlgorithms().getDERObject()// skip old ones

        ASN1EncodableVector digestAlgs = new ASN1EncodableVector();

        for (Iterator it = signerInformationStore.getSigners().iterator(); it.hasNext();)
        {
            SignerInformation        signer = (SignerInformation)it.next();
            AlgorithmIdentifier     digAlgId;

            digAlgId = makeAlgId(signer.getDigestAlgOID(), signer.getDigestAlgParams());

            digestAlgs.add(digAlgId);
        }

        sigGen.getRawOutputStream().write(new DERSet(digestAlgs).getEncoded());

        // encap content info
        ContentInfoParser encapContentInfo = signedData.getEncapContentInfo();

        BERSequenceGenerator eiGen = new BERSequenceGenerator(sigGen.getRawOutputStream());

        eiGen.addObject(encapContentInfo.getContentType());

        ASN1OctetStringParser octs = (ASN1OctetStringParser)
            encapContentInfo.getContent(DERTags.OCTET_STRING);

        if (octs != null)
        {
            pipeOctetString(octs, eiGen.getRawOutputStream());
        }

        eiGen.close();


        writeSetToGeneratorTagged(sigGen, signedData.getCertificates(), 0);
        writeSetToGeneratorTagged(sigGen, signedData.getCrls(), 1);


        ASN1EncodableVector signerInfos = new ASN1EncodableVector();
        for (Iterator it = signerInformationStore.getSigners().iterator(); it.hasNext();)
        {
View Full Code Here


        OutputStream  out)
        throws CMSException, IOException
    {
        ASN1StreamParser in = new ASN1StreamParser(original, CMSUtils.getMaximumMemory());
        ContentInfoParser contentInfo = new ContentInfoParser((ASN1SequenceParser)in.readObject());
        SignedDataParser signedData = SignedDataParser.getInstance(contentInfo.getContent(DERTags.SEQUENCE));

        BERSequenceGenerator sGen = new BERSequenceGenerator(out);

        sGen.addObject(CMSObjectIdentifiers.signedData);

        BERSequenceGenerator sigGen = new BERSequenceGenerator(sGen.getRawOutputStream(), 0, true);

        // version number
        sigGen.addObject(signedData.getVersion());

        // digests
        sigGen.getRawOutputStream().write(signedData.getDigestAlgorithms().getDERObject().getEncoded());

        // encap content info
        ContentInfoParser encapContentInfo = signedData.getEncapContentInfo();

        BERSequenceGenerator eiGen = new BERSequenceGenerator(sigGen.getRawOutputStream());

        eiGen.addObject(encapContentInfo.getContentType());

        ASN1OctetStringParser octs = (ASN1OctetStringParser)
            encapContentInfo.getContent(DERTags.OCTET_STRING);

        if (octs != null)
        {
            pipeOctetString(octs, eiGen.getRawOutputStream());
        }

        eiGen.close();

        //
        // skip existing certs and CRLs
        //
        getASN1Set(signedData.getCertificates());
        getASN1Set(signedData.getCrls());

        //
        // replace the certs and crls in the SignedData object
        //
        ASN1Set certs;

        try
        {
            certs = CMSUtils.createBerSetFromList(CMSUtils.getCertificatesFromStore(certsAndCrls));
        }
        catch (CertStoreException e)
        {
            throw new CMSException("error getting certs from certStore", e);
        }

        if (certs.size() > 0)
        {
            sigGen.getRawOutputStream().write(new DERTaggedObject(false, 0, certs).getEncoded());
        }

        ASN1Set crls;

        try
        {
            crls = CMSUtils.createBerSetFromList(CMSUtils.getCRLsFromStore(certsAndCrls));
        }
        catch (CertStoreException e)
        {
            throw new CMSException("error getting crls from certStore", e);
        }

        if (crls.size() > 0)
        {
            sigGen.getRawOutputStream().write(new DERTaggedObject(false, 1, crls).getEncoded());
        }

        sigGen.getRawOutputStream().write(signedData.getSignerInfos().getDERObject().getEncoded());

        sigGen.close();

        sGen.close();
View Full Code Here

        String oid,
        byte[] enc)
        throws IOException
    {
        ByteArrayInputStream     bIn = new ByteArrayInputStream(enc);
        Asn1InputStream          aIn = new Asn1InputStream(bIn);

        Asn1ObjectIdentifier      o = new Asn1ObjectIdentifier(oid);
        Asn1ObjectIdentifier      encO = (Asn1ObjectIdentifier)aIn.readObject();
       
        if (!o.equals(encO))
        {
            fail("oid ID didn't match - got: " + o + " expected " + encO);
        }
View Full Code Here

        String  oid)
        throws IOException
    {
        Asn1ObjectIdentifier    o = new Asn1ObjectIdentifier(oid);
        ByteArrayInputStream    bIn = new ByteArrayInputStream(o.getEncoded());
        Asn1InputStream         aIn = new Asn1InputStream(bIn);
       
        o = (Asn1ObjectIdentifier)aIn.readObject();
       
        if (!o.toString().equals(oid))
        {
            fail("failed oid check for " + oid);
        }
View Full Code Here

    }
   
    public void testDerReading()
        throws Exception
    {
        Asn1InputStream aIn = new Asn1InputStream(seqData);
       
        Asn1Sequence    seq = (Asn1Sequence)aIn.readObject();
        Object          o = null;
        int             count = 0;
       
        assertNotNull("null sequence returned", seq);
       
View Full Code Here

    public void testNestedReading(
        byte[] data)
        throws Exception
    {
        Asn1InputStream aIn = new Asn1InputStream(data);
       
        Asn1Sequence    seq = (Asn1Sequence)aIn.readObject();
        Object          o = null;
        int             count = 0;
       
        assertNotNull("null sequence returned", seq);
       
View Full Code Here

    }
   
    public void testBerReading()
        throws Exception
    {
        Asn1InputStream aIn = new Asn1InputStream(berSeqData);
       
        Asn1Sequence    seq = (Asn1Sequence)aIn.readObject();
        Object          o = null;
        int             count = 0;
       
        assertNotNull("null sequence returned", seq);
       
View Full Code Here

    }
   
    public void testLongTag()
        throws IOException
    {
        Asn1InputStream aIn = new Asn1InputStream(longTagged);
       
        Asn1TaggedObject tagged = (Asn1TaggedObject)aIn.readObject();
       
        assertEquals(31, tagged.getTagNumber());
    }
View Full Code Here

        assertEquals(31, tagged.getTagNumber());
    }
   
    private void parseEnveloped(byte[] data) throws IOException
    {
        Asn1InputStream aIn = new Asn1InputStream(data);
       
        ContentInfoParser cP = new ContentInfoParser((Asn1Sequence)aIn.readObject());
       
        EnvelopedDataParser eP = new EnvelopedDataParser((Asn1Sequence)cP.getContent(BerTag.SEQUENCE));
       
        eP.getRecipientInfos();
       
View Full Code Here

       out.write(new byte[] { 1, 2, 3, 4 });
       out.write(new byte[4]);
      
       out.close();
      
       Asn1InputStream aIn = new Asn1InputStream(bOut.toByteArray());
      
       BerOctetString s = (BerOctetString)aIn.readObject();
      
       InputStream in = s.getOctetStream();
       int         count = 0;
      
       while (in.read() >= 0)
View Full Code Here

TOP

Related Classes of org.bouncycastle.sasn1.cms.SignedDataParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.