Package eu.europa.esig.dss.cms
Class CMSUtils
java.lang.Object
eu.europa.esig.dss.cms.CMSUtils
Contains utils methods for CMS processing
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
This method returns whether the augmentation of signatures with an archive-time-stamp-v2 is supported by the current implementationstatic void
This method checks whether the embedding of existing Evidence Records within CMS is supported by the current implementationstatic String
Gets encoding of the ContentInfo of CMSstatic DSSResourcesHandlerBuilder
getDSSResourcesHandlerBuilder
(DSSResourcesHandlerBuilder dssResourcesHandlerBuilder) This method is used to verify whether the providedDSSResourcesHandlerBuilder
is supported by the current implementation.static CMS
parseToCMS
(byte[] binaries) Parses the given byte array to aCMS
objectstatic CMS
parseToCMS
(DSSDocument document) Parses the givenDSSDocument
to aCMS
objectstatic CMS
populateDigestAlgorithmSet
(CMS cms, Collection<org.bouncycastle.asn1.x509.AlgorithmIdentifier> digestAlgorithmsToAdd) Adds digest algorithms toCMSSignedData
static org.bouncycastle.cms.SignerInformation
recomputeSignerInformation
(CMS cms, org.bouncycastle.cms.SignerId signerId, org.bouncycastle.operator.DigestCalculatorProvider digestCalculatorProvider, DSSResourcesHandlerBuilder resourcesHandlerBuilder) This method re-created theSignerInformation
with a givensignerId
fromCMS
by providing thedigestCalculatorProvider
to the validation.static CMS
replaceCertificatesAndCRLs
(CMS cms, org.bouncycastle.util.Store<org.bouncycastle.cert.X509CertificateHolder> certificates, org.bouncycastle.util.Store<org.bouncycastle.cert.X509AttributeCertificateHolder> attributeCertificates, org.bouncycastle.util.Store<org.bouncycastle.cert.X509CRLHolder> crls, org.bouncycastle.util.Store<?> ocspResponsesStore, org.bouncycastle.util.Store<?> ocspBasicStore) Replaces SignedData content within theCMS
with the provided valuesstatic CMS
replaceSigners
(CMS cms, org.bouncycastle.cms.SignerInformationStore newSignerStore) Replaces the signers withincms
with thenewSignerStore
static org.bouncycastle.cms.SignerInformation
replaceUnsignedAttributes
(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.cms.AttributeTable unsignedAttributes) This method replacesunsignedAttributes
within the givensignerInformation
static CMS
toCMS
(org.bouncycastle.tsp.TimeStampToken timeStampToken) Converts aTimeStampToken
to aCMS
static org.bouncycastle.cms.CMSTypedData
toCMSEncapsulatedContent
(DSSDocument document) Converts aDSSDocument
to the correspondingCMSTypedData
object typestatic void
writeContentInfoEncoded
(CMS cms, OutputStream os) Writes the encoded binaries of the ContentInfo element to the givenOutputStream
NOTE: This method is used for archive-time-stamp-v2 message-imprint computation.static void
Writes the encoded binaries of the SignedData.certificates field to the givenOutputStream
NOTE: This method is used for archive-time-stamp-v2 message-imprint computation.static void
writeSignedDataCRLsEncoded
(CMS cms, OutputStream os) Writes the encoded binaries of the SignedData.crls field to the givenOutputStream
NOTE: This method is used for archive-time-stamp-v2 message-imprint computation.static void
Writes the encoded binaries of the SignedData.digestAlgorithms field to the givenOutputStream
NOTE: This method is used for evidence record hash computationstatic void
Writes the encoded binaries of the SignedData.signerInfos field to the givenOutputStream
NOTE: This method is used for evidence record hash computationstatic DSSDocument
writeToDSSDocument
(CMS cms, DSSResourcesHandlerBuilder resourcesHandlerBuilder) Creates aDSSDocument
from the givenCMS
.
-
Method Details
-
parseToCMS
Parses the givenDSSDocument
to aCMS
object- Parameters:
document
-DSSDocument
to parse- Returns:
CMS
-
parseToCMS
Parses the given byte array to aCMS
object- Parameters:
binaries
- byte array to parse- Returns:
CMS
-
writeToDSSDocument
public static DSSDocument writeToDSSDocument(CMS cms, DSSResourcesHandlerBuilder resourcesHandlerBuilder) Creates aDSSDocument
from the givenCMS
. This method uses aresourcesHandlerBuilder
which defines the final document's implementation (e.g. in-memory document or a temporary document in a filesystem).- Parameters:
cms
-CMS
to create a document fromresourcesHandlerBuilder
-DSSResourcesHandlerBuilder
- Returns:
DSSDocument
-
recomputeSignerInformation
public static org.bouncycastle.cms.SignerInformation recomputeSignerInformation(CMS cms, org.bouncycastle.cms.SignerId signerId, org.bouncycastle.operator.DigestCalculatorProvider digestCalculatorProvider, DSSResourcesHandlerBuilder resourcesHandlerBuilder) throws org.bouncycastle.cms.CMSException This method re-created theSignerInformation
with a givensignerId
fromCMS
by providing thedigestCalculatorProvider
to the validation. The returnedSignerInformation
contains validated digest according to the provided document.- Parameters:
cms
-CMS
containing a SignerInformation to be validatedsignerId
-SignerId
to re-computedigestCalculatorProvider
-DigestCalculatorProvider
containing digest of the original signed documentresourcesHandlerBuilder
-DSSResourcesHandlerBuilder
- Returns:
SignerInformation
- Throws:
org.bouncycastle.cms.CMSException
- if an exception occurs on SignerInformation re-creation
-
replaceSigners
public static CMS replaceSigners(CMS cms, org.bouncycastle.cms.SignerInformationStore newSignerStore) Replaces the signers withincms
with thenewSignerStore
-
replaceCertificatesAndCRLs
public static CMS replaceCertificatesAndCRLs(CMS cms, org.bouncycastle.util.Store<org.bouncycastle.cert.X509CertificateHolder> certificates, org.bouncycastle.util.Store<org.bouncycastle.cert.X509AttributeCertificateHolder> attributeCertificates, org.bouncycastle.util.Store<org.bouncycastle.cert.X509CRLHolder> crls, org.bouncycastle.util.Store<?> ocspResponsesStore, org.bouncycastle.util.Store<?> ocspBasicStore) Replaces SignedData content within theCMS
with the provided values -
populateDigestAlgorithmSet
public static CMS populateDigestAlgorithmSet(CMS cms, Collection<org.bouncycastle.asn1.x509.AlgorithmIdentifier> digestAlgorithmsToAdd) Adds digest algorithms toCMSSignedData
-
toCMS
Converts aTimeStampToken
to aCMS
- Parameters:
timeStampToken
-TimeStampToken
- Returns:
CMS
-
getContentInfoEncoding
Gets encoding of the ContentInfo of CMS -
writeSignedDataDigestAlgorithmsEncoded
public static void writeSignedDataDigestAlgorithmsEncoded(CMS cms, OutputStream os) throws IOException Writes the encoded binaries of the SignedData.digestAlgorithms field to the givenOutputStream
NOTE: This method is used for evidence record hash computation- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
writeContentInfoEncoded
Writes the encoded binaries of the ContentInfo element to the givenOutputStream
NOTE: This method is used for archive-time-stamp-v2 message-imprint computation.- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
writeSignedDataCertificatesEncoded
Writes the encoded binaries of the SignedData.certificates field to the givenOutputStream
NOTE: This method is used for archive-time-stamp-v2 message-imprint computation.- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
writeSignedDataCRLsEncoded
Writes the encoded binaries of the SignedData.crls field to the givenOutputStream
NOTE: This method is used for archive-time-stamp-v2 message-imprint computation.- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
writeSignedDataSignerInfosEncoded
Writes the encoded binaries of the SignedData.signerInfos field to the givenOutputStream
NOTE: This method is used for evidence record hash computation- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
toCMSEncapsulatedContent
Converts aDSSDocument
to the correspondingCMSTypedData
object type- Parameters:
document
-DSSDocument
- Returns:
CMSTypedData
-
getDSSResourcesHandlerBuilder
public static DSSResourcesHandlerBuilder getDSSResourcesHandlerBuilder(DSSResourcesHandlerBuilder dssResourcesHandlerBuilder) This method is used to verify whether the providedDSSResourcesHandlerBuilder
is supported by the current implementation. Returns the given value in case of success.- Parameters:
dssResourcesHandlerBuilder
-DSSResourcesHandlerBuilder
- Returns:
DSSResourcesHandlerBuilder
-
replaceUnsignedAttributes
public static org.bouncycastle.cms.SignerInformation replaceUnsignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.cms.AttributeTable unsignedAttributes) This method replacesunsignedAttributes
within the givensignerInformation
- Parameters:
signerInformation
-SignerInformation
to replace unsigned attributes table intounsignedAttributes
-AttributeTable
containing the unsigned properties to be replaced with- Returns:
SignerInformation
updated
-
assertATSv2AugmentationSupported
public static void assertATSv2AugmentationSupported()This method returns whether the augmentation of signatures with an archive-time-stamp-v2 is supported by the current implementation -
assertEvidenceRecordEmbeddingSupported
public static void assertEvidenceRecordEmbeddingSupported()This method checks whether the embedding of existing Evidence Records within CMS is supported by the current implementation
-