|
Mixe for Privacy and Anonymity in the Internet
|
This class "dispatches" messages which it receives via proccessMixPacket() to the associated control channel. More...
#include <CAControlChannelDispatcher.hpp>
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 | |
| CAQueue * | m_pSendQueue |
| MIXPACKET * | m_pMixPacket |
| CAAbstractControlChannel ** | m_arControlChannels |
| tQueueEntry * | m_pQueueEntry |
| CAMutex * | m_pcsSendMsg |
| CAMutex * | m_pcsRegisterChannel |
| CAMutex * | m_pcsEnc |
| CAMutex * | m_pcsDec |
| gcm_ctx_64k * | m_pGCMCtxEnc |
| gcm_ctx_64k * | m_pGCMCtxDec |
| UINT32 | m_nEncMsgCounter |
| UINT32 * | m_pEncMsgIV |
| UINT32 | m_nDecMsgCounter |
| UINT8 * | m_pDecMsgIV |
This class "dispatches" messages which it receives via proccessMixPacket() to the associated control channel.
Definition at line 37 of file CAControlChannelDispatcher.hpp.
| CAControlChannelDispatcher::CAControlChannelDispatcher | ( | CAQueue * | pSendQueue, |
| UINT8 * | keyRecv, | ||
| UINT8 * | keySent | ||
| ) | [inline] |
Constructs a new dispatcher.
| pSendQueue | send 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;
}
}
Definition at line 75 of file CAControlChannelDispatcher.hpp.
References m_arControlChannels, m_pcsDec, m_pcsEnc, m_pcsRegisterChannel, m_pcsSendMsg, m_pDecMsgIV, m_pEncMsgIV, m_pGCMCtxDec, m_pGCMCtxEnc, and m_pQueueEntry.
{
delete m_pcsSendMsg;
m_pcsSendMsg = NULL;
delete m_pcsRegisterChannel;
m_pcsRegisterChannel = NULL;
delete[] m_arControlChannels;
m_arControlChannels = NULL;
delete m_pQueueEntry;
m_pQueueEntry = NULL;
if(m_pGCMCtxEnc!=NULL)
delete m_pGCMCtxEnc;
if(m_pGCMCtxDec!=NULL)
delete m_pGCMCtxDec;
delete []m_pEncMsgIV;
delete m_pcsEnc;
delete []m_pDecMsgIV;
delete m_pcsDec;
}
| 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;
}
| 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.
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();
}
| 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;
}
| bool CAControlChannelDispatcher::isKeySet | ( | ) | [inline] |
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;
}
| bool CAControlChannelDispatcher::proccessMixPacket | ( | const MIXPACKET * | pPacket | ) |
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;
}
| SINT32 CAControlChannelDispatcher::registerControlChannel | ( | CAAbstractControlChannel * | pControlChannel | ) |
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;
}
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().
{
if(id>255)
return E_UNKNOWN;
m_pcsRegisterChannel->lock();
delete m_arControlChannels[id];
m_arControlChannels[id]=NULL;
m_pcsRegisterChannel->unlock();
return E_SUCCESS;
}
| 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;
}
Definition at line 123 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), deleteAllControlChannels(), proccessMixPacket(), registerControlChannel(), removeControlChannel(), and ~CAControlChannelDispatcher().
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().
CAMutex* CAControlChannelDispatcher::m_pcsDec [private] |
Definition at line 128 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), decryptMessage(), and ~CAControlChannelDispatcher().
CAMutex* CAControlChannelDispatcher::m_pcsEnc [private] |
Definition at line 127 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), encryptMessage(), and ~CAControlChannelDispatcher().
Definition at line 126 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), deleteAllControlChannels(), proccessMixPacket(), registerControlChannel(), removeControlChannel(), and ~CAControlChannelDispatcher().
CAMutex* CAControlChannelDispatcher::m_pcsSendMsg [private] |
Definition at line 125 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), sendMessages(), and ~CAControlChannelDispatcher().
UINT8* CAControlChannelDispatcher::m_pDecMsgIV [private] |
Definition at line 135 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), decryptMessage(), and ~CAControlChannelDispatcher().
UINT32* CAControlChannelDispatcher::m_pEncMsgIV [private] |
Definition at line 133 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), encryptMessage(), and ~CAControlChannelDispatcher().
gcm_ctx_64k* CAControlChannelDispatcher::m_pGCMCtxDec [private] |
Definition at line 131 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), decryptMessage(), and ~CAControlChannelDispatcher().
gcm_ctx_64k* CAControlChannelDispatcher::m_pGCMCtxEnc [private] |
Definition at line 130 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), encryptMessage(), isKeySet(), and ~CAControlChannelDispatcher().
Definition at line 122 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), and sendMessages().
Definition at line 124 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), sendMessages(), and ~CAControlChannelDispatcher().
CAQueue* CAControlChannelDispatcher::m_pSendQueue [private] |
Definition at line 121 of file CAControlChannelDispatcher.hpp.
Referenced by CAControlChannelDispatcher(), and sendMessages().
1.7.6.1