GetCertificatesFromStore() public static method

public static GetCertificatesFromStore ( IX509Store certStore ) : IList
certStore IX509Store
return IList
Esempio n. 1
0
        public static CmsSignedData ReplaceCertificatesAndCrls(CmsSignedData signedData, IX509Store x509Certs, IX509Store x509Crls, IX509Store x509AttrCerts)
        {
            if (x509AttrCerts != null)
            {
                throw Platform.CreateNotImplementedException("Currently can't replace attribute certificates");
            }
            CmsSignedData cmsSignedData = new CmsSignedData(signedData);
            Asn1Set       certificates  = null;

            try
            {
                Asn1Set asn1Set = CmsUtilities.CreateBerSetFromList(CmsUtilities.GetCertificatesFromStore(x509Certs));
                if (asn1Set.Count != 0)
                {
                    certificates = asn1Set;
                }
            }
            catch (X509StoreException e)
            {
                throw new CmsException("error getting certificates from store", e);
            }
            Asn1Set crls = null;

            try
            {
                Asn1Set asn1Set2 = CmsUtilities.CreateBerSetFromList(CmsUtilities.GetCrlsFromStore(x509Crls));
                if (asn1Set2.Count != 0)
                {
                    crls = asn1Set2;
                }
            }
            catch (X509StoreException e2)
            {
                throw new CmsException("error getting CRLs from store", e2);
            }
            SignedData signedData2 = signedData.signedData;

            cmsSignedData.signedData  = new SignedData(signedData2.DigestAlgorithms, signedData2.EncapContentInfo, certificates, crls, signedData2.SignerInfos);
            cmsSignedData.contentInfo = new ContentInfo(cmsSignedData.contentInfo.ContentType, cmsSignedData.signedData);
            return(cmsSignedData);
        }
Esempio n. 2
0
 public void AddCertificates(
     IX509Store certStore)
 {
     CollectionUtilities.AddRange(_certs, CmsUtilities.GetCertificatesFromStore(certStore));
 }
Esempio n. 3
0
        /**
         * Replace the certificate and CRL information associated with this
         * CmsSignedData object with the new one passed in.
         *
         * @param signedData the signed data object to be used as a base.
         * @param x509Certs the new certificates to be used.
         * @param x509Crls the new CRLs to be used.
         * @return a new signed data object.
         * @exception CmsException if there is an error processing the stores
         */
        public static CmsSignedData ReplaceCertificatesAndCrls(
            CmsSignedData signedData,
            IX509Store x509Certs,
            IX509Store x509Crls,
            IX509Store x509AttrCerts)
        {
            if (x509AttrCerts != null)
            {
                throw Platform.CreateNotImplementedException("Currently can't replace attribute certificates");
            }

            //
            // copy
            //
            CmsSignedData cms = new CmsSignedData(signedData);

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

            try
            {
                Asn1Set asn1Set = CmsUtilities.CreateBerSetFromList(
                    CmsUtilities.GetCertificatesFromStore(x509Certs));

                if (asn1Set.Count != 0)
                {
                    certs = asn1Set;
                }
            }
            catch (X509StoreException e)
            {
                throw new CmsException("error getting certificates from store", e);
            }

            Asn1Set crls = null;

            try
            {
                Asn1Set asn1Set = CmsUtilities.CreateBerSetFromList(
                    CmsUtilities.GetCrlsFromStore(x509Crls));

                if (asn1Set.Count != 0)
                {
                    crls = asn1Set;
                }
            }
            catch (X509StoreException e)
            {
                throw new CmsException("error getting CRLs from store", e);
            }

            //
            // replace the CMS structure.
            //
            SignedData old = signedData.signedData;

            cms.signedData = new SignedData(
                old.DigestAlgorithms,
                old.EncapContentInfo,
                certs,
                crls,
                old.SignerInfos);

            //
            // replace the contentInfo with the new one
            //
            cms.contentInfo = new ContentInfo(cms.contentInfo.ContentType, cms.signedData);

            return(cms);
        }
Esempio n. 4
0
 public OriginatorInfoGenerator(IX509Store origCerts, IX509Store origCrls)
 {
     this.origCerts = CmsUtilities.GetCertificatesFromStore(origCerts);
     this.origCrls  = origCrls == null ? null : CmsUtilities.GetCrlsFromStore(origCrls);
 }
Esempio n. 5
0
 public void AddCertificates(IX509Store certStore)
 {
     CollectionUtilities.AddRange(_certs, (global::System.Collections.IEnumerable)CmsUtilities.GetCertificatesFromStore(certStore));
 }
 public void AddCertificates(
     IX509Store certStore)
 {
     _certs.AddRange(CmsUtilities.GetCertificatesFromStore(certStore));
 }
Esempio n. 7
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);
        }