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.
| Modifier and Type | Field and Description |
|---|---|
| private ASN1Set | |
| private ASN1Set | |
| private boolean | |
| private CMSTypedStream | |
| private ASN1ObjectIdentifier | |
| private SignedDataParser | |
| private SignerInformationStore | |
| private static final DefaultDigestAlgorithmIdentifierFinder | |
| private Set | |
| private Map | |
| private static final CMSSignedHelper |
| Access | Constructor and Description |
|---|---|
| public | |
| 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 |
| Modifier and Type | Method and Description |
|---|---|
| private static ASN1Set | |
| public Store | Returns: a Store of X509AttributeCertificateHolder objects.Return any X.509 attribute certificate objects in this SignedData structure as a Store of X509AttributeCertificateHolder objects. |
| public Store | Returns: a Store of X509CertificateHolder objects.Return any X.509 certificate objects in this SignedData structure as a Store of X509CertificateHolder objects. |
| public Store | Returns: a Store of X509CRLHolder objects.Return any X.509 CRL objects in this SignedData structure as a Store of X509CRLHolder objects. |
| public Set | Returns: the set of digest algorithm identifiersReturn the digest algorithm identifiers for the SignedData object |
| public Store | Returns: a Store of ASN1Encodable objects representing any objects of otherRevocationInfoFormat found.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.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 | |
| private static void | |
| private static void | |
| private void | |
| public static OutputStream | Returns: out.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.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 |
| _certSet | back to summary |
|---|---|
| private ASN1Set _certSet | |
| _crlSet | back to summary |
|---|---|
| private ASN1Set _crlSet | |
| _isCertCrlParsed | back to summary |
|---|---|
| private boolean _isCertCrlParsed | |
| _signedContent | back to summary |
|---|---|
| private CMSTypedStream _signedContent | |
| _signedContentType | back to summary |
|---|---|
| private ASN1ObjectIdentifier _signedContentType | |
| _signedData | back to summary |
|---|---|
| private SignedDataParser _signedData | |
| _signerInfoStore | back to summary |
|---|---|
| private SignerInformationStore _signerInfoStore | |
| dgstAlgFinder | back to summary |
|---|---|
| private static final DefaultDigestAlgorithmIdentifierFinder dgstAlgFinder | |
| digestAlgorithms | back to summary |
|---|---|
| private Set<AlgorithmIdentifier> digestAlgorithms | |
| digests | back to summary |
|---|---|
| private Map<K, V> digests | |
| HELPER | back to summary |
|---|---|
| private static final CMSSignedHelper HELPER | |
| CMSSignedDataParser | back to summary |
|---|---|
| public CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, byte[] sigBlock) throws CMSException | |
| CMSSignedDataParser | back to summary |
|---|---|
| public CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, CMSTypedStream signedContent, byte[] sigBlock) throws CMSException | |
| CMSSignedDataParser | back to summary |
|---|---|
| public CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, InputStream sigData) throws CMSException base constructor - with encapsulated content | |
| CMSSignedDataParser | back to summary |
|---|---|
| public CMSSignedDataParser(DigestCalculatorProvider digestCalculatorProvider, CMSTypedStream signedContent, InputStream sigData) throws CMSException base constructor
| |
| getASN1Set | back to summary |
|---|---|
| private static ASN1Set getASN1Set(ASN1SetParser asn1SetParser) | |
| getAttributeCertificates | back to summary |
|---|---|
| public Store Return any X.509 attribute certificate objects in this SignedData structure as a Store of X509AttributeCertificateHolder objects.
| |
| getCertificates | back to summary |
|---|---|
| public Store Return any X.509 certificate objects in this SignedData structure as a Store of X509CertificateHolder objects.
| |
| getCRLs | back to summary |
|---|---|
| public Store Return any X.509 CRL objects in this SignedData structure as a Store of X509CRLHolder objects.
| |
| getDigestAlgorithmIDs | back to summary |
|---|---|
| public Set Return the digest algorithm identifiers for the SignedData object
| |
| getOtherRevocationInfo | back to summary |
|---|---|
| public Store Return any OtherRevocationInfo OtherRevInfo objects of the type indicated by otherRevocationInfoFormat in this SignedData structure.
| |
| getSignedContent | back to summary |
|---|---|
| public CMSTypedStream getSignedContent() | |
| getSignedContentTypeOID | back 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.
| |
| getSignerInfos | back to summary |
|---|---|
| public SignerInformationStore getSignerInfos() throws CMSException return the collection of signers that are associated with the signatures for the message. | |
| getVersion | back to summary |
|---|---|
| public int getVersion() Return the version number for the SignedData object
| |
| pipeEncapsulatedOctetString | back to summary |
|---|---|
| private static void pipeEncapsulatedOctetString(ContentInfoParser encapContentInfo, OutputStream rawOutputStream) throws IOException | |
| pipeOctetString | back to summary |
|---|---|
| private static void pipeOctetString(ASN1OctetStringParser octs, OutputStream output) throws IOException | |
| populateCertCrlSets | back to summary |
|---|---|
| private void populateCertCrlSets() throws CMSException | |
| replaceCertificatesAndCRLs | back 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.
| |
| replaceSigners | back 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.
| |
| writeSetToGeneratorTagged | back to summary |
|---|---|
| private static void writeSetToGeneratorTagged(ASN1Generator asn1Gen, ASN1SetParser asn1SetParser, int tagNo) throws IOException | |