public AttributeTable remove(ASN1ObjectIdentifier attrType) { AttributeTable newTable = new AttributeTable(attributes); newTable.attributes.remove(attrType); return newTable; } }
public AttributeTable remove(ASN1ObjectIdentifier attrType) { AttributeTable newTable = new AttributeTable(attributes); newTable.attributes.remove(attrType); return newTable; } }
public static AttributeTable emptyIfNull(AttributeTable original) { if (original == null) { return new AttributeTable(new Hashtable<ASN1ObjectIdentifier, Attribute>()); } else { return original; } }
/** * Return the table of unsigned properties. * * @return */ public AttributeTable getUnsignedAttributes() { return new AttributeTable(new Hashtable<ASN1ObjectIdentifier, ASN1Encodable>()); }
AttributeTable getUnsignedAttributes() { return new AttributeTable(new Hashtable()); }
return SignerInformation.replaceUnsignedAttributes(signer, new AttributeTable(signedAttributes));
/** * @param signerInformation * @return the existing signed attributes or an empty attributes {@code Hashtable} */ public static AttributeTable getSignedAttributes(final SignerInformation signerInformation) { final AttributeTable signedAttributes = signerInformation.getSignedAttributes(); if (signedAttributes == null) { return new AttributeTable(new Hashtable<ASN1ObjectIdentifier, Attribute>()); } else { return signedAttributes; } }
/** * @param signerInformation * @return the existing unsigned attributes or an empty attributes hashtable */ public static AttributeTable getUnsignedAttributes(final SignerInformation signerInformation) { final AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes(); if (unsignedAttributes == null) { return new AttributeTable(new Hashtable<ASN1ObjectIdentifier, Attribute>()); } else { return unsignedAttributes; } }
private AttributeTable getAttributeTable() { return new AttributeTable(signerInfo.getAuthenticatedAttributes()); }
private AttributeTable getUnsignedAttributes() { if (unsignedAttributes.isEmpty()) { return null; } ASN1EncodableVector vec = new ASN1EncodableVector(); for (ASN1ObjectIdentifier type : unsignedAttributes.keySet()) { addAttribute(vec, type, unsignedAttributes.get(type)); } return new AttributeTable(vec); }
private AttributeTable mountAttributeTable(Collection<Attribute> collection) { if (collection == null || collection.isEmpty()) { return null; } AttributeTable table = null; Hashtable<DERObjectIdentifier, org.bouncycastle.asn1.cms.Attribute> attributes = new Hashtable<DERObjectIdentifier, org.bouncycastle.asn1.cms.Attribute>(); for (Attribute attribute : collection) { org.bouncycastle.asn1.cms.Attribute bcAttribute = this.transformAttribute(attribute); attributes.put(bcAttribute.getAttrType(), bcAttribute); } if (attributes.size() > 0) { table = new AttributeTable(attributes); } return table; }
@Override protected AttributeTable getUnsignedAttributes(CMSSignedData token) { SignerInformation timestampSignerInformation = token.getSignerInfos().getSigners().iterator().next(); Attribute counterSignature = new Attribute(CMSAttributes.counterSignature, new DERSet(timestampSignerInformation.toASN1Structure())); return new AttributeTable(counterSignature); }
/** * Creates the authenticated attributes for the SignerInfo section of the signature. */ private AttributeTable createAuthenticatedAttributes() { List<Attribute> attributes = new ArrayList<>(); SpcStatementType spcStatementType = new SpcStatementType(AuthenticodeObjectIdentifiers.SPC_INDIVIDUAL_SP_KEY_PURPOSE_OBJID); attributes.add(new Attribute(AuthenticodeObjectIdentifiers.SPC_STATEMENT_TYPE_OBJID, new DERSet(spcStatementType))); if (programName != null || programURL != null) { SpcSpOpusInfo spcSpOpusInfo = new SpcSpOpusInfo(programName, programURL); attributes.add(new Attribute(AuthenticodeObjectIdentifiers.SPC_SP_OPUS_INFO_OBJID, new DERSet(spcSpOpusInfo))); } return new AttributeTable(new DERSet(attributes.toArray(new ASN1Encodable[attributes.size()]))); } }
@Override protected AttributeTable getUnsignedAttributes(CMSSignedData token) { Attribute rfc3161CounterSignature = new Attribute(AuthenticodeObjectIdentifiers.SPC_RFC3161_OBJID, new DERSet(token.toASN1Structure())); return new AttributeTable(rfc3161CounterSignature); } }
/** * Return a new table with the passed in attribute added. * * @param attrType * @param attrValue * @return */ public AttributeTable add(ASN1ObjectIdentifier attrType, ASN1Encodable attrValue) { AttributeTable newTable = new AttributeTable(attributes); newTable.addAttribute(attrType, new Attribute(attrType, new DERSet(attrValue))); return newTable; }
/** * Return a new table with the passed in attribute added. * * @param attrType the type of the attribute to add. * @param attrValue the value corresponding to the attribute (will be wrapped in a SET). * @return a new table with the extra attribute in it. */ public AttributeTable add(ASN1ObjectIdentifier attrType, ASN1Encodable attrValue) { AttributeTable newTable = new AttributeTable(attributes); newTable.addAttribute(attrType, new Attribute(attrType, new DERSet(attrValue))); return newTable; }
@Test public void isEmpty() { assertTrue(DSSASN1Utils.isEmpty(null)); assertTrue(DSSASN1Utils.isEmpty(new AttributeTable(new Hashtable<>()))); Hashtable<ASN1ObjectIdentifier, Object> nonEmpty = new Hashtable<ASN1ObjectIdentifier, Object>(); nonEmpty.put(new ASN1ObjectIdentifier("1.2.3.4.5"), 4); assertFalse(DSSASN1Utils.isEmpty(new AttributeTable(nonEmpty))); }
private static CMSSignedData addTimestamp(String tsaUrl, CMSSignedData signedData) throws IOException { Collection<SignerInformation> signerInfos = signedData.getSignerInfos().getSigners(); // get signature of first signer (should be the only one) SignerInformation si = signerInfos.iterator().next(); byte[] signature = si.getSignature(); // send request to TSA byte[] token = TimeStampingClient.getTimeStampToken(tsaUrl, signature, DigestType.SHA1); // create new SignerInformation with TS attribute Attribute tokenAttr = new Attribute(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, new DERSet(ASN1Primitive.fromByteArray(token))); ASN1EncodableVector timestampVector = new ASN1EncodableVector(); timestampVector.add(tokenAttr); AttributeTable at = new AttributeTable(timestampVector); si = SignerInformation.replaceUnsignedAttributes(si, at); signerInfos.clear(); signerInfos.add(si); SignerInformationStore newSignerStore = new SignerInformationStore(signerInfos); // create new signed data CMSSignedData newSignedData = CMSSignedData.replaceSigners(signedData, newSignerStore); return newSignedData; }
@Test public void emptyIfNull() { assertNotNull(DSSASN1Utils.emptyIfNull(null)); Hashtable<ASN1ObjectIdentifier, Object> nonEmpty = new Hashtable<ASN1ObjectIdentifier, Object>(); nonEmpty.put(new ASN1ObjectIdentifier("1.2.3.4.5"), 4); AttributeTable attributeTable = new AttributeTable(nonEmpty); AttributeTable emptyIfNull = DSSASN1Utils.emptyIfNull(attributeTable); assertNotNull(emptyIfNull); assertEquals(attributeTable, emptyIfNull); }
public AttributeTable getSignedAttributes(final SignatureParameters parameters) { ASN1EncodableVector signedAttributes = new ASN1EncodableVector(); addSigningCertificateAttribute(parameters, signedAttributes); addSigningTimeAttribute(parameters, signedAttributes); addSignerAttribute(parameters, signedAttributes); addSignaturePolicyId(parameters, signedAttributes); addContentHints(parameters, signedAttributes); addContentIdentifier(parameters, signedAttributes); addCommitmentType(parameters, signedAttributes); addSignerLocation(parameters, signedAttributes); addContentTimestamps(parameters, signedAttributes); // mime-type attribute breaks parallel signatures by adding PKCS7 as a mime-type for subsequent signers. // This attribute is not mandatory, so it has been disabled. // signedAttributes = addMimeType(document, signedAttributes); final AttributeTable signedAttributesTable = new AttributeTable(signedAttributes); return signedAttributesTable; }