mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -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
@ -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 **/
|
||||
|
@ -52,6 +52,7 @@ typedef RsPgpId RsPgpId;
|
||||
// The meaning of the different circle types is:
|
||||
//
|
||||
//
|
||||
static const uint32_t GXS_CIRCLE_TYPE_UNKNOWN = 0x0000 ; // not known. Is treated as public.
|
||||
static const uint32_t GXS_CIRCLE_TYPE_PUBLIC = 0x0001 ; // not restricted to a circle
|
||||
static const uint32_t GXS_CIRCLE_TYPE_EXTERNAL = 0x0002 ; // restricted to an external circle, made of RsGxsId
|
||||
static const uint32_t GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY = 0x0003 ; // restricted to a subset of friend nodes of a given RS node given by a RsPgpId list
|
||||
|
@ -33,11 +33,13 @@ typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;
|
||||
class RsGxsGrpMetaData;
|
||||
class RsGxsMsgMetaData;
|
||||
|
||||
|
||||
struct RsGroupMetaData
|
||||
{
|
||||
// (csoler) The correct default value to be used in mCircleType is GXS_CIRCLE_TYPE_PUBLIC, which is defined in rsgxscircles.h,
|
||||
// but because of a loop in the includes, I cannot include it here. So I replaced with its current value 0x0001.
|
||||
|
||||
RsGroupMetaData() : mGroupFlags(0), mSignFlags(0), mPublishTs(0),
|
||||
mCircleType(0), mAuthenFlags(0), mSubscribeFlags(0), mPop(0),
|
||||
mCircleType(0x0001), mAuthenFlags(0), mSubscribeFlags(0), mPop(0),
|
||||
mVisibleMsgCount(0), mLastPost(0), mGroupStatus(0) {}
|
||||
|
||||
void operator =(const RsGxsGrpMetaData& rGxsMeta);
|
||||
|
@ -690,6 +690,7 @@ bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms)
|
||||
RsGxsIdGroup id;
|
||||
|
||||
id.mMeta.mGroupName = params.nickname;
|
||||
id.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC ;
|
||||
id.mImage = params.mImage;
|
||||
|
||||
if (params.isPgpLinked)
|
||||
@ -712,6 +713,7 @@ bool p3IdService::updateIdentity(uint32_t& token, RsGxsIdGroup &group)
|
||||
std::cerr << "p3IdService::updateIdentity()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
group.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC ;
|
||||
|
||||
updateGroup(token, group);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user