Exemplo n.º 1
0
        public XmlSignatureModel(XmlSignature signature, IXmlPolicyMapperBySignature policyMapper = null)
        {
            Type        = signature.SignedEntityType;
            SigningTime = signature.SigningTime;
            if (signature.SignedElement != null)
            {
                SignedElement = new XmlElementModel(signature.SignedElement);
            }
            if (signature.SignatureAlgorithm != null && signature.SignatureValue != null)
            {
                Signature = new SignatureAlgorithmAndValueModel(signature.SignatureAlgorithm, signature.SignatureValue);
            }
            if (signature.PolicyIdentifier != null)
            {
                SignaturePolicy = new SignaturePolicyIdentifierModel(signature.PolicyIdentifier);
            }
            if (signature.SigningCertificate != null)
            {
                Certificate = new CertificateModel(signature.SigningCertificate);
            }
            if (signature.SignatureTimestamps.Any())
            {
                CertifiedDateReference = signature.SignatureTimestamps.First().EncapsulatedTimestamp.GenTime;
                Timestamps             = signature.SignatureTimestamps.Select(ts => new CadesTimestampModel(ts.EncapsulatedTimestamp)).ToList();
            }

            // Validate signature according to the provided policy.
            if (policyMapper != null)
            {
                var vr = signature.Validate(policyMapper);
                ValidationResults = new ValidationResultsModel(vr);
            }
        }
Exemplo n.º 2
0
        public CadesSignerModel(CadesSignerInfo signer)
        {
            SigningTime = signer.SigningTime;
            if (signer.DigestAlgorithm != null && signer.MessageDigest != null)
            {
                MessageDigest = new DigestAlgorithmAndValueModel(signer.DigestAlgorithm, signer.MessageDigest);
            }
            if (signer.SignatureAlgorithm != null && signer.SignatureValue != null)
            {
                Signature = new SignatureAlgorithmAndValueModel(signer.SignatureAlgorithm, signer.SignatureValue);
            }
            if (signer.SignaturePolicy != null && !signer.SignaturePolicy.IsImplicit)
            {
                SignaturePolicy = new SignaturePolicyIdentifierModel(signer.SignaturePolicy);
            }
            if (signer.SigningCertificate != null)
            {
                Certificate = new CertificateModel(signer.SigningCertificate);
            }
            if (signer.SignatureTimeStamps.Any())
            {
                Timestamps = signer.SignatureTimeStamps.Select(s => new CadesTimestampModel(s)).ToList();
            }

            // Get date reference
            try {
                bool isCertified;
                var  dateReference = signer.GetDateReference(out isCertified);
                if (isCertified)
                {
                    CertifiedDateReference = dateReference;
                }
            } catch {
                // do nothing
            }
        }