• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checked streams

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm trying to create a checksum in an applet and send it to the servlet where it can be compared.

I'm having this code:

//mail is a MimeMessage object: a mail containing a bit of text and an attachment and a signature
URLConnection connection = getConnectionToServlet();
OutputStream emptyOutput = new OutputStream(){
public void write(int b) throws IOException {

}
};
CheckedOutputStream checkedOut = new CheckedOutputStream(emptyOutput,new CRC32());
mail.writeTo(checkedOut);
System.out.println("mail checksum over empty-output: "+checkedOut.getChecksum().getValue());
out = connection.getOutputStream();
CheckedOutputStream checkedOut2 = new CheckedOutputStream(out,new CRC32());
mail.writeTo(checkedOut2);
System.out.println("mail checksum over real-output: "+checkedOut2.getChecksum().getValue());



and it gives me the following output:
applet checksum over empty-output: 472918629
applet checksum over real-output: 2979688346

How can this be possible?? I would expect the checkedOutputStream would just take bytes, update checksum and at send bytes to the wrapped stream?
Can someone explain how this is possible?


Also,
when I put that code in a loop, I get results as:
applet checksum over empty-output: 472918629
applet checksum over real-output: 2979688346

applet checksum over empty-output: 1455969375
applet checksum over real-output: 2957360115

applet checksum over empty-output: 1607214671
applet checksum over real-output: 1607214671

So sometimes the checksum is the same... I do not understand.
Thanks.
Tim
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the checksums are different, are the bytes the same? That's the test you need to do.
 
Tim Deborg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Just checked and there seems to be some different bytes in the signature part of the mimemessage. Which is strange I would think because It's just the same object being written to a stream.

Even if I put the code that writes to an empty string in a loop, the result is most often different.

If someone has a clue about for what reason the bytes can change, ...
This is hard to debug (the signed part), but I will have to try. Tomorrow.

Thanks,
Tim
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know what's going on here, but I would try writing the message to System.out or to a file, and then looks at it (as text) to see if you can determine which header value is different. The name and value of the header can be important clues here. Perhaps something is auto-generating a new content ID, or a timestamp. Note that you can tell writeTo() to ignore certain headers - see writeTo(OutputStream, String[]).
[ August 23, 2007: Message edited by: Jim Yingst ]
 
Tim Deborg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
it's not one of the headers, it's a couple of bytes that differ in the signature part in the EML.

:s
 
Tim Deborg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added
properties.put("mail.mime.cachemultipart", "false");
to the javamail session properties and guess what?
It works on the servlet I use but it does not work on the applet :s
I also tried javamail 1.4, 1.1, 1.3.2, 1.4.1ea but no result.

I got my inspiration here: http://osdir.com/ml/encryption.bouncy-castle.devel/2006-07/msg00036.html
The property should make sure the multipart is not reencoded when sending to the stream, but it seems not to work in my applet...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic