client
Class MessageGenerator

java.lang.Object
  extended by client.MessageGenerator

final class MessageGenerator
extends java.lang.Object

Provides methods for generating messages (the mixes are capable of processing) from byte arrays.

Author:
Karl-Peter Fuchs

Field Summary
private static NetworkClockController clock
          Reference on component NetworkClock.
private  Cryptography cryptography
          Used to encrypt messages.
private static InternalInformationPortController internalInformationPort
          Reference on component InternalInformationPortController.
private static java.util.logging.Logger LOGGER
          Logger used to log and display information.
private  java.security.Key[] macKeys
          Keys for message authentication codes (MACs).
private  int NUMBER_OF_MIXES_IN_CASCADE
          Number of mixes in the cascade.
 
Constructor Summary
protected MessageGenerator(int numberOfMixesInCascade, Cryptography cryptography)
          Generates a new MessageGenerator for generating messages (the mixes are capable of processing) from byte arrays.
 
Method Summary
protected  byte[] generateChannelEstablishMessage(byte[] bytePayload)
          Generates a message which consists of one or more (encrypted) layers, the cascade's mixes are capable of processing from the bypassed data (Type: ChannelEstablishMessage).
protected  byte[] generateChannelMessage(byte[] bytePayload)
          Generates a message which consists of one or more (encrypted) layers, the cascade's mixes are capable of processing from the bypassed data (Type: ChannelMessage).
private  Message generatePlaintextChannelEstablishMessage(int positionOfMixInCascade, Payload payload, int messageID)
          Generates a new (plaintext) ChannelEstablishMessage for the specified mix.
private  Message generatePlaintextChannelMessage(int positionOfMixInCascade, Payload payload, int messageID)
          Generates a new (plaintext) ChannelMessage for the specified mix.
 
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 InternalInformationPortController. 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.


clock

private static NetworkClockController clock
Reference on component NetworkClock.


NUMBER_OF_MIXES_IN_CASCADE

private final int NUMBER_OF_MIXES_IN_CASCADE
Number of mixes in the cascade.


cryptography

private Cryptography cryptography
Used to encrypt messages.


macKeys

private java.security.Key[] macKeys
Keys for message authentication codes (MACs).

Constructor Detail

MessageGenerator

protected MessageGenerator(int numberOfMixesInCascade,
                           Cryptography cryptography)
Generates a new MessageGenerator for generating messages (the mixes are capable of processing) from byte arrays.

Parameters:
numberOfMixesInCascade - Number of mixes in the cascade this Client shall use.
cryptography - Reference on Cryptography object that shall be used to encrypt messages.
Method Detail

generateChannelEstablishMessage

protected byte[] generateChannelEstablishMessage(byte[] bytePayload)
                                          throws MessageTooLongException
Generates a message which consists of one or more (encrypted) layers, the cascade's mixes are capable of processing from the bypassed data (Type: ChannelEstablishMessage). A layer is added for each mix in the cascade.

Parameters:
bytePayload - Data to generate the mix message from.
Returns:
The generated ChannelEstablishMessage as a byte array.
Throws:
MessageTooLongException - Thrown when the bypassed message is larger than the maximum message size.

generateChannelMessage

protected byte[] generateChannelMessage(byte[] bytePayload)
                                 throws MessageTooLongException
Generates a message which consists of one or more (encrypted) layers, the cascade's mixes are capable of processing from the bypassed data (Type: ChannelMessage). A layer is added for each mix in the cascade.

Parameters:
bytePayload - Data to generate the mix message from.
Returns:
The generated ChannelMessage as a byte array.
Throws:
MessageTooLongException - Thrown when the bypassed message is larger than the maximum message size.

generatePlaintextChannelEstablishMessage

private Message generatePlaintextChannelEstablishMessage(int positionOfMixInCascade,
                                                         Payload payload,
                                                         int messageID)
Generates a new (plaintext) ChannelEstablishMessage for the specified mix. Generates message header and authentication information as well.

Parameters:
positionOfMixInCascade - The mix' position in the cascade, the plaintext message shall be created for.
payload - Payload to be embedded.
messageID - Note: For testing only (MAKES MIX INSECURE): An identifieing number, which is the same for every envelope of a mix message. Used to trace messages for debugging.
Returns:
The generated (plaintext) message.

generatePlaintextChannelMessage

private Message generatePlaintextChannelMessage(int positionOfMixInCascade,
                                                Payload payload,
                                                int messageID)
Generates a new (plaintext) ChannelMessage for the specified mix. Generates message header and authentication information as well.

Parameters:
positionOfMixInCascade - The mix' position in the cascade, the plaintext message shall be created for.
payload - Payload to be embedded.
messageID - Note: For testing only (MAKES MIX INSECURE): An identifieing number, which is the same for every envelope of a mix message. Used to trace messages for debugging.
Returns:
The generated (plaintext) message.