Esempio n. 1
0
        /// <summary>
        /// Returns a new PKCS#7 instance containing certificates and (optionally CRLs)
        /// </summary>
        /// <param name="CertificateList">The certificate list.</param>
        /// <param name="CrlList">The CRL list.</param>
        /// <returns>
        /// PKCS#7 instance
        /// </returns>
        /// <exception cref="System.ArgumentException">No input</exception>
        public static CmsSignedData Create(ArrayList CertificateList, ArrayList CrlList)
        {
            if ((CertificateList == null) && (CrlList == null))
            {
                throw new ArgumentException("No input");
            }

            CmsSignedDataGenerator p7Gen = new CmsSignedDataGenerator();

            IX509Store certs = X509StoreFactory.Create("CERTIFICATE/COLLECTION", new X509CollectionStoreParameters(CertificateList));

            p7Gen.AddCertificates(certs);

            // If CRL is required
            if (CrlList != null)
            {
                IX509Store crls = X509StoreFactory.Create("CRL/COLLECTION", new X509CollectionStoreParameters(CrlList));
                p7Gen.AddCrls(crls);
            }

            return(p7Gen.Generate(null));
        }
Esempio n. 2
0
        public TimeStampToken Generate(
            TimeStampRequest request,
            BigInteger serialNumber,
            DateTime genTime, X509Extensions additionalExtensions)
        {
            DerObjectIdentifier digestAlgOID = new DerObjectIdentifier(request.MessageImprintAlgOid);

            AlgorithmIdentifier algID          = new AlgorithmIdentifier(digestAlgOID, DerNull.Instance);
            MessageImprint      messageImprint = new MessageImprint(algID, request.GetMessageImprintDigest());

            Accuracy accuracy = null;

            if (accuracySeconds > 0 || accuracyMillis > 0 || accuracyMicros > 0)
            {
                DerInteger seconds = null;
                if (accuracySeconds > 0)
                {
                    seconds = new DerInteger(accuracySeconds);
                }

                DerInteger millis = null;
                if (accuracyMillis > 0)
                {
                    millis = new DerInteger(accuracyMillis);
                }

                DerInteger micros = null;
                if (accuracyMicros > 0)
                {
                    micros = new DerInteger(accuracyMicros);
                }

                accuracy = new Accuracy(seconds, millis, micros);
            }

            DerBoolean derOrdering = null;

            if (ordering)
            {
                derOrdering = DerBoolean.GetInstance(ordering);
            }

            DerInteger nonce = null;

            if (request.Nonce != null)
            {
                nonce = new DerInteger(request.Nonce);
            }

            DerObjectIdentifier tsaPolicy = new DerObjectIdentifier(tsaPolicyOID);

            if (request.ReqPolicy != null)
            {
                tsaPolicy = new DerObjectIdentifier(request.ReqPolicy);
            }


            X509Extensions respExtensions = request.Extensions;

            if (additionalExtensions != null)
            {
                X509ExtensionsGenerator extGen = new X509ExtensionsGenerator();

                if (respExtensions != null)
                {
                    foreach (object oid in respExtensions.ExtensionOids)
                    {
                        DerObjectIdentifier id = DerObjectIdentifier.GetInstance(oid);
                        extGen.AddExtension(id, respExtensions.GetExtension(DerObjectIdentifier.GetInstance(id)));
                    }
                }

                foreach (object oid in additionalExtensions.ExtensionOids)
                {
                    DerObjectIdentifier id = DerObjectIdentifier.GetInstance(oid);
                    extGen.AddExtension(id, additionalExtensions.GetExtension(DerObjectIdentifier.GetInstance(id)));
                }

                respExtensions = extGen.Generate();
            }



            DerGeneralizedTime generalizedTime;

            if (resolution != Resolution.R_SECONDS)
            {
                generalizedTime = new DerGeneralizedTime(createGeneralizedTime(genTime));
            }
            else
            {
                generalizedTime = new DerGeneralizedTime(genTime);
            }


            TstInfo tstInfo = new TstInfo(tsaPolicy, messageImprint,
                                          new DerInteger(serialNumber), generalizedTime, accuracy,
                                          derOrdering, nonce, tsa, respExtensions);

            try
            {
                CmsSignedDataGenerator signedDataGenerator = new CmsSignedDataGenerator();

                byte[] derEncodedTstInfo = tstInfo.GetDerEncoded();

                if (request.CertReq)
                {
                    signedDataGenerator.AddCertificates(x509Certs);
                }

                signedDataGenerator.AddCrls(x509Crls);

                signedDataGenerator.AddSignerInfoGenerator(signerInfoGenerator);

                CmsSignedData signedData = signedDataGenerator.Generate(
                    PkcsObjectIdentifiers.IdCTTstInfo.Id,
                    new CmsProcessableByteArray(derEncodedTstInfo),
                    true);

                return(new TimeStampToken(signedData));
            }
            catch (CmsException cmsEx)
            {
                throw new TspException("Error generating time-stamp token", cmsEx);
            }
            catch (IOException e)
            {
                throw new TspException("Exception encoding info", e);
            }
            catch (X509StoreException e)
            {
                throw new TspException("Exception handling CertStore", e);
            }
            //			catch (InvalidAlgorithmParameterException e)
            //			{
            //				throw new TspException("Exception handling CertStore CRLs", e);
            //			}
        }
Esempio n. 3
0
        public TimeStampToken Generate(TimeStampRequest request, BigInteger serialNumber, DateTime genTime)
        {
            DerObjectIdentifier objectID       = new DerObjectIdentifier(request.MessageImprintAlgOid);
            AlgorithmIdentifier hashAlgorithm  = new AlgorithmIdentifier(objectID, DerNull.Instance);
            MessageImprint      messageImprint = new MessageImprint(hashAlgorithm, request.GetMessageImprintDigest());
            Accuracy            accuracy       = null;

            if (this.accuracySeconds > 0 || this.accuracyMillis > 0 || this.accuracyMicros > 0)
            {
                DerInteger seconds = null;
                if (this.accuracySeconds > 0)
                {
                    seconds = new DerInteger(this.accuracySeconds);
                }
                DerInteger millis = null;
                if (this.accuracyMillis > 0)
                {
                    millis = new DerInteger(this.accuracyMillis);
                }
                DerInteger micros = null;
                if (this.accuracyMicros > 0)
                {
                    micros = new DerInteger(this.accuracyMicros);
                }
                accuracy = new Accuracy(seconds, millis, micros);
            }
            DerBoolean derBoolean = null;

            if (this.ordering)
            {
                derBoolean = DerBoolean.GetInstance(this.ordering);
            }
            DerInteger nonce = null;

            if (request.Nonce != null)
            {
                nonce = new DerInteger(request.Nonce);
            }
            DerObjectIdentifier tsaPolicyId = new DerObjectIdentifier(this.tsaPolicyOID);

            if (request.ReqPolicy != null)
            {
                tsaPolicyId = new DerObjectIdentifier(request.ReqPolicy);
            }
            TstInfo        tstInfo = new TstInfo(tsaPolicyId, messageImprint, new DerInteger(serialNumber), new DerGeneralizedTime(genTime), accuracy, derBoolean, nonce, this.tsa, request.Extensions);
            TimeStampToken result;

            try
            {
                CmsSignedDataGenerator cmsSignedDataGenerator = new CmsSignedDataGenerator();
                byte[] derEncoded = tstInfo.GetDerEncoded();
                if (request.CertReq)
                {
                    cmsSignedDataGenerator.AddCertificates(this.x509Certs);
                }
                cmsSignedDataGenerator.AddCrls(this.x509Crls);
                cmsSignedDataGenerator.AddSigner(this.key, this.cert, this.digestOID, this.signedAttr, this.unsignedAttr);
                CmsSignedData signedData = cmsSignedDataGenerator.Generate(PkcsObjectIdentifiers.IdCTTstInfo.Id, new CmsProcessableByteArray(derEncoded), true);
                result = new TimeStampToken(signedData);
            }
            catch (CmsException e)
            {
                throw new TspException("Error generating time-stamp token", e);
            }
            catch (IOException e2)
            {
                throw new TspException("Exception encoding info", e2);
            }
            catch (X509StoreException e3)
            {
                throw new TspException("Exception handling CertStore", e3);
            }
            return(result);
        }
        //------------------------------------------------------------------------------

        public TimeStampToken Generate(
            TimeStampRequest request,
            IBigInteger serialNumber,
            DateTime genTime)
        {
            DerObjectIdentifier digestAlgOID = new DerObjectIdentifier(request.MessageImprintAlgOid);

            AlgorithmIdentifier algID          = new AlgorithmIdentifier(digestAlgOID, DerNull.Instance);
            MessageImprint      messageImprint = new MessageImprint(algID, request.GetMessageImprintDigest());

            Accuracy accuracy = null;

            if (accuracySeconds > 0 || accuracyMillis > 0 || accuracyMicros > 0)
            {
                DerInteger seconds = null;
                if (accuracySeconds > 0)
                {
                    seconds = new DerInteger(accuracySeconds);
                }

                DerInteger millis = null;
                if (accuracyMillis > 0)
                {
                    millis = new DerInteger(accuracyMillis);
                }

                DerInteger micros = null;
                if (accuracyMicros > 0)
                {
                    micros = new DerInteger(accuracyMicros);
                }

                accuracy = new Accuracy(seconds, millis, micros);
            }

            DerBoolean derOrdering = null;

            if (ordering)
            {
                derOrdering = DerBoolean.GetInstance(ordering);
            }

            DerInteger nonce = null;

            if (request.Nonce != null)
            {
                nonce = new DerInteger(request.Nonce);
            }

            DerObjectIdentifier tsaPolicy = new DerObjectIdentifier(tsaPolicyOID);

            if (request.ReqPolicy != null)
            {
                tsaPolicy = new DerObjectIdentifier(request.ReqPolicy);
            }

            TstInfo tstInfo = new TstInfo(tsaPolicy, messageImprint,
                                          new DerInteger(serialNumber), new DerGeneralizedTime(genTime), accuracy,
                                          derOrdering, nonce, tsa, request.Extensions);

            try
            {
                CmsSignedDataGenerator signedDataGenerator = new CmsSignedDataGenerator();

                byte[] derEncodedTstInfo = tstInfo.GetDerEncoded();

                if (request.CertReq)
                {
                    signedDataGenerator.AddCertificates(x509Certs);
                }

                signedDataGenerator.AddCrls(x509Crls);
                signedDataGenerator.AddSigner(key, cert, digestOID, signedAttr, unsignedAttr);

                CmsSignedData signedData = signedDataGenerator.Generate(
                    PkcsObjectIdentifiers.IdCTTstInfo.Id,
                    new CmsProcessableByteArray(derEncodedTstInfo),
                    true);

                return(new TimeStampToken(signedData));
            }
            catch (CmsException cmsEx)
            {
                throw new TspException("Error generating time-stamp token", cmsEx);
            }
            catch (IOException e)
            {
                throw new TspException("Exception encoding info", e);
            }
            catch (X509StoreException e)
            {
                throw new TspException("Exception handling CertStore", e);
            }
//			catch (InvalidAlgorithmParameterException e)
//			{
//				throw new TspException("Exception handling CertStore CRLs", e);
//			}
        }
        public TimeStampToken Generate(TimeStampRequest request, BigInteger serialNumber, global::System.DateTime genTime)
        {
            //IL_01a0: Expected O, but got Unknown
            DerObjectIdentifier algorithm      = new DerObjectIdentifier(request.MessageImprintAlgOid);
            AlgorithmIdentifier hashAlgorithm  = new AlgorithmIdentifier(algorithm, DerNull.Instance);
            MessageImprint      messageImprint = new MessageImprint(hashAlgorithm, request.GetMessageImprintDigest());
            Accuracy            accuracy       = null;

            if (accuracySeconds > 0 || accuracyMillis > 0 || accuracyMicros > 0)
            {
                DerInteger seconds = null;
                if (accuracySeconds > 0)
                {
                    seconds = new DerInteger(accuracySeconds);
                }
                DerInteger millis = null;
                if (accuracyMillis > 0)
                {
                    millis = new DerInteger(accuracyMillis);
                }
                DerInteger micros = null;
                if (accuracyMicros > 0)
                {
                    micros = new DerInteger(accuracyMicros);
                }
                accuracy = new Accuracy(seconds, millis, micros);
            }
            DerBoolean derBoolean = null;

            if (ordering)
            {
                derBoolean = DerBoolean.GetInstance(ordering);
            }
            DerInteger nonce = null;

            if (request.Nonce != null)
            {
                nonce = new DerInteger(request.Nonce);
            }
            DerObjectIdentifier tsaPolicyId = new DerObjectIdentifier(tsaPolicyOID);

            if (request.ReqPolicy != null)
            {
                tsaPolicyId = new DerObjectIdentifier(request.ReqPolicy);
            }
            TstInfo tstInfo = new TstInfo(tsaPolicyId, messageImprint, new DerInteger(serialNumber), new DerGeneralizedTime(genTime), accuracy, derBoolean, nonce, tsa, request.Extensions);

            try
            {
                CmsSignedDataGenerator cmsSignedDataGenerator = new CmsSignedDataGenerator();
                byte[] derEncoded = tstInfo.GetDerEncoded();
                if (request.CertReq)
                {
                    cmsSignedDataGenerator.AddCertificates(x509Certs);
                }
                cmsSignedDataGenerator.AddCrls(x509Crls);
                cmsSignedDataGenerator.AddSigner(key, cert, digestOID, signedAttr, unsignedAttr);
                CmsSignedData signedData = cmsSignedDataGenerator.Generate(PkcsObjectIdentifiers.IdCTTstInfo.Id, new CmsProcessableByteArray(derEncoded), encapsulate: true);
                return(new TimeStampToken(signedData));
            }
            catch (CmsException e)
            {
                throw new TspException("Error generating time-stamp token", e);
            }
            catch (IOException val)
            {
                IOException e2 = val;
                throw new TspException("Exception encoding info", (global::System.Exception)(object) e2);
            }
            catch (X509StoreException e3)
            {
                throw new TspException("Exception handling CertStore", e3);
            }
        }