Class CMSSignedDataParser
-
- All Implemented Interfaces:
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.
Note also: this class does not introduce buffering - if you are processing large files you should create the parser with: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))); }
where bufSize is a suitably large buffer size.CMSSignedDataParser ep = new CMSSignedDataParser(new BufferedInputStream(encapSigData, bufSize));
-
-
Constructor Summary
Constructors Constructor Description CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, Array<byte> sigBlock)
CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, CMSTypedStream signedContent, Array<byte> sigBlock)
CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, InputStream sigData)
base constructor - with encapsulated content CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, CMSTypedStream signedContent, InputStream sigData)
base constructor
-
Method Summary
Modifier and Type Method Description int
getVersion()
Return the version number for the SignedData object Set<AlgorithmIdentifier>
getDigestAlgorithmIDs()
Return the digest algorithm identifiers for the SignedData object SignerInformationStore
getSignerInfos()
return the collection of signers that are associated with the signatures for the message. Store
getCertificates()
Return any X.509 certificate objects in this SignedData structure as a Store of X509CertificateHolder objects. Store
getCRLs()
Return any X.509 CRL objects in this SignedData structure as a Store of X509CRLHolder objects. Store
getAttributeCertificates()
Return any X.509 attribute certificate objects in this SignedData structure as a Store of X509AttributeCertificateHolder objects. Store
getOtherRevocationInfo(ASN1ObjectIdentifier otherRevocationInfoFormat)
Return any OtherRevocationInfo OtherRevInfo objects of the type indicated by otherRevocationInfoFormat in this SignedData structure. String
getSignedContentTypeOID()
Return the a string representation of the OID associated with the encapsulated content info structure carried in the signed data. CMSTypedStream
getSignedContent()
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. static OutputStream
replaceCertificatesAndCRLs(InputStream original, Store certs, Store crls, Store attrCerts, OutputStream out)
Replace the certificate and CRL information associated with this CMSSignedData object with the new one passed in. -
-
Constructor Detail
-
CMSSignedDataParser
CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, Array<byte> sigBlock)
-
CMSSignedDataParser
CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, CMSTypedStream signedContent, Array<byte> sigBlock)
-
CMSSignedDataParser
CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, InputStream sigData)
base constructor - with encapsulated content
-
CMSSignedDataParser
CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, CMSTypedStream signedContent, InputStream sigData)
base constructor- Parameters:
digestCalculatorProvider
- for generating accumulating digestssignedContent
- the content that was signed.sigData
- the signature object stream.
-
-
Method Detail
-
getVersion
int getVersion()
Return the version number for the SignedData object
- Returns:
the version number
-
getDigestAlgorithmIDs
Set<AlgorithmIdentifier> getDigestAlgorithmIDs()
Return the digest algorithm identifiers for the SignedData object
- Returns:
the set of digest algorithm identifiers
-
getSignerInfos
SignerInformationStore getSignerInfos()
return the collection of signers that are associated with the signatures for the message.
-
getCertificates
Store getCertificates()
Return any X.509 certificate objects in this SignedData structure as a Store of X509CertificateHolder objects.
- Returns:
a Store of X509CertificateHolder objects.
-
getCRLs
Store getCRLs()
Return any X.509 CRL objects in this SignedData structure as a Store of X509CRLHolder objects.
- Returns:
a Store of X509CRLHolder objects.
-
getAttributeCertificates
Store getAttributeCertificates()
Return any X.509 attribute certificate objects in this SignedData structure as a Store of X509AttributeCertificateHolder objects.
- Returns:
a Store of X509AttributeCertificateHolder objects.
-
getOtherRevocationInfo
Store getOtherRevocationInfo(ASN1ObjectIdentifier otherRevocationInfoFormat)
Return any OtherRevocationInfo OtherRevInfo objects of the type indicated by otherRevocationInfoFormat in this SignedData structure.
- Parameters:
otherRevocationInfoFormat
- OID of the format type been looked for.- Returns:
a Store of ASN1Encodable objects representing any objects of otherRevocationInfoFormat found.
-
getSignedContentTypeOID
String getSignedContentTypeOID()
Return the a string representation of the OID associated with the encapsulated content info structure carried in the signed data.
- Returns:
the OID for the content type.
-
getSignedContent
CMSTypedStream getSignedContent()
-
replaceSigners
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.signerInformationStore
- the new signer information store to use.out
- the stream to write the new signed data object to.- Returns:
out.
-
replaceCertificatesAndCRLs
static OutputStream replaceCertificatesAndCRLs(InputStream original, Store certs, Store crls, Store attrCerts, 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.certs
- new certificates to be used, if any.crls
- new CRLs to be used, if any.attrCerts
- new attribute certificates to be used, if any.out
- the stream to write the new signed data object to.- Returns:
out.
-
-
-
-