private void DoCreateStandardAttributeTable(IDictionary parameters, IDictionary std)
        {
            // contentType will be absent if we're trying to generate a counter signature.
            if (parameters.Contains(CmsAttributeTableParameter.ContentType))
            {
                if (!std.Contains(CmsAttributes.ContentType))
                {
                    DerObjectIdentifier contentType = (DerObjectIdentifier)
                                                      parameters[CmsAttributeTableParameter.ContentType];
                    Attribute attr = new Attribute(CmsAttributes.ContentType,
                                                   new DerSet(contentType));
                    std[attr.AttrType] = attr;
                }
            }

            if (!std.Contains(CmsAttributes.SigningTime))
            {
                Attribute attr = new Attribute(CmsAttributes.SigningTime,
                                               new DerSet(new Time(DateTime.UtcNow)));
                std[attr.AttrType] = attr;
            }

            if (!std.Contains(CmsAttributes.MessageDigest))
            {
                byte[]    messageDigest = (byte[])parameters[CmsAttributeTableParameter.Digest];
                Attribute attr          = new Attribute(CmsAttributes.MessageDigest,
                                                        new DerSet(new DerOctetString(messageDigest)));
                std[attr.AttrType] = attr;
            }
        }
Exemplo n.º 2
0
        private Asn1Object GetSingleValuedSignedAttribute(
            DerObjectIdentifier attrOID, string printableName)
        {
            AttributeTable unsignedAttrTable = this.UnsignedAttributes;

            if (unsignedAttrTable != null &&
                unsignedAttrTable.GetAll(attrOID).Count > 0)
            {
                throw new CmsException("The " + printableName
                                       + " attribute MUST NOT be an unsigned attribute");
            }

            AttributeTable signedAttrTable = this.SignedAttributes;

            if (signedAttrTable == null)
            {
                return(null);
            }

            Asn1EncodableVector v = signedAttrTable.GetAll(attrOID);

            switch (v.Count)
            {
            case 0:
                return(null);

            case 1:
                Attribute t          = (Attribute)v[0];
                Asn1Set   attrValues = t.AttrValues;

                if (attrValues.Count != 1)
                {
                    throw new CmsException("A " + printableName
                                           + " attribute MUST have a single attribute value");
                }

                return(attrValues[0].ToAsn1Object());

            default:
                throw new CmsException("The SignedAttributes in a signerInfo MUST NOT include multiple instances of the "
                                       + printableName + " attribute");
            }
        }
Exemplo n.º 3
0
        /**
         * Create a standard attribute table from the passed in parameters - this will
         * normally include contentType and messageDigest. If the constructor
         * using an AttributeTable was used, entries in it for contentType and
         * messageDigest will override the generated ones.
         *
         * @param parameters source parameters for table generation.
         *
         * @return a filled in IDictionary of attributes.
         */
        protected virtual IDictionary CreateStandardAttributeTable(
            IDictionary parameters)
        {
            IDictionary std = Platform.CreateHashtable(table);

            if (!std.Contains(CmsAttributes.ContentType))
            {
                DerObjectIdentifier contentType = (DerObjectIdentifier)
                                                  parameters[CmsAttributeTableParameter.ContentType];
                Attribute attr = new Attribute(CmsAttributes.ContentType,
                                               new DerSet(contentType));
                std[attr.AttrType] = attr;
            }

            if (!std.Contains(CmsAttributes.MessageDigest))
            {
                byte[]    messageDigest = (byte[])parameters[CmsAttributeTableParameter.Digest];
                Attribute attr          = new Attribute(CmsAttributes.MessageDigest,
                                                        new DerSet(new DerOctetString(messageDigest)));
                std[attr.AttrType] = attr;
            }

            return(std);
        }