/** * We are extending CMS Signature * * @param signer * information about signer * @return information about SignerInformation */ private SignerInformation signTimeStamp(SignerInformation signer) throws IOException, TSPException { AttributeTable unsignedAttributes = signer.getUnsignedAttributes(); ASN1EncodableVector vector = new ASN1EncodableVector(); if (unsignedAttributes != null) { vector = unsignedAttributes.toASN1EncodableVector(); } byte[] token = tsaClient.getTimeStampToken(signer.getSignature()); ASN1ObjectIdentifier oid = PKCSObjectIdentifiers.id_aa_signatureTimeStampToken; ASN1Encodable signatureTimeStamp = new Attribute(oid, new DERSet(ASN1Primitive.fromByteArray(token))); vector.add(signatureTimeStamp); Attributes signedAttributes = new Attributes(vector); SignerInformation newSigner = SignerInformation.replaceUnsignedAttributes(signer, new AttributeTable(signedAttributes)); return newSigner; }
/** * Set the MetaData for the generated message. * * @param hashProtected true if the MetaData should be included in first imprint calculation, false otherwise. * @param fileName optional file name, may be null. * @param mediaType optional media type, may be null. * @param attributes optional attributes, may be null. */ public void setMetaData(boolean hashProtected, String fileName, String mediaType, Attributes attributes) { DERUTF8String asn1FileName = null; if (fileName != null) { asn1FileName = new DERUTF8String(fileName); } DERIA5String asn1MediaType = null; if (mediaType != null) { asn1MediaType = new DERIA5String(mediaType); } setMetaData(hashProtected, asn1FileName, asn1MediaType, attributes); }
Attributes getOtherMetaData() { if (metaData != null) { return metaData.getOtherMetaData(); } return null; }
private void setMetaData(boolean hashProtected, DERUTF8String fileName, DERIA5String mediaType, Attributes attributes) { this.metaData = new MetaData(ASN1Boolean.getInstance(hashProtected), fileName, mediaType, attributes); }