Esempio n. 1
0
        /**
         * base constructor
         *
         * @param signedContent the content that was signed.
         * @param sigData the signature object.
         */

        public CmsSignedDataParser(CmsTypedStream signedContent, Stream sigData) : base(sigData)
        {
            try
            {
                _signedContent = signedContent;
                _signedData    = SignedDataParser.GetInstance(contentInfo.GetContent(Asn1Tags.Sequence));
                _digests       = Platform.CreateHashtable();
                _digestOids    = new HashSet();

                Asn1SetParser    digAlgs = _signedData.GetDigestAlgorithms();
                IAsn1Convertible o;

                while ((o = digAlgs.ReadObject()) != null)
                {
                    AlgorithmIdentifier id = AlgorithmIdentifier.GetInstance(o.ToAsn1Object());

                    try
                    {
                        string digestOid  = id.ObjectID.Id;
                        string digestName = Helper.GetDigestAlgName(digestOid);

                        if (!_digests.Contains(digestName))
                        {
                            _digests[digestName] = Helper.GetDigestInstance(digestName);
                            _digestOids.Add(digestOid);
                        }
                    }
                    catch (SecurityUtilityException)
                    {
                        // TODO Should do something other than ignore it
                    }
                }

                //
                // If the message is simply a certificate chain message GetContent() may return null.
                //
                ContentInfoParser cont = _signedData.GetEncapContentInfo();
                var octs = (Asn1OctetStringParser)cont.GetContent(Asn1Tags.OctetString);

                if (octs != null)
                {
                    var ctStr = new CmsTypedStream(cont.ContentType.Id, octs.GetOctetStream());

                    if (_signedContent == null)
                    {
                        _signedContent = ctStr;
                    }
                    else
                    {
                        //
                        // content passed in, need to read past empty encapsulated content info object if present
                        //
                        ctStr.Drain();
                    }
                }

                _signedContentType = _signedContent == null ? cont.ContentType : new DerObjectIdentifier(_signedContent.ContentType);
            }
            catch (IOException e)
            {
                throw new CmsException("io exception: " + e.Message, e);
            }

            if (_digests.Count < 1)
            {
                throw new CmsException("no digests could be created for message.");
            }
        }
        /**
        * base constructor
        *
        * @param signedContent the content that was signed.
        * @param sigData the signature object.
        */

        public CmsSignedDataParser(CmsTypedStream signedContent, Stream sigData) : base(sigData)
        {
            try
            {
                _signedContent = signedContent;
                _signedData = SignedDataParser.GetInstance(contentInfo.GetContent(Asn1Tags.Sequence));
                _digests = Platform.CreateHashtable();
                _digestOids = new HashSet();

                Asn1SetParser digAlgs = _signedData.GetDigestAlgorithms();
                IAsn1Convertible o;

                while ((o = digAlgs.ReadObject()) != null)
                {
                    AlgorithmIdentifier id = AlgorithmIdentifier.GetInstance(o.ToAsn1Object());

                    try
                    {
                        string digestOid = id.ObjectID.Id;
                        string digestName = Helper.GetDigestAlgName(digestOid);

                        if (!_digests.Contains(digestName))
                        {
                            _digests[digestName] = Helper.GetDigestInstance(digestName);
                            _digestOids.Add(digestOid);
                        }
                    }
                    catch (SecurityUtilityException)
                    {
                        // TODO Should do something other than ignore it
                    }
                }

                //
                // If the message is simply a certificate chain message GetContent() may return null.
                //
                ContentInfoParser cont = _signedData.GetEncapContentInfo();
                var octs = (Asn1OctetStringParser) cont.GetContent(Asn1Tags.OctetString);

                if (octs != null)
                {
                    var ctStr = new CmsTypedStream(cont.ContentType.Id, octs.GetOctetStream());

                    if (_signedContent == null)
                    {
                        _signedContent = ctStr;
                    }
                    else
                    {
                        //
                        // content passed in, need to read past empty encapsulated content info object if present
                        //
                        ctStr.Drain();
                    }
                }

                _signedContentType = _signedContent == null ? cont.ContentType : new DerObjectIdentifier(_signedContent.ContentType);
            }
            catch (IOException e)
            {
                throw new CmsException("io exception: " + e.Message, e);
            }

            if (_digests.Count < 1)
            {
                throw new CmsException("no digests could be created for message.");
            }
        }