|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
inputOutputHandler.PreviousMixConnectionHandler
final class PreviousMixConnectionHandler
Handles communication with a previous mix (in the same cascade as this one).
Waits for the previous mix to establish a permanent (TCP) connection, which
is used to transmit the messages (Request
s and
Reply
ies) of all users connected to the cascade's fist mix
(multiplex channel).
(De-)multiplexes Request
s/Reply
ies using an
(encrypted) header (see addInterMixHeader()).
Note: Authentication is NOT implemented!
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
private java.net.InetAddress |
BIND_ADDRESS
Address this PreviousMixConnectionHandler 's socket shall be
bound to. |
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 the previous mix), but the connection is lost (Used for
synchronization, when connection is established again). |
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 |
interMixDecryptCipherWithPreviousMix
Cipher for decrypting multiplex-headers of requests. |
private javax.crypto.Cipher |
interMixEncryptCipherWithPreviousMix
Cipher for encrypting multiplex-headers of replies. |
private javax.crypto.spec.IvParameterSpec |
interMixIVWithPreviousMix
Initialization vector used to encrypt data between this mix and its predecessor. |
private javax.crypto.SecretKey |
interMixKeyWithPreviousMix
Key used to encrypt data between this mix and its predecessor. |
private static InternalInformationPortController |
internalInformationPort
Reference on component InternalInformationPort . |
private boolean |
IS_LAST
Indicates whether this mix is the lost of the cascade or not. |
private static java.util.logging.Logger |
LOGGER
Logger used to log and display information. |
private int |
NUMBER_OF_FURTHER_HOPS
Number of further mixes between the mix this PreviousMixConnectionHandler belongs to and the receiver. |
private OutputStrategyController |
outputStrategy
Reference on component OutputStrategy (Used to add
ChannelReleaseMessages ). |
private int |
PORT
Port number this PreviousMixConnectionHandler runs on. |
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 java.net.InetAddress |
PREVIOUS_MIX_ADDRESS
Address of the previous mix in the cascade. |
private int |
PREVIOUS_MIX_PORT
Port number of the previous mix in the cascade. |
private java.io.InputStream |
previousMixInputStream
InputStream for communicating with previous mix. |
private java.io.OutputStream |
previousMixOutputStream
OutputStream for communicating with previous mix. |
private java.net.Socket |
previousMixSocket
Socket for communicating with previous mix. |
private java.net.ServerSocket |
serverSocket
ServerSocket used to accept the previous mix' connection attempt. |
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 |
PreviousMixConnectionHandler(InputOutputHandlerController inputOutputHandler,
UserDatabaseController userDatabase,
OutputStrategyController outputStrategy,
ExternalInformationPortController externalInformationPort)
Constructs a new PreviousMixConnectionHandler which handles
communication with a previous mix (in the same cascade as this one). |
Method Summary | |
---|---|
protected void |
acceptConnection()
Makes this PreviousMixConnectionHandler wait for
its predecessor to connect. |
private byte[] |
addInterMixHeader(Reply reply)
Adds an (encrypted) header to a Reply containing
an identifier for the suiting channel (the identifier is unique for any
neighboured mixes). |
private User |
createNewUser(int userIdentifier)
Creates a new User with the bypassed identifier. |
private byte[] |
decryptBlockWithHeader(byte[] blockWithHeader)
Decrypts multiplex-header. |
private javax.crypto.spec.IvParameterSpec |
getInterMixIV(KeyGeneratorController keyGenerator)
Generates an initialization vector, that can be used to encrypt multiplex-headers between this mix an its predecessor. |
private javax.crypto.SecretKey |
getInterMixKey(KeyGeneratorController keyGenerator)
Generates a cryptographic key, that can be used to encrypt multiplex-headers between this mix an its predecessor. |
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 Reply ies ready to be sent (to the previous mix). |
private boolean |
isAllowedToSendChannelMessage(User user)
Indicates whether the bypassed user is allowed to send a message or not. |
private ChannelEstablishMessage |
readChannelEstablishMessage(byte[] blockWithHeader,
User user)
Reads a ChannelEstablishMessage from the previous mix,
generates a ChannelEstablishMessage object and returns it. |
private ChannelMessage |
readChannelMessage(byte[] blockWithHeader,
User user)
Reads a ChannelMessage from the previous mix, generates a
ChannelMessage object and returns it. |
private void |
resetInterMixCiphers()
Resets the Cipher s used to encrypt data between this mix
and its predecessor. |
void |
run()
Receives messages from previous mix and passes them to the InputOutputHandler . |
private void |
setUpInterMixCiphers()
Generates a cryptographic key, that is used to encrypt multiplex-headers between this mix an its predecessor and sets up suiting Cipher s. |
private void |
skipChannelEstablishMessage()
Skips a ChannelEstablishMessage on the communication
channel. |
private void |
skipChannelMessage()
Skips a ChannelMessage on the communication channel. |
private void |
waitForConnection()
Waits for the previous mix to establish a connection. |
private void |
waitForIncomingConnection()
Waits for the previous mix to connect. |
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 |
---|
private static InternalInformationPortController internalInformationPort
InternalInformationPort
.
Used to display and/or log data and read general settings.
private static final java.util.logging.Logger LOGGER
private final int PORT
PreviousMixConnectionHandler
runs on.
private final java.net.InetAddress BIND_ADDRESS
PreviousMixConnectionHandler
's socket shall be
bound to.
private final int POSITION_OF_MIX_IN_CASCADE
private final int INTER_MIX_BLOCK_SIZE
private final java.net.InetAddress PREVIOUS_MIX_ADDRESS
private final int PREVIOUS_MIX_PORT
private final int NUMBER_OF_FURTHER_HOPS
PreviousMixConnectionHandler
belongs to and the receiver.
private final boolean IS_LAST
private java.net.Socket previousMixSocket
private java.io.InputStream previousMixInputStream
private java.io.OutputStream previousMixOutputStream
private javax.crypto.Cipher interMixEncryptCipherWithPreviousMix
private javax.crypto.Cipher interMixDecryptCipherWithPreviousMix
private javax.crypto.SecretKey interMixKeyWithPreviousMix
private javax.crypto.spec.IvParameterSpec interMixIVWithPreviousMix
private java.util.concurrent.atomic.AtomicBoolean handleRepliesIsWaitingForConnection
handleReplies()
wants to send
replies (to the previous mix), but the connection is lost (Used for
synchronization, when connection is established again).
handleReplies()
,
waitForIncomingConnection()
private java.net.ServerSocket serverSocket
private InputOutputHandlerController inputOutputHandler
InputOutputHandlerController()
(Used to get
processed replies and add unprocessed requests).
InputOutputHandlerController.addUnprocessedRequest(message.Request)
,
InputOutputHandlerController.getProcessedReply()
private UserDatabaseController userDatabase
UserDatabase
(Used to add/remove
users).
private OutputStrategyController outputStrategy
OutputStrategy
(Used to add
ChannelReleaseMessages
).
private ExternalInformationPortController externalInformationPort
ExternalInformationPort
(Used to
provide the cryptographic key used to encrypt/decrypt multiplex-headers
to the previous mix.
Constructor Detail |
---|
protected PreviousMixConnectionHandler(InputOutputHandlerController inputOutputHandler, UserDatabaseController userDatabase, OutputStrategyController outputStrategy, ExternalInformationPortController externalInformationPort)
PreviousMixConnectionHandler
which handles
communication with a previous mix (in the same cascade as this one).
Waits for the previous mix to establish a permanent (TCP) connection,
which is used to transmit the messages (Request
s and
Reply
ies) of all users connected to the cascade's fist mix
(multiplex channel). (De-)multiplexes
Request
s/Reply
ies using an (encrypted) header
(see addInterMixHeader()).
Requests
are put in the
InputOutputHandlerController
's
requestInputQueue
(see InputOutputHandlerController.addUnprocessedRequest()
).
Reply
ies are taken from the
InputOutputHandlerController
's replyOutputQueue
(see InputOutputHandlerController.getProcessedReply()
).
Adds/removes user to/from UserDatabase
.
Note: Authentication is NOT implemented!
inputOutputHandler
- Reference on
InputOutputHandlerController
(Used to add messages).userDatabase
- Reference on component
UserDatabase
(Used to
add/remove User
)s.outputStrategy
- Reference on component
OutputStrategy
(Used to add
ChannelReleaseMessages
).externalInformationPort
- Reference on component
ExternalInformationPort
(Used to provide the cryptographic key
used to encrypt/decrypt
multiplex-headers to the previous mix.Method Detail |
---|
protected void acceptConnection()
PreviousMixConnectionHandler
wait for
its predecessor to connect.
private void handleReplies()
Reply
ies ready to be sent (to the previous mix).
private void waitForConnection()
private byte[] addInterMixHeader(Reply reply)
Reply
containing
an identifier for the suiting channel (the identifier is unique for any
neighboured mixes).
reply
- Reply
without header.
Reply
with header.public void run()
InputOutputHandler
.
run
in interface java.lang.Runnable
run
in class java.lang.Thread
InputOutputHandlerController.addUnprocessedRequest(message.Request)
private void waitForIncomingConnection()
private byte[] decryptBlockWithHeader(byte[] blockWithHeader)
blockWithHeader
- Block of the Request
containing
the multiplex-header.
private User createNewUser(int userIdentifier) throws java.io.IOException, UserAlreadyExistingException
User
with the bypassed identifier.
userIdentifier
- Used to identify to which user/channel a
message belongs.
User
.
java.io.IOException
- If an I/O error occurres.
UserAlreadyExistingException
- If a User
with the
specified identifier is already
existing (-> attack or collision).private void skipChannelEstablishMessage() throws java.io.IOException
ChannelEstablishMessage
on the communication
channel.
java.io.IOException
- If an I/O error occurres.private void skipChannelMessage() throws java.io.IOException
ChannelMessage
on the communication channel.
java.io.IOException
- If an I/O error occurres.private ChannelEstablishMessage readChannelEstablishMessage(byte[] blockWithHeader, User user) throws java.io.IOException
ChannelEstablishMessage
from the previous mix,
generates a ChannelEstablishMessage
object and returns it.
blockWithHeader
- First part of the message (already received
since overlapped by the block including the
multiplex-header).user
- User
the returned message belongs
to.
ChannelEstablishMessage
;
java.io.IOException
- If an I/O error occurres.private ChannelMessage readChannelMessage(byte[] blockWithHeader, User user) throws java.io.IOException
ChannelMessage
from the previous mix, generates a
ChannelMessage
object and returns it.
blockWithHeader
- First part of the message (already received
since overlapped by the block including the
multiplex-header).user
- User
the returned message belongs
to.
ChannelMessage
;
java.io.IOException
- If an I/O error occurres.private boolean isAllowedToSendChannelMessage(User user)
user
- Reference on User
who's authorization shall be
checked.
private void setUpInterMixCiphers()
Cipher
s.
private void resetInterMixCiphers()
Cipher
s used to encrypt data between this mix
and its predecessor. Must be called when connection was lost, since
Cipher
s might be out of sync in that case.
private javax.crypto.spec.IvParameterSpec getInterMixIV(KeyGeneratorController keyGenerator)
keyGenerator
- Reference on component
KeyGenerator
(Used to
generate the initialization vector).
private javax.crypto.SecretKey getInterMixKey(KeyGeneratorController keyGenerator)
keyGenerator
- Reference on component
KeyGenerator
(Used to
generate the cryptographic key).
private static java.lang.String getProperty(java.lang.String key)
internalInformationPort.getProperty(key)
). Returns the
property with the specified key from the property file.
key
- The property key.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |