private TimeStampedDataParser(Asn1SequenceParser parser)
        {
            this.parser = parser;
            this.version = DerInteger.GetInstance(parser.ReadObject());

            Asn1Object obj = parser.ReadObject().ToAsn1Object();

            if (obj is DerIA5String)
            {
                this.dataUri = DerIA5String.GetInstance(obj);
                obj = parser.ReadObject().ToAsn1Object();
            }

            if (//obj is MetaData ||
                obj is Asn1SequenceParser)
            {
                this.metaData = MetaData.GetInstance(obj.ToAsn1Object());
                obj = parser.ReadObject().ToAsn1Object();
            }

            if (obj is Asn1OctetStringParser)
            {
                this.content = (Asn1OctetStringParser)obj;
            }
        }
		public PublicKeyAndChallenge(
			Asn1Sequence seq)
		{
			pkacSeq = seq;
			spki = SubjectPublicKeyInfo.GetInstance(seq[0]);
			challenge = DerIA5String.GetInstance(seq[1]);
		}
        /**
        * Constructor from given details.
        * <p/>
        * All parameters can be combined.
        *
        * @param namingAuthorityID   ObjectIdentifier for naming authority.
        * @param namingAuthorityUrl  URL for naming authority.
        * @param namingAuthorityText Textual representation of naming authority.
        */
        public NamingAuthority(
			DerObjectIdentifier	namingAuthorityID,
			string				namingAuthorityUrl,
			DirectoryString		namingAuthorityText)
        {
            this.namingAuthorityID = namingAuthorityID;
            this.namingAuthorityUrl = new DerIA5String(namingAuthorityUrl, true);
            this.namingAuthorityText = namingAuthorityText;
        }
		public TimeStampedData(DerIA5String dataUri, MetaData metaData, Asn1OctetString content,
			Evidence temporalEvidence)
		{
			this.version = new DerInteger(1);
			this.dataUri = dataUri;
			this.metaData = metaData;
			this.content = content;
			this.temporalEvidence = temporalEvidence;
		}
 public BiometricData(
     TypeOfBiometricData	typeOfBiometricData,
     AlgorithmIdentifier	hashAlgorithm,
     Asn1OctetString		biometricDataHash)
 {
     this.typeOfBiometricData = typeOfBiometricData;
     this.hashAlgorithm = hashAlgorithm;
     this.biometricDataHash = biometricDataHash;
     this.sourceDataUri = null;
 }
		public MetaData(
			DerBoolean		hashProtected,
			DerUtf8String	fileName,
			DerIA5String	mediaType,
			Attributes		otherMetaData)
		{
			this.hashProtected = hashProtected;
			this.fileName = fileName;
			this.mediaType = mediaType;
			this.otherMetaData = otherMetaData;
		}
		private BiometricData(
			Asn1Sequence seq)
        {
			typeOfBiometricData = TypeOfBiometricData.GetInstance(seq[0]);
			hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]);
			biometricDataHash = Asn1OctetString.GetInstance(seq[2]);

			if (seq.Count > 3)
			{
				sourceDataUri = DerIA5String.GetInstance(seq[3]);
			}
        }
Exemple #8
0
        /// <exception cref="System.IO.IOException"></exception>
        private string GetAccessLocation(X509Certificate certificate, DerObjectIdentifier
                                         accessMethod)
        {
            //byte[] authInfoAccessExtensionValue = certificate.GetExtensionValue(X509Extensions
            //    .AuthorityInfoAccess);
            Asn1OctetString authInfoAccessExtensionValue = certificate.GetExtensionValue(X509Extensions
                                                                                         .AuthorityInfoAccess);

            if (null == authInfoAccessExtensionValue)
            {
                return(null);
            }
            AuthorityInformationAccess authorityInformationAccess;
            //DerOctetString oct = (DerOctetString)(new Asn1InputStream(new MemoryStream
            //    (authInfoAccessExtensionValue)).ReadObject());
            DerOctetString oct = (DerOctetString)authInfoAccessExtensionValue;

            //authorityInformationAccess = new AuthorityInformationAccess((Asn1Sequence)new Asn1InputStream
            //    (oct.GetOctets()).ReadObject());
            authorityInformationAccess = AuthorityInformationAccess.GetInstance((Asn1Sequence) new Asn1InputStream
                                                                                    (oct.GetOctets()).ReadObject());
            AccessDescription[] accessDescriptions = authorityInformationAccess.GetAccessDescriptions
                                                         ();
            foreach (AccessDescription accessDescription in accessDescriptions)
            {
                LOG.Info("access method: " + accessDescription.AccessMethod);
                bool correctAccessMethod = accessDescription.AccessMethod.Equals(accessMethod
                                                                                 );
                if (!correctAccessMethod)
                {
                    continue;
                }
                GeneralName gn = accessDescription.AccessLocation;
                if (gn.TagNo != GeneralName.UniformResourceIdentifier)
                {
                    LOG.Info("not a uniform resource identifier");
                    continue;
                }
                DerIA5String str            = (DerIA5String)((DerTaggedObject)gn.ToAsn1Object()).GetObject();
                string       accessLocation = str.GetString();
                LOG.Info("access location: " + accessLocation);
                return(accessLocation);
            }
            return(null);
        }
Exemple #9
0
        private MetaData(Asn1Sequence seq)
        {
            hashProtected = DerBoolean.GetInstance(seq[0]);
            int num = 1;

            if (num < seq.Count && seq[num] is DerUtf8String)
            {
                fileName = DerUtf8String.GetInstance(seq[num++]);
            }
            if (num < seq.Count && seq[num] is DerIA5String)
            {
                mediaType = DerIA5String.GetInstance(seq[num++]);
            }
            if (num < seq.Count)
            {
                otherMetaData = Attributes.GetInstance(seq[num++]);
            }
        }
Exemple #10
0
        private TimeStampedData(Asn1Sequence seq)
        {
            version = DerInteger.GetInstance(seq[0]);
            int index = 1;

            if (seq[index] is DerIA5String)
            {
                dataUri = DerIA5String.GetInstance(seq[index++]);
            }
            if (seq[index] is MetaData || seq[index] is Asn1Sequence)
            {
                metaData = MetaData.GetInstance(seq[index++]);
            }
            if (seq[index] is Asn1OctetString)
            {
                content = Asn1OctetString.GetInstance(seq[index++]);
            }
            temporalEvidence = Evidence.GetInstance(seq[index]);
        }
		private TimeStampedData(Asn1Sequence seq)
		{
			this.version = DerInteger.GetInstance(seq[0]);
			
			int index = 1;
			if (seq[index] is DerIA5String)
			{
				this.dataUri = DerIA5String.GetInstance(seq[index++]);
			}
			if (seq[index] is MetaData || seq[index] is Asn1Sequence)
			{
				this.metaData = MetaData.GetInstance(seq[index++]);
			}
			if (seq[index] is Asn1OctetString)
			{
				this.content = Asn1OctetString.GetInstance(seq[index++]);
			}
			this.temporalEvidence = Evidence.GetInstance(seq[index]);
		}
Exemple #12
0
        private void CheckConstruction(
            BiometricData bd,
            TypeOfBiometricData dataType,
            AlgorithmIdentifier hashAlgorithm,
            Asn1OctetString dataHash,
            DerIA5String dataUri)
        {
            CheckValues(bd, dataType, hashAlgorithm, dataHash, dataUri);

            bd = BiometricData.GetInstance(bd);

            CheckValues(bd, dataType, hashAlgorithm, dataHash, dataUri);

            Asn1Sequence seq = (Asn1Sequence)Asn1Object.FromByteArray(bd.ToAsn1Object().GetEncoded());

            bd = BiometricData.GetInstance(seq);

            CheckValues(bd, dataType, hashAlgorithm, dataHash, dataUri);
        }
Exemple #13
0
        private MetaData(Asn1Sequence seq)
        {
            this.hashProtected = DerBoolean.GetInstance(seq[0]);

            int index = 1;

            if (index < seq.Count && seq[index] is DerUtf8String)
            {
                this.fileName = DerUtf8String.GetInstance(seq[index++]);
            }
            if (index < seq.Count && seq[index] is DerIA5String)
            {
                this.mediaType = DerIA5String.GetInstance(seq[index++]);
            }
            if (index < seq.Count)
            {
                this.otherMetaData = Attributes.GetInstance(seq[index++]);
            }
        }
Exemple #14
0
		private MetaData(Asn1Sequence seq)
		{
			this.hashProtected = DerBoolean.GetInstance(seq[0]);

			int index = 1;

			if (index < seq.Count && seq[index] is DerUtf8String)
			{
				this.fileName = DerUtf8String.GetInstance(seq[index++]);
			}
			if (index < seq.Count && seq[index] is DerIA5String)
			{
				this.mediaType = DerIA5String.GetInstance(seq[index++]);
			}
			if (index < seq.Count)
			{
				this.otherMetaData = Attributes.GetInstance(seq[index++]);
			}
		}
 internal static void AddAdditionalStoresFromCrlDistributionPoint(
     CrlDistPoint crldp,
     PkixParameters pkixParams)
 {
     if (crldp != null)
     {
         DistributionPoint[] dps = null;
         try
         {
             dps = crldp.GetDistributionPoints();
         }
         catch (Exception e)
         {
             throw new Exception(
                       "Distribution points could not be read.", e);
         }
         for (int i = 0; i < dps.Length; i++)
         {
             DistributionPointName dpn = dps[i].DistributionPointName;
             // look for URIs in fullName
             if (dpn != null)
             {
                 if (dpn.PointType == DistributionPointName.FullName)
                 {
                     GeneralName[] genNames = GeneralNames.GetInstance(
                         dpn.Name).GetNames();
                     // look for an URI
                     for (int j = 0; j < genNames.Length; j++)
                     {
                         if (genNames[j].TagNo == GeneralName.UniformResourceIdentifier)
                         {
                             string location = DerIA5String.GetInstance(
                                 genNames[j].Name).GetString();
                             PkixCertPathValidatorUtilities.AddAdditionalStoreFromLocation(
                                 location, pkixParams);
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #16
0
        public virtual void ToSignaturePolicyIdentifierTest()
        {
            SignaturePolicyIdentifier actual = new SignaturePolicyInfo(POLICY_IDENTIFIER, POLICY_HASH, POLICY_DIGEST_ALGORITHM
                                                                       , POLICY_URI).ToSignaturePolicyIdentifier();
            DerIA5String           deria5String           = new DerIA5String(POLICY_URI);
            SigPolicyQualifierInfo sigPolicyQualifierInfo = new SigPolicyQualifierInfo(Org.BouncyCastle.Asn1.Pkcs.PkcsObjectIdentifiers.IdSpqEtsUri
                                                                                       , deria5String);
            DerOctetString       derOctetString              = new DerOctetString(POLICY_HASH);
            String               algId                       = DigestAlgorithms.GetAllowedDigest(POLICY_DIGEST_ALGORITHM);
            DerObjectIdentifier  asn1ObjectIdentifier        = new DerObjectIdentifier(algId);
            AlgorithmIdentifier  algorithmIdentifier         = new AlgorithmIdentifier(asn1ObjectIdentifier);
            OtherHashAlgAndValue otherHashAlgAndValue        = new OtherHashAlgAndValue(algorithmIdentifier, derOctetString);
            DerObjectIdentifier  derObjectIdentifier         = new DerObjectIdentifier(POLICY_IDENTIFIER);
            DerObjectIdentifier  derObjectIdentifierInstance = DerObjectIdentifier.GetInstance(derObjectIdentifier);
            SignaturePolicyId    signaturePolicyId           = new SignaturePolicyId(derObjectIdentifierInstance, otherHashAlgAndValue
                                                                                     , SignUtils.CreateSigPolicyQualifiers(sigPolicyQualifierInfo));
            SignaturePolicyIdentifier expected = new SignaturePolicyIdentifier(signaturePolicyId);

            NUnit.Framework.Assert.AreEqual(expected.ToAsn1Object(), actual.ToAsn1Object());
        }
        public static List <string> GetAuthorityInformationAccessOcspUrl(X509Certificate cert)
        {
            List <string> ocspUrls = new List <string>();

            try
            {
                Asn1Object obj = GetExtensionValue(cert, X509Extensions.AuthorityInfoAccess.Id);

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

                // For a strange reason I cannot acess the aia.AccessDescription[].
                // Hope it will be fixed in the next version (1.5).
                // AuthorityInformationAccess aia = AuthorityInformationAccess.GetInstance(obj);

                // Switched to manual parse
                Asn1Sequence s        = (Asn1Sequence)obj;
                IEnumerator  elements = s.GetEnumerator();

                while (elements.MoveNext())
                {
                    Asn1Sequence        element = (Asn1Sequence)elements.Current;
                    DerObjectIdentifier oid     = (DerObjectIdentifier)element[0];

                    if (oid.Id.Equals("1.3.6.1.5.5.7.48.1")) // Is Ocsp?
                    {
                        Asn1TaggedObject taggedObject = (Asn1TaggedObject)element[1];
                        GeneralName      gn           = (GeneralName)GeneralName.GetInstance(taggedObject);
                        ocspUrls.Add(((DerIA5String)DerIA5String.GetInstance(gn.Name)).GetString());
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error parsing AIA.", e);
            }

            return(ocspUrls);
        }
Exemple #18
0
		// TODO Add GetInstance method(s) and amke this private?
		public CrlID(
            Asn1Sequence seq)
        {
			foreach (Asn1TaggedObject o in seq)
			{
				switch (o.TagNo)
                {
                case 0:
                    crlUrl = DerIA5String.GetInstance(o, true);
                    break;
                case 1:
                    crlNum = DerInteger.GetInstance(o, true);
                    break;
                case 2:
                    crlTime = DerGeneralizedTime.GetInstance(o, true);
                    break;
                default:
                    throw new ArgumentException("unknown tag number: " + o.TagNo);
                }
            }
        }
Exemple #19
0
    private TimeStampedDataParser(Asn1SequenceParser parser)
    {
        this.parser = parser;
        version     = DerInteger.GetInstance(parser.ReadObject());
        Asn1Object asn1Object = parser.ReadObject().ToAsn1Object();

        if (asn1Object is DerIA5String)
        {
            dataUri    = DerIA5String.GetInstance(asn1Object);
            asn1Object = parser.ReadObject().ToAsn1Object();
        }
        if (asn1Object is Asn1SequenceParser)
        {
            metaData   = MetaData.GetInstance(asn1Object.ToAsn1Object());
            asn1Object = parser.ReadObject().ToAsn1Object();
        }
        if (asn1Object is Asn1OctetStringParser)
        {
            content = (Asn1OctetStringParser)asn1Object;
        }
    }
Exemple #20
0
        // Certificate Revocation Lists

        /**
         * Gets the URL of the Certificate Revocation List for a Certificate
         * @param certificate   the Certificate
         * @return  the String where you can check if the certificate was revoked
         * @throws CertificateParsingException
         * @throws IOException
         */
        public static String GetCRLURL(X509Certificate certificate)
        {
            try {
                Asn1Object obj = GetExtensionValue(certificate, X509Extensions.CrlDistributionPoints.Id);
                if (obj == null)
                {
                    return(null);
                }
                CrlDistPoint        dist  = CrlDistPoint.GetInstance(obj);
                DistributionPoint[] dists = dist.GetDistributionPoints();
                foreach (DistributionPoint p in dists)
                {
                    DistributionPointName distributionPointName = p.DistributionPointName;
                    if (DistributionPointName.FullName != distributionPointName.PointType)
                    {
                        continue;
                    }
                    GeneralNames  generalNames = (GeneralNames)distributionPointName.Name;
                    GeneralName[] names        = generalNames.GetNames();
                    foreach (GeneralName name in names)
                    {
                        if (name.TagNo != GeneralName.UniformResourceIdentifier)
                        {
                            continue;
                        }
                        DerIA5String derStr = DerIA5String.GetInstance((Asn1TaggedObject)name.ToAsn1Object(), false);
                        //return derStr.GetString();
                        //jbonilla - El URL del CRL para el BCE está en la tercera posición y solo se puede acceder desde HTTP.
                        string urlCrl = derStr.GetString();
                        if (urlCrl.ToUpperInvariant().StartsWith("HTTP") && urlCrl.ToUpperInvariant().Contains("CRL"))
                        {
                            return(derStr.GetString());
                        }
                    }
                }
            } catch {
            }
            return(null);
        }
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(this.tag);
            stringBuilder.Append(": ");
            switch (this.tag)
            {
            case 1:
            case 2:
            case 6:
                stringBuilder.Append(DerIA5String.GetInstance(this.obj).GetString());
                goto IL_8C;

            case 4:
                stringBuilder.Append(X509Name.GetInstance(this.obj).ToString());
                goto IL_8C;
            }
            stringBuilder.Append(this.obj.ToString());
IL_8C:
            return(stringBuilder.ToString());
        }
Exemple #22
0
        /// <summary>Gets the URL of the Certificate Revocation List for a Certificate</summary>
        /// <param name="certificate">the Certificate</param>
        /// <returns>the String where you can check if the certificate was revoked</returns>
        public static String GetCRLURL(X509Certificate certificate)
        {
            Asn1Object obj;

            try {
                obj = GetExtensionValue(certificate, X509Extensions.CrlDistributionPoints.Id);
            }
            catch (System.IO.IOException) {
                obj = (Asn1Object)null;
            }
            if (obj == null)
            {
                return(null);
            }
            CrlDistPoint dist = CrlDistPoint.GetInstance(obj);

            DistributionPoint[] dists = dist.GetDistributionPoints();
            foreach (DistributionPoint p in dists)
            {
                DistributionPointName distributionPointName = p.DistributionPointName;
                if (DistributionPointName.FullName != distributionPointName.PointType)
                {
                    continue;
                }
                GeneralNames  generalNames = (GeneralNames)distributionPointName.Name;
                GeneralName[] names        = generalNames.GetNames();
                foreach (GeneralName name in names)
                {
                    if (name.TagNo != GeneralName.UniformResourceIdentifier)
                    {
                        continue;
                    }
                    DerIA5String derStr = DerIA5String.GetInstance((Asn1TaggedObject)name.ToAsn1Object(), false);
                    return(derStr.GetString());
                }
            }
            return(null);
        }
        public void GetNuGetV3ServiceIndexUrl_WithMultipleAttributeValues_Throws()
        {
            using (var certificate = _fixture.GetDefaultCertificate())
            {
                var attributes = CreateAttributeCollection(certificate, _fixture.DefaultKeyPair.Private,
                                                           vector =>
                {
                    var value     = new DerIA5String("https://test.test");
                    var attribute = new BcAttribute(
                        new DerObjectIdentifier(Oids.NuGetV3ServiceIndexUrl),
                        new DerSet(value, value));

                    vector.Add(attribute);
                });

                var exception = Assert.Throws <SignatureException>(
                    () => AttributeUtility.GetNuGetV3ServiceIndexUrl(attributes));

                Assert.Equal(
                    "The nuget-v3-service-index-url attribute must have exactly one attribute value.",
                    exception.Message);
            }
        }
Exemple #24
0
    public CrlID(Asn1Sequence seq)
    {
        foreach (Asn1TaggedObject item in seq)
        {
            switch (item.TagNo)
            {
            case 0:
                crlUrl = DerIA5String.GetInstance(item, isExplicit: true);
                break;

            case 1:
                crlNum = DerInteger.GetInstance(item, isExplicit: true);
                break;

            case 2:
                crlTime = DerGeneralizedTime.GetInstance(item, isExplicit: true);
                break;

            default:
                throw new ArgumentException("unknown tag number: " + item.TagNo);
            }
        }
    }
        /// <summary>
        /// Devuelve la URL del servidor OCSP que contenga el certificado
        /// </summary>
        /// <param name="cert"></param>
        /// <returns></returns>
        public string GetAuthorityInformationAccessOcspUrl(X509Certificate cert)
        {
            List <string> ocspUrls = new List <string>();

            try
            {
                Asn1Object obj = GetExtensionValue(cert, X509Extensions.AuthorityInfoAccess.Id);

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

                // Switched to manual parse
                Asn1Sequence s        = (Asn1Sequence)obj;
                IEnumerator  elements = s.GetEnumerator();

                while (elements.MoveNext())
                {
                    Asn1Sequence        element = (Asn1Sequence)elements.Current;
                    DerObjectIdentifier oid     = (DerObjectIdentifier)element[0];

                    if (oid.Id.Equals("1.3.6.1.5.5.7.48.1")) // Is Ocsp?
                    {
                        Asn1TaggedObject taggedObject = (Asn1TaggedObject)element[1];
                        GeneralName      gn           = (GeneralName)GeneralName.GetInstance(taggedObject);
                        ocspUrls.Add(((DerIA5String)DerIA5String.GetInstance(gn.Name)).GetString());
                    }
                }
            }
            catch (Exception e)
            {
                return(null);
            }

            return(ocspUrls[0]);
        }
Exemple #26
0
        public static List <string> GetAuthorityInformationAccessOcspUrl(X509Certificate in_Certificado)
        {
            List <string> ocspUrls = new List <string>();

            try
            {
                Asn1Object obj = ObtenerValorDeExtension(in_Certificado, X509Extensions.AuthorityInfoAccess.Id);

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


                Asn1Sequence s         = (Asn1Sequence)obj;
                IEnumerator  elementos = s.GetEnumerator();

                while (elementos.MoveNext())
                {
                    Asn1Sequence        elemento = (Asn1Sequence)elementos.Current;
                    DerObjectIdentifier oid      = (DerObjectIdentifier)elemento[0];

                    if (oid.Id.Equals("1.3.6.1.5.5.7.48.1")) // Ocsp?
                    {
                        Asn1TaggedObject objetoTagged = (Asn1TaggedObject)elemento[1];
                        GeneralName      gn           = (GeneralName)GeneralName.GetInstance(objetoTagged);
                        ocspUrls.Add(((DerIA5String)DerIA5String.GetInstance(gn.Name)).GetString());
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error en AuthorityInformationAccess.", e);
            }

            return(ocspUrls);
        }
Exemple #27
0
        public CrlID(Asn1Sequence seq)
        {
            //IL_0078: Unknown result type (might be due to invalid IL or missing references)
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)enumerator.get_Current();
                    switch (asn1TaggedObject.TagNo)
                    {
                    case 0:
                        crlUrl = DerIA5String.GetInstance(asn1TaggedObject, isExplicit: true);
                        break;

                    case 1:
                        crlNum = DerInteger.GetInstance(asn1TaggedObject, isExplicit: true);
                        break;

                    case 2:
                        crlTime = DerGeneralizedTime.GetInstance(asn1TaggedObject, isExplicit: true);
                        break;

                    default:
                        throw new ArgumentException(string.Concat((object)"unknown tag number: ", (object)asn1TaggedObject.TagNo));
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
        private TimeStampedDataParser(Asn1SequenceParser parser)
        {
            this.parser = parser;

            Asn1Object obj = parser.ReadObject().ToAsn1Object();

            if (obj is DerIA5String)
            {
                this.dataUri = DerIA5String.GetInstance(obj);
                obj          = parser.ReadObject().ToAsn1Object();
            }

            if (//obj is MetaData ||
                obj is Asn1SequenceParser)
            {
                this.metaData = MetaData.GetInstance(obj.ToAsn1Object());
                obj           = parser.ReadObject().ToAsn1Object();
            }

            if (obj is Asn1OctetStringParser)
            {
                this.content = (Asn1OctetStringParser)obj;
            }
        }
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(this.tag);
            builder.Append(": ");
            switch (this.tag)
            {
            case 1:
            case 2:
            case 6:
                builder.Append(DerIA5String.GetInstance(this.obj).GetString());
                break;

            case 4:
                builder.Append(X509Name.GetInstance(this.obj).ToString());
                break;

            default:
                builder.Append(this.obj.ToString());
                break;
            }
            return(builder.ToString());
        }
        //Get OCSP URLs from a certificate by checking the extensions, finding the OCSP extension and extracting its URLs.
        public static List <string> GetAuthorityInformationAccessOcspUrl(X509Certificate cert)
        {
            List <string> ocspUrls = new List <string>();

            try
            {
                Asn1Object obj = GetExtensionValue(cert, X509Extensions.AuthorityInfoAccess.Id);

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

                Asn1Sequence s        = (Asn1Sequence)obj;
                IEnumerator  elements = s.GetEnumerator();

                while (elements.MoveNext())
                {
                    Asn1Sequence        element = (Asn1Sequence)elements.Current;
                    DerObjectIdentifier oid     = (DerObjectIdentifier)element[0];

                    if (oid.Id.Equals(OCSP_OID)) // Is OID == OCSP?
                    {
                        Asn1TaggedObject taggedObject = (Asn1TaggedObject)element[1];
                        GeneralName      gn           = (GeneralName)GeneralName.GetInstance(taggedObject);
                        ocspUrls.Add(((DerIA5String)DerIA5String.GetInstance(gn.Name)).GetString());
                    }
                }
            }
            catch (Exception e)
            {
                throw new OCSPExpection("Error parsing AIA.", e);
            }

            return(ocspUrls);
        }
Exemple #31
0
 public TbsSign(DerInteger version, SesSealInfo eSeal, DerBitString timeInfo, DerBitString dataHash, DerIA5String propertyInfo, DerObjectIdentifier signatureAlgorithm)
 {
     Version            = version;
     EsSeal             = eSeal;
     TimeInfo           = timeInfo;
     DataHash           = dataHash;
     PropertyInfo       = propertyInfo;
     SignatureAlgorithm = signatureAlgorithm;
 }
 public NetscapeRevocationUrl(DerIA5String str)
     : base(str.GetString())
 {
 }
Exemple #33
0
        /// <summary>Gives back the CRL URI meta-data found within the given X509 certificate.
        ///     </summary>
        /// <remarks>Gives back the CRL URI meta-data found within the given X509 certificate.
        ///     </remarks>
        /// <param name="certificate">the X509 certificate.</param>
        /// <returns>the CRL URI, or <code>null</code> if the extension is not present.</returns>
        /// <exception cref="System.UriFormatException">System.UriFormatException</exception>
        public virtual string GetCrlUri(X509Certificate certificate)
        {
            //byte[] crlDistributionPointsValue = certificate.GetExtensionValue(X509Extensions.
            //    CrlDistributionPoints);
            Asn1OctetString crlDistributionPointsValue = certificate.GetExtensionValue(X509Extensions.
                                                                                       CrlDistributionPoints);

            if (null == crlDistributionPointsValue)
            {
                return(null);
            }
            Asn1Sequence seq;

            try
            {
                DerOctetString oct;
                //oct = (DEROctetString)(new ASN1InputStream(new ByteArrayInputStream(crlDistributionPointsValue
                //    )).ReadObject());
                oct = (DerOctetString)crlDistributionPointsValue;
                seq = (Asn1Sequence) new Asn1InputStream(oct.GetOctets()).ReadObject();
            }
            catch (IOException e)
            {
                throw new RuntimeException("IO error: " + e.Message, e);
            }
            CrlDistPoint distPoint = CrlDistPoint.GetInstance(seq);

            DistributionPoint[] distributionPoints = distPoint.GetDistributionPoints();
            foreach (DistributionPoint distributionPoint in distributionPoints)
            {
                DistributionPointName distributionPointName = distributionPoint.DistributionPointName;
                if (DistributionPointName.FullName != distributionPointName.PointType)
                {
                    continue;
                }
                GeneralNames  generalNames = (GeneralNames)distributionPointName.Name;
                GeneralName[] names        = generalNames.GetNames();
                foreach (GeneralName name in names)
                {
                    if (name.TagNo != GeneralName.UniformResourceIdentifier)
                    {
                        LOG.Info("not a uniform resource identifier");
                        continue;
                    }
                    string str = null;
                    if (name.ToAsn1Object() is DerTaggedObject)
                    {
                        DerTaggedObject taggedObject = (DerTaggedObject)name.ToAsn1Object();
                        DerIA5String    derStr       = DerIA5String.GetInstance(taggedObject.GetObject());
                        str = derStr.GetString();
                    }
                    else
                    {
                        DerIA5String derStr = DerIA5String.GetInstance(name.ToAsn1Object());
                        str = derStr.GetString();
                    }
                    if (str != null && (str.StartsWith("http://") || str.StartsWith("https://")) &&
                        str.ToUpperInvariant().Contains("CRL"))    //jbonilla - El URL del CRL para el BCE está en la tercera posición y solo se puede acceder desde HTTP.
                    {
                        return(str);
                    }
                    else
                    {
                        LOG.Info("Supports only http:// and https:// protocol for CRL");
                    }
                }
            }

            //jbonilla
            #region BCE
            if (certificate.SubjectDN.ToString()
                .Contains("AC BANCO CENTRAL DEL ECUADOR"))
            {
                return(this.IntermediateAcUrl);
            }
            #endregion

            return(null);
        }
Exemple #34
0
 public SesHeader(DerInteger version, DerIA5String manufacturer)
 {
     Version      = version;
     Manufacturer = manufacturer;
 }
 public PublicKeyAndChallenge(Asn1Sequence seq)
 {
     pkacSeq   = seq;
     spki      = SubjectPublicKeyInfo.GetInstance(seq[0]);
     challenge = DerIA5String.GetInstance(seq[1]);
 }
 public NetscapeRevocationUrl(DerIA5String str)
     : base(str.GetString())
 {
 }
Exemple #37
0
 public VerisignCzagExtension(DerIA5String str)
     : base(str.GetString())
 {
 }
Exemple #38
0
 public BiometricData(TypeOfBiometricData typeOfBiometricData, AlgorithmIdentifier hashAlgorithm, Asn1OctetString biometricDataHash, DerIA5String sourceDataUri)
 {
     this.typeOfBiometricData = typeOfBiometricData;
     this.hashAlgorithm       = hashAlgorithm;
     this.biometricDataHash   = biometricDataHash;
     this.sourceDataUri       = sourceDataUri;
 }
Exemple #39
0
 public TbsSign(DerInteger version, SeSeal eSeal, DerGeneralizedTime timeInfo, DerBitString dataHash, DerIA5String propertyInfo, DerObjectIdentifier signatureAlgorithm, ExtensionData extData)
 {
     Version            = version;
     EsSeal             = eSeal;
     TimeInfo           = timeInfo;
     DataHash           = dataHash;
     PropertyInfo       = propertyInfo;
     ExtensionData      = extData;
     SignatureAlgorithm = signatureAlgorithm;
 }
        /**
         * Constructor from Asn1Sequence.
         * <p/>
         * <p/>
         * <pre>
         *             NamingAuthority ::= SEQUENCE
         *             {
         *               namingAuthorityID OBJECT IDENTIFIER OPTIONAL,
         *               namingAuthorityUrl IA5String OPTIONAL,
         *               namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
         *             }
         * </pre>
         *
         * @param seq The ASN.1 sequence.
         */
        private NamingAuthority(
            Asn1Sequence seq)
        {
            if (seq.Count > 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            IEnumerator e = seq.GetEnumerator();

            if (e.MoveNext())
            {
                Asn1Encodable o = (Asn1Encodable)e.Current;
                if (o is DerObjectIdentifier)
                {
                    namingAuthorityID = (DerObjectIdentifier)o;
                }
                else if (o is DerIA5String)
                {
                    namingAuthorityUrl = DerIA5String.GetInstance(o).GetString();
                }
                else if (o is IAsn1String)
                {
                    namingAuthorityText = DirectoryString.GetInstance(o);
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(o));
                }
            }

            if (e.MoveNext())
            {
                Asn1Encodable o = (Asn1Encodable)e.Current;
                if (o is DerIA5String)
                {
                    namingAuthorityUrl = DerIA5String.GetInstance(o).GetString();
                }
                else if (o is IAsn1String)
                {
                    namingAuthorityText = DirectoryString.GetInstance(o);
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(o));
                }
            }

            if (e.MoveNext())
            {
                Asn1Encodable o = (Asn1Encodable)e.Current;
                if (o is IAsn1String)
                {
                    namingAuthorityText = DirectoryString.GetInstance(o);
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(o));
                }
            }
        }
Exemple #41
0
        /// <summary>
        /// Extract AIA URL. It can be AIA OCSP or AIA Issuer
        /// </summary>
        /// <param name="taggedObject"></param>
        /// <returns></returns>
        string ExtractAIAUrl(Asn1TaggedObject taggedObject)
        {
            var gn = (GeneralName)GeneralName.GetInstance(taggedObject);

            return(((DerIA5String)DerIA5String.GetInstance(gn.Name)).GetString());
        }
 public VerisignCzagExtension(DerIA5String str)
     : base(str.GetString())
 {
 }
        /**
        * Constructor from Asn1Sequence.
        * <p/>
        * <p/>
        * <pre>
        *             NamingAuthority ::= SEQUENCE
        *             {
        *               namingAuthorityID OBJECT IDENTIFIER OPTIONAL,
        *               namingAuthorityUrl IA5String OPTIONAL,
        *               namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
        *             }
        * </pre>
        *
        * @param seq The ASN.1 sequence.
        */
        private NamingAuthority(
			Asn1Sequence seq)
        {
            if (seq.Count > 3)
                throw new ArgumentException("Bad sequence size: " + seq.Count);

            IEnumerator e = seq.GetEnumerator();

            if (e.MoveNext())
            {
                Asn1Encodable o = (Asn1Encodable) e.Current;
                if (o is DerObjectIdentifier)
                {
                    namingAuthorityID = (DerObjectIdentifier) o;
                }
                else if (o is DerIA5String)
                {
                    namingAuthorityUrl = DerIA5String.GetInstance(o);
                }
                else if (o is IAsn1String)
                {
                    namingAuthorityText = DirectoryString.GetInstance(o);
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
                }
            }

            if (e.MoveNext())
            {
                Asn1Encodable o = (Asn1Encodable) e.Current;
                if (o is DerIA5String)
                {
                    namingAuthorityUrl = DerIA5String.GetInstance(o);
                }
                else if (o is IAsn1String)
                {
                    namingAuthorityText = DirectoryString.GetInstance(o);
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
                }
            }

            if (e.MoveNext())
            {
                Asn1Encodable o = (Asn1Encodable) e.Current;
                if (o is IAsn1String)
                {
                    namingAuthorityText = DirectoryString.GetInstance(o);
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
                }
            }
        }