Wrox Programmer Forums
|
BOOK: Beginning Cryptography with Java
This is the forum to discuss the Wrox book Beginning Cryptography with Java by David Hook; ISBN: 9780764596339
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Cryptography with Java section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2007, 04:42 PM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rajkaushik
Default Chapter 9

Using javamail 1.4
Jdk 1.5
BouncyCastle 1.35
=================


Hi
I am following the combining sign with encryption code:

MimeMessage msg = (MimeMessage)cGenerator.submitTask(lineByteArray);
The msg object is not null, as I can see some part of it
-----------------------------------------------------------
===> msg.writeTo(System.out);
From: ctg@cme.epiphany.com
To: aodrisco01@epiphany.com
Message-ID: 20070110032519.1148042987.0.-1.1522@@cme.epiphany.com
Subject: French content
MIME-Version: 1.0
Content-Type: application/pkcs7-mime; name="smime.p7m"; smime-type=enveloped-data
Content-Transfer-Encoding: 7bit
---------------------------------------------------------------
when I do the following, I get the null pointer.
Could you pl guide me how to debug this part.


SMIMEEnveloped enveloped = new SMIMEEnveloped(msg);


Time: 5.516
There was 1 error:
1) testSmime(com.infor.jobfile.TestCTGSecurity)java.l ang.NullPointerException
    at org.bouncycastle.asn1.cms.ContentInfo.getInstance( Unknown Source)
    at org.bouncycastle.cms.CMSUtils.readContentInfo(Unkn own Source)
    at org.bouncycastle.cms.CMSUtils.readContentInfo(Unkn own Source)
    at org.bouncycastle.cms.CMSEnvelopedData.<init>(Unkno wn Source)
    at org.bouncycastle.mail.smime.SMIMEEnveloped.<init>( Unknown Source)
    at com.infor.jobfile.TestCTGSecurity.testSmime(TestCT GSecurity.java:155)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at com.infor.jobfile.TestCTGSecurity.main(TestCTGSecu rity.java:207)





 
Old January 11th, 2007, 03:54 PM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rajkaushik
Default

Some more info:

                  System.out.println("mbp.getContent()=" + mbp.getContent());
                  msg.setContent(mbp.getContent(), mbp.getContentType());
                  msg.saveChanges();
                  System.out.println("msg.getContent()=" + msg.getContent());
                  System.out.println("msg.getContentType()=" + msg.getContentType());


=====
OUTPUT
mbp.getContent()=org.bouncycastle.mail.smime.SMIME EnvelopedGenerator$ContentEncryptor@1938039
msg.getContent()=org.bouncycastle.mail.smime.SMIME EnvelopedGenerator$ContentEncryptor@1938039
msg.getContentType()=application/pkcs7-mime; name="smime.p7m"; smime-type=enveloped-data

But when I inspect the msg object, the content and contentstream attributes are always null.
E

 
Old January 11th, 2007, 07:35 PM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

An enveloped message will normally have a content transfer encoding of either base64 or binary. It is not possible to transfer one correctly with an encoding of 7bit (the data is binary).

I'm guessing that the data is really base64 but that the message has the wrong content-transfer-encoding. Try correcting the encoding to base64 and see if things behave differently.

Regards,

David
 
Old January 15th, 2007, 02:48 PM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rajkaushik
Default

Hi David:
Changing Content-Transfer-Encoding to "base64" or "binary" didn't work.

In the first run, I printed the message just to make sure that the
encoding is binary/base64
----------------------------

     [java] From: "Eric H. Echidna" <eric@bouncycastle.org>
     [java] at javax.mail.internet.MimeMessage.writeTo(MimeMessag e.java:1659
)
     [java] To: example@bouncycastle.org
     [java] at chapter9.EnvelopedSignedMailExample.main(Unknown Source)
     [java] Message-ID: <16316379.31168886611156.JavaMail.rkaushik@catorka ushik>

     [java] Subject: example signed and enveloped message
     [java] MIME-Version: 1.0
     [java] Content-Type: application/pkcs7-mime; name="smime.p7m"; smime-type=e
nveloped-data
     [java] Content-Transfer-Encoding: base64

     [java] Java Result: 1

BUILD SUCCESSFUL
Total time: 7 seconds

Second Run: you still get the NullPointerException


C:\project1\beg-crypto-examples>ant run
Buildfile: build.xml

build:
    [javac] Compiling 1 source file to C:\project1\beg-crypto-examples\bin

run:
     [java] Exception in thread "main" java.lang.NullPointerException
     [java] at org.bouncycastle.asn1.cms.ContentInfo.getInstance( Unknown Sou
rce)
     [java] at org.bouncycastle.cms.CMSUtils.readContentInfo(Unkn own Source)

     [java] at org.bouncycastle.cms.CMSUtils.readContentInfo(Unkn own Source)

     [java] at org.bouncycastle.cms.CMSEnvelopedData.<init>(Unkno wn Source)
     [java] at org.bouncycastle.mail.smime.SMIMEEnveloped.<init>( Unknown Sou
rce)
     [java] at chapter9.EnvelopedSignedMailExample.main(Unknown Source)
     [java] Java Result: 1

 
Old January 15th, 2007, 08:52 PM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

If you can send me the message I'll take a look at it.

It really does sound like the message body is invalid though.

Regards,

David dgh@bund.com.au






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
chapter 7 - chapter 11 pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 3 January 6th, 2008 11:40 AM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.