상속: System.Collections.CollectionBase, IEnumerable
예제 #1
0
 internal X509CrlEntry(ASN1 entry)
 {
     sn = entry[0].Value;
     Array.Reverse(sn);
     revocationDate = ASN1Convert.ToDateTime(entry[1]);
     extensions     = new X509ExtensionCollection(entry[2]);
 }
예제 #2
0
파일: X509Store.cs 프로젝트: nsivov/mono
        private byte[] GetUniqueName(X509ExtensionCollection extensions, byte[] serial = null)
        {
            // We prefer Subject Key Identifier as the unique name
            // as it will provide faster lookups
            X509Extension ext = extensions ["2.5.29.14"];

            if (ext == null)
            {
                return(null);
            }

            SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension(ext);

            if (serial == null)
            {
                return(ski.Identifier);
            }
            else
            {
                byte[] uniqueWithSerial = new byte[ski.Identifier.Length + serial.Length];
                System.Buffer.BlockCopy(ski.Identifier, 0, uniqueWithSerial, 0, ski.Identifier.Length);
                System.Buffer.BlockCopy(serial, 0, uniqueWithSerial, ski.Identifier.Length, serial.Length);
                return(uniqueWithSerial);
            }
        }
예제 #3
0
파일: X509CRL.cs 프로젝트: carrie901/mono
			internal X509CrlEntry (byte[] serialNumber, DateTime revocationDate, X509ExtensionCollection extensions) 
			{
				sn = serialNumber;
				this.revocationDate = revocationDate;
				if (extensions == null)
					this.extensions = new X509ExtensionCollection ();
				else
					this.extensions = extensions;
			}
 public X509CertificateBuilder(byte version)
 {
     if (version > 3)
     {
         throw new ArgumentException("Invalid certificate version");
     }
     this.version = version;
     extensions   = new X509ExtensionCollection();
 }
    public void AddRange (X509ExtensionCollection collection)
    {
        if (collection == null)
            throw new ArgumentNullException ("collection");
        if (readOnly)
            throw new NotSupportedException ("Extensions are read only");

        for (int i = 0; i < collection.InnerList.Count; i++)
            InnerList.Add (collection [i]);
    }
예제 #6
0
        private byte[] GetUniqueName(X509ExtensionCollection extensions)
        {
            X509Extension x509Extension = extensions["2.5.29.14"];

            if (x509Extension == null)
            {
                return(null);
            }
            SubjectKeyIdentifierExtension subjectKeyIdentifierExtension = new SubjectKeyIdentifierExtension(x509Extension);

            return(subjectKeyIdentifierExtension.Identifier);
        }
예제 #7
0
 internal X509CrlEntry(byte[] serialNumber, DateTime revocationDate, X509ExtensionCollection extensions)
 {
     sn = serialNumber;
     this.revocationDate = revocationDate;
     if (extensions == null)
     {
         this.extensions = new X509ExtensionCollection();
     }
     else
     {
         this.extensions = extensions;
     }
 }
 public void AddRange(X509ExtensionCollection collection)
 {
     if (collection == null)
     {
         throw new ArgumentNullException(nameof(collection));
     }
     if (this.readOnly)
     {
         throw new NotSupportedException("Extensions are read only");
     }
     for (int index = 0; index < collection.InnerList.Count; ++index)
     {
         this.InnerList.Add((object)collection[index]);
     }
 }
예제 #9
0
        private byte[] GetUniqueName(X509ExtensionCollection extensions)
        {
            // We prefer Subject Key Identifier as the unique name
            // as it will provide faster lookups
            X509Extension ext = extensions ["2.5.29.14"];

            if (ext == null)
            {
                return(null);
            }

            SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension(ext);

            return(ski.Identifier);
        }
예제 #10
0
        private void Parse(byte[] crl)
        {
            string e = "Input data cannot be coded as a valid CRL.";

            try {
                // CertificateList  ::=  SEQUENCE  {
                ASN1 encodedCRL = new ASN1(encoded);
                if ((encodedCRL.Tag != 0x30) || (encodedCRL.Count != 3))
                {
                    throw new CryptographicException(e);
                }

                // CertificateList / TBSCertList,
                ASN1 toBeSigned = encodedCRL [0];
                if ((toBeSigned.Tag != 0x30) || (toBeSigned.Count < 3))
                {
                    throw new CryptographicException(e);
                }

                int n = 0;
                // CertificateList / TBSCertList / Version OPTIONAL, -- if present, MUST be v2
                if (toBeSigned [n].Tag == 0x02)
                {
                    version = (byte)(toBeSigned [n++].Value [0] + 1);
                }
                else
                {
                    version = 1;                     // DEFAULT
                }
                // CertificateList / TBSCertList / AlgorithmIdentifier,
                signatureOID = ASN1Convert.ToOid(toBeSigned [n++][0]);
                // CertificateList / TBSCertList / Name,
                issuer = X501.ToString(toBeSigned [n++]);
                // CertificateList / TBSCertList / Time,
                thisUpdate = ASN1Convert.ToDateTime(toBeSigned [n++]);
                // CertificateList / TBSCertList / Time OPTIONAL,
                ASN1 next = toBeSigned [n++];
                if ((next.Tag == 0x17) || (next.Tag == 0x18))
                {
                    nextUpdate = ASN1Convert.ToDateTime(next);
                    next       = toBeSigned [n++];
                }
                // CertificateList / TBSCertList / revokedCertificates	SEQUENCE OF SEQUENCE  {
                entries = new ArrayList();
                // this is OPTIONAL so it may not be present if no entries exists
                if ((next != null) && (next.Tag == 0x30))
                {
                    ASN1 revokedCertificates = next;
                    for (int i = 0; i < revokedCertificates.Count; i++)
                    {
                        entries.Add(new X509CrlEntry(revokedCertificates [i]));
                    }
                }
                else
                {
                    n--;
                }
                // CertificateList / TBSCertList / crlExtensions [0] Extensions OPTIONAL }
                ASN1 extns = toBeSigned [n];
                if ((extns != null) && (extns.Tag == 0xA0) && (extns.Count == 1))
                {
                    extensions = new X509ExtensionCollection(extns [0]);
                }
                else
                {
                    extensions = new X509ExtensionCollection(null);                      // result in a read only object
                }
                // CertificateList / AlgorithmIdentifier
                string signatureAlgorithm = ASN1Convert.ToOid(encodedCRL [1][0]);
                if (signatureOID != signatureAlgorithm)
                {
                    throw new CryptographicException(e + " [Non-matching signature algorithms in CRL]");
                }

                // CertificateList / BIT STRING
                byte[] bitstring = encodedCRL [2].Value;
                // first byte contains unused bits in first byte
                signature = new byte [bitstring.Length - 1];
                Buffer.BlockCopy(bitstring, 1, signature, 0, signature.Length);
            }
            catch {
                throw new CryptographicException(e);
            }
        }
예제 #11
0
        private void Parse(byte[] crl)
        {
            string text = "Input data cannot be coded as a valid CRL.";

            try
            {
                ASN1 aSN = new ASN1(encoded);
                if (aSN.Tag != 48 || aSN.Count != 3)
                {
                    throw new CryptographicException(text);
                }
                ASN1 aSN2 = aSN[0];
                if (aSN2.Tag != 48 || aSN2.Count < 3)
                {
                    throw new CryptographicException(text);
                }
                int num = 0;
                if (aSN2[num].Tag == 2)
                {
                    version = (byte)(aSN2[num++].Value[0] + 1);
                }
                else
                {
                    version = 1;
                }
                signatureOID = ASN1Convert.ToOid(aSN2[num++][0]);
                issuer       = X501.ToString(aSN2[num++]);
                thisUpdate   = ASN1Convert.ToDateTime(aSN2[num++]);
                ASN1 aSN3 = aSN2[num++];
                if (aSN3.Tag == 23 || aSN3.Tag == 24)
                {
                    nextUpdate = ASN1Convert.ToDateTime(aSN3);
                    aSN3       = aSN2[num++];
                }
                entries = new ArrayList();
                if (aSN3 != null && aSN3.Tag == 48)
                {
                    ASN1 aSN4 = aSN3;
                    for (int i = 0; i < aSN4.Count; i++)
                    {
                        entries.Add(new X509CrlEntry(aSN4[i]));
                    }
                }
                else
                {
                    num--;
                }
                ASN1 aSN5 = aSN2[num];
                if (aSN5 != null && aSN5.Tag == 160 && aSN5.Count == 1)
                {
                    extensions = new X509ExtensionCollection(aSN5[0]);
                }
                else
                {
                    extensions = new X509ExtensionCollection(null);
                }
                string b = ASN1Convert.ToOid(aSN[1][0]);
                if (signatureOID != b)
                {
                    throw new CryptographicException(text + " [Non-matching signature algorithms in CRL]");
                }
                byte[] value = aSN[2].Value;
                signature = new byte[value.Length - 1];
                Buffer.BlockCopy(value, 1, signature, 0, signature.Length);
            }
            catch
            {
                throw new CryptographicException(text);
                IL_024f :;
            }
        }
예제 #12
0
		private byte[] GetUniqueName (X509ExtensionCollection extensions) 
		{
			// We prefer Subject Key Identifier as the unique name
			// as it will provide faster lookups
			X509Extension ext = extensions ["2.5.29.14"];
			if (ext == null)
				return null;

			SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext);
			return ski.Identifier;
		}
예제 #13
0
        // that's were the real job is!
        private void Parse(byte[] data)
        {
            try {
                decoder = new ASN1(data);
                // Certificate
                if (decoder.Tag != 0x30)
                {
                    throw new CryptographicException(encoding_error);
                }
                // Certificate / TBSCertificate
                if (decoder [0].Tag != 0x30)
                {
                    throw new CryptographicException(encoding_error);
                }

                ASN1 tbsCertificate = decoder [0];

                int tbs = 0;
                // Certificate / TBSCertificate / Version
                ASN1 v = decoder [0][tbs];
                version = 1;                                    // DEFAULT v1
                if ((v.Tag == 0xA0) && (v.Count > 0))
                {
                    // version (optional) is present only in v2+ certs
                    version += v [0].Value [0];                         // zero based
                    tbs++;
                }

                // Certificate / TBSCertificate / CertificateSerialNumber
                ASN1 sn = decoder [0][tbs++];
                if (sn.Tag != 0x02)
                {
                    throw new CryptographicException(encoding_error);
                }
                serialnumber = sn.Value;
                Array.Reverse(serialnumber, 0, serialnumber.Length);

                // Certificate / TBSCertificate / AlgorithmIdentifier
                tbs++;
                // ASN1 signatureAlgo = tbsCertificate.Element (tbs++, 0x30);

                issuer       = tbsCertificate.Element(tbs++, 0x30);
                m_issuername = X501.ToString(issuer);

                ASN1 validity  = tbsCertificate.Element(tbs++, 0x30);
                ASN1 notBefore = validity [0];
                m_from = ASN1Convert.ToDateTime(notBefore);
                ASN1 notAfter = validity [1];
                m_until = ASN1Convert.ToDateTime(notAfter);

                subject   = tbsCertificate.Element(tbs++, 0x30);
                m_subject = X501.ToString(subject);

                ASN1 subjectPublicKeyInfo = tbsCertificate.Element(tbs++, 0x30);

                ASN1 algorithm = subjectPublicKeyInfo.Element(0, 0x30);
                ASN1 algo      = algorithm.Element(0, 0x06);
                m_keyalgo = ASN1Convert.ToOid(algo);
                // parameters ANY DEFINED BY algorithm OPTIONAL
                // so we dont ask for a specific (Element) type and return DER
                ASN1 parameters = algorithm [1];
                m_keyalgoparams = ((algorithm.Count > 1) ? parameters.GetBytes() : null);

                ASN1 subjectPublicKey = subjectPublicKeyInfo.Element(1, 0x03);
                // we must drop th first byte (which is the number of unused bits
                // in the BITSTRING)
                int n = subjectPublicKey.Length - 1;
                m_publickey = new byte [n];
                Buffer.BlockCopy(subjectPublicKey.Value, 1, m_publickey, 0, n);

                // signature processing
                byte[] bitstring = decoder [2].Value;
                // first byte contains unused bits in first byte
                signature = new byte [bitstring.Length - 1];
                Buffer.BlockCopy(bitstring, 1, signature, 0, signature.Length);

                algorithm       = decoder [1];
                algo            = algorithm.Element(0, 0x06);
                m_signaturealgo = ASN1Convert.ToOid(algo);
                parameters      = algorithm [1];
                if (parameters != null)
                {
                    m_signaturealgoparams = parameters.GetBytes();
                }
                else
                {
                    m_signaturealgoparams = null;
                }

                // Certificate / TBSCertificate / issuerUniqueID
                ASN1 issuerUID = tbsCertificate.Element(tbs, 0x81);
                if (issuerUID != null)
                {
                    tbs++;
                    issuerUniqueID = issuerUID.Value;
                }

                // Certificate / TBSCertificate / subjectUniqueID
                ASN1 subjectUID = tbsCertificate.Element(tbs, 0x82);
                if (subjectUID != null)
                {
                    tbs++;
                    subjectUniqueID = subjectUID.Value;
                }

                // Certificate / TBSCertificate / Extensions
                ASN1 extns = tbsCertificate.Element(tbs, 0xA3);
                if ((extns != null) && (extns.Count == 1))
                {
                    extensions = new X509ExtensionCollection(extns [0]);
                }
                else
                {
                    extensions = new X509ExtensionCollection(null);
                }

                // keep a copy of the original data
                m_encodedcert = (byte[])data.Clone();
            }
            catch (Exception ex) {
                throw new CryptographicException(encoding_error, ex);
            }
        }
		public void AddRange (X509ExtensionCollection collection) 
		{
			if (collection == null)
				throw new ArgumentNullException ("collection");
			if (readOnly)
				throw new NotSupportedException ("Extensions are read only");

			for (int i = 0; i < collection.InnerList.Count; i++) 
				InnerList.Add (collection [i]);
		}
예제 #15
0
        private byte[] GetUniqueName(X509ExtensionCollection extensions)
        {
            X509Extension extension = extensions["2.5.29.14"];

            return(extension == null ? (byte[])null : new SubjectKeyIdentifierExtension(extension).Identifier);
        }
예제 #16
0
파일: X509CRL.cs 프로젝트: carrie901/mono
			internal X509CrlEntry (ASN1 entry) 
			{
				sn = entry [0].Value;
				Array.Reverse (sn);
				revocationDate = ASN1Convert.ToDateTime (entry [1]);
				extensions = new X509ExtensionCollection (entry [2]);
			}
예제 #17
0
 private void Parse(byte[] data)
 {
     try
     {
         this.decoder = new ASN1(data);
         if (this.decoder.Tag != 48)
         {
             throw new CryptographicException(X509Certificate.encoding_error);
         }
         if (this.decoder[0].Tag != 48)
         {
             throw new CryptographicException(X509Certificate.encoding_error);
         }
         ASN1 asn  = this.decoder[0];
         int  num  = 0;
         ASN1 asn2 = this.decoder[0][num];
         this.version = 1;
         if (asn2.Tag == 160 && asn2.Count > 0)
         {
             this.version += (int)asn2[0].Value[0];
             num++;
         }
         ASN1 asn3 = this.decoder[0][num++];
         if (asn3.Tag != 2)
         {
             throw new CryptographicException(X509Certificate.encoding_error);
         }
         this.serialnumber = asn3.Value;
         Array.Reverse(this.serialnumber, 0, this.serialnumber.Length);
         num++;
         this.issuer       = asn.Element(num++, 48);
         this.m_issuername = X501.ToString(this.issuer);
         ASN1 asn4 = asn.Element(num++, 48);
         ASN1 time = asn4[0];
         this.m_from = ASN1Convert.ToDateTime(time);
         ASN1 time2 = asn4[1];
         this.m_until   = ASN1Convert.ToDateTime(time2);
         this.subject   = asn.Element(num++, 48);
         this.m_subject = X501.ToString(this.subject);
         ASN1 asn5 = asn.Element(num++, 48);
         ASN1 asn6 = asn5.Element(0, 48);
         ASN1 asn7 = asn6.Element(0, 6);
         this.m_keyalgo = ASN1Convert.ToOid(asn7);
         ASN1 asn8 = asn6[1];
         this.m_keyalgoparams = ((asn6.Count <= 1) ? null : asn8.GetBytes());
         ASN1 asn9 = asn5.Element(1, 3);
         int  num2 = asn9.Length - 1;
         this.m_publickey = new byte[num2];
         Buffer.BlockCopy(asn9.Value, 1, this.m_publickey, 0, num2);
         byte[] value = this.decoder[2].Value;
         this.signature = new byte[value.Length - 1];
         Buffer.BlockCopy(value, 1, this.signature, 0, this.signature.Length);
         asn6 = this.decoder[1];
         asn7 = asn6.Element(0, 6);
         this.m_signaturealgo = ASN1Convert.ToOid(asn7);
         asn8 = asn6[1];
         if (asn8 != null)
         {
             this.m_signaturealgoparams = asn8.GetBytes();
         }
         else
         {
             this.m_signaturealgoparams = null;
         }
         ASN1 asn10 = asn.Element(num, 129);
         if (asn10 != null)
         {
             num++;
             this.issuerUniqueID = asn10.Value;
         }
         ASN1 asn11 = asn.Element(num, 130);
         if (asn11 != null)
         {
             num++;
             this.subjectUniqueID = asn11.Value;
         }
         ASN1 asn12 = asn.Element(num, 163);
         if (asn12 != null && asn12.Count == 1)
         {
             this.extensions = new X509ExtensionCollection(asn12[0]);
         }
         else
         {
             this.extensions = new X509ExtensionCollection(null);
         }
         this.m_encodedcert = (byte[])data.Clone();
     }
     catch (Exception inner)
     {
         throw new CryptographicException(X509Certificate.encoding_error, inner);
     }
 }
예제 #18
0
파일: X509CRL.cs 프로젝트: carrie901/mono
		private void Parse (byte[] crl) 
		{
			string e = "Input data cannot be coded as a valid CRL.";
			try {
				// CertificateList  ::=  SEQUENCE  {
				ASN1 encodedCRL = new ASN1 (encoded);
				if ((encodedCRL.Tag != 0x30) || (encodedCRL.Count != 3))
					throw new CryptographicException (e);

				// CertificateList / TBSCertList,
				ASN1 toBeSigned = encodedCRL [0];
				if ((toBeSigned.Tag != 0x30) || (toBeSigned.Count < 3))
					throw new CryptographicException (e);

				int n = 0;
				// CertificateList / TBSCertList / Version OPTIONAL, -- if present, MUST be v2
				if (toBeSigned [n].Tag == 0x02) {
					version = (byte) (toBeSigned [n++].Value [0] + 1);
				}
				else
					version = 1; // DEFAULT
				// CertificateList / TBSCertList / AlgorithmIdentifier,
				signatureOID = ASN1Convert.ToOid (toBeSigned [n++][0]);
				// CertificateList / TBSCertList / Name,
				issuer = X501.ToString (toBeSigned [n++]);
				// CertificateList / TBSCertList / Time,
				thisUpdate = ASN1Convert.ToDateTime (toBeSigned [n++]);
				// CertificateList / TBSCertList / Time OPTIONAL,
				ASN1 next = toBeSigned [n++];
				if ((next.Tag == 0x17) || (next.Tag == 0x18)) {
					nextUpdate = ASN1Convert.ToDateTime (next);
					next = toBeSigned [n++];
				}
				// CertificateList / TBSCertList / revokedCertificates	SEQUENCE OF SEQUENCE  {
				entries = new ArrayList ();
				// this is OPTIONAL so it may not be present if no entries exists
				if ((next != null) && (next.Tag == 0x30)) {
					ASN1 revokedCertificates = next;
					for (int i=0; i < revokedCertificates.Count; i++) {
						entries.Add (new X509CrlEntry (revokedCertificates [i]));
					}
				} else {
					n--;
				}
				// CertificateList / TBSCertList / crlExtensions [0] Extensions OPTIONAL }
				ASN1 extns = toBeSigned [n];
				if ((extns != null) && (extns.Tag == 0xA0) && (extns.Count == 1))
					extensions = new X509ExtensionCollection (extns [0]);
				else
					extensions = new X509ExtensionCollection (null); // result in a read only object
				// CertificateList / AlgorithmIdentifier
				string signatureAlgorithm = ASN1Convert.ToOid (encodedCRL [1][0]);
				if (signatureOID != signatureAlgorithm)
					throw new CryptographicException (e + " [Non-matching signature algorithms in CRL]");

				// CertificateList / BIT STRING 
				byte[] bitstring = encodedCRL [2].Value;
				// first byte contains unused bits in first byte
				signature = new byte [bitstring.Length - 1];
				Buffer.BlockCopy (bitstring, 1, signature, 0, signature.Length);
			}
			catch {
				throw new CryptographicException (e);
			}
		}
예제 #19
0
        private void Parse(byte[] crl)
        {
            string message = "Input data cannot be coded as a valid CRL.";

            try
            {
                ASN1 asn = new ASN1(this.encoded);
                if ((asn.Tag != 0x30) || (asn.Count != 3))
                {
                    throw new CryptographicException(message);
                }
                ASN1 asn2 = asn[0];
                if ((asn2.Tag != 0x30) || (asn2.Count < 3))
                {
                    throw new CryptographicException(message);
                }
                int num = 0;
                if (asn2[num].Tag == 2)
                {
                    this.version = (byte)(asn2[num++].Value[0] + 1);
                }
                else
                {
                    this.version = 1;
                }
                this.signatureOID = ASN1Convert.ToOid(asn2[num++][0]);
                this.issuer       = X501.ToString(asn2[num++]);
                this.thisUpdate   = ASN1Convert.ToDateTime(asn2[num++]);
                ASN1 time = asn2[num++];
                if ((time.Tag == 0x17) || (time.Tag == 0x18))
                {
                    this.nextUpdate = ASN1Convert.ToDateTime(time);
                    time            = asn2[num++];
                }
                this.entries = new ArrayList();
                if ((time != null) && (time.Tag == 0x30))
                {
                    ASN1 asn4 = time;
                    for (int i = 0; i < asn4.Count; i++)
                    {
                        this.entries.Add(new X509CrlEntry(asn4[i]));
                    }
                }
                else
                {
                    num--;
                }
                ASN1 asn5 = asn2[num];
                if (((asn5 != null) && (asn5.Tag == 160)) && (asn5.Count == 1))
                {
                    this.extensions = new X509ExtensionCollection(asn5[0]);
                }
                else
                {
                    this.extensions = new X509ExtensionCollection(null);
                }
                string str2 = ASN1Convert.ToOid(asn[1][0]);
                if (this.signatureOID != str2)
                {
                    throw new CryptographicException(message + " [Non-matching signature algorithms in CRL]");
                }
                byte[] src = asn[2].Value;
                this.signature = new byte[src.Length - 1];
                Buffer.BlockCopy(src, 1, this.signature, 0, this.signature.Length);
            }
            catch
            {
                throw new CryptographicException(message);
            }
        }
예제 #20
0
 private void Parse(byte[] data)
 {
     try
     {
         this.decoder = new ASN1(data);
         if (this.decoder.Tag != 0x30)
         {
             throw new CryptographicException(encoding_error);
         }
         if (this.decoder[0].Tag != 0x30)
         {
             throw new CryptographicException(encoding_error);
         }
         ASN1 asn   = this.decoder[0];
         int  index = 0;
         ASN1 asn2  = this.decoder[0][index];
         this.version = 1;
         if ((asn2.Tag == 160) && (asn2.Count > 0))
         {
             this.version += asn2[0].Value[0];
             index++;
         }
         ASN1 asn3 = this.decoder[0][index++];
         if (asn3.Tag != 2)
         {
             throw new CryptographicException(encoding_error);
         }
         this.serialnumber = asn3.Value;
         Array.Reverse(this.serialnumber, 0, this.serialnumber.Length);
         index++;
         this.issuer       = asn.Element(index++, 0x30);
         this.m_issuername = X501.ToString(this.issuer);
         ASN1 asn4 = asn.Element(index++, 0x30);
         ASN1 time = asn4[0];
         this.m_from = ASN1Convert.ToDateTime(time);
         ASN1 asn6 = asn4[1];
         this.m_until   = ASN1Convert.ToDateTime(asn6);
         this.subject   = asn.Element(index++, 0x30);
         this.m_subject = X501.ToString(this.subject);
         ASN1 asn7 = asn.Element(index++, 0x30);
         ASN1 asn8 = asn7.Element(0, 0x30);
         ASN1 asn9 = asn8.Element(0, 6);
         this.m_keyalgo = ASN1Convert.ToOid(asn9);
         ASN1 asn10 = asn8[1];
         this.m_keyalgoparams = (asn8.Count <= 1) ? null : asn10.GetBytes();
         ASN1 asn11 = asn7.Element(1, 3);
         int  count = asn11.Length - 1;
         this.m_publickey = new byte[count];
         Buffer.BlockCopy(asn11.Value, 1, this.m_publickey, 0, count);
         byte[] src = this.decoder[2].Value;
         this.signature = new byte[src.Length - 1];
         Buffer.BlockCopy(src, 1, this.signature, 0, this.signature.Length);
         asn8 = this.decoder[1];
         asn9 = asn8.Element(0, 6);
         this.m_signaturealgo = ASN1Convert.ToOid(asn9);
         asn10 = asn8[1];
         if (asn10 != null)
         {
             this.m_signaturealgoparams = asn10.GetBytes();
         }
         else
         {
             this.m_signaturealgoparams = null;
         }
         ASN1 asn12 = asn.Element(index, 0x81);
         if (asn12 != null)
         {
             index++;
             this.issuerUniqueID = asn12.Value;
         }
         ASN1 asn13 = asn.Element(index, 130);
         if (asn13 != null)
         {
             index++;
             this.subjectUniqueID = asn13.Value;
         }
         ASN1 asn14 = asn.Element(index, 0xa3);
         if ((asn14 != null) && (asn14.Count == 1))
         {
             this.extensions = new X509ExtensionCollection(asn14[0]);
         }
         else
         {
             this.extensions = new X509ExtensionCollection(null);
         }
         this.m_encodedcert = (byte[])data.Clone();
     }
     catch (Exception exception)
     {
         throw new CryptographicException(encoding_error, exception);
     }
 }
예제 #21
0
        private void Parse(byte[] crl)
        {
            string text = "Input data cannot be coded as a valid CRL.";

            try
            {
                ASN1 asn = new ASN1(this.encoded);
                if (asn.Tag != 48 || asn.Count != 3)
                {
                    throw new CryptographicException(text);
                }
                ASN1 asn2 = asn[0];
                if (asn2.Tag != 48 || asn2.Count < 3)
                {
                    throw new CryptographicException(text);
                }
                int num = 0;
                if (asn2[num].Tag == 2)
                {
                    this.version = asn2[num++].Value[0] + 1;
                }
                else
                {
                    this.version = 1;
                }
                this.signatureOID = ASN1Convert.ToOid(asn2[num++][0]);
                this.issuer       = X501.ToString(asn2[num++]);
                this.thisUpdate   = ASN1Convert.ToDateTime(asn2[num++]);
                ASN1 asn3 = asn2[num++];
                if (asn3.Tag == 23 || asn3.Tag == 24)
                {
                    this.nextUpdate = ASN1Convert.ToDateTime(asn3);
                    asn3            = asn2[num++];
                }
                this.entries = new ArrayList();
                if (asn3 != null && asn3.Tag == 48)
                {
                    ASN1 asn4 = asn3;
                    for (int i = 0; i < asn4.Count; i++)
                    {
                        this.entries.Add(new X509Crl.X509CrlEntry(asn4[i]));
                    }
                }
                else
                {
                    num--;
                }
                ASN1 asn5 = asn2[num];
                if (asn5 != null && asn5.Tag == 160 && asn5.Count == 1)
                {
                    this.extensions = new X509ExtensionCollection(asn5[0]);
                }
                else
                {
                    this.extensions = new X509ExtensionCollection(null);
                }
                string b = ASN1Convert.ToOid(asn[1][0]);
                if (this.signatureOID != b)
                {
                    throw new CryptographicException(text + " [Non-matching signature algorithms in CRL]");
                }
                byte[] value = asn[2].Value;
                this.signature = new byte[value.Length - 1];
                Buffer.BlockCopy(value, 1, this.signature, 0, this.signature.Length);
            }
            catch
            {
                throw new CryptographicException(text);
            }
        }
예제 #22
0
		public override void Reset () 
		{
			_cert = null;
			_archived = false;
			_extensions = null;
			_name = String.Empty;
			_serial = null;
			_publicKey = null;
			issuer_name = null;
			subject_name = null;
			signature_algorithm = null;
			base.Reset ();
		}
예제 #23
0
		public X509CertificateBuilder (byte version) 
		{
			if (version > 3)
				throw new ArgumentException ("Invalid certificate version");
			this.version = version;
			extensions = new X509ExtensionCollection ();
		}
예제 #24
0
파일: X509Store.cs 프로젝트: Numpsy/mono
		private byte[] GetUniqueName (X509ExtensionCollection extensions, byte[] serial = null) 
		{
			// We prefer Subject Key Identifier as the unique name
			// as it will provide faster lookups
			X509Extension ext = extensions ["2.5.29.14"];
			if (ext == null)
				return null;

			SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext);
			if (serial == null) {
				return ski.Identifier;
			} else {
				byte[] uniqueWithSerial = new byte[ski.Identifier.Length + serial.Length];
				System.Buffer.BlockCopy (ski.Identifier, 0, uniqueWithSerial, 0, ski.Identifier.Length );
				System.Buffer.BlockCopy (serial, 0, uniqueWithSerial, ski.Identifier.Length, serial.Length );
				return uniqueWithSerial;
			}
		}
예제 #25
0
 private void Parse(byte[] data)
 {
     try
     {
         decoder = new ASN1(data);
         if (decoder.Tag != 48)
         {
             throw new CryptographicException(encoding_error);
         }
         if (decoder[0].Tag != 48)
         {
             throw new CryptographicException(encoding_error);
         }
         ASN1 aSN  = decoder[0];
         int  num  = 0;
         ASN1 aSN2 = decoder[0][num];
         version = 1;
         if (aSN2.Tag == 160 && aSN2.Count > 0)
         {
             version += aSN2[0].Value[0];
             num++;
         }
         ASN1 aSN3 = decoder[0][num++];
         if (aSN3.Tag != 2)
         {
             throw new CryptographicException(encoding_error);
         }
         serialnumber = aSN3.Value;
         Array.Reverse(serialnumber, 0, serialnumber.Length);
         num++;
         issuer       = aSN.Element(num++, 48);
         m_issuername = X501.ToString(issuer);
         ASN1 aSN4 = aSN.Element(num++, 48);
         ASN1 time = aSN4[0];
         m_from = ASN1Convert.ToDateTime(time);
         ASN1 time2 = aSN4[1];
         m_until   = ASN1Convert.ToDateTime(time2);
         subject   = aSN.Element(num++, 48);
         m_subject = X501.ToString(subject);
         ASN1 aSN5 = aSN.Element(num++, 48);
         ASN1 aSN6 = aSN5.Element(0, 48);
         ASN1 asn  = aSN6.Element(0, 6);
         m_keyalgo = ASN1Convert.ToOid(asn);
         ASN1 aSN7 = aSN6[1];
         m_keyalgoparams = ((aSN6.Count <= 1) ? null : aSN7.GetBytes());
         ASN1 aSN8 = aSN5.Element(1, 3);
         int  num7 = aSN8.Length - 1;
         m_publickey = new byte[num7];
         Buffer.BlockCopy(aSN8.Value, 1, m_publickey, 0, num7);
         byte[] value = decoder[2].Value;
         signature = new byte[value.Length - 1];
         Buffer.BlockCopy(value, 1, signature, 0, signature.Length);
         aSN6            = decoder[1];
         asn             = aSN6.Element(0, 6);
         m_signaturealgo = ASN1Convert.ToOid(asn);
         aSN7            = aSN6[1];
         if (aSN7 != null)
         {
             m_signaturealgoparams = aSN7.GetBytes();
         }
         else
         {
             m_signaturealgoparams = null;
         }
         ASN1 aSN9 = aSN.Element(num, 129);
         if (aSN9 != null)
         {
             num++;
             issuerUniqueID = aSN9.Value;
         }
         ASN1 aSN10 = aSN.Element(num, 130);
         if (aSN10 != null)
         {
             num++;
             subjectUniqueID = aSN10.Value;
         }
         ASN1 aSN11 = aSN.Element(num, 163);
         if (aSN11 != null && aSN11.Count == 1)
         {
             extensions = new X509ExtensionCollection(aSN11[0]);
         }
         else
         {
             extensions = new X509ExtensionCollection(null);
         }
         m_encodedcert = (byte[])data.Clone();
     }
     catch (Exception inner)
     {
         throw new CryptographicException(encoding_error, inner);
         IL_035f :;
     }
 }