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

Edwin Woudt edwin@cypherpunks.ai
Mon, 28 Aug 2000 11:14:03 -0400 (AST)


edwin       00/08/28 11:14:03

  Modified:    webfunds/client/contracts/wizard KeyContract.java
  Log:
  Fix a few bugs where the wrong keys were verified if the user selected
  to keep the existing key.
  Also fix a bug where the 'override' window was displayed after reading
  a key failed.

Revision  Changes    Path
1.12      +28 -18    java/webfunds/client/contracts/wizard/KeyContract.java

Index: KeyContract.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/KeyContract.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- KeyContract.java	2000/08/28 14:44:51	1.11
+++ KeyContract.java	2000/08/28 15:14:03	1.12
@@ -1,5 +1,5 @@
 /*
- * $Id: KeyContract.java,v 1.11 2000/08/28 14:44:51 edwin Exp $
+ * $Id: KeyContract.java,v 1.12 2000/08/28 15:14:03 edwin Exp $
  *
  * Copyright (c) Systemics Inc 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -26,7 +26,7 @@
  * Panel that asks for the contract key
  *
  * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
  */
 
 public class KeyContract extends SignContractWizardPanel 
@@ -313,10 +313,12 @@
             return false;
         }
 
+        String publicString;
+        
         if (fileName.length() != 0)        // got a name, try for a key
         {
-            String s = loadStringFromFile(fileName, "contract public key");
-            if (s == null)
+            publicString = loadStringFromFile(fileName, "contract public key");
+            if (publicString == null)
                 return false;
     
             String topLevelKey = data.getTopLevelKey();
@@ -330,16 +332,20 @@
             }
 
 
-            s = checkPublicContractKey(s, topLevelKey);
-            if (s == null)
+            publicString = checkPublicContractKey(publicString, topLevelKey);
+            if (publicString == null)
                 return false;
     
             //  ok, so a good key, should we override and use it?
-            if ( alreadyGotAKey && !confirm("override existing contract key?") )
-                return false;
+            if ( alreadyGotAKey 
+                       && !confirm("Override existing public contract key?") ) {
+                publicString = existing;
+            }
+
+        } else {
 
-            data.setPublicContractKey(s);
-            existing = data.getPublicContractKey();
+            // no filename given, use existing key        
+            publicString = existing;
             
         }
 
@@ -358,6 +364,15 @@
         if (secretString == null)
             return false;
 
+        
+        if (existing.length() > 0)         // there was a key there before
+        {
+            if (!confirm("override existing contract secret key?"))
+                secretString = existing;
+        }
+                                              
+
+        // convert to keys for checking
         PGPSecretKey seckey;
         try {
             seckey = KeyUtil.secretKeyFromString(secretString);
@@ -367,8 +382,6 @@
         }
 
 
-        String publicString = data.getPublicContractKey();
-        
         PGPPublicKey pubkey;
         try {
             pubkey = KeyUtil.publicKeyFromString(publicString);
@@ -378,18 +391,15 @@
         }
 
 
+        // check if public and secret key match
         if (!seckey.getKeyID().equals(pubkey.getKeyID())) {
             error("Secret key does not match public key.");
             return false;
         }
         
         
-        if (existing.length() > 0)         // there was a key there before
-        {
-            if (!confirm("override existing contract secret key?"))
-                return true;
-        }
-                                              
+
+        data.setPublicContractKey(publicString);
         data.setSecretContractKey(secretString);
         return true;