Package org.bouncycastle.asn1.cms

Examples of org.bouncycastle.asn1.cms.Attribute


            digest = ((DEROctetString)signerInfo.getObjectAt(next++)).getOctets();
            if (next < signerInfo.size() && (signerInfo.getObjectAt(next) instanceof DERTaggedObject)) {
                DERTaggedObject taggedObject = (DERTaggedObject) signerInfo.getObjectAt(next);
                ASN1Set unat = ASN1Set.getInstance(taggedObject, false);
                AttributeTable attble = new AttributeTable(unat);
                Attribute ts = attble.get(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken);
                if (ts != null && ts.getAttrValues().size() > 0) {
                    ASN1Set attributeValues = ts.getAttrValues();
                    ASN1Sequence tokenSequence = ASN1Sequence.getInstance(attributeValues.getObjectAt(0));
                    ContentInfo contentInfo = new ContentInfo(tokenSequence);
                    this.timeStampToken = new TimeStampToken(contentInfo);
                }
            }
View Full Code Here


            return new SignerInformationStore(new ArrayList(0));
        }
       
        List counterSignatures = new ArrayList();

        Attribute counterSignatureAttribute = unsignedAttributeTable.get(CMSAttributes.counterSignature);
        if (counterSignatureAttribute != null)
        {
            ASN1Set values = counterSignatureAttribute.getAttrValues();
            counterSignatures = new ArrayList(values.size());

            for (Enumeration en = values.getObjects(); en.hasMoreElements();)
            {
                SignerInfo si = SignerInfo.getInstance(en.nextElement());
View Full Code Here

                    hash = null;
                }

                resultDigest = hash;
               
                Attribute dig = signedAttrTable.get(
                                CMSAttributes.messageDigest);
                Attribute type = signedAttrTable.get(
                                CMSAttributes.contentType);

                if (dig == null)
                {
                    throw new SignatureException("no hash for content found in signed attributes");
                }

                if (type == null && !contentType.equals(CMSAttributes.counterSignature))
                {
                    throw new SignatureException("no content type id found in signed attributes");
                }

                DERObject hashObj = dig.getAttrValues().getObjectAt(0).getDERObject();
               
                if (hashObj instanceof ASN1OctetString)
                {
                    byte[]  signedHash = ((ASN1OctetString)hashObj).getOctets();
   
                    if (!MessageDigest.isEqual(hash, signedHash))
                    {
                        throw new SignatureException("content hash found in signed attributes different");
                    }
                }
                else if (hashObj instanceof DERNull)
                {
                    if (hash != null)
                    {
                        throw new SignatureException("NULL hash found in signed attributes when one expected");
                    }
                }

                if (type != null)
                {
                    DERObjectIdentifier  typeOID = (DERObjectIdentifier)type.getAttrValues().getObjectAt(0);

                    if (!typeOID.equals(contentType))
                    {
                        throw new SignatureException("contentType in signed attributes different");
                    }
View Full Code Here

            {
                case 0:
                    break;
                case 1:
                {
                    Attribute t = (Attribute)v.get(0);
//                    assert t != null;

                    ASN1Set attrValues = t.getAttrValues();
                    if (attrValues.size() != 1)
                    {
                        throw new CMSException("A signing-time attribute MUST have a single attribute value");
                    }
View Full Code Here

        for (Iterator it = counterSigners.getSigners().iterator(); it.hasNext();)
        {
            sigs.add(((SignerInformation)it.next()).toSignerInfo());
        }

        v.add(new Attribute(CMSAttributes.counterSignature, new DERSet(sigs)));

        return new SignerInformation(
                new SignerInfo(sInfo.getSID(), sInfo.getDigestAlgorithm(),
                    sInfo.getAuthenticatedAttributes(), sInfo.getDigestEncryptionAlgorithm(), sInfo.getEncryptedDigest(), new DERSet(v)),
                    signerInformation.contentType, signerInformation.content, null);
View Full Code Here

        verifySignatures(sp);
       
        byte[] contentDigest = (byte[])gen.getGeneratedDigests().get(CMSSignedGenerator.DIGEST_SHA1);

        AttributeTable table = ((SignerInformation)sp.getSignerInfos().getSigners().iterator().next()).getSignedAttributes();
        Attribute hash = table.get(CMSAttributes.messageDigest);

        assertTrue(MessageDigest.isEqual(contentDigest, ((ASN1OctetString)hash.getAttrValues().getObjectAt(0)).getOctets()));

        //
        // try using existing signer
        //
        gen = new CMSSignedDataStreamGenerator();
View Full Code Here

            public AttributeTable getAttributes(Map parameters)
            {
                Hashtable table = createStandardAttributeTable(parameters);

                DEROctetString val = new DEROctetString((byte[])parameters.get(CMSAttributeTableGenerator.DIGEST));
                Attribute attr = new Attribute(dummyOid1, new DERSet(val));

                table.put(attr.getAttrType(), attr);

                return new AttributeTable(table);
            }
        };

        CMSAttributeTableGenerator unsignedGen = new CMSAttributeTableGenerator()
        {
            public AttributeTable getAttributes(Map parameters)
            {
                DEROctetString val = new DEROctetString((byte[])parameters.get(CMSAttributeTableGenerator.SIGNATURE));
                Attribute attr = new Attribute(dummyOid2, new DERSet(val));

                return new AttributeTable(new DERSet(attr));
            }
        };
View Full Code Here

            //

            byte[] contentDigest = (byte[])gen.getGeneratedDigests().get(signer.getDigestAlgOID());

            AttributeTable table = signer.getSignedAttributes();
            Attribute hash = table.get(CMSAttributes.messageDigest);

            assertTrue(MessageDigest.isEqual(contentDigest, ((ASN1OctetString)hash.getAttrValues().getObjectAt(0)).getOctets()));
        }
       
        c = signers.getSigners(sid);
       
        assertEquals(2, c.size());
View Full Code Here

        CertStore           certs = CertStore.getInstance("Collection",
                        new CollectionCertStoreParameters(certList), "BC");

        CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

        Attribute attr = new Attribute(CMSAttributes.messageDigest,
                                       new DERSet(
                                            new DEROctetString(
                                                md.digest("Hello world!".getBytes()))));

        ASN1EncodableVector v = new ASN1EncodableVector();
View Full Code Here

    {
        Hashtable std = (Hashtable)table.clone();

        if (!std.containsKey(CMSAttributes.contentType))
        {
            Attribute attr = new Attribute(CMSAttributes.contentType,
                              new DERSet((DERObjectIdentifier)parameters.get(CMSAttributeTableGenerator.CONTENT_TYPE)));
            std.put(attr.getAttrType(), attr);
        }

        if (!std.containsKey(CMSAttributes.signingTime))
        {
            Attribute attr = new Attribute(CMSAttributes.signingTime, new DERSet(new Time(new Date())));
            std.put(attr.getAttrType(), attr);
        }

        if (!std.containsKey(CMSAttributes.messageDigest))
        {
            byte[] hash = (byte[])parameters.get(CMSAttributeTableGenerator.DIGEST);
            Attribute attr;

            if (hash != null)
            {
                attr = new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(hash)));
            }
            else
            {
                attr = new Attribute(CMSAttributes.messageDigest, new DERSet(new DERNull()));
            }

            std.put(attr.getAttrType(), attr);
        }

        return std;
    }
View Full Code Here

TOP

Related Classes of org.bouncycastle.asn1.cms.Attribute

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.