From 3a58aa468f430f009d321f488533f3993b5ae9ef Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 10 Sep 2019 09:52:37 +0200 Subject: [PATCH] add special profile item for not yet validated peer from short invite --- libretroshare/src/retroshare/rspeers.h | 2 + libretroshare/src/rsserver/p3peers.cc | 5 ++ libretroshare/src/rsserver/p3peers.h | 2 + .../src/gui/common/FriendListModel.cpp | 52 +++++++++++++++++-- .../src/gui/common/FriendListModel.h | 4 ++ 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 696ca2de7..cb9f1ec27 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -505,6 +505,8 @@ public: virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list& ids) = 0; virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "") = 0; + virtual RsPgpId pgpIdFromFingerprint(const RsPgpFingerprint& fpr) = 0; + // Note: the two methods below could be unified. The fact that one of them can take an optional RsPeerDetails struct as parameter // seems quite inconsistent. diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 013f67e0d..c320c0260 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -670,6 +670,11 @@ bool p3Peers::gpgSignData(const void *data, const uint32_t len, unsigned char return AuthGPG::getAuthGPG()->SignDataBin(data,len,sign,signlen, reason); } +RsPgpId p3Peers::pgpIdFromFingerprint(const RsPgpFingerprint& fpr) +{ + return PGPHandler::pgpIdFromFingerprint(fpr); +} + bool p3Peers::getGPGDetails(const RsPgpId &pgp_id, RsPeerDetails &d) { #ifdef P3PEERS_DEBUG diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index 792348766..b5b8d09d5 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -91,6 +91,8 @@ public: virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list &ids); virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "") ; + virtual RsPgpId pgpIdFromFingerprint(const RsPgpFingerprint& fpr) override; + /* Add/Remove Friends */ virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT); diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index bbb3e7339..4c37b0927 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -36,7 +36,7 @@ #include "retroshare/rsexpr.h" #include "retroshare/rsmsgs.h" -//#define DEBUG_MESSAGE_MODEL +#define DEBUG_MODEL #define IS_MESSAGE_UNREAD(flags) (flags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)) @@ -728,7 +728,7 @@ void RsFriendListModel::checkInternalData(bool force) if(mLocations[i].last_update_ts + NODE_DETAILS_UPDATE_DELAY < now) { #ifdef DEBUG_MODEL - std::cerr << "Updating ID " << node.node_info.id << std::endl; + std::cerr << "Updating ID " << mLocations[i].node_info.id << std::endl; #endif RsPeerId id(mLocations[i].node_info.id); // this avoids zeroing the id field when writing the node data rsPeers->getPeerDetails(id,mLocations[i].node_info); @@ -973,6 +973,48 @@ RsFriendListModel::EntryType RsFriendListModel::getType(const QModelIndex& i) co return e.type; } +std::map::const_iterator RsFriendListModel::createInvalidatedProfile(const RsPgpFingerprint& fpr,std::map& pgp_indices,std::vector& mProfiles) +{ + RsPgpId pgp_id = rsPeers->pgpIdFromFingerprint(fpr); + + auto it2 = pgp_indices.find(pgp_id); + + if(it2 != pgp_indices.end()) + { + std::cerr << "(EE) asked to create an invalidated profile that already exists!" << std::endl; + return it2; + } + + HierarchicalProfileInformation hprof ; + + if(rsPeers->getGPGDetails(pgp_id,hprof.profile_info)) + { + std::cerr << "(EE) asked to create an invalidated profile that already exists!" << std::endl; + return it2; + } + + hprof.profile_info.isOnlyGPGdetail = true; + hprof.profile_info.gpg_id = pgp_id; + + hprof.profile_info.name = tr("Profile ID ").toStdString() + pgp_id.toStdString() + tr(" (Not yet validated)").toStdString(); + hprof.profile_info.issuer = pgp_id; + + hprof.profile_info.fpr = fpr; /* pgp fingerprint */ + + hprof.profile_info.trustLvl = 0; + hprof.profile_info.validLvl = 0; + + pgp_indices[pgp_id] = mProfiles.size(); + mProfiles.push_back(hprof); + + it2 = pgp_indices.find(pgp_id); + +#ifdef DEBUG_MODEL + RsDbg() << " Creating invalidated profile pgp id = " << pgp_id << " (" << hprof.profile_info.name << ") and fingerprint " << fpr << std::endl; +#endif + return it2; +} + std::map::const_iterator RsFriendListModel::checkProfileIndex(const RsPgpId& pgp_id,std::map& pgp_indices,std::vector& mProfiles,bool create) { auto it2 = pgp_indices.find(pgp_id); @@ -1042,7 +1084,11 @@ void RsFriendListModel::updateInternalData() auto it2 = checkProfileIndex(hnode.node_info.gpg_id,pgp_indices,mProfiles,hnode.node_info.gpg_id == rsPeers->getGPGOwnId()); if(it2 == pgp_indices.end()) - continue; + { + // This peer's pgp key hasn't been validated yet. We list such peers at the end. + + it2 = createInvalidatedProfile(hnode.node_info.fpr,pgp_indices,mProfiles); + } mProfiles[it2->second].child_node_indices.push_back(mLocations.size()); mLocations.push_back(hnode); diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index 9ff26391e..c3df062cd 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -164,6 +164,10 @@ private: std::vector& mProfiles, bool create); + std::map::const_iterator createInvalidatedProfile(const RsPgpFingerprint& pgp_id, + std::map& pgp_indices, + std::vector& mProfiles); + QVariant sizeHintRole (const EntryIndex& e, int col) const; QVariant displayRole (const EntryIndex& e, int col) const; QVariant decorationRole(const EntryIndex& e, int col) const;