Beispiel #1
0
        public SignerLocation(
            DerUtf8String countryName,
            DerUtf8String localityName,
            Asn1Sequence postalAddress)
        {
            if (postalAddress != null && postalAddress.Count > 6)
            {
                throw new ArgumentException("postal address must contain less than 6 strings");
            }

            if (countryName != null)
            {
                this.countryName = DerUtf8String.GetInstance(countryName.ToAsn1Object());
            }

            if (localityName != null)
            {
                this.localityName = DerUtf8String.GetInstance(localityName.ToAsn1Object());
            }

            if (postalAddress != null)
            {
                this.postalAddress = (Asn1Sequence)postalAddress.ToAsn1Object();
            }
        }
Beispiel #2
0
        public SignerLocation(
            Asn1Sequence seq)
        {
            foreach (DerTaggedObject o in seq)
            {
                switch (o.TagNo)
                {
                case 0:
                    this.countryName = DerUtf8String.GetInstance(o, true);
                    break;

                case 1:
                    this.localityName = DerUtf8String.GetInstance(o, true);
                    break;

                case 2:
                    this.postalAddress = Asn1Sequence.GetInstance(o, true);
                    if (postalAddress != null && postalAddress.Count > 6)
                    {
                        throw new ArgumentException("postal address must contain less than 6 strings");
                    }
                    break;

                default:
                    throw new ArgumentException("illegal tag");
                }
            }
        }
Beispiel #3
0
        public SignerLocation(
            Asn1Sequence seq)
        {
            foreach (Asn1TaggedObject obj in seq)
            {
                switch (obj.TagNo)
                {
                case 0:
                    this.countryName = DerUtf8String.GetInstance(obj, true);
                    break;

                case 1:
                    this.localityName = DerUtf8String.GetInstance(obj, true);
                    break;

                case 2:
                    bool isExplicit = obj.IsExplicit();                                 // handle erroneous implicitly tagged sequences
                    this.postalAddress = Asn1Sequence.GetInstance(obj, isExplicit);
                    if (postalAddress != null && postalAddress.Count > 6)
                    {
                        throw new ArgumentException("postal address must contain less than 6 strings");
                    }
                    break;

                default:
                    throw new ArgumentException("illegal tag");
                }
            }
        }
Beispiel #4
0
    public SignerLocation(Asn1Sequence seq)
    {
        foreach (Asn1TaggedObject item in seq)
        {
            switch (item.TagNo)
            {
            case 0:
                countryName = DerUtf8String.GetInstance(item, isExplicit: true);
                break;

            case 1:
                localityName = DerUtf8String.GetInstance(item, isExplicit: true);
                break;

            case 2:
            {
                bool explicitly = item.IsExplicit();
                postalAddress = Asn1Sequence.GetInstance(item, explicitly);
                if (postalAddress != null && postalAddress.Count > 6)
                {
                    throw new ArgumentException("postal address must contain less than 6 strings");
                }
                break;
            }

            default:
                throw new ArgumentException("illegal tag");
            }
        }
    }
Beispiel #5
0
        public EsPropertyInfo(Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            Type       = DerInteger.GetInstance(e.Next());
            Name       = DerUtf8String.GetInstance(e.Next());
            CertList   = Asn1Sequence.GetInstance(e.Next());
            CreateDate = DerUtcTime.GetInstance(e.Next());
            ValidStart = DerUtcTime.GetInstance(e.Next());
            ValidEnd   = DerUtcTime.GetInstance(e.Next());
        }
        private ContentHints(Asn1Sequence seq)
        {
            IAsn1Convertible asn1Convertible = seq[0];

            if (asn1Convertible.ToAsn1Object() is DerUtf8String)
            {
                this.contentDescription = DerUtf8String.GetInstance(asn1Convertible);
                this.contentType        = DerObjectIdentifier.GetInstance(seq[1]);
                return;
            }
            this.contentType = DerObjectIdentifier.GetInstance(seq[0]);
        }
Beispiel #7
0
        public SesPropertyInfo(Asn1Sequence sequence)
        {
            IEnumerator e = sequence.GetEnumerator();

            Type         = DerInteger.GetInstance(e.Next());
            Name         = DerUtf8String.GetInstance(e.Next());
            CertListType = DerInteger.GetInstance(e.Next());
            CertList     = SesCertCollect.GetInstance(CertListType, e.Next());
            CreateDate   = DerGeneralizedTime.GetInstance(e.Next());
            ValidStart   = DerGeneralizedTime.GetInstance(e.Next());
            ValidEnd     = DerGeneralizedTime.GetInstance(e.Next());
        }
Beispiel #8
0
        /**
         * constructor
         */
        private ContentHints(
            Asn1Sequence seq)
        {
            IAsn1Convertible field = seq[0];

            if (field.ToAsn1Object() is DerUtf8String)
            {
                contentDescription = DerUtf8String.GetInstance(field);
                contentType        = DerObjectIdentifier.GetInstance(seq[1]);
            }
            else
            {
                contentType = DerObjectIdentifier.GetInstance(seq[0]);
            }
        }
        public SignerLocation(Asn1Sequence seq)
        {
            //IL_0086: Unknown result type (might be due to invalid IL or missing references)
            //IL_0091: 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:
                        countryName = DerUtf8String.GetInstance(asn1TaggedObject, isExplicit: true);
                        break;

                    case 1:
                        localityName = DerUtf8String.GetInstance(asn1TaggedObject, isExplicit: true);
                        break;

                    case 2:
                    {
                        bool explicitly = asn1TaggedObject.IsExplicit();
                        postalAddress = Asn1Sequence.GetInstance(asn1TaggedObject, explicitly);
                        if (postalAddress != null && postalAddress.Count > 6)
                        {
                            throw new ArgumentException("postal address must contain less than 6 strings");
                        }
                        break;
                    }

                    default:
                        throw new ArgumentException("illegal tag");
                    }
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Beispiel #10
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++]);
            }
        }
Beispiel #11
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++]);
            }
        }
 public SignerLocation(DerUtf8String countryName, DerUtf8String localityName, Asn1Sequence postalAddress)
 {
     //IL_0017: Unknown result type (might be due to invalid IL or missing references)
     if (postalAddress != null && postalAddress.Count > 6)
     {
         throw new ArgumentException("postal address must contain less than 6 strings");
     }
     if (countryName != null)
     {
         this.countryName = DerUtf8String.GetInstance(countryName.ToAsn1Object());
     }
     if (localityName != null)
     {
         this.localityName = DerUtf8String.GetInstance(localityName.ToAsn1Object());
     }
     if (postalAddress != null)
     {
         this.postalAddress = (Asn1Sequence)postalAddress.ToAsn1Object();
     }
 }
        internal CertificateTrustBlock(byte[] encoded)
        {
            Asn1Sequence seq = Asn1Sequence.GetInstance(encoded);

            for (IEnumerator en = seq.GetEnumerator(); en.MoveNext();)
            {
                Asn1Encodable obj = (Asn1Encodable)en.Current;

                if (obj is Asn1Sequence)
                {
                    this.uses = Asn1Sequence.GetInstance(obj);
                }
                else if (obj is Asn1TaggedObject)
                {
                    this.prohibitions = Asn1Sequence.GetInstance((Asn1TaggedObject)obj, false);
                }
                else if (obj is DerUtf8String)
                {
                    this.alias = DerUtf8String.GetInstance(obj).GetString();
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// Return a control value of the specified type.
        /// </summary>
        /// <param name="type">the type OID for the control value we are checking for.</param>
        /// <returns>the control value if present, null otherwise.</returns>
        public IControl GetControl(DerObjectIdentifier type)
        {
            AttributeTypeAndValue found = FindControl(type);

            if (found != null)
            {
                if (found.Type.Equals(CrmfObjectIdentifiers.id_regCtrl_pkiArchiveOptions))
                {
                    return(new PkiArchiveControl(PkiArchiveOptions.GetInstance(found.Value)));
                }

                if (found.Type.Equals(CrmfObjectIdentifiers.id_regCtrl_regToken))
                {
                    return(new RegTokenControl(DerUtf8String.GetInstance(found.Value)));
                }

                if (found.Type.Equals(CrmfObjectIdentifiers.id_regCtrl_authenticator))
                {
                    return(new AuthenticatorControl(DerUtf8String.GetInstance(found.Value)));
                }
            }
            return(null);
        }
Beispiel #15
0
        private void ReadInformation()
        {
            if (_signerInformation.SignedAttributes[PkcsObjectIdentifiers.Pkcs9AtSigningTime] != null)
            {
                _signingDate = DerUtcTime.GetInstance(_signerInformation.SignedAttributes[PkcsObjectIdentifiers.Pkcs9AtSigningTime].AttrValues[0]).ToDateTime().ToLocalTime();
            }

            if (_signerInformation.SignedAttributes[PkcsObjectIdentifiers.IdAAEtsSignerAttr] != null)
            {
                var signerAttr = SignerAttribute.GetInstance(_signerInformation.SignedAttributes[PkcsObjectIdentifiers.IdAAEtsSignerAttr].AttrValues[0]);

                List <string> claimedRoles = new List <string>();

                foreach (BcCms.Attribute claimedAttr in signerAttr.ClaimedAttributes)
                {
                    foreach (var value in claimedAttr.AttrValues)
                    {
                        claimedRoles.Add(DerUtf8String.GetInstance(value).GetString());
                    }
                }

                _signerRoles = claimedRoles;
            }

            if (_signerInformation.UnsignedAttributes != null &&
                _signerInformation.UnsignedAttributes[PkcsObjectIdentifiers.IdAASignatureTimeStampToken] != null)
            {
                _timeStamp = new TimeStampToken(new CmsSignedData(_signerInformation.UnsignedAttributes[PkcsObjectIdentifiers.IdAASignatureTimeStampToken].AttrValues[0].GetEncoded()));
            }

            // Se leen las contrafirmas
            var signers = _signerInformation.GetCounterSignatures().GetSigners();

            _counterSignatures = new List <SignerInfoNode>();

            foreach (var signer in signers)
            {
                SignerInfoNode node = new SignerInfoNode((SignerInformation)signer, _sigDocument);

                _counterSignatures.Add(node);
            }

            // Se intenta identificar el certificado empleado para la firma, esto quizás se pueda mejorar
            byte[]       certHash     = null;
            IssuerSerial issuerSerial = null;

            if (_signerInformation.DigestAlgOid == DigestMethod.SHA1.Oid)
            {
                BcCms.Attribute    attr = _signerInformation.SignedAttributes[PkcsObjectIdentifiers.IdAASigningCertificate];
                SigningCertificate sc   = SigningCertificate.GetInstance(attr.AttrValues[0]);
                EssCertID          ecid = sc.GetCerts()[0];
                issuerSerial = ecid.IssuerSerial;
                certHash     = ecid.GetCertHash();
            }
            else
            {
                BcCms.Attribute      attr = _signerInformation.SignedAttributes[PkcsObjectIdentifiers.IdAASigningCertificateV2];
                SigningCertificateV2 sc2  = SigningCertificateV2.GetInstance(attr.AttrValues[0]);
                EssCertIDv2          ecid = sc2.GetCerts()[0];
                issuerSerial = ecid.IssuerSerial;
                certHash     = ecid.GetCertHash();
            }

            DigestMethod digestMethod = DigestMethod.GetByOid(_signerInformation.DigestAlgOid);

            foreach (X509CertificateStructure cs in _sigDocument.Certificates)
            {
                if (issuerSerial == null || cs.TbsCertificate.SerialNumber.Equals(issuerSerial.Serial))
                {
                    byte[] currentCertHash = digestMethod.CalculateDigest(cs.GetEncoded());

                    if (certHash.SequenceEqual(currentCertHash))
                    {
                        _certificate = new X509Certificate(cs);
                        break;
                    }
                }
            }
        }