Exemple #1
0
        internal TbsCertificateStructure(
            Asn1Sequence seq)
        {
            int seqStart = 0;

            this.seq = seq;

            //
            // some certficates don't include a version number - we assume v1
            //
            if (seq[0] is DerTaggedObject)
            {
                version = DerInteger.GetInstance((Asn1TaggedObject)seq[0], true);
            }
            else
            {
                seqStart = -1;                          // field 0 is missing!
                version  = new DerInteger(0);
            }

            serialNumber = DerInteger.GetInstance(seq[seqStart + 1]);

            signature = AlgorithmIdentifier.GetInstance(seq[seqStart + 2]);
            issuer    = X509Name.GetInstance(seq[seqStart + 3]);

            //
            // before and after dates
            //
            Asn1Sequence dates = (Asn1Sequence)seq[seqStart + 4];

            startDate = Time.GetInstance(dates[0]);
            endDate   = Time.GetInstance(dates[1]);

            subject = X509Name.GetInstance(seq[seqStart + 5]);

            //
            // public key info.
            //
            subjectPublicKeyInfo = SubjectPublicKeyInfo.GetInstance(seq[seqStart + 6]);

            for (int extras = seq.Count - (seqStart + 6) - 1; extras > 0; extras--)
            {
                DerTaggedObject extra = (DerTaggedObject)seq[seqStart + 6 + extras];

                switch (extra.TagNo)
                {
                case 1:
                    issuerUniqueID = DerBitString.GetInstance(extra, false);
                    break;

                case 2:
                    subjectUniqueID = DerBitString.GetInstance(extra, false);
                    break;

                case 3:
                    extensions = X509Extensions.GetInstance(extra);
                    break;
                }
            }
        }
        private AttributeCertificateInfo(
            Asn1Sequence seq)
        {
            if (seq.Count < 7 || seq.Count > 9)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            this.version                = DerInteger.GetInstance(seq[0]);
            this.holder                 = Holder.GetInstance(seq[1]);
            this.issuer                 = AttCertIssuer.GetInstance(seq[2]);
            this.signature              = AlgorithmIdentifier.GetInstance(seq[3]);
            this.serialNumber           = DerInteger.GetInstance(seq[4]);
            this.attrCertValidityPeriod = AttCertValidityPeriod.GetInstance(seq[5]);
            this.attributes             = Asn1Sequence.GetInstance(seq[6]);

            for (int i = 7; i < seq.Count; i++)
            {
                Asn1Encodable obj = (Asn1Encodable)seq[i];

                if (obj is DerBitString)
                {
                    this.issuerUniqueID = DerBitString.GetInstance(seq[i]);
                }
                else if (obj is Asn1Sequence || obj is X509Extensions)
                {
                    this.extensions = X509Extensions.GetInstance(seq[i]);
                }
            }
        }
Exemple #3
0
        internal TbsCertificateList(
            Asn1Sequence seq)
        {
            if (seq.Count < 3 || seq.Count > 7)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            int seqPos = 0;

            this.seq = seq;

            if (seq[seqPos] is DerInteger)
            {
                version = DerInteger.GetInstance(seq[seqPos++]);
            }
            else
            {
                version = new DerInteger(0);
            }

            signature  = AlgorithmIdentifier.GetInstance(seq[seqPos++]);
            issuer     = X509Name.GetInstance(seq[seqPos++]);
            thisUpdate = Time.GetInstance(seq[seqPos++]);

            if (seqPos < seq.Count &&
                (seq[seqPos] is DerUtcTime ||
                 seq[seqPos] is DerGeneralizedTime ||
                 seq[seqPos] is Time))
            {
                nextUpdate = Time.GetInstance(seq[seqPos++]);
            }

            if (seqPos < seq.Count &&
                !(seq[seqPos] is DerTaggedObject))
            {
                revokedCertificates = Asn1Sequence.GetInstance(seq[seqPos++]);
            }

            if (seqPos < seq.Count &&
                seq[seqPos] is DerTaggedObject)
            {
                crlExtensions = X509Extensions.GetInstance(seq[seqPos]);
            }
        }