예제 #1
0
 private CertificateList(Asn1Sequence seq)
 {
     //IL_0019: Unknown result type (might be due to invalid IL or missing references)
     if (seq.Count != 3)
     {
         throw new ArgumentException("sequence wrong size for CertificateList", "seq");
     }
     tbsCertList = TbsCertificateList.GetInstance(seq[0]);
     sigAlgID    = AlgorithmIdentifier.GetInstance(seq[1]);
     sig         = DerBitString.GetInstance(seq[2]);
 }
예제 #2
0
        private SubjectPublicKeyInfo(
            Asn1Sequence seq)
        {
            if (seq.Count != 2)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
            }

            this.algID   = AlgorithmIdentifier.GetInstance(seq[0]);
            this.keyData = DerBitString.GetInstance(seq[1]);
        }
예제 #3
0
 public new static KeyUsage GetInstance(object obj)
 {
     if (obj is KeyUsage)
     {
         return((KeyUsage)obj);
     }
     if (obj is X509Extension)
     {
         return(GetInstance(X509Extension.ConvertValueToObject((X509Extension)obj)));
     }
     return(new KeyUsage(DerBitString.GetInstance(obj)));
 }
예제 #4
0
        private CertificateList(
            Asn1Sequence seq)
        {
            if (seq.Count != 3)
            {
                throw new ArgumentException("sequence wrong size for CertificateList", "seq");
            }

            tbsCertList = TbsCertificateList.GetInstance(seq[0]);
            sigAlgID    = AlgorithmIdentifier.GetInstance(seq[1]);
            sig         = DerBitString.GetInstance(seq[2]);
        }
예제 #5
0
        private CertTemplate(Asn1Sequence seq)
        {
            this.seq = seq;

            foreach (Asn1TaggedObject tObj in seq)
            {
                switch (tObj.TagNo)
                {
                case 0:
                    version = DerInteger.GetInstance(tObj, false);
                    break;

                case 1:
                    serialNumber = DerInteger.GetInstance(tObj, false);
                    break;

                case 2:
                    signingAlg = AlgorithmIdentifier.GetInstance(tObj, false);
                    break;

                case 3:
                    issuer = X509Name.GetInstance(tObj, true); // CHOICE
                    break;

                case 4:
                    validity = OptionalValidity.GetInstance(Asn1Sequence.GetInstance(tObj, false));
                    break;

                case 5:
                    subject = X509Name.GetInstance(tObj, true); // CHOICE
                    break;

                case 6:
                    publicKey = SubjectPublicKeyInfo.GetInstance(tObj, false);
                    break;

                case 7:
                    issuerUID = DerBitString.GetInstance(tObj, false);
                    break;

                case 8:
                    subjectUID = DerBitString.GetInstance(tObj, false);
                    break;

                case 9:
                    extensions = X509Extensions.GetInstance(tObj, false);
                    break;

                default:
                    throw new ArgumentException("unknown tag: " + tObj.TagNo, "seq");
                }
            }
        }
예제 #6
0
        public CertificationRequest(
            Asn1Sequence seq)
        {
            if (seq.Count != 3)
            {
                throw new ArgumentException("Wrong number of elements in sequence", "seq");
            }

            reqInfo  = CertificationRequestInfo.GetInstance(seq[0]);
            sigAlgId = AlgorithmIdentifier.GetInstance(seq[1]);
            sigBits  = DerBitString.GetInstance(seq[2]);
        }
예제 #7
0
파일: TbsSign.cs 프로젝트: fendaq/OfdSharp
        public TbsSign(Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            Version            = DerInteger.GetInstance(e.Next());
            EsSeal             = SesSealInfo.GetInstance(e.Next());
            TimeInfo           = DerBitString.GetInstance(e.Next());
            DataHash           = DerBitString.GetInstance(e.Next());
            PropertyInfo       = DerIA5String.GetInstance(e.Next());
            Cert               = Asn1OctetString.GetInstance(e.Next());
            SignatureAlgorithm = DerObjectIdentifier.GetInstance(e.Next());
        }
        private AttributeCertificate(
            Asn1Sequence seq)
        {
            if (seq.Count != 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            this.acinfo             = AttributeCertificateInfo.GetInstance(seq[0]);
            this.signatureAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]);
            this.signatureValue     = DerBitString.GetInstance(seq[2]);
        }
예제 #9
0
        public SesSignature(Asn1Sequence seq)
        {
            var e = seq.GetEnumerator();

            TbsSign        = TbsSign.GetInstance(e.Next());
            Cert           = Asn1OctetString.GetInstance(e.Next());
            SignatureAlgId = DerObjectIdentifier.GetInstance(e.Next());
            Signature      = DerBitString.GetInstance(e.Next());
            if (e.MoveNext())
            {
                TimeStamp = DerBitString.GetInstance(e.Next());
            }
        }
예제 #10
0
 private IssuerSerial(Asn1Sequence seq)
 {
     if (seq.Count != 2 && seq.Count != 3)
     {
         throw new ArgumentException("Bad sequence size: " + seq.Count);
     }
     issuer = GeneralNames.GetInstance(seq[0]);
     serial = DerInteger.GetInstance(seq[1]);
     if (seq.Count == 3)
     {
         issuerUid = DerBitString.GetInstance(seq[2]);
     }
 }
예제 #11
0
        public VipNetKeyInfo(Asn1Sequence seq)
        {
            RawData  = seq.GetEncoded();
            KeyClass = (DerInteger)seq[0];
            KeyType  = (DerInteger)seq[1];

            for (int i = 2; i < seq.Count; ++i)
            {
                if (seq[i] is Asn1TaggedObject tag)
                {
                    switch (tag.TagNo)
                    {
                    case 0:
                        Algorithm = AlgorithmIdentifier.GetInstance(tag.GetObject());
                        break;

                    case 1:
                        SerialNumber = Asn1OctetString.GetInstance(tag.GetObject());
                        break;

                    case 2:
                        AddSerialNumber = Asn1OctetString.GetInstance(tag.GetObject());
                        break;

                    case 3:
                        CertSerialNumber = Asn1OctetString.GetInstance(tag.GetObject());
                        break;

                    case 4:
                        SubjectUID = Asn1OctetString.GetInstance(tag.GetObject());
                        break;

                    case 5:
                        RecipientUID = Asn1OctetString.GetInstance(tag.GetObject());
                        break;

                    case 6:
                        Validity = KeyValidity.GetInstance(tag.GetObject());
                        break;

                    case 7:
                        KeyUID = DerBitString.GetInstance(tag.GetObject());
                        break;

                    case 10:
                        Flags = DerInteger.GetInstance(tag.GetObject());
                        break;
                    }
                }
            }
        }
예제 #12
0
        private PrivateKeyInfo(Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            this.version = DerInteger.GetInstance(CollectionUtilities.RequireNext(e));

            int versionValue = GetVersionValue(version);

            this.privateKeyAlgorithm = AlgorithmIdentifier.GetInstance(CollectionUtilities.RequireNext(e));
            this.privateKey          = Asn1OctetString.GetInstance(CollectionUtilities.RequireNext(e));

            int lastTag = -1;

            while (e.MoveNext())
            {
                Asn1TaggedObject tagged = (Asn1TaggedObject)e.Current;

                int tag = tagged.TagNo;
                if (tag <= lastTag)
                {
                    throw new ArgumentException("invalid optional field in private key info", "seq");
                }

                lastTag = tag;

                switch (tag)
                {
                case 0:
                {
                    this.attributes = Asn1Set.GetInstance(tagged, false);
                    break;
                }

                case 1:
                {
                    if (versionValue < 1)
                    {
                        throw new ArgumentException("'publicKey' requires version v2(1) or later", "seq");
                    }

                    this.publicKey = DerBitString.GetInstance(tagged, false);
                    break;
                }

                default:
                {
                    throw new ArgumentException("unknown optional field in private key info", "seq");
                }
                }
            }
        }
예제 #13
0
파일: TbsSign.cs 프로젝트: fendaq/OfdSharp
        public TbsSign(Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            Version      = DerInteger.GetInstance(e.Next());
            EsSeal       = SeSeal.GetInstance(e.Next());
            TimeInfo     = DerGeneralizedTime.GetInstance(e.Next());
            DataHash     = DerBitString.GetInstance(e.Next());
            PropertyInfo = DerIA5String.GetInstance(e.Next());
            if (e.MoveNext())
            {
                ExtData = ExtensionData.GetInstance(e.Current);
            }
        }
예제 #14
0
파일: asn1.cs 프로젝트: AS2805/6.5.3
        public Asn1Object AddObject(string oid, byte[] enc)
        {
            DerObjectIdentifier o = new DerObjectIdentifier(oid);
            var der = DerBitString.GetInstance(o);


            DerBitString s1 = new DerBitString(enc, 0);


            Asn1Object encO = Asn1Object.FromByteArray(s1.GetEncoded());


            return(encO);
        }
예제 #15
0
        public TbsSign(Asn1Sequence seq)
        {
            var e = seq.GetEnumerator();

            Version      = DerInteger.GetInstance(e.Next());
            EsSeal       = SesSealInfo.GetInstance(e.Next());
            TimeInfo     = DerBitString.GetInstance(e.Next());
            DataHash     = DerBitString.GetInstance(e.Next());
            PropertyInfo = DerIA5String.GetInstance(e.Next());
            if (e.MoveNext())
            {
                ExtensionData = ExtensionData.GetInstance(e.Next());
            }
        }
예제 #16
0
 private IssuerSerial(Asn1Sequence seq)
 {
     //IL_002d: Unknown result type (might be due to invalid IL or missing references)
     if (seq.Count != 2 && seq.Count != 3)
     {
         throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
     }
     issuer = GeneralNames.GetInstance(seq[0]);
     serial = DerInteger.GetInstance(seq[1]);
     if (seq.Count == 3)
     {
         issuerUid = DerBitString.GetInstance(seq[2]);
     }
 }
예제 #17
0
        public X509Certificate(
            X509CertificateStructure c)
        {
            this.c = c;

            try
            {
                Asn1OctetString str = this.GetExtensionValue(new DerObjectIdentifier("2.5.29.19"));

                if (str != null)
                {
                    basicConstraints = BasicConstraints.GetInstance(
                        X509ExtensionUtilities.FromExtensionValue(str));
                }
            }
            catch (Exception e)
            {
                throw new CertificateParsingException("cannot construct BasicConstraints: " + e);
            }

            try
            {
                Asn1OctetString str = this.GetExtensionValue(new DerObjectIdentifier("2.5.29.15"));

                if (str != null)
                {
                    DerBitString bits = DerBitString.GetInstance(
                        X509ExtensionUtilities.FromExtensionValue(str));

                    byte[] bytes  = bits.GetBytes();
                    int    length = (bytes.Length * 8) - bits.PadBits;

                    keyUsage = new bool[(length < 9) ? 9 : length];

                    for (int i = 0; i != length; i++)
                    {
//						keyUsage[i] = (bytes[i / 8] & (0x80 >>> (i % 8))) != 0;
                        keyUsage[i] = (bytes[i / 8] & (0x80 >> (i % 8))) != 0;
                    }
                }
                else
                {
                    keyUsage = null;
                }
            }
            catch (Exception e)
            {
                throw new CertificateParsingException("cannot construct KeyUsage: " + e);
            }
        }
        private X509CertificateStructure(
            Asn1Sequence seq)
        {
            if (seq.Count != 3)
            {
                throw new ArgumentException("sequence wrong size for a certificate", "seq");
            }

            //
            // correct x509 certficate
            //
            tbsCert  = TbsCertificateStructure.GetInstance(seq[0]);
            sigAlgID = AlgorithmIdentifier.GetInstance(seq[1]);
            sig      = DerBitString.GetInstance(seq[2]);
        }
예제 #19
0
        private PopoSigningKey(Asn1Sequence seq)
        {
            int index = 0;

            if (seq[index] is Asn1TaggedObject)
            {
                Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[index++];
                if (asn1TaggedObject.TagNo != 0)
                {
                    throw new ArgumentException("Unknown PopoSigningKeyInput tag: " + asn1TaggedObject.TagNo, "seq");
                }
                this.poposkInput = PopoSigningKeyInput.GetInstance(asn1TaggedObject.GetObject());
            }
            this.algorithmIdentifier = AlgorithmIdentifier.GetInstance(seq[index++]);
            this.signature           = DerBitString.GetInstance(seq[index]);
        }
예제 #20
0
 private PkiMessage(Asn1Sequence seq)
 {
     header = PkiHeader.GetInstance(seq[0]);
     body   = PkiBody.GetInstance(seq[1]);
     for (int i = 2; i < seq.Count; i++)
     {
         Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[i].ToAsn1Object();
         if (asn1TaggedObject.TagNo == 0)
         {
             protection = DerBitString.GetInstance(asn1TaggedObject, isExplicit: true);
         }
         else
         {
             extraCerts = Asn1Sequence.GetInstance(asn1TaggedObject, explicitly: true);
         }
     }
 }
예제 #21
0
        private ObjectDigestInfo(Asn1Sequence seq)
        {
            if (seq.Count > 4 || seq.Count < 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }
            this.digestedObjectType = DerEnumerated.GetInstance(seq[0]);
            int num = 0;

            if (seq.Count == 4)
            {
                this.otherObjectTypeID = DerObjectIdentifier.GetInstance(seq[1]);
                num++;
            }
            this.digestAlgorithm = AlgorithmIdentifier.GetInstance(seq[1 + num]);
            this.objectDigest    = DerBitString.GetInstance(seq[2 + num]);
        }
예제 #22
0
        private PopoSigningKey(Asn1Sequence seq)
        {
            //IL_0049: Unknown result type (might be due to invalid IL or missing references)
            int index = 0;

            if (seq[index] is Asn1TaggedObject)
            {
                Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[index++];
                if (asn1TaggedObject.TagNo != 0)
                {
                    throw new ArgumentException(string.Concat((object)"Unknown PopoSigningKeyInput tag: ", (object)asn1TaggedObject.TagNo), "seq");
                }
                poposkInput = PopoSigningKeyInput.GetInstance(asn1TaggedObject.GetObject());
            }
            algorithmIdentifier = AlgorithmIdentifier.GetInstance(seq[index++]);
            signature           = DerBitString.GetInstance(seq[index]);
        }
예제 #23
0
        private OobCertHash(Asn1Sequence seq)
        {
            int num = seq.Count - 1;

            this.hashVal = DerBitString.GetInstance(seq[num--]);
            for (int i = num; i >= 0; i--)
            {
                Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[i];
                if (asn1TaggedObject.TagNo == 0)
                {
                    this.hashAlg = AlgorithmIdentifier.GetInstance(asn1TaggedObject, true);
                }
                else
                {
                    this.certId = CertId.GetInstance(asn1TaggedObject, true);
                }
            }
        }
예제 #24
0
        // Extension method to the .NET PublicKey class
        public static string Format(this System.Security.Cryptography.X509Certificates.PublicKey public_key)
        {
            Asn1Sequence inner = Asn1Sequence.GetInstance(Asn1Object.FromByteArray(EncodeX509PublicKey(public_key)));

            byte[]       raw_key   = DerBitString.GetInstance(inner[1]).GetBytes();
            Asn1Sequence algorithm = Asn1Sequence.GetInstance(inner[0]);

            if (DerObjectIdentifier.GetInstance(algorithm[0]).Id == RSA_PUBLIC_KEY)
            {
                Asn1Sequence rsa_values = Asn1Sequence.GetInstance(Asn1Object.FromByteArray(raw_key));
                return("RSA Public Key (" + Hex.ToHexString(DerInteger.GetInstance(rsa_values[0]).Value.ToByteArrayUnsigned()) + ", " +
                       DerInteger.GetInstance(rsa_values[1]).ToString() + ")");
            }
            else
            {
                return("EC Public Key (" + DerObjectIdentifier.GetInstance(algorithm[1]).Id + ", " + Hex.ToHexString(raw_key) + ")");
            }
        }
예제 #25
0
        private ObjectDigestInfo(Asn1Sequence seq)
        {
            //IL_002d: Unknown result type (might be due to invalid IL or missing references)
            if (seq.Count > 4 || seq.Count < 3)
            {
                throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
            }
            digestedObjectType = DerEnumerated.GetInstance(seq[0]);
            int num = 0;

            if (seq.Count == 4)
            {
                otherObjectTypeID = DerObjectIdentifier.GetInstance(seq[1]);
                num++;
            }
            digestAlgorithm = AlgorithmIdentifier.GetInstance(seq[1 + num]);
            objectDigest    = DerBitString.GetInstance(seq[2 + num]);
        }
예제 #26
0
        private OobCertHash(Asn1Sequence seq)
        {
            int num = seq.Count - 1;

            hashVal = DerBitString.GetInstance(seq[num--]);
            for (int num2 = num; num2 >= 0; num2--)
            {
                Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[num2];
                if (asn1TaggedObject.TagNo == 0)
                {
                    hashAlg = AlgorithmIdentifier.GetInstance(asn1TaggedObject, explicitly: true);
                }
                else
                {
                    certId = CertId.GetInstance(asn1TaggedObject, isExplicit: true);
                }
            }
        }
예제 #27
0
		private DistributionPoint(Asn1Sequence seq)
		{
			for (int i = 0; i != seq.Count; i++)
			{
				Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[i]);
				switch (instance.TagNo)
				{
				case 0:
					distributionPoint = DistributionPointName.GetInstance(instance, explicitly: true);
					break;
				case 1:
					reasons = new ReasonFlags(DerBitString.GetInstance(instance, isExplicit: false));
					break;
				case 2:
					cRLIssuer = GeneralNames.GetInstance(instance, explicitly: false);
					break;
				}
			}
		}
예제 #28
0
        private PkiMessage(Asn1Sequence seq)
        {
            header = PkiHeader.GetInstance(seq[0]);
            body   = PkiBody.GetInstance(seq[1]);

            for (int pos = 2; pos < seq.Count; ++pos)
            {
                Asn1TaggedObject tObj = (Asn1TaggedObject)seq[pos].ToAsn1Object();

                if (tObj.TagNo == 0)
                {
                    protection = DerBitString.GetInstance(tObj, true);
                }
                else
                {
                    extraCerts = Asn1Sequence.GetInstance(tObj, true);
                }
            }
        }
        private AttributeCertificateInfo(
            Asn1Sequence seq)
        {
            if (seq.Count < 6 || seq.Count > 9)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            int start;

            if (seq[0] is DerInteger)   // in version 1 certs version is DEFAULT  v1(0)
            {
                this.version = DerInteger.GetInstance(seq[0]);
                start        = 1;
            }
            else
            {
                this.version = new DerInteger(0);
                start        = 0;
            }

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

            for (int i = start + 6; 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]);
                }
            }
        }
        internal TbsCertificateStructure(Asn1Sequence seq)
        {
            int num = 0;

            this.seq = seq;
            if (seq[0] is DerTaggedObject)
            {
                this.version = DerInteger.GetInstance((Asn1TaggedObject)seq[0], true);
            }
            else
            {
                num          = -1;
                this.version = new DerInteger(0);
            }
            this.serialNumber = DerInteger.GetInstance(seq[num + 1]);
            this.signature    = AlgorithmIdentifier.GetInstance(seq[num + 2]);
            this.issuer       = X509Name.GetInstance(seq[num + 3]);
            Asn1Sequence asn1Sequence = (Asn1Sequence)seq[num + 4];

            this.startDate            = Time.GetInstance(asn1Sequence[0]);
            this.endDate              = Time.GetInstance(asn1Sequence[1]);
            this.subject              = X509Name.GetInstance(seq[num + 5]);
            this.subjectPublicKeyInfo = SubjectPublicKeyInfo.GetInstance(seq[num + 6]);
            for (int i = seq.Count - (num + 6) - 1; i > 0; i--)
            {
                DerTaggedObject derTaggedObject = (DerTaggedObject)seq[num + 6 + i];
                switch (derTaggedObject.TagNo)
                {
                case 1:
                    this.issuerUniqueID = DerBitString.GetInstance(derTaggedObject, false);
                    break;

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

                case 3:
                    this.extensions = X509Extensions.GetInstance(derTaggedObject);
                    break;
                }
            }
        }