Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Private Attributes | List of all members
CAControlChannelDispatcher Class Reference

This class "dispatches" messages which it receives via proccessMixPacket() to the associated control channel. More...

#include <CAControlChannelDispatcher.hpp>

Collaboration diagram for CAControlChannelDispatcher:

Public Member Functions

 CAControlChannelDispatcher (CAQueue *pSendQueue, UINT8 *keyRecv, UINT8 *keySent)
 Constructs a new dispatcher. More...
 
 ~CAControlChannelDispatcher ()
 
void deleteAllControlChannels (void)
 Deregisters all control channels and calls delete on every registered control channel object. More...
 
SINT32 registerControlChannel (CAAbstractControlChannel *pControlChannel)
 Registers a control channel for receiving messages. More...
 
SINT32 removeControlChannel (UINT32 id)
 
bool proccessMixPacket (const MIXPACKET *pPacket)
 
SINT32 sendMessages (UINT32 id, const UINT8 *msg, UINT32 msglen)
 
SINT32 encryptMessage (const UINT8 *in, UINT32 inlen, UINT8 *out, UINT32 *outlen)
 Encrypts a control channel message. More...
 
SINT32 decryptMessage (const UINT8 *in, UINT32 inlen, UINT8 *out, UINT32 *outlen)
 Decrypts a control channel message, which has to be of form: cipher text auth tag - 16 bytes. More...
 
bool isKeySet ()
 Temp workaorund function - to be removed soon... More...
 

Private Attributes

CAQueuem_pSendQueue
 
MIXPACKETm_pMixPacket
 
CAAbstractControlChannel ** m_arControlChannels
 
tQueueEntrym_pQueueEntry
 
CAMutexm_pcsSendMsg
 
CAMutexm_pcsRegisterChannel
 
CAMutexm_pcsEnc
 
CAMutexm_pcsDec
 
gcm_ctx_64k * m_pGCMCtxEnc
 
gcm_ctx_64k * m_pGCMCtxDec
 
UINT32 m_nEncMsgCounter
 
UINT32m_pEncMsgIV
 
UINT32 m_nDecMsgCounter
 
UINT8m_pDecMsgIV
 

Detailed Description

This class "dispatches" messages which it receives via proccessMixPacket() to the associated control channel.

Definition at line 38 of file CAControlChannelDispatcher.hpp.

Constructor & Destructor Documentation

◆ CAControlChannelDispatcher()

CAControlChannelDispatcher::CAControlChannelDispatcher ( CAQueue pSendQueue,
UINT8 keyRecv,
UINT8 keySent 
)
inline

Constructs a new dispatcher.

Parameters
pSendQueuesend queue in which the mix packets will be puted, if a control channel sends a message

Definition at line 45 of file CAControlChannelDispatcher.hpp.

46  {
47  m_pSendQueue=pSendQueue;
51  memset(m_arControlChannels,0,256*sizeof(CAAbstractControlChannel*));
52  m_pcsSendMsg=new CAMutex();
54  m_pcsEnc=new CAMutex();
55  m_pcsDec=new CAMutex();
57  m_pEncMsgIV=new UINT32[3];
58  memset(m_pEncMsgIV,0,12);
60  m_pDecMsgIV=new UINT8[12];
61  memset(m_pDecMsgIV,0,12);
62  if(keySent!=NULL)
63  {
64  m_pGCMCtxEnc=new gcm_ctx_64k;
65  m_pGCMCtxDec=new gcm_ctx_64k;
66  gcm_init_64k(m_pGCMCtxEnc,keySent,128);
67  gcm_init_64k(m_pGCMCtxDec,keyRecv,128);
68  }
69  else
70  {
71  m_pGCMCtxEnc=NULL;
72  m_pGCMCtxDec=NULL;
73  }
74  }
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
The base of each control channel.
CAAbstractControlChannel ** m_arControlChannels
MIXPACKET packet
Definition: typedefs.hpp:170
struct t_queue_entry tQueueEntry
Definition: typedefs.hpp:188

References m_arControlChannels, m_nDecMsgCounter, m_nEncMsgCounter, m_pcsDec, m_pcsEnc, m_pcsRegisterChannel, m_pcsSendMsg, m_pDecMsgIV, m_pEncMsgIV, m_pGCMCtxDec, m_pGCMCtxEnc, m_pMixPacket, m_pQueueEntry, m_pSendQueue, and t_queue_entry::packet.

◆ ~CAControlChannelDispatcher()

CAControlChannelDispatcher::~CAControlChannelDispatcher ( )
inline

Definition at line 76 of file CAControlChannelDispatcher.hpp.

77  {
78  delete m_pcsSendMsg;
79  m_pcsSendMsg = NULL;
80  delete m_pcsRegisterChannel;
81  m_pcsRegisterChannel = NULL;
82  delete[] m_arControlChannels;
83  m_arControlChannels = NULL;
84  delete m_pQueueEntry;
85  m_pQueueEntry = NULL;
86  if(m_pGCMCtxEnc!=NULL)
87  delete m_pGCMCtxEnc;
88  if(m_pGCMCtxDec!=NULL)
89  delete m_pGCMCtxDec;
90  delete []m_pEncMsgIV;
91  delete m_pcsEnc;
92  delete []m_pDecMsgIV;
93  delete m_pcsDec;
94  }

References m_arControlChannels, m_pcsDec, m_pcsEnc, m_pcsRegisterChannel, m_pcsSendMsg, m_pDecMsgIV, m_pEncMsgIV, m_pGCMCtxDec, m_pGCMCtxEnc, and m_pQueueEntry.

Member Function Documentation

◆ decryptMessage()

SINT32 CAControlChannelDispatcher::decryptMessage ( const UINT8 in,
UINT32  inlen,
UINT8 out,
UINT32 outlen 
)

Decrypts a control channel message, which has to be of form: cipher text auth tag - 16 bytes.

Definition at line 108 of file CAControlChannelDispatcher.cpp.

109  {
110  if(m_pGCMCtxDec!=NULL)
111  {
112  m_pcsDec->lock();
113  UINT32 iv=htonl(m_nDecMsgCounter);
115  memcpy(m_pDecMsgIV+8,&iv,4);
116  ::gcm_decrypt_64k(m_pGCMCtxDec,(UINT32*) m_pDecMsgIV , in,inlen-16,in+inlen-16,out);
117  *outlen=inlen-16;
118  m_pcsDec->unlock();
119  }
120  else
121  {
122  memcpy(out,in,inlen);
123  *outlen=inlen;
124  }
125  return E_SUCCESS;
126  }
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2

References E_SUCCESS, CAMutex::lock(), m_nDecMsgCounter, m_pcsDec, m_pDecMsgIV, m_pGCMCtxDec, and CAMutex::unlock().

Referenced by CASyncControlChannel::proccessMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteAllControlChannels()

void CAControlChannelDispatcher::deleteAllControlChannels ( void  )

Deregisters all control channels and calls delete on every registered control channel object.

Definition at line 57 of file CAControlChannelDispatcher.cpp.

58  {
60  for(UINT32 i=0;i<256;i++)
61  {
62  delete m_arControlChannels[i];
63  m_arControlChannels[i]=NULL;
64  }
66  }

References CAMutex::lock(), m_arControlChannels, m_pcsRegisterChannel, and CAMutex::unlock().

Referenced by CAFirstMixChannelList::remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encryptMessage()

SINT32 CAControlChannelDispatcher::encryptMessage ( const UINT8 in,
UINT32  inlen,
UINT8 out,
UINT32 outlen 
)

Encrypts a control channel message.

The output format is: cipher text auth tag - 16 bytes

Definition at line 89 of file CAControlChannelDispatcher.cpp.

90  {
91  if(m_pGCMCtxEnc!=NULL)
92  {
93  m_pcsEnc->lock();
94  m_pEncMsgIV[2]=htonl(m_nEncMsgCounter);
96  ::gcm_encrypt_64k(m_pGCMCtxEnc, m_pEncMsgIV , in,inlen,out,(UINT32*)(out+inlen));
97  *outlen=inlen+16;
98  m_pcsEnc->unlock();
99  }
100  else
101  {
102  memcpy(out,in,inlen);
103  *outlen=inlen;
104  }
105  return E_SUCCESS;
106  }

References E_SUCCESS, CAMutex::lock(), m_nEncMsgCounter, m_pcsEnc, m_pEncMsgIV, m_pGCMCtxEnc, and CAMutex::unlock().

Referenced by CAAbstractControlChannel::sendXMLMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isKeySet()

bool CAControlChannelDispatcher::isKeySet ( )
inline

Temp workaorund function - to be removed soon...

Definition at line 116 of file CAControlChannelDispatcher.hpp.

117  {
118  return m_pGCMCtxEnc!=NULL;
119  }

References m_pGCMCtxEnc.

Referenced by CASyncControlChannel::proccessMessage().

Here is the caller graph for this function:

◆ proccessMixPacket()

bool CAControlChannelDispatcher::proccessMixPacket ( const MIXPACKET pPacket)

Definition at line 68 of file CAControlChannelDispatcher.cpp.

69  {
70  if(pPacket->channel < 256 && pPacket->channel > 0)
71  {
73  CAAbstractControlChannel* pControlChannel=m_arControlChannels[pPacket->channel];
74  if (pControlChannel != NULL)
75  {
76  bool ret = (pControlChannel->proccessMessage(pPacket->data,pPacket->flags) == E_SUCCESS);
78  return ret;
79  }
80  else
81  {
83  return true;
84  }
85  }
86  return false;
87  }
virtual SINT32 proccessMessage(const UINT8 *msg, UINT32 msglen)=0
Processes some bytes of a message we got from the communication channel.
HCHANNEL channel
Definition: typedefs.hpp:117
UINT8 data[DATA_SIZE]
Definition: typedefs.hpp:121
UINT16 flags
Definition: typedefs.hpp:118

References t_MixPacket::channel, t_MixPacket::data, E_SUCCESS, t_MixPacket::flags, CAMutex::lock(), m_arControlChannels, m_pcsRegisterChannel, CAAbstractControlChannel::proccessMessage(), and CAMutex::unlock().

Referenced by CAFirstMix::doUserLogin_internal(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), and CALastMixB::loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerControlChannel()

SINT32 CAControlChannelDispatcher::registerControlChannel ( CAAbstractControlChannel pControlChannel)

Registers a control channel for receiving messages.

Definition at line 34 of file CAControlChannelDispatcher.cpp.

35  {
36  if(pControlChannel==NULL||pControlChannel->getID()>255)
37  return E_UNKNOWN;
39  pControlChannel->setDispatcher(this);
40  m_arControlChannels[pControlChannel->getID()]= pControlChannel;
42  return E_SUCCESS;
43  }
UINT32 getID() const
Returns the id of this control channel.
SINT32 setDispatcher(CAControlChannelDispatcher *pDispatcher)
Sets the Dispatcher.
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References E_SUCCESS, E_UNKNOWN, CAAbstractControlChannel::getID(), CAMutex::lock(), m_arControlChannels, m_pcsRegisterChannel, CAAbstractControlChannel::setDispatcher(), and CAMutex::unlock().

Referenced by CAReplayCtrlChannelMsgProc::CAReplayCtrlChannelMsgProc(), and CAFirstMix::doUserLogin_internal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeControlChannel()

SINT32 CAControlChannelDispatcher::removeControlChannel ( UINT32  id)

Definition at line 45 of file CAControlChannelDispatcher.cpp.

46  {
47  if(id>255)
48  return E_UNKNOWN;
50  delete m_arControlChannels[id];
51  m_arControlChannels[id]=NULL;
53  return E_SUCCESS;
54  }

References E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_arControlChannels, m_pcsRegisterChannel, and CAMutex::unlock().

Referenced by CAReplayCtrlChannelMsgProc::~CAReplayCtrlChannelMsgProc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessages()

SINT32 CAControlChannelDispatcher::sendMessages ( UINT32  id,
const UINT8 msg,
UINT32  msglen 
)

Definition at line 128 of file CAControlChannelDispatcher.cpp.

129  {
130  #ifdef DEBUG
131  CAMsg::printMsg(LOG_DEBUG,"dispatch - sendMesg()\n");
132  #endif
133  if(msg==NULL)
134  return E_UNKNOWN;
135  m_pcsSendMsg->lock();
136  m_pMixPacket->channel=id;
137  UINT32 aktIndex=0;
138 
139  //prevent data garbage from old messages to be transmitted again
140  memset(m_pMixPacket->data, 0, DATA_SIZE);
141  while(msglen>0)
142  {
143  if(msglen>DATA_SIZE)
144  {
146  }
147  else
148  {
149  m_pMixPacket->flags=(UINT16)msglen;
150  }
151  memcpy(m_pMixPacket->data,msg+aktIndex,m_pMixPacket->flags);
153  aktIndex+=m_pMixPacket->flags;
154  msglen-=m_pMixPacket->flags;
155  }
156  m_pcsSendMsg->unlock();
157  return E_SUCCESS;
158  }
unsigned short UINT16
Definition: basetypedefs.h:133
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
SINT32 add(const void *buff, UINT32 size)
Adds data to the Queue.
Definition: CAQueue.cpp:76
Definition: typedefs.hpp:169
#define DATA_SIZE
Definition: typedefs.hpp:69

References CAQueue::add(), t_MixPacket::channel, t_MixPacket::data, DATA_SIZE, E_SUCCESS, E_UNKNOWN, t_MixPacket::flags, CAMutex::lock(), m_pcsSendMsg, m_pMixPacket, m_pQueueEntry, m_pSendQueue, CAMsg::printMsg(), and CAMutex::unlock().

Referenced by CAAbstractControlChannel::sendXMLMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_arControlChannels

CAAbstractControlChannel** CAControlChannelDispatcher::m_arControlChannels
private

◆ m_nDecMsgCounter

UINT32 CAControlChannelDispatcher::m_nDecMsgCounter
private

Definition at line 135 of file CAControlChannelDispatcher.hpp.

Referenced by CAControlChannelDispatcher(), and decryptMessage().

◆ m_nEncMsgCounter

UINT32 CAControlChannelDispatcher::m_nEncMsgCounter
private

Definition at line 133 of file CAControlChannelDispatcher.hpp.

Referenced by CAControlChannelDispatcher(), and encryptMessage().

◆ m_pcsDec

CAMutex* CAControlChannelDispatcher::m_pcsDec
private

◆ m_pcsEnc

CAMutex* CAControlChannelDispatcher::m_pcsEnc
private

◆ m_pcsRegisterChannel

CAMutex* CAControlChannelDispatcher::m_pcsRegisterChannel
private

◆ m_pcsSendMsg

CAMutex* CAControlChannelDispatcher::m_pcsSendMsg
private

◆ m_pDecMsgIV

UINT8* CAControlChannelDispatcher::m_pDecMsgIV
private

◆ m_pEncMsgIV

UINT32* CAControlChannelDispatcher::m_pEncMsgIV
private

◆ m_pGCMCtxDec

gcm_ctx_64k* CAControlChannelDispatcher::m_pGCMCtxDec
private

◆ m_pGCMCtxEnc

gcm_ctx_64k* CAControlChannelDispatcher::m_pGCMCtxEnc
private

◆ m_pMixPacket

MIXPACKET* CAControlChannelDispatcher::m_pMixPacket
private

Definition at line 123 of file CAControlChannelDispatcher.hpp.

Referenced by CAControlChannelDispatcher(), and sendMessages().

◆ m_pQueueEntry

tQueueEntry* CAControlChannelDispatcher::m_pQueueEntry
private

◆ m_pSendQueue

CAQueue* CAControlChannelDispatcher::m_pSendQueue
private

Definition at line 122 of file CAControlChannelDispatcher.hpp.

Referenced by CAControlChannelDispatcher(), and sendMessages().


The documentation for this class was generated from the following files: