[Webfunds-commits] java/webfunds/client/contracts/wizard FinishSig.java

Edwin Woudt edwin@cypherpunks.ai
Wed, 16 Aug 2000 04:30:38 -0400 (AST)


edwin       00/08/16 04:30:38

  Modified:    webfunds/client/contracts/wizard FinishSig.java
  Log:
  Use new more resilient method for reading keys.
  This fixes a bug where gnupg added a proprietary packet to the beginniing of
  a secret key and the wizard could not read it.

Revision  Changes    Path
1.4       +30 -21    java/webfunds/client/contracts/wizard/FinishSig.java

Index: FinishSig.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/FinishSig.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FinishSig.java	2000/08/15 23:22:34	1.3
+++ FinishSig.java	2000/08/16 08:30:37	1.4
@@ -1,5 +1,5 @@
 /*
- * $Id: FinishSig.java,v 1.3 2000/08/15 23:22:34 edwin Exp $
+ * $Id: FinishSig.java,v 1.4 2000/08/16 08:30:37 edwin Exp $
  *
  * Copyright (c) Systemics Inc 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -8,21 +8,21 @@
 package webfunds.client.contracts.wizard;
 
 
-import cryptix.openpgp.PGPException;
+import cryptix.openpgp.PGPAbstractDataFormatException;
 import cryptix.openpgp.PGPMessage;
-import cryptix.openpgp.PGPPublicKey;
+import cryptix.openpgp.PGPKeyFactory;
 import cryptix.openpgp.PGPSecretKey;
+import cryptix.openpgp.PGPWrongPassphraseException;
 import cryptix.openpgp.util.PGPArmoury;
 
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 
+import java.util.Vector;
+
 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
@@ -32,7 +32,7 @@
  * Panel that does the actual signing.
  *
  * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  */
 
 public class FinishSig extends WizardPanel 
@@ -207,23 +207,32 @@
                 error("Invalid contract key, not armoured?",iae);
                 return false;
             }
-        
-            ByteArrayInputStream bais = new ByteArrayInputStream(akey.getPayload());
-            DataInputStream dis = new DataInputStream(bais);
-        
         
+
             // get the unarmoured secret key
-            PGPSecretKey skey = new PGPSecretKey();
+            PGPKeyFactory factory = new PGPKeyFactory();
+            PGPSecretKey skey;
             try {
-                skey.readKey(dis);
-            } catch (PGPException pe) {
-                error("Error parsing contract",pe);
-                return false;
-            }
-            try {
+                
+                Vector keys = factory.decodeKeys(akey.getPayload());
+                if (keys.size() > 1) {
+                    error("More than one key found in input file", null);
+                    return false;
+                } else if (keys.size() < 1) {
+                    error("No key found in input file", null);         
+                    return false;
+                }                
+                skey = (PGPSecretKey)keys.elementAt(0);
                 skey.decrypt(txtPass.getText());
-            } catch (PGPException pe) {
-                error("Wrong passphrase", pe);
+                
+            } catch (PGPWrongPassphraseException wpe) {
+                error("Wrong passphrase", wpe);
+                return false;
+            } catch (PGPAbstractDataFormatException ape) {
+                error("Error parsing contract key", ape);
+                return false;
+            } catch (ClassCastException cce) {
+                error("No secret key found",cce);
                 return false;
             }
         
@@ -266,4 +275,4 @@
     }
     
     
-}
\ No newline at end of file
+}