Class CAdESUtils
java.lang.Object
eu.europa.esig.dss.cades.CAdESUtils
The utils for dealing with CMS and related objects
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DigestAlgorithmThe default DigestAlgorithm for ArchiveTimestampstatic final InMemoryResourcesHandlerBuilderThe default resources handler builder to be used across the code -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddSigningCertificateAttribute(org.bouncycastle.asn1.ASN1EncodableVector signedAttributes, DigestAlgorithm digestAlgorithm, CertificateToken signingToken) Method to add signing certificate to ASN.1 DER encoded signed attributes.static booleancontainsATSTv2(org.bouncycastle.cms.SignerInformation signerInformation) Checks if the givenSignerInformation's unsignedProperties contain an archive-time-stamp (ATSv2) elementstatic booleancontainsEvidenceRecord(org.bouncycastle.cms.SignerInformation signerInformation) Checks if the given signer contains an evidence record unsigned attributestatic org.bouncycastle.asn1.cms.AttributeTableemptyIfNull(org.bouncycastle.asn1.cms.AttributeTable originalAttributeTable) Deprecated.since DSS 6.4.static List<org.bouncycastle.tsp.TimeStampToken> findArchiveTimeStampTokens(org.bouncycastle.asn1.cms.AttributeTable unsignedAttributes) Finds archiveTimeStampTokensstatic org.bouncycastle.asn1.ASN1SequencegetAtsHashIndex(org.bouncycastle.asn1.cms.AttributeTable timestampUnsignedAttributes) Returns ats-hash-index table, with a related version present in from timestamp's unsigned propertiesstatic org.bouncycastle.asn1.ASN1SequencegetAtsHashIndexByVersion(org.bouncycastle.asn1.cms.AttributeTable timestampUnsignedAttributes, org.bouncycastle.asn1.ASN1ObjectIdentifier atsHashIndexVersionIdentifier) Returns ats-hash-index table, with a specified version present in from timestamp's unsigned propertiesstatic List<byte[]> getATSHashIndexV3OctetString(org.bouncycastle.asn1.ASN1ObjectIdentifier attributeIdentifier, org.bouncycastle.asn1.ASN1Set attributeValues) Returns octets from the given attribute for ATS-Hash-Index-v3 tablestatic org.bouncycastle.asn1.ASN1ObjectIdentifiergetAtsHashIndexVersionIdentifier(org.bouncycastle.asn1.cms.AttributeTable timestampUnsignedAttributes) ReturnsASN1ObjectIdentifierof the found AtsHashIndexstatic org.bouncycastle.asn1.cms.AttributeTablegetAttributesFromByteArray(byte[] encodedAttributes) This method returns an AttributeTable parsed from ASN.1 encoded representationstatic org.bouncycastle.asn1.ASN1SequencegetCertificatesHashIndex(org.bouncycastle.asn1.ASN1Sequence atsHashIndexValue) Extract the Unsigned Attribute Archive Timestamp Cert Hash Index from a timestampTokenstatic org.bouncycastle.cms.CMSSignedDatagetCMSSignedData(org.bouncycastle.asn1.cms.Attribute attribute) Creates a CMSSignedData from the providedattributestatic org.bouncycastle.asn1.ASN1SequencegetCRLHashIndex(org.bouncycastle.asn1.ASN1Sequence atsHashIndexValue) Extract the Unsigned Attribute Archive Timestamp Crl Hash Index from a timestampTokenstatic org.bouncycastle.asn1.DERTaggedObjectgetDERSignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation) Gets the DER SignedAttributes table from the givenSignerInformationstatic org.bouncycastle.operator.DigestCalculatorProvidergetDigestCalculatorProvider(DSSDocument toSignDocument, DigestAlgorithm digestAlgorithm) Deprecated.since DSS 6.4.static byte[]getEncodedValue(org.bouncycastle.asn1.cms.Attribute attribute) Gets encoded value of theAttributestatic DategetEvidenceRecordGenerationTime(org.bouncycastle.asn1.tsp.EvidenceRecord evidenceRecord) Gets a generation time of the evidence record as indicated by the first timestamp's generation timegetEvidenceRecordIncorporationType(org.bouncycastle.asn1.ASN1ObjectIdentifier unsignedAttributeOID) Gets the evidence record incorporation type based on theunsignedAttributeOIDstatic List<org.bouncycastle.asn1.ASN1ObjectIdentifier> Returns a list of all CMS evidence record identifiersstatic List<byte[]> getOctetStringForAtsHashIndex(org.bouncycastle.asn1.cms.Attribute attribute, org.bouncycastle.asn1.ASN1ObjectIdentifier atsHashIndexVersionIdentifier) Returns octets from the given attribute by defined atsh-hash-index typestatic DSSDocumentgetOriginalDocument(CMS cms, List<DSSDocument> detachedDocuments) Returns the original document from the providedCMSstatic org.bouncycastle.asn1.cms.AttributegetSignedAttribute(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns a signed attribute with the givenoidfromsignerInformationif present and unique.static org.bouncycastle.asn1.cms.AttributeTablegetSignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation) This method returns the existing signed attributes or a new empty attributes hashtablestatic org.bouncycastle.asn1.cms.Attribute[]getSignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns signed attributes matching the givenoidfromsignerInformationif present.static byte[]getSignedDataEncodedOCSPResponse(byte[] binaries, org.bouncycastle.asn1.ASN1ObjectIdentifier objectIdentifier) This method returns encoded binaries used for OCSP token incorporation within a SignedData.crls attributestatic List<org.bouncycastle.asn1.ASN1ObjectIdentifier> Returns a list of all CMS timestamp identifiersstatic org.bouncycastle.tsp.TimeStampTokengetTimeStampToken(org.bouncycastle.asn1.cms.Attribute attribute) Creates a TimeStampToken from the providedattributestatic TimestampTypegetTimestampTypeByOid(org.bouncycastle.asn1.ASN1ObjectIdentifier oid) This method returns a corresponding TimestampType for the given CMSoidstatic org.bouncycastle.asn1.cms.AttributegetUnsignedAttribute(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns an unsigned attribute with the givenoidfromsignerInformationif present and unique.static org.bouncycastle.asn1.cms.AttributeTablegetUnsignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation) This method returns the existing unsigned attributes or a new empty attributes hashtablestatic org.bouncycastle.asn1.cms.Attribute[]getUnsignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns unsigned attributes matching the givenoidfromsignerInformationif present.static org.bouncycastle.asn1.ASN1SequencegetUnsignedAttributesHashIndex(org.bouncycastle.asn1.ASN1Sequence atsHashIndexValue) Extract the Unsigned Attribute Archive Timestamp Attribute Hash Index from a timestampTokenstatic booleanisArchiveTimeStampToken(org.bouncycastle.asn1.cms.Attribute attribute) Checks if the attribute is of an allowed archive timestamp typestatic booleanisAttributeOfType(org.bouncycastle.asn1.cms.Attribute attribute, org.bouncycastle.asn1.ASN1ObjectIdentifier asn1ObjectIdentifier) Deprecated.since DSS 6.4.static booleanisCMSSignedDataEqual(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.CMSSignedData signedDataToCompare) Compares two CMSSignedData objects by their encoded binariesstatic booleanisEmpty(org.bouncycastle.asn1.cms.AttributeTable attributeTable) Deprecated.since DSS 6.4.static DatereadSigningDate(org.bouncycastle.asn1.ASN1Encodable attrValue) Reads the SigningDate with respect to the RFC 3852
-
Field Details
-
DEFAULT_ARCHIVE_TIMESTAMP_HASH_ALGO
The default DigestAlgorithm for ArchiveTimestamp -
DEFAULT_RESOURCES_HANDLER_BUILDER
The default resources handler builder to be used across the code
-
-
Method Details
-
getDERSignedAttributes
public static org.bouncycastle.asn1.DERTaggedObject getDERSignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation) Gets the DER SignedAttributes table from the givenSignerInformation- Parameters:
signerInformation-SignerInformation- Returns:
DERTaggedObjectrepresenting the signed attributes
-
getUnsignedAttributes
public static org.bouncycastle.asn1.cms.AttributeTable getUnsignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation) This method returns the existing unsigned attributes or a new empty attributes hashtable- Parameters:
signerInformation- the signer information- Returns:
- the existing unsigned attributes or an empty attributes hashtable
-
getSignedAttributes
public static org.bouncycastle.asn1.cms.AttributeTable getSignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation) This method returns the existing signed attributes or a new empty attributes hashtable- Parameters:
signerInformation- the signer information- Returns:
- the existing signed attributes or an empty attributes
Hashtable
-
getAttributesFromByteArray
public static org.bouncycastle.asn1.cms.AttributeTable getAttributesFromByteArray(byte[] encodedAttributes) This method returns an AttributeTable parsed from ASN.1 encoded representation- Parameters:
encodedAttributes- ASN.1 encoded AttributesTable- Returns:
- AttributeTable created from given encodedAttributes
-
addSigningCertificateAttribute
public static void addSigningCertificateAttribute(org.bouncycastle.asn1.ASN1EncodableVector signedAttributes, DigestAlgorithm digestAlgorithm, CertificateToken signingToken) Method to add signing certificate to ASN.1 DER encoded signed attributes. Certificate will be added as either signing-certificate or signing-certificate-v2 attribute depending on digest algorithm being used.- Parameters:
signedAttributes- Signed attributes to append signing certificate todigestAlgorithm- the digest algorithm to be usedsigningToken- The signing certificate to be appended
-
isCMSSignedDataEqual
public static boolean isCMSSignedDataEqual(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.CMSSignedData signedDataToCompare) throws IOException Compares two CMSSignedData objects by their encoded binaries- Parameters:
signedData-CMSSignedDataobject to comparesignedDataToCompare-CMSSignedDataobject to compare with- Returns:
- true if binaries of two CMSSignedData are equal, false otherwise
- Throws:
IOException- if an exception occurs
-
getSignedAttribute
public static org.bouncycastle.asn1.cms.Attribute getSignedAttribute(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns a signed attribute with the givenoidfromsignerInformationif present and unique. If multiple Attributes extraction is expected, please use#getSignedAttributes(signerInformation, oid)method.- Parameters:
signerInformation-SignerInformationcontaining signed attributesoid-ASN1ObjectIdentifieroid of the element to extract- Returns:
Attributewith the given OID
-
getSignedAttributes
public static org.bouncycastle.asn1.cms.Attribute[] getSignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns signed attributes matching the givenoidfromsignerInformationif present. Otherwise, returns an empty array.- Parameters:
signerInformation-SignerInformationcontaining signed attributesoid-ASN1ObjectIdentifieroid of the elements to extract- Returns:
- an array of
Attributes with the given OID
-
getUnsignedAttribute
public static org.bouncycastle.asn1.cms.Attribute getUnsignedAttribute(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns an unsigned attribute with the givenoidfromsignerInformationif present and unique. If multiple Attributes extraction is expected, please use#getUnsignedAttributes(signerInformation, oid)method.- Parameters:
signerInformation-SignerInformationto get attribute fromoid-ASN1ObjectIdentifierof the target attribute- Returns:
Attribute
-
getUnsignedAttributes
public static org.bouncycastle.asn1.cms.Attribute[] getUnsignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns unsigned attributes matching the givenoidfromsignerInformationif present. Otherwise, returns an empty array.- Parameters:
signerInformation-SignerInformationcontaining unsigned attributesoid-ASN1ObjectIdentifieroid of the elements to extract- Returns:
- an array of
Attributes with the given OID
-
getOriginalDocument
Returns the original document from the providedCMS- Parameters:
cms-CMSto get original document fromdetachedDocuments- list ofDSSDocuments- Returns:
- original
DSSDocument
-
getDigestCalculatorProvider
@Deprecated public static org.bouncycastle.operator.DigestCalculatorProvider getDigestCalculatorProvider(DSSDocument toSignDocument, DigestAlgorithm digestAlgorithm) Deprecated.since DSS 6.4. To be removedReturns aDigestCalculatorProvider- Parameters:
toSignDocument-DSSDocumentto signdigestAlgorithm-DigestAlgorithmto use- Returns:
DigestCalculatorProvider
-
containsATSTv2
public static boolean containsATSTv2(org.bouncycastle.cms.SignerInformation signerInformation) Checks if the givenSignerInformation's unsignedProperties contain an archive-time-stamp (ATSv2) element- Parameters:
signerInformation-SignerInformationto check- Returns:
- TRUE if the signerInformation contains an ATSv2, FALSE otherwise
-
readSigningDate
-
findArchiveTimeStampTokens
public static List<org.bouncycastle.tsp.TimeStampToken> findArchiveTimeStampTokens(org.bouncycastle.asn1.cms.AttributeTable unsignedAttributes) Finds archiveTimeStampTokens- Parameters:
unsignedAttributes-AttributeTableto obtain timestamps from- Returns:
- a list of
TimeStampTokens
-
getTimestampOids
Returns a list of all CMS timestamp identifiers- Returns:
- a list of
ASN1ObjectIdentifiers
-
isArchiveTimeStampToken
public static boolean isArchiveTimeStampToken(org.bouncycastle.asn1.cms.Attribute attribute) Checks if the attribute is of an allowed archive timestamp type- Parameters:
attribute-Attributeto check- Returns:
- true if the attribute represents an archive timestamp element, false otherwise
-
getTimestampTypeByOid
This method returns a corresponding TimestampType for the given CMSoid- Parameters:
oid-ASN1ObjectIdentifierof the timestamp attribute- Returns:
TimestampType, null when OID is not recognized
-
getAtsHashIndex
public static org.bouncycastle.asn1.ASN1Sequence getAtsHashIndex(org.bouncycastle.asn1.cms.AttributeTable timestampUnsignedAttributes) Returns ats-hash-index table, with a related version present in from timestamp's unsigned properties- Parameters:
timestampUnsignedAttributes-AttributeTableunsigned properties of the timestamp- Returns:
- the content of SignedAttribute: ATS-hash-index unsigned attribute with a present version
-
getCertificatesHashIndex
public static org.bouncycastle.asn1.ASN1Sequence getCertificatesHashIndex(org.bouncycastle.asn1.ASN1Sequence atsHashIndexValue) Extract the Unsigned Attribute Archive Timestamp Cert Hash Index from a timestampToken- Parameters:
atsHashIndexValue-ASN1Sequence- Returns:
ASN1Sequence
-
getCRLHashIndex
public static org.bouncycastle.asn1.ASN1Sequence getCRLHashIndex(org.bouncycastle.asn1.ASN1Sequence atsHashIndexValue) Extract the Unsigned Attribute Archive Timestamp Crl Hash Index from a timestampToken- Parameters:
atsHashIndexValue-ASN1Sequence- Returns:
ASN1Sequence
-
getUnsignedAttributesHashIndex
public static org.bouncycastle.asn1.ASN1Sequence getUnsignedAttributesHashIndex(org.bouncycastle.asn1.ASN1Sequence atsHashIndexValue) Extract the Unsigned Attribute Archive Timestamp Attribute Hash Index from a timestampToken- Parameters:
atsHashIndexValue-ASN1Sequence- Returns:
ASN1Sequence
-
getAtsHashIndexByVersion
public static org.bouncycastle.asn1.ASN1Sequence getAtsHashIndexByVersion(org.bouncycastle.asn1.cms.AttributeTable timestampUnsignedAttributes, org.bouncycastle.asn1.ASN1ObjectIdentifier atsHashIndexVersionIdentifier) Returns ats-hash-index table, with a specified version present in from timestamp's unsigned properties- Parameters:
timestampUnsignedAttributes-AttributeTableunsigned properties of the timestampatsHashIndexVersionIdentifier-ASN1ObjectIdentifieridentifier of ats-hash-index table to get- Returns:
- the content of SignedAttribute: ATS-hash-index unsigned attribute with a requested version if present
-
getAtsHashIndexVersionIdentifier
public static org.bouncycastle.asn1.ASN1ObjectIdentifier getAtsHashIndexVersionIdentifier(org.bouncycastle.asn1.cms.AttributeTable timestampUnsignedAttributes) ReturnsASN1ObjectIdentifierof the found AtsHashIndex- Parameters:
timestampUnsignedAttributes-AttributeTableof the timestamp's unsignedAttributes- Returns:
ASN1ObjectIdentifierof the AtsHashIndex element version
-
getOctetStringForAtsHashIndex
public static List<byte[]> getOctetStringForAtsHashIndex(org.bouncycastle.asn1.cms.Attribute attribute, org.bouncycastle.asn1.ASN1ObjectIdentifier atsHashIndexVersionIdentifier) Returns octets from the given attribute by defined atsh-hash-index type- Parameters:
attribute-Attributeto get byte array fromatsHashIndexVersionIdentifier-ASN1ObjectIdentifierto specify rules- Returns:
- byte array
-
getATSHashIndexV3OctetString
public static List<byte[]> getATSHashIndexV3OctetString(org.bouncycastle.asn1.ASN1ObjectIdentifier attributeIdentifier, org.bouncycastle.asn1.ASN1Set attributeValues) Returns octets from the given attribute for ATS-Hash-Index-v3 table- Parameters:
attributeIdentifier-ASN1ObjectIdentifierof the corresponding AttributeattributeValues-ASN1Setof the corresponding Attribute- Returns:
- byte array representing an octet string
-
getEvidenceRecordOids
Returns a list of all CMS evidence record identifiers- Returns:
- a list of
ASN1ObjectIdentifiers
-
getEvidenceRecordIncorporationType
public static EvidenceRecordIncorporationType getEvidenceRecordIncorporationType(org.bouncycastle.asn1.ASN1ObjectIdentifier unsignedAttributeOID) Gets the evidence record incorporation type based on theunsignedAttributeOID- Parameters:
unsignedAttributeOID-ASN1ObjectIdentifier- Returns:
EvidenceRecordIncorporationType
-
containsEvidenceRecord
public static boolean containsEvidenceRecord(org.bouncycastle.cms.SignerInformation signerInformation) Checks if the given signer contains an evidence record unsigned attribute- Parameters:
signerInformation-SignerInformation- Returns:
- TRUE if an evidence record attribute is present within unsigned attributes table, FALSE otherwise
-
getEvidenceRecordGenerationTime
public static Date getEvidenceRecordGenerationTime(org.bouncycastle.asn1.tsp.EvidenceRecord evidenceRecord) Gets a generation time of the evidence record as indicated by the first timestamp's generation time- Parameters:
evidenceRecord-EvidenceRecordto get a generation time for- Returns:
Dategeneration time
-
isEmpty
Deprecated.since DSS 6.4. Please useeu.europa.esig.dss.spi.DSSASN1Utils#isEmptymethod instead.Checks if theattributeTableis empty- Parameters:
attributeTable-AttributeTable- Returns:
- TRUE if the attribute table is empty, FALSE otherwise
-
emptyIfNull
@Deprecated public static org.bouncycastle.asn1.cms.AttributeTable emptyIfNull(org.bouncycastle.asn1.cms.AttributeTable originalAttributeTable) Deprecated.since DSS 6.4. Please useeu.europa.esig.dss.spi.DSSASN1Utils#emptyIfNullmethod instead.Returns the currentoriginalAttributeTableif instantiated, an emptyAttributeTableif null- Parameters:
originalAttributeTable-AttributeTable- Returns:
AttributeTable
-
isAttributeOfType
@Deprecated public static boolean isAttributeOfType(org.bouncycastle.asn1.cms.Attribute attribute, org.bouncycastle.asn1.ASN1ObjectIdentifier asn1ObjectIdentifier) Deprecated.since DSS 6.4. Please useeu.europa.esig.dss.spi.DSSASN1Utils#isAttributeOfTypemethod instead.Checks if the given attribute is an instance of the expected asn1ObjectIdentifier type- Parameters:
attribute-Attributeto checkasn1ObjectIdentifier-ASN1ObjectIdentifiertype to check against- Returns:
- TRUE if the attribute is of type asn1ObjectIdentifier, FALSE otherwise
-
getTimeStampToken
public static org.bouncycastle.tsp.TimeStampToken getTimeStampToken(org.bouncycastle.asn1.cms.Attribute attribute) Creates a TimeStampToken from the providedattribute- Parameters:
attribute-Attributeto generateTimeStampTokenfrom- Returns:
TimeStampToken
-
getCMSSignedData
public static org.bouncycastle.cms.CMSSignedData getCMSSignedData(org.bouncycastle.asn1.cms.Attribute attribute) throws org.bouncycastle.cms.CMSException, IOException Creates a CMSSignedData from the providedattribute- Parameters:
attribute-Attributeto generateCMSSignedDatafrom- Returns:
CMSSignedData- Throws:
IOException- in case of encoding exceptionorg.bouncycastle.cms.CMSException- in case if the providedattributecannot be converted toCMSSignedData
-
getEncodedValue
public static byte[] getEncodedValue(org.bouncycastle.asn1.cms.Attribute attribute) throws IOException Gets encoded value of theAttribute- Parameters:
attribute-Attributeto get encoded binaries for- Returns:
- byte array
- Throws:
IOException- if an exception on data reading occurs
-
getSignedDataEncodedOCSPResponse
public static byte[] getSignedDataEncodedOCSPResponse(byte[] binaries, org.bouncycastle.asn1.ASN1ObjectIdentifier objectIdentifier) This method returns encoded binaries used for OCSP token incorporation within a SignedData.crls attribute- Parameters:
binaries- byte array containing OCSP tokenobjectIdentifier-ASN1ObjectIdentifier- Returns:
- encoded binaries
-