com.monica.javacom.ciphering
Class MJCBasicCiphering

java.lang.Object
  |
  +--com.monica.javacom.ciphering.MJCBasicCiphering
All Implemented Interfaces:
MJCCiphering, MJCConfigureable, MJCReadable, MJCReader, MJCWriteable, MJCWriter, java.lang.Runnable

public class MJCBasicCiphering
extends java.lang.Object
implements MJCCiphering

This is a middle level layer in the MJC layer hierarchy responsible for ciphering the data stream between the upper layers. Implements cipher key exchanges, coding and encoding. At initialization it is transparent, it leaves data as it is, it just lets input through. After getting setTransparent(false) the keyexchange starts. The client side has the setTransparent(false) called by the upper layer. It sends a special message to the server, that also calls its own setTransparent(false). The server generates an rsa-key-pair, sends the public key to the client in a special packet. After that, he constructs his own RSA coder with the private key of the keypair just generated. The client, after receiving the public key, constructs his RSA coder, and generates an aes key. He sends this key, coded with the public key, to the server, and constructs his AES coder. The server, as he got the AES key, also constructs the AES coder. So, by now, both sides have the proper AES coder (hopefully). The server sends a special String, included in a control pocket, to the client, and switches to ciphering mode. From this point he can only recieve encripted data, this means, every pocket, he gets will be decripted before forwarding it to the upper layer. The client, as it gets the special control packet, tries to decript it. If the original String is the result, then everything worked fine during the key exchange, and it also switches to ciphering mode, like the server. At this point the setTransparent(false) function returns from its synchronized state, and the communication (telnet initialization, authentification, data exchange) can go on encripted.


Constructor Summary
MJCBasicCiphering(boolean in_enVagyokASzerver)
          Constructs a new MJCCiphering layer.
 
Method Summary
 void connectionClosedEvent(MJCReadable readable)
          Indicates that the source connection of the specified MJCReadable has been closed.
 void errorEvent(java.lang.String errorDescription, MJCReadable readable)
          Indicates that there was an error in the source connection of the specified MJCReadable.
 void flush()
          Flushes the contents of the write buffer to bottom layers.
 int getAvailable()
          Returns the number of bytes that are available for read out from this MJCReadable.
 java.lang.String getCipheringName()
          Returns the MJC name of the MJCCiphering.
 java.lang.String getCipheringVersion()
          Returns the MJC version of the MJCCiphering.
 MJCConfiguration getConfiguration()
          Returns the MJCConfiguration with which this object is customized.
 java.lang.String getInput()
          Returns the contents of the read buffer from this MJCReadable.
 java.lang.String getLastWriteableError()
          Returns the error message of the last occured error.
 MJCReadable getReadable()
          Returns the MJCReadable from which data will be read.
 java.lang.String getReadableName()
          Returns the MJC name of the MJCReadable.
 java.lang.String getReadableVersion()
          Returns the MJC version of the MJCReadable.
 MJCReader getReader()
          Returns the MJCReader to which readEvents will be sent.
 java.lang.String getReaderName()
          Returns the MJC name of the MJCReader.
 java.lang.String getReaderVersion()
          Returns the MJC version of the MJCReader.
 MJCWriteable getWriteable()
          Returns the MJCWriteable to which this MCJWriter will write.
 java.lang.String getWriteableName()
          Returns the MJC name of the MJCWriteable.
 java.lang.String getWriteableVersion()
          Returns the MJC version of the MJCWriteable.
 java.lang.String getWriterName()
          Returns the MJC name of the MJCWriter.
 java.lang.String getWriterVersion()
          Returns the MJC version of the MJCWriter.
 boolean isReadableConnected()
          Returns wether the MJCReadable is still connected to its source.
 boolean isWriteableConnected()
          Returns wether the MJCWriteable is connected to its target.
 void readEvent(MJCReadable readable)
          Indicates that there is data available from the specified MJCReadable.
 void run()
          Run thread.
 void setConfiguration(MJCConfiguration configuration)
          Sets the MJCConfiguration for this object.
 void setReadable(MJCReadable readable)
          Sets the MJCReadable from which data has to be read.
 void setReader(MJCReader reader)
          Sets the MJCReader to which the readEvents have to be sent.
 void setTransparent(boolean status)
          This method toggles the transparency mode of the MJCCiphering layer.
 void setWriteable(MJCWriteable writeable)
          Sets the MJCWriteable to which this MJCWriter will write.
 boolean write(char c)
          Writes one single char.
 boolean write(char[] c)
          Writes a char array.
 boolean write(java.lang.String s)
          Writes a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MJCBasicCiphering

public MJCBasicCiphering(boolean in_enVagyokASzerver)
Constructs a new MJCCiphering layer.
Parameters:
in_enVagyokASzerver - true if this is the server side, false if this is the client side
Method Detail

getCipheringName

public java.lang.String getCipheringName()
Returns the MJC name of the MJCCiphering.
Specified by:
getCipheringName in interface MJCCiphering
Returns:
the MJC name of the MJCCiphering

getCipheringVersion

public java.lang.String getCipheringVersion()
Returns the MJC version of the MJCCiphering.
Specified by:
getCipheringVersion in interface MJCCiphering
Returns:
the MJC version of the MJCCiphering

setTransparent

public void setTransparent(boolean status)
This method toggles the transparency mode of the MJCCiphering layer. The parameter true makes the layer transparent, this means no encoding will happen, the parameter false shows the beginning of the encoding. By default the layer is transparent. Currently only setTransparent(false) is supported, setTransparent(true) has no effect.
Specified by:
setTransparent in interface MJCCiphering
Parameters:
status - the desired transparency mode

getWriterName

public java.lang.String getWriterName()
Returns the MJC name of the MJCWriter.
Specified by:
getWriterName in interface MJCWriter
Returns:
the MJC name of the MJCWriter

getWriterVersion

public java.lang.String getWriterVersion()
Returns the MJC version of the MJCWriter.
Specified by:
getWriterVersion in interface MJCWriter
Returns:
the MJC version of the MJCWriter

setWriteable

public void setWriteable(MJCWriteable writeable)
Sets the MJCWriteable to which this MJCWriter will write.
Specified by:
setWriteable in interface MJCWriter
Parameters:
writeable - the MJCWriteable to which this MJCWriter will write

getWriteable

public MJCWriteable getWriteable()
Returns the MJCWriteable to which this MCJWriter will write.
Specified by:
getWriteable in interface MJCWriter
Returns:
the MJCWriteable to which this MJCWriter will write

setConfiguration

public void setConfiguration(MJCConfiguration configuration)
Sets the MJCConfiguration for this object.
Specified by:
setConfiguration in interface MJCConfigureable
Parameters:
configuration - the MJCConfiguration object for the customization

getConfiguration

public MJCConfiguration getConfiguration()
Returns the MJCConfiguration with which this object is customized.
Specified by:
getConfiguration in interface MJCConfigureable
Returns:
the MJCConfiguration with which this object is customized

getReadableName

public java.lang.String getReadableName()
Returns the MJC name of the MJCReadable.
Specified by:
getReadableName in interface MJCReadable
Returns:
the MJC name of the MJCReadable

getReadableVersion

public java.lang.String getReadableVersion()
Returns the MJC version of the MJCReadable.
Specified by:
getReadableVersion in interface MJCReadable
Returns:
the MJC version of the MJCReadable

isReadableConnected

public boolean isReadableConnected()
Returns wether the MJCReadable is still connected to its source.
Specified by:
isReadableConnected in interface MJCReadable
Returns:
wether the MJCReadable is still connected to its source

getAvailable

public int getAvailable()
Returns the number of bytes that are available for read out from this MJCReadable.
Specified by:
getAvailable in interface MJCReadable
Returns:
the number of bytes available for read out

getInput

public java.lang.String getInput()
Returns the contents of the read buffer from this MJCReadable.
Specified by:
getInput in interface MJCReadable
Returns:
the contents of the read buffer

setReader

public void setReader(MJCReader reader)
Sets the MJCReader to which the readEvents have to be sent.
Specified by:
setReader in interface MJCReadable
Parameters:
reader - the MJCReader to which the readEvents have to be sent

getReader

public MJCReader getReader()
Returns the MJCReader to which readEvents will be sent.
Specified by:
getReader in interface MJCReadable
Returns:
the MJCReader to which readEvents will be sent

setReadable

public void setReadable(MJCReadable readable)
Sets the MJCReadable from which data has to be read.
Specified by:
setReadable in interface MJCReader
Parameters:
readable - the MJCReadable from which data has to be read

getReadable

public MJCReadable getReadable()
Returns the MJCReadable from which data will be read.
Specified by:
getReadable in interface MJCReader
Returns:
the MJCReadable from which data will be read

run

public void run()
Run thread. The function of it is reading the data from the lower layer, and transferring it to the readbuffer.
Specified by:
run in interface java.lang.Runnable

getReaderName

public java.lang.String getReaderName()
Returns the MJC name of the MJCReader.
Specified by:
getReaderName in interface MJCReader
Returns:
the MJC name of the MJCReader

getReaderVersion

public java.lang.String getReaderVersion()
Returns the MJC version of the MJCReader.
Specified by:
getReaderVersion in interface MJCReader
Returns:
the MJC version of the MJCReader

readEvent

public void readEvent(MJCReadable readable)
Indicates that there is data available from the specified MJCReadable.
Specified by:
readEvent in interface MJCReader
Parameters:
readable - there is data available from the readable

connectionClosedEvent

public void connectionClosedEvent(MJCReadable readable)
Indicates that the source connection of the specified MJCReadable has been closed.
Specified by:
connectionClosedEvent in interface MJCReader
Parameters:
readable - the MJCReadable whose source connection has been closed

errorEvent

public void errorEvent(java.lang.String errorDescription,
                       MJCReadable readable)
Indicates that there was an error in the source connection of the specified MJCReadable.
Specified by:
errorEvent in interface MJCReader
Parameters:
errorDescription - the error message
readable - the MJCReadable where the error occured

getWriteableName

public java.lang.String getWriteableName()
Returns the MJC name of the MJCWriteable.
Specified by:
getWriteableName in interface MJCWriteable
Returns:
the MJC name of the MJCWriteable

getWriteableVersion

public java.lang.String getWriteableVersion()
Returns the MJC version of the MJCWriteable.
Specified by:
getWriteableVersion in interface MJCWriteable
Returns:
the MJC version of the MJCWriteable

write

public boolean write(char c)
Writes one single char. Writing is synchronous and can be buffered.
Specified by:
write in interface MJCWriteable
Parameters:
c - the char to be written
Returns:
wether the writing has been successful

write

public boolean write(char[] c)
Writes a char array. Writing is synchronous and can be buffered.
Specified by:
write in interface MJCWriteable
Parameters:
c - the char array to be written
Returns:
wether the writing has been successful

write

public boolean write(java.lang.String s)
Writes a String. Writing is synchronous and can be buffered.
Specified by:
write in interface MJCWriteable
Parameters:
s - the String to be written
Returns:
wether the writing has been successful

flush

public void flush()
Flushes the contents of the write buffer to bottom layers.
Specified by:
flush in interface MJCWriteable

getLastWriteableError

public java.lang.String getLastWriteableError()
Returns the error message of the last occured error. After returning it, the error message will be deleted and cannot be queried again.
Specified by:
getLastWriteableError in interface MJCWriteable
Returns:
the last error message

isWriteableConnected

public boolean isWriteableConnected()
Returns wether the MJCWriteable is connected to its target.
Specified by:
isWriteableConnected in interface MJCWriteable
Returns:
wether the MJCWriteable is connected to its target