Package eu.europa.esig.dss.cms.object
Class CMSObjectUtils
java.lang.Object
eu.europa.esig.dss.cms.object.CMSObjectUtils
- All Implemented Interfaces:
ICMSUtils
Implements
ICMSUtils
using a eu.europa.esig.dss.cms.bc.CMSSignedDataWrapper
processing-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method checks whether the augmentation of signatures with an archive-time-stamp-v2 is supported by the current implementationvoid
This method checks whether the embedding of existing Evidence Records within CMS is supported by the current implementationGets encoding of the ContentInfo of CMSgetDSSResourcesHandlerBuilder
(DSSResourcesHandlerBuilder dssResourcesHandlerBuilder) This method is used to verify whether the providedDSSResourcesHandlerBuilder
is supported by the current implementation.static org.bouncycastle.asn1.cms.SignedData
getSignedData
(CMS cms) Gets SignedData element of the CMSparseToCMS
(byte[] binaries) Parses the given byte array to aCMS
objectparseToCMS
(DSSDocument document) Parses the givenDSSDocument
to aCMS
objectpopulateDigestAlgorithmSet
(CMS cms, Collection<org.bouncycastle.asn1.x509.AlgorithmIdentifier> digestAlgorithmsToAdd) Adds digest algorithms toCMSSignedData
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.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 valuesreplaceSigners
(CMS cms, org.bouncycastle.cms.SignerInformationStore newSignerStore) Replaces the signers withincms
with thenewSignerStore
org.bouncycastle.cms.SignerInformation
replaceUnsignedAttributes
(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.cms.AttributeTable unsignedAttributes) This method replacesunsignedAttributes
within the givensignerInformation
toCMS
(org.bouncycastle.tsp.TimeStampToken timeStampToken) Converts aTimeStampToken
to aCMS
org.bouncycastle.cms.CMSTypedData
toCMSEncapsulatedContent
(DSSDocument document) Converts aDSSDocument
to the correspondingCMSTypedData
object typestatic org.bouncycastle.util.Store
<org.bouncycastle.util.Encodable> toCRLsStore
(org.bouncycastle.util.Store<org.bouncycastle.cert.X509CRLHolder> crls, org.bouncycastle.util.Store<?> ocspResponses, org.bouncycastle.util.Store<?> ocspBasicResponses) Creates a new combined SignedData.crls store containing CRLs, OCSP responses and OCSP Basic responsesvoid
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.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.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.void
Writes the encoded binaries of the SignedData.digestAlgorithms field to the givenOutputStream
NOTE: This method is used for evidence record hash computationvoid
Writes the encoded binaries of the SignedData.signerInfos field to the givenOutputStream
NOTE: This method is used for evidence record hash computationwriteToDSSDocument
(CMS cms, DSSResourcesHandlerBuilder resourcesHandlerBuilder) Creates aDSSDocument
from the givenCMS
using the implementation based coding.
-
Constructor Details
-
CMSObjectUtils
public CMSObjectUtils()Default constructor
-
-
Method Details
-
parseToCMS
Description copied from interface:ICMSUtils
Parses the givenDSSDocument
to aCMS
object- Specified by:
parseToCMS
in interfaceICMSUtils
- Parameters:
document
-DSSDocument
to parse- Returns:
CMS
-
parseToCMS
Description copied from interface:ICMSUtils
Parses the given byte array to aCMS
object- Specified by:
parseToCMS
in interfaceICMSUtils
- Parameters:
binaries
- byte array to parse- Returns:
CMS
-
writeToDSSDocument
Description copied from interface:ICMSUtils
Creates aDSSDocument
from the givenCMS
using the implementation based coding. This method uses aresourcesHandlerBuilder
which defines the final document's implementation (e.g. in-memory document or a temporary document in a filesystem). NOTE: When used, the dss-cms-object implementation stores document using a DL coding, and dss-cms-stream stores documents using BER coding.- Specified by:
writeToDSSDocument
in interfaceICMSUtils
- Parameters:
cms
-CMS
to create a document fromresourcesHandlerBuilder
-DSSResourcesHandlerBuilder
- Returns:
DSSDocument
-
recomputeSignerInformation
public org.bouncycastle.cms.SignerInformation recomputeSignerInformation(CMS cms, org.bouncycastle.cms.SignerId signerId, org.bouncycastle.operator.DigestCalculatorProvider digestCalculatorProvider, DSSResourcesHandlerBuilder resourcesHandlerBuilder) throws org.bouncycastle.cms.CMSException Description copied from interface:ICMSUtils
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.- Specified by:
recomputeSignerInformation
in interfaceICMSUtils
- 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
Description copied from interface:ICMSUtils
Replaces the signers withincms
with thenewSignerStore
- Specified by:
replaceSigners
in interfaceICMSUtils
- Parameters:
cms
-CMS
to replace signers innewSignerStore
-SignerInformationStore
representing the new signers to be replaced with- Returns:
CMS
containing the new signers store
-
replaceCertificatesAndCRLs
public 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) Description copied from interface:ICMSUtils
Replaces SignedData content within theCMS
with the provided values- Specified by:
replaceCertificatesAndCRLs
in interfaceICMSUtils
- Parameters:
cms
-CMS
to replace content incertificates
-Store
attributeCertificates
-Store
crls
-Store
ocspResponsesStore
-Store
ocspBasicStore
-Store
- Returns:
CMS
-
toCRLsStore
public static org.bouncycastle.util.Store<org.bouncycastle.util.Encodable> toCRLsStore(org.bouncycastle.util.Store<org.bouncycastle.cert.X509CRLHolder> crls, org.bouncycastle.util.Store<?> ocspResponses, org.bouncycastle.util.Store<?> ocspBasicResponses) Creates a new combined SignedData.crls store containing CRLs, OCSP responses and OCSP Basic responses- Parameters:
crls
-Store
containing CRLsocspResponses
-Store
containing OCSP responsesocspBasicResponses
-Store
containing OCSP Basic responses- Returns:
Store
-
populateDigestAlgorithmSet
public CMS populateDigestAlgorithmSet(CMS cms, Collection<org.bouncycastle.asn1.x509.AlgorithmIdentifier> digestAlgorithmsToAdd) Description copied from interface:ICMSUtils
Adds digest algorithms toCMSSignedData
- Specified by:
populateDigestAlgorithmSet
in interfaceICMSUtils
- Parameters:
cms
-CMS
to extenddigestAlgorithmsToAdd
- a collection of digestAlgorithmIdentifier
s to be included- Returns:
CMS
-
toCMS
Description copied from interface:ICMSUtils
Converts aTimeStampToken
to aCMS
-
getContentInfoEncoding
Description copied from interface:ICMSUtils
Gets encoding of the ContentInfo of CMS- Specified by:
getContentInfoEncoding
in interfaceICMSUtils
- Parameters:
cms
-CMS
to check- Returns:
String
encoding, e.g. 'DER' or 'BER'
-
writeSignedDataDigestAlgorithmsEncoded
Description copied from interface:ICMSUtils
Writes the encoded binaries of the SignedData.digestAlgorithms field to the givenOutputStream
NOTE: This method is used for evidence record hash computation- Specified by:
writeSignedDataDigestAlgorithmsEncoded
in interfaceICMSUtils
- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
writeContentInfoEncoded
Description copied from interface:ICMSUtils
Writes the encoded binaries of the ContentInfo element to the givenOutputStream
NOTE: This method is used for archive-time-stamp-v2 message-imprint computation.- Specified by:
writeContentInfoEncoded
in interfaceICMSUtils
- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
writeSignedDataCertificatesEncoded
Description copied from interface:ICMSUtils
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.- Specified by:
writeSignedDataCertificatesEncoded
in interfaceICMSUtils
- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
writeSignedDataCRLsEncoded
Description copied from interface:ICMSUtils
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.- Specified by:
writeSignedDataCRLsEncoded
in interfaceICMSUtils
- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
writeSignedDataSignerInfosEncoded
Description copied from interface:ICMSUtils
Writes the encoded binaries of the SignedData.signerInfos field to the givenOutputStream
NOTE: This method is used for evidence record hash computation- Specified by:
writeSignedDataSignerInfosEncoded
in interfaceICMSUtils
- Parameters:
cms
-CMS
os
-OutputStream
- Throws:
IOException
- if an exception occurs on bytes writing
-
getSignedData
Gets SignedData element of the CMS- Parameters:
cms
-CMS
- Returns:
SignedData
-
toCMSEncapsulatedContent
Description copied from interface:ICMSUtils
Converts aDSSDocument
to the correspondingCMSTypedData
object type- Specified by:
toCMSEncapsulatedContent
in interfaceICMSUtils
- Parameters:
document
-DSSDocument
- Returns:
CMSTypedData
-
getDSSResourcesHandlerBuilder
public DSSResourcesHandlerBuilder getDSSResourcesHandlerBuilder(DSSResourcesHandlerBuilder dssResourcesHandlerBuilder) Description copied from interface:ICMSUtils
This method is used to verify whether the providedDSSResourcesHandlerBuilder
is supported by the current implementation. Returns the given value in case of success.- Specified by:
getDSSResourcesHandlerBuilder
in interfaceICMSUtils
- Parameters:
dssResourcesHandlerBuilder
-DSSResourcesHandlerBuilder
- Returns:
DSSResourcesHandlerBuilder
-
replaceUnsignedAttributes
public org.bouncycastle.cms.SignerInformation replaceUnsignedAttributes(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.cms.AttributeTable unsignedAttributes) Description copied from interface:ICMSUtils
This method replacesunsignedAttributes
within the givensignerInformation
- Specified by:
replaceUnsignedAttributes
in interfaceICMSUtils
- Parameters:
signerInformation
-SignerInformation
to replace unsigned attributes table intounsignedAttributes
-AttributeTable
containing the unsigned properties to be replaced with- Returns:
SignerInformation
updated
-
assertATSv2AugmentationSupported
public void assertATSv2AugmentationSupported()Description copied from interface:ICMSUtils
This method checks whether the augmentation of signatures with an archive-time-stamp-v2 is supported by the current implementation- Specified by:
assertATSv2AugmentationSupported
in interfaceICMSUtils
-
assertEvidenceRecordEmbeddingSupported
public void assertEvidenceRecordEmbeddingSupported()Description copied from interface:ICMSUtils
This method checks whether the embedding of existing Evidence Records within CMS is supported by the current implementation- Specified by:
assertEvidenceRecordEmbeddingSupported
in interfaceICMSUtils
-