[Webfunds-commits] java/webfunds/sox DepositRequest.java PaymentFactory.java Request.java
Ian Grigg
iang@cypherpunks.ai
Wed, 16 Aug 2000 15:51:20 -0400 (AST)
iang 00/08/16 15:51:20
Modified: webfunds TODO_SCW
webfunds/client/sox SOXWallet.java
webfunds/ricardian Contract.java KeyUtil.java
webfunds/sox DepositRequest.java PaymentFactory.java
Request.java
Log:
some more explanation!
Revision Changes Path
1.3 +9 -9 java/webfunds/TODO_SCW
Index: TODO_SCW
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/TODO_SCW,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TODO_SCW 2000/08/16 18:44:19 1.2
+++ TODO_SCW 2000/08/16 19:51:17 1.3
@@ -2,10 +2,6 @@
I. Sanity checking is needed:
- (* that these are all potential checks may be also conducted within
- Contract.verify, now called in FinishSig after Signing. But, earlier
- checks would be good too.)
-
I.a) Contract - all these can be repaired and saved on the fly
+ no trailing spaces
@@ -34,14 +30,18 @@
then the decrypted version is disposed of quickly... may not be the
case.)
- - now picks up dud passphrase but takes about 30 seconds the
- first time to find out... Must be SecureRandom?
-
I.d) Signed Contract
* signature made is correct and verifiable with contents of contract
- + no additional chars introduced, strip sig and keys and diff with
- initial prototype contract.
+ + additional potential sanity check: that the signed contract can
+ be un-signed and contents compared with original proto-contract to
+ ensure that no additional chars were introduced during the signing
+ process.
+
+ * signifies checks that are conducted within Contract.verify(),
+ now called in FinishSig.next() after act of contract signing.
+ BUT, earlier checking of these conditions would be good too.
+
II. Presentation.
1.130 +2 -1 java/webfunds/client/sox/SOXWallet.java
Index: SOXWallet.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/SOXWallet.java,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -r1.129 -r1.130
--- SOXWallet.java 2000/07/16 19:31:35 1.129
+++ SOXWallet.java 2000/08/16 19:51:18 1.130
@@ -1,4 +1,4 @@
-/* $Id: SOXWallet.java,v 1.129 2000/07/16 19:31:35 iang Exp $
+/* $Id: SOXWallet.java,v 1.130 2000/08/16 19:51:18 iang Exp $
*
* Copyright (c) Systemics Inc. 1995-2000 on behalf of
* The WebFunds Development Team. All Rights Reserved.
@@ -1003,6 +1003,7 @@
if (sub == null)
{
makeNewSub = true; // only if our account...
+ logmsg("no sub " + item.fp() + " in " + ac.fp() + ", making...");
sub = new ValueAccount(item);
try {
ac.newSub(sub);
1.31 +1 -1 java/webfunds/ricardian/Contract.java
Index: Contract.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/ricardian/Contract.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- Contract.java 2000/08/16 18:40:48 1.30
+++ Contract.java 2000/08/16 19:51:18 1.31
@@ -1,4 +1,4 @@
-/* $Id: Contract.java,v 1.30 2000/08/16 18:40:48 iang Exp $
+/* $Id: Contract.java,v 1.31 2000/08/16 19:51:18 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
1.3 +17 -1 java/webfunds/ricardian/KeyUtil.java
Index: KeyUtil.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/ricardian/KeyUtil.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- KeyUtil.java 2000/08/15 02:14:32 1.2
+++ KeyUtil.java 2000/08/16 19:51:18 1.3
@@ -115,6 +115,22 @@
PGPUserID uid = findUserId(key, userIdTag);
if (uid == null) return false;
+ /*
+ * check the userId is the only one by matching empty string
+ * should reverse these checks :)
+ */
+ try {
+
+ PGPUserID uid2 = findUserId(key, "");
+ if (uid2 == null)
+ throw new RuntimeException("no UserId second time? " + uid);
+ if (!uid2.equals(uid))
+ throw new RuntimeException("1st UserId not same as 2nd: " +
+ uid + " != " + uid2);
+ } catch (StripKeyException ex) {
+ return false;
+ }
+
// we now have a key with single userId
Vector sigs = uid.getSignatures();
@@ -144,7 +160,7 @@
* Return the first UserId on the key that matches 'userIdTag' or return
* null.
*/
- private static PGPUserID findUserId(PGPPublicKey key, String userIdTag)
+ public static PGPUserID findUserId(PGPPublicKey key, String userIdTag)
throws StripKeyException
{
PGPUserID res = null;
1.23 +115 -72 java/webfunds/sox/DepositRequest.java
Index: DepositRequest.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/DepositRequest.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- DepositRequest.java 2000/07/16 19:27:24 1.22
+++ DepositRequest.java 2000/08/16 19:51:19 1.23
@@ -1,5 +1,5 @@
/*
- * $Id: DepositRequest.java,v 1.22 2000/07/16 19:27:24 iang Exp $
+ * $Id: DepositRequest.java,v 1.23 2000/08/16 19:51:19 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -19,12 +19,25 @@
{
/**
* The version of the encoded deposit request.
+ *
+ * 1 - original, as delivered, but virtual, number not present in packet
+ * 2 - add version number to this DepositRequest (and all others).
+ * 3 - withdrawal - can exchange one payment for another
+ * 3 - use me next
+ *
* Originally, in Request.VERSION == 2, there were no local versions.
* We'll call that VERS == 1.
*/
- public static final int VERSION = 2;
- protected int version = VERSION; // change this if an old packet
+ public static final int // VERSION = 2, // old name, deprecated
+ DEPOSIT_ORIGINAL = 1, // number never used
+ DEPOSIT_LOCAL_VERS = 2, // local version added
+ DEPOSIT_WITHDRAW = 3, // can exchange types
+ DEPOSIT_not_used_yet = 4; // use me next...
+
+ protected int version = DEPOSIT_LOCAL_VERS; // change this if an old packet
+ public int getVersion() { return version; }
+
public static final String name = "SOX.Deposit";
public String getName() { return name ; }
@@ -117,6 +130,36 @@
public byte[] getDepositDesc() { return depositDesc; }
/**
+ * The type of payment that the caller wants to withdraw,
+ * where the type is a number from PaymentFactory.
+ * Defaults to PaymentFactory.NONE, meaning that this is
+ * a straight Deposit request.
+ *
+ * Added for version DEPOSIT_WITHDRAW.
+ */
+ protected int typeOfPayment = PaymentFactory.NONE;
+ public int getTypeOfPayment() { return typeOfPayment; }
+ public void setTypeOfPayment(int type) { typeOfPayment = type; }
+
+ /**
+ * The state of the protocol that the caller wants to
+ * (re)start this request processing in.
+ * The contents are undefined here, it depends on the
+ * protocol implied by the type of Payment requested.
+ *
+ * This might be redundant (use Payment instead), or
+ * too simplistic (as Payment is signed, it can't be
+ * changed ...). We'll see.
+ *
+ * Added for version DEPOSIT_WITHDRAW.
+ */
+ protected int protocolState = 0;
+ public int getProtocolState() { return protocolState; }
+ public void setProtocolState(int state) { protocolState = state; }
+
+
+
+ /**
* Get a Reply with Errors set.
*/
public Reply errorReply(int e)
@@ -151,7 +194,7 @@
* If the signature is not present in the encoded data,
* the created request will be unsigned.
*
- * @param depositReqData the previosly encoded request
+ * @param depositReqData the previously encoded request
* @excep SOXPacketException The input data was badly formatted
*/
public DepositRequest(byte[] depositReqData)
@@ -191,45 +234,68 @@
{
DataOutputStream dos = new DataOutputStream(os);
super.encode(dos);
+
+// will I need this???
+// encode_payload(dos);
+// }
+//
+// protected void encode_payload(DecodeOutputStream dos)
+// throws IOException
+// {
+// /* DataOutputStream dos = new DataOutputStream(os); ??? */
- if (req_version >= 3) // New! for version == 2 && super.version == 3
-//{
+ // New! for version == 2 && super.version == 3
+ if (req_version >= REQ_SUBS_ADD_V)
dos.writeByte(version);
-//System.err.println("DR V" + version);
-//} else System.err.println("DR V1");
payment.encode(dos);
writeString(dos, depositId);
writeByteArray(dos, depositDesc);
+
+ if (version >= DEPOSIT_WITHDRAW) // New! I can jump technologies...
+ {
+ dos.writeByte(typeOfPayment);
+ dos.writeByte(protocolState);
+ }
}
/**
- * Update this deposit request object with the values from
- * a deposit request on the input stream (such as might be
- * send by the encode() method of a deposit request object).
+ * Recover this deposit request object with the values from
+ * a deposit request on the input stream (such as might be
+ * sent by the encode() method of a deposit request object).
*
- * @param is the stream containing the encoded deposit request
- * @excep IOException An I/O error occurred
- * @excep SOXPacketException The input data was badly formatted
+ * @param is the stream containing the encoded deposit request
+ * @excep IOException An I/O error occurred
+ * @excep SOXPacketException The input data was badly formatted
*/
public void decode(InputStream is)
throws IOException, SOXPacketException
{
DataInputStream dis = new DataInputStream(is);
super.decode(dis);
+
+// will I need this???
+// decode_payload(dis);
+// }
+//
+// protected void decode_payload(DataInputStream is)
+// throws IOException, SOXPacketException
+// {
+// /* DataInputStream dis = new DataInputStream(is); ??? */
- //
- // the problem here being that all receipts include the
- // deposit, which will need to be recovered, as long as
- // the receipt is to remain usable!
+ /*
+ * the problem here being that all receipts include the
+ * deposit, which will need to be recovered, as long as
+ * the receipt is to remain usable!
+ */
int v = 1;
- if (req_version >= 3) // parent VERSION, used to add this version
+ if (req_version >= REQ_SUBS_ADD_V) // parent, adds my version num
{
v = dis.readUnsignedByte();
- if (v != VERSION)
+ if (! ((DEPOSIT_LOCAL_VERS <= v) && (v <=DEPOSIT_WITHDRAW)) )
throw new SOXPacketException("Invalid version in DepositR:" +
- v + " != " + VERSION);
+ v + " != {"+DEPOSIT_LOCAL_VERS+","+DEPOSIT_WITHDRAW+"}");
version = v; // remember this for sig checks
}
@@ -237,6 +303,12 @@
depositId = readString(dis);
depositDesc = readByteArray(dis);
+
+ if (version >= DEPOSIT_WITHDRAW) // New! I can jump technologies...
+ {
+ typeOfPayment = dis.readUnsignedByte();
+ protocolState = dis.readUnsignedByte();
+ }
}
public String toAscii()
@@ -256,16 +328,27 @@
*/
public String toString()
{
- String retval = "SOX DepositRequest V" + version + ":";
- retval += super.toString();
+ String s = "SOX DepositRequest " + vString() + ":";
+ s += super.toString();
- retval += "\tPayment: "+payment+"\n";
- retval += "\tDeposit Id: "+depositId+"\n";
+ s += "\tPayment: "+payment+"\n";
+ s += "\tDeposit Id: "+depositId+"\n";
if (depositDesc == null)
- retval += "\tDesc: <none>\n";
+ s += "\tDesc: <none>\n";
else
- retval += "\tDesc: "+webfunds.utils.Hex.printable(depositDesc)+"\n";
- return retval;
+ s += "\tDesc: "+webfunds.utils.Hex.printable(depositDesc)+"\n";
+
+ if (version >= DEPOSIT_WITHDRAW)
+ {
+ s += "\ttype: " + PaymentFactory.getTypeString(typeOfPayment) ;
+ s += " state: " + protocolState;
+ }
+ return s;
+ }
+
+ public String vString()
+ {
+ return "V" + version + " " + super.getRequestVersion() + ")";
}
public static DepositRequest example()
@@ -278,12 +361,15 @@
DepositRequest req = new DepositRequest(reqId, ac, pay, depId, desc);
+ req.setTypeOfPayment(Utils.exampleByte());
+ req.setProtocolState(Utils.exampleByte());
+
return req ;
}
public static void main(String[] args)
{
- int num = 20;
+ int num = 2000;
String type = "-c";
if (args.length > 0)
{
@@ -376,47 +462,4 @@
b = new DepositRequest(System.in);
System.err.println("Read: " + b);
}
-// public static void main(String[] args)
-// {
-// args = null;
-//
-// try
-// {
-//
-// DepositRequest req = DepositRequest.example();
-//
-// ByteArrayOutputStream baos = new ByteArrayOutputStream();
-//
-// System.err.println("Writing: " + req);
-//
-// req.encode(baos);
-// ByteArrayInputStream bais;
-// bais = new ByteArrayInputStream( baos.toByteArray() );
-//
-// DepositRequest req2 = new DepositRequest(bais);
-//
-// System.err.println("Reading: " + req2);
-// }
-// catch(Exception e)
-// {
-// e.printStackTrace();
-// System.exit(1);
-// }
-// }
-//
-// /*family*/ static void tryit(DepositRequest p)
-// throws Exception
-// {
-// System.err.println("Writing: " + p);
-// ByteArrayOutputStream baos = new ByteArrayOutputStream();
-//
-// p.encode(baos);
-// byte[] buf = baos.toByteArray();
-//
-// DepositRequest q = new DepositRequest(buf);
-// if (!p.equals(q))
-// {
-// throw new RuntimeException("FAILED:\n\n"+q+"\n\n"+p+"\nEND\n");
-// }
-// }
}
1.3 +40 -5 java/webfunds/sox/PaymentFactory.java
Index: PaymentFactory.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/PaymentFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PaymentFactory.java 2000/08/05 13:05:39 1.2
+++ PaymentFactory.java 2000/08/16 19:51:19 1.3
@@ -1,4 +1,4 @@
-/* $Id: PaymentFactory.java,v 1.2 2000/08/05 13:05:39 iang Exp $
+/* $Id: PaymentFactory.java,v 1.3 2000/08/16 19:51:19 iang Exp $
*
* Copyright (c) Systemics Inc. 1995-2000 on behalf of
* The WebFunds Development Team. All Rights Reserved.
@@ -11,14 +11,19 @@
/**
* Use the numbers 100 - 110 for experimental methods.
* Once you are ready, ask the WebFunds team to allocate
- * you a fixed number from below!
- * Hmm, that should keep contention in the other 4 billion
- * spots down to a workable minmum ;)
+ * you a fixed number from the fixed blocks.
*/
- public static final int SOX_CHEQUE = 1,
+ public static final int NONE = 0,
+ SOX_CHEQUE = 1,
RANDOM_TOKEN = 2,
WAGNER_TOKEN = 3;
+ private static final String[] typeNames = {
+ "SOX Cheque",
+ "Random Token",
+ "Wagner Token"
+ };
+
private PaymentFactory() {}
@@ -33,5 +38,35 @@
e.printStackTrace();
throw new SOXException("Payment Decode Error");
}
+ }
+
+ /**
+ * Is this a valid type, at least according to the ones known
+ * about here?
+ *
+ * @return false if not a known type, else true
+ */
+ public static boolean valid(int type)
+ {
+ if (type <= 0)
+ return false;
+ if (type >= 4)
+ return false;
+ return true ;
+ }
+
+ /**
+ * Return a diags string for this type.
+ */
+ public static String getTypeString(int type)
+ {
+ if (!valid(type))
+ {
+ if ((100 <= type) && (type <= 110))
+ return "experimental " + " (" + type + ")";
+
+ return "<" + type + " invalid>";
+ }
+ return typeNames[type - 1] + " (" + type + ")";
}
}
1.18 +26 -8 java/webfunds/sox/Request.java
Index: Request.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Request.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Request.java 2000/07/06 17:05:28 1.17
+++ Request.java 2000/08/16 19:51:19 1.18
@@ -1,5 +1,5 @@
/*
- * $Id: Request.java,v 1.17 2000/07/06 17:05:28 gelderen Exp $
+ * $Id: Request.java,v 1.18 2000/08/16 19:51:19 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -21,13 +21,31 @@
extends Encodable
{
/**
- * The version of the encoded request.
- * 2 - original SOX-2, without daughter versions.
+ * The version of the encoded :
+ *
+ * 1 was pre-dawn-of-time, may have been SOX-1
+ * 2 - original SOX-2, as delivered
+ * 3 - all daughter requests add their own version bytes
+ * 4 - use me next
+ *
+ * To change the version, add a REQ_reason_for_change constant
+ * with the REQ_not_used_yet number (and advance this one).
+ * Set req_version to the new reason request version number.
+ */
+ public static final int REQ_VERSION = 3, // old name, deprecated
+ REQ_ORIGINAL = 2, // change 1 ==> 2 was pre-dawn
+
+ REQ_SUBS_ADD_V = 3, // daughters add versions!
+ REQ_not_used_yet = 4; // use me next...
+
+ // public static final int versionOld = 2; // old name, deprecated
+
+ /**
+ * Initialised to the current best version from the REQ_* constants.
*/
- public static final int REQ_VERSION = 3; // daughters add versions!
- public static final int versionOld = 2;
+ protected int req_version = REQ_SUBS_ADD_V; // for new versions, change this
- protected int req_version = REQ_VERSION; // for old requests, change this
+ public int getRequestVersion() { return req_version; }
/**
* Returns the name of the packet as it goes on the wire.
@@ -254,9 +272,9 @@
{
DataInputStream dis = new DataInputStream(is);
int v = dis.readUnsignedByte();
- if (v != REQ_VERSION && v != versionOld)
+ if (v != REQ_SUBS_ADD_V && v != REQ_ORIGINAL)
throw new SOXPacketException("Invalid version number in Request:" +
- v + " != " + REQ_VERSION + " (" + versionOld + ")");
+ v + " != " + REQ_SUBS_ADD_V +" ("+REQ_ORIGINAL+")");
req_version = v; // need to preserve encoding for sig check