[Webfunds-commits] java/webfunds/ricardian Contract.java

Edwin Woudt edwin@cypherpunks.ai
Fri, 30 Jun 2000 21:26:35 -0400 (AST)


edwin       00/06/30 21:26:35

  Modified:    webfunds/ricardian Tag: OPENPGP Contract.java
  Log:
  Verify both types of contracts (X.509/OpenPGP) transparantly.

Revision  Changes    Path
No                   revision

= Diff supressed due to Sticky Options =


No                   revision

= Diff supressed due to Sticky Options =


1.19.2.4  +62 -52    java/webfunds/ricardian/Contract.java

Index: Contract.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/ricardian/Contract.java,v
retrieving revision 1.19.2.3
retrieving revision 1.19.2.4
diff -u -r1.19.2.3 -r1.19.2.4
--- Contract.java	2000/06/12 15:25:28	1.19.2.3
+++ Contract.java	2000/07/01 01:26:34	1.19.2.4
@@ -1,5 +1,5 @@
 /*
- * $Id: Contract.java,v 1.19.2.3 2000/06/12 15:25:28 edwin Exp $
+ * $Id: Contract.java,v 1.19.2.4 2000/07/01 01:26:34 edwin Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -670,6 +670,8 @@
         return getCert("contract");
     }
 
+
+    // ### FIXME (edwin): Should read the key from the contract
     private PGPPublicKey getContractCertPGP()
         throws ContractException
     {
@@ -760,61 +762,69 @@
         throws ContractException
     {
         String s = new String(contractData);
-        PGPPublicKey issuerKey = getContractCertPGP();
-        
-        try {
-            return PGPMessage.verifyClearSign(s, issuerKey);
-        } catch (IOException ioe) {
-            return false;
-        }
-        
-/*        // Get the Certificate from the contract
-        X509Cert issuerCert = getContractCert();
 
-        // Extract the signature
-        String s = new String(contractData);
-        byte[] sig;
-        try {
-            sig = Armoury.decodeByteArray("SIGNATURE", s);
-        } catch (IOException ex) {
-            throw new ContractException("signature is bad: " + ex);
-        }
+        // ### FIXME (edwin): Figure out a better way to check this
+        if (s.startsWith("-----BEGIN PGP SIGNED MESSAGE-----")) {
 
-        // Get the prepared (i.e. CR/NL processed) contract
-        byte[] decoded;
-        byte[] data;
-        try {
-            decoded = Armoury.decodeData(contractData);
-            data = Armoury.prepareDataToSign(decoded);
-        } catch (IOException ex) {
-            throw new ContractException("contract part is bad: " + ex);
-        }
-
-        PublicKey pK = Crypto.getPublicKeyFromCert(issuerCert);
-
-        //
-        // Drop last 2 bytes - which are a CR/LN - as these might have
-        // snuck in?  Pox on those who don't comment this!  Further
-        // pestilence & plague on them who didn't fix it at source!!
-        // Rot & Ruin on they who let the "standard" reflect this
-        // abomination !*!%!
-        //
-        // It turns out that the last CR/LN is not counted in a signature.
-        //
-        boolean ok;
-        int i = 0;
-        do
-        {
+            PGPPublicKey issuerKey = getContractCertPGP();
+            
             try {
-                ok = Crypto.verify(pK, sig, data);
-            } catch (java.security.KeyException ex) {
-                throw new ContractException("bad key on verify: " + ex);
+                return PGPMessage.verifyClearSign(s, issuerKey);
+            } catch (IOException ioe) {
+                return false;
             }
-            logmsg("Attempt " + (++i) + ": " + ok);
-
-        } while (!ok && (data = mungeLastLine(data)) != null) ;
-
-        return ok ; */
+            
+        } else {  // X.509 signed contract
+        
+            // Get the Certificate from the contract
+            X509Cert issuerCert = getContractCert();
+    
+            // Extract the signature
+            byte[] sig;
+            try {
+                sig = Armoury.decodeByteArray("SIGNATURE", s);
+            } catch (IOException ex) {
+                throw new ContractException("signature is bad: " + ex);
+            }
+    
+            // Get the prepared (i.e. CR/NL processed) contract
+            byte[] decoded;
+            byte[] data;
+            try {
+                decoded = Armoury.decodeData(contractData);
+                data = Armoury.prepareDataToSign(decoded);
+            } catch (IOException ex) {
+                throw new ContractException("contract part is bad: " + ex);
+            }
+    
+            PublicKey pK = Crypto.getPublicKeyFromCert(issuerCert);
+    
+            //
+            // Drop last 2 bytes - which are a CR/LN - as these might have
+            // snuck in?  Pox on those who don't comment this!  Further
+            // pestilence & plague on them who didn't fix it at source!!
+            // Rot & Ruin on they who let the "standard" reflect this
+            // abomination !*!%!
+            //
+            // It turns out that the last CR/LN is not counted in a signature.
+            //
+            boolean ok;
+            int i = 0;
+            do
+            {
+                try {
+                    ok = Crypto.verify(pK, sig, data);
+                } catch (java.security.KeyException ex) {
+                    throw new ContractException("bad key on verify: " + ex);
+                }
+                logmsg("Attempt " + (++i) + ": " + ok);
+    
+            } while (!ok && (data = mungeLastLine(data)) != null) ;
+    
+            return ok ;
+        
+        }
+      
     }
 
     /*