Ejemplo n.º 1
0
 public SignerInformationStore GetSignerInfos()
 {
     if (_signerInfoStore == null)
     {
         PopulateCertCrlSets();
         IList       list       = Platform.CreateArrayList();
         IDictionary dictionary = Platform.CreateHashtable();
         foreach (object key in _digests.Keys)
         {
             dictionary[key] = DigestUtilities.DoFinal((IDigest)_digests[key]);
         }
         try
         {
             Asn1SetParser    signerInfos = _signedData.GetSignerInfos();
             IAsn1Convertible asn1Convertible;
             while ((asn1Convertible = signerInfos.ReadObject()) != null)
             {
                 SignerInfo instance      = SignerInfo.GetInstance(asn1Convertible.ToAsn1Object());
                 string     digestAlgName = Helper.GetDigestAlgName(instance.DigestAlgorithm.Algorithm.Id);
                 byte[]     digest        = (byte[])dictionary[digestAlgName];
                 list.Add(new SignerInformation(instance, _signedContentType, null, new BaseDigestCalculator(digest)));
             }
         }
         catch (IOException ex)
         {
             throw new CmsException("io exception: " + ex.Message, ex);
         }
         _signerInfoStore = new SignerInformationStore(list);
     }
     return(_signerInfoStore);
 }
Ejemplo n.º 2
0
 public SignerInformationStore GetSignerInfos()
 {
     //IL_00e9: Expected O, but got Unknown
     if (_signerInfoStore == null)
     {
         PopulateCertCrlSets();
         global::System.Collections.IList list = Platform.CreateArrayList();
         IDictionary val = Platform.CreateHashtable();
         {
             global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)_digests.get_Keys()).GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     object current = enumerator.get_Current();
                     val.set_Item(current, (object)DigestUtilities.DoFinal((IDigest)_digests.get_Item(current)));
                 }
             }
             finally
             {
                 global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                 if (disposable != null)
                 {
                     disposable.Dispose();
                 }
             }
         }
         try
         {
             Asn1SetParser    signerInfos = _signedData.GetSignerInfos();
             IAsn1Convertible asn1Convertible;
             while ((asn1Convertible = signerInfos.ReadObject()) != null)
             {
                 SignerInfo instance      = SignerInfo.GetInstance(asn1Convertible.ToAsn1Object());
                 string     digestAlgName = Helper.GetDigestAlgName(instance.DigestAlgorithm.Algorithm.Id);
                 byte[]     digest        = (byte[])val.get_Item((object)digestAlgName);
                 list.Add((object)new SignerInformation(instance, _signedContentType, null, new BaseDigestCalculator(digest)));
             }
         }
         catch (IOException val2)
         {
             IOException val3 = val2;
             throw new CmsException("io exception: " + ((global::System.Exception)(object) val3).get_Message(), (global::System.Exception)(object) val3);
         }
         _signerInfoStore = new SignerInformationStore((global::System.Collections.ICollection)list);
     }
     return(_signerInfoStore);
 }
Ejemplo n.º 3
0
        /**
         * return the collection of signers that are associated with the
         * signatures for the message.
         * @throws CmsException
         */
        public SignerInformationStore GetSignerInfos()
        {
            if (_signerInfoStore == null)
            {
                IList       signerInfos = new ArrayList();
                IDictionary hashes      = new Hashtable();

                foreach (object digestKey in _digests.Keys)
                {
                    hashes[digestKey] = DigestUtilities.DoFinal(
                        (IDigest)_digests[digestKey]);
                }

                try
                {
                    Asn1SetParser    s = _signedData.GetSignerInfos();
                    IAsn1Convertible o;

                    while ((o = s.ReadObject()) != null)
                    {
                        SignerInfo info       = SignerInfo.GetInstance(o.ToAsn1Object());
                        string     digestName = Helper.GetDigestAlgName(
                            info.DigestAlgorithm.ObjectID.Id);

                        byte[] hash = (byte[])hashes[digestName];

                        signerInfos.Add(
                            new SignerInformation(
                                info,
                                new DerObjectIdentifier(_signedContent.ContentType),
                                null,
                                hash));
                    }
                }
                catch (IOException e)
                {
                    throw new CmsException("io exception: " + e.Message, e);
                }

                _signerInfoStore = new SignerInformationStore(signerInfos);
            }

            return(_signerInfoStore);
        }
Ejemplo n.º 4
0
        /**
         * return the collection of signers that are associated with the
         * signatures for the message.
         * @throws CmsException
         */
        public SignerInformationStore GetSignerInfos()
        {
            if (_signerInfoStore == null)
            {
                PopulateCertCrlSets();

                IList       signerInfos = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList();
                IDictionary hashes      = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();

                foreach (object digestKey in _digests.Keys)
                {
                    hashes[digestKey] = DigestUtilities.DoFinal(
                        (IDigest)_digests[digestKey]);
                }

                try
                {
                    Asn1SetParser    s = _signedData.GetSignerInfos();
                    IAsn1Convertible o;

                    while ((o = s.ReadObject()) != null)
                    {
                        SignerInfo info       = SignerInfo.GetInstance(o.ToAsn1Object());
                        string     digestName = Helper.GetDigestAlgName(
                            info.DigestAlgorithm.Algorithm.Id);

                        byte[] hash = (byte[])hashes[digestName];

                        signerInfos.Add(new SignerInformation(info, _signedContentType, null, new BaseDigestCalculator(hash)));
                    }
                }
                catch (IOException e)
                {
                    throw new CmsException("io exception: " + e.Message, e);
                }

                _signerInfoStore = new SignerInformationStore(signerInfos);
            }

            return(_signerInfoStore);
        }
Ejemplo n.º 5
0
        /**
         * Replace the certificate and CRL information associated with this
         * CMSSignedData object with the new one passed in.
         * <p>
         * The output stream is returned unclosed.
         * </p>
         * @param original the signed data stream to be used as a base.
         * @param certsAndCrls the new certificates and CRLs to be used.
         * @param out the stream to Write the new signed data object to.
         * @return out.
         * @exception CmsException if there is an error processing the CertStore
         */
        public static Stream ReplaceCertificatesAndCrls(
            Stream original,
            IX509Store x509Certs,
            IX509Store x509Crls,
            IX509Store x509AttrCerts,
            Stream outStr)
        {
            if (x509AttrCerts != null)
            {
                throw new NotImplementedException("Currently can't replace attribute certificates");
            }

            Asn1StreamParser  inStr       = new Asn1StreamParser(original, CmsUtilities.MaximumMemory);
            ContentInfoParser contentInfo = new ContentInfoParser((Asn1SequenceParser)inStr.ReadObject());
            SignedDataParser  signedData  = SignedDataParser.GetInstance(contentInfo.GetContent(Asn1Tags.Sequence));

            BerSequenceGenerator sGen = new BerSequenceGenerator(outStr);

            sGen.AddObject(CmsObjectIdentifiers.SignedData);

            BerSequenceGenerator sigGen = new BerSequenceGenerator(sGen.GetRawOutputStream(), 0, true);

            // version number
            sigGen.AddObject(signedData.Version);

            // digests
            WriteToGenerator(sigGen, signedData.GetDigestAlgorithms().ToAsn1Object());

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

            BerSequenceGenerator eiGen = new BerSequenceGenerator(sigGen.GetRawOutputStream());

            eiGen.AddObject(encapContentInfo.ContentType);

            Asn1OctetStringParser octs = (Asn1OctetStringParser)encapContentInfo.GetContent(Asn1Tags.OctetString);

            if (octs != null)
            {
                BerOctetStringGenerator octGen = new BerOctetStringGenerator(eiGen.GetRawOutputStream(), 0, true);
                byte[] inBuffer  = new byte[4096];
                byte[] outBuffer = new byte[4096];
                Stream inOctets  = octs.GetOctetStream();
                Stream outOctets = octGen.GetOctetOutputStream(outBuffer);

                int len;
                while ((len = inOctets.Read(inBuffer, 0, inBuffer.Length)) > 0)
                {
                    outOctets.Write(inBuffer, 0, len);
                }

                outOctets.Close();
            }

            eiGen.Close();

            //
            // skip existing certs and CRLs
            //
            Asn1SetParser set = signedData.GetCertificates();

            if (set != null)
            {
                set.ToAsn1Object();
            }

            set = signedData.GetCrls();

            if (set != null)
            {
                set.ToAsn1Object();
            }

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

            try
            {
                certs = CmsUtilities.CreateDerSetFromList(
                    CmsUtilities.GetCertificatesFromStore(x509Certs));
            }
            catch (X509StoreException e)
            {
                throw new CmsException("error getting certs from certStore", e);
            }

            if (certs.Count > 0)
            {
                WriteToGenerator(sigGen, new DerTaggedObject(false, 0, certs));
            }

            Asn1Set crls;

            try
            {
                crls = CmsUtilities.CreateDerSetFromList(
                    CmsUtilities.GetCrlsFromStore(x509Crls));
            }
            catch (X509StoreException e)
            {
                throw new CmsException("error getting crls from certStore", e);
            }

            if (crls.Count > 0)
            {
                WriteToGenerator(sigGen, new DerTaggedObject(false, 1, crls));
            }

            WriteToGenerator(sigGen, signedData.GetSignerInfos().ToAsn1Object());

            sigGen.Close();

            sGen.Close();

            return(outStr);
        }