inputOutputHandler
Class NextMixConnectionHandler

java.lang.Object
  extended by java.lang.Thread
      extended by inputOutputHandler.NextMixConnectionHandler
All Implemented Interfaces:
java.lang.Runnable

final class NextMixConnectionHandler
extends java.lang.Thread

Handles communication with the next mix in the cascade.

Establishes a (TCP) connection with the next mix which is used to transmit messages (Requests and Replyies) of all users connected to the cascade's fist mix (multiplex channel).

(De-)multiplexes Requests/Replyies using an (encrypted) header (see generateInterMixHeader()).

Replyies are put in the InputOutputHandlerController's replyInputQueue (see InputOutputHandlerController.addUnprocessedReply()). Requests are taken from the InputOutputHandlerController's requestOutputQueue (see InputOutputHandlerController.getProcessedRequest()).

Note: Authentication is NOT implemented!

Author:
Karl-Peter Fuchs

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  ExternalInformationPortController externalInformationPort
          Reference on component ExternalInformationPort (Used to provide the cryptographic key used to encrypt/decrypt multiplex-headers to the previous mix.
private  java.util.concurrent.atomic.AtomicBoolean handleRepliesIsWaitingForConnection
          Indicates that method handleReplies() wants to send replies (to next mix), but the connection is lost (Used for synchronization, when reestablishing connection).
private  InputOutputHandlerController inputOutputHandler
          Reference on InputOutputHandlerController() (Used to get processed replies and add unprocessed requests).
private  int INTER_MIX_BLOCK_SIZE
          Block size of the cryptographic algorithm used to encrypt the multiplex-header.
private  javax.crypto.Cipher interMixDecryptCipherWithNextMix
          Cipher for decrypting multiplex-headers of replies.
private  javax.crypto.Cipher interMixEncryptCipherWithNextMix
          Cipher for encrypting multiplex-headers of requests.
private  javax.crypto.spec.IvParameterSpec interMixIVWithNextMix
          Initialization vector used to encrypt data between this mix and the next one.
private  javax.crypto.SecretKey interMixKeyWithNextMix
          Key used to encrypt data between this mix and the next one.
private static InternalInformationPortController internalInformationPort
          Reference on component InternalInformationPort.
private static java.util.logging.Logger LOGGER
          Logger used to log and display information.
private  java.net.InetAddress NEXT_MIX_ADDRESS
          Address of the next mix (in the cascade).
private  int NEXT_MIX_INFO_PORT
          Port number of the next mix' ExternalInformationProvider component (used to receive key for enrypting/decrypting multiplex-headers).
private  int NEXT_MIX_PORT
          Port number of the next mix (in the cascade).
private  java.io.InputStream nextMixInputStream
          InputStream for communicating with next mix.
private  java.io.OutputStream nextMixOutputStream
          OutputStream for communicating with next mix.
private  java.net.Socket nextMixSocket
          Socket for communicating with next mix.
private  int POSITION_OF_MIX_IN_CASCADE
          The mix' position in the cascade this object belongs to. "1" means "first mix", "2" means "a middle mix" and "3" means "last mix" of cascade.
private  UserDatabaseController userDatabase
          Reference on component UserDatabase (Used to add/remove users).
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected NextMixConnectionHandler(InputOutputHandlerController inputOutputHandler, UserDatabaseController userDatabase, ExternalInformationPortController externalInformationPort)
          Constructs a new NextMixConnectionHandler which handles communication with the next mix in the cascade.
 
Method Summary
private  void connectToNextMix()
          Establishes a (permanent) connection to the next mix of the cascade.
private  byte[] encryptInterMixHeader(byte[] message)
          Encrypts the block containing the multiplex-header of the bypassed message.
private  byte[] generateInterMixHeader(Request request)
          Adds an (encrypted) header to a Request containing an identifier for the suiting channel (the identifier is unique for any neighboured mixes).
private  byte[] getPayload(Request request)
          Returns the payload of the bypassed Request.
private static java.lang.String getProperty(java.lang.String key)
          Simply used to shorten method calls (calls internalInformationPort.getProperty(key)).
private  void handleReplies()
          Waits for Replyies sent by next mix.
private  void resetInterMixCiphers()
          Resets the Ciphers used to encrypt data between this mix and the next one.
 void run()
          Sends processed messages (Requests) to next mix.
private  void setUpInterMixCiphers()
          Receives a cryptographic key, that is used to encrypt multiplex-headers (between this mix an the next mix) from the next mix and sets up suiting Ciphers.
private  void waitForConnection()
          Waits until a connection to the next mix is (re)established.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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.


POSITION_OF_MIX_IN_CASCADE

private final int POSITION_OF_MIX_IN_CASCADE
The mix' position in the cascade this object belongs to. "1" means "first mix", "2" means "a middle mix" and "3" means "last mix" of cascade.


INTER_MIX_BLOCK_SIZE

private final int INTER_MIX_BLOCK_SIZE
Block size of the cryptographic algorithm used to encrypt the multiplex-header.


NEXT_MIX_ADDRESS

private final java.net.InetAddress NEXT_MIX_ADDRESS
Address of the next mix (in the cascade).


NEXT_MIX_PORT

private final int NEXT_MIX_PORT
Port number of the next mix (in the cascade).


NEXT_MIX_INFO_PORT

private final int NEXT_MIX_INFO_PORT
Port number of the next mix' ExternalInformationProvider component (used to receive key for enrypting/decrypting multiplex-headers).


userDatabase

private UserDatabaseController userDatabase
Reference on component UserDatabase (Used to add/remove users).


inputOutputHandler

private InputOutputHandlerController inputOutputHandler
Reference on InputOutputHandlerController() (Used to get processed replies and add unprocessed requests).

See Also:
InputOutputHandlerController.addUnprocessedRequest(Request), InputOutputHandlerController.getProcessedReply()

externalInformationPort

private ExternalInformationPortController externalInformationPort
Reference on component ExternalInformationPort (Used to provide the cryptographic key used to encrypt/decrypt multiplex-headers to the previous mix.


nextMixSocket

private java.net.Socket nextMixSocket
Socket for communicating with next mix.


nextMixInputStream

private java.io.InputStream nextMixInputStream
InputStream for communicating with next mix.


nextMixOutputStream

private java.io.OutputStream nextMixOutputStream
OutputStream for communicating with next mix.


interMixEncryptCipherWithNextMix

private javax.crypto.Cipher interMixEncryptCipherWithNextMix
Cipher for encrypting multiplex-headers of requests.


interMixDecryptCipherWithNextMix

private javax.crypto.Cipher interMixDecryptCipherWithNextMix
Cipher for decrypting multiplex-headers of replies.


interMixKeyWithNextMix

private javax.crypto.SecretKey interMixKeyWithNextMix
Key used to encrypt data between this mix and the next one.


interMixIVWithNextMix

private javax.crypto.spec.IvParameterSpec interMixIVWithNextMix
Initialization vector used to encrypt data between this mix and the next one.


handleRepliesIsWaitingForConnection

private java.util.concurrent.atomic.AtomicBoolean handleRepliesIsWaitingForConnection
Indicates that method handleReplies() wants to send replies (to next mix), but the connection is lost (Used for synchronization, when reestablishing connection).

See Also:
handleReplies(), connectToNextMix()
Constructor Detail

NextMixConnectionHandler

protected NextMixConnectionHandler(InputOutputHandlerController inputOutputHandler,
                                   UserDatabaseController userDatabase,
                                   ExternalInformationPortController externalInformationPort)
Constructs a new NextMixConnectionHandler which handles communication with the next mix in the cascade.

Establishes a (TCP) connection with the next mix which is used to transmit messages (Requests and Replyies) of all users connected to the cascade's fist mix (multiplex channel).

(De-)multiplexes Requests/Replyies using an (encrypted) header (see generateInterMixHeader()).

Replyies are put in the InputOutputHandlerController's replyInputQueue (see InputOutputHandlerController.addUnprocessedReply()). Requests are taken from the InputOutputHandlerController's requestOutputQueue (see InputOutputHandlerController.getProcessedRequest()).

Note: Authentication is NOT implemented!

Method Detail

handleReplies

private void handleReplies()
Waits for Replyies sent by next mix.


waitForConnection

private void waitForConnection()
Waits until a connection to the next mix is (re)established.


run

public void run()
Sends processed messages (Requests) to next mix.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
InputOutputHandlerController.getProcessedRequest()

connectToNextMix

private void connectToNextMix()
Establishes a (permanent) connection to the next mix of the cascade.


generateInterMixHeader

private byte[] generateInterMixHeader(Request request)
Adds an (encrypted) header to a Request containing an identifier for the suiting channel (the identifier is unique for any neighboured mixes).

Parameters:
request - Request without header.
Returns:
Request with header.

getPayload

private byte[] getPayload(Request request)
Returns the payload of the bypassed Request.

Parameters:
request - Request containing the payload to be returned.
Returns:
Payload of the bypassed Request.

encryptInterMixHeader

private byte[] encryptInterMixHeader(byte[] message)
Encrypts the block containing the multiplex-header of the bypassed message.

Parameters:
message - Message with plaintext multiplex-header.
Returns:
Message with encrypted multiplex-header.

setUpInterMixCiphers

private void setUpInterMixCiphers()
Receives a cryptographic key, that is used to encrypt multiplex-headers (between this mix an the next mix) from the next mix and sets up suiting Ciphers.

Note: Authentication NOT implemented!


resetInterMixCiphers

private void resetInterMixCiphers()
Resets the Ciphers used to encrypt data between this mix and the next one. Must be called when connection was lost, since Ciphers might be out of sync in that case.


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.