Mixe for Privacy and Anonymity in the Internet
CAMuxSocket.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 __CAMUXSOCKET__
30 #define __CAMUXSOCKET__
31 #include "CASocket.hpp"
32 #include "CASymChannelCipher.hpp"
33 #include "CAMutex.hpp"
34 #include "CATLSClientSocket.hpp"
35 
37  {
40  };
41 
43 
44 
46  {
47  public:
49  ~CAMuxSocket();
50 
53  {
54  return m_pHashKeyEntry->hashkey;
55  }
56 
57  SINT32 accept(UINT16 port);
58  SINT32 accept(const CASocketAddr& oAddr);
60  SINT32 connect(CASocketAddr& psa,UINT retry,UINT32 time);
61  SINT32 close();
62  SINT32 send(MIXPACKET *pPacket);
63  SINT32 send(MIXPACKET *pPacket,UINT8* buff);
64  SINT32 prepareForSend(MIXPACKET* inoutPacket);
65  SINT32 receive(MIXPACKET *pPacket);
66  SINT32 receive(MIXPACKET *pPacket,UINT32 timeout);
67 
70  {
71  return m_pSocket->receiveFully(buff,len);
72  }
73 
75  {
76  return m_pSocket->receiveFullyT(buff,len, msTimeOut);
77  }
78 
79  //int close(HCHANNEL channel_id);
80  //int close(HCHANNEL channel_id,UINT8* buff);
81 #ifdef LOG_CRIME
82  void sigCrime(HCHANNEL channel_id,MIXPACKET* sigPacket);
83 #endif
91  SINT32 setCASocket(CASocket *pSocket);
93 
94 
95  SINT32 setCrypt(bool b);
97  {
98  return m_bIsCrypted;
99  }
100 
101 
102  /***Sets the cipher algorithm used. Note: the current values for keys and IVs will not be carried over to the new cipher algorithm!
103  **/
105 
115  SINT32 setKey(UINT8* key,UINT32 keyLen)
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  }
131 
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  }
147 
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  }
165 
166  static SINT32 init()
167  {
169  return E_SUCCESS;
170  }
171 
172  static SINT32 cleanup()
173  {
175  {
178  delete tmpEntry;
179  }
180  delete ms_pcsHashKeyList;
181  ms_pcsHashKeyList=NULL;
182  return E_SUCCESS;
183  }
184 
185  private:
195 
196  static t_hashkeylistEntry* ms_phashkeylistAvailableHashKeys; //stores the available hashkeys -> if this list is empty new entires are created on the fly
197  static SINT32 ms_nMaxHashKeyValue; // the maximum value of a hash key
199 
200  };
201 #endif
#define CASymCipherMuxSocket
SYMCHANNELCIPHER_ALGORITHM
#define SOCKET
Definition: StdAfx.h:460
unsigned short UINT16
Definition: basetypedefs.h:133
unsigned int UINT
Definition: basetypedefs.h:155
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
SINT32 receiveFully(UINT8 *buff, UINT32 len)
Receives all len bytes.
CAMutex m_csSend
CAMutex m_csReceive
SOCKET getSocket()
Definition: CAMuxSocket.hpp:92
UINT32 m_aktBuffPos
static SINT32 init()
SINT32 close()
Closes the underlying socket.
SINT32 accept(UINT16 port)
SINT32 receive(MIXPACKET *pPacket)
Receives a whole MixPacket.
CASocket * m_pSocket
SINT32 connect(CASocketAddr &psa)
static t_hashkeylistEntry * ms_phashkeylistAvailableHashKeys
SINT32 setSendKey(UINT8 *key, UINT32 keyLen)
CASymCipherMuxSocket * m_pCipherOut
SINT32 setReceiveKey(UINT8 *key, UINT32 keyLen)
SINT32 setCrypt(bool b)
bool getIsEncrypted()
Definition: CAMuxSocket.hpp:96
SINT32 send(MIXPACKET *pPacket)
Sends a MixPacket over the Network.
SINT32 setKey(UINT8 *key, UINT32 keyLen)
Sets the symmetric keys used for de-/encrypting the Mux connection.
SINT32 getHashKey()
Returns a Hashkey which uniquely identifies this socket.
Definition: CAMuxSocket.hpp:52
CASymCipherMuxSocket * m_pCipherIn
SINT32 setCASocket(CASocket *pSocket)
This will set the underlying CASocket.
Definition: CAMuxSocket.cpp:81
SINT32 receiveFully(UINT8 *buff, UINT32 len)
Receives some "plain" bytes from the underlying socket - just a convenient function....
Definition: CAMuxSocket.hpp:69
UINT8 * m_Buff
CASocket * getCASocket()
Definition: CAMuxSocket.hpp:84
static CAMutex * ms_pcsHashKeyList
SINT32 prepareForSend(MIXPACKET *inoutPacket)
SINT32 setCipher(SYMCHANNELCIPHER_ALGORITHM algCipher)
Definition: CAMuxSocket.cpp:90
static SINT32 ms_nMaxHashKeyValue
t_hashkeylistEntry * m_pHashKeyEntry
static SINT32 cleanup()
CAMuxSocket(SYMCHANNELCIPHER_ALGORITHM algCipher)
Definition: CAMuxSocket.cpp:42
SINT32 receiveFully(UINT8 *buff, UINT32 len, UINT32 msTimeOut)
Definition: CAMuxSocket.hpp:74
This is an abstract class for representing a socket address used in CASocket, CADatagramSocket and CA...
SOCKET getSocket()
Returns the number of the Socket used.
Definition: CASocket.hpp:87
virtual SINT32 receiveFullyT(UINT8 *buff, UINT32 len, UINT32 msTimeOut)
Trys to receive all bytes.
Definition: CASocket.cpp:677
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3
Definition: CAMuxSocket.hpp:37
struct __t_hash_key_entry__ * next
Definition: CAMuxSocket.hpp:38
SINT32 hashkey
Definition: CAMuxSocket.hpp:39
UINT32 HCHANNEL
Definition: typedefs.hpp:34
UINT16 len
Definition: typedefs.hpp:0