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

#include <CAMuxSocket.hpp>

Collaboration diagram for CAMuxSocket:

Public Member Functions

 CAMuxSocket (SYMCHANNELCIPHER_ALGORITHM algCipher)
 
 ~CAMuxSocket ()
 
SINT32 getHashKey ()
 Returns a Hashkey which uniquely identifies this socket. More...
 
SINT32 accept (UINT16 port)
 
SINT32 accept (const CASocketAddr &oAddr)
 Waits for an incoming connection on oAddr. More...
 
SINT32 connect (CASocketAddr &psa)
 
SINT32 connect (CASocketAddr &psa, UINT retry, UINT32 time)
 
SINT32 close ()
 Closes the underlying socket. More...
 
SINT32 send (MIXPACKET *pPacket)
 Sends a MixPacket over the Network. More...
 
SINT32 send (MIXPACKET *pPacket, UINT8 *buff)
 
SINT32 prepareForSend (MIXPACKET *inoutPacket)
 
SINT32 receive (MIXPACKET *pPacket)
 Receives a whole MixPacket. More...
 
SINT32 receive (MIXPACKET *pPacket, UINT32 timeout)
 Trys to receive a Mix-Packet. More...
 
SINT32 receiveFully (UINT8 *buff, UINT32 len)
 Receives some "plain" bytes from the underlying socket - just a convenient function... More...
 
SINT32 receiveFully (UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 
CASocketgetCASocket ()
 
SINT32 setCASocket (CASocket *pSocket)
 This will set the underlying CASocket. More...
 
SOCKET getSocket ()
 
SINT32 setCrypt (bool b)
 
bool getIsEncrypted ()
 
SINT32 setCipher (SYMCHANNELCIPHER_ALGORITHM algCipher)
 
SINT32 setKey (UINT8 *key, UINT32 keyLen)
 Sets the symmetric keys used for de-/encrypting the Mux connection. More...
 
SINT32 setSendKey (UINT8 *key, UINT32 keyLen)
 
SINT32 setReceiveKey (UINT8 *key, UINT32 keyLen)
 

Static Public Member Functions

static SINT32 init ()
 
static SINT32 cleanup ()
 

Private Attributes

CASocketm_pSocket
 
UINT32 m_aktBuffPos
 
UINT8m_Buff
 
CASymCipherMuxSocketm_pCipherIn
 
CASymCipherMuxSocketm_pCipherOut
 
bool m_bIsCrypted
 
CAMutex m_csSend
 
CAMutex m_csReceive
 
t_hashkeylistEntrym_pHashKeyEntry
 

Static Private Attributes

static t_hashkeylistEntryms_phashkeylistAvailableHashKeys =NULL
 
static SINT32 ms_nMaxHashKeyValue =0
 
static CAMutexms_pcsHashKeyList =NULL
 

Detailed Description

Definition at line 45 of file CAMuxSocket.hpp.

Constructor & Destructor Documentation

◆ CAMuxSocket()

CAMuxSocket::CAMuxSocket ( SYMCHANNELCIPHER_ALGORITHM  algCipher)

Definition at line 42 of file CAMuxSocket.cpp.

43  {
44  m_pSocket = new CASocket();
46  m_aktBuffPos=0;
47  m_bIsCrypted=false;
50  {//generate new hash keys
51  for(UINT i=0;i<512;i++)
52  {
57  }
58  }
62  m_pCipherIn = NULL;
63  m_pCipherOut = NULL;
64  setCipher(algCipher);
65  }
struct __t_hash_key_entry__ t_hashkeylistEntry
Definition: CAMuxSocket.hpp:42
unsigned int UINT
Definition: basetypedefs.h:155
unsigned char UINT8
Definition: basetypedefs.h:135
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
UINT32 m_aktBuffPos
CASocket * m_pSocket
static t_hashkeylistEntry * ms_phashkeylistAvailableHashKeys
CASymCipherMuxSocket * m_pCipherOut
CASymCipherMuxSocket * m_pCipherIn
UINT8 * m_Buff
static CAMutex * ms_pcsHashKeyList
SINT32 setCipher(SYMCHANNELCIPHER_ALGORITHM algCipher)
Definition: CAMuxSocket.cpp:90
static SINT32 ms_nMaxHashKeyValue
t_hashkeylistEntry * m_pHashKeyEntry
struct __t_hash_key_entry__ * next
Definition: CAMuxSocket.hpp:38
SINT32 hashkey
Definition: CAMuxSocket.hpp:39
#define MIXPACKET_SIZE
Definition: typedefs.hpp:40

References __t_hash_key_entry__::hashkey, CAMutex::lock(), m_aktBuffPos, m_bIsCrypted, m_Buff, m_pCipherIn, m_pCipherOut, m_pHashKeyEntry, m_pSocket, MIXPACKET_SIZE, ms_nMaxHashKeyValue, ms_pcsHashKeyList, ms_phashkeylistAvailableHashKeys, __t_hash_key_entry__::next, setCipher(), and CAMutex::unlock().

Here is the call graph for this function:

◆ ~CAMuxSocket()

CAMuxSocket::~CAMuxSocket ( )

Definition at line 67 of file CAMuxSocket.cpp.

68  {
69  close();
70  delete []m_Buff;
71  m_Buff = NULL;
76  delete m_pCipherIn;
77  delete m_pCipherOut;
78  delete m_pSocket;
79  }
SINT32 close()
Closes the underlying socket.

References close(), CAMutex::lock(), m_Buff, m_pCipherIn, m_pCipherOut, m_pHashKeyEntry, m_pSocket, ms_pcsHashKeyList, ms_phashkeylistAvailableHashKeys, __t_hash_key_entry__::next, and CAMutex::unlock().

Here is the call graph for this function:

Member Function Documentation

◆ accept() [1/2]

SINT32 CAMuxSocket::accept ( const CASocketAddr oAddr)

Waits for an incoming connection on oAddr.

Return values
E_SUCCESS,ifsuccessful
E_SOCKET_BIND,E_SOCKET_LISTEN
E_UNKOWN

Definition at line 146 of file CAMuxSocket.cpp.

147  {
148  CASocket oSocket;
149  oSocket.create(oAddr.getType());
150  oSocket.setReuseAddr(true);
151  SINT32 ret=oSocket.listen(oAddr);
152  if(ret!=E_SUCCESS)
153  return ret;
154  ret=oSocket.accept(*m_pSocket);
155  if(ret!=E_SUCCESS)
156  return E_UNKNOWN;
157  oSocket.close();
158  //m_Socket.setRecvLowWat(MIXPACKET_SIZE);
159  m_aktBuffPos=0;
160  return E_SUCCESS;
161  }
signed int SINT32
Definition: basetypedefs.h:132
virtual SINT32 getType() const =0
The type (family) of socket for which this address is useful.
virtual SINT32 listen(const CASocketAddr &psa)
Starts listening on address psa.
Definition: CASocket.cpp:142
virtual SINT32 setReuseAddr(bool b)
Definition: CASocket.cpp:839
virtual SINT32 accept(CASocket &s)
Accepts a new connection.
Definition: CASocket.cpp:192
virtual SINT32 create()
Definition: CASocket.cpp:73
virtual SINT32 close()
Definition: CASocket.cpp:351
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References CASocket::accept(), CASocket::close(), CASocket::create(), E_SUCCESS, E_UNKNOWN, CASocketAddr::getType(), CASocket::listen(), m_aktBuffPos, m_pSocket, and CASocket::setReuseAddr().

Here is the call graph for this function:

◆ accept() [2/2]

SINT32 CAMuxSocket::accept ( UINT16  port)

Definition at line 126 of file CAMuxSocket.cpp.

127  {
128  CASocket oSocket;
129  oSocket.create();
130  oSocket.setReuseAddr(true);
131  if(oSocket.listen(port)!=E_SUCCESS)
132  return E_UNKNOWN;
133  if(oSocket.accept(*m_pSocket)!=E_SUCCESS)
134  return E_UNKNOWN;
135  oSocket.close();
136  //m_Socket.setRecvLowWat(MIXPACKET_SIZE);
137  m_aktBuffPos=0;
138  return E_SUCCESS;
139  }

References CASocket::accept(), CASocket::close(), CASocket::create(), E_SUCCESS, E_UNKNOWN, CASocket::listen(), m_aktBuffPos, m_pSocket, and CASocket::setReuseAddr().

Referenced by CALastMix::init(), and CAMiddleMix::init().

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

◆ cleanup()

static SINT32 CAMuxSocket::cleanup ( )
inlinestatic

Definition at line 172 of file CAMuxSocket.hpp.

173  {
175  {
178  delete tmpEntry;
179  }
180  delete ms_pcsHashKeyList;
181  ms_pcsHashKeyList=NULL;
182  return E_SUCCESS;
183  }
Definition: CAMuxSocket.hpp:37

References E_SUCCESS, ms_pcsHashKeyList, ms_phashkeylistAvailableHashKeys, and __t_hash_key_entry__::next.

Referenced by CALibProxytest::cleanup().

Here is the caller graph for this function:

◆ close()

SINT32 CAMuxSocket::close ( )

Closes the underlying socket.

Definition at line 175 of file CAMuxSocket.cpp.

176  {
177  m_aktBuffPos=0;
178  return m_pSocket->close();
179  }

References CASocket::close(), m_aktBuffPos, and m_pSocket.

Referenced by CAFirstMix::clean(), CALastMix::clean(), CALocalProxy::clean(), CAMiddleMix::clean(), CAMiddleMix::loop(), CAFirstMixB::loop(), CALastMixB::loop(), and ~CAMuxSocket().

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

◆ connect() [1/2]

SINT32 CAMuxSocket::connect ( CASocketAddr psa)

Definition at line 163 of file CAMuxSocket.cpp.

164  {
165  return connect(psa,1,0);
166  }
SINT32 connect(CASocketAddr &psa)

Referenced by CAFirstMix::connectToNextMix(), CAMiddleMix::connectToNextMix(), and CALocalProxy::init().

Here is the caller graph for this function:

◆ connect() [2/2]

SINT32 CAMuxSocket::connect ( CASocketAddr psa,
UINT  retry,
UINT32  time 
)

Definition at line 168 of file CAMuxSocket.cpp.

169  {
170  //m_Socket.setRecvLowWat(MIXPACKET_SIZE);
171  m_aktBuffPos=0;
172  return m_pSocket->connect(psa,retry,time);
173  }
virtual SINT32 connect(const CASocketAddr &psa)
Definition: CASocket.hpp:64

References CASocket::connect(), m_aktBuffPos, and m_pSocket.

Here is the call graph for this function:

◆ getCASocket()

CASocket* CAMuxSocket::getCASocket ( )
inline

◆ getHashKey()

SINT32 CAMuxSocket::getHashKey ( )
inline

Returns a Hashkey which uniquely identifies this socket.

Definition at line 52 of file CAMuxSocket.hpp.

53  {
54  return m_pHashKeyEntry->hashkey;
55  }

References __t_hash_key_entry__::hashkey, and m_pHashKeyEntry.

Referenced by CAFirstMixChannelList::add(), CAFirstMixChannelList::addChannel(), CAFirstMix::doUserLogin_internal(), CAFirstMixChannelList::get(), CAFirstMixChannelList::getFirstChannelForSocket(), CAFirstMixChannelList::remove(), and CAFirstMixChannelList::removeChannel().

Here is the caller graph for this function:

◆ getIsEncrypted()

bool CAMuxSocket::getIsEncrypted ( )
inline

Definition at line 96 of file CAMuxSocket.hpp.

97  {
98  return m_bIsCrypted;
99  }

References m_bIsCrypted.

◆ getSocket()

SOCKET CAMuxSocket::getSocket ( )
inline

Definition at line 92 of file CAMuxSocket.hpp.

92 {return m_pSocket->getSocket();}
SOCKET getSocket()
Returns the number of the Socket used.
Definition: CASocket.hpp:87

References CASocket::getSocket(), and m_pSocket.

Referenced by CASocketGroup::add(), CASocketGroup::isSignaled(), CASocketGroupEpoll::isSignaled(), CAFirstMixB::loop(), and CASocketGroup::remove().

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

◆ init()

static SINT32 CAMuxSocket::init ( )
inlinestatic

Definition at line 166 of file CAMuxSocket.hpp.

167  {
169  return E_SUCCESS;
170  }

References E_SUCCESS, and ms_pcsHashKeyList.

Referenced by CALibProxytest::init().

Here is the caller graph for this function:

◆ prepareForSend()

SINT32 CAMuxSocket::prepareForSend ( MIXPACKET inoutPacket)

Definition at line 232 of file CAMuxSocket.cpp.

233  {
234  m_csSend.lock();
235  pinoutPacket->channel=htonl(pinoutPacket->channel);
236  pinoutPacket->flags=htons(pinoutPacket->flags);
237  m_pCipherOut->crypt1(((UINT8*)pinoutPacket),((UINT8*)pinoutPacket),16);
238  m_csSend.unlock();
239  return MIXPACKET_SIZE;
240  }
CAMutex m_csSend

References t_MixPacket::channel, t_MixPacket::flags, CAMutex::lock(), m_csSend, m_pCipherOut, MIXPACKET_SIZE, and CAMutex::unlock().

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

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

◆ receive() [1/2]

SINT32 CAMuxSocket::receive ( MIXPACKET pPacket)

Receives a whole MixPacket.

Blocks until a packet is received or a socket error occurs.

Parameters
pPacketon return stores the received MixPacket
Return values
SOCKET_ERROR,incase of an error
MIXPACKET_SIZEotherwise

Definition at line 249 of file CAMuxSocket.cpp.

250  {
251  SINT32 retLock = m_csReceive.lock();
252  if (retLock != E_SUCCESS)
253  {
254  CAMsg::printMsg(LOG_CRIT, "Could not lock MuxSocket receive method! Error code: %d\n", retLock);
255  return E_UNKNOWN;
256  }
257 
259  {
261  return SOCKET_ERROR;
262  }
263  if(m_bIsCrypted)
264  m_pCipherIn->crypt1((UINT8*)pPacket,(UINT8*)pPacket,16);
265  pPacket->channel=ntohl(pPacket->channel);
266  pPacket->flags=ntohs(pPacket->flags);
268  return MIXPACKET_SIZE;
269  }
#define SOCKET_ERROR
Definition: StdAfx.h:464
SINT32 receiveFully(UINT8 *buff, UINT32 len)
Receives all len bytes.
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
CAMutex m_csReceive

References t_MixPacket::channel, E_SUCCESS, E_UNKNOWN, t_MixPacket::flags, CAMutex::lock(), m_bIsCrypted, m_csReceive, m_pCipherIn, m_pSocket, MIXPACKET_SIZE, CAMsg::printMsg(), CAClientSocket::receiveFully(), SOCKET_ERROR, and CAMutex::unlock().

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

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

◆ receive() [2/2]

SINT32 CAMuxSocket::receive ( MIXPACKET pPacket,
UINT32  msTimeout 
)

Trys to receive a Mix-Packet.

If after timout milliseconds not a whole packet is available E_AGAIN will be returned. In this case you should later try to get the rest of the packet

Definition at line 278 of file CAMuxSocket.cpp.

279  {
280  if (m_pSocket->isClosed())
281  {
282  return E_NOT_CONNECTED;
283  }
284 
285  SINT32 retLock = m_csReceive.lock();
286  if (retLock != E_SUCCESS)
287  {
288  CAMsg::printMsg(LOG_CRIT,
289  "Could not lock MuxSocket timed receive method! Error code: %d\n", retLock);
290  return E_UNKNOWN;
291  }
294  if(ret<=0&&ret!=E_AGAIN) //if socket was set in non-blocking mode
295  {
297  return E_UNKNOWN;
298  }
299  if(ret==len) //whole packet recieved
300  {
301  if(m_bIsCrypted)
302  m_pCipherIn->crypt1(m_Buff,m_Buff,16);
303  memcpy(pPacket,m_Buff,MIXPACKET_SIZE);
304  pPacket->channel=ntohl(pPacket->channel);
305  pPacket->flags=ntohs(pPacket->flags);
306  m_aktBuffPos=0;
308  return MIXPACKET_SIZE;
309  }
310  if(ret>0) //some new bytes arrived
311  m_aktBuffPos+=ret;
312  if(msTimeout==0) //we should not wait any more
313  {
315  return E_AGAIN;
316  }
317  UINT64 timeE;
318  UINT64 timeC;
319  getcurrentTimeMillis(timeE);
320  add64(timeE,msTimeout);
321  UINT32 dt=msTimeout;
322  CASingleSocketGroup oSocketGroup(false);
323  oSocketGroup.add(*this);
324  for(;;)
325  {
326  if (m_pSocket->isClosed())
327  {
329  return E_NOT_CONNECTED;
330  }
331  ret=oSocketGroup.select(dt);
332  if(ret!=1)
333  {
335  return E_UNKNOWN;
336  }
338  if (m_pSocket->isClosed())
339  {
341  return E_NOT_CONNECTED;
342  }
344  if(ret<=0&&ret!=E_AGAIN)
345  {
346  if (m_pSocket->isClosed())
347  {
348  CAMsg::printMsg(LOG_ERR, "Error while receiving from socket. Socket is closed! Receive returned: %i Reason: %s (%i)\n", ret, GET_NET_ERROR_STR(GET_NET_ERROR), GET_NET_ERROR);
349  }
350  else
351  {
352  CAMsg::printMsg(LOG_ERR, "Error while receiving from socket. Receive returned: %i Reason: %s (%i)\n", ret, GET_NET_ERROR_STR(GET_NET_ERROR), GET_NET_ERROR);
353  }
355  return E_UNKNOWN;
356  }
357  if(ret==len)
358  {
359  if(m_bIsCrypted)
360  m_pCipherIn->crypt1(m_Buff,m_Buff,16);
361  memcpy(pPacket,m_Buff,MIXPACKET_SIZE);
362  pPacket->channel=ntohl(pPacket->channel);
363  pPacket->flags=ntohs(pPacket->flags);
364  m_aktBuffPos=0;
366  return MIXPACKET_SIZE;
367  }
368  if(ret>0)
369  m_aktBuffPos+=ret;
370  getcurrentTimeMillis(timeC);
371  if(isGreater64(timeC,timeE)||isEqual64(timeC,timeE))
372  break;
373  dt=diff64(timeE,timeC);
374  }
376  return E_AGAIN;
377  }
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
Definition: CAUtil.cpp:252
UINT32 diff64(const UINT64 &bigop, const UINT64 &smallop)
Definition: CAUtil.hpp:398
bool isEqual64(UINT64 &op1, UINT64 &op2)
Definition: CAUtil.hpp:455
void add64(UINT64 &op1, UINT32 op2)
Definition: CAUtil.hpp:375
bool isGreater64(UINT64 &op1, UINT64 &op2)
Definition: CAUtil.hpp:416
#define GET_NET_ERROR
Definition: StdAfx.h:469
#define GET_NET_ERROR_STR(x)
Definition: StdAfx.h:471
unsigned int UINT32
Definition: basetypedefs.h:131
virtual SINT32 receive(UINT8 *buff, UINT32 len)
Will receive some bytes from the socket.
Definition: CASocket.cpp:645
virtual bool isClosed()
Definition: CASocket.hpp:132
#define E_NOT_CONNECTED
Definition: errorcodes.hpp:22
#define E_AGAIN
Definition: errorcodes.hpp:9
HCHANNEL channel
Definition: typedefs.hpp:117
UINT16 flags
Definition: typedefs.hpp:118
UINT16 len
Definition: typedefs.hpp:0

References CASocketGroup::add(), add64(), t_MixPacket::channel, diff64(), E_AGAIN, E_NOT_CONNECTED, E_SUCCESS, E_UNKNOWN, t_MixPacket::flags, GET_NET_ERROR, GET_NET_ERROR_STR, getcurrentTimeMillis(), CASocket::isClosed(), isEqual64(), isGreater64(), len, CAMutex::lock(), m_aktBuffPos, m_bIsCrypted, m_Buff, m_csReceive, m_pCipherIn, m_pSocket, MIXPACKET_SIZE, CAMsg::printMsg(), CASocket::receive(), CASocketGroup::select(), and CAMutex::unlock().

Here is the call graph for this function:

◆ receiveFully() [1/2]

SINT32 CAMuxSocket::receiveFully ( UINT8 buff,
UINT32  len 
)
inline

Receives some "plain" bytes from the underlying socket - just a convenient function...

Definition at line 69 of file CAMuxSocket.hpp.

70  {
71  return m_pSocket->receiveFully(buff,len);
72  }

References len, m_pSocket, and CAClientSocket::receiveFully().

Referenced by CALastMix::processKeyExchange(), and CAMiddleMix::processKeyExchange().

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

◆ receiveFully() [2/2]

SINT32 CAMuxSocket::receiveFully ( UINT8 buff,
UINT32  len,
UINT32  msTimeOut 
)
inline

Definition at line 74 of file CAMuxSocket.hpp.

75  {
76  return m_pSocket->receiveFullyT(buff,len, msTimeOut);
77  }
virtual SINT32 receiveFullyT(UINT8 *buff, UINT32 len, UINT32 msTimeOut)
Trys to receive all bytes.
Definition: CASocket.cpp:677

References len, m_pSocket, and CASocket::receiveFullyT().

Here is the call graph for this function:

◆ send() [1/2]

SINT32 CAMuxSocket::send ( MIXPACKET pPacket)

Sends a MixPacket over the Network.

Will block until the whole packet is send.

Parameters
pPacketMixPacket to send
Return values
MIXPACKET_SIZEif MixPacket was successful send
E_UNKNOWNotherwise

Definition at line 186 of file CAMuxSocket.cpp.

187  {
188  m_csSend.lock();
189  int ret;
190  UINT8 tmpBuff[16];
191  memcpy(tmpBuff,pPacket,16);
192  pPacket->channel=htonl(pPacket->channel);
193  pPacket->flags=htons(pPacket->flags);
194  if(m_bIsCrypted)
195  m_pCipherOut->crypt1(((UINT8*)pPacket),((UINT8*)pPacket),16);
196  ret=m_pSocket->sendFully(((UINT8*)pPacket),MIXPACKET_SIZE);
197  if(ret!=E_SUCCESS)
198  {
199  #ifdef _DEBUG
200  CAMsg::printMsg(LOG_DEBUG,"MuxSocket-Send-Error!\n");
201  CAMsg::printMsg(LOG_DEBUG,"SOCKET-ERROR: %i\n",GET_NET_ERROR);
202  #endif
203  ret=E_UNKNOWN;
204  }
205  else
206  {
207  ret=MIXPACKET_SIZE;
208  }
209  memcpy(pPacket,tmpBuff,16);
210  m_csSend.unlock();
211  return ret;
212  }
virtual SINT32 sendFully(const UINT8 *buff, UINT32 len)
Sends all data over the network.
Definition: CASocket.cpp:587

References t_MixPacket::channel, E_SUCCESS, E_UNKNOWN, t_MixPacket::flags, GET_NET_ERROR, CAMutex::lock(), m_bIsCrypted, m_csSend, m_pCipherOut, m_pSocket, MIXPACKET_SIZE, CAMsg::printMsg(), CASocket::sendFully(), and CAMutex::unlock().

Referenced by CALocalProxy::loop(), and CALocalProxy::processKeyExchange().

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

◆ send() [2/2]

SINT32 CAMuxSocket::send ( MIXPACKET pPacket,
UINT8 buff 
)

Definition at line 215 of file CAMuxSocket.cpp.

216  {
217  m_csSend.lock();
218  int ret;
219  UINT8 tmpBuff[16];
220  memcpy(tmpBuff,pPacket,16);
221  pPacket->channel=htonl(pPacket->channel);
222  pPacket->flags=htons(pPacket->flags);
223  if(m_bIsCrypted)
224  m_pCipherOut->crypt1(((UINT8*)pPacket),((UINT8*)pPacket),16);
225  memcpy(buff,((UINT8*)pPacket),MIXPACKET_SIZE);
226  ret=MIXPACKET_SIZE;
227  memcpy(pPacket,tmpBuff,16);
228  m_csSend.unlock();
229  return ret;
230  }

References t_MixPacket::channel, t_MixPacket::flags, CAMutex::lock(), m_bIsCrypted, m_csSend, m_pCipherOut, MIXPACKET_SIZE, and CAMutex::unlock().

Here is the call graph for this function:

◆ setCASocket()

SINT32 CAMuxSocket::setCASocket ( CASocket pSocket)

This will set the underlying CASocket.

Note: The object will be under full controll of CAMuxSocket. It will be destroyed by CAMuxSocket, if not longer needed. Therefore it must have be dynamically allocated.

Parameters
pSocketthe new CASocket to use, should not be NULL
Returns
E_SUCCESS, if successful, E_UNKNOWN otherwise

Definition at line 81 of file CAMuxSocket.cpp.

82  {
83  if (m_pSocket == NULL)
84  return E_UNKNOWN;
85  delete m_pSocket;
86  m_pSocket = pSocket;
87  return E_SUCCESS;
88  }

References E_SUCCESS, E_UNKNOWN, and m_pSocket.

◆ setCipher()

SINT32 CAMuxSocket::setCipher ( SYMCHANNELCIPHER_ALGORITHM  algCipher)

Definition at line 90 of file CAMuxSocket.cpp.

91 {
92  if (algCipher == UNDEFINED_CIPHER)
93  return E_UNKNOWN;
94  if (m_pCipherIn != NULL)
95  {
96  delete m_pCipherIn;
97  }
98  if (m_pCipherOut != NULL)
99  {
100  delete m_pCipherOut;
101  }
102 #ifndef MUXSOCKET_CIPHER_NO_ENCRYPTION
105 #else
106 #ifdef DEUBG
107  CAMsg::printMsg(LOG_WARN, "MuxSocket: Using NULL cipher (no encryption)!\n");
108 #endif
111 #endif
112  return E_SUCCESS;
113 }
@ NULL_CIPHER
@ UNDEFINED_CIPHER
static CASymChannelCipher * createCipher(SYMCHANNELCIPHER_ALGORITHM alg)

References CASymChannelCipherFactory::createCipher(), E_SUCCESS, E_UNKNOWN, m_pCipherIn, m_pCipherOut, NULL_CIPHER, CAMsg::printMsg(), and UNDEFINED_CIPHER.

Referenced by CAMuxSocket(), and CALocalProxy::processKeyExchange().

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

◆ setCrypt()

SINT32 CAMuxSocket::setCrypt ( bool  b)

Definition at line 115 of file CAMuxSocket.cpp.

116  {
117  m_csSend.lock();
118  m_csReceive.lock();
119  m_bIsCrypted=b;
121  m_csSend.unlock();
122  return E_SUCCESS;
123  }

References E_SUCCESS, CAMutex::lock(), m_bIsCrypted, m_csReceive, m_csSend, and CAMutex::unlock().

Referenced by CAFirstMix::doUserLogin_internal(), CAMiddleMix::loop(), CALastMix::processKeyExchange(), and CALocalProxy::processKeyExchange().

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

◆ setKey()

SINT32 CAMuxSocket::setKey ( UINT8 key,
UINT32  keyLen 
)
inline

Sets the symmetric keys used for de-/encrypting the Mux connection.

Parameters
keybuffer conntaining the key bits
keyLensize of the buffer (keys) if keylen=16, then the key is used for incomming and outgoing direction (key only) if keylen=32, then the first bytes are used for incoming and the last bytes are used for outgoing
Return values
E_SUCCESSif successful
E_UNKNOWNotherwise

Definition at line 115 of file CAMuxSocket.hpp.

116  {
117  if(keyLen==16)
118  {
119  m_pCipherIn->setKey(key);
120  m_pCipherOut->setKey(key);
121  }
122  else if(keyLen==32)
123  {
124  m_pCipherOut->setKey(key);
125  m_pCipherIn->setKey(key+16);
126  }
127  else
128  return E_UNKNOWN;
129  return E_SUCCESS;
130  }

References E_SUCCESS, E_UNKNOWN, m_pCipherIn, and m_pCipherOut.

◆ setReceiveKey()

SINT32 CAMuxSocket::setReceiveKey ( UINT8 key,
UINT32  keyLen 
)
inline

Definition at line 148 of file CAMuxSocket.hpp.

149  {
150  if(keyLen==16)
151  {
152  m_pCipherIn->setKey(key);
153  }
154  else if(keyLen==32)
155  {
156  m_pCipherIn->setKey(key);
157  m_pCipherIn->setIVs(key+16);
158  }
159  else
160  {
161  return E_UNKNOWN;
162  }
163  return E_SUCCESS;
164  }

References E_SUCCESS, E_UNKNOWN, and m_pCipherIn.

Referenced by CAFirstMix::doUserLogin_internal(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), and CALocalProxy::processKeyExchange().

Here is the caller graph for this function:

◆ setSendKey()

SINT32 CAMuxSocket::setSendKey ( UINT8 key,
UINT32  keyLen 
)
inline

Definition at line 132 of file CAMuxSocket.hpp.

133  {
134  if(keyLen==16)
135  {
136  m_pCipherOut->setKey(key);
137  }
138  else if(keyLen==32)
139  {
140  m_pCipherOut->setKey(key);
141  m_pCipherOut->setIVs(key+16);
142  }
143  else
144  return E_UNKNOWN;
145  return E_SUCCESS;
146  }

References E_SUCCESS, E_UNKNOWN, and m_pCipherOut.

Referenced by CAFirstMix::doUserLogin_internal(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), and CALocalProxy::processKeyExchange().

Here is the caller graph for this function:

Member Data Documentation

◆ m_aktBuffPos

UINT32 CAMuxSocket::m_aktBuffPos
private

Definition at line 187 of file CAMuxSocket.hpp.

Referenced by accept(), CAMuxSocket(), close(), connect(), and receive().

◆ m_bIsCrypted

bool CAMuxSocket::m_bIsCrypted
private

Definition at line 191 of file CAMuxSocket.hpp.

Referenced by CAMuxSocket(), getIsEncrypted(), receive(), send(), and setCrypt().

◆ m_Buff

UINT8* CAMuxSocket::m_Buff
private

Definition at line 188 of file CAMuxSocket.hpp.

Referenced by CAMuxSocket(), receive(), and ~CAMuxSocket().

◆ m_csReceive

CAMutex CAMuxSocket::m_csReceive
private

Definition at line 193 of file CAMuxSocket.hpp.

Referenced by receive(), and setCrypt().

◆ m_csSend

CAMutex CAMuxSocket::m_csSend
private

Definition at line 192 of file CAMuxSocket.hpp.

Referenced by prepareForSend(), send(), and setCrypt().

◆ m_pCipherIn

CASymCipherMuxSocket* CAMuxSocket::m_pCipherIn
private

Definition at line 189 of file CAMuxSocket.hpp.

Referenced by CAMuxSocket(), receive(), setCipher(), setKey(), setReceiveKey(), and ~CAMuxSocket().

◆ m_pCipherOut

CASymCipherMuxSocket* CAMuxSocket::m_pCipherOut
private

◆ m_pHashKeyEntry

t_hashkeylistEntry* CAMuxSocket::m_pHashKeyEntry
private

Definition at line 194 of file CAMuxSocket.hpp.

Referenced by CAMuxSocket(), getHashKey(), and ~CAMuxSocket().

◆ m_pSocket

CASocket* CAMuxSocket::m_pSocket
private

◆ ms_nMaxHashKeyValue

SINT32 CAMuxSocket::ms_nMaxHashKeyValue =0
staticprivate

Definition at line 197 of file CAMuxSocket.hpp.

Referenced by CAMuxSocket().

◆ ms_pcsHashKeyList

CAMutex * CAMuxSocket::ms_pcsHashKeyList =NULL
staticprivate

Definition at line 198 of file CAMuxSocket.hpp.

Referenced by CAMuxSocket(), cleanup(), init(), and ~CAMuxSocket().

◆ ms_phashkeylistAvailableHashKeys

t_hashkeylistEntry * CAMuxSocket::ms_phashkeylistAvailableHashKeys =NULL
staticprivate

Definition at line 196 of file CAMuxSocket.hpp.

Referenced by CAMuxSocket(), cleanup(), and ~CAMuxSocket().


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