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

Ian Grigg iang@cypherpunks.ai
Sat, 26 Aug 2000 18:57:22 -0400 (AST)


iang        00/08/26 18:57:22

  Modified:    webfunds/ricardian Contract.java KeyUtil.java
  Log:
  Contract: added diags where contract key suddenly decides is unselfsigned
  KeyUtil: added in some handy armouring methods needed above, and also in SCW

Revision  Changes    Path
1.36      +6 -4      java/webfunds/ricardian/Contract.java

Index: Contract.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/ricardian/Contract.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- Contract.java	2000/08/21 18:10:47	1.35
+++ Contract.java	2000/08/26 22:57:21	1.36
@@ -1,4 +1,4 @@
-/* $Id: Contract.java,v 1.35 2000/08/21 18:10:47 iang Exp $
+/* $Id: Contract.java,v 1.36 2000/08/26 22:57:21 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -712,7 +712,7 @@
      *
      *  @see http://www.systemics.com/docs/ricardo/issuer/server-manage.html
      */
-    public final static String USERID_TOP_LEVEL    = "[cert]",
+    public final static String USERID_TOP_LEVEL    = "[certification]",
                                USERID_CONTRACT     = "[contract]",
                                USERID_SERVER       = "[server]",
                                USERID_OPERATOR     = "[operator]";
@@ -881,6 +881,7 @@
 
         // convert it to a PGPPublicKey and check the self-signature
         PGPPublicKey key = (PGPPublicKey)cert.getPublicKey();
+        String s = KeyUtil.publicKeyToString(key);
 
         /*
          *  Only accept valid self-signed keys.
@@ -889,6 +890,7 @@
         try {
             cert.verify(key);
         } catch (SignatureException se) {
+System.err.println("(rearmoured key) -----\n\n" + s + "\n\n");
             throw new ContractException(errno, e + "not self-signed - "+ se);
         } catch (NoSuchProviderException nspe) {
             throw new InternalError("Should not happen - "+nspe);
@@ -964,7 +966,7 @@
      *  that all certs match our current path goodness criteria:
      *
      *       1. all keys {top, contract, server} are self-signed.
-     *       2. top-level cert key signs contract key.
+     *       2. top-level certification key signs contract key.
      *       3. contract key signs contract.
      *       4. no other signatures are included.
      *
@@ -1048,7 +1050,7 @@
             contractCert.verify(topLevelKey);
         } catch (SignatureException se) {
             throw new ContractException(ContractException.KEY_CON_SIG,
-                                    "unsigned by cert key - "+se);
+                              "unsigned by "+USERID_TOP_LEVEL+" key - "+se);
             // return false; // result = false;
         } catch (NoSuchProviderException nspe) {
             throw new Panic("Should not happen - "+nspe);



1.4       +30 -0     java/webfunds/ricardian/KeyUtil.java

Index: KeyUtil.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/ricardian/KeyUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- KeyUtil.java	2000/08/16 19:51:18	1.3
+++ KeyUtil.java	2000/08/26 22:57:21	1.4
@@ -5,12 +5,42 @@
 import java.io.*;
 import java.util.Vector;
 import cryptix.openpgp.*;
+import cryptix.openpgp.util.PGPArmoury;
 
 
 public final class KeyUtil {
 
     /** Static methods only. */
     private KeyUtil() {}
+
+    public static PGPPublicKey publicKeyFromString(String s)
+        throws PGPException
+    {
+        PGPArmoury armouredKey = new PGPArmoury(s);
+        PGPKeyFactory factory = new PGPKeyFactory();
+        Vector keys = factory.decodeKeys(armouredKey.getPayload());
+        PGPPublicKey pk = (PGPPublicKey)keys.elementAt(0);
+        return pk;
+    }
+        
+    static final String PUBLIC_KEY_BLOCK = "PGP PUBLIC KEY BLOCK";
+    static final String SECRET_KEY_BLOCK = "PGP PRIVATE KEY BLOCK";
+            
+    public static String secretKeyToString(PGPSecretKey sk)
+    {
+        PGPArmoury armouredKey = new PGPArmoury(sk.getEncoded(),
+                                         SECRET_KEY_BLOCK);
+        return armouredKey.toString();
+    }
+        
+    public static String publicKeyToString(PGPPublicKey pk)
+    {
+        PGPArmoury armouredKey = new PGPArmoury(pk.getEncoded(),
+                                         PUBLIC_KEY_BLOCK);
+        return armouredKey.toString();   
+       
+    }
+
 
 
     /**