Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Private Attributes
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:
[legend]

List of all members.

Public Member Functions

 CAControlChannelDispatcher (CAQueue *pSendQueue, UINT8 *keyRecv, UINT8 *keySent)
 Constructs a new dispatcher.
 ~CAControlChannelDispatcher ()
void deleteAllControlChannels (void)
 Deregisters all control channels and calls delete on every registered control channel object.
SINT32 registerControlChannel (CAAbstractControlChannel *pControlChannel)
 Registers a control channel for receiving messages.
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.
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.
bool isKeySet ()
 Temp workaorund function - to be removed soon...

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 37 of file CAControlChannelDispatcher.hpp.


Constructor & Destructor Documentation

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 44 of file CAControlChannelDispatcher.hpp.

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.

      {
        m_pSendQueue=pSendQueue;
        m_pQueueEntry=new tQueueEntry;
        m_pMixPacket=&m_pQueueEntry->packet;
        m_arControlChannels=new CAAbstractControlChannel*[256];
        memset(m_arControlChannels,0,256*sizeof(CAAbstractControlChannel*));
        m_pcsSendMsg=new CAMutex();
        m_pcsRegisterChannel=new CAMutex();
        m_pcsEnc=new CAMutex();
        m_pcsDec=new CAMutex();
        m_nEncMsgCounter=0;
        m_pEncMsgIV=new UINT32[3];
        memset(m_pEncMsgIV,0,12);
        m_nDecMsgCounter=0;
        m_pDecMsgIV=new UINT8[12];
        memset(m_pDecMsgIV,0,12);
        if(keySent!=NULL)
        {
          m_pGCMCtxEnc=new gcm_ctx_64k;
          m_pGCMCtxDec=new gcm_ctx_64k;
          gcm_init_64k(m_pGCMCtxEnc,keySent,128);
          gcm_init_64k(m_pGCMCtxDec,keyRecv,128);
        }
        else
        {
          m_pGCMCtxEnc=NULL;
          m_pGCMCtxDec=NULL;
        }
      }

Member Function Documentation

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.

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

Referenced by CASyncControlChannel::proccessMessage().

  {
    if(m_pGCMCtxDec!=NULL)
      {
        m_pcsDec->lock();
        UINT32 iv=htonl(m_nDecMsgCounter);
        m_nDecMsgCounter++;
        memcpy(m_pDecMsgIV+8,&iv,4);
        ::gcm_decrypt_64k(m_pGCMCtxDec,(UINT32*) m_pDecMsgIV , in,inlen-16,in+inlen-16,out);
        *outlen=inlen-16;
        m_pcsDec->unlock();
      }
    else
    {
      memcpy(out,in,inlen);
      *outlen=inlen;
    }
      return E_SUCCESS;
  }

Here is the call graph for this function:

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

Definition at line 57 of file CAControlChannelDispatcher.cpp.

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

Referenced by CAFirstMixChannelList::remove().

  {
    m_pcsRegisterChannel->lock();
    for(UINT32 i=0;i<256;i++)
    {
      delete m_arControlChannels[i];
      m_arControlChannels[i]=NULL;
    }
    m_pcsRegisterChannel->unlock();
  }

Here is the call graph for this function:

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.

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

Referenced by CAAbstractControlChannel::sendXMLMessage().

  {
    if(m_pGCMCtxEnc!=NULL)
    {
      m_pcsEnc->lock();
      m_pEncMsgIV[2]=htonl(m_nEncMsgCounter);
      m_nEncMsgCounter++;
      ::gcm_encrypt_64k(m_pGCMCtxEnc, m_pEncMsgIV , in,inlen,out,(UINT32*)(out+inlen));
      *outlen=inlen+16;
      m_pcsEnc->unlock();
    }
    else
    {
      memcpy(out,in,inlen);
      *outlen=inlen;
    }
      return E_SUCCESS;
  }

Here is the call graph for this function:

Temp workaorund function - to be removed soon...

Definition at line 115 of file CAControlChannelDispatcher.hpp.

References m_pGCMCtxEnc.

Referenced by CASyncControlChannel::proccessMessage().

      {
        return m_pGCMCtxEnc!=NULL;
      }

Definition at line 68 of file CAControlChannelDispatcher.cpp.

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(), fm_loopReadFromMix(), CALastMixA::loop(), CAFirstMixB::loop(), CAFirstMixA::loop(), and CALastMixB::loop().

  {
    if(pPacket->channel < 256 && pPacket->channel > 0)
    {
      m_pcsRegisterChannel->lock();
      CAAbstractControlChannel* pControlChannel=m_arControlChannels[pPacket->channel];
      if (pControlChannel != NULL)
      {
        bool ret = (pControlChannel->proccessMessage(pPacket->data,pPacket->flags) == E_SUCCESS);
        m_pcsRegisterChannel->unlock();
        return ret;
      }
      else
      {
        m_pcsRegisterChannel->unlock();
        return true;
      }
    }
    return false;
  }

Here is the call graph for this function:

Registers a control channel for receiving messages.

Definition at line 34 of file CAControlChannelDispatcher.cpp.

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().

  {
    if(pControlChannel==NULL||pControlChannel->getID()>255)
      return E_UNKNOWN;
    m_pcsRegisterChannel->lock();
    pControlChannel->setDispatcher(this);
    m_arControlChannels[pControlChannel->getID()]= pControlChannel;
    m_pcsRegisterChannel->unlock();
    return E_SUCCESS;
  }

Here is the call graph for this function:

Definition at line 45 of file CAControlChannelDispatcher.cpp.

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:

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

Definition at line 128 of file CAControlChannelDispatcher.cpp.

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().

  {
    #ifdef DEBUG
      CAMsg::printMsg(LOG_DEBUG,"dispatch - sendMesg()\n");
    #endif
    if(msg==NULL)
      return E_UNKNOWN;
    m_pcsSendMsg->lock();
    m_pMixPacket->channel=id;
    UINT32 aktIndex=0;

    //prevent data garbage from old messages to be transmitted again
    memset(m_pMixPacket->data, 0, DATA_SIZE);
    while(msglen>0)
    {
      if(msglen>DATA_SIZE)
      {
        m_pMixPacket->flags=DATA_SIZE;
      }
      else
      {
        m_pMixPacket->flags=(UINT16)msglen;
      }
      memcpy(m_pMixPacket->data,msg+aktIndex,m_pMixPacket->flags);
      m_pSendQueue->add(m_pQueueEntry,sizeof(tQueueEntry));
      aktIndex+=m_pMixPacket->flags;
      msglen-=m_pMixPacket->flags;
    }
    m_pcsSendMsg->unlock();
    return E_SUCCESS;
  }

Here is the call graph for this function:


Member Data Documentation

Definition at line 134 of file CAControlChannelDispatcher.hpp.

Referenced by CAControlChannelDispatcher(), and decryptMessage().

Definition at line 132 of file CAControlChannelDispatcher.hpp.

Referenced by CAControlChannelDispatcher(), and encryptMessage().

Definition at line 122 of file CAControlChannelDispatcher.hpp.

Referenced by CAControlChannelDispatcher(), and sendMessages().

Definition at line 121 of file CAControlChannelDispatcher.hpp.

Referenced by CAControlChannelDispatcher(), and sendMessages().


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