List of usage examples for org.bouncycastle.cms CMSAttributeTableGenerator CONTENT_TYPE
String CONTENT_TYPE
To view the source code for org.bouncycastle.cms CMSAttributeTableGenerator CONTENT_TYPE.
Click Source Link
From source file:eu.europa.ec.markt.dss.signature.pades.PAdESLevelBaselineB.java
License:Open Source License
AttributeTable getSignedAttributes(Map params, CAdESLevelBaselineB cadesProfile, SignatureParameters parameters, byte[] messageDigest) { AttributeTable signedAttributes = cadesProfile.getSignedAttributes(parameters); if (signedAttributes.get(CMSAttributes.contentType) == null) { ASN1ObjectIdentifier contentType = (ASN1ObjectIdentifier) params .get(CMSAttributeTableGenerator.CONTENT_TYPE); // contentType will be null if we're trying to generate a counter signature. if (contentType != null) { signedAttributes = signedAttributes.add(CMSAttributes.contentType, contentType); }// w w w .j av a 2s.c om } if (signedAttributes.get(CMSAttributes.messageDigest) == null) { // byte[] messageDigest = (byte[]) params.get(CMSAttributeTableGenerator.DIGEST); signedAttributes = signedAttributes.add(CMSAttributes.messageDigest, new DEROctetString(messageDigest)); } return signedAttributes; }
From source file:eu.europa.ec.markt.dss.signature.pades.PAdESProfileEPES.java
License:Open Source License
CMSSignedDataGenerator createCMSSignedDataGenerator(ContentSigner contentSigner, DigestCalculatorProvider digestCalculatorProvider, final SignatureParameters parameters, final byte[] messageDigest) throws IOException { try {/*from w w w . j av a2 s. com*/ CMSSignedDataGenerator generator = new CMSSignedDataGenerator(); X509Certificate signerCertificate = parameters.getSigningCertificate(); X509CertificateHolder certHolder = new X509CertificateHolder(signerCertificate.getEncoded()); SignerInfoGeneratorBuilder sigenb = new SignerInfoGeneratorBuilder(digestCalculatorProvider); final CAdESProfileEPES profile = new CAdESProfileEPES(true); sigenb = sigenb.setSignedAttributeGenerator(new CMSAttributeTableGenerator() { @Override public AttributeTable getAttributes(Map params) throws CMSAttributeTableGenerationException { Hashtable clone = (Hashtable) profile.getSignedAttributes(parameters).clone(); if (!clone.containsKey(CMSAttributes.contentType)) { DERObjectIdentifier contentType = (DERObjectIdentifier) params .get(CMSAttributeTableGenerator.CONTENT_TYPE); // contentType will be null if we're trying to generate a counter signature. if (contentType != null) { Attribute attr = new Attribute(CMSAttributes.contentType, new DERSet(contentType)); clone.put(attr.getAttrType(), attr); } } if (!clone.containsKey(CMSAttributes.messageDigest)) { System.out.println("Digest propos : " + org.apache.commons.codec.binary.Hex.encodeHexString(messageDigest)); // byte[] messageDigest = (byte[]) params.get(CMSAttributeTableGenerator.DIGEST); Attribute attr = new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(messageDigest))); clone.put(attr.getAttrType(), attr); } if (parameters.getCommitmentTypeIndication() != null && !parameters.getCommitmentTypeIndication().isEmpty()) { ASN1EncodableVector vector = new ASN1EncodableVector(); for (String id : parameters.getCommitmentTypeIndication()) { vector.add(new DERObjectIdentifier(id)); } DERSet set = new DERSet(new DERSequence(vector)); Attribute attr = new Attribute(new DERObjectIdentifier("1.2.840.113549.1.9.16.2.16"), set); clone.put(attr.getAttrType(), attr); } return new AttributeTable(clone); } }); // sigenb.setUnsignedAttributeGenerator(new SimpleAttributeTableGenerator(new AttributeTable( // new Hashtable<ASN1ObjectIdentifier, ASN1Encodable>()))); /* * We don't include a unsigned attribute table if not needed : a unsignedAttrs of signerInfo includes no * Attribute, UnsignedAttributes ::= SET SIZE (1..MAX) OF Attribute(defined in RFC3852). */ SignerInfoGenerator sigen = sigenb.build(contentSigner, certHolder); generator.addSignerInfoGenerator(sigen); Collection<X509Certificate> certs = new ArrayList<X509Certificate>(); if (parameters.getCertificateChain() == null || !parameters.getCertificateChain().contains(parameters.getSigningCertificate())) { certs.add(parameters.getSigningCertificate()); } certs.addAll(parameters.getCertificateChain()); JcaCertStore certStore = new JcaCertStore(certs); generator.addCertificates(certStore); System.out.println("Gnrator cr"); return generator; } catch (CertificateException e) { throw new IOException(e); } catch (OperatorCreationException e) { throw new IOException(e); } catch (CMSException e) { throw new IOException(e); } }
From source file:eu.europa.esig.dss.pades.signature.PAdESLevelBaselineB.java
License:Open Source License
AttributeTable getSignedAttributes(Map params, CAdESLevelBaselineB cadesProfile, PAdESSignatureParameters parameters, byte[] messageDigest) { AttributeTable signedAttributes = cadesProfile.getSignedAttributes(parameters); if (signedAttributes.get(CMSAttributes.contentType) == null) { ASN1ObjectIdentifier contentType = (ASN1ObjectIdentifier) params .get(CMSAttributeTableGenerator.CONTENT_TYPE); // contentType will be null if we're trying to generate a counter signature. if (contentType != null) { signedAttributes = signedAttributes.add(CMSAttributes.contentType, contentType); }/*from w w w .j a v a2s .co m*/ } if (signedAttributes.get(CMSAttributes.messageDigest) == null) { signedAttributes = signedAttributes.add(CMSAttributes.messageDigest, new DEROctetString(messageDigest)); } return signedAttributes; }
From source file:org.demoiselle.signer.policy.impl.cades.pkcs7.impl.DemoiselleSignedAttributeTableGenerator.java
License:Open Source License
/** * Create a standard attribute table from the passed in parameters - this will * normally include contentType, signingTime, and messageDigest. If the constructor * using an AttributeTable was used, entries in it for contentType, signingTime, and * messageDigest will override the generated ones. * * @param parameters source parameters for table generation. * * @return a filled in Hashtable of attributes. *///ww w. j a va2 s. c o m protected Hashtable createStandardAttributeTable(Map parameters) { Hashtable std = copyHashTable(table); if (!std.containsKey(CMSAttributes.contentType)) { ASN1ObjectIdentifier contentType = ASN1ObjectIdentifier .getInstance(parameters.get(CMSAttributeTableGenerator.CONTENT_TYPE)); // contentType will be null if we're trying to generate a counter signature. if (contentType != null) { Attribute attr = new Attribute(CMSAttributes.contentType, new DERSet(contentType)); std.put(attr.getAttrType(), attr); } } if (!std.containsKey(CMSAttributes.messageDigest)) { byte[] messageDigest = (byte[]) parameters.get(CMSAttributeTableGenerator.DIGEST); Attribute attr = new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(messageDigest))); std.put(attr.getAttrType(), attr); } return std; }