List of usage examples for org.bouncycastle.cms CMSSignedData replaceCertificatesAndCRLs
public static CMSSignedData replaceCertificatesAndCRLs(CMSSignedData signedData, Store certificates, Store attrCerts, Store revocations) throws CMSException
From source file:br.gov.jfrj.siga.cd.AssinaturaDigital.java
License:Open Source License
@SuppressWarnings("static-access") protected static byte[] converterPkcs7EmCMSComCertificadosECRLs(final byte[] assinatura) throws Exception { CMSSignedData cmssd = new CMSSignedData(assinatura); Store certs = cmssd.getCertificates(); Store certsAndCrls = buscarCrlParaCadaCertificado(certs); CMSSignedData cmssdcrl = cmssd.replaceCertificatesAndCRLs(cmssd, certsAndCrls, certsAndCrls, certsAndCrls); return cmssdcrl.getEncoded(); }
From source file:br.gov.jfrj.siga.cd.TimeStamper.java
License:Open Source License
/** * Modyfy PKCS#7 data by adding timestamp * /*from www . ja v a 2 s. c o m*/ * (at) param signedData (at) throws Exception */ public static CMSSignedData addTimestamp(CMSSignedData signedData) throws Exception { Collection ss = signedData.getSignerInfos().getSigners(); SignerInformation si = (SignerInformation) ss.iterator().next(); TimeStampToken tok = getTimeStampToken(si.getSignature()); // CertStore certs = tok.getCertificatesAndCRLs("Collection", "BC"); Store certs = tok.getCertificates(); Store certsAndCrls = AssinaturaDigital.buscarCrlParaCadaCertificado(certs); CMSSignedData cmssdcrl = CMSSignedData.replaceCertificatesAndCRLs(tok.toCMSSignedData(), certsAndCrls, certsAndCrls, certsAndCrls); tok = new TimeStampToken(cmssdcrl); ASN1InputStream asn1InputStream = new ASN1InputStream(tok.getEncoded()); ASN1Primitive tstDER = asn1InputStream.readObject(); DERSet ds = new DERSet(tstDER); Attribute a = new Attribute(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, ds); ASN1EncodableVector dv = new ASN1EncodableVector(); dv.add(a); AttributeTable at = new AttributeTable(dv); si = SignerInformation.replaceUnsignedAttributes(si, at); ss.clear(); ss.add(si); SignerInformationStore sis = new SignerInformationStore(ss); signedData = CMSSignedData.replaceSigners(signedData, sis); return signedData; }
From source file:ee.ria.xroad.proxy.messagelog.TimestamperUtil.java
License:Open Source License
@SuppressWarnings("unchecked") static TimeStampToken addSignerCertificate(TimeStampResponse tsResponse, X509Certificate signerCertificate) throws Exception { CMSSignedData cms = tsResponse.getTimeStampToken().toCMSSignedData(); List<X509Certificate> collection = new ArrayList<>(); collection.add(signerCertificate);/*from w w w. j av a2 s . c o m*/ collection.addAll(cms.getCertificates().getMatches(null)); return new TimeStampToken(CMSSignedData.replaceCertificatesAndCRLs(cms, new JcaCertStore(collection), cms.getAttributeCertificates(), cms.getCRLs())); }