Esempio n. 1
0
        private static Asn1Encodable EncodeDnEntry(DnEntry dnEntry)
        {
            DerObjectIdentifier type  = new DerObjectIdentifier(dnEntry.Definition.Oid);
            Asn1Encodable       value = null;

            switch (dnEntry.Definition.ValueType)
            {
            case DnEntryValueType.PrintableString:
                value = new DerPrintableString(Encoding.UTF8.GetBytes(dnEntry.Value));
                break;

            case DnEntryValueType.UniversalString:
                value = new DerUniversalString(Encoding.UTF8.GetBytes(dnEntry.Value));
                break;

            case DnEntryValueType.Utf8String:
                value = new DerUtf8String(Encoding.UTF8.GetBytes(dnEntry.Value));
                break;

            case DnEntryValueType.BmpString:
                value = new DerBmpString(Encoding.UTF8.GetBytes(dnEntry.Value));
                break;

            default:
                // TODO - Does BC support DnEntryValueType.TeletexString ???
                throw new Exception("Unsupported type of DnEntry value");
            }

            return(new DerSequence(type, value));
        }
Esempio n. 2
0
		private LdsVersionInfo(Asn1Sequence seq)
		{
			if (seq.Count != 2)
				throw new ArgumentException("sequence wrong size for LDSVersionInfo", "seq");

			this.ldsVersion = DerPrintableString.GetInstance(seq[0]);
			this.unicodeVersion = DerPrintableString.GetInstance(seq[1]);
		}
Esempio n. 3
0
		/**
		* Constructor from a given details.
		* <p/>
		* <p/>
		* value = amount�10^exponent
		*
		* @param currency The currency. Must be the ISO code.
		* @param amount   The amount
		* @param exponent The exponent
		*/
		public MonetaryLimit(
			string	currency,
			int		amount,
			int		exponent)
		{
			this.currency = new DerPrintableString(currency, true);
			this.amount = new DerInteger(amount);
			this.exponent = new DerInteger(exponent);
		}
 /**
  * Constructor from a given details.
  * <p/>
  * <p/>
  * value = amount�10^exponent
  *
  * @param currency The currency. Must be the ISO code.
  * @param amount   The amount
  * @param exponent The exponent
  */
 public MonetaryLimit(
     string currency,
     int amount,
     int exponent)
 {
     this.currency = new DerPrintableString(currency, true);
     this.amount   = new DerInteger(amount);
     this.exponent = new DerInteger(exponent);
 }
Esempio n. 5
0
 private LdsVersionInfo(Asn1Sequence seq)
 {
     if (seq.Count != 2)
     {
         throw new ArgumentException("sequence wrong size for LDSVersionInfo", "seq");
     }
     ldsVersion     = DerPrintableString.GetInstance(seq[0]);
     unicodeVersion = DerPrintableString.GetInstance(seq[1]);
 }
Esempio n. 6
0
 private LdsVersionInfo(Asn1Sequence seq)
 {
     //IL_0019: Unknown result type (might be due to invalid IL or missing references)
     if (seq.Count != 2)
     {
         throw new ArgumentException("sequence wrong size for LDSVersionInfo", "seq");
     }
     ldsVersion     = DerPrintableString.GetInstance(seq[0]);
     unicodeVersion = DerPrintableString.GetInstance(seq[1]);
 }
Esempio n. 7
0
        public CertDigestObj(Asn1Sequence sequence)
        {
            IEnumerator enumerator = sequence.GetEnumerator();

            enumerator.MoveNext();
            Type = DerPrintableString.GetInstance(enumerator.Current);

            enumerator.MoveNext();
            Value = Asn1OctetString.GetInstance(enumerator.Current);
        }
Esempio n. 8
0
		private MonetaryLimit(
			Asn1Sequence seq)
		{
			if (seq.Count != 3)
				throw new ArgumentException("Bad sequence size: " + seq.Count);

			currency = DerPrintableString.GetInstance(seq[0]);
			amount = DerInteger.GetInstance(seq[1]);
			exponent = DerInteger.GetInstance(seq[2]);
		}
 private MonetaryLimit(Asn1Sequence seq)
 {
     if (seq.Count != 3)
     {
         throw new ArgumentException("Bad sequence size: " + seq.Count);
     }
     currency = DerPrintableString.GetInstance(seq[0]);
     amount   = DerInteger.GetInstance(seq[1]);
     exponent = DerInteger.GetInstance(seq[2]);
 }
Esempio n. 10
0
    protected override bool Asn1Equals(Asn1Object asn1Object)
    {
        DerPrintableString derPrintableString = asn1Object as DerPrintableString;

        if (derPrintableString == null)
        {
            return(false);
        }
        return(str.Equals(derPrintableString.str));
    }
        public override Asn1Object GetConvertedValue(DerObjectIdentifier oid, string value)
        {
            var result = base.GetConvertedValue(oid, value);

            if (result is DerUtf8String)
            {
                result = new DerPrintableString(value);
            }
            return(result);
        }
Esempio n. 12
0
        public DeclarationOfMajority(bool fullAge, string country)
        {
            //IL_0014: Unknown result type (might be due to invalid IL or missing references)
            if (country.get_Length() > 2)
            {
                throw new ArgumentException("country can only be 2 characters");
            }
            DerPrintableString derPrintableString = new DerPrintableString(country, validate: true);

            declaration = new DerTaggedObject(explicitly: false, 1, (!fullAge) ? new DerSequence(DerBoolean.False, derPrintableString) : new DerSequence(derPrintableString));
        }
Esempio n. 13
0
 private MonetaryLimit(Asn1Sequence seq)
 {
     //IL_0024: Unknown result type (might be due to invalid IL or missing references)
     if (seq.Count != 3)
     {
         throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
     }
     currency = DerPrintableString.GetInstance(seq[0]);
     amount   = DerInteger.GetInstance(seq[1]);
     exponent = DerInteger.GetInstance(seq[2]);
 }
Esempio n. 14
0
        /**
        * Constructor from a given details.
        * <p/>
        * <p/>
        * Either <code>generalName</code> or <code>certRef</code> MUST be
        * <code>null</code>.
        *
        * @param country            The country code whose laws apply.
        * @param typeOfSubstitution The type of procuration.
        * @param thirdPerson        The GeneralName of the person who is represented.
        * @param certRef            Reference to certificate of the person who is represented.
        */
        public Procuration(
			string			country,
			DirectoryString	typeOfSubstitution,
			GeneralName		thirdPerson,
			IssuerSerial	certRef)
        {
            this.country = new DerPrintableString(country, true);
            this.typeOfSubstitution = typeOfSubstitution;
            this.thirdPerson = thirdPerson;
            this.certRef = certRef;
        }
    public DeclarationOfMajority(bool fullAge, string country)
    {
        if (country.Length > 2)
        {
            throw new ArgumentException("country can only be 2 characters");
        }
        DerPrintableString derPrintableString = new DerPrintableString(country, validate: true);
        DerSequence        obj = (!fullAge) ? new DerSequence(DerBoolean.False, derPrintableString) : new DerSequence(derPrintableString);

        declaration = new DerTaggedObject(explicitly: false, 1, obj);
    }
Esempio n. 16
0
        /**
        * Constructor from a given details.
        *
        * @param nameOrPseudonym  Name or pseudonym.
        * @param nameDistiguisher Name distinguisher.
        * @param dateOfBirth      Date of birth.
        * @param placeOfBirth     Place of birth.
        * @param gender           Gender.
        * @param postalAddress    Postal Address.
        */
        public PersonalData(
			NameOrPseudonym		nameOrPseudonym,
			BigInteger			nameDistiguisher,
			DerGeneralizedTime	dateOfBirth,
			string				placeOfBirth,
			string				gender,
			string				postalAddress)
        {
            this.nameOrPseudonym = nameOrPseudonym;
            this.dateOfBirth = dateOfBirth;
            this.gender = new DerPrintableString(gender, true);
            this.nameDistiguisher = nameDistiguisher;
            this.postalAddress = new DirectoryString(postalAddress);
            this.placeOfBirth = new DirectoryString(placeOfBirth);
        }
Esempio n. 17
0
        /**
         * Constructor from Asn1Sequence.
         * <p/>
         * The sequence is of type NameOrPseudonym:
         * <p/>
         * <pre>
         *     PersonalData ::= SEQUENCE {
         *       nameOrPseudonym NameOrPseudonym,
         *       nameDistinguisher [0] INTEGER OPTIONAL,
         *       dateOfBirth [1] GeneralizedTime OPTIONAL,
         *       placeOfBirth [2] DirectoryString OPTIONAL,
         *       gender [3] PrintableString OPTIONAL,
         *       postalAddress [4] DirectoryString OPTIONAL
         *       }
         * </pre>
         *
         * @param seq The ASN.1 sequence.
         */
        private PersonalData(
            Asn1Sequence seq)
        {
            if (seq.Count < 1)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();

            nameOrPseudonym = NameOrPseudonym.GetInstance(e.Current);

            while (e.MoveNext())
            {
                Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
                int tag            = o.TagNo;
                switch (tag)
                {
                case 0:
                    nameDistinguisher = DerInteger.GetInstance(o, false).Value;
                    break;

                case 1:
                    dateOfBirth = DerGeneralizedTime.GetInstance(o, false);
                    break;

                case 2:
                    placeOfBirth = DirectoryString.GetInstance(o, true);
                    break;

                case 3:
                    gender = DerPrintableString.GetInstance(o, false).GetString();
                    break;

                case 4:
                    postalAddress = DirectoryString.GetInstance(o, true);
                    break;

                default:
                    throw new ArgumentException("Bad tag number: " + o.TagNo);
                }
            }
        }
 public static Iso4217CurrencyCode GetInstance(object obj)
 {
     if (obj == null || obj is Iso4217CurrencyCode)
     {
         return((Iso4217CurrencyCode)obj);
     }
     if (obj is DerInteger)
     {
         DerInteger instance = DerInteger.GetInstance(obj);
         int        intValue = instance.Value.IntValue;
         return(new Iso4217CurrencyCode(intValue));
     }
     if (obj is DerPrintableString)
     {
         DerPrintableString instance2 = DerPrintableString.GetInstance(obj);
         return(new Iso4217CurrencyCode(instance2.GetString()));
     }
     throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
 }
Esempio n. 19
0
 public static Iso4217CurrencyCode GetInstance(object obj)
 {
     //IL_0064: Unknown result type (might be due to invalid IL or missing references)
     if (obj == null || obj is Iso4217CurrencyCode)
     {
         return((Iso4217CurrencyCode)obj);
     }
     if (obj is DerInteger)
     {
         DerInteger instance = DerInteger.GetInstance(obj);
         int        intValue = instance.Value.IntValue;
         return(new Iso4217CurrencyCode(intValue));
     }
     if (obj is DerPrintableString)
     {
         DerPrintableString instance2 = DerPrintableString.GetInstance(obj);
         return(new Iso4217CurrencyCode(instance2.GetString()));
     }
     throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
 }
Esempio n. 20
0
        private PersonalData(Asn1Sequence seq)
        {
            //IL_0024: Unknown result type (might be due to invalid IL or missing references)
            //IL_00e9: Unknown result type (might be due to invalid IL or missing references)
            if (seq.Count < 1)
            {
                throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
            }
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            enumerator.MoveNext();
            nameOrPseudonym = NameOrPseudonym.GetInstance(enumerator.get_Current());
            while (enumerator.MoveNext())
            {
                Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(enumerator.get_Current());
                switch (instance.TagNo)
                {
                case 0:
                    nameDistinguisher = DerInteger.GetInstance(instance, isExplicit: false).Value;
                    break;

                case 1:
                    dateOfBirth = DerGeneralizedTime.GetInstance(instance, isExplicit: false);
                    break;

                case 2:
                    placeOfBirth = DirectoryString.GetInstance(instance, isExplicit: true);
                    break;

                case 3:
                    gender = DerPrintableString.GetInstance(instance, isExplicit: false).GetString();
                    break;

                case 4:
                    postalAddress = DirectoryString.GetInstance(instance, isExplicit: true);
                    break;

                default:
                    throw new ArgumentException(string.Concat((object)"Bad tag number: ", (object)instance.TagNo));
                }
            }
        }
Esempio n. 21
0
        private ProcurationSyntax(Asn1Sequence seq)
        {
            //IL_002d: Unknown result type (might be due to invalid IL or missing references)
            //IL_00cb: Unknown result type (might be due to invalid IL or missing references)
            if (seq.Count < 1 || seq.Count > 3)
            {
                throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
            }
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(enumerator.get_Current());
                switch (instance.TagNo)
                {
                case 1:
                    country = DerPrintableString.GetInstance(instance, isExplicit: true).GetString();
                    break;

                case 2:
                    typeOfSubstitution = DirectoryString.GetInstance(instance, isExplicit: true);
                    break;

                case 3:
                {
                    Asn1Object @object = instance.GetObject();
                    if (@object is Asn1TaggedObject)
                    {
                        thirdPerson = GeneralName.GetInstance(@object);
                    }
                    else
                    {
                        certRef = IssuerSerial.GetInstance(@object);
                    }
                    break;
                }

                default:
                    throw new ArgumentException(string.Concat((object)"Bad tag number: ", (object)instance.TagNo));
                }
            }
        }
		public DeclarationOfMajority(
			bool	fullAge,
			string	country)
		{
			if (country.Length > 2)
				throw new ArgumentException("country can only be 2 characters");

			DerPrintableString countryString = new DerPrintableString(country, true);

			DerSequence seq;
			if (fullAge)
			{
				seq = new DerSequence(countryString);
			}
			else
			{
				seq = new DerSequence(DerBoolean.False, countryString);
			}

			this.declaration = new DerTaggedObject(false, 1, seq);
		}
Esempio n. 23
0
        private ProcurationSyntax(Asn1Sequence seq)
        {
            if (seq.Count < 1 || seq.Count > 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }
            IEnumerator enumerator = seq.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(enumerator.Current);
                switch (instance.TagNo)
                {
                case 1:
                    this.country = DerPrintableString.GetInstance(instance, true).GetString();
                    break;

                case 2:
                    this.typeOfSubstitution = DirectoryString.GetInstance(instance, true);
                    break;

                case 3:
                {
                    Asn1Object @object = instance.GetObject();
                    if (@object is Asn1TaggedObject)
                    {
                        this.thirdPerson = GeneralName.GetInstance(@object);
                    }
                    else
                    {
                        this.certRef = IssuerSerial.GetInstance(@object);
                    }
                    break;
                }

                default:
                    throw new ArgumentException("Bad tag number: " + instance.TagNo);
                }
            }
        }
Esempio n. 24
0
        /**
         * Constructor from Asn1Sequence.
         * <p/>
         * The sequence is of type ProcurationSyntax:
         * <p/>
         * <pre>
         *               ProcurationSyntax ::= SEQUENCE {
         *                 country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
         *                 typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
         *                 signingFor [3] EXPLICIT SigningFor
         *               }
         * <p/>
         *               SigningFor ::= CHOICE
         *               {
         *                 thirdPerson GeneralName,
         *                 certRef IssuerSerial
         *               }
         * </pre>
         *
         * @param seq The ASN.1 sequence.
         */
        private ProcurationSyntax(
            Asn1Sequence seq)
        {
            if (seq.Count < 1 || seq.Count > 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            IEnumerator e = seq.GetEnumerator();

            while (e.MoveNext())
            {
                Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
                switch (o.TagNo)
                {
                case 1:
                    country = DerPrintableString.GetInstance(o, true).GetString();
                    break;

                case 2:
                    typeOfSubstitution = DirectoryString.GetInstance(o, true);
                    break;

                case 3:
                    Asn1Object signingFor = o.GetObject();
                    if (signingFor is Asn1TaggedObject)
                    {
                        thirdPerson = GeneralName.GetInstance(signingFor);
                    }
                    else
                    {
                        certRef = IssuerSerial.GetInstance(signingFor);
                    }
                    break;

                default:
                    throw new ArgumentException("Bad tag number: " + o.TagNo);
                }
            }
        }
Esempio n. 25
0
//        internal int			numeric;

        public static Iso4217CurrencyCode GetInstance(
            object obj)
        {
            if (obj == null || obj is Iso4217CurrencyCode)
            {
                return((Iso4217CurrencyCode)obj);
            }

            if (obj is DerInteger)
            {
                DerInteger numericobj = DerInteger.GetInstance(obj);
                int        numeric    = numericobj.Value.IntValue;
                return(new Iso4217CurrencyCode(numeric));
            }

            if (obj is DerPrintableString)
            {
                DerPrintableString alphabetic = DerPrintableString.GetInstance(obj);
                return(new Iso4217CurrencyCode(alphabetic.GetString()));
            }

            throw new ArgumentException("unknown object in GetInstance: " + obj.GetType().FullName, "obj");
        }
Esempio n. 26
0
        public DeclarationOfMajority(bool fullAge, string country)
        {
            if (country.Length > 2)
            {
                throw new ArgumentException("country can only be 2 characters");
            }
            DerPrintableString derPrintableString = new DerPrintableString(country, true);
            DerSequence        obj;

            if (fullAge)
            {
                obj = new DerSequence(derPrintableString);
            }
            else
            {
                obj = new DerSequence(new Asn1Encodable[]
                {
                    DerBoolean.False,
                    derPrintableString
                });
            }
            this.declaration = new DerTaggedObject(false, 1, obj);
        }
Esempio n. 27
0
//        internal int			numeric;

        public static Iso4217CurrencyCode GetInstance(
            object obj)
        {
            if (obj == null || obj is Iso4217CurrencyCode)
            {
                return((Iso4217CurrencyCode)obj);
            }

            if (obj is DerInteger)
            {
                DerInteger numericobj = DerInteger.GetInstance(obj);
                int        numeric    = numericobj.Value.IntValue;
                return(new Iso4217CurrencyCode(numeric));
            }

            if (obj is DerPrintableString)
            {
                DerPrintableString alphabetic = DerPrintableString.GetInstance(obj);
                return(new Iso4217CurrencyCode(alphabetic.GetString()));
            }

            throw new ArgumentException("unknown object in GetInstance: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
        }
Esempio n. 28
0
        public DeclarationOfMajority(
            bool fullAge,
            string country)
        {
            if (country.Length > 2)
            {
                throw new ArgumentException("country can only be 2 characters");
            }

            DerPrintableString countryString = new DerPrintableString(country, true);

            DerSequence seq;

            if (fullAge)
            {
                seq = new DerSequence(countryString);
            }
            else
            {
                seq = new DerSequence(DerBoolean.False, countryString);
            }

            this.declaration = new DerTaggedObject(false, 1, seq);
        }
Esempio n. 29
0
    private ProfessionInfo(Asn1Sequence seq)
    {
        if (seq.Count > 5)
        {
            throw new ArgumentException("Bad sequence size: " + seq.Count);
        }
        IEnumerator enumerator = seq.GetEnumerator();

        enumerator.MoveNext();
        Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.Current;

        if (asn1Encodable is Asn1TaggedObject)
        {
            Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)asn1Encodable;
            if (asn1TaggedObject.TagNo != 0)
            {
                throw new ArgumentException("Bad tag number: " + asn1TaggedObject.TagNo);
            }
            namingAuthority = NamingAuthority.GetInstance(asn1TaggedObject, isExplicit: true);
            enumerator.MoveNext();
            asn1Encodable = (Asn1Encodable)enumerator.Current;
        }
        professionItems = Asn1Sequence.GetInstance(asn1Encodable);
        if (enumerator.MoveNext())
        {
            asn1Encodable = (Asn1Encodable)enumerator.Current;
            if (asn1Encodable is Asn1Sequence)
            {
                professionOids = Asn1Sequence.GetInstance(asn1Encodable);
            }
            else if (asn1Encodable is DerPrintableString)
            {
                registrationNumber = DerPrintableString.GetInstance(asn1Encodable).GetString();
            }
            else
            {
                if (!(asn1Encodable is Asn1OctetString))
                {
                    throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(asn1Encodable));
                }
                addProfessionInfo = Asn1OctetString.GetInstance(asn1Encodable);
            }
        }
        if (enumerator.MoveNext())
        {
            asn1Encodable = (Asn1Encodable)enumerator.Current;
            if (asn1Encodable is DerPrintableString)
            {
                registrationNumber = DerPrintableString.GetInstance(asn1Encodable).GetString();
            }
            else
            {
                if (!(asn1Encodable is DerOctetString))
                {
                    throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(asn1Encodable));
                }
                addProfessionInfo = (DerOctetString)asn1Encodable;
            }
        }
        if (enumerator.MoveNext())
        {
            asn1Encodable = (Asn1Encodable)enumerator.Current;
            if (!(asn1Encodable is DerOctetString))
            {
                throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(asn1Encodable));
            }
            addProfessionInfo = (DerOctetString)asn1Encodable;
        }
    }
        public static List <CertSimples> ListaCertificado(X509Certificate2Collection Certificados)
        {
            List <CertSimples> oLista = new List <CertSimples>();

            for (int i = 0; i < Certificados.Count; i++)
            {
                X509Certificate2 oCertificado = Certificados[i];

                CertSimples oCert = new CertSimples();
                oCert.SerialNumber = oCertificado.SerialNumber;
                oCert.Subject      = oCertificado.Subject;

                try
                {
                    string[] DadosSubject = oCertificado.Subject.Split(',');
                    if (DadosSubject[0].IndexOf(":") > -1)
                    {
                        oCert.Nome = DadosSubject[0].Substring(3, DadosSubject[0].IndexOf(":") - 3);
                    }
                    else
                    {
                        oCert.Nome = DadosSubject[0].Substring(3);
                    }
                }
                catch (Exception ex)
                {
                    oCert.Nome = oCert.Subject;
                }



                foreach (var obj in oCertificado.Extensions)
                {
                    if (obj.Oid.Value == "2.5.29.17") //otherName
                    {
                        byte[] Dados = obj.RawData;
                        Stream sm    = new MemoryStream(Dados);
                        // StreamReader oSr = new StreamReader(sm);

                        //string teste = System.Text.Encoding.ASCII.GetString(Dados);
                        DerSequence otherName     = (DerSequence)Asn1Object.FromStream(sm);
                        var         objCollection = otherName.GetEnumerator();
                        while (objCollection.MoveNext())
                        {
                            Org.BouncyCastle.Asn1.DerTaggedObject iSub = (Org.BouncyCastle.Asn1.DerTaggedObject)objCollection.Current;
                            Asn1Object derObject = iSub.GetObject();
                            if (derObject.GetType().Name.Contains("DerSequence"))
                            {
                                var            objSubCollection = ((DerSequence)derObject).GetEnumerator();
                                byte           count            = 0;
                                string         strOID           = "";
                                DerOctetString strOctet;// = (DerOctetString)derObject;
                                string         strTexto = "";

                                while (objSubCollection.MoveNext())
                                {
                                    var Conteudo = objSubCollection.Current;
                                    if (count == 0)
                                    {
                                        strOID = Conteudo.ToString();
                                    }
                                    else
                                    {
                                        Org.BouncyCastle.Asn1.DerTaggedObject subCampos = (Org.BouncyCastle.Asn1.DerTaggedObject)Conteudo;
                                        Asn1Object derSub = subCampos.GetObject();
                                        try
                                        {
                                            if (derSub.GetType().Name.Contains("DerOctetString"))
                                            {
                                                strOctet = (DerOctetString)derSub;
                                                byte[] Texto = strOctet.GetOctets();
                                                strTexto = System.Text.Encoding.ASCII.GetString(Texto);
                                            }
                                            else
                                            {
                                                DerPrintableString strPtrString = (DerPrintableString)derSub;
                                                strTexto = strPtrString.GetString();
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            strTexto = derSub.ToString();
                                        }
                                    }
                                    count++;
                                }


                                if (strOID == "2.16.76.1.3.1") //PESSOA FÍSICA
                                {
                                    //i· OID = 2.16.76.1.3.1 e conteúdo = nas primeiras 8(oito) posições, a data de nascimento do titular, no formato ddmmaaaa; nas 11(onze) posições subseqüentes, o Cadastro de Pessoa Física(CPF) do titular; nas 11(onze) posições subseqüentes, o Número de Identificação Social – NIS(PIS, PASEP ou CI); nas 15(quinze) posições subseqüentes, o número do Registro Geral(RG) do titular; nas 10(dez) posições subseqüentes, as siglas do órgão expedidor do RG e respectiva unidade da federação;
                                    try
                                    {
                                        oCert.DataNascimento = strTexto.Substring(0, 8);
                                        oCert.CPF            = strTexto.Substring(8, 11);
                                        oCert.NIS            = strTexto.Substring(19, 11);
                                        oCert.RG             = strTexto.Substring(30, 15);
                                        oCert.OrgaoExpedidor = strTexto.Substring(45);
                                        oCert.Tipo           = "F";
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("Erro na leitura da OID=2.16.76.1.3.1:" + ex.Message, ex);
                                    }
                                }
                                else if (strOID == "2.16.76.1.3.6") //PESSOA FÍSICA
                                {
                                    //ii· OID = 2.16.76.1.3.6 e conteúdo = nas 12 (doze) posições o número do Cadastro Específico do INSS (CEI) da pessoa física titular do certificado;
                                }
                                else if (strOID == "2.16.76.1.3.6") //PESSOA FÍSICA
                                {
                                    try
                                    {
                                        //iii· OID = 2.16.76.1.3.5 e conteúdo nas primeiras 12(doze) posições, o número de inscrição do Título de Eleitor; nas 3(três) posições subseqüentes, a Zona Eleitoral; nas 4(quatro) posições seguintes, a Seção; nas 22(vinte e duas) posições subseqüentes, o município e a UF do Título de Eleitor.
                                        oCert.TituloEleitor      = strTexto.Substring(0, 12);
                                        oCert.ZonaEleitoral      = strTexto.Substring(12, 3);
                                        oCert.SecaoEleitoral     = strTexto.Substring(15, 4);
                                        oCert.MunicipioEleitoral = strTexto.Substring(19, 22);
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("Erro na leitura da OID=2.16.76.1.3.6:" + ex.Message, ex);
                                    }
                                }
                                else if (strOID == "2.16.76.1.4.2.1.1")
                                {
                                    try
                                    {
                                        oCert.OAB = strTexto;
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("Erro na leitura da OID=2.16.76.1.4.2.1.1:" + ex.Message, ex);
                                    }
                                }
                                else if (strOID == "2.16.76.1.3.4")    //PESSOA JURÍDICA
                                {
                                    try
                                    {
                                        oCert.Tipo = "J";
                                        //i· OID = 2.16.76.1.3.4 e conteúdo = nas primeiras 8(oito) posições, a data de nascimento do responsável pelo certificado, no formato ddmmaaaa; nas 11(onze) posições subseqüentes, o Cadastro de Pessoa Física(CPF) do responsável; nas 11(onze) posições subseqüentes, o Número de Identificação Social – NIS(PIS, PASEP ou CI); nas 15(quinze) posições subseqüentes, o número do Registro Geral(RG) do responsável; nas 10(dez) posições subseqüentes, as siglas do órgão expedidor do RG e respectiva Unidade da Federação;
                                        oCert.DataNascimento = strTexto.Substring(0, 8);
                                        oCert.CPF            = strTexto.Substring(8, 11);
                                        try
                                        {
                                            oCert.NIS            = strTexto.Substring(19, 11);
                                            oCert.RG             = strTexto.Substring(30, 15);
                                            oCert.OrgaoExpedidor = strTexto.Substring(45, 10);
                                        }
                                        catch (Exception ex)
                                        { }
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("Erro na leitura da OID=2.16.76.1.3.4:" + strTexto + "." + ex.Message, ex);
                                    }
                                }
                                else if (strOID == "2.16.76.1.3.2")    //PESSOA JURÍDICA
                                {
                                    //ii· OID = 2.16.76.1.3.2 e conteúdo = nome do responsável pelo certificado;
                                    try
                                    {
                                        oCert.NomeResponsavel = strTexto;
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("Erro na leitura da OID=2.16.76.1.3.2:" + ex.Message, ex);
                                    }
                                }
                                else if (strOID == "2.16.76.1.3.3")    //PESSOA JURÍDICA
                                {
                                    //iii· OID = 2.16.76.1.3.3 e conteúdo = nas 14(quatorze) posições o número do Cadastro Nacional de Pessoa Jurídica(CNPJ) da pessoa jurídica titular do certificado;
                                    try
                                    {
                                        oCert.CNPJ = strTexto;
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("Erro na leitura da OID=2.16.76.1.3.3:" + ex.Message, ex);
                                    }
                                }
                                else if (strOID == "2.16.76.1.3.7")    //PESSOA JURÍDICA
                                {
                                    //iv. OID = 2.16.76.1.3.7 e conteúdo = nas 12 (doze) posições o número do Cadastro Específico do INSS (CEI) da pessoa jurídica titular do certificado.
                                }

                                count = 0;
                            }
                            else
                            {
                                //i. rfc822Name contendo o endereço e-mail do titular do certificado.
                                if (derObject.GetType().Name == "DerOctetString")
                                {
                                    DerOctetString strOctet = (DerOctetString)derObject;
                                    byte[]         Texto    = strOctet.GetOctets();
                                    string         strTexto = System.Text.Encoding.ASCII.GetString(Texto);
                                    oCert.Email = strTexto;
                                }
                                else
                                {
                                    string texto = derObject.GetType().Name;
                                }
                            }
                        }
                        sm.Close();
                    }
                }
                oCert.Certificado = oCertificado;
                oLista.Add(oCert);
            }

            return(oLista);
        }
Esempio n. 31
0
 public LdsVersionInfo(string ldsVersion, string unicodeVersion)
 {
     this.ldsVersion     = new DerPrintableString(ldsVersion);
     this.unicodeVersion = new DerPrintableString(unicodeVersion);
 }
 protected bool CanBePrintable(string str) =>
 DerPrintableString.IsPrintableString(str);
Esempio n. 33
0
        /**
        * Constructor from Asn1Sequence.
        * <p/>
        * The sequence is of type ProcurationSyntax:
        * <p/>
        * <pre>
        *               ProcurationSyntax ::= SEQUENCE {
        *                 country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
        *                 typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
        *                 signingFor [3] EXPLICIT SigningFor
        *               }
        * <p/>
        *               SigningFor ::= CHOICE
        *               {
        *                 thirdPerson GeneralName,
        *                 certRef IssuerSerial
        *               }
        * </pre>
        *
        * @param seq The ASN.1 sequence.
        */
        private Procuration(
			Asn1Sequence seq)
        {
            if (seq.Count < 1 || seq.Count > 3)
                throw new ArgumentException("Bad sequence size: " + seq.Count);

            IEnumerator e = seq.GetEnumerator();

            while (e.MoveNext())
            {
                Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
                switch (o.TagNo)
                {
                    case 1:
                        country = DerPrintableString.GetInstance(o, true);
                        break;
                    case 2:
                        typeOfSubstitution = DirectoryString.GetInstance(o, true);
                        break;
                    case 3:
                        Asn1Object signingFor = o.GetObject();
                        if (signingFor is Asn1TaggedObject)
                        {
                            thirdPerson = GeneralName.GetInstance(signingFor);
                        }
                        else
                        {
                            certRef = IssuerSerial.GetInstance(signingFor);
                        }
                        break;
                    default:
                        throw new ArgumentException("Bad tag number: " + o.TagNo);
                }
            }
        }
Esempio n. 34
0
        /**
        * Constructor from given details.
        * <p/>
        * <code>professionItems</code> is mandatory, all other parameters are
        * optional.
        *
        * @param namingAuthority    The naming authority.
        * @param professionItems    Directory strings of the profession.
        * @param professionOids     DERObjectIdentfier objects for the
        *                           profession.
        * @param registrationNumber Registration number.
        * @param addProfessionInfo  Additional infos in encoded form.
        */
        public ProfessionInfo(
			NamingAuthority			namingAuthority,
			DirectoryString[]		professionItems,
			DerObjectIdentifier[]	professionOids,
			string					registrationNumber,
			Asn1OctetString			addProfessionInfo)
        {
            this.namingAuthority = namingAuthority;
            this.professionItems = new DerSequence(professionItems);
            this.professionOids = new DerSequence(professionOids);
            this.registrationNumber = new DerPrintableString(registrationNumber, true);
            this.addProfessionInfo = addProfessionInfo;
        }
Esempio n. 35
0
        /**
         * Constructor from Asn1Sequence.
         * <p/>
         * <p/>
         * <pre>
         *               ProfessionInfo ::= SEQUENCE
         *               {
         *                 namingAuthority [0] EXPLICIT NamingAuthority OPTIONAL,
         *                 professionItems SEQUENCE OF DirectoryString (SIZE(1..128)),
         *                 professionOids SEQUENCE OF OBJECT IDENTIFIER OPTIONAL,
         *                 registrationNumber PrintableString(SIZE(1..128)) OPTIONAL,
         *                 addProfessionInfo OCTET STRING OPTIONAL
         *               }
         * </pre>
         *
         * @param seq The ASN.1 sequence.
         */
        private ProfessionInfo(
            Asn1Sequence seq)
        {
            if (seq.Count > 5)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            Asn1Encodable o = (Asn1Encodable)e.Current;

            if (o is Asn1TaggedObject)
            {
                Asn1TaggedObject ato = (Asn1TaggedObject)o;
                if (ato.TagNo != 0)
                {
                    throw new ArgumentException("Bad tag number: " + ato.TagNo);
                }

                namingAuthority = NamingAuthority.GetInstance(ato, true);
                e.MoveNext();
                o = (Asn1Encodable)e.Current;
            }

            professionItems = Asn1Sequence.GetInstance(o);

            if (e.MoveNext())
            {
                o = (Asn1Encodable)e.Current;
                if (o is Asn1Sequence)
                {
                    professionOids = Asn1Sequence.GetInstance(o);
                }
                else if (o is DerPrintableString)
                {
                    registrationNumber = DerPrintableString.GetInstance(o).GetString();
                }
                else if (o is Asn1OctetString)
                {
                    addProfessionInfo = Asn1OctetString.GetInstance(o);
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(o));
                }
            }

            if (e.MoveNext())
            {
                o = (Asn1Encodable)e.Current;
                if (o is DerPrintableString)
                {
                    registrationNumber = DerPrintableString.GetInstance(o).GetString();
                }
                else if (o is DerOctetString)
                {
                    addProfessionInfo = (DerOctetString)o;
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(o));
                }
            }

            if (e.MoveNext())
            {
                o = (Asn1Encodable)e.Current;
                if (o is DerOctetString)
                {
                    addProfessionInfo = (DerOctetString)o;
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(o));
                }
            }
        }
Esempio n. 36
0
        /**
        * Constructor from Asn1Sequence.
        * <p/>
        * <p/>
        * <pre>
        *               ProfessionInfo ::= SEQUENCE
        *               {
        *                 namingAuthority [0] EXPLICIT NamingAuthority OPTIONAL,
        *                 professionItems SEQUENCE OF DirectoryString (SIZE(1..128)),
        *                 professionOids SEQUENCE OF OBJECT IDENTIFIER OPTIONAL,
        *                 registrationNumber PrintableString(SIZE(1..128)) OPTIONAL,
        *                 addProfessionInfo OCTET STRING OPTIONAL
        *               }
        * </pre>
        *
        * @param seq The ASN.1 sequence.
        */
        private ProfessionInfo(
			Asn1Sequence seq)
        {
            if (seq.Count > 5)
                throw new ArgumentException("Bad sequence size: " + seq.Count);

            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            Asn1Encodable o = (Asn1Encodable) e.Current;

            if (o is Asn1TaggedObject)
            {
                Asn1TaggedObject ato = (Asn1TaggedObject) o;
                if (ato.TagNo != 0)
                    throw new ArgumentException("Bad tag number: " + ato.TagNo);

                namingAuthority = NamingAuthority.GetInstance(ato, true);
                e.MoveNext();
                o = (Asn1Encodable) e.Current;
            }

            professionItems = Asn1Sequence.GetInstance(o);

            if (e.MoveNext())
            {
                o = (Asn1Encodable) e.Current;
                if (o is Asn1Sequence)
                {
                    professionOids = Asn1Sequence.GetInstance(o);
                }
                else if (o is DerPrintableString)
                {
                    registrationNumber = DerPrintableString.GetInstance(o);
                }
                else if (o is Asn1OctetString)
                {
                    addProfessionInfo = Asn1OctetString.GetInstance(o);
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
                }
            }

            if (e.MoveNext())
            {
                o = (Asn1Encodable) e.Current;
                if (o is DerPrintableString)
                {
                    registrationNumber = DerPrintableString.GetInstance(o);
                }
                else if (o is DerOctetString)
                {
                    addProfessionInfo = (DerOctetString) o;
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
                }
            }

            if (e.MoveNext())
            {
                o = (Asn1Encodable) e.Current;
                if (o is DerOctetString)
                {
                    addProfessionInfo = (DerOctetString) o;
                }
                else
                {
                    throw new ArgumentException("Bad object encountered: " + o.GetType().Name);
                }
            }
        }
Esempio n. 37
0
        private ProfessionInfo(Asn1Sequence seq)
        {
            //IL_0024: Unknown result type (might be due to invalid IL or missing references)
            //IL_0070: Unknown result type (might be due to invalid IL or missing references)
            //IL_010d: Unknown result type (might be due to invalid IL or missing references)
            //IL_0168: Unknown result type (might be due to invalid IL or missing references)
            //IL_01a7: Unknown result type (might be due to invalid IL or missing references)
            if (seq.Count > 5)
            {
                throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
            }
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            enumerator.MoveNext();
            Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.get_Current();

            if (asn1Encodable is Asn1TaggedObject)
            {
                Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)asn1Encodable;
                if (asn1TaggedObject.TagNo != 0)
                {
                    throw new ArgumentException(string.Concat((object)"Bad tag number: ", (object)asn1TaggedObject.TagNo));
                }
                namingAuthority = NamingAuthority.GetInstance(asn1TaggedObject, isExplicit: true);
                enumerator.MoveNext();
                asn1Encodable = (Asn1Encodable)enumerator.get_Current();
            }
            professionItems = Asn1Sequence.GetInstance(asn1Encodable);
            if (enumerator.MoveNext())
            {
                asn1Encodable = (Asn1Encodable)enumerator.get_Current();
                if (asn1Encodable is Asn1Sequence)
                {
                    professionOids = Asn1Sequence.GetInstance(asn1Encodable);
                }
                else if (asn1Encodable is DerPrintableString)
                {
                    registrationNumber = DerPrintableString.GetInstance(asn1Encodable).GetString();
                }
                else
                {
                    if (!(asn1Encodable is Asn1OctetString))
                    {
                        throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(asn1Encodable));
                    }
                    addProfessionInfo = Asn1OctetString.GetInstance(asn1Encodable);
                }
            }
            if (enumerator.MoveNext())
            {
                asn1Encodable = (Asn1Encodable)enumerator.get_Current();
                if (asn1Encodable is DerPrintableString)
                {
                    registrationNumber = DerPrintableString.GetInstance(asn1Encodable).GetString();
                }
                else
                {
                    if (!(asn1Encodable is DerOctetString))
                    {
                        throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(asn1Encodable));
                    }
                    addProfessionInfo = (DerOctetString)asn1Encodable;
                }
            }
            if (enumerator.MoveNext())
            {
                asn1Encodable = (Asn1Encodable)enumerator.get_Current();
                if (!(asn1Encodable is DerOctetString))
                {
                    throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(asn1Encodable));
                }
                addProfessionInfo = (DerOctetString)asn1Encodable;
            }
        }
 /**
  * return true if the passed in string can be represented without
  * loss as a PrintableString, false otherwise.
  */
 protected bool CanBePrintable(
     string str)
 {
     return(DerPrintableString.IsPrintableString(str));
 }
Esempio n. 39
0
		public LdsVersionInfo(string ldsVersion, string unicodeVersion)
		{
			this.ldsVersion = new DerPrintableString(ldsVersion);
			this.unicodeVersion = new DerPrintableString(unicodeVersion);
		}
Esempio n. 40
0
        /**
        * Constructor from Asn1Sequence.
        * <p/>
        * The sequence is of type NameOrPseudonym:
        * <p/>
        * <pre>
        *     PersonalData ::= SEQUENCE {
        *       nameOrPseudonym NameOrPseudonym,
        *       nameDistinguisher [0] INTEGER OPTIONAL,
        *       dateOfBirth [1] GeneralizedTime OPTIONAL,
        *       placeOfBirth [2] DirectoryString OPTIONAL,
        *       gender [3] PrintableString OPTIONAL,
        *       postalAddress [4] DirectoryString OPTIONAL
        *       }
        * </pre>
        *
        * @param seq The ASN.1 sequence.
        */
        private PersonalData(
			Asn1Sequence seq)
        {
            if (seq.Count < 1)
                throw new ArgumentException("Bad sequence size: " + seq.Count);

            IEnumerator e = seq.GetEnumerator();
            e.MoveNext();

            nameOrPseudonym = NameOrPseudonym.GetInstance(e.Current);

            while (e.MoveNext())
            {
                Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
                int tag = o.TagNo;
                switch (tag)
                {
                    case 0:
                        nameDistiguisher = DerInteger.GetInstance(o, false).Value;
                        break;
                    case 1:
                        dateOfBirth = DerGeneralizedTime.GetInstance(o, false);
                        break;
                    case 2:
                        placeOfBirth = DirectoryString.GetInstance(o, true);
                        break;
                    case 3:
                        gender = DerPrintableString.GetInstance(o, false);
                        break;
                    case 4:
                        postalAddress = DirectoryString.GetInstance(o, true);
                        break;
                    default:
                        throw new ArgumentException("Bad tag number: " + o.TagNo);
                }
            }
        }
Esempio n. 41
0
 public CertDigestObj(DerPrintableString type, Asn1OctetString value)
 {
     Type  = type;
     Value = value;
 }