mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-07 13:52:43 -04:00
added consistency check in meta data in publishGroup() and updateGroup() in order to avoid bad data supplied from GXS services
This commit is contained in:
parent
d2dc632176
commit
06265f2b54
6 changed files with 106 additions and 21 deletions
|
@ -1554,15 +1554,88 @@ void RsGenExchange::notifyChangedGroupStats(const RsGxsGroupId &grpId)
|
|||
mNotifications.push_back(gc);
|
||||
}
|
||||
|
||||
bool RsGenExchange::checkGroupMetaConsistency(const RsGroupMetaData& meta)
|
||||
{
|
||||
std::cerr << "Checking group consistency:" << std::endl;
|
||||
|
||||
if(meta.mGroupName.empty())
|
||||
{
|
||||
std::cerr << "(EE) cannot create a group with no name." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(meta.mGroupFlags != GXS_SERV::FLAG_PRIVACY_PUBLIC && meta.mGroupFlags != GXS_SERV::FLAG_PRIVACY_RESTRICTED && meta.mGroupFlags != GXS_SERV::FLAG_PRIVACY_PRIVATE)
|
||||
{
|
||||
std::cerr << "(EE) mGroupFlags has incorrect value " << std::hex << meta.mGroupFlags << std::dec << ". A value among GXS_SERV::FLAG_PRIVACY_{PUBLIC,RESTRICTED,PRIVATE} is expected." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
if(meta.mCircleType < GXS_CIRCLE_TYPE_PUBLIC || meta.mCircleType > GXS_CIRCLE_TYPE_YOUR_EYES_ONLY)
|
||||
{
|
||||
std::cerr << "(EE) mCircleType has incorrect value " << std::hex << meta.mCircleType << std::dec << ". A single value among GXS_CIRCLE_TYPE_{PUBLIC,EXTERNAL,YOUR_FRIENDS_ONLY,LOCAL,EXT_SELF,YOUR_EYES_ONLY} is expected." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
if(meta.mCircleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
{
|
||||
if(!meta.mInternalCircle.isNull())
|
||||
{
|
||||
std::cerr << "(EE) Group circle type is EXTERNAL, but an internal circle ID " << meta.mInternalCircle << " was supplied. This is an error." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
if(meta.mCircleId.isNull())
|
||||
{
|
||||
std::cerr << "(EE) Group circle type is EXTERNAL, but no external circle ID was supplied. meta.mCircleId is indeed empty. This is an error." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
if(meta.mCircleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
|
||||
{
|
||||
if(!meta.mCircleId.isNull())
|
||||
{
|
||||
std::cerr << "(EE) Group circle type is YOUR_FRIENDS_ONLY, but an external circle ID " << meta.mCircleId << " was supplied. This is an error." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
if(meta.mInternalCircle.isNull())
|
||||
{
|
||||
std::cerr << "(EE) Group circle type is YOUR_FRIENDS_ONLY, but no internal circle ID was supplied. meta.mInternalCircle is indeed empty. This is an error." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
if(meta.mCircleType == GXS_CIRCLE_TYPE_EXT_SELF)
|
||||
{
|
||||
if(!meta.mCircleId.isNull())
|
||||
{
|
||||
std::cerr << "(EE) Group circle type is EXT_SELF, but an external circle ID " << meta.mCircleId << " was supplied. This is an error." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
if(!meta.mInternalCircle.isNull())
|
||||
{
|
||||
std::cerr << "(EE) Group circle type is EXT_SELF, but an internal circle ID " << meta.mInternalCircle << " was supplied. This is an error." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "Group is clean." << std::endl;
|
||||
return true ;
|
||||
}
|
||||
|
||||
void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem)
|
||||
{
|
||||
if(!checkGroupMetaConsistency(grpItem->meta))
|
||||
{
|
||||
std::cerr << "(EE) Cannot publish group. Some information was not supplied." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
RS_STACK_MUTEX(mGenMtx) ;
|
||||
token = mDataAccess->generatePublicToken();
|
||||
GxsGrpPendingSign ggps(grpItem, token);
|
||||
mGrpsToPublish.push_back(ggps);
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::publishGroup() token: " << token;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
@ -1572,6 +1645,12 @@ void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem)
|
|||
|
||||
void RsGenExchange::updateGroup(uint32_t& token, RsGxsGrpItem* grpItem)
|
||||
{
|
||||
if(!checkGroupMetaConsistency(grpItem->meta))
|
||||
{
|
||||
std::cerr << "(EE) Cannot update group. Some information was not supplied." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
RS_STACK_MUTEX(mGenMtx) ;
|
||||
token = mDataAccess->generatePublicToken();
|
||||
mGroupUpdatePublish.push_back(GroupUpdatePublish(grpItem, token));
|
||||
|
|
|
@ -689,6 +689,8 @@ private:
|
|||
|
||||
void publishMsgs();
|
||||
|
||||
bool checkGroupMetaConsistency(const RsGroupMetaData& meta);
|
||||
|
||||
/*!
|
||||
* processes msg local meta changes
|
||||
*/
|
||||
|
|
|
@ -3890,16 +3890,14 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
|
|||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
|
||||
else if(circleType == GXS_CIRCLE_TYPE_PUBLIC || circleType == GXS_CIRCLE_TYPE_UNKNOWN) // this complies with the fact that p3IdService does not initialise the circle type.
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " PUBLIC_CIRCLE, can send"<< std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
else if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " EXTERNAL_CIRCLE, will be sent encrypted."<< std::endl;
|
||||
|
@ -3907,8 +3905,7 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
|
|||
should_encrypt = true ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
|
||||
else if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
|
||||
|
@ -3922,8 +3919,11 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
|
|||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " YOUREYESONLY, checking further"<< std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
else
|
||||
{
|
||||
std::cerr << "(EE) unknown value found in circle type for group " << grpMeta.mGroupId << ": " << (int)circleType << ": this is probably a bug in the design of the group creation." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGxsNetService::checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxsGrpMetaData& grpMeta, RsGxsCircleId& should_encrypt_id)
|
||||
|
@ -4281,19 +4281,16 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
|
|||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
|
||||
else if(circleType == GXS_CIRCLE_TYPE_PUBLIC || circleType == GXS_CIRCLE_TYPE_UNKNOWN) // this complies with the fact that p3IdService does not initialise the circle type.
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: PUBLIC => returning true" << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
const RsGxsCircleId& circleId = grpMeta.mCircleId;
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
else if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
{
|
||||
const RsGxsCircleId& circleId = grpMeta.mCircleId;
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs ids list will be encrypted." << std::endl;
|
||||
#endif
|
||||
|
@ -4338,8 +4335,7 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
|
|||
|
||||
return true ;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
|
||||
else if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
|
||||
|
@ -4350,8 +4346,11 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
|
|||
#endif
|
||||
return res ;
|
||||
}
|
||||
|
||||
return false;
|
||||
else
|
||||
{
|
||||
std::cerr << "(EE) unknown value found in circle type for group " << grpMeta.mGroupId << ": " << (int)circleType << ": this is probably a bug in the design of the group creation." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** inherited methods **/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue