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

Ian Grigg iang@cypherpunks.ai
Wed, 16 Aug 2000 14:43:51 -0400 (AST)


iang        00/08/16 14:43:51

  Modified:    webfunds/client/contracts/wizard FinishSig.java
  Log:
  Added Contract.getContract and contract.verify after writing it out
  in order to check the results.  This part works, although the actual
  checks within Contract.verify don't handle keys and sigs well yet.

Revision  Changes    Path
1.5       +38 -3     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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FinishSig.java	2000/08/16 08:30:37	1.4
+++ FinishSig.java	2000/08/16 18:43:51	1.5
@@ -1,5 +1,5 @@
 /*
- * $Id: FinishSig.java,v 1.4 2000/08/16 08:30:37 edwin Exp $
+ * $Id: FinishSig.java,v 1.5 2000/08/16 18:43:51 iang Exp $
  *
  * Copyright (c) Systemics Inc 2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -27,12 +27,15 @@
 import java.awt.event.*;
 import javax.swing.*;
 
+import webfunds.ricardian.Contract;
+import webfunds.ricardian.ContractException;
 
+
 /**
  * Panel that does the actual signing.
  *
  * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
  */
 
 public class FinishSig extends WizardPanel 
@@ -269,9 +272,41 @@
             return false;
         }
 
+        if (!sanityCheckContract(signedBytes))
+            return false;
 
-        return true;
+        return true ;
+
+    }
+
+    public final static String eoln = "\r\n";  // how PGP cleartext is prepared
+
+    private boolean sanityCheckContract(byte[] contractBytes)
+    {
+        String s = "[local]" + eoln +
+                   "digest_version=3" + eoln;
+        byte[] locFile = s.getBytes();
+
+        Contract con;
+        try {
+            con = Contract.getContract(contractBytes, locFile, null);
+        } catch (ContractException ex) {
+            error("Not a contract!", ex);
+            return false;
+        }
+        
+        try {
+            if (!con.verifyContract())
+            {
+                error("contract failed to verify?", null);
+                return false;
+            }
+        } catch (ContractException ex) {
+            error("contract failed to verify!", ex);
+            return false;
+        }
 
+        return true;
     }