コード例 #1
0
ファイル: X509Name.cs プロジェクト: arvindixonos/Zain360
        /**
         * test for equivalence - note: case is ignored.
         */
        public bool Equivalent(
            X509Name other)
        {
            if (other == null)
            {
                return(false);
            }

            if (other == this)
            {
                return(true);
            }

            int orderingSize = ordering.Count;

            if (orderingSize != other.ordering.Count)
            {
                return(false);
            }

            bool[] indexes = new bool[orderingSize];
            int    start, end, delta;

            if (ordering[0].Equals(other.ordering[0]))   // guess forward
            {
                start = 0;
                end   = orderingSize;
                delta = 1;
            }
            else  // guess reversed - most common problem
            {
                start = orderingSize - 1;
                end   = -1;
                delta = -1;
            }

            for (int i = start; i != end; i += delta)
            {
                bool found = false;
                DerObjectIdentifier oid = (DerObjectIdentifier)ordering[i];
                string value            = (string)values[i];

                for (int j = 0; j < orderingSize; j++)
                {
                    if (indexes[j])
                    {
                        continue;
                    }

                    DerObjectIdentifier oOid = (DerObjectIdentifier)other.ordering[j];

                    if (oid.Equals(oOid))
                    {
                        string oValue = (string)other.values[j];

                        if (equivalentStrings(value, oValue))
                        {
                            indexes[j] = true;
                            found      = true;
                            break;
                        }
                    }
                }

                if (!found)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
 public void SetIssuer(
     X509Name issuer)
 {
     this.issuer = issuer;
 }
コード例 #3
0
 public void SetSubject(
     X509Name subject)
 {
     this.subject = subject;
 }
コード例 #4
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 Asn1TaggedObject)
            {
                version = DerInteger.GetInstance((Asn1TaggedObject)seq[0], true);
            }
            else
            {
                seqStart = -1;                          // field 0 is missing!
                version  = new DerInteger(0);
            }

            bool isV1 = false;
            bool isV2 = false;

            if (version.Value.Equals(BigInteger.Zero))
            {
                isV1 = true;
            }
            else if (version.Value.Equals(BigInteger.One))
            {
                isV2 = true;
            }
            else if (!version.Value.Equals(BigInteger.Two))
            {
                throw new ArgumentException("version number not recognised");
            }

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

            int extras = seq.Count - (seqStart + 6) - 1;

            if (extras != 0 && isV1)
            {
                throw new ArgumentException("version 1 certificate contains extra data");
            }

            while (extras > 0)
            {
                Asn1TaggedObject extra = Asn1TaggedObject.GetInstance(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:
                {
                    if (isV2)
                    {
                        throw new ArgumentException("version 2 certificate cannot contain extensions");
                    }

                    extensions = X509Extensions.GetInstance(Asn1Sequence.GetInstance(extra, true));
                    break;
                }

                default:
                {
                    throw new ArgumentException("Unknown tag encountered in structure: " + extra.TagNo);
                }
                }
                extras--;
            }
        }