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); } }
public CertificateModel(PKCertificate cert) : base(cert) { IssuerDisplayName = cert.IssuerDisplayName; SerialNumber = cert.SerialNumber.ToString(); EmailAddress = cert.EmailAddress; ValidityStart = cert.ValidityStart; ValidityEnd = cert.ValidityEnd; BinaryThumbprintSHA256 = cert.ThumbprintSHA256; BinaryThumbprintSHA1 = cert.ThumbprintSHA1; if (cert.SubjectName != null) { SubjectName = new NameModel(cert.SubjectName); } if (cert.IssuerName != null) { IssuerName = new NameModel(cert.IssuerName); } if (cert.PkiBrazil != null) { PkiBrazil = new PkiBrazilCertificateModel(cert.PkiBrazil); } if (!cert.IsSelfSigned) { Issuer = new CertificateModel(cert.Issuer); } }
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 } }