messageProcessor
Class Recoder

java.lang.Object
  extended by messageProcessor.Recoder

final class Recoder
extends java.lang.Object

Recodes (decrypts/encrypts) messages. Prevents linkability of (incoming and outgoing) messages due to their appearance.

This class is thread-safe (but parallel execution of a single instance's methods won't increase performance. For parallel processing, several Recoders are needed).

Author:
Karl-Peter Fuchs

Field Summary
private  javax.crypto.Cipher asymmetricCipher
          Cipher for asymmetric cryptography.
private static InternalInformationPortController internalInformationPort
          Reference on InternalInformationPort.
private  java.security.KeyPair KEY_PAIR
          Public and private key of the asymmetric crypto system.
private static java.util.logging.Logger LOGGER
          Logger used to log and display information.
 
Constructor Summary
protected Recoder()
          Constructor used to generate a Recoder used to encrypt replies.
protected Recoder(java.security.KeyPair keyPair)
          Constructor used to generate a Recoder used to decrypt requests.
 
Method Summary
protected  byte[] decrypt(byte[] data, java.lang.String transformation)
          Decrypts the bypassed data using the internal asymmetric cipher (and private key) and the specified transformation.
private  ChannelEstablishMessage decrypt(ChannelEstablishMessage message)
          Decrypts the hybridly encrypted, bypassed ChannelEstablishMessage.
private  ChannelMessage decrypt(ChannelMessage message)
          Decrypts the symmetrically encrypted, bypassed ChannelMessage.
private  ReplyMessage encrypt(ReplyMessage message)
          Encrypts the bypassed ReplyMessage.
protected  java.security.Key getPublicKey()
          Returns the public key of this Recoder.
private  void initializeCiphersForUser(User channel, ChannelEstablishMessage message)
          Initializes the ciphers used to recode messages for the bypassed user/channel.
protected  Message recode(BasicMessage message)
          Recodes (decrypts/encrypts) the bypassed message according to its type.
 
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 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.


KEY_PAIR

private final java.security.KeyPair KEY_PAIR
Public and private key of the asymmetric crypto system.


asymmetricCipher

private javax.crypto.Cipher asymmetricCipher
Cipher for asymmetric cryptography.

Constructor Detail

Recoder

protected Recoder(java.security.KeyPair keyPair)
Constructor used to generate a Recoder used to decrypt requests.

Creates a new Recoder which will use the bypassed KeyPair to decrypt messages.

Instantiates Cipher objects for later use as specified in the property file.

Parameters:
keyPair - Public and private key of the asymmetric crypto system.

Recoder

protected Recoder()
Constructor used to generate a Recoder used to encrypt replies.

Method Detail

getPublicKey

protected java.security.Key getPublicKey()
Returns the public key of this Recoder.

Returns:
The public key of this Recoder.

recode

protected Message recode(BasicMessage message)
Recodes (decrypts/encrypts) the bypassed message according to its type.

Parameters:
message - The message to be recoded.
Returns:
The recoded message (same reference as previously bypassed). "Null", if recoding failed.

decrypt

private ChannelEstablishMessage decrypt(ChannelEstablishMessage message)
Decrypts the hybridly encrypted, bypassed ChannelEstablishMessage.

Parameters:
message - The message to be decrypted.
Returns:
The decrypted message (same reference as previously bypassed). null, if recoding failed.

decrypt

private ChannelMessage decrypt(ChannelMessage message)
Decrypts the symmetrically encrypted, bypassed ChannelMessage.

Parameters:
message - The message to be decrypted.
Returns:
The decrypted message (same reference as previously bypassed). null, if recoding failed.

encrypt

private ReplyMessage encrypt(ReplyMessage message)
Encrypts the bypassed ReplyMessage.

Parameters:
message - The message to be encrypted.
Returns:
The encrypted message (same reference as previously bypassed). null, if recoding failed.

initializeCiphersForUser

private void initializeCiphersForUser(User channel,
                                      ChannelEstablishMessage message)
                               throws java.lang.Exception
Initializes the ciphers used to recode messages for the bypassed user/channel.

Parameters:
channel - User/channel the ciphers shall be initialized for.
message - Message containing the data needed to initialize the ciphers (session key and initialization vector).
Throws:
java.lang.Exception - If the initialization process fails.

decrypt

protected byte[] decrypt(byte[] data,
                         java.lang.String transformation)
                  throws java.lang.Exception
Decrypts the bypassed data using the internal asymmetric cipher (and private key) and the specified transformation.

Parameters:
data - Data to be decrypted.
transformation - Transformation that shall be used for decryption.
Returns:
Decrypted data.
Throws:
java.lang.Exception - Any type of error preventing the data from being decrypted.