|
From: <ed...@bo...> - 2003-08-23 06:36:10
|
edwin 03/08/23 02:36:05
Modified: openpgp CHANGELOG.TXT
openpgp/src/cryptix/openpgp/packet
PGPCompressedDataPacket.java
openpgp/src/cryptix/openpgp/test/all TestOpenPGP.java
Added: openpgp/src/cryptix/openpgp/io
PGPZLibInputStreamAdapter.java
openpgp/src/cryptix/openpgp/test/interop ZLibEOFTest.java
openpgp/src/testdata zlib_eof.asc
Log:
- Fixed the infamous EOFException: Unexpected end of ZLIB input stream.
Revision Changes Path
1.21 +2 -1 projects/openpgp/CHANGELOG.TXT
Index: CHANGELOG.TXT
===================================================================
RCS file: /home/cryptix-cvs/cvsroot/projects/openpgp/CHANGELOG.TXT,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- CHANGELOG.TXT 23 Aug 2003 02:22:11 -0000 1.20
+++ CHANGELOG.TXT 23 Aug 2003 06:36:04 -0000 1.21
@@ -7,7 +7,8 @@
public key and principal that are signed as well. This is more like
what other Certificate implementations do, and it also allows one to
construct a KeyBundle from the returned data again.
-Bugsfixes/new features
+Bugfixes/new features
+- Fixed the infamous EOFException: Unexpected end of ZLIB input stream.
- Snapshots are now compiled on JDK 1.2, so that they continue to work on that
version of the JDK. Due to a Sun API change, a library compiled on JDK 1.3 or
higher would not work on JDK 1.2.
1.1 projects/openpgp/src/cryptix/openpgp/io/PGPZLibInputStreamAdapter.java
Index: PGPZLibInputStreamAdapter.java
===================================================================
/* $Id: PGPZLibInputStreamAdapter.java,v 1.1 2003/08/23 06:36:05 edwin Exp $
*
* Copyright (C) 1999-2003 The Cryptix Foundation Limited.
* All rights reserved.
*
* Use, modification, copying and distribution of this software is subject
* the terms and conditions of the Cryptix General Licence. You should have
* received a copy of the Cryptix General License along with this library;
* if not, you can download a copy from http://www.cryptix.org/ .
*/
package cryptix.openpgp.io;
import cryptix.openpgp.PGPDataFormatException;
import cryptix.openpgp.PGPFatalDataFormatException;
import java.io.IOException;
import java.io.InputStream;
/**
* Special version of PGPInputStreamAdapter that outputs an extra dummy byte.
*
* <p>
* This solves a bug where java.util.zip.Inflate expects an extra dummy byte at
* the end of the compressed stream and crashes with an EOFException if it is
* not there.
* </p>
*
* @see cryptix.openpgp.io.PGPOutputStreamAdapter
*
* @author Mathias Kolehmainen (ri...@ro...)
* @author Edwin Woudt (ed...@wo...)
* @version $Revision: 1.1 $
*/
public class PGPZLibInputStreamAdapter extends InputStream {
private PGPPacketDataInputStream in;
/**
* Construt the adapter which will use the given PGPPacketDataInputStream
* as the underlying input stream to which all method calls are forwarded.
*
* @param in a PGPPacketDatInputStream to read from.
*/
public PGPZLibInputStreamAdapter(PGPPacketDataInputStream in) {
this.in = in;
}
private boolean dummySent = false;
/**
* Calls readBuffer on the underlying stream passing in a newly
* allocated byte array for temporary storage.
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if an I/O error occurs, or if the underlying
* stream throws a PGPDataFormatException or a
* PGPFatalDataFormatException.
*/
public int read() throws IOException {
byte[] buf = new byte[1];
try {
int len = in.readBuffer(buf);
if (len > 0) return byteToInt(buf[0]);
if (dummySent) return -1;
dummySent = true;
return 0;
}
catch(PGPDataFormatException e) {
throw(new IOException("Data format exception: " + e.getMessage()));
}
catch(PGPFatalDataFormatException e) {
throw(new IOException("Fatal data format exception: " + e.getMessage()));
}
}
/**
* Calls the readBuffer method on the underlying stream.
*
* @param b the buffer into which the data is read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> is there is no more data because the end of
* the stream has been reached.
* @exception IOException if an I/O error occurs, or if the underlying
* stream throws a PGPDataFormatException or a
* PGPFatalDataFormatException.
* @see java.io.InputStream#read(byte[], int, int)
*/
public int read(byte b[]) throws IOException {
try {
int r = in.readBuffer(b);
if (r > 0) return r;
if (dummySent) return -1;
dummySent = true;
return 1;
}
catch(PGPDataFormatException e) {
throw(new IOException("Data format exception: " + e.getMessage()));
}
catch(PGPFatalDataFormatException e) {
throw(new IOException("Fatal data format exception: " + e.getMessage()));
}
}
/**
* Call the readBuffer method on the underlying stream.
*
* @param b the buffer into which the data is read.
* @param off the start offset in array <code>b</code>
* at which the data is written.
* @param len the maximum number of bytes to read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception IOException if an I/O error occurs, or if the underlying stream
* throws a PGPDataFormatException or a PGPFatalDataFormatException.
*/
public int read(byte b[], int off, int len) throws IOException {
try {
int r = in.readBuffer(b, off, len);
if (r > 0) return r;
if (dummySent) return -1;
dummySent = true;
return 1;
}
catch(PGPDataFormatException e) {
throw(new IOException("Data format exception: " + e.getMessage()));
}
catch(PGPFatalDataFormatException e) {
throw(new IOException("Fatal data format exception: " + e.getMessage()));
}
}
/**
* This adapter always returns zero here.
*
* @return zero.
* @exception IOException if an I/O error occurs.
*/
public int available() throws IOException {
return 0;
}
/**
* This adapter does not implement close, this method does nothing.
*
* @exception IOException if an I/O error occurs.
*/
public void close() throws IOException {}
/**
* Marking is not supported, this does nothing.
*/
public synchronized void mark(int readlimit) {}
/**
* Marking is not supported, this always throws an exception.
*
* @exception IOException is thrown whenever this is called.
*/
public synchronized void reset() throws IOException {
throw new IOException("mark/reset not supported");
}
/**
* Marking is not supported, so this always returns false.
*
*
* @return false
*/
public boolean markSupported() {
return false;
}
// Private helper methods
//...........................................................................
/**
* @param b an unsigned byte
* @return the byte represented as an int (0 - 255)
*/
private static final int byteToInt(byte b) {
int i = 0;
if ((b & 0x80) != 0) {
i |= 0x80;
b &= 0x7F;
}
i |= b;
return(i);
}
}
1.13 +4 -4 projects/openpgp/src/cryptix/openpgp/packet/PGPCompressedDataPacket.java
Index: PGPCompressedDataPacket.java
===================================================================
RCS file: /home/cryptix-cvs/cvsroot/projects/openpgp/src/cryptix/openpgp/packet/PGPCompressedDataPacket.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- PGPCompressedDataPacket.java 22 Apr 2002 17:46:12 -0000 1.12
+++ PGPCompressedDataPacket.java 23 Aug 2003 06:36:05 -0000 1.13
@@ -1,4 +1,4 @@
-/* $Id: PGPCompressedDataPacket.java,v 1.12 2002/04/22 17:46:12 edwin Exp $
+/* $Id: PGPCompressedDataPacket.java,v 1.13 2003/08/23 06:36:05 edwin Exp $
*
* Copyright (C) 1999-2002 The Cryptix Foundation Limited.
* All rights reserved.
@@ -17,10 +17,10 @@
import cryptix.openpgp.io.PGPCompressorInputStream;
import cryptix.openpgp.io.PGPCompressorOutputStream;
-import cryptix.openpgp.io.PGPInputStreamAdapter;
import cryptix.openpgp.io.PGPOutputStreamAdapter;
import cryptix.openpgp.io.PGPPacketDataInputStream;
import cryptix.openpgp.io.PGPPacketDataOutputStream;
+import cryptix.openpgp.io.PGPZLibInputStreamAdapter;
import cryptix.openpgp.algorithm.PGPAlgorithmFactory;
import cryptix.openpgp.algorithm.PGPCompressor;
@@ -45,7 +45,7 @@
* @see cryptix.openpgp.packet.PGPPacketFactory
*
* @author Mathias Kolehmainen (ri...@ro...)
- * @version $Revision: 1.12 $
+ * @version $Revision: 1.13 $
*/
public class PGPCompressedDataPacket extends PGPContainerPacket {
@@ -132,7 +132,7 @@
PGPCompressorInputStream expander;
try {
PGPCompressor cp = factory.getCompressionAlgorithm(alg);
- expander = cp.getExpansionStream(new PGPInputStreamAdapter(in));
+ expander = cp.getExpansionStream(new PGPZLibInputStreamAdapter(in));
} catch (NoSuchAlgorithmException nsae) {
in.readByteArray();
throw new PGPDataFormatException("id not found - "+nsae);
1.13 +2 -1 projects/openpgp/src/cryptix/openpgp/test/all/TestOpenPGP.java
Index: TestOpenPGP.java
===================================================================
RCS file: /home/cryptix-cvs/cvsroot/projects/openpgp/src/cryptix/openpgp/test/all/TestOpenPGP.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TestOpenPGP.java 22 Apr 2002 17:48:50 -0000 1.12
+++ TestOpenPGP.java 23 Aug 2003 06:36:05 -0000 1.13
@@ -1,4 +1,4 @@
-/* $Id: TestOpenPGP.java,v 1.12 2002/04/22 17:48:50 edwin Exp $
+/* $Id: TestOpenPGP.java,v 1.13 2003/08/23 06:36:05 edwin Exp $
*
* Copyright (C) 1999-2001 The Cryptix Foundation Limited.
* All rights reserved.
@@ -27,6 +27,7 @@
public TestSuite suite() {
TestSuite all = new TestSuite("All OpenPGP tests");
+ all.addTestSuite(cryptix.openpgp.test.interop.ZLibEOFTest.class);
all.addTestSuite(cryptix.openpgp.test.util.PGPCompareTest.class);
all.addTestSuite(cryptix.openpgp.test.util.PGPCRCTest.class);
all.addTestSuite(cryptix.openpgp.test.util.PGPMPITest.class);
1.1 projects/openpgp/src/cryptix/openpgp/test/interop/ZLibEOFTest.java
Index: ZLibEOFTest.java
===================================================================
/* $Id: ZLibEOFTest.java,v 1.1 2003/08/23 06:36:05 edwin Exp $
*
* Copyright (C) 1999-2002 The Cryptix Foundation Limited.
* All rights reserved.
*
* Use, modification, copying and distribution of this software is subject
* the terms and conditions of the Cryptix General Licence. You should have
* received a copy of the Cryptix General License along with this library;
* if not, you can download a copy from http://www.cryptix.org/ .
*/
package cryptix.openpgp.test.interop;
import cryptix.message.*;
import cryptix.openpgp.*;
import cryptix.pki.*;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.*;
import java.util.*;
public class ZLibEOFTest extends TestCase
{
private static final String FS = System.getProperty("file.separator");
private final File _testdir;
public ZLibEOFTest(String name)
{
super(name);
String td = System.getProperty("CRYPTIX_OPENPGP_TESTDIR");
if(td == null || "".equals(td) ) {
_testdir = new File("." + FS + "testdata");
}
else {
_testdir = new File(td + FS + "testdata");
}
}
protected void setUp() {
}
protected void tearDown() {
}
public void testZlibEOF()
throws Exception
{
FileInputStream in;
Collection msgs;
MessageFactory mf = MessageFactory.getInstance("OpenPGP");
in = new FileInputStream(new File(_testdir, "bob-secret.pgp.asc"));
msgs = mf.generateMessages(in);
KeyBundleMessage kbm = (KeyBundleMessage)msgs.iterator().next();
KeyBundle bundle = kbm.getKeyBundle();
in.close();
in = new FileInputStream(new File(_testdir, "zlib_eof.asc"));
msgs = mf.generateMessages(in);
EncryptedMessage em = (EncryptedMessage)msgs.iterator().next();
in.close();
Message msg = em.decrypt(bundle, "TestingPassphrase".toCharArray());
String data = ((LiteralMessage)msg).getTextData();
assertEquals("Decrypted data: ", "Hello", data);
}
}
1.1 projects/openpgp/src/testdata/zlib_eof.asc
Index: zlib_eof.asc
===================================================================
-----BEGIN PGP MESSAGE-----
Version: PGP 8.0.2
qANQR1DBwE4D0CKyoVrEnYIQBADgCqARKI1HqPUXLeQN/K6tzDUDOzTn+7Z36MPI
o9XKbbUWQwOtVxJr7BC+DSj6l7DkyPrlAc14EB0CXQSfa0mLYc7BBNlSF7DJdnZn
paJ0Cq0b0Yt02HPjkCneKLGC32ZlOjbgqJe9q3MkTH1wuLpMHsqbV+fI9x1jhaZ7
7jV3fwP/dRkRjEyJa78e9vfhZp9qQZYRM9KK/902eP7DQDT4mhT8i945EhmrY62F
+nUAZwzbxKDOSywTfePty8pDXFA46PM7owE+hq6Q6gbHXrmkQ4K1xx3tbyPVmw++
lhYK2rLCHpf75nFh+VkP4uwd5B0KEf/ORjlXijgzbsnVbISaE7rSOAHIIrhH3bnQ
9z47RWedm+JcLDfJxabaHQPmWDksObXlQuFzzgaknL48gujcDf7/ebzdnaBnttoI
=Uiwc
-----END PGP MESSAGE-----
|