Davis, Cale
2014-07-09 15:33:36 UTC
Hello,
I'm using bouncy castle 1.49 to parse a signed MDN. I'm parsing a signed MDN so that I can verify the signature later. An MDN is a receipt message used in the AS2 protocol. The signed MDN I'm using for testing is attached. A signed MDN is a multipart message that has two parts. The first part is another 2-part multipart message. The second part is the signature. I've tried parsing the message a couple different ways. Below are my tests that are written in Scala.
import com.elemica.smime.SMimeHelper
import java.io.{FileInputStream, File}
import javax.mail.internet.{MimeMultipart, MimeMessage}
import net.liftweb.util.Helpers
import org.bouncycastle.cms.{CMSSignedData, CMSProcessableByteArray}
import org.bouncycastle.mail.smime.SMIMESignedParser
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder
import org.specs2.mutable.Specification
class SMimeParseSpec extends Specification {
val filePath = "/home/daviscale/mdn_example.mime"
val file = new File(filePath)
val fileInputStream = new FileInputStream(file)
val mimeMessage = new MimeMessage(SMimeHelper.getSession, fileInputStream)
"The bouncy castle library " should {
"parse a signed MDN with SMIMESignedParser" in {
val mimeMultipart = mimeMessage.getContent.asInstanceOf[MimeMultipart]
val mdnPart = mimeMultipart.getBodyPart(0)
val mdnPartBytes = Helpers.readWholeStream(mdnPart.getInputStream)
val signaturePart = mimeMultipart.getBodyPart(1)
val signaturePartBytes = Helpers.readWholeStream(signaturePart.getInputStream)
val cmsByteArray = new CMSProcessableByteArray(mdnPartBytes)
val cmsSignedData = new CMSSignedData(cmsByteArray, signaturePartBytes)
true
}
"parse a signed MDN with CMSSignedData" in {
val smimeParser = new SMIMESignedParser(new JcaDigestCalculatorProviderBuilder().setProvider("BC").build(),mimeMessage.getContent.asInstanceOf[MimeMultipart])
true
}
}
}
The tests throw an exception in the same place. Here are the exceptions:
[info] SMimeParseSpec
[info]
[info] The bouncy castle library should
[error] ! parse a signed MDN with SMIMESignedParser
[error] CMSException: IOException reading content. (null:-1)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedData.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$1.apply$mcZ$sp(SMimeParseSpec.scala:31)
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1InputStream.readObject(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedData.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$1.apply$mcZ$sp(SMimeParseSpec.scala:31)
[error] DER length more than 4 bytes: 111
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1InputStream.readObject(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedData.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$1.apply$mcZ$sp(SMimeParseSpec.scala:31)
[error] ! parse a signed MDN with CMSSignedData
[error] CMSException: IOException reading content. (null:-1)
[error] org.bouncycastle.cms.CMSContentInfoParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$2.apply$mcZ$sp(SMimeParseSpec.scala:35)
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1StreamParser.readObject(Unknown Source)
[error] org.bouncycastle.cms.CMSContentInfoParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$2.apply$mcZ$sp(SMimeParseSpec.scala:35)
[error] DER length more than 4 bytes: 111
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1StreamParser.readObject(Unknown Source)
[error] org.bouncycastle.cms.CMSContentInfoParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$2.apply$mcZ$sp(SMimeParseSpec.scala:35)
Any thoughts on what I can do to successfully parse the MDN would be appreciated.
Thanks,
Cale
Cale Davis | Software Developer | Elemica
780 Johnson Ferry Road | Suite 400 | Atlanta, Georgia | 30342
Mobile: +1 770 286 2645
Skype: cale.davis.elemica
www.elemica.com<http://www.elemica.com/>
This message contains confidential or privileged information and is intended only for the individual named. If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Nothing in this email is intended to bind Elemica, Inc., which only operates under the terms of written agreements signed by an authorized officer. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission.
I'm using bouncy castle 1.49 to parse a signed MDN. I'm parsing a signed MDN so that I can verify the signature later. An MDN is a receipt message used in the AS2 protocol. The signed MDN I'm using for testing is attached. A signed MDN is a multipart message that has two parts. The first part is another 2-part multipart message. The second part is the signature. I've tried parsing the message a couple different ways. Below are my tests that are written in Scala.
import com.elemica.smime.SMimeHelper
import java.io.{FileInputStream, File}
import javax.mail.internet.{MimeMultipart, MimeMessage}
import net.liftweb.util.Helpers
import org.bouncycastle.cms.{CMSSignedData, CMSProcessableByteArray}
import org.bouncycastle.mail.smime.SMIMESignedParser
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder
import org.specs2.mutable.Specification
class SMimeParseSpec extends Specification {
val filePath = "/home/daviscale/mdn_example.mime"
val file = new File(filePath)
val fileInputStream = new FileInputStream(file)
val mimeMessage = new MimeMessage(SMimeHelper.getSession, fileInputStream)
"The bouncy castle library " should {
"parse a signed MDN with SMIMESignedParser" in {
val mimeMultipart = mimeMessage.getContent.asInstanceOf[MimeMultipart]
val mdnPart = mimeMultipart.getBodyPart(0)
val mdnPartBytes = Helpers.readWholeStream(mdnPart.getInputStream)
val signaturePart = mimeMultipart.getBodyPart(1)
val signaturePartBytes = Helpers.readWholeStream(signaturePart.getInputStream)
val cmsByteArray = new CMSProcessableByteArray(mdnPartBytes)
val cmsSignedData = new CMSSignedData(cmsByteArray, signaturePartBytes)
true
}
"parse a signed MDN with CMSSignedData" in {
val smimeParser = new SMIMESignedParser(new JcaDigestCalculatorProviderBuilder().setProvider("BC").build(),mimeMessage.getContent.asInstanceOf[MimeMultipart])
true
}
}
}
The tests throw an exception in the same place. Here are the exceptions:
[info] SMimeParseSpec
[info]
[info] The bouncy castle library should
[error] ! parse a signed MDN with SMIMESignedParser
[error] CMSException: IOException reading content. (null:-1)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedData.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$1.apply$mcZ$sp(SMimeParseSpec.scala:31)
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1InputStream.readObject(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedData.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$1.apply$mcZ$sp(SMimeParseSpec.scala:31)
[error] DER length more than 4 bytes: 111
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1InputStream.readObject(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedData.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$1.apply$mcZ$sp(SMimeParseSpec.scala:31)
[error] ! parse a signed MDN with CMSSignedData
[error] CMSException: IOException reading content. (null:-1)
[error] org.bouncycastle.cms.CMSContentInfoParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$2.apply$mcZ$sp(SMimeParseSpec.scala:35)
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1StreamParser.readObject(Unknown Source)
[error] org.bouncycastle.cms.CMSContentInfoParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$2.apply$mcZ$sp(SMimeParseSpec.scala:35)
[error] DER length more than 4 bytes: 111
[error] org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown Source)
[error] org.bouncycastle.asn1.ASN1StreamParser.readObject(Unknown Source)
[error] org.bouncycastle.cms.CMSContentInfoParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] org.bouncycastle.mail.smime.SMIMESignedParser.<init>(Unknown Source)
[error] com.elemica.service.mdn.SMimeParseSpec$$anonfun$1$$anonfun$apply$2.apply$mcZ$sp(SMimeParseSpec.scala:35)
Any thoughts on what I can do to successfully parse the MDN would be appreciated.
Thanks,
Cale
Cale Davis | Software Developer | Elemica
780 Johnson Ferry Road | Suite 400 | Atlanta, Georgia | 30342
Mobile: +1 770 286 2645
Skype: cale.davis.elemica
www.elemica.com<http://www.elemica.com/>
This message contains confidential or privileged information and is intended only for the individual named. If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Nothing in this email is intended to bind Elemica, Inc., which only operates under the terms of written agreements signed by an authorized officer. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission.