From ae0412c0877dfe5d066758246bf20146e7bf79e9 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Thu, 26 Sep 2019 23:12:26 +0200 Subject: [PATCH] sendMail check if recipients are known --- libretroshare/src/gxs/rsgixs.h | 2 ++ libretroshare/src/retroshare/rsidentity.h | 13 ++++++++-- libretroshare/src/retroshare/rsreputations.h | 3 ++- libretroshare/src/services/p3idservice.cc | 4 +++ libretroshare/src/services/p3idservice.h | 6 +++-- libretroshare/src/services/p3msgservice.cc | 27 ++++++++++++++++---- 6 files changed, 45 insertions(+), 10 deletions(-) diff --git a/libretroshare/src/gxs/rsgixs.h b/libretroshare/src/gxs/rsgixs.h index 76581fe4f..a7ab1db82 100644 --- a/libretroshare/src/gxs/rsgixs.h +++ b/libretroshare/src/gxs/rsgixs.h @@ -165,6 +165,8 @@ public: virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey& key) = 0; virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey& key) = 0; // For signing outgoing messages. virtual bool getIdDetails(const RsGxsId& id, RsIdentityDetails& details) = 0 ; // Proxy function so that we get p3Identity info from Gxs + + virtual ~RsGixs(); }; class GixsReputation diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index 5abdfb47b..cc5772e83 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -338,7 +338,7 @@ struct RsIdentityDetails : RsSerializable RS_SERIAL_PROCESS(mNickname); RS_SERIAL_PROCESS(mFlags); RS_SERIAL_PROCESS(mPgpId); - //RS_SERIAL_PROCESS(mReputation); + RS_SERIAL_PROCESS(mReputation); RS_SERIAL_PROCESS(mAvatar); RS_SERIAL_PROCESS(mPublishTS); RS_SERIAL_PROCESS(mLastUsageTS); @@ -352,7 +352,6 @@ struct RsIdentityDetails : RsSerializable struct RsIdentity : RsGxsIfaceHelper { explicit RsIdentity(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {} - virtual ~RsIdentity() {} /** * @brief Create a new identity @@ -419,6 +418,14 @@ struct RsIdentity : RsGxsIfaceHelper */ virtual bool getOwnPseudonimousIds(std::vector& ids) = 0; + /** + * @brief Check if an id is known + * @jsonapi{development} + * @param[in] id Id to check + * @return true if the id is known, false otherwise + */ + virtual bool isKnownId(const RsGxsId& id) = 0; + /** * @brief Check if an id is own * @jsonapi{development} @@ -568,4 +575,6 @@ struct RsIdentity : RsGxsIfaceHelper RS_DEPRECATED_FOR("getIdentitiesSummaries getIdentitiesInfo") virtual bool getGroupData( const uint32_t& token, std::vector& groups) = 0; + + virtual ~RsIdentity(); }; diff --git a/libretroshare/src/retroshare/rsreputations.h b/libretroshare/src/retroshare/rsreputations.h index 8ea6ff213..b8426e642 100644 --- a/libretroshare/src/retroshare/rsreputations.h +++ b/libretroshare/src/retroshare/rsreputations.h @@ -72,7 +72,6 @@ struct RsReputationInfo : RsSerializable mFriendsNegativeVotes(0), mFriendAverageScore(RS_REPUTATION_THRESHOLD_DEFAULT), mOverallReputationLevel(RsReputationLevel::NEUTRAL) {} - virtual ~RsReputationInfo() {} RsOpinion mOwnOpinion; @@ -94,6 +93,8 @@ struct RsReputationInfo : RsSerializable RS_SERIAL_PROCESS(mFriendAverageScore); RS_SERIAL_PROCESS(mOverallReputationLevel); } + + virtual ~RsReputationInfo(); }; diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 95adf0b96..b09f2b883 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -4788,3 +4788,7 @@ RsIdentityUsage::RsIdentityUsage( RsIdentityUsage::RsIdentityUsage() : mServiceId(RsServiceType::NONE), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0) {} + +RsIdentity::~RsIdentity() = default; +RsReputationInfo::~RsReputationInfo() = default; +RsGixs::~RsGixs() = default; diff --git a/libretroshare/src/services/p3idservice.h b/libretroshare/src/services/p3idservice.h index 4e22698b6..64e335ef5 100644 --- a/libretroshare/src/services/p3idservice.h +++ b/libretroshare/src/services/p3idservice.h @@ -298,7 +298,9 @@ public: //virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ; //virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list& peer_ids) ; - virtual bool isOwnId(const RsGxsId& key_id) ; + inline bool isKnownId(const RsGxsId& id) override { return haveKey(id); } + + bool isOwnId(const RsGxsId& key_id) override; virtual bool signData( const uint8_t* data, uint32_t data_size, @@ -619,7 +621,7 @@ private: bool ownIdsAreLoaded() { RS_STACK_MUTEX(mIdMtx); return mOwnIdsLoaded; } bool mAutoAddFriendsIdentitiesAsContacts; - uint32_t mMaxKeepKeysBanned ; + uint32_t mMaxKeepKeysBanned; RS_SET_CONTEXT_DEBUG_LEVEL(1) }; diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 80081b160..5d9bc90ee 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -1246,15 +1246,32 @@ uint32_t p3MsgService::sendMail( "You must specify at least one recipient" )) return false; auto dstCheck = - [&](const std::set& dstSet) + [&](const std::set& dstSet, const std::string& setName) { - for(const RsGxsId& dst: dstSet) if(dst.isNull()) return false; + for(const RsGxsId& dst: dstSet) + { + if(dst.isNull()) + { + errorMsg = setName + " contains a null recipient"; + RsErr() << fname << " " << errorMsg << std::endl; + return false; + } + + if(!rsIdentity->isKnownId(dst)) + { + rsIdentity->requestIdentity(dst); + errorMsg = setName + " contains an unknown recipient: " + + dst.toStdString(); + RsErr() << fname << " " << errorMsg << std::endl; + return false; + } + } return true; }; - if(!pCheck(dstCheck(to), "to contains a null recipient" )) return false; - if(!pCheck(dstCheck(cc), "cc contains a null recipient" )) return false; - if(!pCheck(dstCheck(bcc), "bcc contains a null recipient")) return false; + if(!dstCheck(to, "to")) return false; + if(!dstCheck(cc, "cc")) return false; + if(!dstCheck(bcc, "bcc")) return false; MessageInfo msgInfo;