private void VerifySignatures(CmsSignedData s, byte[] contentDigest) { IX509Store x509Certs = s.GetCertificates("Collection"); IX509Store x509Crls = s.GetCrls("Collection"); SignerInformationStore signers = s.GetSignerInfos(); foreach (SignerInformation signer in signers.GetSigners()) { ICollection certCollection = x509Certs.GetMatches(signer.SignerID); IEnumerator certEnum = certCollection.GetEnumerator(); certEnum.MoveNext(); X509Certificate cert = (X509Certificate)certEnum.Current; VerifySigner(signer, cert); if (contentDigest != null) { Assert.IsTrue(Arrays.AreEqual(contentDigest, signer.GetContentDigest())); } } ICollection certColl = x509Certs.GetMatches(null); ICollection crlColl = x509Crls.GetMatches(null); Assert.AreEqual(certColl.Count, s.GetCertificates("Collection").GetMatches(null).Count); Assert.AreEqual(crlColl.Count, s.GetCrls("Collection").GetMatches(null).Count); }
public override IList <X509Crl> GetCRLsFromSignature() { IList <X509Crl> list = new List <X509Crl>(); // Add certificates contained in SignedData foreach (X509Crl crl in cmsSignedData.GetCrls ("Collection").GetMatches(null)) { list.Add(crl); } // Add certificates in CAdES-XL certificate-values inside SignerInfo attribute if present SignerInformation si = BCStaticHelpers.GetSigner(cmsSignedData, signerId); if (si != null && si.UnsignedAttributes != null && si.UnsignedAttributes[PkcsObjectIdentifiers.IdAAEtsRevocationValues] != null) { RevocationValues revValues = RevocationValues.GetInstance(si.UnsignedAttributes[PkcsObjectIdentifiers.IdAAEtsRevocationValues].AttrValues[0]); foreach (CertificateList crlObj in revValues.GetCrlVals()) { X509Crl crl = new X509Crl(crlObj); list.Add(crl); } } return(list); }
public override IList <X509Crl> GetCRLsFromSignature() { IList <X509Crl> list = new AList <X509Crl>(); try { // Add certificates contained in SignedData foreach (X509Crl crl in cmsSignedData.GetCrls ("Collection").GetMatches(null)) { list.AddItem(crl); } // Add certificates in CAdES-XL certificate-values inside SignerInfo attribute if present SignerInformation si = cmsSignedData.GetSignerInfos().GetFirstSigner(signerId); if (si != null && si.UnsignedAttributes != null && si.UnsignedAttributes[PkcsObjectIdentifiers.IdAAEtsRevocationValues] != null) { RevocationValues revValues = RevocationValues.GetInstance(si.UnsignedAttributes[PkcsObjectIdentifiers.IdAAEtsRevocationValues].AttrValues[0]); foreach (CertificateList crlObj in revValues.GetCrlVals()) { X509Crl crl = new X509Crl(crlObj); list.AddItem(crl); } } } /*catch (StoreException e) * { * throw new RuntimeException(e); * }*/ catch (CrlException e) { throw new RuntimeException(e); } return(list); }
public IX509Store GetCrls(string type) { return(tsToken.GetCrls(type)); }
private void VerifySignatures(CmsSignedData s, byte[] contentDigest) { IX509Store x509Certs = s.GetCertificates("Collection"); IX509Store x509Crls = s.GetCrls("Collection"); SignerInformationStore signers = s.GetSignerInfos(); foreach (SignerInformation signer in signers.GetSigners()) { ICollection certCollection = x509Certs.GetMatches(signer.SignerID); IEnumerator certEnum = certCollection.GetEnumerator(); certEnum.MoveNext(); X509Certificate cert = (X509Certificate) certEnum.Current; VerifySigner(signer, cert); if (contentDigest != null) { Assert.IsTrue(Arrays.AreEqual(contentDigest, signer.GetContentDigest())); } } ICollection certColl = x509Certs.GetMatches(null); ICollection crlColl = x509Crls.GetMatches(null); Assert.AreEqual(certColl.Count, s.GetCertificates("Collection").GetMatches(null).Count); Assert.AreEqual(crlColl.Count, s.GetCrls("Collection").GetMatches(null).Count); }
/// <summary> /// Adds or removes Content to P7mFile /// </summary> /// <param name="CmsData">Signature Info</param> /// <param name="File">File, if null returns only Signature Info</param> /// <returns></returns> public static byte[] EmbedFileToPkcs(byte[] CmsData, byte[] File) { DerObjectIdentifier contentTypeOID = CmsObjectIdentifiers.Data; Asn1EncodableVector digestAlgs = new Asn1EncodableVector(); Asn1EncodableVector signerInfos = new Asn1EncodableVector(); Asn1OctetString octs = null; if (File != null) { octs = new DerOctetString(File); } Org.BouncyCastle.Asn1.Cms.ContentInfo encInfo = new Org.BouncyCastle.Asn1.Cms.ContentInfo(contentTypeOID, octs); CmsProcessable content = new CmsProcessableByteArray(CmsData); Asn1Set certificates = null; Asn1Set certrevlist = null; ArrayList _certs = new ArrayList(); ArrayList _crls = new ArrayList(); ICollection certsColl = new ArrayList(); ICollection crlsColl = new ArrayList(); CmsSignedData cms = new CmsSignedData(CmsData); SignerInformationStore signers = cms.GetSignerInfos(); IX509Store store = cms.GetCertificates("Collection"); IX509Store crls = cms.GetCrls("Collection"); certsColl = store.GetMatches(null); crlsColl = crls.GetMatches(null); foreach (SignerInformation signer in signers.GetSigners()) { //digestAlgs.Add(Helper.FixAlgID(signer.DigestAlgorithmID)); digestAlgs.Add(signer.DigestAlgorithmID); signerInfos.Add(signer.ToSignerInfo()); } foreach (Org.BouncyCastle.X509.X509Certificate cert in certsColl) { _certs.Add(Asn1Object.FromByteArray(cert.GetEncoded())); } foreach (Org.BouncyCastle.X509.X509Certificate clr in crlsColl) { _crls.Add(Asn1Object.FromByteArray(clr.GetEncoded())); } if (_certs.Count != 0) { certificates = CreateBerSetFromList(_certs); } if (_crls.Count != 0) { certrevlist = CreateBerSetFromList(_crls); } SignedData sd = new SignedData( new DerSet(digestAlgs), encInfo, certificates, certrevlist, new DerSet(signerInfos)); Org.BouncyCastle.Asn1.Cms.ContentInfo contentInfo = new Org.BouncyCastle.Asn1.Cms.ContentInfo(CmsObjectIdentifiers.SignedData, sd); byte[] retval = new CmsSignedData(content, contentInfo.GetDerEncoded()).GetEncoded(); string asn = BitConverter.ToString(retval).Replace("-", ""); return(retval); }