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

Ian Grigg iang@cypherpunks.ai
Sat, 26 Aug 2000 19:35:08 -0400 (AST)


iang        00/08/26 19:35:07

  Modified:    webfunds/client/contracts/wizard KeyContract.java
                        KeyServer.java KeyTop.java
  Log:
  1.  upgraded the printed help messages, for space and content.  Need to
      check on other platforms, the borders may not be right...
  2.  added sanity checking, specifically using the KeyPanel utilities
      to ensure keys are stripped of surplus sigs.
  3.  rewrote the KeyContract.next() methods to use OpenPGP checking more
      directly where there is quite complex sanity checking to be done.
  4.  changed [cert] all over to [certification] as former was way too
      overloaded (spotted by Jeroen).  Actually this change is really in
      Contract.java...

Revision  Changes    Path
1.7       +99 -25    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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- KeyContract.java	2000/08/26 18:56:14	1.6
+++ KeyContract.java	2000/08/26 23:35:07	1.7
@@ -1,5 +1,5 @@
 /*
- * $Id: KeyContract.java,v 1.6 2000/08/26 18:56:14 gelderen Exp $
+ * $Id: KeyContract.java,v 1.7 2000/08/26 23:35:07 iang Exp $
  *
  * Copyright (c) Systemics Inc 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -18,12 +18,19 @@
 import java.awt.event.*;
 import javax.swing.*;
 
+import cryptix.openpgp.PGPException;
+import cryptix.openpgp.PGPPublicKey;
+import cryptix.openpgp.PGPSecretKey;
+import webfunds.ricardian.Contract;
 
+import webfunds.ricardian.KeyUtil;
+
+
 /**
  * Panel that asks for the contract key
  *
  * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
  */
 
 public class KeyContract extends KeyPanel 
@@ -52,6 +59,7 @@
         JButton    but;
         JLabel     lab;
 
+        final String tag = webfunds.ricardian.Contract.USERID_CONTRACT;
 
         // Ok, this is where the real dirty work starts. Do not attempt 
         // to change it, unless you understand the GridBagLayout and 
@@ -64,7 +72,7 @@
         c.fill       = GridBagConstraints.NONE;
         c.anchor     = GridBagConstraints.WEST;
         c.insets     = new Insets(5, 5, 5, 5);
-        lab = new JLabel("Select the contract signing PGP key."); 
+        lab = new JLabel("Select the " + tag + " signing PGP key."); 
         gridbag.setConstraints(lab,c); add(lab);
         
         
@@ -75,13 +83,10 @@
         c.anchor     = GridBagConstraints.WEST;
         c.insets     = new Insets(5, 5, 15, 5);
         lab = new JLabel("<html><font size='-1'><b>"+
-                         "In this step you will choose the PGP key that will "+
-                         "sign this contract. If you don't have one yet, then "+
-                         "you should create one with your favourite PGP "+
-                         "implementation. "+
-                         "Make sure it is a DH/DSS or DSA/ElGamal key and "+
-                         "that it is signed by the top-level issuer key. "+
-                         "</b></font></html>"); 
+                  "Select the file containing your "+
+                  tag +
+                  " key for signing this contract." +
+                  "</b></font></html>"); 
         gridbag.setConstraints(lab,c); add(lab);
 
         
@@ -164,13 +169,14 @@
         c.weighty    = 0;      c.weightx   = 1;
         c.fill       = GridBagConstraints.HORIZONTAL;
         c.anchor     = GridBagConstraints.WEST;
-        c.insets     = new Insets(5, 5, 10, 5);
+        c.insets     = new Insets(5, 5, 5, 5);
         lab = new JLabel("<html><font size='-1'><b>"+
-                         "In PGPKeys, click with the right mouse button on "+
-                         "key and select the 'Export' option. You will have "+
-                         "to do this two times, once with and once without "+
-                         "the private (secret) part of the key."+
-                         "</b></font></html>"); 
+                  "Right-Click on the "+
+                  tag +
+                  " key and select 'Export'. "+
+                  "Do this once <i>with</i> and once <i>without</i> "+
+                  "the private (secret) part of the key."+
+                  "</b></font></html>"); 
         gridbag.setConstraints(lab,c); add(lab);
         
 
@@ -189,18 +195,49 @@
         c.weighty    = 0;      c.weightx   = 1;
         c.fill       = GridBagConstraints.HORIZONTAL;
         c.anchor     = GridBagConstraints.WEST;
-        c.insets     = new Insets(5, 5, 0, 5);
+        c.insets     = new Insets(5, 5, 5, 5);
         lab = new JLabel("<html><font size='-1'><b>"+
-                  "Public key: 'gpg -a --export \"[contract]\" > key.asc'<br>"+
-                  "Secret key: 'gpg -a --export-secret-key \"[contract]\" > "+ 
-                  "skey.asc' "+
+                  "Public key: 'gpg -a --export \"" +
+                  tag +
+                  "\" > key.asc'<br>"+
+                  "Secret key: 'gpg -a --export-secret-key \"" +
+                  tag +
+                  "\" > skey.asc' "+
                   "</b></font></html>"); 
         gridbag.setConstraints(lab,c); add(lab);
         
 
+        c.gridheight = 1;      c.gridwidth = 2;
+        c.gridy      = 10;     c.gridx     = 0;
+        c.weighty    = 0;      c.weightx   = 0;
+        c.fill       = GridBagConstraints.NONE;
+        c.anchor     = GridBagConstraints.WEST;
+        c.insets     = new Insets(5, 5, 0, 5);
+        lab = new JLabel("Creating your OpenPGP " + tag + " key:"); 
+        gridbag.setConstraints(lab,c); add(lab);
+        
+        
+        c.gridheight = 1;      c.gridwidth = 2;
+        c.gridy      = 11;     c.gridx     = 0;
+        c.weighty    = 0;      c.weightx   = 1;
+        c.fill       = GridBagConstraints.HORIZONTAL;
+        c.anchor     = GridBagConstraints.WEST;
+        c.insets     = new Insets(5, 5, 5, 5);
+        lab = new JLabel("<html><font size='-1'><b>"+
+                  "Create a DH/DSS or DSA/ElGamal key "+
+                  "that it is self-signed and has the "+
+                  tag +
+                  " tag in the User Id field."+
+                  " Sign the key with your "+
+                  webfunds.ricardian.Contract.USERID_TOP_LEVEL +
+                  " key."+
+                  "</b></font></html>"); 
+        gridbag.setConstraints(lab,c); add(lab);
+
+
         // Filler, makes sure the whole thing is aligned to the top
         c.gridheight = 1;      c.gridwidth = 2;
-        c.gridy      = 10;      c.gridx     = 0;
+        c.gridy      = 12;     c.gridx     = 0;
         c.weighty    = 1;      c.weightx   = 0;
         c.fill       = GridBagConstraints.NONE;
         c.anchor     = GridBagConstraints.CENTER;
@@ -267,17 +304,54 @@
     }
 
     public boolean next() {
+
+        String s = data.getTopLevelKey();
+        PGPPublicKey topLevelKey;
+        try {
+            topLevelKey = KeyUtil.publicKeyFromString(s);
+        } catch (PGPException ex) {
+            error("no top level key available?", ex);
+            return false;
+        }
+        
+        PGPPublicKey contractKey = loadPublicKey(txtFile.getText());
+        if (contractKey == null)
+            return false;
 
-        String key = loadAndCheckPublicKey(txtFile.getText());
+System.err.println("CONTRACT -----------\n" + KeyUtil.publicKeyToString(contractKey));
+        final String tag = Contract.USERID_CONTRACT;
+        PGPPublicKey stripped;
+        try {
+            stripped = KeyUtil.stripAndVerifyKey(contractKey,
+                                          tag,
+                                          topLevelKey);
+        } catch (Exception ex) {
+            error("not fit for purpose or unsiged!", ex);
+            return false;
+        }
 
-        if (key != null) {
-            data.setPublicContractKey(key);
+        String contractKeyAsString = KeyUtil.publicKeyToString(stripped);
+System.err.println("\n\nCONTRACT +++++++++++\n" + contractKeyAsString);
+
+        if (contractKeyAsString != null) {
+            data.setPublicContractKey(contractKeyAsString);
         } else {
             return false;
         }
 
+        
+        PGPSecretKey secret = loadSecretKey(txtFile2.getText());
+        if (secret == null)
+            return false;
+
+        // how to do this?
+        // if (!secret.matches(key))
+        // {
+        //     error("secret key is not for this " + tag + " key");
+        //     return false;
+        // {
         
-        String key2 = loadAndCheckPrivateKey(txtFile2.getText());
+        String key2 = KeyUtil.secretKeyToString(secret);
 
         if (key2 != null) {
             data.setSecretContractKey(key2);



1.7       +23 -14    java/webfunds/client/contracts/wizard/KeyServer.java

Index: KeyServer.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/KeyServer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- KeyServer.java	2000/08/26 18:56:14	1.6
+++ KeyServer.java	2000/08/26 23:35:07	1.7
@@ -1,5 +1,5 @@
 /*
- * $Id: KeyServer.java,v 1.6 2000/08/26 18:56:14 gelderen Exp $
+ * $Id: KeyServer.java,v 1.7 2000/08/26 23:35:07 iang Exp $
  *
  * Copyright (c) Systemics Inc 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -18,12 +18,15 @@
 import java.awt.event.*;
 import javax.swing.*;
 
+import cryptix.openpgp.PGPPublicKey;
+import webfunds.ricardian.Contract;
+import webfunds.ricardian.KeyUtil;
 
 /**
- * Panel that asks for the server certification key
+ * Panel that asks for the [operator] certification key
  *
  * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
  */
 
 public class KeyServer extends KeyPanel 
@@ -63,7 +66,7 @@
         c.fill       = GridBagConstraints.NONE;
         c.anchor     = GridBagConstraints.WEST;
         c.insets     = new Insets(5, 5, 5, 5);
-        lab = new JLabel("Select the transaction server PGP key."); 
+        lab = new JLabel("Select the operator's server PGP key."); 
         gridbag.setConstraints(lab,c); add(lab);
         
         
@@ -74,10 +77,12 @@
         c.anchor     = GridBagConstraints.WEST;
         c.insets     = new Insets(5, 5, 15, 5);
         lab = new JLabel("<html><font size='-1'><b>"+
-                         "In this step you will choose the operator's PGP Key."+
-                         " You should have obtained it from your server "+
-                         "operator. "+
-                         "</b></font></html>"); 
+                  "Select the file containing the operator's PGP Key."+
+                  " You should have obtained this key from your server "+
+                  "operator.  It will have the \""+
+                  webfunds.ricardian.Contract.USERID_OPERATOR +
+                  "\" tag in the User Id field."+
+                  "</b></font></html>"); 
         gridbag.setConstraints(lab,c); add(lab);
 
         
@@ -154,15 +159,19 @@
 
     public boolean next() {
         
-        String key = loadAndCheckPublicKey(txtFile.getText());
+        PGPPublicKey key = checkPublicKey(txtFile.getText(),
+                                           Contract.USERID_OPERATOR,
+                                           null);
+        if (key == null)
+            return false;
 
-        if (key != null) {
-            data.setServerKey(key);
-            return true;
-        } else {
+        String s;
+        s = KeyUtil.publicKeyToString(key);
+        if (s == null)
             return false;
-        }
 
+        data.setServerKey(s);
+        return true;
     }
 
 



1.7       +42 -10    java/webfunds/client/contracts/wizard/KeyTop.java

Index: KeyTop.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/KeyTop.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- KeyTop.java	2000/08/26 18:56:14	1.6
+++ KeyTop.java	2000/08/26 23:35:07	1.7
@@ -1,5 +1,5 @@
 /*
- * $Id: KeyTop.java,v 1.6 2000/08/26 18:56:14 gelderen Exp $
+ * $Id: KeyTop.java,v 1.7 2000/08/26 23:35:07 iang Exp $
  *
  * Copyright (c) Systemics Inc 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -15,12 +15,14 @@
 import java.awt.event.*;
 import javax.swing.*;
 
+import webfunds.ricardian.Contract;
 
+
 /**
  * Panel that asks for the toplevel certification key
  *
  * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
  */
 
 public class KeyTop extends KeyPanel 
@@ -60,7 +62,8 @@
         c.fill       = GridBagConstraints.NONE;
         c.anchor     = GridBagConstraints.WEST;
         c.insets     = new Insets(5, 5, 5, 5);
-        lab = new JLabel("Select the top-level issuer PGP key."); 
+        final String tag = webfunds.ricardian.Contract.USERID_TOP_LEVEL;
+        lab = new JLabel("Select your " + tag + " PGP key."); 
         gridbag.setConstraints(lab,c); add(lab);
         
         
@@ -71,10 +74,8 @@
         c.anchor     = GridBagConstraints.WEST;
         c.insets     = new Insets(5, 5, 15, 5);
         lab = new JLabel("<html><font size='-1'><b>"+
-                         "In this step you will choose the top-level issuer "+
-                         "PGP key. If you don't have one yet, then you should "+
-                         "create one with your favourite PGP implementation. "+
-                         "Make sure it is a DH/DSS or DSA/ElGamal key."+
+                         "In this step you will select the file which "+
+                         "contains your top-level "+ tag + " PGP key."+
                          "</b></font></html>"); 
         gridbag.setConstraints(lab,c); add(lab);
 
@@ -142,14 +143,43 @@
         c.anchor     = GridBagConstraints.WEST;
         c.insets     = new Insets(5, 5, 15, 5);
         lab = new JLabel("<html><font size='-1'><b>"+
-                         "Use 'gpg -a --export \"[cert]\" > cert.asc' "+
+                         "Use 'gpg -a --export \"" +
+                         tag +
+                         "\" > cert.asc' "+
                          "</b></font></html>"); 
         gridbag.setConstraints(lab,c); add(lab);
         
 
+        c.gridheight = 1;      c.gridwidth = 2;
+        c.gridy      = 7;     c.gridx     = 0;
+        c.weighty    = 0;      c.weightx   = 0;
+        c.fill       = GridBagConstraints.NONE;
+        c.anchor     = GridBagConstraints.WEST;
+        c.insets     = new Insets(5, 5, 5, 5);
+        lab = new JLabel("Creating your OpenPGP " + tag + " key:"); 
+        gridbag.setConstraints(lab,c); add(lab);
+        
+        
+        c.gridheight = 1;      c.gridwidth = 2;
+        c.gridy      = 8;     c.gridx     = 0;
+        c.weighty    = 0;      c.weightx   = 1;
+        c.fill       = GridBagConstraints.HORIZONTAL;
+        c.anchor     = GridBagConstraints.WEST;
+        c.insets     = new Insets(5, 5, 15, 5);
+        lab = new JLabel("<html><font size='-1'><b>"+
+                         "Use your favourite OpenPGP implementation. " +
+                         "Make sure it is a DH/DSS or DSA/ElGamal key, "+
+                         "that it is self-signed, "+
+                         "and that it contains the " + tag +
+                         " tag anywhere in the User Id field "+
+                         "(include the square brackets). "+
+                         "</b></font></html>"); 
+        gridbag.setConstraints(lab,c); add(lab);
+
+
         // Filler, makes sure the whole thing is aligned to the top
         c.gridheight = 1;      c.gridwidth = 2;
-        c.gridy      = 7;      c.gridx     = 0;
+        c.gridy      = 9;      c.gridx     = 0;
         c.weighty    = 1;      c.weightx   = 0;
         c.fill       = GridBagConstraints.NONE;
         c.anchor     = GridBagConstraints.CENTER;
@@ -198,7 +228,9 @@
 
     public boolean next() {
         
-        String key = loadAndCheckPublicKey(txtFile.getText());
+        String key = loadAndCheckPublicKey(txtFile.getText(),
+                                           Contract.USERID_TOP_LEVEL,
+                                           null);
 
         if (key != null) {
             data.setTopLevelKey(key);