28 #include "../StdAfx.h"
29 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_LAST_MIX
31 #include "../CALibProxytest.hpp"
32 #include "../CALastMixChannelList.hpp"
33 #include "../CASingleSocketGroup.hpp"
34 #include "../CAPool.hpp"
35 #include "../CACmdLnOptions.hpp"
37 #include "../CASocketGroupEpoll.hpp"
39 #include "../CAControlChannelDispatcher.hpp"
40 #include "../CASymChannelCipherFactory.hpp"
41 #ifdef WITH_INTEGRITY_CHECK
42 #include "../CASymCipherGCM.hpp"
48 #define MACRO_DO_LOG_CHANNEL(a)\
49 CAMsg::printMsg(LOG_DEBUG,#a ":%u,%Lu,%Lu,%u,%u,%u,%u\n",\
50 pChannelListEntry->channelIn,pChannelListEntry->timeCreated,pQueueEntry->timestamp_proccessing_end,\
51 pChannelListEntry->trafficInFromUser,pChannelListEntry->trafficOutToUser,\
52 pChannelListEntry->packetsDataInFromUser,pChannelListEntry->packetsDataOutToUser);
53 #define MACRO_DO_LOG_CHANNEL_CLOSE_FROM_USER MACRO_DO_LOG_CHANNEL(1)
54 #define MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX MACRO_DO_LOG_CHANNEL(2)
57 #define LAST_MIX_SIZE_OF_SYMMETRIC_KEYS 2*KEY_SIZE
59 #ifndef MULTI_THREADED_PACKET_PROCESSING
69 #ifdef DELAY_CHANNELS_LATENCY
89 #ifdef WITH_INTEGRITY_CHECK
100 pLogThread->
start(
this);
103 bool bUserSurveillance =
false;
106 #ifdef ANON_DEBUG_MODE
107 bool bIsDebugPacket =
false;
111 CAMsg::printMsg(LOG_DEBUG,
"Channel time log format is as follows: Channel-ID,Channel Start [micros], Channel End [micros], Upload (bytes), Download (bytes), DataAndOpenPacketsFromUser, DataPacketsToUser\n");
128 #if defined(LOG_PACKET_TIMES) || defined(LOG_CHANNEL)
131 #ifdef LOG_PACKET_TIMES
132 set64(pQueueEntry->timestamp_proccessing_start, pQueueEntry->timestamp_proccessing_start_OP);
141 #ifdef ANON_DEBUG_MODE
148 bIsDebugPacket =
true;
152 bIsDebugPacket =
false;
163 if (pChannelListEntry == NULL)
167 #if defined(ANON_DEBUG_MODE)
175 CAMsg::printMsg(LOG_DEBUG,
"Received a channel open packet for incoming channel: %u\n", pMixPacket->
channel);
180 CAMsg::printMsg(LOG_ERR,
"Error in channel open asym decryption - channel!\n");
184 #ifdef LOG_PACKET_TIMES
185 setZero64(pQueueEntry->timestamp_proccessing_start);
192 #ifdef REPLAY_DETECTION
203 #ifdef WITH_INTEGRITY_CHECK
208 UINT16 lengthAndFlagsField = 0;
210 payloadLen = ntohs(lengthAndFlagsField);
232 #ifdef LOG_PACKET_TIMES
235 #ifdef WITH_INTEGRITY_CHECK
247 #ifdef LOG_PACKET_TIMES
248 setZero64(pQueueEntry->timestamp_proccessing_start);
252 #if defined(ANON_DEBUG_MODE)
254 EVP_EncodeBlock(tmpPacketBase64, tmpPacketData,
DATA_SIZE);
255 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-open packet: %s\n", tmpPacketBase64);
257 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-open packet!\n");
262 #if defined(ANON_DEBUG_MODE)
264 EVP_EncodeBlock(tmpPacketBase64, tmpPacketData,
DATA_SIZE);
265 CAMsg::printMsg(LOG_ERR,
"Integrity check ok in channel-open packet: %s\n", tmpPacketBase64);
288 #if defined(_DEBUG) || defined(DELAY_CHANNELS_LATENCY)
298 #ifdef WITH_INTEGRITY_CHECK
304 #ifdef LOG_PACKET_TIMES
305 setZero64(pQueueEntry->timestamp_proccessing_start);
318 time_t timeChannelOpened = time(NULL);
319 bool bIsCrime =
false;
320 if (bUserSurveillance)
326 EVP_EncodeBlock(base64Payload, pMixPacket->
payload.
data, payLen);
327 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, previous mix channel (opened at: %u): %u - Upstream Payload (Base64 encoded): %s\n", timeChannelOpened, pMixPacket->
channel, base64Payload);
364 memcpy(crimeBuff, pMixPacket->
payload.
data, payLen);
372 "%u -- Proxy Connection source port: %u -- Content: \n%s\n",
390 #ifdef WITH_INTEGRITY_CHECK
396 #ifdef LOG_PACKET_TIMES
397 setZero64(pQueueEntry->timestamp_proccessing_start);
416 #if defined(DELAY_CHANNELS_LATENCY)
421 #ifdef LASTMIX_CHECK_MEMORY
422 pQueue->logIfSizeGreaterThen(100000);
425 #
if defined(LOG_CHANNEL)
427 pQueueEntry->timestamp_proccessing_start, payLen
429 #
if defined(DELAY_CHANNELS_LATENCY)
437 #ifdef ANON_DEBUG_MODE
445 psocketgroupCacheRead->
add(*tmpSocket);
447 #ifdef LOG_PACKET_TIMES
449 m_pLogPacketStats->addToTimeingStats(*pQueueEntry,
CHANNEL_OPEN,
true);
451 #ifdef DATA_RETENTION_LOG
452 pQueueEntry->dataRetentionLogEntry.t_out = htonl(time(NULL));
453 pQueueEntry->dataRetentionLogEntry.entity.last.channelid = htonl(pMixPacket->
channel);
454 pQueueEntry->dataRetentionLogEntry.entity.last.port_out = tmpSocket->
getLocalPort();
455 pQueueEntry->dataRetentionLogEntry.entity.last.port_out = htons(pQueueEntry->dataRetentionLogEntry.entity.last.port_out);
456 tmpSocket->
getLocalIP(pQueueEntry->dataRetentionLogEntry.entity.last.ip_out);
457 m_pDataRetentionLog->log(&pQueueEntry->dataRetentionLogEntry);
461 #ifdef WITH_INTEGRITY_CHECK
486 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket),pChannelListEntry);
488 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket));
490 #if defined (LOG_PACKET_TIMES) ||defined (LOG_CHANNEL)
493 #if defined (LOG_PACKET_TIMES)
494 set64(pQueueEntry->timestamp_proccessing_end_OP,pQueueEntry->timestamp_proccessing_end);
495 m_pLogPacketStats->addToTimeingStats(*pQueueEntry,
CHANNEL_CLOSE,
true);
498 pChannelListEntry->packetsDataInFromUser++;
499 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_USER
505 #if defined(ANON_DEBUG_MODE)
511 pChannelListEntry->packetsDataInFromUser++;
513 #ifdef WITH_INTEGRITY_CHECK
515 UINT16 lengthAndFlagsField=0;
516 pChannelListEntry->
pCipher->decryptMessage(pMixPacket->
data, 2,(
UINT8*) &lengthAndFlagsField,
false);
517 payloadLen = ntohs(lengthAndFlagsField);
523 retval = pChannelListEntry->
pCipher->decryptMessage(pMixPacket->
data, payloadLen + 3 +
GCM_MAC_SIZE, plaintextBuff,
true);
526 #if defined(ANON_DEBUG_MODE)
528 EVP_EncodeBlock(tmpPacketBase64, tmpPacket,
DATA_SIZE);
529 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-data packet: %s\n", tmpPacketBase64);
531 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-data packet!\n");
534 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
535 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
537 delete pChannelListEntry->
pSocket;
538 pChannelListEntry->
pSocket = NULL;
545 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
547 delete pChannelListEntry->
pCipher;
548 pChannelListEntry->
pCipher = NULL;
550 pChannelListEntry->packetsDataOutToUser++;
552 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
555 #ifdef LOG_PACKET_TIMES
556 setZero64(pQueueEntry->timestamp_proccessing_start);
561 memcpy(pMixPacket->
data, plaintextBuff, payloadLen + 3);
575 pChannelListEntry->trafficInFromUser+=ret;
577 #ifdef LOG_PACKET_TIMES
583 if(bUserSurveillance)
588 EVP_EncodeBlock(base64Payload,pMixPacket->
payload.
data,ret);
589 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, previous mix channel (opened at: %u): %u - Upstream Payload (Base64 encoded): %s\n", pChannelListEntry->timeChannelOpened,pMixPacket->
channel,base64Payload);
590 pChannelListEntry->bLogPayload=
true;
612 else if(checkCrime(pMixPacket->
payload.
data, ret,
false))
624 "%u -- Content: \n%s\n", pMixPacket->
channel,
636 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
637 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
639 delete pChannelListEntry->
pSocket;
640 pChannelListEntry->
pSocket = NULL;
648 #ifdef WITH_INTEGRITY_CHECK
649 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
652 delete pChannelListEntry->
pCipher;
653 pChannelListEntry->
pCipher = NULL;
655 pChannelListEntry->packetsDataOutToUser++;
657 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
660 #ifdef LOG_PACKET_TIMES
661 setZero64(pQueueEntry->timestamp_proccessing_start);
676 #ifdef WITH_INTEGRITY_CHECK
677 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
683 pChannelListEntry->packetsDataOutToUser++;
685 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
687 #ifdef LOG_PACKET_TIMES
688 setZero64(pQueueEntry->timestamp_proccessing_start);
696 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket),pChannelListEntry);
698 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket));
700 #ifdef LOG_PACKET_TIMES
702 m_pLogPacketStats->addToTimeingStats(*pQueueEntry,
CHANNEL_DATA,
true);
705 #ifdef WITH_INTEGRITY_CHECK
715 countRead=psocketgroupCacheWrite->
select(0);
721 while(pChannelListEntry!=NULL)
725 while(pChannelListEntry!=NULL&&countRead>0)
745 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
746 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
748 delete pChannelListEntry->
pSocket;
749 pChannelListEntry->
pSocket = NULL;
750 delete pChannelListEntry->
pCipher;
751 pChannelListEntry->
pCipher = NULL;
758 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
766 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
767 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
769 delete pChannelListEntry->
pSocket;
770 pChannelListEntry->
pSocket = NULL;
776 #ifdef WITH_INTEGRITY_CHECK
777 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
780 delete pChannelListEntry->
pCipher;
781 pChannelListEntry->
pCipher = NULL;
785 #ifdef LOG_PACKET_TIMES
786 setZero64(pQueueEntry->timestamp_proccessing_start);
791 pChannelListEntry->packetsDataOutToUser++;
795 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
812 countRead=psocketgroupCacheRead->
select(0);
813 #ifdef DELAY_CHANNELS_LATENCY
814 UINT64 current_time_millis;
821 while(pChannelListEntry!=NULL)
825 while(pChannelListEntry!=NULL&&countRead>0)
833 #ifdef DELAY_CHANNELS
834 && ( pChannelListEntry->delayBucket>0)
836 #ifdef DELAY_CHANNELS_LATENCY
837 &&(
isGreater64(current_time_millis,pChannelListEntry->timeLatency))
841 #ifndef DELAY_CHANNELS
846 pChannelListEntry->delayBucket,
850 #ifdef LOG_PACKET_TIMES
852 set64(pQueueEntry->timestamp_proccessing_start_OP,pQueueEntry->timestamp_proccessing_start);
857 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
858 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
860 delete pChannelListEntry->
pSocket;
861 pChannelListEntry->
pSocket = NULL;
867 #ifdef WITH_INTEGRITY_CHECK
868 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
871 delete pChannelListEntry->
pCipher;
872 pChannelListEntry->
pCipher = NULL;
876 #ifdef LOG_PACKET_TIMES
882 pChannelListEntry->packetsDataOutToUser++;
886 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
893 #if defined(LOG_CHANNEL)
894 pChannelListEntry->trafficOutToUser+=ret;
896 #ifdef DELAY_CHANNELS
897 m_pChannelList->reduceDelayBuckets(pChannelListEntry->delayBucketID, ret);
909 if(pChannelListEntry->bLogPayload)
912 EVP_EncodeBlock(base64Payload,pMixPacket->
payload.
data,ret);
913 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, previous mix channel (opened at: %u): %u - Downstream Payload (Base64 encoded): %s\n", pChannelListEntry->timeChannelOpened,pChannelListEntry->
channelIn,base64Payload);
916 #ifdef WITH_INTEGRITY_CHECK
917 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, ret + 3, ciphertextBuff);
923 #ifdef LOG_PACKET_TIMES
926 #ifdef ANON_DEBUG_MODE
927 if (pChannelListEntry->bDebug )
931 EVP_EncodeBlock(tmpPacketBase64, pMixPacket->
data,
DATA_SIZE);
932 CAMsg::printMsg(LOG_ERR,
"Put AN.ON debug packet into send queue: %s\n", tmpPacketBase64);
938 #if defined(LOG_CHANNEL)
939 pChannelListEntry->packetsDataOutToUser++;
958 #ifndef FAST_PROCESSING
968 CAMsg::printMsg(LOG_CRIT,
"CALastMixA - loop() - Seems that we are restarting now!!\n");
972 delete pQueueEntryCrime;
973 pQueueEntryCrime = NULL;
979 delete []ciphertextBuff;
980 ciphertextBuff = NULL;
981 delete []plaintextBuff;
982 plaintextBuff = NULL;
988 delete psocketgroupCacheWrite;
989 psocketgroupCacheWrite = NULL;
990 delete psocketgroupCacheRead;
991 psocketgroupCacheRead = NULL;
1002 struct lm_packet_proccessing_loop_args_t
1005 CAQueue* pIncomingPacketQueue;
1007 typedef struct lm_packet_proccessing_loop_args_t tPacketProcessingLoopArgs;
1016 for (
UINT32 i = 0; i < numThreads; i++)
1018 pIncomingPacketQueues[i]=
new CAQueue();
1019 tPacketProcessingLoopArgs* pPacketProcessingArgs =
new tPacketProcessingLoopArgs;
1020 pPacketProcessingArgs->pLastMix =
this;
1021 pPacketProcessingArgs->pIncomingPacketQueue = pIncomingPacketQueues[i];
1022 pPacketProcessingThreads->
addRequest(lm_loopPacketProcessing, pPacketProcessingArgs);
1032 #if defined(LOG_PACKET_TIMES) ||defined(LOG_CHANNEL)
1035 #ifdef LOG_PACKET_TIMES
1036 set64(pQueueEntry->timestamp_proccessing_start,pQueueEntry->timestamp_proccessing_start_OP);
1047 pIncomingPacketQueues[pMixPacket->
channel%numThreads]->
add(pQueueEntry, ret);
1052 pPacketProcessingThreads->
destroy(
true);
1053 delete pPacketProcessingThreads;
1068 CALastMixA*
pMix =
static_cast<tPacketProcessingLoopArgs*
>(params)->pLastMix;
1069 CAQueue* pIncomingPacketsQueue =
static_cast<tPacketProcessingLoopArgs*
>(params)->pIncomingPacketQueue;
1071 #ifndef NEW_MIX_TYPE
1073 #ifdef DELAY_CHANNELS
1078 #ifdef DELAY_CHANNELS_LATENCY
1098 #ifdef WITH_INTEGRITY_CHECK
1111 bool bUserSurveillance =
false;
1114 #ifdef ANON_DEBUG_MODE
1115 bool bIsDebugPacket =
false;
1119 CAMsg::printMsg(LOG_DEBUG,
"Channel time log format is as follows: Channel-ID,Channel Start [micros], Channel End [micros], Upload (bytes), Download (bytes), DataAndOpenPacketsFromUser, DataPacketsToUser\n");
1122 while(!
pMix->m_bRestart)
1136 #if defined(LOG_PACKET_TIMES) ||defined(LOG_CHANNEL)
1139 #ifdef LOG_PACKET_TIMES
1140 set64(pQueueEntry->timestamp_proccessing_start,pQueueEntry->timestamp_proccessing_start_OP);
1142 #ifdef ANON_DEBUG_MODE
1149 bIsDebugPacket =
true;
1153 bIsDebugPacket =
false;
1156 pChannelListEntry=pChannelList->
get(pMixPacket->
channel);
1164 if(pChannelListEntry==NULL)
1168 #if defined(ANON_DEBUG_MODE)
1176 CAMsg::printMsg(LOG_DEBUG,
"Received a channel open packet for incoming channel: %u\n",pMixPacket->
channel);
1179 SINT32 retAsymDecryption=
pMix->m_pRSA->decryptOAEP(pMixPacket->
data,rsaBuff,&rsaOutLen);
1183 CAMsg::printMsg(LOG_DEBUG,
"Error in channel open asym decryption - channel!\n");
1186 #ifdef REPLAY_DETECTION
1197 #ifdef WITH_INTEGRITY_CHECK
1202 UINT16 lengthAndFlagsField=0;
1204 payloadLen = ntohs(lengthAndFlagsField);
1226 #ifdef LOG_PACKET_TIMES
1229 #ifdef WITH_INTEGRITY_CHECK
1241 #ifdef LOG_PACKET_TIMES
1242 setZero64(pQueueEntry->timestamp_proccessing_start);
1245 #if defined(ANON_DEBUG_MODE)
1247 EVP_EncodeBlock(tmpPacketBase64,tmpPacketData,
DATA_SIZE);
1248 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-open packet: %s\n",tmpPacketBase64);
1250 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-open packet!\n");
1254 #if defined(ANON_DEBUG_MODE)
1256 EVP_EncodeBlock(tmpPacketBase64,tmpPacketData,
DATA_SIZE);
1257 CAMsg::printMsg(LOG_ERR,
"Integrity check ok in channel-open packet: %s\n",tmpPacketBase64);
1265 ptmpLB=
pMix->m_pSocksLB;
1267 ptmpLB =
pMix->m_pVPNLB;
1280 #if defined (_DEBUG) || defined (DELAY_CHANNELS_LATENCY)
1290 #ifdef WITH_INTEGRITY_CHECK
1296 #ifdef LOG_PACKET_TIMES
1297 setZero64(pQueueEntry->timestamp_proccessing_start);
1309 time_t timeChannelOpened= time(NULL);
1310 if(bUserSurveillance)
1315 EVP_EncodeBlock(base64Payload,pMixPacket->
payload.
data,payLen);
1316 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, previous mix channel (opened at: %u): %u - Upstream Payload (Base64 encoded): %s\n", timeChannelOpened,pMixPacket->
channel,base64Payload);
1352 memcpy(crimeBuff,pMixPacket->
payload.
data,payLen);
1360 "%u -- Proxy Connection source port: %u -- Content: \n%s\n", pMixPacket->
channel,srcPort,
1377 #ifdef WITH_INTEGRITY_CHECK
1383 #ifdef LOG_PACKET_TIMES
1384 setZero64(pQueueEntry->timestamp_proccessing_start);
1393 #if defined (DELAY_CHANNELS_LATENCY)
1398 #ifdef LASTMIX_CHECK_MEMORY
1399 pQueue->logIfSizeGreaterThen(100000);
1401 pChannelList->
add(pMixPacket->
channel,tmpSocket,newCipher,pQueue
1402 #
if defined (LOG_CHANNEL)
1403 ,pQueueEntry->timestamp_proccessing_start,payLen
1405 #
if defined (DELAY_CHANNELS_LATENCY)
1411 #ifdef ANON_DEBUG_MODE
1416 psocketgroupCacheRead->
add(*tmpSocket,pChannelList->
get(pMixPacket->
channel));
1418 psocketgroupCacheRead->
add(*tmpSocket);
1420 #ifdef LOG_PACKET_TIMES
1422 m_pLogPacketStats->addToTimeingStats(*pQueueEntry,
CHANNEL_OPEN,
true);
1424 #ifdef DATA_RETENTION_LOG
1425 pQueueEntry->dataRetentionLogEntry.t_out=htonl(time(NULL));
1426 pQueueEntry->dataRetentionLogEntry.entity.last.channelid=htonl(pMixPacket->
channel);
1427 pQueueEntry->dataRetentionLogEntry.entity.last.port_out=tmpSocket->
getLocalPort();
1428 pQueueEntry->dataRetentionLogEntry.entity.last.port_out=htons(pQueueEntry->dataRetentionLogEntry.entity.last.port_out);
1429 tmpSocket->
getLocalIP(pQueueEntry->dataRetentionLogEntry.entity.last.ip_out);
1430 m_pDataRetentionLog->log(&pQueueEntry->dataRetentionLogEntry);
1435 #ifdef WITH_INTEGRITY_CHECK
1459 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket),pChannelListEntry);
1461 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket));
1463 #if defined (LOG_PACKET_TIMES) ||defined (LOG_CHANNEL)
1466 #if defined (LOG_PACKET_TIMES)
1467 set64(pQueueEntry->timestamp_proccessing_end_OP,pQueueEntry->timestamp_proccessing_end);
1468 m_pLogPacketStats->addToTimeingStats(*pQueueEntry,
CHANNEL_CLOSE,
true);
1471 pChannelListEntry->packetsDataInFromUser++;
1472 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_USER
1478 #if defined(ANON_DEBUG_MODE)
1484 pChannelListEntry->packetsDataInFromUser++;
1486 #ifdef WITH_INTEGRITY_CHECK
1488 UINT16 lengthAndFlagsField=0;
1489 pChannelListEntry->
pCipher->decryptMessage(pMixPacket->
data, 2,(
UINT8*) &lengthAndFlagsField,
false);
1490 payloadLen = ntohs(lengthAndFlagsField);
1496 retval = pChannelListEntry->
pCipher->decryptMessage(pMixPacket->
data, payloadLen + 3 +
GCM_MAC_SIZE, plaintextBuff,
true);
1499 #if defined(ANON_DEBUG_MODE)
1501 EVP_EncodeBlock(tmpPacketBase64, tmpPacket,
DATA_SIZE);
1502 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-data packet: %s\n", tmpPacketBase64);
1504 CAMsg::printMsg(LOG_ERR,
"Integrity check failed in channel-data packet!\n");
1507 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
1508 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
1510 delete pChannelListEntry->
pSocket;
1511 pChannelListEntry->
pSocket = NULL;
1518 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
1520 delete pChannelListEntry->
pCipher;
1521 pChannelListEntry->
pCipher = NULL;
1523 pChannelListEntry->packetsDataOutToUser++;
1525 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
1528 #ifdef LOG_PACKET_TIMES
1529 setZero64(pQueueEntry->timestamp_proccessing_start);
1533 memcpy(pMixPacket->
data, plaintextBuff, payloadLen + 3);
1547 pChannelListEntry->trafficInFromUser+=ret;
1549 #ifdef LOG_PACKET_TIMES
1555 if(bUserSurveillance)
1560 EVP_EncodeBlock(base64Payload,pMixPacket->
payload.
data,ret);
1561 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, previous mix channel (opened at: %u): %u - Upstream Payload (Base64 encoded): %s\n", pChannelListEntry->timeChannelOpened,pMixPacket->
channel,base64Payload);
1562 pChannelListEntry->bLogPayload=
true;
1584 else if(checkCrime(pMixPacket->
payload.
data, ret,
false))
1597 "%u -- Content: \n%s\n", pMixPacket->
channel,
1609 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
1610 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
1612 delete pChannelListEntry->
pSocket;
1613 pChannelListEntry->
pSocket = NULL;
1621 #ifdef WITH_INTEGRITY_CHECK
1622 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
1625 delete pChannelListEntry->
pCipher;
1626 pChannelListEntry->
pCipher = NULL;
1628 pChannelListEntry->packetsDataOutToUser++;
1630 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
1633 #ifdef LOG_PACKET_TIMES
1634 setZero64(pQueueEntry->timestamp_proccessing_start);
1648 #ifdef WITH_INTEGRITY_CHECK
1649 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
1655 pChannelListEntry->packetsDataOutToUser++;
1657 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
1659 #ifdef LOG_PACKET_TIMES
1660 setZero64(pQueueEntry->timestamp_proccessing_start);
1667 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket),pChannelListEntry);
1669 psocketgroupCacheWrite->
add(*(pChannelListEntry->
pSocket));
1671 #ifdef LOG_PACKET_TIMES
1673 m_pLogPacketStats->addToTimeingStats(*pQueueEntry,
CHANNEL_DATA,
true);
1676 #ifdef WITH_INTEGRITY_CHECK
1686 countRead=psocketgroupCacheWrite->
select(0);
1692 while(pChannelListEntry!=NULL)
1696 while(pChannelListEntry!=NULL&&countRead>0)
1715 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
1716 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
1718 delete pChannelListEntry->
pSocket;
1719 pChannelListEntry->
pSocket = NULL;
1720 delete pChannelListEntry->
pCipher;
1721 pChannelListEntry->
pCipher = NULL;
1728 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
1736 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
1737 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
1739 delete pChannelListEntry->
pSocket;
1740 pChannelListEntry->
pSocket = NULL;
1746 #ifdef WITH_INTEGRITY_CHECK
1747 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
1750 delete pChannelListEntry->
pCipher;
1751 pChannelListEntry->
pCipher = NULL;
1755 #ifdef LOG_PACKET_TIMES
1756 setZero64(pQueueEntry->timestamp_proccessing_start);
1760 pChannelListEntry->packetsDataOutToUser++;
1764 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
1781 countRead=psocketgroupCacheRead->
select(0);
1782 #ifdef DELAY_CHANNELS_LATENCY
1783 UINT64 current_time_millis;
1790 while(pChannelListEntry!=NULL)
1794 while(pChannelListEntry!=NULL&&countRead>0)
1802 #ifdef DELAY_CHANNELS
1803 && ( pChannelListEntry->delayBucket>0)
1805 #ifdef DELAY_CHANNELS_LATENCY
1806 &&(
isGreater64(current_time_millis,pChannelListEntry->timeLatency))
1810 #ifndef DELAY_CHANNELS
1815 pChannelListEntry->delayBucket,
1819 #ifdef LOG_PACKET_TIMES
1821 set64(pQueueEntry->timestamp_proccessing_start_OP,pQueueEntry->timestamp_proccessing_start);
1826 psocketgroupCacheRead->
remove(*(pChannelListEntry->
pSocket));
1827 psocketgroupCacheWrite->
remove(*(pChannelListEntry->
pSocket));
1829 delete pChannelListEntry->
pSocket;
1830 pChannelListEntry->
pSocket = NULL;
1836 #ifdef WITH_INTEGRITY_CHECK
1837 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, 3, ciphertextBuff);
1840 delete pChannelListEntry->
pCipher;
1841 pChannelListEntry->
pCipher = NULL;
1845 #ifdef LOG_PACKET_TIMES
1850 pChannelListEntry->packetsDataOutToUser++;
1854 MACRO_DO_LOG_CHANNEL_CLOSE_FROM_MIX
1861 #if defined(LOG_CHANNEL)
1862 pChannelListEntry->trafficOutToUser+=ret;
1864 #ifdef DELAY_CHANNELS
1865 pChannelList->reduceDelayBuckets(pChannelListEntry->delayBucketID, ret);
1878 if(pChannelListEntry->bLogPayload)
1881 EVP_EncodeBlock(base64Payload,pMixPacket->
payload.
data,ret);
1882 CAMsg::printMsg(LOG_CRIT,
"Crime detection: User surveillance, previous mix channel (opened at: %u): %u - Downstream Payload (Base64 encoded): %s\n", pChannelListEntry->timeChannelOpened,pChannelListEntry->
channelIn,base64Payload);
1885 #ifdef WITH_INTEGRITY_CHECK
1886 pChannelListEntry->
pCipher->encryptMessage(pMixPacket->
data, ret + 3, ciphertextBuff);
1892 #ifdef LOG_PACKET_TIMES
1895 #ifdef ANON_DEBUG_MODE
1896 if (pChannelListEntry->bDebug )
1900 EVP_EncodeBlock(tmpPacketBase64, pMixPacket->
data,
DATA_SIZE);
1901 CAMsg::printMsg(LOG_ERR,
"Put AN.ON debug packet into send queue: %s\n", tmpPacketBase64);
1906 #if defined(LOG_CHANNEL)
1907 pChannelListEntry->packetsDataOutToUser++;
1926 #ifndef FAST_PROCESSING
1938 delete pQueueEntryCrime;
1939 pQueueEntryCrime = NULL;
1945 delete []ciphertextBuff;
1946 ciphertextBuff = NULL;
1947 delete []plaintextBuff;
1948 plaintextBuff = NULL;
1951 delete psocketgroupCacheWrite;
1952 psocketgroupCacheWrite = NULL;
1953 delete psocketgroupCacheRead;
1954 psocketgroupCacheRead = NULL;
#define LAST_MIX_SIZE_OF_SYMMETRIC_KEYS
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
SINT32 getcurrentTimeMicros(UINT64 &u64Time)
Gets the current Systemtime in micros seconds.
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
void setZero64(UINT64 &op1)
void add64(UINT64 &op1, UINT32 op2)
bool isGreater64(UINT64 &op1, UINT64 &op2)
void set64(UINT64 &op1, UINT32 op2)
#define MAX_MIXIN_SEND_QUEUE_SIZE
#define LAST_MIX_TO_PROXY_SEND_TIMEOUT
#define LAST_MIX_TO_PROXY_CONNECT_TIMEOUT
#define THREAD_RETURN_SUCCESS
#define FLOW_CONTROL_SENDME_HARD_LIMIT
#define FLOW_CONTROL_SENDME_SOFT_LIMIT
SINT32 decryptOAEP(const UINT8 *from, UINT8 *to, UINT32 *len)
Decrypts one OAEP encoded block which is stored in from.
This class stores Addresses off different Cache-Proxies.
CASocketAddrINet * get()
Gets the 'next' Address according to the Load-Balancing algorithm.
bool proccessMixPacket(const MIXPACKET *pPacket)
SINT32 insert(UINT8 key[16], UINT64 timestamp)
Inserts this key in the replay DB.
lmChannelListEntry * get(HCHANNEL channelIn)
SINT32 add(HCHANNEL id, CASocket *pSocket, CASymChannelCipher *pCipher, CAQueue *pQueue)
lmChannelListEntry * getFirstSocket()
lmChannelListEntry * getNextSocket()
SINT32 removeChannel(HCHANNEL channelIn)
volatile UINT32 m_logDownloadedPackets
CAQueue * m_pQueueSendToMix
volatile UINT64 m_logDownloadedBytes
volatile UINT64 m_logUploadedBytes
CACacheLoadBalancing * m_pVPNLB
CALastMixChannelList * m_pChannelList
CAQueue * m_pQueueReadFromMix
CACacheLoadBalancing * m_pCacheLB
friend THREAD_RETURN lm_loopLog(void *)
volatile UINT32 m_logUploadedPackets
CACacheLoadBalancing * m_pSocksLB
static CACmdLnOptions * getOptions()
CAControlChannelDispatcher * m_pMuxInControlChannelDispatcher
UINT64 m_u64ReferenceTime
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
This is a simple FIFO-Queue.
SINT32 add(const void *buff, UINT32 size)
Adds data to the Queue.
SINT32 get(UINT8 *pbuff, UINT32 *psize)
Gets up to psize number of bytes from the Queue.
SINT32 peek(UINT8 *pbuff, UINT32 *psize)
Peeks data from the Queue.
SINT32 close()
Closes the Queue (for writing).
SINT32 remove(UINT32 *psize)
Removes data from the Queue.
UINT32 getSize()
Returns the size of stored data in byte.
bool isClosed()
Returns true, if the Queue is closed.
bool isEmpty()
Returns true, if the Queue is empty.
UINT32 getSizeLookFree()
Returns the size of stored data in byte.
SINT32 remove(CASocket &s)
bool isSignaled(CASocket &s)
SINT32 add(CASocket &s)
Adds the socket s to the socket group.
void * getFirstSignaledSocketData()
void * getNextSignaledSocketData()
virtual SINT32 receive(UINT8 *buff, UINT32 len)
Will receive some bytes from the socket.
virtual SINT32 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
virtual SINT32 setRecvBuff(UINT32 r)
virtual SINT32 sendTimeOut(const UINT8 *buff, UINT32 len, UINT32 msTimeOut)
Sends some data over the network.
virtual SINT32 setNonBlocking(bool b)
virtual SINT32 setSendBuff(SINT32 r)
Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r)
virtual SINT32 getLocalIP(UINT8 r_Ip[4])
LERNGRUPPE Returns the source address of the socket.
virtual SINT32 connect(const CASocketAddr &psa)
virtual SINT32 getLocalPort()
static CASymChannelCipher * createCipher(SYMCHANNELCIPHER_ALGORITHM alg)
virtual SINT32 crypt2(const UINT8 *in, UINT8 *out, UINT32 len)=0
virtual SINT32 crypt1(const UINT8 *in, UINT8 *out, UINT32 len)=0
This class could be used for encryption/decryption of data (streams) with AES using 128bit GCM mode.
void setGCMKeys(UINT8 *keyRecv, UINT8 *keySend)
SINT32 encryptMessage(const UINT8 *in, UINT32 inlen, UINT8 *out)
SINT32 decryptMessage(const UINT8 *in, UINT32 inlen, UINT8 *out, bool integrityCheck)
SINT32 start(void *param, bool bDaemon=false, bool bSilent=false)
Starts the execution of the main function of this thread.
SINT32 setMainLoop(THREAD_MAIN_TYP fnc)
Sets the main function which will be executed within this thread.
SINT32 join()
Waits for the main function to finish execution.
SINT32 destroy(bool bWaitForFinish)
SINT32 addRequest(THREAD_MAIN_TYP, void *args)
Adds a new request (task) to this threadpool.
struct t_MixPacketPayload payload
CASymChannelCipher * pCipher
SINT32 sendmeCounterDownstream
SINT32 sendmeCounterUpstream
#define MIX_PAYLOAD_SOCKS
#define NEW_FLOW_CONTROL_FLAG
struct t_queue_entry tQueueEntry
#define CHANNEL_SIG_CRIME
#define PAYLOAD_HEADER_SIZE
#define CONNECTION_ERROR_FLAG
#define INTEGRITY_ERROR_FLAG