org.bouncycastle.cms

Class CMSSignedDataParser

Known Direct Subclasses:
SMIMESignedParser

public class CMSSignedDataParser
extends CMSContentInfoParser

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(encapSigData);

      sp.getSignedContent().drain();

      CertStore               certs = sp.getCertificatesAndCRLs("Collection", "BC");
      SignerInformationStore  signers = sp.getSignerInfos();
      
      Collection              c = signers.getSigners();
      Iterator                it = c.iterator();

      while (it.hasNext())
      {
          SignerInformation   signer = (SignerInformation)it.next();
          Collection          certCollection = certs.getCertificates(signer.getSID());

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

          System.out.println("verify returns: " + signer.verify(cert, "BC"));
      }
 
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

Fields inherited from class org.bouncycastle.cms.CMSContentInfoParser

_contentInfo, _data

Constructor Summary

CMSSignedDataParser(InputStream sigData)
base constructor - with encapsulated content
CMSSignedDataParser(byte[] sigBlock)
CMSSignedDataParser(CMSTypedStream signedContent, InputStream sigData)
base constructor
CMSSignedDataParser(CMSTypedStream signedContent, byte[] sigBlock)

Method Summary

CertStore
getCertificatesAndCRLs(String type, String provider)
return a CertStore containing the certificates and CRLs associated with this message.
CMSTypedStream
getSignedContent()
SignerInformationStore
getSignerInfos()
return the collection of signers that are associated with the signatures for the message.

Methods inherited from class org.bouncycastle.cms.CMSContentInfoParser

close

Constructor Details

CMSSignedDataParser

public CMSSignedDataParser(InputStream sigData)
            throws CMSException
base constructor - with encapsulated content

CMSSignedDataParser

public CMSSignedDataParser(byte[] sigBlock)
            throws CMSException

CMSSignedDataParser

public CMSSignedDataParser(CMSTypedStream signedContent,
                           InputStream sigData)
            throws CMSException
base constructor
Parameters:
signedContent - the content that was signed.
sigData - the signature object stream.

CMSSignedDataParser

public CMSSignedDataParser(CMSTypedStream signedContent,
                           byte[] sigBlock)
            throws CMSException

Method Details

getCertificatesAndCRLs

public CertStore getCertificatesAndCRLs(String type,
                                        String provider)
            throws NoSuchAlgorithmException,
                   NoSuchProviderException,
                   CMSException
return a CertStore containing the certificates and CRLs associated with this message.

getSignedContent

public CMSTypedStream getSignedContent()

getSignerInfos

public SignerInformationStore getSignerInfos()
            throws CMSException
return the collection of signers that are associated with the signatures for the message.