Example #1
0
        void decodeTbsResponse(Asn1Reader tbsResponseData)
        {
            tbsResponseData.MoveNext();
            if (tbsResponseData.Tag == 160)
            {
                //Asn1Reader aversion = new Asn1Reader(tbsResponseData.RawData, tbsResponseData.PayloadStartOffset);
                Asn1Reader aversion = new Asn1Reader(tbsResponseData);
                aversion.MoveNext();
                Version = aversion.GetPayload()[0] + 1;
                tbsResponseData.MoveNextCurrentLevel();
            }
            else
            {
                Version = 1;
            }
            //responderID
            switch (tbsResponseData.Tag)
            {
            case 161:
                ResponderNameId = new X500DistinguishedName(tbsResponseData.GetPayload());
                tbsResponseData.MoveNextCurrentLevel();
                break;

            case 162:
                tbsResponseData.MoveNext();
                StringBuilder SB = new StringBuilder();
                foreach (Byte element in tbsResponseData.GetPayload())
                {
                    SB.Append(element.ToString("X2"));
                }
                ResponderKeyId = SB.ToString();
                tbsResponseData.MoveNext();
                break;

            default:
                throw new Exception("Invalid tag at responderID. Expected 161 (byName) or 162 (byKey).");
            }
            //tbsResponseData.MoveNextCurrentLevel();
            ProducedAt = Asn1Utils.DecodeGeneralizedTime(tbsResponseData.GetTagRawData());
            if (DateTime.Now < ProducedAt.AddMinutes(-10))
            {
                ResponseErrorInformation += (Int32)OCSPResponseComplianceError.ResponseNotTimeValid;
            }
            //responses
            tbsResponseData.MoveNext();
            //single response
            Asn1Reader responses = new Asn1Reader(tbsResponseData.GetTagRawData());

            responses.MoveNext();
            Int32 Offset;

            Responses = new OCSPSingleResponseCollection();
            do
            {
                Asn1Reader response = new Asn1Reader(responses);
                Offset = response.NextCurrentLevelOffset;
                Responses.Add(new OCSPSingleResponse(response));
                if (Request != null)
                {
                    foreach (OCSPSingleResponse item in Responses)
                    {
                        Boolean certidmatch = Request.RequestList.Any(x => x.CertId.Equals(item.CertId));
                        if (!certidmatch)
                        {
                            ResponseErrorInformation += (Int32)OCSPResponseComplianceError.CertIdMismatch;
                        }
                    }
                }
            } while (Offset != 0);
            if (tbsResponseData.NextCurrentLevelOffset != 0)
            {
                tbsResponseData.MoveNextCurrentLevel();
                if (tbsResponseData.Tag == 161)
                {
                    X509ExtensionCollection exts = new X509ExtensionCollection();
                    exts.Decode(tbsResponseData.GetPayload());
                    foreach (X509Extension item in exts)
                    {
                        _listExtensions.Add(CryptographyUtils.ConvertExtension(item));
                        if (_listExtensions[_listExtensions.Count - 1].Oid.Value == X509CertExtensions.X509OcspNonce)
                        {
                            NonceReceived = true;
                            NonceValue    = _listExtensions[_listExtensions.Count - 1].Format(false);
                        }
                    }
                }
                else
                {
                    throw new Exception("Unexpected tag at responseExtensions. Expected 161.");
                }
            }
        }
 internal OCSPSingleResponseCollectionEnumerator(OCSPSingleResponseCollection entries)
 {
     _entries  = entries;
     m_current = -1;
 }