public OcspReq Generate(string signingAlgorithm, AsymmetricKeyParameter privateKey, X509Certificate[] chain, SecureRandom random)
 {
     //IL_0008: Unknown result type (might be due to invalid IL or missing references)
     //IL_002f: Unknown result type (might be due to invalid IL or missing references)
     if (signingAlgorithm == null)
     {
         throw new ArgumentException("no signing algorithm specified");
     }
     try
     {
         DerObjectIdentifier algorithmOid = OcspUtilities.GetAlgorithmOid(signingAlgorithm);
         return(GenerateRequest(algorithmOid, privateKey, chain, random));
     }
     catch (ArgumentException)
     {
         throw new ArgumentException("unknown signing algorithm specified: " + signingAlgorithm);
     }
 }
Exemple #2
0
        public OcspReq Generate(string signingAlgorithm, AsymmetricKeyParameter privateKey, X509Certificate[] chain, SecureRandom random)
        {
            if (signingAlgorithm == null)
            {
                throw new ArgumentException("no signing algorithm specified");
            }
            OcspReq result;

            try
            {
                DerObjectIdentifier algorithmOid = OcspUtilities.GetAlgorithmOid(signingAlgorithm);
                result = this.GenerateRequest(algorithmOid, privateKey, chain, random);
            }
            catch (ArgumentException)
            {
                throw new ArgumentException("unknown signing algorithm specified: " + signingAlgorithm);
            }
            return(result);
        }
        private BasicOcspResp GenerateResponse(string signatureName, AsymmetricKeyParameter privateKey, X509Certificate[] chain, DateTime producedAt, SecureRandom random)
        {
            DerObjectIdentifier algorithmOid;

            try
            {
                algorithmOid = OcspUtilities.GetAlgorithmOid(signatureName);
            }
            catch (Exception innerException)
            {
                throw new ArgumentException("unknown signing algorithm specified", innerException);
            }
            Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(new Asn1Encodable[0]);

            foreach (BasicOcspRespGenerator.ResponseObject responseObject in this.list)
            {
                try
                {
                    asn1EncodableVector.Add(new Asn1Encodable[]
                    {
                        responseObject.ToResponse()
                    });
                }
                catch (Exception e)
                {
                    throw new OcspException("exception creating Request", e);
                }
            }
            ResponseData responseData = new ResponseData(this.responderID.ToAsn1Object(), new DerGeneralizedTime(producedAt), new DerSequence(asn1EncodableVector), this.responseExtensions);
            ISigner      signer       = null;

            try
            {
                signer = SignerUtilities.GetSigner(signatureName);
                if (random != null)
                {
                    signer.Init(true, new ParametersWithRandom(privateKey, random));
                }
                else
                {
                    signer.Init(true, privateKey);
                }
            }
            catch (Exception ex)
            {
                throw new OcspException("exception creating signature: " + ex, ex);
            }
            DerBitString signature = null;

            try
            {
                byte[] derEncoded = responseData.GetDerEncoded();
                signer.BlockUpdate(derEncoded, 0, derEncoded.Length);
                signature = new DerBitString(signer.GenerateSignature());
            }
            catch (Exception ex2)
            {
                throw new OcspException("exception processing TBSRequest: " + ex2, ex2);
            }
            AlgorithmIdentifier sigAlgID = OcspUtilities.GetSigAlgID(algorithmOid);
            DerSequence         certs    = null;

            if (chain != null && chain.Length > 0)
            {
                Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector(new Asn1Encodable[0]);
                try
                {
                    for (int num = 0; num != chain.Length; num++)
                    {
                        asn1EncodableVector2.Add(new Asn1Encodable[]
                        {
                            X509CertificateStructure.GetInstance(Asn1Object.FromByteArray(chain[num].GetEncoded()))
                        });
                    }
                }
                catch (IOException e2)
                {
                    throw new OcspException("error processing certs", e2);
                }
                catch (CertificateEncodingException e3)
                {
                    throw new OcspException("error encoding certs", e3);
                }
                certs = new DerSequence(asn1EncodableVector2);
            }
            return(new BasicOcspResp(new BasicOcspResponse(responseData, sigAlgID, signature, certs)));
        }
        private BasicOcspResp GenerateResponse(
            string signatureName,
            AsymmetricKeyParameter privateKey,
            X509Certificate[]               chain,
            DateTime producedAt,
            SecureRandom random)
        {
            DerObjectIdentifier signingAlgorithm;

            try
            {
                signingAlgorithm = OcspUtilities.GetAlgorithmOid(signatureName);
            }
            catch (Exception e)
            {
                throw new ArgumentException("unknown signing algorithm specified", "signatureName", e);
            }

            Asn1EncodableVector responses = new Asn1EncodableVector();

            foreach (ResponseObject respObj in list)
            {
                try
                {
                    responses.Add(respObj.ToResponse());
                }
                catch (Exception e)
                {
                    throw new OcspException("exception creating Request", e);
                }
            }

            ResponseData tbsResp = new ResponseData(responderID.ToAsn1Object(), new DerGeneralizedTime(producedAt), new DerSequence(responses), responseExtensions);

            ISigner sig = null;

            try
            {
                sig = SignerUtilities.GetSigner(signatureName);

                if (random != null)
                {
                    sig.Init(true, new ParametersWithRandom(privateKey, random));
                }
                else
                {
                    sig.Init(true, privateKey);
                }
            }
            catch (Exception e)
            {
                throw new OcspException("exception creating signature: " + e, e);
            }

            DerBitString bitSig = null;

            try
            {
                byte[] encoded = tbsResp.GetDerEncoded();
                sig.BlockUpdate(encoded, 0, encoded.Length);

                bitSig = new DerBitString(sig.GenerateSignature());
            }
            catch (Exception e)
            {
                throw new OcspException("exception processing TBSRequest: " + e, e);
            }

            AlgorithmIdentifier sigAlgId = OcspUtilities.GetSigAlgID(signingAlgorithm);

            if (chain != null && chain.Length > 0)
            {
                Asn1EncodableVector v = new Asn1EncodableVector();
                try
                {
                    for (int i = 0; i != chain.Length; i++)
                    {
                        v.Add(
                            X509CertificateStructure.GetInstance(
                                Asn1Object.FromByteArray(chain[i].GetEncoded())));
                    }
                }
                catch (IOException e)
                {
                    throw new OcspException("error processing certs", e);
                }
                catch (CertificateEncodingException e)
                {
                    throw new OcspException("error encoding certs", e);
                }

                return(new BasicOcspResp(new BasicOcspResponse(tbsResp, sigAlgId, bitSig, new DerSequence(v))));
            }
            else
            {
                return(new BasicOcspResp(new BasicOcspResponse(tbsResp, sigAlgId, bitSig, null)));
            }
        }
        private BasicOcspResp GenerateResponse(
            ISignatureFactory signatureCalculator,
            X509Certificate[]               chain,
            DateTime producedAt)
        {
            AlgorithmIdentifier signingAlgID     = (AlgorithmIdentifier)signatureCalculator.AlgorithmDetails;
            DerObjectIdentifier signingAlgorithm = signingAlgID.Algorithm;

            Asn1EncodableVector responses = new Asn1EncodableVector();

            foreach (ResponseObject respObj in list)
            {
                try
                {
                    responses.Add(respObj.ToResponse());
                }
                catch (Exception e)
                {
                    throw new OcspException("exception creating Request", e);
                }
            }

            ResponseData tbsResp = new ResponseData(responderID.ToAsn1Object(), new DerGeneralizedTime(producedAt), new DerSequence(responses), responseExtensions);
            DerBitString bitSig  = null;

            try
            {
                IStreamCalculator streamCalculator = signatureCalculator.CreateCalculator();

                byte[] encoded = tbsResp.GetDerEncoded();

                streamCalculator.Stream.Write(encoded, 0, encoded.Length);

                Platform.Dispose(streamCalculator.Stream);

                bitSig = new DerBitString(((IBlockResult)streamCalculator.GetResult()).Collect());
            }
            catch (Exception e)
            {
                throw new OcspException("exception processing TBSRequest: " + e, e);
            }

            AlgorithmIdentifier sigAlgId = OcspUtilities.GetSigAlgID(signingAlgorithm);

            DerSequence chainSeq = null;

            if (chain != null && chain.Length > 0)
            {
                Asn1EncodableVector v = new Asn1EncodableVector();
                try
                {
                    for (int i = 0; i != chain.Length; i++)
                    {
                        v.Add(
                            X509CertificateStructure.GetInstance(
                                Asn1Object.FromByteArray(chain[i].GetEncoded())));
                    }
                }
                catch (IOException e)
                {
                    throw new OcspException("error processing certs", e);
                }
                catch (CertificateEncodingException e)
                {
                    throw new OcspException("error encoding certs", e);
                }

                chainSeq = new DerSequence(v);
            }

            return(new BasicOcspResp(new BasicOcspResponse(tbsResp, sigAlgId, bitSig, chainSeq)));
        }
        private BasicOcspResp GenerateResponse(ISignatureFactory signatureCalculator, X509Certificate[] chain, global::System.DateTime producedAt)
        {
            //IL_016c: Expected O, but got Unknown
            AlgorithmIdentifier algorithmIdentifier = (AlgorithmIdentifier)signatureCalculator.AlgorithmDetails;
            DerObjectIdentifier algorithm           = algorithmIdentifier.Algorithm;
            Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)list).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    ResponseObject responseObject = (ResponseObject)enumerator.get_Current();
                    try
                    {
                        asn1EncodableVector.Add(responseObject.ToResponse());
                    }
                    catch (global::System.Exception e)
                    {
                        throw new OcspException("exception creating Request", e);
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            ResponseData responseData = new ResponseData(responderID.ToAsn1Object(), new DerGeneralizedTime(producedAt), new DerSequence(asn1EncodableVector), responseExtensions);
            DerBitString derBitString = null;

            try
            {
                IStreamCalculator streamCalculator = signatureCalculator.CreateCalculator();
                byte[]            derEncoded       = responseData.GetDerEncoded();
                streamCalculator.Stream.Write(derEncoded, 0, derEncoded.Length);
                Platform.Dispose(streamCalculator.Stream);
                derBitString = new DerBitString(((IBlockResult)streamCalculator.GetResult()).Collect());
            }
            catch (global::System.Exception ex)
            {
                throw new OcspException(string.Concat((object)"exception processing TBSRequest: ", (object)ex), ex);
            }
            AlgorithmIdentifier sigAlgID = OcspUtilities.GetSigAlgID(algorithm);
            DerSequence         certs    = null;

            if (chain != null && chain.Length > 0)
            {
                Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector();
                try
                {
                    for (int i = 0; i != chain.Length; i++)
                    {
                        asn1EncodableVector2.Add(X509CertificateStructure.GetInstance(Asn1Object.FromByteArray(chain[i].GetEncoded())));
                    }
                }
                catch (IOException val)
                {
                    IOException e2 = val;
                    throw new OcspException("error processing certs", (global::System.Exception)(object) e2);
                }
                catch (CertificateEncodingException e3)
                {
                    throw new OcspException("error encoding certs", e3);
                }
                certs = new DerSequence(asn1EncodableVector2);
            }
            return(new BasicOcspResp(new BasicOcspResponse(responseData, sigAlgID, derBitString, certs)));
        }