Top Description Fields Constructors Methods
org.bouncycastle.cms

public Class CMSSignedDataParser

extends CMSContentInfoParser
Class Inheritance
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream, .OutputStream, java.util.ArrayList, .Collections, .HashMap, .HashSet, .Iterator, .List, .Map, .Set, org.bouncycastle.asn1.ASN1Encodable, .ASN1EncodableVector, .ASN1Generator, .ASN1ObjectIdentifier, .ASN1OctetStringParser, .ASN1SequenceParser, .ASN1Set, .ASN1SetParser, .ASN1StreamParser, .BERSequenceGenerator, .BERSetParser, .BERTaggedObject, .BERTags, .DERSet, .DERTaggedObject, org.bouncycastle.asn1.cms.CMSObjectIdentifiers, .ContentInfoParser, .SignedDataParser, .SignerInfo, org.bouncycastle.asn1.x509.AlgorithmIdentifier, org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder, .DigestCalculator, .DigestCalculatorProvider, .OperatorCreationException, org.bouncycastle.util.Store, org.bouncycastle.util.io.Streams

Parsing class for an CMS Signed Data object from an input stream.

Note

that because we are in a streaming mode only one signer can be tried and it is important that the methods on the parser are called in the appropriate order.

A simple example of usage for an encapsulated signature.

Two notes: first, in the example below the validity of the certificate isn't verified, just the fact that one of the certs matches the given signer, and, second, because we are in a streaming mode the order of the operations is important.

     CMSSignedDataParser     sp = new CMSSignedDataParser(new JcaDigestCalculatorProviderBuilder().setProvider("BC").build(), encapSigData);

     sp.getSignedContent().drain();

     Store                   certStore = sp.getCertificates();
     SignerInformationStore  signers = sp.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();

         System.out.println("verify returns: " + signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert)));
     }
Note also: this class does not introduce buffering - if you are processing large files you should create the parser with:
         CMSSignedDataParser     ep = new CMSSignedDataParser(new BufferedInputStream(encapSigData, bufSize));
 
where bufSize is a suitably large buffer size.

Field Summary

Modifier and TypeField and Description
private ASN1Set
private ASN1Set
private boolean
private CMSTypedStream
private ASN1ObjectIdentifier
private SignedDataParser
private SignerInformationStore
private static final DefaultDigestAlgorithmIdentifierFinder
private Set<AlgorithmIdentifier>
private Map<K, V>
private static final CMSSignedHelper
Inherited from org.bouncycastle.cms.CMSContentInfoParser:
_contentInfo_data

Constructor Summary

AccessConstructor and Description
public
CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, byte[] sigBlock)

public
CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, CMSTypedStream signedContent, byte[] sigBlock)

public
CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, InputStream sigData)

base constructor - with encapsulated content

public
CMSSignedDataParser(DigestCalculatorProvider
for generating accumulating digests
digestCalculatorProvider
,
CMSTypedStream
the content that was signed.
signedContent
,
InputStream
the signature object stream.
sigData
)

base constructor

Method Summary

Modifier and TypeMethod and Description
private static ASN1Set
getASN1Set(ASN1SetParser asn1SetParser)

public Store<T>

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<T>

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<T>

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 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 CMSTypedStream
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.

public SignerInformationStore
getSignerInfos()

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

public int

Returns:

the version number
getVersion
()

Return the version number for the SignedData object

private static void
pipeEncapsulatedOctetString(ContentInfoParser encapContentInfo, OutputStream rawOutputStream)

private static void
private void
public static OutputStream

Returns:

out.
replaceCertificatesAndCRLs
(InputStream
the signed data stream to be used as a base.
original
,
Store<T>
new certificates to be used, if any.
certs
,
Store<T>
new CRLs to be used, if any.
crls
,
Store<T>
new attribute certificates to be used, if any.
attrCerts
,
OutputStream
the stream to write the new signed data object to.
out
)

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

The output stream is returned unclosed.

public static OutputStream

Returns:

out.
replaceSigners
(InputStream
the signed data stream to be used as a base.
original
,
SignerInformationStore
the new signer information store to use.
signerInformationStore
,
OutputStream
the stream to write the new signed data object to.
out
)

Replace the signerinformation store associated with the passed in message contained in the stream original 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.

private static void
writeSetToGeneratorTagged(ASN1Generator asn1Gen, ASN1SetParser asn1SetParser, int tagNo)

Inherited from org.bouncycastle.cms.CMSContentInfoParser:
close

Field Detail

_certSetback to summary
private ASN1Set _certSet
_crlSetback to summary
private ASN1Set _crlSet
_isCertCrlParsedback to summary
private boolean _isCertCrlParsed
_signedContentback to summary
private CMSTypedStream _signedContent
_signedContentTypeback to summary
private ASN1ObjectIdentifier _signedContentType
_signedDataback to summary
private SignedDataParser _signedData
_signerInfoStoreback to summary
private SignerInformationStore _signerInfoStore
dgstAlgFinderback to summary
private static final DefaultDigestAlgorithmIdentifierFinder dgstAlgFinder
digestAlgorithmsback to summary
private Set<AlgorithmIdentifier> digestAlgorithms
digestsback to summary
private Map<K, V> digests
HELPERback to summary
private static final CMSSignedHelper HELPER

Constructor Detail

CMSSignedDataParserback to summary
public CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, byte[] sigBlock) throws CMSException
CMSSignedDataParserback to summary
public CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, CMSTypedStream signedContent, byte[] sigBlock) throws CMSException
CMSSignedDataParserback to summary
public CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, InputStream sigData) throws CMSException

base constructor - with encapsulated content

CMSSignedDataParserback to summary
public CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, CMSTypedStream signedContent, InputStream sigData) throws CMSException

base constructor

Parameters
digestCalculatorProvider:DigestCalculatorProvider

for generating accumulating digests

signedContent:CMSTypedStream

the content that was signed.

sigData:InputStream

the signature object stream.

Method Detail

getASN1Setback to summary
private static ASN1Set getASN1Set(ASN1SetParser asn1SetParser)
getAttributeCertificatesback to summary
public Store<T> getAttributeCertificates() throws CMSException

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

Returns:Store<T>

a Store of X509AttributeCertificateHolder objects.

getCertificatesback to summary
public Store<T> getCertificates() throws CMSException

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

Returns:Store<T>

a Store of X509CertificateHolder objects.

getCRLsback to summary
public Store<T> getCRLs() throws CMSException

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

Returns:Store<T>

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

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

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 CMSTypedStream 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.

getSignerInfosback to summary
public SignerInformationStore getSignerInfos() throws CMSException

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 the SignedData object

Returns:int

the version number

pipeEncapsulatedOctetStringback to summary
private static void pipeEncapsulatedOctetString(ContentInfoParser encapContentInfo, OutputStream rawOutputStream) throws IOException
pipeOctetStringback to summary
private static void pipeOctetString(ASN1OctetStringParser octs, OutputStream output) throws IOException
populateCertCrlSetsback to summary
private void populateCertCrlSets() throws CMSException
replaceCertificatesAndCRLsback to summary
public static OutputStream replaceCertificatesAndCRLs(InputStream original, Store<T> certs, Store<T> crls, Store<T> attrCerts, OutputStream out) throws CMSException, IOException

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

The output stream is returned unclosed.

Parameters
original:InputStream

the signed data stream to be used as a base.

certs:Store<T>

new certificates to be used, if any.

crls:Store<T>

new CRLs to be used, if any.

attrCerts:Store<T>

new attribute certificates to be used, if any.

out:OutputStream

the stream to write the new signed data object to.

Returns:OutputStream

out.

Exceptions
CMSException:
if there is an error processing the CertStore
replaceSignersback to summary
public static OutputStream replaceSigners(InputStream original, SignerInformationStore signerInformationStore, OutputStream out) throws CMSException, IOException

Replace the signerinformation store associated with the passed in message contained in the stream original 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.

The output stream is returned unclosed.

Parameters
original:InputStream

the signed data stream to be used as a base.

signerInformationStore:SignerInformationStore

the new signer information store to use.

out:OutputStream

the stream to write the new signed data object to.

Returns:OutputStream

out.

writeSetToGeneratorTaggedback to summary
private static void writeSetToGeneratorTagged(ASN1Generator asn1Gen, ASN1SetParser asn1SetParser, int tagNo) throws IOException