From: <ed...@bo...> - 2003-08-23 11:37:59
|
edwin 03/08/23 07:37:56 Modified: openpgp CHANGELOG.TXT openpgp/src/cryptix/openpgp/provider PGPDetachedSignatureMessageImpl.java PGPMessageFactory.java openpgp/src/cryptix/openpgp/test/interop PGP8Interop.java Added: openpgp/src/testdata PGP8_sig_DHDSS.pgp PGP8_sig_RSAleg.pgp PGP8_sig_RSAnew.pgp Log: More PGP8 interop testing: - Fixed support for stand alone signed messages that did not use a OnePassSignature packet. Revision Changes Path 1.23 +2 -0 projects/openpgp/CHANGELOG.TXT Index: CHANGELOG.TXT =================================================================== RCS file: /home/cryptix-cvs/cvsroot/projects/openpgp/CHANGELOG.TXT,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- CHANGELOG.TXT 23 Aug 2003 10:14:08 -0000 1.22 +++ CHANGELOG.TXT 23 Aug 2003 11:37:55 -0000 1.23 @@ -23,6 +23,8 @@ - Fixed a NullPointerException in PGPSignedMessageImpl for encrypted and signed messages that did not use a OnePassSignature packet (these messages are generated by PGP when encrypting to a Legacy RSA key). +- Fixed support for stand alone signed messages that did not use a + OnePassSignature packet. - Encryption to keys that only have one key (that is used for both signing and encryption) is now supported. - Added support for the new SHA-1 based checksum for encrypting secret keys. 1.2 +13 -1 projects/openpgp/src/cryptix/openpgp/provider/PGPDetachedSignatureMessageImpl.java Index: PGPDetachedSignatureMessageImpl.java =================================================================== RCS file: /home/cryptix-cvs/cvsroot/projects/openpgp/src/cryptix/openpgp/provider/PGPDetachedSignatureMessageImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PGPDetachedSignatureMessageImpl.java 27 Dec 2001 14:40:28 -0000 1.1 +++ PGPDetachedSignatureMessageImpl.java 23 Aug 2003 11:37:55 -0000 1.2 @@ -1,4 +1,4 @@ -/* $Id: PGPDetachedSignatureMessageImpl.java,v 1.1 2001/12/27 14:40:28 edwin Exp $ +/* $Id: PGPDetachedSignatureMessageImpl.java,v 1.2 2003/08/23 11:37:55 edwin Exp $ * * Copyright (C) 2001 The Cryptix Foundation Limited. * All rights reserved. @@ -33,7 +33,7 @@ * Represents a detached signature. * * @author Edwin Woudt <ed...@cr...> - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ public class PGPDetachedSignatureMessageImpl extends PGPDetachedSignatureMessage @@ -58,6 +58,18 @@ this.pkt = pkt; } + +// Own methods +// .......................................................................... + + /** + * Return the contained packet. + */ + public PGPSignaturePacket getPacket() + { + return pkt; + } + // Verify methods // .......................................................................... 1.4 +43 -9 projects/openpgp/src/cryptix/openpgp/provider/PGPMessageFactory.java Index: PGPMessageFactory.java =================================================================== RCS file: /home/cryptix-cvs/cvsroot/projects/openpgp/src/cryptix/openpgp/provider/PGPMessageFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PGPMessageFactory.java 4 Feb 2003 13:22:56 -0000 1.3 +++ PGPMessageFactory.java 23 Aug 2003 11:37:55 -0000 1.4 @@ -1,4 +1,4 @@ -/* $Id: PGPMessageFactory.java,v 1.3 2003/02/04 13:22:56 edwin Exp $ +/* $Id: PGPMessageFactory.java,v 1.4 2003/08/23 11:37:55 edwin Exp $ * * Copyright (C) 2001 The Cryptix Foundation Limited. * All rights reserved. @@ -53,7 +53,7 @@ * Service provider interface for MessageFactory * * @author Edwin Woudt <ed...@cr...> - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ public class PGPMessageFactory extends MessageFactorySpi { @@ -250,20 +250,54 @@ Enumeration en = ((PGPCompressedDataPacket)pkt).listPackets(); Object obj = en.nextElement(); - if (! (obj instanceof PGPLiteralDataPacket)) { - throw new MessageException("Invalid message format."); - } - PGPLiteralMessageImpl lm = new PGPLiteralMessageImpl( + if (obj instanceof PGPSignaturePacket) + { + Object obj2 = en.nextElement(); + + if (! (obj2 instanceof PGPLiteralDataPacket)) { + throw new MessageException("Invalid message format."); + } + + PGPSignedMessageImpl sm = new PGPSignedMessageImpl( + (PGPSignaturePacket)obj, new PGPLiteralMessageImpl( + (PGPLiteralDataPacket)obj2)); + + result.add(sm); + + } else { + + if (! (obj instanceof PGPLiteralDataPacket)) { + throw new MessageException("Invalid message format."); + } + + PGPLiteralMessageImpl lm = new PGPLiteralMessageImpl( (PGPLiteralDataPacket)obj); - result.add(lm); - + result.add(lm); + } + } else if (pkt instanceof PGPLiteralDataPacket) { PGPLiteralMessageImpl lm = new PGPLiteralMessageImpl( (PGPLiteralDataPacket)pkt); - result.add(lm); + + if ((result.size() > 0) && (result.elementAt(result.size()-1) + instanceof PGPDetachedSignatureMessageImpl)) + { + + PGPDetachedSignatureMessageImpl dsm = + (PGPDetachedSignatureMessageImpl) + result.remove(result.size() - 1); + PGPSignedMessageImpl sm = new PGPSignedMessageImpl( + dsm.getPacket(), lm); + result.add(sm); + + } else { + + result.add(lm); + + } } else if (pkt instanceof PGPSignaturePacket) { 1.2 +28 -1 projects/openpgp/src/cryptix/openpgp/test/interop/PGP8Interop.java Index: PGP8Interop.java =================================================================== RCS file: /home/cryptix-cvs/cvsroot/projects/openpgp/src/cryptix/openpgp/test/interop/PGP8Interop.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PGP8Interop.java 23 Aug 2003 10:35:58 -0000 1.1 +++ PGP8Interop.java 23 Aug 2003 11:37:55 -0000 1.2 @@ -1,4 +1,4 @@ -/* $Id: PGP8Interop.java,v 1.1 2003/08/23 10:35:58 edwin Exp $ +/* $Id: PGP8Interop.java,v 1.2 2003/08/23 11:37:55 edwin Exp $ * * Copyright (C) 1999-2002 The Cryptix Foundation Limited. * All rights reserved. @@ -61,6 +61,7 @@ Iterator it; KeyBundle prvDHDSS, pubDHDSS, prvRSAleg, pubRSAleg, prvRSAnew, pubRSAnew; MessageFactory mf = MessageFactory.getInstance("OpenPGP"); + in = new FileInputStream(new File(_testdir, "PGP8_testkey_DHDSS.asc")); msgs = mf.generateMessages(in); @@ -89,6 +90,7 @@ pubRSAnew = kbm.getKeyBundle(); in.close(); + in = new FileInputStream(new File(_testdir, "PGP8_enc_DHDSS_sig_RSAleg.asc")); msgs = mf.generateMessages(in); it = msgs.iterator(); @@ -115,6 +117,31 @@ assertTrue("Correctly signed", sm.verify(pubRSAnew)); lm = (LiteralMessage)sm.getContents(); assertEquals("Decrypted data", "Hello", lm.getTextData()); + + + in = new FileInputStream(new File(_testdir, "PGP8_sig_DHDSS.pgp")); + msgs = mf.generateMessages(in); + it = msgs.iterator(); + sm = (SignedMessage)msgs.iterator().next(); + assertTrue("Correctly signed", sm.verify(pubDHDSS)); + lm = (LiteralMessage)sm.getContents(); + assertEquals("Signed data", "Hello", lm.getTextData()); + + in = new FileInputStream(new File(_testdir, "PGP8_sig_RSAnew.pgp")); + msgs = mf.generateMessages(in); + it = msgs.iterator(); + sm = (SignedMessage)msgs.iterator().next(); + assertTrue("Correctly signed", sm.verify(pubRSAnew)); + lm = (LiteralMessage)sm.getContents(); + assertEquals("Signed data", "Hello", lm.getTextData()); + + in = new FileInputStream(new File(_testdir, "PGP8_sig_RSAleg.pgp")); + msgs = mf.generateMessages(in); + it = msgs.iterator(); + sm = (SignedMessage)msgs.iterator().next(); + assertTrue("Correctly signed", sm.verify(pubRSAleg)); + lm = (LiteralMessage)sm.getContents(); + assertEquals("Signed data", "Hello", lm.getTextData()); } |