merged with latest upstream trunk

This commit is contained in:
csoler 2015-12-05 16:49:00 -05:00
commit 0c1e6301b3
295 changed files with 17456 additions and 12859 deletions

View file

@ -31,6 +31,7 @@
#include "openssl/err.h"
#include "util/rsaes.h"
#include "util/rsmemory.h"
#include <serialiser/rsmsgitems.h>
@ -435,10 +436,6 @@ bool DistantChatService::handleEncryptedData(const uint8_t *data_bytes,uint32_t
{
RS_STACK_MUTEX(mDistantChatMtx); /********** STACK LOCKED MTX ******/
uint32_t decrypted_size = RsAES::get_buffer_size(data_size-8);
uint8_t *decrypted_data = new uint8_t[decrypted_size];
uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
std::map<RsPeerId,DistantChatDHInfo>::iterator it = _distant_chat_virtual_peer_ids.find(virtual_peer_id) ;
if(it == _distant_chat_virtual_peer_ids.end())
@ -455,8 +452,11 @@ bool DistantChatService::handleEncryptedData(const uint8_t *data_bytes,uint32_t
std::cerr << "(EE) no GXS id data for ID=" << gxs_id << ". This is a bug." << std::endl;
return true ;
}
uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
memcpy(aes_key,it2->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ;
uint32_t decrypted_size = RsAES::get_buffer_size(data_size-8);
uint8_t *decrypted_data = new uint8_t[decrypted_size];
#ifdef DEBUG_DISTANT_CHAT
std::cerr << " Using IV: " << std::hex << *(uint64_t*)data_bytes << std::dec << std::endl;
std::cerr << " Decrypted buffer size: " << decrypted_size << std::endl;
@ -540,7 +540,7 @@ void DistantChatService::handleRecvDHPublicKey(RsChatDHPublicKeyItem *item)
#endif
uint32_t pubkey_size = BN_num_bytes(item->public_key) ;
unsigned char *data = (unsigned char *)malloc(pubkey_size) ;
RsTemporaryMemory data(pubkey_size) ;
BN_bn2bin(item->public_key, data) ;
RsTlvSecurityKey signature_key ;
@ -585,7 +585,7 @@ void DistantChatService::handleRecvDHPublicKey(RsChatDHPublicKeyItem *item)
signature_key = item->gxs_key ;
}
if(!GxsSecurity::validateSignature((char*)data,pubkey_size,signature_key,item->signature))
if(!GxsSecurity::validateSignature((char*)(uint8_t*)data,pubkey_size,signature_key,item->signature))
{
std::cerr << "(SS) Signature was verified and it doesn't check! This is a security issue!" << std::endl;
return ;
@ -690,10 +690,10 @@ bool DistantChatService::locked_sendDHPublicKey(const DH *dh,const RsGxsId& own_
uint32_t error_status ;
uint32_t size = BN_num_bytes(dhitem->public_key) ;
unsigned char *data = (unsigned char *)malloc(size) ;
RsTemporaryMemory data(size) ;
BN_bn2bin(dhitem->public_key, data) ;
if(!mGixs->signData((unsigned char*)data,size,own_gxs_id,signature,error_status))
if(!mGixs->signData(data,size,own_gxs_id,signature,error_status))
{
switch(error_status)
{
@ -702,11 +702,9 @@ bool DistantChatService::locked_sendDHPublicKey(const DH *dh,const RsGxsId& own_
default: std::cerr << "(EE) Unknown error when signing" << std::endl;
break ;
}
free(data) ;
delete(dhitem);
return false;
}
free(data) ;
if(!mGixs->getKey(own_gxs_id,signature_key_public))
{
@ -810,19 +808,16 @@ void DistantChatService::sendTurtleData(RsChatItem *item)
else
{
uint32_t rssize = item->serial_size();
uint8_t *buff = (uint8_t*)malloc(rssize) ;
RsTemporaryMemory buff(rssize) ;
if(!item->serialise(buff,rssize))
{
std::cerr << "(EE) DistantChatService::sendTurtleData(): Could not serialise item!" << std::endl;
free(buff) ;
delete item ;
return ;
}
sendEncryptedTurtleData(buff,rssize,RsGxsId(item->PeerId())) ;
free(buff) ;
}
delete item ;
}

View file

@ -34,6 +34,7 @@
#include "pqi/p3historymgr.h"
#include "retroshare/rspeers.h"
#include "retroshare/rsiface.h"
#include "retroshare/rsreputations.h"
#include "retroshare/rsidentity.h"
#include "rsserver/p3face.h"
#include "gxs/rsgixs.h"
@ -168,13 +169,27 @@ bool DistributedChatService::handleRecvChatLobbyMsgItem(RsChatMsgItem *ci)
{
RsIdentityDetails details;
if(!rsIdentity->getIdDetails(cli->signature.keyId,details) || !( details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN))
if(!rsIdentity->getIdDetails(cli->signature.keyId,details))
{
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << "(WW) cannot get ID " << cli->signature.keyId << " for checking signature of lobby item." << std::endl;
#endif
return false;
}
if(!(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED))
{
std::cerr << "(WW) Received a lobby msg/item that is not PGP-authed (id=" << cli->signature.keyId << "), whereas the lobby flags require it. Rejecting!" << std::endl;
return false ;
}
}
if(rsReputations->isIdentityBanned(cli->signature.keyId))
{
std::cerr << "(WW) Received lobby msg/item from banned identity " << cli->signature.keyId << ". Dropping it." << std::endl;
return false ;
}
if(!bounceLobbyObject(cli,cli->PeerId())) // forwards the message to friends, keeps track of subscribers, etc.
return false;
@ -665,13 +680,26 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
{
RsIdentityDetails details;
if(!rsIdentity->getIdDetails(item->signature.keyId,details) || !(details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN))
if(!rsIdentity->getIdDetails(item->signature.keyId,details))
{
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << "(WW) cannot get ID " << item->signature.keyId << " for checking signature of lobby item." << std::endl;
#endif
return ;
}
if(!(details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED))
{
std::cerr << "(WW) Received a lobby msg/item that is not PGP-authed (ID=" << item->signature.keyId << "), whereas the lobby flags require it. Rejecting!" << std::endl;
return ;
}
}
if(rsReputations->isIdentityBanned(item->signature.keyId))
{
std::cerr << "(WW) Received lobby msg/item from banned identity " << item->signature.keyId << ". Dropping it." << std::endl;
return ;
}
addTimeShiftStatistics((int)now - (int)item->sendTime) ;
if(now+100 > (time_t) item->sendTime + MAX_KEEP_MSG_RECORD) // the message is older than the max cache keep minus 100 seconds ! It's too old, and is going to make an echo!