Mixe for Privacy and Anonymity in the Internet
CASyncControlChannel.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 
29 #ifndef _CASYNCCONTROLCHANNEL_
30 #define _CASYNCCONTROLCHANNEL_
31 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
33 
37 {
38  public:
43  CASyncControlChannel(UINT8 id, bool bIsEncrypted):
44  CAAbstractControlChannel(id,bIsEncrypted)
45  {
46  m_MsgBuff=new UINT8[0xFFFF+32];
47  m_aktIndex=0;
49  }
50  virtual ~CASyncControlChannel();
56  virtual SINT32 processXMLMessage(const XERCES_CPP_NAMESPACE::DOMDocument* docMsg)=0;
57 
58  protected:
59  SINT32 proccessMessage(const UINT8* msg, UINT32 msglen)
60  {
61  #ifdef DEBUG
62  CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessage - msglen=%u\n",msglen);
63  #endif
64  if(m_MsgBytesLeft==0)//start of new XML Msg
65  {
66  if(msglen<2)//this should never happen...
67  return E_UNKNOWN;
68  m_MsgBytesLeft=(msg[0]<<8)|msg[1];
69  if(m_bIsEncrypted && m_pDispatcher->isKeySet()) // note: the second check is just a workaround for the time the encryption is not support by all JAPs/Mixes
70  {
71  m_MsgBytesLeft+=16;//auth tag
72  }
73  #ifdef DEBUG
74  CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessage - start of a new msg of len=%u\n",m_MsgBytesLeft);
75  #endif
76  msglen-=2;
77  m_aktIndex=msglen;
78  m_MsgBytesLeft-=msglen;
79  memcpy(m_MsgBuff,msg+2,msglen);
80  }
81  else//received some part...
82  {
83  msglen=min(m_MsgBytesLeft,msglen);
84  memcpy(m_MsgBuff+m_aktIndex,msg,msglen);
85  m_aktIndex+=msglen;
86  m_MsgBytesLeft-=msglen;
87  }
88  if(m_MsgBytesLeft==0)
89  {//whole msg receveid
90  if(m_bIsEncrypted)
91  {
92  UINT8* buff=new UINT8[m_aktIndex];
93  memcpy(buff,m_MsgBuff,m_aktIndex);
95  delete[]buff;
96  }
97  return proccessMessageComplete();
98  }
99  return E_SUCCESS;
100  }
101 
104  {
105  #ifdef DEBUG
106  if(m_aktIndex<0xFFFF)
107  {
109  CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessageComplete() - msg=%s\n",m_MsgBuff);
110  }
111  else
112  CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessageComplete() \n");
113  #endif
114 
115  XERCES_CPP_NAMESPACE::DOMDocument* doc=parseDOMDocument(m_MsgBuff,m_aktIndex);
116  m_aktIndex=0;
117  m_MsgBytesLeft=0;
118  if(doc==NULL)
119  {
120  CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel:: received XML document could not be parsed\n");
121  return E_UNKNOWN;
122  }
123  #ifdef DEBUG
124  CAMsg::printMsg(LOG_DEBUG,"CASyncControlChannel::proccessMessageComplete() call processXMLMessage()\n");
125  #endif
126  SINT32 ret=processXMLMessage(doc);
127  if (doc != NULL)
128  {
129  doc->release();
130  doc = NULL;
131  }
132  return ret;
133  }
134 
141 };
142 #endif
143 #endif //ONLY_LOCAL_PROXY
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument(const UINT8 *const buff, UINT32 len)
Parses a buffer containing an XML document and returns this document.
Definition: CAUtil.cpp:663
#define min(a, b)
Definition: StdAfx.h:649
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
The base of each control channel.
CAControlChannelDispatcher * m_pDispatcher
bool isKeySet()
Temp workaorund function - to be removed soon...
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.
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
A synchronous control channel.
UINT8 * m_MsgBuff
buffer for assembling the parts of the message
CASyncControlChannel(UINT8 id, bool bIsEncrypted)
Constructor for a synchronized (e.g.
UINT32 m_MsgBytesLeft
how much bytes we need until all bytes are received?
SINT32 proccessMessageComplete()
Parses the bytes in m_MsgBuff and calls processXMLMessage()
UINT32 m_aktIndex
how much bytes have we received already?
SINT32 proccessMessage(const UINT8 *msg, UINT32 msglen)
Processes some bytes of a message we got from the communication channel.
virtual SINT32 processXMLMessage(const XERCES_CPP_NAMESPACE::DOMDocument *docMsg)=0
Override this method to receive a XML Message.
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3