Package eu.europa.esig.dss.cades
Class CMSUtils
java.lang.Object
eu.europa.esig.dss.cades.CMSUtils
The utils for dealing with CMS object
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DigestAlgorithmThe default DigestAlgorithm for ArchiveTimestamp -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bouncycastle.cms.CMSSignedDataaddDigestAlgorithm(org.bouncycastle.cms.CMSSignedData cmsSignedData, org.bouncycastle.asn1.x509.AlgorithmIdentifier algorithmIdentifier) This method adds a DigestAlgorithm used by an Archive TimeStamp to the SignedData.digestAlgorithms set, when required.static 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 org.bouncycastle.cms.CMSSignedDatagenerateCMSSignedData(org.bouncycastle.cms.CMSSignedDataGenerator generator, org.bouncycastle.cms.CMSTypedData content, boolean encapsulate) This method generateCMSSignedDatausing the provided #CMSSignedDataGenerator, the content and the indication if the content should be encapsulated.static org.bouncycastle.cms.SignerInformationStoregenerateCounterSigners(org.bouncycastle.cms.CMSSignedDataGenerator cmsSignedDataGenerator, org.bouncycastle.cms.SignerInformation signerInfoToSign) Generates a counter signaturestatic org.bouncycastle.cms.CMSSignedDatagenerateDetachedCMSSignedData(org.bouncycastle.cms.CMSSignedDataGenerator generator, org.bouncycastle.cms.CMSProcessableByteArray content) Generates a detached CMS SignedDatastatic org.bouncycastle.asn1.cms.AttributeTablegetAttributesFromByteArray(byte[] encodedAttributes) This method returns an AttributeTable parsed from ASN.1 encoded representationstatic org.bouncycastle.cms.CMSTypedDatagetContentToBeSigned(DSSDocument toSignData) Returns the content to be signedstatic 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) Returns aDigestCalculatorProviderstatic DSSDocumentgetOriginalDocument(org.bouncycastle.cms.CMSSignedData cmsSignedData, List<DSSDocument> detachedDocuments) Returns the original document from the providedcmsSignedDatastatic org.bouncycastle.asn1.cms.AttributegetSignedAttribute(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns a signed attribute with the givenoidfromsignerInformationif presentstatic org.bouncycastle.asn1.cms.AttributeTablegetSignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation) This method returns the existing signed attributes or a new empty attributes hashtablestatic byte[]getSignedContent(org.bouncycastle.cms.CMSTypedData cmsTypedData) This method returns the signed content extracted from a CMSTypedDatastatic org.bouncycastle.asn1.cms.AttributegetUnsignedAttribute(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid) Returns an unsigned attribute by its givenoidstatic org.bouncycastle.asn1.cms.AttributeTablegetUnsignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation) This method returns the existing unsigned attributes or a new empty attributes hashtablestatic booleanisCMSSignedDataEqual(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.CMSSignedData signedDataToCompare) Compares two CMSSignedData objects by their encoded binariesstatic booleanisDetachedSignature(org.bouncycastle.cms.CMSSignedData cmsSignedData) Checks if the signature is detachedstatic org.bouncycastle.cms.CMSSignedDatapopulateDigestAlgorithmSet(org.bouncycastle.cms.CMSSignedData newCmsSignedData, org.bouncycastle.cms.CMSSignedData oldCmsSignedData) This method is used to ensure the presence of all items from SignedData.digestAlgorithm set fromoldCmsSignedDatawithinnewCmsSignedDatastatic 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
-
-
Method Details
-
generateCMSSignedData
public static org.bouncycastle.cms.CMSSignedData generateCMSSignedData(org.bouncycastle.cms.CMSSignedDataGenerator generator, org.bouncycastle.cms.CMSTypedData content, boolean encapsulate) This method generateCMSSignedDatausing the provided #CMSSignedDataGenerator, the content and the indication if the content should be encapsulated.- Parameters:
generator-CMSSignedDataGeneratorcontent-CMSTypedDataencapsulate- true if the content should be encapsulated in the signature, false otherwise- Returns:
CMSSignedData
-
generateCounterSigners
public static org.bouncycastle.cms.SignerInformationStore generateCounterSigners(org.bouncycastle.cms.CMSSignedDataGenerator cmsSignedDataGenerator, org.bouncycastle.cms.SignerInformation signerInfoToSign) Generates a counter signature- Parameters:
cmsSignedDataGenerator-CMSSignedDataGeneratorto extend the CMS SignedDatasignerInfoToSign-SignerInformationto be counter signed- Returns:
SignerInformationStorewith a counter signature
-
generateDetachedCMSSignedData
public static org.bouncycastle.cms.CMSSignedData generateDetachedCMSSignedData(org.bouncycastle.cms.CMSSignedDataGenerator generator, org.bouncycastle.cms.CMSProcessableByteArray content) Generates a detached CMS SignedData- Parameters:
generator-CMSSignedDataGeneratorcontent-CMSProcessableByteArrayto sign- Returns:
CMSSignedData
-
populateDigestAlgorithmSet
public static org.bouncycastle.cms.CMSSignedData populateDigestAlgorithmSet(org.bouncycastle.cms.CMSSignedData newCmsSignedData, org.bouncycastle.cms.CMSSignedData oldCmsSignedData) This method is used to ensure the presence of all items from SignedData.digestAlgorithm set fromoldCmsSignedDatawithinnewCmsSignedData- Parameters:
newCmsSignedData-CMSSignedDatato be extended with digest algorithms, if requiredoldCmsSignedData-CMSSignedDatato copy digest algorithms set from- Returns:
- extended
CMSSignedData
-
addDigestAlgorithm
public static org.bouncycastle.cms.CMSSignedData addDigestAlgorithm(org.bouncycastle.cms.CMSSignedData cmsSignedData, org.bouncycastle.asn1.x509.AlgorithmIdentifier algorithmIdentifier) This method adds a DigestAlgorithm used by an Archive TimeStamp to the SignedData.digestAlgorithms set, when required. See ETSI EN 319 122-1, ch. "5.5.3 The archive-time-stamp-v3 attribute"- Parameters:
cmsSignedData-CMSSignedDatato extendalgorithmIdentifier-AlgorithmIdentifierto add- Returns:
CMSSignedData
-
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
-
getSignedContent
public static byte[] getSignedContent(org.bouncycastle.cms.CMSTypedData cmsTypedData) This method returns the signed content extracted from a CMSTypedData- Parameters:
cmsTypedData-CMSTypedDatacannot be null- Returns:
- the signed content extracted from
CMSTypedData
-
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 append
-
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- Parameters:
signerInformation-SignerInformationcontaining signed attributesoid-ASN1ObjectIdentifieroid of the element to extract- Returns:
Attributewith 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 by its givenoid- Parameters:
signerInformation-SignerInformationto get attribute fromoid-ASN1ObjectIdentifierof the target attribute- Returns:
Attribute
-
isDetachedSignature
public static boolean isDetachedSignature(org.bouncycastle.cms.CMSSignedData cmsSignedData) Checks if the signature is detached- Parameters:
cmsSignedData-CMSSignedData- Returns:
- TRUE if the signature is detached, FALSE otherwise
-
getOriginalDocument
public static DSSDocument getOriginalDocument(org.bouncycastle.cms.CMSSignedData cmsSignedData, List<DSSDocument> detachedDocuments) Returns the original document from the providedcmsSignedData- Parameters:
cmsSignedData-CMSSignedDatato get original document fromdetachedDocuments- list ofDSSDocuments- Returns:
- original
DSSDocument
-
getContentToBeSigned
Returns the content to be signed- Parameters:
toSignData-DSSDocumentto sign- Returns:
CMSTypedData
-
getDigestCalculatorProvider
public static org.bouncycastle.operator.DigestCalculatorProvider getDigestCalculatorProvider(DSSDocument toSignDocument, DigestAlgorithm digestAlgorithm) Returns 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
Reads the SigningDate with respect to the RFC 3852- Parameters:
attrValue-ASN1Encodablecontaining the signingDate- Returns:
Dateif its format is correct, null otherwise
-