Esempio n. 1
0
        void m_initialize(Asn1Reader response)
        {
            response.MoveNext();
            CertId = new CertID(Asn1Utils.Encode(response.GetPayload(), 48));
            response.MoveNextCurrentLevel();
            switch (response.Tag)
            {
            case 128:
                CertStatus = CertificateStatus.Good;
                response.MoveNextCurrentLevel();
                break;

            case 161:
                CertStatus = CertificateStatus.Revoked;
                response.MoveNext();
                DateTime revokedWhen = Asn1Utils.DecodeGeneralizedTime(response.GetTagRawData());
                response.MoveNext();
                Int16 reason = 0;
                if (response.Tag == 160)
                {
                    response.MoveNext();
                    reason = response.GetPayload()[0];
                    response.MoveNext();
                }
                RevocationInfo = new X509CRLEntry(CertId.SerialNumber, revokedWhen, reason);
                break;

            case 130:
                CertStatus = CertificateStatus.Unknown;
                response.MoveNextCurrentLevel();
                break;
            }
            //response.MoveNextCurrentLevel();
            ThisUpdate = Asn1Utils.DecodeGeneralizedTime(response.GetTagRawData());
            while (response.MoveNextCurrentLevel())
            {
                switch (response.Tag)
                {
                case 160:
                    Asn1Reader asn = new Asn1Reader(response.GetPayload());
                    NextUpdate = Asn1Utils.DecodeGeneralizedTime(asn.GetTagRawData());
                    break;

                case 161:
                    Extensions = Crypt32Managed.DecodeX509Extensions(response.GetPayload());
                    break;
                }
            }
        }
Esempio n. 2
0
        void m_initialize(Byte[] rawData)
        {
            Asn1Reader asn = new Asn1Reader(rawData);

            if (asn.Tag != 48)
            {
                throw new InvalidDataException();
            }
            asn.MoveNext();
            if (asn.Tag != (Byte)Asn1Type.INTEGER)
            {
                throw new InvalidDataException();
            }
            SerialNumber = Asn1Utils.DecodeInteger(asn.GetTagRawData(), true);
            asn.MoveNext();
            if (asn.Tag != (Byte)Asn1Type.UTCTime && asn.Tag != (Byte)Asn1Type.Generalizedtime)
            {
                throw new InvalidDataException();
            }
            if (asn.Tag == (Byte)Asn1Type.UTCTime)
            {
                RevocationDate = Asn1Utils.DecodeUTCTime(asn.GetTagRawData());
            }
            if (asn.Tag == (Byte)Asn1Type.Generalizedtime)
            {
                RevocationDate = Asn1Utils.DecodeGeneralizedTime(asn.GetTagRawData());
            }
            if (asn.MoveNext())
            {
                foreach (X509Extension item in Crypt32Managed.DecodeX509Extensions(asn.GetTagRawData()).Cast <X509Extension>().Where(item => item.Oid.Value == "2.5.29.21"))
                {
                    ReasonCode = item.RawData[2];
                }
            }
            RawData = rawData;
        }
Esempio n. 3
0
 void getExtensions(Byte[] bytes)
 {
     exts = Crypt32Managed.DecodeX509Extensions(bytes);
 }
Esempio n. 4
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 = false;
                        foreach (OCSPSingleRequest reqitem in Request.RequestList.Cast <OCSPSingleRequest>().Where(reqitem => reqitem.CertId.Equals(item.CertId)))
                        {
                            certidmatch = true;
                        }
                        if (!certidmatch)
                        {
                            ResponseErrorInformation += (Int32)OCSPResponseComplianceError.CertIdMismatch;
                        }
                    }
                }
            } while (Offset != 0);
            if (tbsResponseData.NextCurrentLevelOffset != 0)
            {
                tbsResponseData.MoveNextCurrentLevel();
                if (tbsResponseData.Tag == 161)
                {
                    X509ExtensionCollection exts = Crypt32Managed.DecodeX509Extensions(tbsResponseData.GetPayload());
                    foreach (X509Extension item in exts)
                    {
                        _listExtensions.Add(CryptographyUtils.ConvertExtension(item));
                        if (_listExtensions[_listExtensions.Count - 1].Oid.Value == "1.3.6.1.5.5.7.48.1.2")
                        {
                            NonceReceived = true;
                            NonceValue    = _listExtensions[_listExtensions.Count - 1].Format(false);
                        }
                    }
                }
                else
                {
                    throw new Exception("Unexpected tag at responseExtensions. Expected 161.");
                }
            }
        }