webfunds.sox
Class EncryptedRequest

java.lang.Object
  |
  +--webfunds.sox.Encodable
        |
        +--webfunds.sox.BasicRequest
              |
              +--webfunds.sox.EncryptedRequest

public class EncryptedRequest
extends BasicRequest

An EncryptedRequest is a "basic" request, that encapsulates a (signable) Request. This class can be thought of as the "gateway" between the basic transport layer and the (signable) Request layer

See Also:
Serialized Form

Field Summary
protected  byte[] data
          The (encrypted) payload
protected  int encType
          The type of encryption used
protected  byte[] inner
          The inner packet within the encrypted payload, to be made into a request.
protected  java.security.Key key
          The key used for encrypting and decrypting the payload.
static int NONE
          Definitions for the various encryption methods
protected  byte[] plaintext
          The (decrypted) payload
static int PUBLIC
           
protected  Request req
           
static int SECRET
           
protected  java.lang.String type
           
 int version
           
static int VERSION
          The version number of the encrypted request packet.
 
Constructor Summary
EncryptedRequest(byte[] data)
           
EncryptedRequest(EncryptedRequest req)
          Extend this to convert these into application requests.
EncryptedRequest(java.io.InputStream is)
           
EncryptedRequest(Request req)
          Construct a null-encrypted request (type "none").
EncryptedRequest(Request req, java.security.Key key, byte[] data)
          Construct an encrypted request (type secret).
EncryptedRequest(Request req, java.security.Key key, java.security.PublicKey pub)
          Construct an encrypted request (type public).
 
Method Summary
 EncryptedReply createReply(Reply reply)
           
 EncryptedReply createReply(Reply reply, java.security.Key sessionKey)
           
 void decode(java.io.InputStream is)
           
 Request decodeApplicationRequest(java.lang.String type, byte[] encoded)
          Extend this class to use SOX for something else.
 java.lang.String decodeHeader()
          Now it is decrypted, we can decode the plaintext payload.
 void decryptPacket(java.security.PrivateKey key)
          Decrypt this packet.
 void encode(java.io.OutputStream os)
           
 byte[] encodeRequest(Request request)
           
 byte[] getInner()
           
 Request getRequest()
          Packet Factory method to decode the inner request, according to type.
 Request getRequest(java.security.PrivateKey key)
          Decrypt this packet and return the request within.
 java.lang.String getType()
           
 boolean isEncrypted()
           
 boolean isStandardSOX()
           
 java.lang.String toString()
           
 
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, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final int VERSION
The version number of the encrypted request packet. This is the default, latest version. A received packet may be of a lesser version than this code.

version

public int version

NONE

public static final int NONE
Definitions for the various encryption methods

PUBLIC

public static final int PUBLIC

SECRET

public static final int SECRET

data

protected byte[] data
The (encrypted) payload

plaintext

protected byte[] plaintext
The (decrypted) payload

inner

protected byte[] inner
The inner packet within the encrypted payload, to be made into a request.

key

protected java.security.Key key
The key used for encrypting and decrypting the payload.

encType

protected int encType
The type of encryption used

type

protected java.lang.String type

req

protected Request req
Constructor Detail

EncryptedRequest

public EncryptedRequest(Request req)
                 throws SOXPacketException
Construct a null-encrypted request (type "none"). No encryption is done. This may be useful for countries where clients are not allowed to encrypt their communications, although SOX servers may potentially refuse to accept unencrypted requests.
Parameters:
req - The request to be encrypted

EncryptedRequest

public EncryptedRequest(Request req,
                        java.security.Key key,
                        java.security.PublicKey pub)
                 throws SOXKeyException,
                        SOXPacketException
Construct an encrypted request (type public). The request body is encrypted with the provided key, and this key is then encrypted with the certificate.
Parameters:
req - The request to be encrypted
key - The key with which to encrypt the request data
cert - The certificate with which to encrypt the key

EncryptedRequest

public EncryptedRequest(Request req,
                        java.security.Key key,
                        byte[] data)
                 throws SOXKeyException,
                        SOXPacketException
Construct an encrypted request (type secret). The request body is encrypted with the provided key (which was previously provided by the server), and the (symetrically) encrypted data is used by the server to retrieve the key.
Parameters:
req - The request to be encrypted
key - The key with which to encrypt the request data
cert - The certificate with which to encrypt the key

EncryptedRequest

public EncryptedRequest(byte[] data)
                 throws SOXPacketException,
                        UnknownRequestException

EncryptedRequest

public EncryptedRequest(java.io.InputStream is)
                 throws java.io.IOException,
                        SOXPacketException

EncryptedRequest

public EncryptedRequest(EncryptedRequest req)
Extend this to convert these into application requests.
Method Detail

isEncrypted

public boolean isEncrypted()

getType

public java.lang.String getType()

getInner

public byte[] getInner()

encode

public void encode(java.io.OutputStream os)
            throws java.io.IOException
Overrides:
encode in class Encodable

decode

public void decode(java.io.InputStream is)
            throws java.io.IOException,
                   SOXPacketException
Overrides:
decode in class Encodable

encodeRequest

public byte[] encodeRequest(Request request)
                     throws SOXPacketException

decryptPacket

public void decryptPacket(java.security.PrivateKey key)
                   throws SOXKeyException
Decrypt this packet. Call this first. These steps are broken out so that decryption and packet examination can help decide how to treat the inner data.

getRequest

public Request getRequest(java.security.PrivateKey key)
                   throws SOXPacketException,
                          SOXKeyException
Decrypt this packet and return the request within. (probably) not used anymore.

decodeHeader

public java.lang.String decodeHeader()
                              throws SOXPacketException
Now it is decrypted, we can decode the plaintext payload.

decodeApplicationRequest

public Request decodeApplicationRequest(java.lang.String type,
                                        byte[] encoded)
                                 throws SOXPacketException
Extend this class to use SOX for something else.
Returns:
a request of type

getRequest

public Request getRequest()
                   throws SOXPacketException
Packet Factory method to decode the inner request, according to type. This method only does the standard SOX set here. Also only works if in a decrypted state.

isStandardSOX

public boolean isStandardSOX()
Returns:
true if this is one of the standard set and decodeRequest works elsewise false, including if not yet decrypted

createReply

public EncryptedReply createReply(Reply reply)
                           throws SOXKeyException

createReply

public EncryptedReply createReply(Reply reply,
                                  java.security.Key sessionKey)
                           throws SOXKeyException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object