|
From: zhao <hy...@ya...> - 2007-04-02 17:51:35
|
From: zhao <hy...@ya...>
To: Christian Brien <ch...@br...>; Edwin Woudt <ed...@cr...>; Naresh Arige <AR...@em...>; "Mar...@We..." <Mar...@We...>
Sent: Monday, April 2, 2007 10:43:41 AM
Subject: Re: [Cryptix-users] cryptix.openpgp.PGPFatalDataFormatException: Read tried past end of inputstream
Here is a detailed stack trace:
cryptix.openpgp.PGPFatalDataFormatException: Read tried past end of inputstream.
at cryptix.openpgp.io.PGPLengthDataInputStream.readDirect(PGPLengthDataInputStream.java:123)
at cryptix.openpgp.io.PGPLengthDataInputStream.readInternal(PGPLengthDataInputStream.java:163)
at cryptix.openpgp.io.PGPLengthDataInputStream.readBuffer(PGPLengthDataInputStream.java:286)
at cryptix.openpgp.io.PGPLengthDataInputStream.readBuffer(PGPLengthDataInputStream.java:250)
at cryptix.openpgp.io.PGPLengthDataInputStream.readByteArray(PGPLengthDataInputStream.java:321)
at
cryptix.openpgp.packet.PGPEncryptedDataPacket.decodeBody(PGPEncryptedDataPacket.java:452)
at cryptix.openpgp.packet.PGPPacketFactory.readPacket(PGPPacketFactory.java:236)
at cryptix.openpgp.provider.PGPMessageFactory.generateBinary(PGPMessageFactory.java:205)
at cryptix.openpgp.provider.PGPMessageFactory.engineGenerateMessages(PGPMessageFactory.java:76)
at cryptix.message.MessageFactory.generateMessages(MessageFactory.java:142)
Also I found someone posted this issue at 12/15/2005, Did it get fixed at time? Or is there any workaround on this issue?
-------------------------
: Ramanathan, Alagammai \(Cognizant\)
<Alagammai@co...>
cryptix.openpgp.PGPFatalDataFormatException: Read
tried past end of inputstream.
2005-12-15 03:30
----------------
Thanks
Jack
----- Original Message ----
From: zhao <hy...@ya...>
To: Christian Brien <ch...@br...>
Cc: Edwin Woudt <ed...@cr...>
Sent: Thursday, March 29, 2007 9:08:24 AM
Subject: Re: [Cryptix-users] cryptix.openpgp.PGPFatalDataFormatException: Read tried past end of inputstream
Hi, Christian:
I think the problem is from PGPMessageFactory line 201-205, But I am not sure how to fix it since I am not sure the detial of your code.
I also attached a java file and two zip files, which you can run to debug the code.
Please follow these steps:
1: encrypt the two zip files into two encrypted gpg files using some public key , after this you will have two encrypted file,, for example BookSmall.zip.gpg and BookBig.zip.gpg
2: In the java program, please change the privateKeyFileName and passPhrase
3: For gpgFileName , you can using the small one and big one to see the difference, small size ziped encrypted file works fine, but the big one does not.
4:If you have any question, please feel free to let me know.
Thanks
Jack
============================
Here is my java code
============================
package com.aa.net.t1;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Collection;
import cryptix.message.EncryptedMessage;
import cryptix.message.KeyBundleMessage;
import cryptix.message.LiteralMessage;
import cryptix.message.Message;
import cryptix.message.MessageFactory;
import cryptix.message.SignedMessage;
import cryptix.pki.KeyBundle;
/**
* @author jzhao
*
*/
public class Tt1 {
/**
* @param args
*/
public static void main(String[] args) {
String privateKeyFileName="Your_Private_Key"; ///Change this to your private key file name
String passPhrase="Your_passPhrase"; ///Change this to your passPhrase
String gpgFileName = "BookSmall.zip.gpg"; //this small one works
//String gpgFileName = "BookBig.zip.gpg"; //this big does not work
testZipDecryptNewVersion(gpgFileName, privateKeyFileName, passPhrase);// this is not working
}
public static void testZipDecryptNewVersion(String encryptedFileName, String privateKeyFileName, String passPhrase)
{
String gpgFileName = encryptedFileName;
String decryptedFileName="Dcrypted_"+encryptedFileName.substring(0,encryptedFileName.length()-4);
java.security.Security.addProvider( new cryptix.jce.provider.CryptixCrypto() );
java.security.Security.addProvider( new cryptix.openpgp.provider.CryptixOpenPGP() );
try
{
// Read the key
FileInputStream inKey = new FileInputStream( privateKeyFileName );
// read the key messages into keybundle
MessageFactory mf = MessageFactory.getInstance( "OpenPGP" );
Collection msgsK = mf.generateMessages( inKey );
KeyBundleMessage kbm = (KeyBundleMessage) msgsK.iterator().next();
KeyBundle bundle = kbm.getKeyBundle();
inKey.close();
FileInputStream in=null;
try {
in = new FileInputStream( gpgFileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FileOutputStream out=null;
try {
out = new FileOutputStream( decryptedFileName );
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Message msg = null;
// InputStream is passed from the process itself
Collection msgs = mf.generateMessages( in );
msg = (Message) msgs.iterator().next();
// **********************************************************************
// Decrypt the message.
// **********************************************************************
if (msg instanceof EncryptedMessage)
{
msg = ((EncryptedMessage) msg).decrypt( bundle, passPhrase.toCharArray() );
}
if (msg instanceof SignedMessage)
{
msg = ((SignedMessage) msg).getContents();
}
if (msg instanceof LiteralMessage)
{
out.write( ((LiteralMessage) msg).getBinaryData() );
}
System.out.println("OK--done, check out the decrypted file : "+decryptedFileName);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
============================
+++++++++++++++++++++++++++++++++++++++
possible bug from here
++++++++++++++++++++++++++++++++++++
private Collection generateBinary(InputStream in)
throws MessageException, IOException
{
PGPPacketFactory pf = PGPPacketFactory.getDefaultInstance();
PGPAlgorithmFactory af = PGPAlgorithmFactory.getDefaultInstance();
PGPPacket pkt = null;
Vector result = new Vector();
Vector sessionkeys = new Vector();
while (in.available() > 0) {
try {
in.mark(16384);
pkt = pf.readPacket(in, af);
} catch (PGPDataFormatException dfe) {
throw
new
MessageException(""+dfe);
} catch (PGPFatalDataFormatException fdfe) {
throw new MessageException(""+fdfe);
}
.......
++++++++++++++++++++++++++++++++++++++
Thanks!
----- Original Message ----
From: Christian Brien <ch...@br...>
To: zhao <hy...@ya...>
Sent: Thursday, March 29, 2007 12:19:08 AM
Subject: Re: [Cryptix-users] cryptix.openpgp.PGPFatalDataFormatException: Read tried past end of inputstream
Hi Zhao,
I'm using the PGPDecodedMessageInputStream for decryption. The thing
is that i encountered a similar error there with some files of a
certain filesize. During debugging i found a small error in the
PGPDecodedMessageInputStream class. After fixing this error it's now
working perfectly.
If you want to try this way for your files just change line 910 in
PGPDecodedMessageInputStream.java from:
if (size < temp.length) {
to:
if (size <= temp.length) {
and rebuild the cryptix-openpgp-provider.jar.
If you could send me a file that's causing such an error i will have a
look through the PGPMessageFactory as well.
Regards,
Christian
Zitat
von zhao <hy...@ya...>:
> Hi, Christian:
>
> Here is another useful information, which is it is working fine
> if I decrypt this big abc.zip.gpg by GPGKeys/GPGTool.
>
> It is not working if I decrypt the big abc.zip.gpg inside my java code
>
> It is working if I decrypt the small abc.zip.gpg inside my java code.
>
>
> =====================
> here is the source code:
>
> public class Decrypter
> {
> private String passPhrase = null;
> private KeyBundle bundle = null;
> private MessageFactory mf = null;
>
> public Decrypt(String keyname, String passPhrase)
>
{
> try{
> this.passPhrase = passPhrase;
> FileInputStream in = new FileInputStream( keyname );
> // read the key messages into keybundle
> mf = MessageFactory.getInstance( "OpenPGP" );
> Collection msgs = mf.generateMessages( in );
> KeyBundleMessage kbm = (KeyBundleMessage) msgs.iterator().next();
> bundle =
kbm.getKeyBundle();
> in.close();
> }
> catch (Exception e)
> {
> log.error( "Error in Decrypt constructor." );
> throw new DecryptException( e );
> }
>
> }
>
> public void decrypt(InputStream in, OutputStream out)
> {
> //
> **********************************************************************
> // Read the
message.
> //
> **********************************************************************
> Message msg = null;
> try
> {
> // InputStream is passed from the process itself
> Collection msgs = mf.generateMessages( in );
> msg = (Message) msgs.iterator().next();
> //
> **********************************************************************
> //
Decrypt the message.
> //
> **********************************************************************
> if (msg instanceof EncryptedMessage)
> {
> msg = ((EncryptedMessage) msg).decrypt( bundle,
> passPhrase.toCharArray() );
> }
> if (msg instanceof SignedMessage)
> {
> msg =
((SignedMessage) msg).getContents();
> }
> if (msg instanceof LiteralMessage)
> {
> out.write( ((LiteralMessage) msg).getBinaryData() );
> }
> }
> catch (Exception e)
> {
> log.error( "Error during decrypting." ,e);
> throw new DecryptException( e
);
> }
> }
> }
> ================================
>
>
> Thanks!
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
It's here! Your new message!
Get
new email alerts with the free Yahoo! Toolbar.
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html |