GetSignedAttributes() private method

private GetSignedAttributes ( SignatureParameters parameters ) : IDictionary
parameters SignatureParameters
return IDictionary
Exemplo n.º 1
1
        /// <exception cref="System.IO.IOException"></exception>
        //private CmsSignedDataGenerator CreateCMSSignedDataGenerator(ContentSigner contentSigner
        //    , DigestCalculatorProvider digestCalculatorProvider, SignatureParameters parameters
        //    , CAdESProfileBES cadesProfile, bool includeUnsignedAttributes, CmsSignedData originalSignedData
        //    )
        private CmsSignedDataGenerator CreateCMSSignedDataGenerator(ISigner signer
            , SignatureParameters parameters, CAdESProfileBES cadesProfile
            , bool includeUnsignedAttributes, CmsSignedData originalSignedData
            )
        {
            try
            {
                CmsSignedDataGenerator generator = new CmsSignedDataGenerator();
                X509Certificate signerCertificate = parameters.SigningCertificate;

                //X509CertificateHolder certHolder = new X509CertificateHolder(signerCertificate.GetEncoded());
                ArrayList certList = new ArrayList();
                certList.Add(signerCertificate);
                IX509Store certHolder = X509StoreFactory.Create("CERTIFICATE/COLLECTION",
                    new X509CollectionStoreParameters(certList));

                //jbonilla - El provider siempre es BC C#
                //SignerInfoGeneratorBuilder sigInfoGeneratorBuilder = new SignerInfoGeneratorBuilder
                //    (digestCalculatorProvider);

                CmsAttributeTableGenerator signedAttrGen = new DefaultSignedAttributeTableGenerator
                    (new AttributeTable(cadesProfile.GetSignedAttributes(parameters)));

                CmsAttributeTableGenerator unsignedAttrGen = new SimpleAttributeTableGenerator
                    ((includeUnsignedAttributes) ? new AttributeTable(cadesProfile.GetUnsignedAttributes
                    (parameters)) : null);

                //jbonilla - No existe ContentSigner en BC C#
                //SignerInfoGenerator sigInfoGen = sigInfoGeneratorBuilder.Build(contentSigner, certHolder);                

                //generator.AddSignerInfoGenerator(sigInfoGen);
                generator.SignerProvider = signer;
                generator.AddSigner(new NullPrivateKey(), signerCertificate, parameters.SignatureAlgorithm.GetOid()
                    , parameters.DigestAlgorithm.GetOid(), signedAttrGen, unsignedAttrGen);

                if (originalSignedData != null)
                {
                    generator.AddSigners(originalSignedData.GetSignerInfos());
                }
                //ICollection<X509Certificate> certs = new AList<X509Certificate>();
                IList certs = new ArrayList();
                //certs.AddItem(parameters.SigningCertificate);
                certs.Add(parameters.SigningCertificate);
                if (parameters.CertificateChain != null)
                {
                    foreach (X509Certificate c in parameters.CertificateChain)
                    {
                        if (!c.SubjectDN.Equals(parameters.SigningCertificate.SubjectDN))
                        {
                            //certs.AddItem(c);
                            certs.Add(c);
                        }
                    }
                }
                //JcaCertStore certStore = new JcaCertStore(certs);
                IX509Store certStore = X509StoreFactory.Create("Certificate/Collection",
                    new X509CollectionStoreParameters(certs));
                generator.AddCertificates(certStore);
                if (originalSignedData != null)
                {
                    generator.AddCertificates(originalSignedData.GetCertificates("Collection"));
                }
                return generator;
            }
            catch (CmsException e)
            {
                throw new IOException("CmsException", e);
            }
            catch (CertificateEncodingException e)
            {
                throw new IOException("CertificateEncodingException", e);
            }
            /*catch (OperatorCreationException e)
			{
				throw new IOException(e);
			}*/
        }
Exemplo n.º 2
0
        /*
         * /// <exception cref="System.IO.IOException"></exception>
         * public override Document ExtendDocument(Document document, Document originalDocument
         *  , SignatureParameters parameters)
         * {
         *  CAdESSignatureExtension extension = GetExtensionProfile(parameters);
         *  if (extension != null)
         *  {
         *      return extension.ExtendSignatures(document, originalDocument, parameters);
         *  }
         *  else
         *  {
         *      //LOG.Info("No extension for " + parameters.SignatureFormat);
         *  }
         *  return document;
         * }
         */

        private CmsSignedDataGenerator CreateCMSSignedDataGenerator(ISignatureFactory factory,
                                                                    SignatureParameters parameters, CAdESProfileBES cadesProfile,
                                                                    bool includeUnsignedAttributes, CmsSignedData originalSignedData
                                                                    )
        {
            var signedAttrGen = new DefaultSignedAttributeTableGenerator(
                new AttributeTable(cadesProfile.GetSignedAttributes(parameters)));

            SimpleAttributeTableGenerator unsignedAttrGen = null;

            if (includeUnsignedAttributes)
            {
                var attributes = cadesProfile.GetUnsignedAttributes(parameters);
                if (attributes.Count != 0)
                {
                    unsignedAttrGen = new SimpleAttributeTableGenerator(new AttributeTable(attributes));
                }
            }

            SignerInfoGeneratorBuilder sigInfoGeneratorBuilder = new SignerInfoGeneratorBuilder();

            sigInfoGeneratorBuilder.WithSignedAttributeGenerator(signedAttrGen);
            if (unsignedAttrGen != null)
            {
                sigInfoGeneratorBuilder.WithUnsignedAttributeGenerator(unsignedAttrGen);
            }

            CmsSignedDataGenerator generator = new CmsSignedDataGenerator();

            generator.AddSignerInfoGenerator(sigInfoGeneratorBuilder.Build(factory, parameters.SigningCertificate));

            if (originalSignedData != null)
            {
                generator.AddSigners(originalSignedData.GetSignerInfos());
            }

            var certs = new List <X509Certificate>();

            certs.Add(parameters.SigningCertificate);
            if (parameters.CertificateChain != null)
            {
                foreach (X509Certificate cert in parameters.CertificateChain)
                {
                    if (!cert.SubjectDN.Equals(parameters.SigningCertificate.SubjectDN))
                    {
                        certs.Add(cert);
                    }
                }
            }
            IX509Store certStore = X509StoreFactory.Create("Certificate/Collection",
                                                           new X509CollectionStoreParameters(certs));

            generator.AddCertificates(certStore);
            if (originalSignedData != null)
            {
                generator.AddCertificates(originalSignedData.GetCertificates("Collection"));
            }

            return(generator);
        }
Exemplo n.º 3
0
        /// <exception cref="System.IO.IOException"></exception>
        //private CmsSignedDataGenerator CreateCMSSignedDataGenerator(ContentSigner contentSigner
        //    , DigestCalculatorProvider digestCalculatorProvider, SignatureParameters parameters
        //    , CAdESProfileBES cadesProfile, bool includeUnsignedAttributes, CmsSignedData originalSignedData
        //    )
        private CmsSignedDataGenerator CreateCMSSignedDataGenerator(ISigner signer
                                                                    , SignatureParameters parameters, CAdESProfileBES cadesProfile
                                                                    , bool includeUnsignedAttributes, CmsSignedData originalSignedData
                                                                    )
        {
            try
            {
                CmsSignedDataGenerator generator         = new CmsSignedDataGenerator();
                X509Certificate        signerCertificate = parameters.SigningCertificate;

                //X509CertificateHolder certHolder = new X509CertificateHolder(signerCertificate.GetEncoded());
                ArrayList certList = new ArrayList();
                certList.Add(signerCertificate);
                IX509Store certHolder = X509StoreFactory.Create("CERTIFICATE/COLLECTION",
                                                                new X509CollectionStoreParameters(certList));

                //jbonilla - El provider siempre es BC C#
                //SignerInfoGeneratorBuilder sigInfoGeneratorBuilder = new SignerInfoGeneratorBuilder
                //    (digestCalculatorProvider);

                CmsAttributeTableGenerator signedAttrGen = new DefaultSignedAttributeTableGenerator
                                                               (new AttributeTable(cadesProfile.GetSignedAttributes(parameters)));

                CmsAttributeTableGenerator unsignedAttrGen = new SimpleAttributeTableGenerator
                                                                 ((includeUnsignedAttributes) ? new AttributeTable(cadesProfile.GetUnsignedAttributes
                                                                                                                       (parameters)) : null);

                //jbonilla - No existe ContentSigner en BC C#
                //SignerInfoGenerator sigInfoGen = sigInfoGeneratorBuilder.Build(contentSigner, certHolder);

                //generator.AddSignerInfoGenerator(sigInfoGen);
                generator.SignerProvider = signer;
                generator.AddSigner(new NullPrivateKey(), signerCertificate, parameters.SignatureAlgorithm.GetOid()
                                    , parameters.DigestAlgorithm.GetOid(), signedAttrGen, unsignedAttrGen);

                if (originalSignedData != null)
                {
                    generator.AddSigners(originalSignedData.GetSignerInfos());
                }
                //ICollection<X509Certificate> certs = new AList<X509Certificate>();
                IList certs = new ArrayList();
                //certs.AddItem(parameters.SigningCertificate);
                certs.Add(parameters.SigningCertificate);
                if (parameters.CertificateChain != null)
                {
                    foreach (X509Certificate c in parameters.CertificateChain)
                    {
                        if (!c.SubjectDN.Equals(parameters.SigningCertificate.SubjectDN))
                        {
                            //certs.AddItem(c);
                            certs.Add(c);
                        }
                    }
                }
                //JcaCertStore certStore = new JcaCertStore(certs);
                IX509Store certStore = X509StoreFactory.Create("Certificate/Collection",
                                                               new X509CollectionStoreParameters(certs));
                generator.AddCertificates(certStore);
                if (originalSignedData != null)
                {
                    generator.AddCertificates(originalSignedData.GetCertificates("Collection"));
                }
                return(generator);
            }
            catch (CmsException e)
            {
                throw new IOException("CmsException", e);
            }
            catch (CertificateEncodingException e)
            {
                throw new IOException("CertificateEncodingException", e);
            }

            /*catch (OperatorCreationException e)
             *          {
             *                  throw new IOException(e);
             *          }*/
        }