fixed usage info statistics in identities

This commit is contained in:
csoler 2020-07-08 12:56:40 +02:00
parent 57a1c4bf5d
commit 6d665868e8
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
10 changed files with 75 additions and 80 deletions

View File

@ -219,7 +219,13 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
// network pre-request key to allow message authentication.
mGixs->requestKey(obj->signature.keyId,peer_list,RsIdentityUsage(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id));
mGixs->requestKey(obj->signature.keyId,peer_list,RsIdentityUsage(RsServiceType::CHAT,
RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,
RsGxsGroupId(),
RsGxsMessageId(),
RsGxsMessageId(),
RsGxsMessageId(),
obj->lobby_id));
uint32_t size = RsChatSerialiser(RsSerializationFlags::SIGNATURE)
.size(dynamic_cast<RsItem*>(obj));
@ -238,7 +244,13 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
}
uint32_t error_status ;
RsIdentityUsage use_info(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id) ;
RsIdentityUsage use_info(RsServiceType::CHAT,
RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,
RsGxsGroupId(),
RsGxsMessageId(),
RsGxsMessageId(),
RsGxsMessageId(),
obj->lobby_id) ;
if(!mGixs->validateData(memory,size,obj->signature,false,use_info,error_status))
{

View File

@ -450,7 +450,7 @@ void p3discovery2::recvIdentityList(const RsPeerId& pid,const std::list<RsGxsId>
std::cerr << "p3discovery2::recvIdentityList(): from peer " << pid << ": " << ids.size() << " identities" << std::endl;
#endif
RsIdentityUsage use_info(RS_SERVICE_TYPE_DISC,RsIdentityUsage::IDENTITY_DATA_UPDATE);
RsIdentityUsage use_info(RsServiceType::GOSSIP_DISCOVERY,RsIdentityUsage::IDENTITY_NEW_FROM_DISCOVERY);
for(auto it(ids.begin());it!=ids.end();++it)
{

View File

@ -2108,7 +2108,7 @@ bool p3GRouter::verifySignedDataItem(const RsGRouterAbstractMsgItem *item,const
if(!signature_serializer.serialise(const_cast<RsGRouterAbstractMsgItem*>(item),data,&data_size))
throw std::runtime_error("Cannot serialise signed data.");
RsIdentityUsage use(RS_SERVICE_TYPE_GROUTER,info);
RsIdentityUsage use(RsServiceType::GROUTER,info);
if(!mGixs->validateData( data, data_size, item->signature, true, use, error_status ))
{

View File

@ -512,7 +512,7 @@ int RsGenExchange::createGroupSignatures(RsTlvKeySignatureSet& signSet, RsTlvBin
if(GxsSecurity::getSignature((char*)grpData.bin_data, grpData.bin_len, authorKey, sign))
{
id_ret = SIGN_SUCCESS;
mGixs->timeStampKey(grpMeta.mAuthorId,RsIdentityUsage(mServType,RsIdentityUsage::GROUP_AUTHOR_SIGNATURE_CREATION,grpMeta.mGroupId)) ;
mGixs->timeStampKey(grpMeta.mAuthorId,RsIdentityUsage(RsServiceType(mServType),RsIdentityUsage::GROUP_AUTHOR_SIGNATURE_CREATION,grpMeta.mGroupId)) ;
signSet.keySignSet[INDEX_AUTHEN_IDENTITY] = sign;
}
else
@ -953,7 +953,12 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, const uin
{
std::list<RsPeerId> peers;
peers.push_back(msg->PeerId());
mGixs->requestKey(metaData.mAuthorId, peers, RsIdentityUsage((RsServiceType)serviceType(),RsIdentityUsage::MESSAGE_AUTHOR_SIGNATURE_VALIDATION,metaData.mGroupId,metaData.mMsgId,metaData.mParentId,metaData.mThreadId));
mGixs->requestKey(metaData.mAuthorId, peers, RsIdentityUsage((RsServiceType)serviceType(),
RsIdentityUsage::MESSAGE_AUTHOR_SIGNATURE_VALIDATION,
metaData.mGroupId,
metaData.mMsgId,
metaData.mParentId,
metaData.mThreadId));
#ifdef GEN_EXCH_DEBUG
std::cerr << ", Key missing. Retry later." << std::endl;
@ -1030,7 +1035,7 @@ int RsGenExchange::validateGrp(RsNxsGrp* grp)
#ifdef GEN_EXCH_DEBUG
std::cerr << " key ID validation result: " << idValidate << std::endl;
#endif
mGixs->timeStampKey(metaData.mAuthorId,RsIdentityUsage(mServType,RsIdentityUsage::GROUP_AUTHOR_SIGNATURE_VALIDATION,metaData.mGroupId));
mGixs->timeStampKey(metaData.mAuthorId,RsIdentityUsage(RsServiceType(mServType),RsIdentityUsage::GROUP_AUTHOR_SIGNATURE_VALIDATION,metaData.mGroupId));
}
else
{
@ -1048,7 +1053,7 @@ int RsGenExchange::validateGrp(RsNxsGrp* grp)
#endif
std::list<RsPeerId> peers;
peers.push_back(grp->PeerId());
mGixs->requestKey(metaData.mAuthorId, peers,RsIdentityUsage(mServType,RsIdentityUsage::GROUP_AUTHOR_SIGNATURE_VALIDATION,metaData.mGroupId));
mGixs->requestKey(metaData.mAuthorId, peers,RsIdentityUsage(RsServiceType(mServType),RsIdentityUsage::GROUP_AUTHOR_SIGNATURE_VALIDATION,metaData.mGroupId));
return VALIDATE_FAIL_TRY_LATER;
}
}
@ -3350,7 +3355,7 @@ bool RsGenExchange::updateValid(const RsGxsGrpMetaData& oldGrpMeta, const RsNxsG
// also check this is the latest published group
bool latest = newGrp.metaData->mPublishTs > oldGrpMeta.mPublishTs;
mGixs->timeStampKey(newGrp.metaData->mAuthorId, RsIdentityUsage(mServType,RsIdentityUsage::GROUP_ADMIN_SIGNATURE_CREATION, oldGrpMeta.mGroupId)) ;
mGixs->timeStampKey(newGrp.metaData->mAuthorId, RsIdentityUsage(RsServiceType(mServType),RsIdentityUsage::GROUP_ADMIN_SIGNATURE_CREATION, oldGrpMeta.mGroupId)) ;
return GxsSecurity::validateNxsGrp(newGrp, adminSign, keyMit->second) && latest;
}

View File

@ -215,7 +215,8 @@ bool RsGxsIntegrityCheck::check()
rsReputations->overallReputationLevel(
grp->metaData->mAuthorId ) >
RsReputationLevel::LOCALLY_NEGATIVE )
used_gxs_ids.insert(std::make_pair(grp->metaData->mAuthorId, RsIdentityUsage(mGenExchangeClient->serviceType(), RsIdentityUsage::GROUP_AUTHOR_KEEP_ALIVE,grp->grpId)));
used_gxs_ids.insert(std::make_pair(grp->metaData->mAuthorId, RsIdentityUsage(RsServiceType(mGenExchangeClient->serviceType()),
RsIdentityUsage::GROUP_AUTHOR_KEEP_ALIVE,grp->grpId)));
}
}
}
@ -404,7 +405,12 @@ bool RsGxsIntegrityCheck::check()
rsReputations->overallReputationLevel(
msg->metaData->mAuthorId ) >
RsReputationLevel::LOCALLY_NEGATIVE )
used_gxs_ids.insert(std::make_pair(msg->metaData->mAuthorId,RsIdentityUsage(mGenExchangeClient->serviceType(),RsIdentityUsage::MESSAGE_AUTHOR_KEEP_ALIVE,msg->metaData->mGroupId,msg->metaData->mMsgId))) ;
used_gxs_ids.insert(std::make_pair(msg->metaData->mAuthorId,RsIdentityUsage(RsServiceType(mGenExchangeClient->serviceType()),
RsIdentityUsage::MESSAGE_AUTHOR_KEEP_ALIVE,
msg->metaData->mGroupId,
msg->metaData->mMsgId,
msg->metaData->mParentId,
msg->metaData->mThreadId))) ;
}
}

View File

@ -976,7 +976,7 @@ void p3GxsTunnelService::handleRecvDHPublicKey(RsGxsTunnelDHPublicKeyItem *item)
std::cerr << "(SS) Signature was verified and it doesn't check! This is a security issue!" << std::endl;
return ;
}
mGixs->timeStampKey(item->signature.keyId,RsIdentityUsage(RS_SERVICE_TYPE_GXS_TUNNEL,RsIdentityUsage::GXS_TUNNEL_DH_SIGNATURE_CHECK));
mGixs->timeStampKey(item->signature.keyId,RsIdentityUsage(RsServiceType::GXS_TUNNEL,RsIdentityUsage::GXS_TUNNEL_DH_SIGNATURE_CHECK));
#ifdef DEBUG_GXS_TUNNEL
std::cerr << " Signature checks! Sender's ID = " << senders_id << std::endl;

View File

@ -234,33 +234,30 @@ struct RsIdentityUsage : RsSerializable
GXS_TUNNEL_DH_SIGNATURE_CHECK = 0x0c,
GXS_TUNNEL_DH_SIGNATURE_CREATION = 0x0d,
/// Identity received through GXS sync
IDENTITY_NEW_FROM_GXS_SYNC = 0x0e,
/// Group update on that identity data. Can be avatar, name, etc.
IDENTITY_DATA_UPDATE = 0x0e,
IDENTITY_NEW_FROM_DISCOVERY = 0x0f,
/// Explicit request to friend
IDENTITY_NEW_FROM_EXPLICIT_REQUEST = 0x10,
/// Any signature verified for that identity
IDENTITY_GENERIC_SIGNATURE_CHECK = 0x0f,
IDENTITY_GENERIC_SIGNATURE_CHECK = 0x11,
/// Any signature made by that identity
IDENTITY_GENERIC_SIGNATURE_CREATION = 0x10,
IDENTITY_GENERIC_SIGNATURE_CREATION = 0x12,
IDENTITY_GENERIC_ENCRYPTION = 0x11,
IDENTITY_GENERIC_DECRYPTION = 0x12,
CIRCLE_MEMBERSHIP_CHECK = 0x13
IDENTITY_GENERIC_ENCRYPTION = 0x13,
IDENTITY_GENERIC_DECRYPTION = 0x14,
CIRCLE_MEMBERSHIP_CHECK = 0x15
} ;
RS_DEPRECATED
RsIdentityUsage( uint16_t service, const RsIdentityUsage::UsageCode& code,
const RsGxsGroupId& gid = RsGxsGroupId(),
const RsGxsMessageId& mid = RsGxsMessageId(),
uint64_t additional_id=0,
const std::string& comment = std::string() );
RsIdentityUsage( RsServiceType service,
RsIdentityUsage::UsageCode code,
const RsGxsGroupId& gid = RsGxsGroupId(),
const RsGxsMessageId& mid = RsGxsMessageId(),
const RsGxsMessageId& pid = RsGxsMessageId(),
const RsGxsMessageId& tid = RsGxsMessageId(),
const RsGxsMessageId& message_id = RsGxsMessageId(),
const RsGxsMessageId& parent_id = RsGxsMessageId(),
const RsGxsMessageId& thread_id = RsGxsMessageId(),
uint64_t additional_id=0,
const std::string& comment = std::string() );

View File

@ -1468,7 +1468,7 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
rsPeers->getOnlineList(peers) ;
}
mIdentities->requestKey(pit->first, peers,RsIdentityUsage(serviceType(),RsIdentityUsage::CIRCLE_MEMBERSHIP_CHECK,RsGxsGroupId(cache.mCircleId)));
mIdentities->requestKey(pit->first, peers,RsIdentityUsage(RsServiceType::GXSCIRCLE,RsIdentityUsage::CIRCLE_MEMBERSHIP_CHECK,RsGxsGroupId(cache.mCircleId)));
all_ids_here = false;
}

View File

@ -641,7 +641,7 @@ void p3IdService::notifyChanges(std::vector<RsGxsNotify *> &changes)
rsEvents->postEvent(ev);
// also time_stamp the key that this group represents
timeStampKey(RsGxsId(gid),RsIdentityUsage(serviceType(),RsIdentityUsage::IDENTITY_DATA_UPDATE)) ;
timeStampKey(RsGxsId(gid),RsIdentityUsage(RsServiceType(serviceType()),RsIdentityUsage::IDENTITY_NEW_FROM_GXS_SYNC)) ;
should_subscribe = true;
}
break;
@ -654,7 +654,7 @@ void p3IdService::notifyChanges(std::vector<RsGxsNotify *> &changes)
rsEvents->postEvent(ev);
// also time_stamp the key that this group represents
timeStampKey(RsGxsId(gid),RsIdentityUsage(serviceType(),RsIdentityUsage::IDENTITY_DATA_UPDATE)) ;
timeStampKey(RsGxsId(gid),RsIdentityUsage(RsServiceType(serviceType()),RsIdentityUsage::IDENTITY_NEW_FROM_GXS_SYNC)) ;
should_subscribe = true;
}
break;
@ -1214,8 +1214,7 @@ bool p3IdService::requestIdentity(
return false;
}
RsIdentityUsage usageInfo( RsServiceType::GXSID,
RsIdentityUsage::IDENTITY_DATA_UPDATE );
RsIdentityUsage usageInfo( RsServiceType::GXSID, RsIdentityUsage::IDENTITY_NEW_FROM_EXPLICIT_REQUEST );
return requestKey(id, askPeersList, usageInfo);
}
@ -1360,7 +1359,7 @@ bool p3IdService::signData(const uint8_t *data,uint32_t data_size,const RsGxsId&
return false ;
}
error_status = RS_GIXS_ERROR_NO_ERROR ;
timeStampKey(own_gxs_id,RsIdentityUsage(serviceType(),RsIdentityUsage::IDENTITY_GENERIC_SIGNATURE_CREATION)) ;
timeStampKey(own_gxs_id,RsIdentityUsage(RsServiceType(serviceType()),RsIdentityUsage::IDENTITY_GENERIC_SIGNATURE_CREATION)) ;
return true ;
}
@ -1433,7 +1432,7 @@ bool p3IdService::encryptData( const uint8_t *decrypted_data,
return false ;
}
error_status = RS_GIXS_ERROR_NO_ERROR ;
timeStampKey(encryption_key_id,RsIdentityUsage(serviceType(),RsIdentityUsage::IDENTITY_GENERIC_ENCRYPTION)) ;
timeStampKey(encryption_key_id,RsIdentityUsage(RsServiceType::GXSID,RsIdentityUsage::IDENTITY_GENERIC_ENCRYPTION)) ;
return true ;
}
@ -1522,7 +1521,7 @@ bool p3IdService::encryptData( const uint8_t* decrypted_data,
{
timeStampKey( *it,
RsIdentityUsage(
serviceType(),
RsServiceType::GXSID,
RsIdentityUsage::IDENTITY_GENERIC_ENCRYPTION ) );
}
@ -1563,7 +1562,7 @@ bool p3IdService::decryptData( const uint8_t *encrypted_data,
error_status = RS_GIXS_ERROR_NO_ERROR;
timeStampKey( key_id,
RsIdentityUsage(
serviceType(),
RsServiceType::GXSID,
RsIdentityUsage::IDENTITY_GENERIC_DECRYPTION) );
return true ;
@ -1656,7 +1655,7 @@ bool p3IdService::decryptData( const uint8_t* encrypted_data,
{
timeStampKey( *it,
RsIdentityUsage(
serviceType(),
RsServiceType::GXSID,
RsIdentityUsage::IDENTITY_GENERIC_DECRYPTION ) );
}
@ -3223,7 +3222,7 @@ bool p3IdService::cachetest_handlerequest(uint32_t token)
if (!haveKey(*vit))
{
std::list<RsPeerId> nullpeers;
requestKey(*vit, nullpeers,RsIdentityUsage(serviceType(),RsIdentityUsage::UNKNOWN_USAGE));
requestKey(*vit, nullpeers,RsIdentityUsage(RsServiceType::GXSID,RsIdentityUsage::UNKNOWN_USAGE));
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cachetest_request() Requested Key Id: " << *vit;
@ -4840,42 +4839,6 @@ RsIdentityUsage::RsIdentityUsage(RsServiceType service, RsIdentityUsage::UsageCo
mHash = hs.hash();
}
RsIdentityUsage::RsIdentityUsage(
uint16_t service, const RsIdentityUsage::UsageCode& code,
const RsGxsGroupId& gid, const RsGxsMessageId& mid,
uint64_t additional_id,const std::string& comment ) :
mServiceId(static_cast<RsServiceType>(service)), mUsageCode(code),
mGrpId(gid), mMsgId(mid), mAdditionalId(additional_id), mComment(comment)
{
#ifdef DEBUG_IDS
std::cerr << "New identity usage: " << std::endl;
std::cerr << " service=" << std::hex << service << std::endl;
std::cerr << " code =" << std::hex << code << std::endl;
std::cerr << " grpId =" << std::hex << gid << std::endl;
std::cerr << " msgId =" << std::hex << mid << std::endl;
std::cerr << " add id =" << std::hex << additional_id << std::endl;
std::cerr << " commnt =\"" << std::hex << comment << "\"" << std::endl;
#endif
/* This is a hack, since it will hash also mHash, but because it is
* initialized to 0, and only computed in the constructor here, it should
* be ok. */
librs::crypto::HashStream hs(librs::crypto::HashStream::SHA1) ;
hs << (uint32_t)service ; // G10h4ck: Why uint32 if it's 16 bits?
hs << (uint8_t)code ;
hs << gid ;
hs << mid ;
hs << (uint64_t)additional_id ;
hs << comment ;
mHash = hs.hash();
#ifdef DEBUG_IDS
std::cerr << " hash =\"" << std::hex << mHash << "\"" << std::endl;
#endif
}
RsIdentityUsage::RsIdentityUsage() :
mServiceId(RsServiceType::NONE), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0)
{}

View File

@ -1864,7 +1864,8 @@ QString IdDialog::createUsageString(const RsIdentityUsage& u) const
case RsServiceType::FORUMS: service_name = tr("Forums") ; service_type = RetroShareLink::TYPE_FORUM ; break ;
case RsServiceType::POSTED: service_name = tr("Boards") ; service_type = RetroShareLink::TYPE_POSTED ; break ;
case RsServiceType::CHAT: service_name = tr("Chat") ; service_type = RetroShareLink::TYPE_CHAT_ROOM ; break ;
case RsServiceType::GXS_TRANS: service_name = tr("GxsMail"); service_type = RetroShareLink::TYPE_MESSAGE ; break ;
case RsServiceType::GXS_TRANS: return tr("GxsMail author ");
#ifdef TODO
// We need a RS link for circles if we want to do that.
//
@ -1895,10 +1896,17 @@ QString IdDialog::createUsageString(const RsIdentityUsage& u) const
{
RetroShareLink l;
std::cerr << "Signature validation/keep alive signature:" << std::endl;
std::cerr << " service ID = " << std::hex << (uint16_t)u.mServiceId << std::dec << std::endl;
std::cerr << " u.mGrpId = " << u.mGrpId << std::endl;
std::cerr << " u.mMsgId = " << u.mMsgId << std::endl;
std::cerr << " u.mParentId = " << u.mParentId << std::endl;
std::cerr << " u.mThreadId = " << u.mThreadId << std::endl;
if(service_type == RetroShareLink::TYPE_CHANNEL && !u.mThreadId.isNull())
l = RetroShareLink::createGxsMessageLink(service_type,u.mGrpId,u.mThreadId,tr("vote/comment"));
l = RetroShareLink::createGxsMessageLink(service_type,u.mGrpId,u.mThreadId,tr("Vote/comment"));
else if(service_type == RetroShareLink::TYPE_POSTED && !u.mThreadId.isNull())
l = RetroShareLink::createGxsMessageLink(service_type,u.mGrpId,u.mThreadId,tr("vote"));
l = RetroShareLink::createGxsMessageLink(service_type,u.mGrpId,u.mThreadId,tr("Vote"));
else
l = RetroShareLink::createGxsMessageLink(service_type,u.mGrpId,u.mMsgId,tr("Message"));
@ -1928,9 +1936,13 @@ QString IdDialog::createUsageString(const RsIdentityUsage& u) const
{
return tr("Signature in distant tunnel system.");
}
case RsIdentityUsage::IDENTITY_DATA_UPDATE: // Group update on that identity data. Can be avatar, name, etc.
case RsIdentityUsage::IDENTITY_NEW_FROM_GXS_SYNC: // Group update on that identity data. Can be avatar, name, etc.
{
return tr("Update of identity data.");
return tr("Received from GXS sync.");
}
case RsIdentityUsage::IDENTITY_NEW_FROM_DISCOVERY: // Own friend sended his own ids
{
return tr("Friend node identity received through discovery.");
}
case RsIdentityUsage::IDENTITY_GENERIC_SIGNATURE_CHECK: // Any signature verified for that identity
{