[Webfunds-commits] java/webfunds/sox SimpleIssuer.java

Jeroen C. van Gelderen gelderen@cypherpunks.ai
Thu, 30 Nov 2000 17:01:34 -0400 (AST)


gelderen    00/11/30 17:01:34

  Modified:    webfunds/sox SimpleIssuer.java
  Log:
  Work around the stale key problem.
  
  SimpleIssuer requests the CommsKey once and caches it for all future
  requests. If the issuer changes it's CommsKey in the meantime then all
  requests encrypted with the old key will fail.
  
  We try and detect this condition (but we can never know for sure as
  the server can't tell us the CommsKey is stale) and if we think we
  have a stale key we refresh the CommsKey and retry the failed request.

Revision  Changes    Path
1.20      +40 -24    java/webfunds/sox/SimpleIssuer.java

Index: SimpleIssuer.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/SimpleIssuer.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- SimpleIssuer.java	2000/09/24 23:58:09	1.19
+++ SimpleIssuer.java	2000/11/30 21:01:33	1.20
@@ -1,5 +1,5 @@
 /*
- * $Id: SimpleIssuer.java,v 1.19 2000/09/24 23:58:09 iang Exp $
+ * $Id: SimpleIssuer.java,v 1.20 2000/11/30 21:01:33 gelderen Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -22,7 +22,7 @@
  *
  * @version 1.3
  */
-public class SimpleIssuer
+public final class SimpleIssuer
     extends Debug
     implements Issuer
 {
@@ -139,6 +139,15 @@
 
 /////////  Keys and Certs  //////////////////////////////////////////
 
+
+    private void refetchCommsKey()
+        throws SOXIssuerException, SOXLaterException
+    {
+        commsKey = null;
+        fetchCommsKey();
+    }
+
+
     /**
      * Fetch the current communications certificate for this issuer.
      * The certificate signatures are verified before assigning.
@@ -147,7 +156,7 @@
      *
      * This won't do anything if commsKey is already set.
      */
-    protected void fetchCommsKey()
+    private void fetchCommsKey()
         throws SOXIssuerException, SOXLaterException
     {
         if (commsKey != null)
@@ -182,11 +191,11 @@
             logmsg("Verifying ServerCert is signed by Server CA certificate");
             if (!Crypto.verifyCertificate(serverCert, signerKey)) {
 
-byte[] b = signerKey.getEncoded();
-PGPArmoury ok = new PGPArmoury(b, PGPArmoury.TYPE_PUBLIC_KEY);
-b = Crypto.getPublicKeyFromCert(serverCert).getEncoded();
-PGPArmoury sk = new PGPArmoury(b, PGPArmoury.TYPE_PUBLIC_KEY);
-logmsg(
+                byte[] b = signerKey.getEncoded();
+                PGPArmoury ok = new PGPArmoury(b, PGPArmoury.TYPE_PUBLIC_KEY);
+                b = Crypto.getPublicKeyFromCert(serverCert).getEncoded();
+                PGPArmoury sk = new PGPArmoury(b, PGPArmoury.TYPE_PUBLIC_KEY);
+                logmsg(
                     "serverCert (first) not signed by operator Cert (2nd)\n\n"+
                     sk + "\n\n\n" + ok + "\n\n");
 
@@ -212,6 +221,8 @@
 
         // Careful not to set this before validating the signature
         commsKey = Crypto.getPublicKeyFromCert(commsCert);
+
+        logmsg("Finished fetchCommsKey at " + System.currentTimeMillis() );
     }
 
     /**
@@ -229,7 +240,7 @@
      *  This won't do anything if [server] is already set.  If a
      *  signature failure has occurred then set the key to null first.
      */
-    protected void fetchServerCert()
+    private void fetchServerCert()
         throws SOXIssuerException, SOXLaterException
     {
         if (serverCert != null)
@@ -297,19 +308,29 @@
      * // Strategy: if the first request fails, fetch a new key and retry.
      * @except SOXIssuerException if this Issuer is dead, try another
      */
-    protected byte[] internalRequest(Request request)
+    private byte[] internalRequest(Request request)
         throws SOXIssuerException, SOXLaterException
     {
         fetchCommsKey();
 
-logmsg("after comms key == " + System.currentTimeMillis() );
 
-        try
-        {
-            return requestOnce(request);
+        try {
+
+            try {
+                return requestOnce(request);
+
+            } catch(SOXKeyException ex) {
+                /*
+                 * We are here because the key is stale. Try and get a new
+                 * CommsKey *once* and retry the request.
+                 */
+                logmsg("*** first request failed, refetching comms...");
+                refetchCommsKey();
+                logmsg("*** trying request again...");
+                return requestOnce(request);
+            }
         }
-        catch (SOXKeyException ex)
-        {
+        catch (SOXKeyException ex) {
             //
             //  SOXKeyException is thrown when my key is duff.
             //  Let parent (SmartIssuer) sort it out.
@@ -318,21 +339,16 @@
             throw new SOXIssuerException(ex.getNumber(),
                                          "request: " + ex.getMessage());
 
-//        } catch (java.net.ConnectException ex) {  // from IOEx
-//            setDead(ex.getMessage());      // URL is wrong or server is down
-//            throw new SOXLaterException("internalRequest: " + ex.getMessage());
         } catch (SOXPacketException ex) {
             setDead(ex.getMessage());
             throw new SOXIssuerException(ex.getNumber(),
                                          "SOXPE 3: " + ex.getMessage());
-//        } catch (IOException ex) {
-//            ex.printStackTrace(err());
-//            setDead(ex.getMessage());
-//            throw new SOXIssuerException("bad IO request: " + ex.getMessage());
+
         } catch (SOXIssuerException ex) {   // Even if I don't deal with it...
             logmsg("catching (and dying on)" + ex);
             setDead(ex.getMessage());       // ...I should still bail out.
             throw ex ;
+
         } catch (SOXLaterException ex) {    // Even if I don't deal with it...
             logmsg("catching (and dying on)" + ex);
             setDead(ex.getMessage());       // ...I should still bail out.
@@ -343,7 +359,7 @@
     /**
      * Issue a request once only.
      */
-    protected byte[] requestOnce(Request request)
+    private byte[] requestOnce(Request request)
         throws SOXPacketException, SOXKeyException,
                SOXLaterException, SOXIssuerException
     {