webfunds.sox
Class Request

java.lang.Object
  |
  +--webfunds.sox.Encodable
        |
        +--webfunds.sox.Request
Direct Known Subclasses:
DepositRequest, MailRequest, NymRequest, RegisterRequest, TimeSyncRequest

public abstract class Request
extends Encodable

This class represents a signed receipt, such as received from an issuer in response to a deposit request. SOX clients usually only create receipts using data received from the issuer.

See Also:
Serialized Form

Field Summary
protected  AccountId account
          The identifer of the account for which this is a request
static int REQ_not_used_yet
          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 Note that Requests and their Replies have the same version number.
static int REQ_ORIGINAL
          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 Note that Requests and their Replies have the same version number.
static int REQ_SUBS_ADD_V
          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 Note that Requests and their Replies have the same version number.
protected  int req_version
          Initialised to the current best version from the REQ_* constants.
static int REQ_VERSION
          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 Note that Requests and their Replies have the same version number.
protected  java.lang.String requestId
          An identifier for the request This is used for the prevention of replay attacks since the server may choose not respond to requests with an identical id (or will return the previous reply to this request).
protected  byte[] sig
          The signature of all other request fields
protected  long timestamp
          The time at which this request was created Used for the prevention of replay attacks, since the server will not respond to old requests.
 
Constructor Summary
Request(byte[] requestData)
          Construct a request object from a byte array that was previously returned from the encode() method of a request object.
Request(java.io.InputStream is)
          Construct a request object from data on an input stream that was previously returned from the encode() method of a request object.
Request(java.lang.String requestId, AccountId acc)
          Create an unsigned request
Request(java.lang.String requestId, AccountId acc, long timestamp)
          Create an unsigned request
 
Method Summary
 void decode(java.io.InputStream is)
          Update this request object with the values from a request encoded as a byte array (such as previously returned from the encode() method of a request object).
 void encode(java.io.OutputStream os)
          Encode a deposit request to an output stream, suitable for using with RequestPacket to send to remote servers (which use the decode() method to re-construct the object).
 boolean equals(java.lang.Object obj)
           
abstract  Reply errorReply(int err)
          Get an error Reply for this Request.
 AccountId getAccountId()
          Get the account identifier of the request
abstract  java.lang.String getName()
          Returns the name of the packet as it goes on the wire.
 java.lang.String getRequestId()
          Get the identifier on this request Note: although a java String is used, this identifier should only contain 8-bit ascii characters.
 int getRequestVersion()
           
 long getTimestamp()
          Get the time and date of the request
 int getVersion()
           
 boolean isSigned()
          Check to see if this request is signed NOTE: This does not check the validity of the signature, only that this request has one.
 Reply reconstructReply(byte[] buf)
          Get an error Reply for this Request.
 void setRequestVersion(int v)
          Set the version number of this request.
 void setSignature(byte[] sig)
          Define the signature for this request
 java.lang.String toString()
          Convert this object to a human readable string
 boolean verify(java.security.PublicKey key)
          Verify the signature on this request.
 
Methods inherited from class webfunds.sox.Encodable
decode, encode, main, readByteArray, readCertificate, readProperties, readString, writeByteArray, writeCertificate, writeProperties, writeString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REQ_VERSION

public static final int REQ_VERSION
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 Note that Requests and their Replies have the same version number. Changes in the Reply format imply changes in the below number. How the client works out what version the server is at is unknown... 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.

REQ_ORIGINAL

public static final int REQ_ORIGINAL
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 Note that Requests and their Replies have the same version number. Changes in the Reply format imply changes in the below number. How the client works out what version the server is at is unknown... 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.

REQ_SUBS_ADD_V

public static final int REQ_SUBS_ADD_V
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 Note that Requests and their Replies have the same version number. Changes in the Reply format imply changes in the below number. How the client works out what version the server is at is unknown... 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.

REQ_not_used_yet

public static final int REQ_not_used_yet
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 Note that Requests and their Replies have the same version number. Changes in the Reply format imply changes in the below number. How the client works out what version the server is at is unknown... 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.

req_version

protected int req_version
Initialised to the current best version from the REQ_* constants.

requestId

protected java.lang.String requestId
An identifier for the request This is used for the prevention of replay attacks since the server may choose not respond to requests with an identical id (or will return the previous reply to this request). The identifier need only be unique over the past few minutes, since requests older than a few minutes are ignored anyway. Note: although we use a java String, this identifier should only contain 8-bit ascii characters.

account

protected AccountId account
The identifer of the account for which this is a request

timestamp

protected long timestamp
The time at which this request was created Used for the prevention of replay attacks, since the server will not respond to old requests.

sig

protected byte[] sig
The signature of all other request fields
Constructor Detail

Request

public Request(java.lang.String requestId,
               AccountId acc,
               long timestamp)
Create an unsigned request
Parameters:
requestId - the request identifier
acc - the identifier of the account holder making the request
date - the time of the request

Request

public Request(java.lang.String requestId,
               AccountId acc)
Create an unsigned request
Parameters:
requestId - the request identifier
acc - the identifier of the account holder making the request

Request

public Request(byte[] requestData)
        throws SOXPacketException
Construct a request object from a byte array that was previously returned from the encode() method of a request object. This is the usual method of constructing Requests for SOX clients, and is done using data received from the issuer. If the signature is not present in the encoded data, the created request will be unsigned. This constructor is not usually called by SOX clients.
Parameters:
requestData - the previously encoded request

Request

public Request(java.io.InputStream is)
        throws SOXPacketException
Construct a request object from data on an input stream that was previously returned from the encode() method of a request object. This is the usual method of constructing Requests for SOX clients, and is done using data received from the issuer. If the signature is not present in the encoded data, the created request will be unsigned. This constructor is not usually called by SOX clients.
Parameters:
requestData - the previously encoded request
Method Detail

getRequestVersion

public int getRequestVersion()

getVersion

public int getVersion()

setRequestVersion

public void setRequestVersion(int v)
Set the version number of this request. Not currently used, but something is needed. Will be used once we figure out what the server is set to...

getName

public abstract java.lang.String getName()
Returns the name of the packet as it goes on the wire.

getRequestId

public java.lang.String getRequestId()
Get the identifier on this request Note: although a java String is used, this identifier should only contain 8-bit ascii characters.

getAccountId

public AccountId getAccountId()
Get the account identifier of the request

getTimestamp

public long getTimestamp()
Get the time and date of the request

errorReply

public abstract Reply errorReply(int err)
Get an error Reply for this Request.
Parameters:
err - is the error number to set the reply to

reconstructReply

public Reply reconstructReply(byte[] buf)
                       throws SOXPacketException
Get an error Reply for this Request.
Parameters:
err - is the error number to set the reply to

isSigned

public boolean isSigned()
Check to see if this request is signed NOTE: This does not check the validity of the signature, only that this request has one.
Returns:
boolean true if this request has a signature

setSignature

public void setSignature(byte[] sig)
Define the signature for this request
Parameters:
sig - the signature to place on the request, or if null, then the signature (if any) is removed.

verify

public boolean verify(java.security.PublicKey key)
               throws SOXKeyException
Verify the signature on this request. This can be done by anyone with access to the public key (but not the private key).
Parameters:
key - the key to use to verify the request
Returns:
true if the signature is valid

decode

public void decode(java.io.InputStream is)
            throws java.io.IOException,
                   SOXPacketException
Update this request object with the values from a request encoded as a byte array (such as previously returned from the encode() method of a request object). If the signature is not present in the encoded data, the current signature (if any) will be removed. This method is usually used by subclasses to decode the request/timestamp/sig fields.
Overrides:
decode in class Encodable
Parameters:
is - the stream from which to read the request

encode

public void encode(java.io.OutputStream os)
            throws java.io.IOException
Encode a deposit request to an output stream, suitable for using with RequestPacket to send to remote servers (which use the decode() method to re-construct the object). If the signature is not present, an unsigned request will be encoded. (That is, it is sign()'s responsibility to set the sig to null in order to sign.)
Overrides:
encode in class Encodable
Parameters:
os - the stream on which to send the output
Returns:
byte[] the request in encoded form

toString

public java.lang.String toString()
Convert this object to a human readable string
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object