Esempio n. 1
0
        static DateTime GetSigningTime(Asn1Encodable encodable)
        {
            // Special attention to the conversion from Der*Time to .Net's DateTime
            // (May lost timezone information)

            // Try to parse as UTC time
            try
            {
                DerUtcTime timeUtc = (DerUtcTime)DerUtcTime.GetInstance(encodable);
                return(timeUtc.ToAdjustedDateTime());
            }
            catch (Exception e)
            {
            }

            // Try to parse as GeneralizedTime
            try
            {
                DerGeneralizedTime timeGenTime = (DerGeneralizedTime)DerGeneralizedTime.GetInstance(encodable);
                return(timeGenTime.ToDateTime());
            }
            catch (Exception e)
            {
            }

            return(DateTime.Now);
        }
Esempio n. 2
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());
        }
Esempio n. 3
0
 private CrlIdentifier(Asn1Sequence seq)
 {
     if (seq == null)
     {
         throw new ArgumentNullException("seq");
     }
     if (seq.Count < 2 || seq.Count > 3)
     {
         throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
     }
     this.crlIssuer     = X509Name.GetInstance(seq[0]);
     this.crlIssuedTime = DerUtcTime.GetInstance(seq[1]);
     if (seq.Count > 2)
     {
         this.crlNumber = DerInteger.GetInstance(seq[2]);
     }
 }
Esempio n. 4
0
 private CrlIdentifier(Asn1Sequence seq)
 {
     //IL_000e: Unknown result type (might be due to invalid IL or missing references)
     //IL_0040: Unknown result type (might be due to invalid IL or missing references)
     if (seq == null)
     {
         throw new ArgumentNullException("seq");
     }
     if (seq.Count < 2 || seq.Count > 3)
     {
         throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count), "seq");
     }
     crlIssuer     = X509Name.GetInstance(seq[0]);
     crlIssuedTime = DerUtcTime.GetInstance(seq[1]);
     if (seq.Count > 2)
     {
         crlNumber = DerInteger.GetInstance(seq[2]);
     }
 }
Esempio n. 5
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;
                    }
                }
            }
        }