Exemple #1
0
        void decodeCms(Asn1Reader asn)
        {
            asn.MoveNextAndExpectTags(48, (Byte)Asn1Type.OBJECT_IDENTIFIER);
            if (asn.Tag == 48)
            {
                Status = new TspStatusInfo(asn.GetTagRawData());
                if (Status.ResponseStatus != TspResponseStatus.Granted && Status.ResponseStatus != TspResponseStatus.GrantedWithModifications)
                {
                    return;
                }
                asn.MoveNextCurrentLevelAndExpectTags(48);
            }
            else
            {
                asn.MoveToPosition(0);
            }
            signedCms = new DefaultSignedPkcs7(asn.GetTagRawData());

            ResponseType = signedCms.ContentType;
            switch (ResponseType.Value)
            {
            // TimeStamp Token
            case "1.2.840.113549.1.9.16.1.4":
                decodeTstInfo(new Asn1Reader(signedCms.Content));
                break;

            // PKCS 7 DATA
            case "1.2.840.113549.1.7.1":
                break;
            }
            getSigningTime();
            _rawData.AddRange(asn.GetRawData());
            validate();
        }
Exemple #2
0
        void m_decode(Byte[] rawData)
        {
            var aiaUrls  = new List <String>();
            var ocspUrls = new List <String>();
            var asn      = new Asn1Reader(rawData);

            if (asn.Tag != 48)
            {
                throw new Asn1InvalidTagException(asn.Offset);
            }
            asn.MoveNext();
            do
            {
                Int32 offset = asn.Offset;
                if (asn.Tag != 48)
                {
                    throw new Asn1InvalidTagException(asn.Offset);
                }
                asn.MoveNext();
                String oidString = Asn1Utils.DecodeObjectIdentifier(asn.GetTagRawData()).Value;
                asn.MoveNextAndExpectTags(0x86);
                switch (oidString)
                {
                case "1.3.6.1.5.5.7.48.2": aiaUrls.Add(Encoding.ASCII.GetString(asn.GetPayload())); break;

                case "1.3.6.1.5.5.7.48.1": ocspUrls.Add(Encoding.ASCII.GetString(asn.GetPayload())); break;
                }
                asn.MoveToPosition(offset);
            } while (asn.MoveNextCurrentLevel());
            CertificationAuthorityIssuer    = aiaUrls.ToArray();
            OnlineCertificateStatusProtocol = ocspUrls.ToArray();
        }
Exemple #3
0
        void m_decode(Byte[] rawData)
        {
            Asn1Reader asn = new Asn1Reader(rawData);

            if (asn.Tag != 48)
            {
                throw new Asn1InvalidTagException(asn.Offset);
            }
            asn.MoveNext();
            Oid oid = Asn1Utils.DecodeObjectIdentifier(asn.GetTagRawData());

            switch (oid.Value)
            {
            case "1.3.6.1.5.5.7.2.1":
                Type = X509PolicyQualifierType.CpsUrl;
                asn.MoveNext();
                PolicyUrl = new Uri(Asn1Utils.DecodeIA5String(asn.GetTagRawData()).Replace("\0", null));
                break;

            case "1.3.6.1.5.5.7.2.2":
                Type = X509PolicyQualifierType.UserNotice;
                if (!asn.MoveNext())
                {
                    return;
                }
                if (asn.Tag != 48)
                {
                    throw new Asn1InvalidTagException(asn.Offset);
                }
                asn.MoveNext();
                if (asn.Tag == 48)
                {
                    Int32 offset = asn.Offset;
                    asn.MoveNext();
                    NoticeReference = Asn1Utils.DecodeAnyString(asn.GetTagRawData(), new[] { Asn1Type.IA5String, Asn1Type.VisibleString, Asn1Type.BMPString, Asn1Type.UTF8String });
                    asn.MoveNext();
                    asn.MoveNext();
                    NoticeNumber = (Int32)Asn1Utils.DecodeInteger(asn.GetTagRawData());
                    asn.MoveToPosition(offset);
                    if (asn.MoveNextCurrentLevel())
                    {
                        NoticeText = Asn1Utils.DecodeAnyString(asn.GetTagRawData(), new[] { Asn1Type.IA5String, Asn1Type.VisibleString, Asn1Type.BMPString, Asn1Type.UTF8String });
                    }
                }
                else
                {
                    NoticeText = Asn1Utils.DecodeAnyString(asn.GetTagRawData(), new[] { Asn1Type.IA5String, Asn1Type.VisibleString, Asn1Type.BMPString, Asn1Type.UTF8String });
                }
                break;

            default: m_reset(); return;
            }
        }
Exemple #4
0
        void decodeSignerInfos(Asn1Reader asn)
        {
            if (asn.PayloadLength == 0)
            {
                return;
            }
            Int32 offset = asn.Offset;

            asn.MoveNext();
            do
            {
                _signerInfos.Add(new PkcsSignerInfo(asn.GetTagRawData()));
            } while (asn.MoveNextCurrentLevel());
            asn.MoveToPosition(offset);
        }
Exemple #5
0
        void decodeCRLs(Asn1Reader asn)
        {
            if (asn.PayloadLength == 0)
            {
                return;
            }
            Int32 offset = asn.Offset;

            asn.MoveNext();
            do
            {
                _crls.Add(new X509CRL2(asn.GetTagRawData()));
            } while (asn.MoveNextCurrentLevel());
            asn.MoveToPosition(offset);
        }
Exemple #6
0
        void decodeValidity(Asn1Reader asn)
        {
            ThisUpdate = Asn1Utils.DecodeDateTime(asn.GetTagRawData());
            Int32 offset = asn.Offset;

            asn.MoveNext();
            if (asn.Tag == (Byte)Asn1Type.UTCTime || asn.Tag == (Byte)Asn1Type.GeneralizedTime)
            {
                NextUpdate = Asn1Utils.DecodeDateTime(asn.GetTagRawData());
            }
            else
            {
                asn.MoveToPosition(offset);
            }
            //asn.MoveToPosition(offset);
        }
Exemple #7
0
        static void buildTree(Asn1Reader root, Asn1TreeNode tree)
        {
            root.MoveNext();
            Int32 index = 0;

            do
            {
                tree.AddChild(new Asn1Lite(root, tree, index));
                index++;
            } while (root.MoveNextCurrentLevel());
            root.Reset();
            foreach (Asn1TreeNode node in tree.Children.Where(node => node.Value.IsContainer && node.Value.PayloadLength > 0))
            {
                root.MoveToPosition(node.Value.Offset);
                buildTree(root, node);
            }
        }
Exemple #8
0
        void decodeDigestAlgorithms(Asn1Reader asn)
        {
            // asn tag -> SET (0x31)
            Int32 offset = asn.Offset;

            if (asn.PayloadLength == 0)
            {
                return;
            }
            asn.MoveNext();
            do
            {
                _digestAlgorithms.Add(new AlgorithmIdentifier(asn.GetTagRawData()));
            } while (asn.MoveNextCurrentLevel());

            asn.MoveToPosition(offset);
        }
Exemple #9
0
        void decodeCertificates(Asn1Reader asn)
        {
            if (asn.PayloadLength == 0)
            {
                return;
            }
            Int32 offset = asn.Offset;

            asn.MoveNext();
            do
            {
                // sometimes we can get thing called ExtendedCertificate. I have no idea what it is.
                try {
                    _certificates.Add(new X509Certificate2(asn.GetTagRawData()));
                } catch { }
            } while (asn.MoveNextCurrentLevel());
            asn.MoveToPosition(offset);
        }
Exemple #10
0
        Byte[] extractContent(Asn1Reader asn)
        {
            Int32 offset = asn.Offset;

            asn.MoveNext();
            Byte[] payload = null;
            ContentType = new Asn1ObjectIdentifier(asn.GetTagRawData()).Value;
            if (asn.MoveNextCurrentLevel())
            {
                // content [0] EXPLICIT ANY DEFINED BY contentType
                asn.MoveNextAndExpectTags((Byte)Asn1Type.OCTET_STRING, 48); // octet string or sequence
                payload       = asn.GetPayload();
                contentOffset = asn.Offset;
                contentSize   = asn.TagLength;
            }
            asn.MoveToPosition(offset);
            return(payload);
        }