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

Edwin Woudt edwin@cypherpunks.ai
Mon, 28 Aug 2000 10:44:51 -0400 (AST)


edwin       00/08/28 10:44:51

  Modified:    webfunds/client/contracts/wizard KeyContract.java
  Log:
  - Check if the public and secret key match.
  - Remove usage of KeyUtil.secretKeyToString as it is not really necessairy

Revision  Changes    Path
1.11      +22 -12    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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- KeyContract.java	2000/08/28 13:37:13	1.10
+++ KeyContract.java	2000/08/28 14:44:51	1.11
@@ -1,5 +1,5 @@
 /*
- * $Id: KeyContract.java,v 1.10 2000/08/28 13:37:13 edwin Exp $
+ * $Id: KeyContract.java,v 1.11 2000/08/28 14:44:51 edwin Exp $
  *
  * Copyright (c) Systemics Inc 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -15,6 +15,7 @@
 import java.awt.event.*;
 import javax.swing.*;
 
+import cryptix.openpgp.PGPPublicKey;
 import cryptix.openpgp.PGPSecretKey;
 
 import webfunds.ricardian.KeyUtil;
@@ -25,7 +26,7 @@
  * Panel that asks for the contract key
  *
  * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
  */
 
 public class KeyContract extends SignContractWizardPanel 
@@ -357,30 +358,39 @@
         if (secretString == null)
             return false;
 
-        PGPSecretKey secret;
+        PGPSecretKey seckey;
         try {
-            secret = KeyUtil.secretKeyFromString(secretString);
+            seckey = KeyUtil.secretKeyFromString(secretString);
         } catch (ArmouredKeyException ex) {
             error("Contract secret key: " + ex);
             return false;
         }
 
-        // how to do this?
-        // if (!secret.matches(key))
-        // {
-        //     error("secret key is not for this " + tag + " key");
-        //     return false;
-        // {
+
+        String publicString = data.getPublicContractKey();
         
-        String key2 = KeyUtil.secretKeyToString(secret);
+        PGPPublicKey pubkey;
+        try {
+            pubkey = KeyUtil.publicKeyFromString(publicString);
+        } catch (ArmouredKeyException ex) {
+            error("Contract secret key: " + ex);
+            return false;
+        }
 
+
+        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.setSecretContractKey(key2);
+        data.setSecretContractKey(secretString);
         return true;
 
     }