Top Description Fields Constructors Methods
org.bouncycastle.cms

public Class CMSSignedData

extends Object
implements Encodable
Class Inheritance
All Implemented Interfaces
org.bouncycastle.util.Encodable
Imports
java.io.IOException, .InputStream, .OutputStream, java.util.ArrayList, .Collection, .Collections, .Enumeration, .HashSet, .Iterator, .List, .Map, .Set, org.bouncycastle.asn1.ASN1Encodable, .ASN1EncodableVector, .ASN1InputStream, .ASN1ObjectIdentifier, .ASN1OctetString, .ASN1Sequence, .ASN1Set, .BERSequence, .DLSet, org.bouncycastle.asn1.cms.ContentInfo, .SignedData, .SignerInfo, org.bouncycastle.asn1.x509.AlgorithmIdentifier, org.bouncycastle.cert.X509AttributeCertificateHolder, .X509CRLHolder, .X509CertificateHolder, org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder, .OperatorCreationException, org.bouncycastle.util.Encodable, .Store

general class for handling a pkcs7-signature message. A simple example of usage - note, in the example below the validity of the certificate isn't verified, just the fact that one of the certs matches the given signer...
 Store                   certStore = s.getCertificates();
 SignerInformationStore  signers = s.getSignerInfos();
 Collection              c = signers.getSigners();
 Iterator                it = c.iterator();

 while (it.hasNext())
 {
     SignerInformation   signer = (SignerInformation)it.next();
     Collection          certCollection = certStore.getMatches(signer.getSID());

     Iterator              certIt = certCollection.iterator();
     X509CertificateHolder cert = (X509CertificateHolder)certIt.next();

     if (signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert)))
     {
         verified++;
     }   
 }

Field Summary

Modifier and TypeField and Description
pack-priv ContentInfo
private static final DefaultDigestAlgorithmIdentifierFinder
private Map<K, V>
private static final CMSSignedHelper
pack-priv CMSTypedData
pack-priv SignedData
pack-priv SignerInformationStore

Constructor Summary

AccessConstructor and Description
private
public
CMSSignedData(byte[] sigBlock)

public
CMSSignedData(CMSProcessable signedContent, byte[] sigBlock)

public
CMSSignedData(Map<K, V>
a map of precomputed digests for content indexed by name of hash.
hashes
,
byte[]
the signature object.
sigBlock
)

Content with detached signature, digests precomputed

public
CMSSignedData(CMSProcessable
the content that was signed.
signedContent
,
InputStream
the signature object.
sigData
)

base constructor - content with detached signature.

public
CMSSignedData(InputStream sigData)

base constructor - with encapsulated content

public
CMSSignedData(final CMSProcessable signedContent, ContentInfo sigData)

public
CMSSignedData(Map<K, V> hashes, ContentInfo sigData)

public

Method Summary

Modifier and TypeMethod and Description
public static CMSSignedData

Returns:

a new signed data object.
addDigestAlgorithm
(CMSSignedData
the signed data object to be used as a base.
signedData
,
AlgorithmIdentifier
the digest algorithm to be added to the signed data.
digestAlgorithm
)

Return a new CMSSignedData which guarantees to have the passed in digestAlgorithm in it.

public Store<X509AttributeCertificateHolder>

Returns:

a Store of X509AttributeCertificateHolder objects.
getAttributeCertificates
()

Return any X.509 attribute certificate objects in this SignedData structure as a Store of X509AttributeCertificateHolder objects.

public Store<X509CertificateHolder>

Returns:

a Store of X509CertificateHolder objects.
getCertificates
()

Return any X.509 certificate objects in this SignedData structure as a Store of X509CertificateHolder objects.

public Store<X509CRLHolder>

Returns:

a Store of X509CRLHolder objects.
getCRLs
()

Return any X.509 CRL objects in this SignedData structure as a Store of X509CRLHolder objects.

public Set<AlgorithmIdentifier>

Returns:

the set of digest algorithm identifiers
getDigestAlgorithmIDs
()

Return the digest algorithm identifiers for the SignedData object

public byte[]
getEncoded()

Implements org.bouncycastle.util.Encodable.getEncoded.

return the ASN.1 encoded representation of this object.
public byte[]
getEncoded(String
the ASN.1 encoding format to use ("BER", "DL", or "DER").
encoding
)

return the ASN.1 encoded representation of this object using the specified encoding.

public Store<T>

Returns:

a Store of ASN1Encodable objects representing any objects of otherRevocationInfoFormat found.
getOtherRevocationInfo
(ASN1ObjectIdentifier
OID of the format type been looked for.
otherRevocationInfoFormat
)

Return any OtherRevocationInfo OtherRevInfo objects of the type indicated by otherRevocationInfoFormat in this SignedData structure.

public CMSTypedData
public String

Returns:

the OID for the content type.
getSignedContentTypeOID
()

Return the a string representation of the OID associated with the encapsulated content info structure carried in the signed data.

private SignedData
public SignerInformationStore
getSignerInfos()

return the collection of signers that are associated with the signatures for the message.

public int
getVersion()

Return the version number for this object

public boolean

Returns:

true if the message has no signers or content, false otherwise.
isCertificateManagementMessage
()

Return if this is object represents a certificate management message.

public boolean

Returns:

true if this message represents a detached signature, false otherwise.
isDetachedSignature
()

Return if this is object represents a detached signature.

public static CMSSignedData

Returns:

a new signed data object.
replaceCertificatesAndCRLs
(CMSSignedData
the signed data object to be used as a base.
signedData
,
Store<T>
the new certificates to be used.
certificates
,
Store<T>
the new attribute certificates to be used.
attrCerts
,
Store<T>
the new CRLs to be used - a collection of X509CRLHolder objects, OtherRevocationInfoFormat, or both.
revocations
)

Replace the certificate and CRL information associated with this CMSSignedData object with the new one passed in.

public static CMSSignedData

Returns:

a new signed data object.
replaceSigners
(CMSSignedData
the signed data object to be used as a base.
signedData
,
SignerInformationStore
the new signer information store to use.
signerInformationStore
)

Replace the SignerInformation store associated with this CMSSignedData object with the new one passed in. You would probably only want to do this if you wanted to change the unsigned attributes associated with a signer, or perhaps delete one.

public ContentInfo
toASN1Structure()

return the ContentInfo

private boolean
public boolean

Returns:

true if all verify, false otherwise.
verifySignatures
(SignerInformationVerifierProvider
a provider of SignerInformationVerifier objects.
verifierProvider
)

Verify all the SignerInformation objects and their associated counter signatures attached to this CMS SignedData object.

public boolean

Returns:

true if all verify, false otherwise.
verifySignatures
(SignerInformationVerifierProvider
a provider of SignerInformationVerifier objects.
verifierProvider
,
boolean
if true don't check counter signatures. If false check counter signatures as well.
ignoreCounterSignatures
)

Verify all the SignerInformation objects and optionally their associated counter signatures attached to this CMS SignedData object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentInfoback to summary
pack-priv ContentInfo contentInfo
dgstAlgFinderback to summary
private static final DefaultDigestAlgorithmIdentifierFinder dgstAlgFinder
hashesback to summary
private Map<K, V> hashes
HELPERback to summary
private static final CMSSignedHelper HELPER
signedContentback to summary
pack-priv CMSTypedData signedContent
signedDataback to summary
pack-priv SignedData signedData
signerInfoStoreback to summary
pack-priv SignerInformationStore signerInfoStore

Constructor Detail

CMSSignedDataback to summary
private CMSSignedData(CMSSignedData c)
CMSSignedDataback to summary
public CMSSignedData(byte[] sigBlock) throws CMSException
CMSSignedDataback to summary
public CMSSignedData(CMSProcessable signedContent, byte[] sigBlock) throws CMSException
CMSSignedDataback to summary
public CMSSignedData(Map<K, V> hashes, byte[] sigBlock) throws CMSException

Content with detached signature, digests precomputed

Parameters
hashes:Map<K, V>

a map of precomputed digests for content indexed by name of hash.

sigBlock:byte[]

the signature object.

CMSSignedDataback to summary
public CMSSignedData(CMSProcessable signedContent, InputStream sigData) throws CMSException

base constructor - content with detached signature.

Parameters
signedContent:CMSProcessable

the content that was signed.

sigData:InputStream

the signature object.

CMSSignedDataback to summary
public CMSSignedData(InputStream sigData) throws CMSException

base constructor - with encapsulated content

CMSSignedDataback to summary
public CMSSignedData(final CMSProcessable signedContent, ContentInfo sigData) throws CMSException
CMSSignedDataback to summary
public CMSSignedData(Map<K, V> hashes, ContentInfo sigData) throws CMSException
CMSSignedDataback to summary
public CMSSignedData(ContentInfo sigData) throws CMSException

Method Detail

addDigestAlgorithmback to summary
public static CMSSignedData addDigestAlgorithm(CMSSignedData signedData, AlgorithmIdentifier digestAlgorithm)

Return a new CMSSignedData which guarantees to have the passed in digestAlgorithm in it.

Parameters
signedData:CMSSignedData

the signed data object to be used as a base.

digestAlgorithm:AlgorithmIdentifier

the digest algorithm to be added to the signed data.

Returns:CMSSignedData

a new signed data object.

getAttributeCertificatesback to summary
public Store<X509AttributeCertificateHolder> getAttributeCertificates()

Return any X.509 attribute certificate objects in this SignedData structure as a Store of X509AttributeCertificateHolder objects.

Returns:Store<X509AttributeCertificateHolder>

a Store of X509AttributeCertificateHolder objects.

getCertificatesback to summary
public Store<X509CertificateHolder> getCertificates()

Return any X.509 certificate objects in this SignedData structure as a Store of X509CertificateHolder objects.

Returns:Store<X509CertificateHolder>

a Store of X509CertificateHolder objects.

getCRLsback to summary
public Store<X509CRLHolder> getCRLs()

Return any X.509 CRL objects in this SignedData structure as a Store of X509CRLHolder objects.

Returns:Store<X509CRLHolder>

a Store of X509CRLHolder objects.

getDigestAlgorithmIDsback to summary
public Set<AlgorithmIdentifier> getDigestAlgorithmIDs()

Return the digest algorithm identifiers for the SignedData object

Returns:Set<AlgorithmIdentifier>

the set of digest algorithm identifiers

getEncodedback to summary
public byte[] getEncoded() throws IOException

Implements org.bouncycastle.util.Encodable.getEncoded.

return the ASN.1 encoded representation of this object.

Returns:byte[]

Doc from org.bouncycastle.util.Encodable.getEncoded.

a byte array representing the encoding.

Exceptions
IOException:

Doc from org.bouncycastle.util.Encodable.getEncoded.

if an issue arises generation the encoding.

getEncodedback to summary
public byte[] getEncoded(String encoding) throws IOException

return the ASN.1 encoded representation of this object using the specified encoding.

Parameters
encoding:String

the ASN.1 encoding format to use ("BER", "DL", or "DER").

getOtherRevocationInfoback to summary
public Store<T> getOtherRevocationInfo(ASN1ObjectIdentifier otherRevocationInfoFormat)

Return any OtherRevocationInfo OtherRevInfo objects of the type indicated by otherRevocationInfoFormat in this SignedData structure.

Parameters
otherRevocationInfoFormat:ASN1ObjectIdentifier

OID of the format type been looked for.

Returns:Store<T>

a Store of ASN1Encodable objects representing any objects of otherRevocationInfoFormat found.

getSignedContentback to summary
public CMSTypedData getSignedContent()
getSignedContentTypeOIDback to summary
public String getSignedContentTypeOID()

Return the a string representation of the OID associated with the encapsulated content info structure carried in the signed data.

Returns:String

the OID for the content type.

getSignedDataback to summary
private SignedData getSignedData() throws CMSException
getSignerInfosback to summary
public SignerInformationStore getSignerInfos()

return the collection of signers that are associated with the signatures for the message.

getVersionback to summary
public int getVersion()

Return the version number for this object

isCertificateManagementMessageback to summary
public boolean isCertificateManagementMessage()

Return if this is object represents a certificate management message.

Returns:boolean

true if the message has no signers or content, false otherwise.

isDetachedSignatureback to summary
public boolean isDetachedSignature()

Return if this is object represents a detached signature.

Returns:boolean

true if this message represents a detached signature, false otherwise.

replaceCertificatesAndCRLsback to summary
public static CMSSignedData replaceCertificatesAndCRLs(CMSSignedData signedData, Store<T> certificates, Store<T> attrCerts, Store<T> revocations) throws CMSException

Replace the certificate and CRL information associated with this CMSSignedData object with the new one passed in.

Parameters
signedData:CMSSignedData

the signed data object to be used as a base.

certificates:Store<T>

the new certificates to be used.

attrCerts:Store<T>

the new attribute certificates to be used.

revocations:Store<T>

the new CRLs to be used - a collection of X509CRLHolder objects, OtherRevocationInfoFormat, or both.

Returns:CMSSignedData

a new signed data object.

Exceptions
CMSException:
if there is an error processing the CertStore
replaceSignersback to summary
public static CMSSignedData replaceSigners(CMSSignedData signedData, SignerInformationStore signerInformationStore)

Replace the SignerInformation store associated with this CMSSignedData object with the new one passed in. You would probably only want to do this if you wanted to change the unsigned attributes associated with a signer, or perhaps delete one.

Parameters
signedData:CMSSignedData

the signed data object to be used as a base.

signerInformationStore:SignerInformationStore

the new signer information store to use.

Returns:CMSSignedData

a new signed data object.

toASN1Structureback to summary
public ContentInfo toASN1Structure()

return the ContentInfo

verifyCounterSignatureback to summary
private boolean verifyCounterSignature(SignerInformation counterSigner, SignerInformationVerifierProvider verifierProvider) throws OperatorCreationException, CMSException
verifySignaturesback to summary
public boolean verifySignatures(SignerInformationVerifierProvider verifierProvider) throws CMSException

Verify all the SignerInformation objects and their associated counter signatures attached to this CMS SignedData object.

Parameters
verifierProvider:SignerInformationVerifierProvider

a provider of SignerInformationVerifier objects.

Returns:boolean

true if all verify, false otherwise.

Exceptions
CMSException:
if an exception occurs during the verification process.
verifySignaturesback to summary
public boolean verifySignatures(SignerInformationVerifierProvider verifierProvider, boolean ignoreCounterSignatures) throws CMSException

Verify all the SignerInformation objects and optionally their associated counter signatures attached to this CMS SignedData object.

Parameters
verifierProvider:SignerInformationVerifierProvider

a provider of SignerInformationVerifier objects.

ignoreCounterSignatures:boolean

if true don't check counter signatures. If false check counter signatures as well.

Returns:boolean

true if all verify, false otherwise.

Exceptions
CMSException:
if an exception occurs during the verification process.