Top Description Inners Fields Constructors Methods
org.bouncycastle.mail.smime

public Class SMIMESignedParser

extends CMSSignedDataParser
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedOutputStream, .File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .IOException, .InputStream, .OutputStream, java.security.AccessController, .PrivilegedAction, jakarta.activation.CommandMap, .MailcapCommandMap, jakarta.mail.BodyPart, .MessagingException, .Part, .Session, jakarta.mail.internet.MimeBodyPart, .MimeMessage, .MimeMultipart, org.bouncycastle.cms.CMSException, .CMSSignedDataParser, .CMSTypedStream, org.bouncycastle.operator.DigestCalculatorProvider

general class for handling a pkcs7-signature message.

A simple example of usage - note, in the example below the validity of the certificate isn't verified, just the fact that one of the certs matches the given signer...

 CertStore               certs = s.getCertificates("Collection", "BCFIPS");
 SignerInformationStore  signers = s.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();

     if (signer.verify(cert.getPublicKey()))
     {
         verified++;
     }   
 }

Note

if you are using this class with AS2 or some other protocol that does not use 7bit as the default content transfer encoding you will need to use the constructor that allows you to specify the default content transfer encoding, such as "binary".

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv MimeBodyPart
pack-priv Object

Constructor Summary

AccessConstructor and Description
public
SMIMESignedParser(DigestCalculatorProvider
provider for digest calculators.
digCalcProvider
,
MimeMultipart
signed message with signature.
message
)

base constructor using a defaultContentTransferEncoding of 7bit.

public
SMIMESignedParser(DigestCalculatorProvider
provider for digest calculators.
digCalcProvider
,
MimeMultipart
signed message with signature.
message
,
File
the temporary file to use to back the signed data.
backingFile
)

base constructor using a defaultContentTransferEncoding of 7bit and a specified backing file.

public
SMIMESignedParser(DigestCalculatorProvider
provider for digest calculators.
digCalcProvider
,
MimeMultipart
the signed message with signature.
message
,
String
new default to use.
defaultContentTransferEncoding
)

base constructor with settable contentTransferEncoding.

public
SMIMESignedParser(DigestCalculatorProvider
provider for digest calculators.
digCalcProvider
,
MimeMultipart
the signed message with signature.
message
,
String
new default to use.
defaultContentTransferEncoding
,
File
the temporary file to use to back the signed data.
backingFile
)

base constructor with settable contentTransferEncoding and a specified backing file.

public
SMIMESignedParser(DigestCalculatorProvider
provider for digest calculators.
digCalcProvider
,
Part
the message containing the encapsulated signed data.
message
)

base constructor for a signed message with encapsulated content.

public
SMIMESignedParser(DigestCalculatorProvider
provider for digest calculators.
digCalcProvider
,
Part
the Part containing the signed content.
message
,
File
the file the encapsulated part is to be written to after it has been decoded.
file
)

Constructor for a signed message with encapsulated content.

Method Summary

Modifier and TypeMethod and Description
private void
public MimeBodyPart

Returns:

the signed body part in this message.
getContent
()

return the content that was signed.

public MimeMessage

Returns:

a MimeMessage holding the content.
getContentAsMimeMessage
(Session
the session to base the MimeMessage around.
session
)

Return the content that was signed as a mime message.

public Object

Returns:

depending on whether this was unencapsulated or not it will return a MimeMultipart or a MimeBodyPart
getContentWithSignature
()

return the content that was signed with its signature attached.

private static InputStream
getInputStream(Part bodyPart)

private static CMSTypedStream
getSignedInputStream(BodyPart bodyPart, String defaultContentTransferEncoding, File backingFile)

private static File
Inherited from org.bouncycastle.cms.CMSSignedDataParser:
getAttributeCertificatesgetCertificatesgetCRLsgetDigestAlgorithmIDsgetOtherRevocationInfogetSignedContentgetSignedContentTypeOIDgetSignerInfosgetVersionreplaceCertificatesAndCRLsreplaceSigners

Field Detail

contentback to summary
pack-priv MimeBodyPart content
messageback to summary
pack-priv Object message

Constructor Detail

SMIMESignedParserback to summary
public SMIMESignedParser(DigestCalculatorProvider digCalcProvider, MimeMultipart message) throws MessagingException, CMSException

base constructor using a defaultContentTransferEncoding of 7bit. A temporary backing file will be created for the signed data.

Parameters
digCalcProvider:DigestCalculatorProvider

provider for digest calculators.

message:MimeMultipart

signed message with signature.

Exceptions
MessagingException:
on an error extracting the signature or otherwise processing the message.
CMSException:
if some other problem occurs.
SMIMESignedParserback to summary
public SMIMESignedParser(DigestCalculatorProvider digCalcProvider, MimeMultipart message, File backingFile) throws MessagingException, CMSException

base constructor using a defaultContentTransferEncoding of 7bit and a specified backing file.

Parameters
digCalcProvider:DigestCalculatorProvider

provider for digest calculators.

message:MimeMultipart

signed message with signature.

backingFile:File

the temporary file to use to back the signed data.

Exceptions
MessagingException:
on an error extracting the signature or otherwise processing the message.
CMSException:
if some other problem occurs.
SMIMESignedParserback to summary
public SMIMESignedParser(DigestCalculatorProvider digCalcProvider, MimeMultipart message, String defaultContentTransferEncoding) throws MessagingException, CMSException

base constructor with settable contentTransferEncoding. A temporary backing file will be created to contain the signed data.

Parameters
digCalcProvider:DigestCalculatorProvider

provider for digest calculators.

message:MimeMultipart

the signed message with signature.

defaultContentTransferEncoding:String

new default to use.

Exceptions
MessagingException:
on an error extracting the signature or otherwise processing the message.
CMSException:
if some other problem occurs.r
SMIMESignedParserback to summary
public SMIMESignedParser(DigestCalculatorProvider digCalcProvider, MimeMultipart message, String defaultContentTransferEncoding, File backingFile) throws MessagingException, CMSException

base constructor with settable contentTransferEncoding and a specified backing file.

Parameters
digCalcProvider:DigestCalculatorProvider

provider for digest calculators.

message:MimeMultipart

the signed message with signature.

defaultContentTransferEncoding:String

new default to use.

backingFile:File

the temporary file to use to back the signed data.

Exceptions
MessagingException:
on an error extracting the signature or otherwise processing the message.
CMSException:
if some other problem occurs.
SMIMESignedParserback to summary
public SMIMESignedParser(DigestCalculatorProvider digCalcProvider, Part message) throws MessagingException, CMSException, SMIMEException

base constructor for a signed message with encapsulated content.

Note

in this case the encapsulated MimeBody part will only be suitable for a single writeTo - once writeTo has been called the file containing the body part will be deleted. If writeTo is not called the file will be left in the temp directory.

Parameters
digCalcProvider:DigestCalculatorProvider

provider for digest calculators.

message:Part

the message containing the encapsulated signed data.

Exceptions
MessagingException:
on an error extracting the signature or otherwise processing the message.
CMSException:
if some other problem occurs.
SMIMEException:
if the body part encapsulated in the message cannot be extracted.
SMIMESignedParserback to summary
public SMIMESignedParser(DigestCalculatorProvider digCalcProvider, Part message, File file) throws MessagingException, CMSException, SMIMEException

Constructor for a signed message with encapsulated content. The encapsulated content, if it exists, is written to the file represented by the File object passed in.

Parameters
digCalcProvider:DigestCalculatorProvider

provider for digest calculators.

message:Part

the Part containing the signed content.

file:File

the file the encapsulated part is to be written to after it has been decoded.

Exceptions
MessagingException:
on an error extracting the signature or otherwise processing the message.
CMSException:
if some other problem occurs.
SMIMEException:
if the body part encapsulated in the message cannot be extracted.

Method Detail

drainContentback to summary
private void drainContent() throws CMSException
getContentback to summary
public MimeBodyPart getContent()

return the content that was signed.

Returns:MimeBodyPart

the signed body part in this message.

getContentAsMimeMessageback to summary
public MimeMessage getContentAsMimeMessage(Session session) throws MessagingException, IOException

Return the content that was signed as a mime message.

Parameters
session:Session

the session to base the MimeMessage around.

Returns:MimeMessage

a MimeMessage holding the content.

Exceptions
MessagingException:
if there is an issue creating the MimeMessage.
IOException:
if there is an issue reading the content.
getContentWithSignatureback to summary
public Object getContentWithSignature()

return the content that was signed with its signature attached.

Returns:Object

depending on whether this was unencapsulated or not it will return a MimeMultipart or a MimeBodyPart

getInputStreamback to summary
private static InputStream getInputStream(Part bodyPart) throws MessagingException
getSignedInputStreamback to summary
private static CMSTypedStream getSignedInputStream(BodyPart bodyPart, String defaultContentTransferEncoding, File backingFile) throws MessagingException
getTmpFileback to summary
private static File getTmpFile() throws MessagingException
org.bouncycastle.mail.smime back to summary

private Class SMIMESignedParser.TemporaryFileInputStream

extends BufferedInputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final File
Inherited from java.io.BufferedInputStream:
bufcountmarklimitmarkpospos

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.BufferedInputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.
Inherited from java.io.BufferedInputStream:
availablemarkmarkSupportedreadreadresetskiptransferTo

Field Detail

_fileback to summary
private final File _file

Constructor Detail

TemporaryFileInputStreamback to summary
pack-priv TemporaryFileInputStream(File file) throws FileNotFoundException

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.BufferedInputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.BufferedInputStream.close.

Closes this input stream and releases any system resources associated with the stream. Once the stream has been closed, further read(), available(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Exceptions
IOException:
if an I/O error occurs.