Example #1
0
		public OcspRequest(
            TbsRequest	tbsRequest,
            Signature	optionalSignature)
        {
			if (tbsRequest == null)
				throw new ArgumentNullException("tbsRequest");

			this.tbsRequest = tbsRequest;
            this.optionalSignature = optionalSignature;
        }
Example #2
0
        private OcspRequest(
            Asn1Sequence seq)
        {
            tbsRequest = TbsRequest.GetInstance(seq[0]);

            if (seq.Count == 2)
            {
                optionalSignature = Signature.GetInstance(
                    (Asn1TaggedObject)seq[1], true);
            }
        }
Example #3
0
		private OcspRequest(
            Asn1Sequence seq)
        {
            tbsRequest = TbsRequest.GetInstance(seq[0]);

			if (seq.Count == 2)
            {
                optionalSignature = Signature.GetInstance(
					(Asn1TaggedObject)seq[1], true);
            }
        }
Example #4
0
        public OcspRequest(
            TbsRequest tbsRequest,
            Signature optionalSignature)
        {
            if (tbsRequest == null)
            {
                throw new ArgumentNullException("tbsRequest");
            }

            this.tbsRequest        = tbsRequest;
            this.optionalSignature = optionalSignature;
        }
		private OcspReq GenerateRequest(
			DerObjectIdentifier		signingAlgorithm,
			AsymmetricKeyParameter	privateKey,
			X509Certificate[]		chain,
			SecureRandom			random)
		{
			Asn1EncodableVector requests = new Asn1EncodableVector();

			foreach (RequestObject reqObj in list)
			{
				try
				{
					requests.Add(reqObj.ToRequest());
				}
				catch (Exception e)
				{
					throw new OcspException("exception creating Request", e);
				}
			}

			TbsRequest tbsReq = new TbsRequest(requestorName, new DerSequence(requests), requestExtensions);

			ISigner sig = null;
			Signature signature = null;

			if (signingAlgorithm != null)
			{
				if (requestorName == null)
				{
					throw new OcspException("requestorName must be specified if request is signed.");
				}

				try
				{
					sig = SignerUtilities.GetSigner(signingAlgorithm.Id);
					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 = tbsReq.GetEncoded();
					sig.BlockUpdate(encoded, 0, encoded.Length);

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

				AlgorithmIdentifier sigAlgId = new AlgorithmIdentifier(signingAlgorithm, DerNull.Instance);

				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);
					}

					signature = new Signature(sigAlgId, bitSig, new DerSequence(v));
				}
				else
				{
					signature = new Signature(sigAlgId, bitSig);
				}
			}

			return new OcspReq(new OcspRequest(tbsReq, signature));
		}