| java.lang.Object org.bouncycastle.cms.CMSContentInfoParser org.bouncycastle.cms.CMSSignedDataParser
All known Subclasses: org.bouncycastle.mail.smime.SMIMESignedParser,
CMSSignedDataParser | public class CMSSignedDataParser extends CMSContentInfoParser (Code) | | 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.
|
Method Summary | |
public X509Store | getAttributeCertificates(String type, String provider) return a X509Store containing the attribute certificates, if any, contained
in this message. | public X509Store | getCRLs(String type, String provider) return a X509Store containing CRLs, if any, contained
in this message. | public X509Store | getCertificates(String type, String provider) return a X509Store containing the public key certificates, if any, contained
in this message. | public CertStore | getCertificatesAndCRLs(String type, String provider) return a CertStore containing the certificates and CRLs associated with
this message. | public CMSTypedStream | getSignedContent() | public SignerInformationStore | getSignerInfos() return the collection of signers that are associated with the
signatures for the message. | public int | getVersion() | public static OutputStream | replaceCertificatesAndCRLs(InputStream original, CertStore certsAndCrls, OutputStream out) 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 - the signed data stream to be used as a base. Parameters: certsAndCrls - the new certificates and CRLs to be used. Parameters: out - the stream to write the new signed data object to. | public static OutputStream | replaceSigners(InputStream original, SignerInformationStore signerInformationStore, OutputStream 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.
The output stream is returned unclosed.
Parameters: original - the signed data stream to be used as a base. Parameters: signerInformationStore - the new signer information store to use. Parameters: out - the stream to write the new signed data object to. |
CMSSignedDataParser | public CMSSignedDataParser(CMSTypedStream signedContent, InputStream sigData) throws CMSException(Code) | | base constructor
Parameters: signedContent - the content that was signed. Parameters: sigData - the signature object stream. |
getVersion | public int getVersion()(Code) | | Return the version number for the SignedData object
the version number |
replaceCertificatesAndCRLs | public static OutputStream replaceCertificatesAndCRLs(InputStream original, CertStore certsAndCrls, OutputStream out) throws CMSException, IOException(Code) | | 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 - the signed data stream to be used as a base. Parameters: certsAndCrls - the new certificates and CRLs to be used. Parameters: out - the stream to write the new signed data object to. out. exception: CMSException - if there is an error processing the CertStore |
replaceSigners | public static OutputStream replaceSigners(InputStream original, SignerInformationStore signerInformationStore, OutputStream out) throws CMSException, IOException(Code) | | 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 - the signed data stream to be used as a base. Parameters: signerInformationStore - the new signer information store to use. Parameters: out - the stream to write the new signed data object to. out. |
|
|