client
Class Client

java.lang.Object
  extended by client.Client
All Implemented Interfaces:
ClientInterface

public final class Client
extends java.lang.Object
implements ClientInterface

The Client used to anonymize data (e. g. from a user's application) via a cascade of mixes. Follows the "everything is a stream" concept. See architectureInterfaces.ClientInterface. From a user perspective, this Client behaves quite equal to a socket (java.net.Socket) and therefore abstracts from the underlying technique.

Author:
Karl-Peter Fuchs

Nested Class Summary
private  class Client.CascadeInputOutputHandler
          Internal class used to communicate with the mix cascade.
 
Field Summary
private  java.net.InetAddress CASCADE_ADDRESS
          Address of the cascade (cascade's first mix) used to transmit messages.
private  int CASCADE_PORT
          Port number of the cascade (cascade's first mix) used to transmit messages.
private  int CASCADE_TIMEOUT
          Period of time, a client waits for the cascade to accept his connection request in ms.
private  ClientInputStream clientInputStream
          ClientInputStream for client communication.
private  ClientOutputStream clientOutputStream
          ClientOutputStream for client communication.
private  Cryptography cryptography
          Used to perform cryptographic operations (decrypting, encrypting, generating session keys, MACs... ).
private static InternalInformationPortController internalInformationPort
          Reference on component InternalInformationPort.
private  boolean isChannelEstablished
          Indicates whether a channel to the cascade is established or not.
private  boolean isDisconnectRequested
          Indicates whether the user (application) called disconnect() and therefore wants to release his/its connection to the cascade.
private  boolean isFirstWriteDone
          Indicates whether the user (application) has already put data in the OutputStream (used to start the ).
private  boolean isReadMethodReturnForced
          Indicates whether the method receiveDataFromCascade() shall return all data received so far, no matter how much data it is waiting for (since no further data can be expected from the cascade).
private  boolean isReadMethodWaiting
          Indicates whether the method receiveDataFromCascade() is waiting for new data from the cascade (used for synchronization).
private  boolean isWriteMethodWaiting
          Indicates whether the method putInSendBuffer() is waiting for the CascadeInputOutputHandler to send the data it gave to it (used for synchronization).
private static java.util.logging.Logger LOGGER
          Logger used to log and display information.
private  int MAX_CHANNEL_ESTABLISH_MESSAGE_LENGTH
          Maximum amount of data (payload), that can be stored in a ChannelEstablishMessage.
private  int MAX_CHANNEL_MESSAGE_LENGTH
          Maximum amount of data (payload), that can be stored in a ChannelMessage.
private  MessageGenerator messageGenerator
          Used to generate message the mixes are capable of processing.
private  java.net.Socket mix
          Socket for mix communication.
private  java.io.InputStream mixInputStream
          MixInputStream for mix communication.
private  java.io.OutputStream mixOutputStream
          MixOutputStream for mix communication.
private  long REACTION_TIME
          Period of time to wait between the receival of a Reply (from the cascade) and the sending of a new Request for the user (application) to react (= add new data to be sent).
private  int RECEIVE_BUFFER_SIZE
          Initial size of the receiveBuffer.
private  java.nio.ByteBuffer receiveBuffer
          Buffer to store incoming data from the cascade.
private  java.lang.Object receiveBufferSynchronizer
          Object used to synchronize the receiveBuffer.
private  int SEND_BUFFER_SIZE
          Initial size of the sendBuffer.
private  java.nio.ByteBuffer sendBuffer
          Buffer to store data that shall be sent to the cascade.
 
Constructor Summary
Client()
          Creates a new Client which receives the keys (to encrypt messages) from the cascade's mixes automatically.
Client(java.security.Key[] publicKeysOfMixes)
          Creates a new Client which uses the bypassed keys to encrypt messages.
 
Method Summary
 void connect()
          Connects client to the mix cascade, specified in property file.
 void disconnect()
          Disconnects client from mix cascade.
 ClientInputStream getInputStream()
          Returns an InputStream that can be used to receive data anonymously.
 ClientOutputStream getOutputStream()
          Returns an OutputStream that can be used to send data anonymously.
private static java.lang.String getProperty(java.lang.String key)
          Simply used to shorten method calls (calls internalInformationPort.getProperty(key)).
private static java.security.PublicKey[] getPublicKeys()
          Retrieves the public keys of all mixes in the cascade (address of first mix must be specified in property file) for later encryption.
protected  void putInSendBuffer(byte[] data)
          Adds the bypassed data to the sendBuffer (from where it gets transmitted to the mix cascade by CascadeInputOutputHandler ).
protected  byte[] receiveDataFromCascade(int amoutOfDataNeeded)
          Tries to read amoutOfDataNeeded bytes from the mix cascade.
private  void sendMessage(byte[] dataToSend)
          Sends the bypassed data to the mix cascade.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

internalInformationPort

private static InternalInformationPortController internalInformationPort
Reference on component InternalInformationPort. Used to display and/or log data and read general settings.


LOGGER

private static final java.util.logging.Logger LOGGER
Logger used to log and display information.


CASCADE_ADDRESS

private final java.net.InetAddress CASCADE_ADDRESS
Address of the cascade (cascade's first mix) used to transmit messages.


CASCADE_PORT

private final int CASCADE_PORT
Port number of the cascade (cascade's first mix) used to transmit messages.


CASCADE_TIMEOUT

private final int CASCADE_TIMEOUT
Period of time, a client waits for the cascade to accept his connection request in ms.


MAX_CHANNEL_ESTABLISH_MESSAGE_LENGTH

private final int MAX_CHANNEL_ESTABLISH_MESSAGE_LENGTH
Maximum amount of data (payload), that can be stored in a ChannelEstablishMessage.


MAX_CHANNEL_MESSAGE_LENGTH

private final int MAX_CHANNEL_MESSAGE_LENGTH
Maximum amount of data (payload), that can be stored in a ChannelMessage.


REACTION_TIME

private final long REACTION_TIME
Period of time to wait between the receival of a Reply (from the cascade) and the sending of a new Request for the user (application) to react (= add new data to be sent). Note: If no new data or a disconnect request has arrived during this period of time, a dummy message is sent.


mix

private java.net.Socket mix
Socket for mix communication.


clientOutputStream

private ClientOutputStream clientOutputStream
ClientOutputStream for client communication.


clientInputStream

private ClientInputStream clientInputStream
ClientInputStream for client communication.


mixOutputStream

private java.io.OutputStream mixOutputStream
MixOutputStream for mix communication.


mixInputStream

private java.io.InputStream mixInputStream
MixInputStream for mix communication.


receiveBuffer

private java.nio.ByteBuffer receiveBuffer
Buffer to store incoming data from the cascade.


receiveBufferSynchronizer

private java.lang.Object receiveBufferSynchronizer
Object used to synchronize the receiveBuffer.

Note: This requires a special object, since the used ByteBuffer-object may change during runtime (In Java, ByteBuffers can't be resized. Nevertheless, the buffer's size must be adjusted in a few cases (when unexpected large write-requests occur)). Therefore, a permanently available object must be present.

See Also:
receiveBuffer

sendBuffer

private java.nio.ByteBuffer sendBuffer
Buffer to store data that shall be sent to the cascade.


RECEIVE_BUFFER_SIZE

private final int RECEIVE_BUFFER_SIZE
Initial size of the receiveBuffer.

See Also:
receiveBuffer

SEND_BUFFER_SIZE

private final int SEND_BUFFER_SIZE
Initial size of the sendBuffer.

See Also:
sendBuffer

isChannelEstablished

private boolean isChannelEstablished
Indicates whether a channel to the cascade is established or not.


isReadMethodWaiting

private boolean isReadMethodWaiting
Indicates whether the method receiveDataFromCascade() is waiting for new data from the cascade (used for synchronization).

See Also:
receiveDataFromCascade(int)

isReadMethodReturnForced

private boolean isReadMethodReturnForced
Indicates whether the method receiveDataFromCascade() shall return all data received so far, no matter how much data it is waiting for (since no further data can be expected from the cascade).

See Also:
receiveDataFromCascade(int)

isWriteMethodWaiting

private boolean isWriteMethodWaiting
Indicates whether the method putInSendBuffer() is waiting for the CascadeInputOutputHandler to send the data it gave to it (used for synchronization).

See Also:
putInSendBuffer(byte[])

isDisconnectRequested

private boolean isDisconnectRequested
Indicates whether the user (application) called disconnect() and therefore wants to release his/its connection to the cascade.

See Also:
disconnect()

isFirstWriteDone

private boolean isFirstWriteDone
Indicates whether the user (application) has already put data in the OutputStream (used to start the ). called disconnect() and therefore wants to release his/its connection to the CascadeInputOutputHandler at the right time.

See Also:
disconnect()

cryptography

private Cryptography cryptography
Used to perform cryptographic operations (decrypting, encrypting, generating session keys, MACs... ).


messageGenerator

private MessageGenerator messageGenerator
Used to generate message the mixes are capable of processing.

Constructor Detail

Client

public Client(java.security.Key[] publicKeysOfMixes)
Creates a new Client which uses the bypassed keys to encrypt messages.

Parameters:
publicKeysOfMixes - Public keys of the cascade's mixes (used to encrypt messages).

Client

public Client()
Creates a new Client which receives the keys (to encrypt messages) from the cascade's mixes automatically.

Method Detail

getPublicKeys

private static java.security.PublicKey[] getPublicKeys()
Retrieves the public keys of all mixes in the cascade (address of first mix must be specified in property file) for later encryption.

Returns:
The public keys of all mixes in the cascade.

getInputStream

public ClientInputStream getInputStream()
Returns an InputStream that can be used to receive data anonymously.

Specified by:
getInputStream in interface ClientInterface
Returns:
InputStream that can be used to receive data anonymously.
Throws:
java.io.IOException - I/O problem occurred.

getOutputStream

public ClientOutputStream getOutputStream()
Returns an OutputStream that can be used to send data anonymously.

Specified by:
getOutputStream in interface ClientInterface
Returns:
OutputStream that can be used to send data anonymously.
Throws:
java.io.IOException - I/O problem occurred.

connect

public void connect()
             throws java.io.IOException
Connects client to the mix cascade, specified in property file.

Specified by:
connect in interface ClientInterface
Throws:
java.io.IOException - I/O problem occurred.

disconnect

public void disconnect()
                throws java.io.IOException
Disconnects client from mix cascade.

Specified by:
disconnect in interface ClientInterface
Throws:
java.io.IOException - I/O problem occurred.

putInSendBuffer

protected void putInSendBuffer(byte[] data)
Adds the bypassed data to the sendBuffer (from where it gets transmitted to the mix cascade by CascadeInputOutputHandler ). Blocks until all data is written (if data doesn't fit in buffer).

Parameters:
data - Data to be put in sendBuffer.

sendMessage

private void sendMessage(byte[] dataToSend)
Sends the bypassed data to the mix cascade. Called by CascadeInputOutputHandler.

Parameters:
dataToSend - Data to be sent.

receiveDataFromCascade

protected byte[] receiveDataFromCascade(int amoutOfDataNeeded)
Tries to read amoutOfDataNeeded bytes from the mix cascade. Blocks until amoutOfDataNeeded bytes are available, or no further data can be expected from the corresponding communication partner.

Parameters:
amoutOfDataNeeded - Number of bytes that shall be read.
Returns:
Read data.

getProperty

private static java.lang.String getProperty(java.lang.String key)
Simply used to shorten method calls (calls internalInformationPort.getProperty(key)). Returns the property with the specified key from the property file.

Parameters:
key - The property key.
Returns:
The property with the specified key in the property file.