mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 22:25:04 -04:00
merged with upstream/master
This commit is contained in:
commit
6c8737c84a
38 changed files with 284 additions and 109 deletions
|
@ -1543,13 +1543,20 @@ void p3GRouter::handleIncomingReceiptItem(RsGRouterSignedReceiptItem *receipt_it
|
|||
else
|
||||
std::cerr << " checking receipt hash : OK" << std::endl;
|
||||
#endif
|
||||
// check signature.
|
||||
// check signature. The policy if the following:
|
||||
// if we're the destination:
|
||||
// signature should check and signing key should be available // always ensures the receipt is valid
|
||||
// else
|
||||
// if key is available, signature should check // early protects against frodulent receipts that we can check
|
||||
|
||||
uint32_t error_status ;
|
||||
|
||||
if(! verifySignedDataItem(receipt_item))
|
||||
{
|
||||
std::cerr << " checking receipt signature : FAILED. Receipt is dropped." << std::endl;
|
||||
return ;
|
||||
}
|
||||
if(! verifySignedDataItem(receipt_item,error_status))
|
||||
if( (it->second.routing_flags & GRouterRoutingInfo::ROUTING_FLAGS_IS_ORIGIN) || (error_status != RsGixs::RS_GIXS_ERROR_KEY_NOT_AVAILABLE))
|
||||
{
|
||||
std::cerr << " checking receipt signature : FAILED. Receipt is dropped. Error status=" << error_status << std::endl;
|
||||
return ;
|
||||
}
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " checking receipt signature : OK. " << std::endl;
|
||||
std::cerr << " removing messsage from cache." << std::endl;
|
||||
|
@ -1698,7 +1705,9 @@ void p3GRouter::handleIncomingDataItem(RsGRouterGenericDataItem *data_item)
|
|||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " step B: item is for us and is new, so make sure it's authentic and create a receipt" << std::endl;
|
||||
#endif
|
||||
if(!verifySignedDataItem(data_item)) // we should get proper flags out of this
|
||||
uint32_t error_status ;
|
||||
|
||||
if(!verifySignedDataItem(data_item,error_status)) // we should get proper flags out of this
|
||||
{
|
||||
std::cerr << " verifying item signature: FAILED! Droping that item" ;
|
||||
std::cerr << " You probably received a message from a person you don't have key." << std::endl;
|
||||
|
@ -1978,7 +1987,7 @@ bool p3GRouter::signDataItem(RsGRouterAbstractMsgItem *item,const RsGxsId& signi
|
|||
return false ;
|
||||
}
|
||||
}
|
||||
bool p3GRouter::verifySignedDataItem(RsGRouterAbstractMsgItem *item)
|
||||
bool p3GRouter::verifySignedDataItem(RsGRouterAbstractMsgItem *item,uint32_t& error_status)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -1997,9 +2006,6 @@ bool p3GRouter::verifySignedDataItem(RsGRouterAbstractMsgItem *item)
|
|||
if(!item->serialise_signed_data(data,data_size))
|
||||
throw std::runtime_error("Cannot serialise signed data.") ;
|
||||
|
||||
|
||||
uint32_t error_status ;
|
||||
|
||||
if(!mGixs->validateData(data,data_size,item->signature,true,error_status))
|
||||
{
|
||||
switch(error_status)
|
||||
|
@ -2115,8 +2121,9 @@ bool p3GRouter::sendData(const RsGxsId& destination,const GRouterServiceId& clie
|
|||
}
|
||||
|
||||
// Verify the signature. If that fails, there's a bug somewhere!!
|
||||
|
||||
if(!verifySignedDataItem(data_item))
|
||||
uint32_t error_status;
|
||||
|
||||
if(!verifySignedDataItem(data_item,error_status))
|
||||
{
|
||||
std::cerr << "Cannot verify data item that was just signed. Some error occured!" << std::endl;
|
||||
delete data_item;
|
||||
|
|
|
@ -263,7 +263,7 @@ private:
|
|||
|
||||
// signs an item with the given key.
|
||||
bool signDataItem(RsGRouterAbstractMsgItem *item,const RsGxsId& id) ;
|
||||
bool verifySignedDataItem(RsGRouterAbstractMsgItem *item) ;
|
||||
bool verifySignedDataItem(RsGRouterAbstractMsgItem *item, uint32_t &error_status) ;
|
||||
bool encryptDataItem(RsGRouterGenericDataItem *item,const RsGxsId& destination_key) ;
|
||||
bool decryptDataItem(RsGRouterGenericDataItem *item) ;
|
||||
|
||||
|
|
|
@ -2873,11 +2873,11 @@ void RsGenExchange::processRecvdGroups()
|
|||
|
||||
if(gpsi.mAttempts == VALIDATE_MAX_ATTEMPTS)
|
||||
{
|
||||
delete grp;
|
||||
erase = true;
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " max attempts " << VALIDATE_MAX_ATTEMPTS << " reached. Will delete group " << grp->grpId << std::endl;
|
||||
#endif
|
||||
delete grp;
|
||||
erase = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -763,15 +763,19 @@ bool p3GxsTunnelService::handleEncryptedData(const uint8_t *data_bytes,uint32_t
|
|||
uint32_t encrypted_size = data_size - GXS_TUNNEL_ENCRYPTION_IV_SIZE - GXS_TUNNEL_ENCRYPTION_HMAC_SIZE;
|
||||
uint32_t decrypted_size = RsAES::get_buffer_size(encrypted_size);
|
||||
uint8_t *encrypted_data = (uint8_t*)data_bytes+GXS_TUNNEL_ENCRYPTION_IV_SIZE+GXS_TUNNEL_ENCRYPTION_HMAC_SIZE;
|
||||
uint8_t *decrypted_data = new uint8_t[decrypted_size];
|
||||
|
||||
RsTemporaryMemory decrypted_data(decrypted_size);
|
||||
uint8_t aes_key[GXS_TUNNEL_AES_KEY_SIZE] ;
|
||||
|
||||
if(!decrypted_data)
|
||||
return false ;
|
||||
|
||||
std::map<TurtleVirtualPeerId,GxsTunnelDHInfo>::iterator it = _gxs_tunnel_virtual_peer_ids.find(virtual_peer_id) ;
|
||||
|
||||
if(it == _gxs_tunnel_virtual_peer_ids.end())
|
||||
{
|
||||
std::cerr << "(EE) item is not coming out of a registered tunnel. Weird. hash=" << hash << ", peer id = " << virtual_peer_id << std::endl;
|
||||
return true ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
tunnel_id = it->second.tunnel_id ;
|
||||
|
@ -780,7 +784,7 @@ bool p3GxsTunnelService::handleEncryptedData(const uint8_t *data_bytes,uint32_t
|
|||
if(it2 == _gxs_tunnel_contacts.end())
|
||||
{
|
||||
std::cerr << "(EE) no tunnel data for tunnel ID=" << tunnel_id << ". This is a bug." << std::endl;
|
||||
return true ;
|
||||
return false ;
|
||||
}
|
||||
memcpy(aes_key,it2->second.aes_key,GXS_TUNNEL_AES_KEY_SIZE) ;
|
||||
|
||||
|
@ -800,8 +804,6 @@ bool p3GxsTunnelService::handleEncryptedData(const uint8_t *data_bytes,uint32_t
|
|||
std::cerr << "(EE) packet HMAC does not match. Computed HMAC=" << RsUtil::BinToHex((char*)hm,GXS_TUNNEL_ENCRYPTION_HMAC_SIZE) << std::endl;
|
||||
std::cerr << "(EE) resetting new DH session." << std::endl;
|
||||
|
||||
delete[] decrypted_data ;
|
||||
|
||||
locked_restartDHSession(virtual_peer_id,it2->second.own_gxs_id) ;
|
||||
|
||||
return false ;
|
||||
|
@ -812,8 +814,6 @@ bool p3GxsTunnelService::handleEncryptedData(const uint8_t *data_bytes,uint32_t
|
|||
std::cerr << "(EE) packet decryption failed." << std::endl;
|
||||
std::cerr << "(EE) resetting new DH session." << std::endl;
|
||||
|
||||
delete[] decrypted_data ;
|
||||
|
||||
locked_restartDHSession(virtual_peer_id,it2->second.own_gxs_id) ;
|
||||
|
||||
return false ;
|
||||
|
@ -829,8 +829,6 @@ bool p3GxsTunnelService::handleEncryptedData(const uint8_t *data_bytes,uint32_t
|
|||
//
|
||||
citem = dynamic_cast<RsGxsTunnelItem*>(RsGxsTunnelSerialiser().deserialise(decrypted_data,&decrypted_size)) ;
|
||||
|
||||
delete[] decrypted_data ;
|
||||
|
||||
if(citem == NULL)
|
||||
{
|
||||
std::cerr << "(EE) item could not be de-serialized. That is an error." << std::endl;
|
||||
|
@ -1003,7 +1001,7 @@ void p3GxsTunnelService::handleRecvDHPublicKey(RsGxsTunnelDHPublicKeyItem *item)
|
|||
|
||||
#ifdef DEBUG_GXS_TUNNEL
|
||||
std::cerr << " DH key computed. Tunnel is now secured!" << std::endl;
|
||||
std::cerr << " Key computed: " << RsUtil::BinToHex((char*)pinfo.aes_key,16) << std::cerr << std::endl;
|
||||
std::cerr << " Key computed: " << RsUtil::BinToHex((char*)pinfo.aes_key,16) << std::endl;
|
||||
std::cerr << " Sending a ACK packet." << std::endl;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -823,8 +823,6 @@ continue_packet:
|
|||
std::cerr << "[" << (void*)pthread_self() << "] " << "deserializing. Size=" << pktlen << std::endl ;
|
||||
#endif
|
||||
|
||||
inReadBytes_locked(pktlen); // only count deserialised packets, because that's what is actually been transfered.
|
||||
|
||||
RsItem *pkt = mRsSerialiser->deserialise(block, &pktlen);
|
||||
|
||||
if ((pkt != NULL) && (0 < handleincomingitem_locked(pkt,pktlen)))
|
||||
|
@ -832,6 +830,7 @@ continue_packet:
|
|||
#ifdef DEBUG_PQISTREAMER
|
||||
pqioutput(PQL_DEBUG_BASIC, pqistreamerzone, "Successfully Read a Packet!");
|
||||
#endif
|
||||
inReadBytes_locked(pktlen); // only count deserialised packets, because that's what is actually been transfered.
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -952,7 +951,7 @@ int pqistreamer::inAllowedBytes_locked()
|
|||
static const float AVG_PERIOD = 5; // sec
|
||||
static const float AVG_FRAC = 0.8; // for low pass filter.
|
||||
|
||||
void pqistreamer::outSentBytes_locked(int outb)
|
||||
void pqistreamer::outSentBytes_locked(uint32_t outb)
|
||||
{
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
{
|
||||
|
@ -1022,7 +1021,7 @@ void pqistreamer::outSentBytes_locked(int outb)
|
|||
return;
|
||||
}
|
||||
|
||||
void pqistreamer::inReadBytes_locked(int inb)
|
||||
void pqistreamer::inReadBytes_locked(uint32_t inb)
|
||||
{
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
{
|
||||
|
|
|
@ -102,10 +102,10 @@ class pqistreamer: public PQInterface
|
|||
float outTimeSlice_locked();
|
||||
|
||||
int outAllowedBytes_locked();
|
||||
void outSentBytes_locked(int );
|
||||
void outSentBytes_locked(uint32_t );
|
||||
|
||||
int inAllowedBytes_locked();
|
||||
void inReadBytes_locked(int );
|
||||
void inReadBytes_locked(uint32_t );
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1258,6 +1258,9 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
std::vector<std::string> plugins_directories ;
|
||||
|
||||
#ifdef __APPLE__
|
||||
plugins_directories.push_back(rsAccounts->PathDataDirectory()) ;
|
||||
#endif
|
||||
#ifndef WINDOWS_SYS
|
||||
plugins_directories.push_back(std::string(PLUGIN_DIR)) ;
|
||||
#endif
|
||||
|
|
|
@ -280,7 +280,7 @@ int p3BandwidthControl::getAllBandwidthRates(std::map<RsPeerId, RsConfigDataRate
|
|||
|
||||
}
|
||||
|
||||
int p3BandwidthControl::ExtractTrafficInfo(std::list<RSTrafficClue>& in_stats,std::list<RSTrafficClue>& out_stats)
|
||||
int p3BandwidthControl::ExtractTrafficInfo(std::list<RSTrafficClue>& out_stats, std::list<RSTrafficClue>& in_stats)
|
||||
{
|
||||
return mPg->ExtractTrafficInfo(out_stats,in_stats) ;
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ class p3BandwidthControl: public p3Service, public pqiServiceMonitor
|
|||
virtual int getAllBandwidthRates(std::map<RsPeerId, RsConfigDataRates> &ratemap);
|
||||
|
||||
|
||||
virtual int ExtractTrafficInfo(std::list<RSTrafficClue> &in_stats, std::list<RSTrafficClue> &out_stats);
|
||||
virtual int ExtractTrafficInfo(std::list<RSTrafficClue> &out_stats, std::list<RSTrafficClue> &in_stats);
|
||||
|
||||
/*!
|
||||
* Interface stuff.
|
||||
|
|
|
@ -514,20 +514,20 @@ bool p3GxsChannels::setChannelDownloadDirectory(const RsGxsGroupId &groupId, con
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsChannels::getChannelDownloadDirectory(const RsGxsGroupId & id,std::string& directory)
|
||||
bool p3GxsChannels::getChannelDownloadDirectory(const RsGxsGroupId & groupId,std::string& directory)
|
||||
{
|
||||
#ifdef GXSCHANNELS_DEBUG
|
||||
std::cerr << "p3GxsChannels::autoDownloadEnabled(" << id << ")" << std::endl;
|
||||
std::cerr << "p3GxsChannels::getChannelDownloadDirectory(" << id << ")" << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<RsGxsGroupId, RsGroupMetaData>::iterator it;
|
||||
|
||||
it = mSubscribedGroups.find(id);
|
||||
it = mSubscribedGroups.find(groupId);
|
||||
|
||||
if (it == mSubscribedGroups.end())
|
||||
{
|
||||
#ifdef GXSCHANNELS_DEBUG
|
||||
std::cerr << "p3GxsChannels::autoDownloadEnabled() No Entry" << std::endl;
|
||||
std::cerr << "p3GxsChannels::getChannelDownloadDirectory() No Entry" << std::endl;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
|
@ -904,7 +904,7 @@ void p3GxsChannels::handleResponse(uint32_t token, uint32_t req_type)
|
|||
/********************************************************************************************/
|
||||
|
||||
|
||||
bool p3GxsChannels::autoDownloadEnabled(const RsGxsGroupId &id,bool& enabled)
|
||||
bool p3GxsChannels::autoDownloadEnabled(const RsGxsGroupId &groupId,bool& enabled)
|
||||
{
|
||||
#ifdef GXSCHANNELS_DEBUG
|
||||
std::cerr << "p3GxsChannels::autoDownloadEnabled(" << id << ")";
|
||||
|
@ -913,7 +913,7 @@ bool p3GxsChannels::autoDownloadEnabled(const RsGxsGroupId &id,bool& enabled)
|
|||
|
||||
std::map<RsGxsGroupId, RsGroupMetaData>::iterator it;
|
||||
|
||||
it = mSubscribedGroups.find(id);
|
||||
it = mSubscribedGroups.find(groupId);
|
||||
if (it == mSubscribedGroups.end())
|
||||
{
|
||||
#ifdef GXSCHANNELS_DEBUG
|
||||
|
@ -927,22 +927,24 @@ bool p3GxsChannels::autoDownloadEnabled(const RsGxsGroupId &id,bool& enabled)
|
|||
/* extract from ServiceString */
|
||||
SSGxsChannelGroup ss;
|
||||
ss.load(it->second.mServiceString);
|
||||
enabled = ss.mAutoDownload;
|
||||
enabled = ss.mAutoDownload;
|
||||
|
||||
return true ;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SSGxsChannelGroup::load(const std::string &input)
|
||||
{
|
||||
if(input.empty())
|
||||
{
|
||||
#ifdef GXSCHANNELS_DEBUG
|
||||
std::cerr << "SSGxsChannelGroup::load() asked to load a null string." << std::endl;
|
||||
#endif
|
||||
return true ;
|
||||
}
|
||||
int download_val;
|
||||
mAutoDownload = false;
|
||||
mDownloadDirectory.clear();
|
||||
|
||||
if(input.empty())
|
||||
{
|
||||
std::cerr << "(EE) SSGxsChannelGroup::load() asked to load a null string. Weird." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
RsTemporaryMemory tmpmem(input.length());
|
||||
|
||||
|
|
|
@ -45,12 +45,12 @@
|
|||
class SSGxsChannelGroup
|
||||
{
|
||||
public:
|
||||
|
||||
SSGxsChannelGroup(): mAutoDownload(false), mDownloadDirectory("") {}
|
||||
bool load(const std::string &input);
|
||||
std::string save() const;
|
||||
|
||||
bool mAutoDownload;
|
||||
std::string mDownloadDirectory ;
|
||||
std::string mDownloadDirectory;
|
||||
};
|
||||
|
||||
|
||||
|
@ -176,7 +176,7 @@ static uint32_t channelsAuthenPolicy();
|
|||
void updateSubscribedGroup(const RsGroupMetaData &group);
|
||||
void clearUnsubscribedGroup(const RsGxsGroupId &id);
|
||||
bool setAutoDownload(const RsGxsGroupId &groupId, bool enabled);
|
||||
bool autoDownloadEnabled(const RsGxsGroupId &id, bool &enabled);
|
||||
bool autoDownloadEnabled(const RsGxsGroupId &groupId, bool &enabled);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -859,7 +859,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
|||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Dropping, because the serial size exceeds the accepted limit." << std::endl ;
|
||||
#endif
|
||||
std::cerr << " Caught a turtle search item with arbitrary large size from " << item->PeerId() << " of size " << item->serial_size() << ". This is not allowed => dropping." << std::endl;
|
||||
std::cerr << " Caught a turtle search item with arbitrary large size from " << item->PeerId() << " of size " << item->serial_size() << " and depth " << item->depth << ". This is not allowed => dropping." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
|
|
|
@ -182,6 +182,7 @@ void ContentValue::put(const std::string &key, uint32_t len, const char* value){
|
|||
|
||||
mKvData.insert(std::pair<std::string, std::pair<uint32_t, char*> >
|
||||
(key, std::pair<uint32_t, char*>(len, dest)));
|
||||
//delete[] dest; //Deleted by clearData()
|
||||
}
|
||||
|
||||
bool ContentValue::getAsBool(const std::string &key, bool& value) const{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue