From 720d5ea8a6f1ccca2f492aac1c84404beeccc92a Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Mon, 13 May 2019 00:11:54 +0200 Subject: [PATCH 01/45] Implement libretroshare short invites support --- .../src/gossipdiscovery/p3gossipdiscovery.cc | 19 +- libretroshare/src/pqi/authssl.cc | 11 +- libretroshare/src/pqi/p3peermgr.cc | 77 +++++- libretroshare/src/pqi/p3peermgr.h | 9 + libretroshare/src/pqi/p3servicecontrol.cc | 8 + libretroshare/src/pqi/pqissl.cc | 11 +- libretroshare/src/pqi/pqissllistener.cc | 11 +- libretroshare/src/retroshare/rsevents.h | 3 + libretroshare/src/retroshare/rspeers.h | 83 ++++++- libretroshare/src/rsserver/p3peers.cc | 225 +++++++++++++++++- libretroshare/src/rsserver/p3peers.h | 19 ++ 11 files changed, 457 insertions(+), 19 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index e50073945..0c2a8fb0d 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -27,6 +27,7 @@ #include "retroshare/rsiface.h" #include "rsserver/p3face.h" #include "util/rsdebug.h" +#include "retroshare/rspeers.h" /**** * #define P3DISC_DEBUG 1 @@ -1249,9 +1250,25 @@ void p3discovery2::recvInvite( void p3discovery2::rsEventsHandler(const RsEvent& event) { + Dbg3() << __PRETTY_FUNCTION__ << " " << static_cast(event.mType) + << std::endl; + switch(event.mType) { - // TODO: When an SSL-only friend become online requestInvite(...) + case RsEventType::PEER_STATE_CHANGED: + { + const RsPeerId& sslId = + static_cast(event).mSslId; + if( rsPeers && rsPeers->isSslOnlyFriend(sslId) && + mServiceCtrl->isPeerConnected( + getServiceInfo().mServiceType, sslId ) ) + { + if(!requestInvite(sslId, sslId)) + RsErr() << __PRETTY_FUNCTION__ << " requestInvite to peer " + << sslId << " failed" << std::endl; + } + break; + } default: break; } } diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 5d56b3843..1a9648300 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1196,6 +1196,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) std::string sslCn = RsX509Cert::getCertIssuerString(*x509Cert); RsPgpId pgpId(sslCn); + if(sslId.isNull()) { std::string errMsg = "x509Cert has invalid sslId!"; @@ -1231,8 +1232,10 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } + bool isSslOnlyFriend = rsPeers->isSslOnlyFriend(sslId); + uint32_t auth_diagnostic; - if(!AuthX509WithGPG(x509Cert, auth_diagnostic)) + if(!isSslOnlyFriend && !AuthX509WithGPG(x509Cert, auth_diagnostic)) { std::string errMsg = "Certificate was rejected because PGP " "signature verification failed with diagnostic: " @@ -1255,7 +1258,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } - if ( pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && + if ( !isSslOnlyFriend && pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) ) { std::string errMsg = "Connection attempt signed by PGP key id: " + @@ -1279,7 +1282,9 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) setCurrentConnectionAttemptInfo(pgpId, sslId, sslCn); LocalStoreCert(x509Cert); - Dbg1() << __PRETTY_FUNCTION__ << " authentication successfull!" << std::endl; + RsInfo() << __PRETTY_FUNCTION__ << " authentication successfull for " + << "sslId: " << sslId << " isSslOnlyFriend: " << isSslOnlyFriend + << std::endl; if(rsEvents) { diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index f3d8b08f2..a4960f7c4 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1029,6 +1029,73 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg return true; } + +bool p3PeerMgrIMPL::addSslOnlyFriend( + const RsPeerId& sslId, const RsPeerDetails& dt ) +{ + if(sslId.isNull() || sslId == getOwnId()) return false; + + peerState pstate; + + { RS_STACK_MUTEX(mPeerMtx); + + /* If in mOthersList -> move over */ + auto it = mOthersList.find(sslId); + if (it != mOthersList.end()) + { + pstate = it->second; + mOthersList.erase(it); + } + + } // RS_STACK_MUTEX(mPeerMtx); + + pstate.id = sslId; + + if(!dt.name.empty()) pstate.name = dt.name; + if(!dt.dyndns.empty()) pstate.dyndns = dt.dyndns; + pstate.hiddenNode = dt.isHiddenNode; + if(!dt.hiddenNodeAddress.empty()) + pstate.hiddenDomain = dt.hiddenNodeAddress; + if(dt.hiddenNodePort) pstate.hiddenPort = dt.hiddenNodePort; + if(dt.hiddenType) pstate.hiddenType = dt.hiddenType; + if(!dt.location.empty()) pstate.location = dt.location; + + { RS_STACK_MUTEX(mPeerMtx); + + mFriendList[sslId] = pstate; + mStatusChanged = true; + + } // RS_STACK_MUTEX(mPeerMtx); + + IndicateConfigChanged(); + mLinkMgr->addFriend(sslId, dt.vs_dht != RS_VS_DHT_OFF); + + // To update IP addresses is much more confortable to use locators + if(!dt.isHiddenNode) + { + for(const std::string& locator : dt.ipAddressList) + addPeerLocator(sslId, locator); + + if(dt.extPort && !dt.extAddr.empty()) + { + RsUrl locator; + locator.setScheme("ipv4").setHost(dt.extAddr) + .setPort(dt.extPort); + addPeerLocator(sslId, locator); + } + + if(dt.localPort && !dt.localAddr.empty()) + { + RsUrl locator; + locator.setScheme("ipv4").setHost(dt.localAddr) + .setPort(dt.localPort); + addPeerLocator(sslId, locator); + } + } + + return true; +} + bool p3PeerMgrIMPL::removeFriend(const RsPgpId &id) { #ifdef PEER_DEBUG @@ -2344,7 +2411,15 @@ bool p3PeerMgrIMPL::loadList(std::list& load) #endif /* ************* */ // permission flags is used as a mask for the existing perms, so we set it to 0xffff - addFriend(peer_id, peer_pgp_id, pitem->netMode, pitem->vs_disc, pitem->vs_dht, pitem->lastContact, RS_NODE_PERM_ALL); + if(!addFriend( peer_id, peer_pgp_id, pitem->netMode, + pitem->vs_disc, pitem->vs_dht, + pitem->lastContact, RS_NODE_PERM_ALL )) + { + RsInfo() << __PRETTY_FUNCTION__ << " loading SSL-only " + << "friend: " << peer_id << " " << pitem->location + << std::endl; + addSslOnlyFriend(peer_id); + } setLocation(pitem->nodePeerId, pitem->location); } diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 781dd6115..260864cd6 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -127,6 +127,10 @@ public: rstime_t lastContact = 0, ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT) ) = 0; + virtual bool addSslOnlyFriend( + const RsPeerId& sslId, + const RsPeerDetails& details = RsPeerDetails() ) = 0; + virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId) = 0; virtual bool isFriend(const RsPeerId& ssl_id) = 0; @@ -242,6 +246,11 @@ public: virtual bool addFriend(const RsPeerId&ssl_id, const RsPgpId&gpg_id, uint32_t netMode = RS_NET_MODE_UDP, uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL, rstime_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT)); + + bool addSslOnlyFriend( + const RsPeerId& sslId, + const RsPeerDetails& details = RsPeerDetails() ) override; + virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId); virtual bool removeFriend(const RsPgpId &pgp_id); diff --git a/libretroshare/src/pqi/p3servicecontrol.cc b/libretroshare/src/pqi/p3servicecontrol.cc index 23dcaf747..d361f25bd 100644 --- a/libretroshare/src/pqi/p3servicecontrol.cc +++ b/libretroshare/src/pqi/p3servicecontrol.cc @@ -28,6 +28,8 @@ #include "rsitems/rsnxsitems.h" #include "pqi/p3cfgmgr.h" #include "pqi/pqiservice.h" +#include "retroshare/rspeers.h" +#include "retroshare/rsevents.h" /*******************************/ // #define SERVICECONTROL_DEBUG 1 @@ -756,6 +758,12 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId) mPeerFilterMap[peerId] = peerFilter; } recordFilterChanges_locked(peerId, originalFilter, peerFilter); + + using Evt_t = RsPeerStateChangedEvent; + std::shared_ptr lockedRsEvents = rsEvents; + if(lockedRsEvents) + lockedRsEvents->postEvent(std::unique_ptr(new Evt_t(peerId))); + return true; } diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 16fd78cc9..8a3d49901 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -35,7 +35,7 @@ #include "pqi/pqissllistener.h" #include "pqi/p3linkmgr.h" -#include +#include "retroshare/rspeers.h" #include #include @@ -1180,10 +1180,13 @@ int pqissl::Authorise_SSL_Connection() /* At this point the actual connection authentication has already been * performed in AuthSSL::VerifyX509Callback, any furter authentication check - * like the following two are redundant. */ + * like the followings are redundant. */ + + bool isSslOnlyFriend = rsPeers->isSslOnlyFriend(certPeerId); uint32_t authErrCode = 0; - if(!AuthSSL::instance().AuthX509WithGPG(peercert, authErrCode)) + if( !isSslOnlyFriend && + !AuthSSL::instance().AuthX509WithGPG(peercert, authErrCode) ) { RsFatal() << __PRETTY_FUNCTION__ << " failure verifying peer " << "certificate signature. This should never happen at this " @@ -1195,7 +1198,7 @@ int pqissl::Authorise_SSL_Connection() } RsPgpId pgpId = RsX509Cert::getCertIssuer(*peercert); - if( pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && + if( !isSslOnlyFriend && pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) ) { RsFatal() << __PRETTY_FUNCTION__ << " pgpId: " << pgpId diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index d1a9e31a9..e295a7784 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -784,10 +784,13 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info) #ifdef RS_PQISSL_AUTH_DOUBLE_CHECK /* At this point the actual connection authentication has already been * performed in AuthSSL::VerifyX509Callback, any furter authentication check - * like the following two are redundant. */ + * like the followings are redundant. */ + + bool isSslOnlyFriend = rsPeers->isSslOnlyFriend(newPeerId); uint32_t authErrCode = 0; - if(!AuthSSL::instance().AuthX509WithGPG(peercert, authErrCode)) + if( !isSslOnlyFriend && + !AuthSSL::instance().AuthX509WithGPG(peercert, authErrCode) ) { RsFatal() << __PRETTY_FUNCTION__ << " failure verifying peer " << "certificate signature. This should never happen at this " @@ -798,7 +801,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info) exit(failure); } - if( pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && + if( !isSslOnlyFriend && pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) ) { RsFatal() << __PRETTY_FUNCTION__ << " pgpId: " << pgpId @@ -822,7 +825,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info) else ++it; } - if (found == false) + if (!found) { Dbg1() << __PRETTY_FUNCTION__ << " got secure connection from address: " << info.addr << " with previously unknown SSL certificate: " diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 94ae866f8..869e5d2d6 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -63,6 +63,9 @@ enum class RsEventType : uint32_t /// @see RsGxsChanges GXS_CHANGES = 5, + /// Emitted when a peer state changes, @see RsPeers + PEER_STATE_CHANGED = 6, + MAX /// Used to detect invalid event type passed }; diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index ab5404859..7f1551f69 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -31,6 +31,7 @@ #include "util/rsurl.h" #include "util/rsdeprecate.h" #include "util/rstime.h" +#include "retroshare/rsevents.h" class RsPeers; @@ -358,6 +359,23 @@ struct RsGroupInfo : RsSerializable } }; +/** Event emitted when a peer change state */ +struct RsPeerStateChangedEvent : RsEvent +{ + /// @param[in] sslId is of the peer which changed state + RsPeerStateChangedEvent(RsPeerId sslId); + + /// Storage fot the id of the peer that changed state + RsPeerId mSslId; + + void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mSslId); + } +}; + /** The Main Interface Class - for information about your Peers * A peer is another RS instance, means associated with an SSL certificate * A same GPG person can have multiple peer running with different SSL certs @@ -434,6 +452,16 @@ public: */ virtual bool isPgpFriend(const RsPgpId& pgpId) = 0; + /** + * @brief Check if given peer is a trusted SSL node pending PGP approval + * Peers added through short invite remain in this state as long as their + * PGP key is not received and verified/approved by the user. + * @jsonapi{development} + * @param[in] sslId id of the peer to check + * @return true if the node is trusted, false otherwise + */ + virtual bool isSslOnlyFriend(const RsPeerId& sslId) = 0; + virtual std::string getPeerName(const RsPeerId &ssl_id) = 0; virtual std::string getGPGName(const RsPgpId& gpg_id) = 0; @@ -474,8 +502,24 @@ public: * @param[in] flags service permissions flag * @return false if error occurred, true otherwise */ - virtual bool addFriend( const RsPeerId &sslId, const RsPgpId& gpgId, - ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT ) = 0; + virtual bool addFriend( + const RsPeerId& sslId, const RsPgpId& gpgId, + ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT ) = 0; + + /** + * @brief Add SSL-only trusted node + * When adding an SSL-only node, it is authorized to connect. Every time a + * connection is established the user is notified about the need to verify + * the PGP fingerprint, until she does, at that point the node become a full + * SSL+PGP friend. + * @jsonapi{development} + * @param[in] sslId SSL id of the node to add + * @param[in] details Optional extra details known about the node to add + * @return false if error occurred, true otherwise + */ + virtual bool addSslOnlyFriend( + const RsPeerId& sslId, + const RsPeerDetails& details = RsPeerDetails() ) = 0; /** * @brief Revoke connection trust from to node @@ -597,6 +641,38 @@ public: bool includeSignatures = false, bool includeExtraLocators = true ) = 0; + /** + * @brief Get RetroShare short invite of the given peer + * @jsonapi{development} + * @param[out] invite storage for the generated invite + * @param[in] sslId Id of the peer of which we want to generate an invite, + * a null id (all 0) is passed, an invite for own node is returned. + * @param[in] formatRadix true to get in base64 format false to get URL. + * @param[in] bareBones true to get smallest invite, which miss also + * the information necessary to attempt an outgoing connection, but still + * enough to accept an incoming one. + * @param[in] baseUrl URL into which to sneak in the RetroShare invite + * radix, this is primarly useful to trick other applications into making + * the invite clickable, or to disguise the RetroShare invite into a + * "normal" looking web link. Used only if formatRadix is false. + * @return false if error occurred, true otherwise + */ + virtual bool getShortInvite( + std::string& invite, const RsPeerId& sslId = RsPeerId(), + bool formatRadix = false, bool bareBones = false, + const std::string& baseUrl = "https://retroshare.me/" ) = 0; + + /** + * @brief Parse the give short invite to extract contained information + * @jsonapi{development} + * @param[in] invite string containing the short invite to parse + * @param[out] details storage for the extracted information, consider it + * valid only if the function return true + * @return false if error occurred, true otherwise + */ + virtual bool parseShortInvite( + const std::string& invite, RsPeerDetails& details ) = 0; + /** * @brief Add trusted node from invite * @jsonapi{development} @@ -749,6 +825,3 @@ public: RS_DEPRECATED_FOR(isPgpFriend) virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend) = 0; }; - - - diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index ddab5fabf..64e94d973 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -570,6 +570,9 @@ std::string p3Peers::getGPGName(const RsPgpId &gpg_id) bool p3Peers::isPgpFriend(const RsPgpId& pgpId) { return AuthGPG::getAuthGPG()->isGPGAccepted(pgpId); } +bool p3Peers::isSslOnlyFriend(const RsPeerId& sslId) +{ return isFriend(sslId) && !isPgpFriend(getGPGId(sslId)); } + bool p3Peers::isGPGAccepted(const RsPgpId &gpg_id_is_friend) { return isPgpFriend(gpg_id_is_friend); } @@ -749,6 +752,10 @@ bool p3Peers::addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePe return mPeerMgr->addFriend(ssl_id, gpg_id, RS_NET_MODE_UDP, RS_VS_DISC_FULL, RS_VS_DHT_FULL, now, perm_flags); } +bool p3Peers::addSslOnlyFriend( + const RsPeerId& sslId, const RsPeerDetails& details ) +{ return mPeerMgr->addSslOnlyFriend(sslId, details); } + bool p3Peers::removeKeysFromPGPKeyring(const std::set& pgp_ids,std::string& backup_file,uint32_t& error_code) { return AuthGPG::getAuthGPG()->removeKeysFromPGPKeyring(pgp_ids,backup_file,error_code) ; @@ -1104,6 +1111,221 @@ bool p3Peers::GetPGPBase64StringAndCheckSum( const RsPgpId& gpg_id, return true ; } +enum class RsShortInviteFieldType : uint8_t +{ + SSL_ID = 0x00, + PEER_NAME = 0x01, + LOCATOR = 0x02, + + /* The following will be deprecated, and ported to LOCATOR when generic + * trasport layer will be implemented */ + HIDDEN_LOCATOR = 0x90, + DNS_LOCATOR = 0x91, + EXT4_LOCATOR = 0x92, +}; + +bool p3Peers::getShortInvite( + std::string& invite, const RsPeerId& _sslId, bool formatRadix, + bool bareBones, const std::string& baseUrl ) +{ + RsPeerId sslId = _sslId; + if(sslId.isNull()) sslId = getOwnId(); + + RsPeerDetails tDetails; + if(!getPeerDetails(sslId, tDetails)) return false; + + std::vector inviteBuf(1000, 0); + RsGenericSerializer::SerializeContext ctx( + inviteBuf.data(), static_cast(inviteBuf.size())); + RsGenericSerializer::SerializeJob j = RsGenericSerializer::SERIALIZE; + + RsShortInviteFieldType tType = RsShortInviteFieldType::SSL_ID; + RS_SERIAL_PROCESS(tType); + RS_SERIAL_PROCESS(sslId); + + tType = RsShortInviteFieldType::PEER_NAME; + RS_SERIAL_PROCESS(tType); + RS_SERIAL_PROCESS(tDetails.name); + + if(!bareBones) + { + /* If is hidden use hidden address and port as locator, else if we have + * a valid dyndns and extPort use that as locator, else if we have a + * valid extAddr and extPort use that as locator, otherwise use most + * recently known locator */ + sockaddr_storage tExt; + if(tDetails.isHiddenNode) + { + tType = RsShortInviteFieldType::HIDDEN_LOCATOR; + RS_SERIAL_PROCESS(tType); + RS_SERIAL_PROCESS(tDetails.hiddenType); + RS_SERIAL_PROCESS(tDetails.hiddenNodeAddress); + RS_SERIAL_PROCESS(tDetails.hiddenNodePort); + } + else if( !tDetails.dyndns.empty() && + (tDetails.extPort || tDetails.localPort) ) + { + uint16_t tPort = tDetails.extPort ? + tDetails.extPort : tDetails.localPort; + tType = RsShortInviteFieldType::DNS_LOCATOR; + RS_SERIAL_PROCESS(tType); + RS_SERIAL_PROCESS(tDetails.dyndns); + RS_SERIAL_PROCESS(tPort); + } + else if( sockaddr_storage_inet_pton(tExt, tDetails.extAddr) && + sockaddr_storage_isValidNet(tExt) && + sockaddr_storage_ipv6_to_ipv4(tExt) && + tDetails.extPort ) + { + uint32_t t4Addr = + reinterpret_cast(tExt).sin_addr.s_addr; + + tType = RsShortInviteFieldType::EXT4_LOCATOR; + RS_SERIAL_PROCESS(tType); + RS_SERIAL_PROCESS(t4Addr); + RS_SERIAL_PROCESS(tDetails.extPort); + } + else if(!tDetails.ipAddressList.empty()) + { + const std::string& tLc = tDetails.ipAddressList.front(); + std::string tLocator = tLc.substr(0, tLc.find_first_of(" ")-1); + tType = RsShortInviteFieldType::LOCATOR; + RS_SERIAL_PROCESS(tType); + RS_SERIAL_PROCESS(tLocator); + } + } + + Radix64::encode(ctx.mData, static_cast(ctx.mOffset), invite); + + if(!formatRadix) + { + RsUrl inviteUrl(baseUrl); + inviteUrl.setQueryKV("rsInvite", invite); + invite = inviteUrl.toString(); + } + + return ctx.mOk; +} + +bool p3Peers::parseShortInvite( + const std::string& inviteStrUrl, RsPeerDetails& details ) +{ + if(inviteStrUrl.empty()) + { + RsErr() << __PRETTY_FUNCTION__ << " can't parse empty invite" + << std::endl; + return false; + } + + const std::string* rsInvite = &inviteStrUrl; + + RsUrl inviteUrl(inviteStrUrl); + if(inviteUrl.hasQueryK("rsInvite")) + rsInvite = inviteUrl.getQueryV("rsInvite"); + + std::vector inviteBuf = Radix64::decode(*rsInvite); + RsGenericSerializer::SerializeContext ctx( + inviteBuf.data(), static_cast(inviteBuf.size())); + RsGenericSerializer::SerializeJob j = RsGenericSerializer::DESERIALIZE; + + while(ctx.mOk && ctx.mOffset < ctx.mSize) + { + RsShortInviteFieldType fieldType; + RS_SERIAL_PROCESS(fieldType); + + if(!ctx.mOk) + { + RsWarn() << __PRETTY_FUNCTION__ << " failed to parse fieldType" + << std::endl; + break; + } + + switch (fieldType) + { + case RsShortInviteFieldType::SSL_ID: + RS_SERIAL_PROCESS(details.id); + break; + case RsShortInviteFieldType::PEER_NAME: + RS_SERIAL_PROCESS(details.name); + break; + case RsShortInviteFieldType::LOCATOR: + { + std::string locatorStr; + RS_SERIAL_PROCESS(locatorStr); + if(ctx.mOk) details.ipAddressList.push_back(locatorStr); + else RsWarn() << __PRETTY_FUNCTION__ << " failed to parse locator" + << std::endl; + break; + } + case RsShortInviteFieldType::DNS_LOCATOR: + RS_SERIAL_PROCESS(details.dyndns); + if(!ctx.mOk) + { + RsWarn() << __PRETTY_FUNCTION__ << " failed to parse DNS " + << "locator host" << std::endl; + break; + } + + RS_SERIAL_PROCESS(details.extPort); + if(!ctx.mOk) RsWarn() << __PRETTY_FUNCTION__ << " failed to parse " + << "DNS locator port" << std::endl; + + break; + + case RsShortInviteFieldType::EXT4_LOCATOR: + { + sockaddr_in tExtAddr; + RS_SERIAL_PROCESS(tExtAddr.sin_addr.s_addr); + if(!ctx.mOk) + { + RsWarn() << __PRETTY_FUNCTION__ << " failed to parse IPv4" + << std::endl; + break; + } + details.extAddr = rs_inet_ntoa(tExtAddr.sin_addr); + + RS_SERIAL_PROCESS(details.extPort); + if(!ctx.mOk) + RsWarn() << __PRETTY_FUNCTION__ << " failed to parse extPort" + << std::endl; + + break; + } + + case RsShortInviteFieldType::HIDDEN_LOCATOR: + RS_SERIAL_PROCESS(details.hiddenType); + if(!ctx.mOk) + { + RsWarn() << __PRETTY_FUNCTION__ << " failed to parse hiddenType" + << std::endl; + break; + } + + RS_SERIAL_PROCESS(details.hiddenNodeAddress); + if(!ctx.mOk) + { + RsWarn() << __PRETTY_FUNCTION__ << " failed to parse " + << "hiddenNodeAddress" << std::endl; + break; + } + + RS_SERIAL_PROCESS(details.hiddenNodePort); + if(!ctx.mOk) RsWarn() << __PRETTY_FUNCTION__ << " failed to parse " + << "hiddenNodePort" << std::endl; + + break; + + default: + RsWarn() << __PRETTY_FUNCTION__ << " got unkown field type: " + << static_cast(fieldType) << std::endl; + break; + } + } + + + return ctx.mOk; +} + bool p3Peers::acceptInvite( const std::string& invite, ServicePermissionFlags flags ) { @@ -1503,4 +1725,5 @@ void p3Peers::setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermi mPeerMgr->setServicePermissionFlags(gpg_id,flags) ; } - +RsPeerStateChangedEvent::RsPeerStateChangedEvent(RsPeerId sslId) : + RsEvent(RsEventType::PEER_STATE_CHANGED), mSslId(sslId) {} diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index a44fb4142..c6bc82704 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -69,6 +69,9 @@ public: virtual bool isFriend(const RsPeerId &id); virtual bool isPgpFriend(const RsPgpId& pgpId); + /// @see RsPeers + bool isSslOnlyFriend(const RsPeerId& sslId) override; + RS_DEPRECATED_FOR(isPgpFriend) virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend); @@ -90,6 +93,12 @@ public: /* Add/Remove Friends */ virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT); + + /// @see RsPeers + bool addSslOnlyFriend( + const RsPeerId& sslId, + const RsPeerDetails& details = RsPeerDetails() ) override; + virtual bool removeFriend(const RsPgpId& gpgid); virtual bool removeFriendLocation(const RsPeerId& sslId); @@ -128,6 +137,16 @@ public: virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum); + /// @see RsPeers + bool getShortInvite( + std::string& invite, const RsPeerId& sslId = RsPeerId(), + bool formatRadix = false, bool bareBones = false, + const std::string& baseUrl = "https://retroshare.me/" ) override; + + /// @see RsPeers + bool parseShortInvite( + const std::string& invite, RsPeerDetails& details ) override; + /// @see RsPeers::acceptInvite virtual bool acceptInvite( const std::string& invite, From bde6235758a1ebe15f2f5cd2d9fab6c423fda100 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Mon, 13 May 2019 09:52:30 +0200 Subject: [PATCH 02/45] Fix windows compilation --- libretroshare/src/rsserver/p3peers.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 64e94d973..2c1d7a7d5 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1274,14 +1274,16 @@ bool p3Peers::parseShortInvite( case RsShortInviteFieldType::EXT4_LOCATOR: { - sockaddr_in tExtAddr; - RS_SERIAL_PROCESS(tExtAddr.sin_addr.s_addr); + uint32_t t4Addr = 0; + RS_SERIAL_PROCESS(t4Addr); if(!ctx.mOk) { RsWarn() << __PRETTY_FUNCTION__ << " failed to parse IPv4" << std::endl; break; } + sockaddr_in tExtAddr; + tExtAddr.sin_addr.s_addr = t4Addr; details.extAddr = rs_inet_ntoa(tExtAddr.sin_addr); RS_SERIAL_PROCESS(details.extPort); From 56e591f7289ccfb2daca0a2b5c51a7e6ad1d6562 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 22 May 2019 21:46:11 +0200 Subject: [PATCH 03/45] added a flag in peerState specific to short invites, and several checks for consistency --- libretroshare/src/pqi/p3peermgr.cc | 73 ++++++++++++++++++++++----- libretroshare/src/pqi/p3peermgr.h | 10 ++++ libretroshare/src/rsserver/p3peers.cc | 15 +++++- libretroshare/src/util/rsthreads.cc | 6 +++ 4 files changed, 91 insertions(+), 13 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 676247c99..62191499c 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -89,7 +89,7 @@ static const std::string kConfigKeyProxyServerPortI2P = "PROXY_SERVER_PORT_I2P"; void printConnectState(std::ostream &out, peerState &peer); peerState::peerState() - :netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0), + :skip_pgp_signature_validation(false),netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0), hiddenNode(false), hiddenPort(0), hiddenType(RS_HIDDEN_TYPE_NONE) { sockaddr_storage_clear(localaddr); @@ -338,17 +338,31 @@ bool p3PeerMgrIMPL::isFriend(const RsPeerId& id) #ifdef PEER_DEBUG_COMMON std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") called" << std::endl; #endif - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + RS_STACK_MUTEX(mPeerMtx); bool ret = (mFriendList.end() != mFriendList.find(id)); #ifdef PEER_DEBUG_COMMON std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") returning : " << ret << std::endl; #endif return ret; } +bool p3PeerMgrIMPL::isSslOnlyFriend(const RsPeerId& id) +{ +#ifdef PEER_DEBUG_COMMON + std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") called" << std::endl; +#endif + RS_STACK_MUTEX(mPeerMtx); + auto it = mFriendList.find(id); + bool ret = it != mFriendList.end() && it->second.skip_pgp_signature_validation ; + +#ifdef PEER_DEBUG_COMMON + std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") returning : " << ret << std::endl; +#endif + return ret; +} bool p3PeerMgrIMPL::getPeerName(const RsPeerId &ssl_id, std::string &name) { - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + RS_STACK_MUTEX(mPeerMtx); /* check for existing */ std::map::iterator it; @@ -915,9 +929,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg if (id == AuthSSL::getAuthSSL()->OwnId()) { -#ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::addFriend() cannot add own id as a friend." << std::endl; -#endif + RsErr() << "p3PeerMgrIMPL::addFriend() cannot add own id as a friend. That's a bug!" << std::endl; /* (1) already exists */ return false; } @@ -937,8 +949,19 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg #ifdef PEER_DEBUG std::cerr << "p3PeerMgrIMPL::addFriend() Already Exists" << std::endl; #endif - /* (1) already exists */ - return true; + if(it->second.gpg_id.isNull()) // already exists as a SSL-only friend + { + it->second.gpg_id = input_gpg_id; + it->second.skip_pgp_signature_validation = false; + return true; + } + else if(it->second.gpg_id != input_gpg_id)// already exists as a friend with a different PGP id!! + { + RsErr() << "Trying to add SSL id (" << id << ") that is already a friend with existing PGP key (" << it->second.gpg_id << ") but using a different PGP key (" << input_gpg_id << "). This is a bug!" << std::endl; + return false; + } + else + return true; /* (1) already exists */ } //Authentication is now tested at connection time, we don't store the ssl cert anymore @@ -973,6 +996,15 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg it->second.netMode = netMode; it->second.lastcontact = lastContact; + if(!it->second.gpg_id.isNull() && it->second.gpg_id != input_gpg_id)// already exists as a friend with a different PGP id!! + { + RsErr() << "Trying to add SSL id (" << id << ") that is already known (but not friend) with existing PGP key (" << it->second.gpg_id << ") but using a different PGP key (" << input_gpg_id << "). This is a bug!" << std::endl; + return false; + } + + it->second.gpg_id = input_gpg_id; + it->second.skip_pgp_signature_validation = false; + mStatusChanged = true; notifyLinkMgr = true; @@ -997,6 +1029,9 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg pstate.netMode = netMode; pstate.lastcontact = lastContact; + it->second.gpg_id = input_gpg_id; + it->second.skip_pgp_signature_validation = false; + /* addr & timestamps -> auto cleared */ mFriendList[id] = pstate; @@ -1030,14 +1065,18 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg } -bool p3PeerMgrIMPL::addSslOnlyFriend( - const RsPeerId& sslId, const RsPeerDetails& dt ) +bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPeerDetails& dt ) { - if(sslId.isNull() || sslId == getOwnId()) return false; + if(sslId.isNull() || sslId == getOwnId()) + { + RsErr() <<"Attempt to add yourself or a null ID as SSL-only friend (id=" << sslId << ")" << std::endl; + return false; + } peerState pstate; - { RS_STACK_MUTEX(mPeerMtx); + { + RS_STACK_MUTEX(mPeerMtx); /* If in mOthersList -> move over */ auto it = mOthersList.find(sslId); @@ -1047,8 +1086,16 @@ bool p3PeerMgrIMPL::addSslOnlyFriend( mOthersList.erase(it); } + } // RS_STACK_MUTEX(mPeerMtx); + if(!pstate.gpg_id.isNull() && AuthGPG::getAuthGPG()->isGPGAccepted(pstate.gpg_id)) + { + RsErr() << "Trying to add as SSL-only friend a peer which PGP id is already a friend. This means the code is inconsistent. Not doing this!" << std::endl; + return false; + } + + pstate.gpg_id.clear(); pstate.id = sslId; if(!dt.name.empty()) pstate.name = dt.name; @@ -1060,6 +1107,8 @@ bool p3PeerMgrIMPL::addSslOnlyFriend( if(dt.hiddenType) pstate.hiddenType = dt.hiddenType; if(!dt.location.empty()) pstate.location = dt.location; + pstate.skip_pgp_signature_validation = true; + { RS_STACK_MUTEX(mPeerMtx); mFriendList[sslId] = pstate; diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 260864cd6..1dbabbd22 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -76,6 +76,14 @@ class peerState RsPeerId id; RsPgpId gpg_id; + // This flag is used when adding a single SSL cert as friend without adding its PGP key in the friend list. This allows to + // have short invites. However, because this represent a significant security risk, we perform multiple consistency checks + // whenever we use this flag, in particular: + // flat is true <==> friend SSL cert is in the friend list, but PGP id is not in the friend list + // PGP id is undefined and therefore set to null + + bool skip_pgp_signature_validation; + uint32_t netMode; /* EXT / UPNP / UDP / HIDDEN / INVALID */ /* visState */ uint16_t vs_disc; @@ -133,6 +141,7 @@ public: virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId) = 0; virtual bool isFriend(const RsPeerId& ssl_id) = 0; + virtual bool isSslOnlyFriend(const RsPeerId &ssl_id)=0; virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list &ids) = 0; virtual bool removeAllFriendLocations(const RsPgpId &gpgid) = 0; @@ -255,6 +264,7 @@ public: virtual bool removeFriend(const RsPgpId &pgp_id); virtual bool isFriend(const RsPeerId &ssl_id); + virtual bool isSslOnlyFriend(const RsPeerId &ssl_id); virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list &ids); virtual bool removeAllFriendLocations(const RsPgpId &gpgid); diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 2c1d7a7d5..426fa5e55 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -571,7 +571,20 @@ bool p3Peers::isPgpFriend(const RsPgpId& pgpId) { return AuthGPG::getAuthGPG()->isGPGAccepted(pgpId); } bool p3Peers::isSslOnlyFriend(const RsPeerId& sslId) -{ return isFriend(sslId) && !isPgpFriend(getGPGId(sslId)); } +{ + bool has_ssl_only_flag = mPeerMgr->isSslOnlyFriend(sslId) ; + + if(has_ssl_only_flag) + { + if(isPgpFriend(getGPGId(sslId))) + { + RsErr() << "Peer " << sslId << " has SSL-friend-only flag but his PGP id is in the list of friends. This is inconsistent (Bug in the code). Returning false for security reasons." << std::endl; + return false; + } + return true; + } + return false; +} bool p3Peers::isGPGAccepted(const RsPgpId &gpg_id_is_friend) { return isPgpFriend(gpg_id_is_friend); } diff --git a/libretroshare/src/util/rsthreads.cc b/libretroshare/src/util/rsthreads.cc index e474633f7..d4a27f6d5 100644 --- a/libretroshare/src/util/rsthreads.cc +++ b/libretroshare/src/util/rsthreads.cc @@ -110,6 +110,12 @@ RsThread::~RsThread() { RsErr() << "Deleting a thread that is still running! Something is very wrong here and Retroshare is likely to crash because of this." << std::endl; print_stacktrace(); + + while(isRunning()) + { + std::cerr << "." << std::endl; + rstime::rs_usleep(1000*1000); + } } } From 4eb6b0b066a5f3325f4ecdbcea0bec8e9f8c1ab1 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 26 May 2019 17:08:36 +0200 Subject: [PATCH 04/45] fixed uninitialized memory read for variable mRsEventsHandle --- libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc | 2 +- libretroshare/src/pqi/p3peermgr.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index 0c2a8fb0d..e1b499172 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -100,7 +100,7 @@ void DiscPgpInfo::mergeFriendList(const std::set &friends) p3discovery2::p3discovery2( p3PeerMgr* peerMgr, p3LinkMgr* linkMgr, p3NetMgr* netMgr, p3ServiceControl* sc, RsGixs* gixs ) : - p3Service(), mPeerMgr(peerMgr), mLinkMgr(linkMgr), mNetMgr(netMgr), + p3Service(), mRsEventsHandle(0), mPeerMgr(peerMgr), mLinkMgr(linkMgr), mNetMgr(netMgr), mServiceCtrl(sc), mGixs(gixs), mDiscMtx("p3discovery2"), mLastPgpUpdate(0) { Dbg3() << __PRETTY_FUNCTION__ << std::endl; diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 62191499c..11dda3667 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1718,7 +1718,7 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons sockaddr_storage_clear(addr_filtered) ; sockaddr_storage_copyip(addr_filtered,addr) ; -#ifdef PEER_DEBUG +#ifndef PEER_DEBUG std::cerr << "Own external address is " << sockaddr_storage_iptostring(addr_filtered) << ", as reported by friend " << from << std::endl; #endif From 8fddb559b9b0144ba0a3ff6fa2a62c3c4a932c5d Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 27 May 2019 21:48:47 +0200 Subject: [PATCH 05/45] fixed stupid bug that crashed the code in a different place --- libretroshare/src/pqi/p3peermgr.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 11dda3667..7f70dfe10 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -944,7 +944,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg #endif std::map::iterator it; - if (mFriendList.end() != mFriendList.find(id)) + if (mFriendList.end() != (it=mFriendList.find(id))) { #ifdef PEER_DEBUG std::cerr << "p3PeerMgrIMPL::addFriend() Already Exists" << std::endl; @@ -1029,8 +1029,8 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg pstate.netMode = netMode; pstate.lastcontact = lastContact; - it->second.gpg_id = input_gpg_id; - it->second.skip_pgp_signature_validation = false; + pstate.gpg_id = input_gpg_id; + pstate.skip_pgp_signature_validation = false; /* addr & timestamps -> auto cleared */ @@ -1821,7 +1821,7 @@ bool p3PeerMgrIMPL::getExtAddressReportedByFriends(sockaddr_storage &addr, uint8 { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - uint32_t count ; + uint32_t count =0; locked_computeCurrentBestOwnExtAddressCandidate(addr,count) ; From 3a799bae37c60262228fd77f8ee9c6dc417892a3 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 6 Jun 2019 21:41:38 +0200 Subject: [PATCH 06/45] added optional display of short invites in places with certificates --- libretroshare/src/rsserver/p3peers.cc | 13 +++++- retroshare-gui/src/gui/HomePage.cpp | 27 ++++++++++-- retroshare-gui/src/gui/HomePage.h | 22 +++++----- .../src/gui/connect/ConfCertDialog.cpp | 27 +++++++----- .../src/gui/connect/ConfCertDialog.h | 2 +- .../src/gui/connect/ConfCertDialog.ui | 11 ++++- .../src/gui/settings/CryptoPage.cpp | 42 +++++++++++-------- retroshare-gui/src/gui/settings/CryptoPage.ui | 9 +++- 8 files changed, 106 insertions(+), 47 deletions(-) diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 426fa5e55..1c68d5c71 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1129,6 +1129,7 @@ enum class RsShortInviteFieldType : uint8_t SSL_ID = 0x00, PEER_NAME = 0x01, LOCATOR = 0x02, + PGP_FINGERPRINT = 0x03, /* The following will be deprecated, and ported to LOCATOR when generic * trasport layer will be implemented */ @@ -1156,6 +1157,10 @@ bool p3Peers::getShortInvite( RS_SERIAL_PROCESS(tType); RS_SERIAL_PROCESS(sslId); + tType = RsShortInviteFieldType::PGP_FINGERPRINT; + RS_SERIAL_PROCESS(tType); + RS_SERIAL_PROCESS(tDetails.fpr); + tType = RsShortInviteFieldType::PEER_NAME; RS_SERIAL_PROCESS(tType); RS_SERIAL_PROCESS(tDetails.name); @@ -1220,8 +1225,7 @@ bool p3Peers::getShortInvite( return ctx.mOk; } -bool p3Peers::parseShortInvite( - const std::string& inviteStrUrl, RsPeerDetails& details ) +bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& details ) { if(inviteStrUrl.empty()) { @@ -1261,6 +1265,11 @@ bool p3Peers::parseShortInvite( case RsShortInviteFieldType::PEER_NAME: RS_SERIAL_PROCESS(details.name); break; + + case RsShortInviteFieldType::PGP_FINGERPRINT: + RS_SERIAL_PROCESS(details.fpr); + break; + case RsShortInviteFieldType::LOCATOR: { std::string locatorStr; diff --git a/retroshare-gui/src/gui/HomePage.cpp b/retroshare-gui/src/gui/HomePage.cpp index 5637a4b18..de03141d3 100644 --- a/retroshare-gui/src/gui/HomePage.cpp +++ b/retroshare-gui/src/gui/HomePage.cpp @@ -48,7 +48,8 @@ HomePage::HomePage(QWidget *parent) : MainPage(parent), ui(new Ui::HomePage), - mIncludeAllIPs(false) + mIncludeAllIPs(false), + mUseShortFormat(true) { ui->setupUi(this); @@ -109,11 +110,19 @@ void HomePage::certContextMenu(QPoint point) menu.addAction(CopyAction); menu.addAction(SaveAction); + QAction *shortFormatAct = new QAction(QIcon(), tr("Use new (short) certificate format"),this); + connect(shortFormatAct, SIGNAL(triggered()), this, SLOT(toggleUseShortFormat())); + shortFormatAct->setCheckable(true); + shortFormatAct->setChecked(mUseShortFormat); + + menu.addAction(shortFormatAct); + if(!RsAccounts::isHiddenNode()) { - QAction *includeIPsAct = new QAction(QIcon(), mIncludeAllIPs? tr("Include only current IP"):tr("Include all your known IPs"),this); + QAction *includeIPsAct = new QAction(QIcon(), tr("Include all your known IPs"),this); connect(includeIPsAct, SIGNAL(triggered()), this, SLOT(toggleIncludeAllIPs())); includeIPsAct->setCheckable(true); + includeIPsAct->setChecked(mIncludeAllIPs); menu.addAction(includeIPsAct); } @@ -121,6 +130,11 @@ void HomePage::certContextMenu(QPoint point) menu.exec(QCursor::pos()); } +void HomePage::toggleUseShortFormat() +{ + mUseShortFormat = !mUseShortFormat; + updateOwnCert(); +} void HomePage::toggleIncludeAllIPs() { mIncludeAllIPs = !mIncludeAllIPs; @@ -144,11 +158,16 @@ void HomePage::updateOwnCert() return ; } - std::string invite = rsPeers->GetRetroshareInvite(detail.id,false,include_extra_locators); + std::string invite ; + + if(mUseShortFormat) + rsPeers->getShortInvite(invite,rsPeers->getOwnId(),true,!mIncludeAllIPs); + else + invite = rsPeers->GetRetroshareInvite(detail.id,false,include_extra_locators); ui->userCertEdit->setPlainText(QString::fromUtf8(invite.c_str())); - QString description = ConfCertDialog::getCertificateDescription(detail,false,include_extra_locators); + QString description = ConfCertDialog::getCertificateDescription(detail,false,mUseShortFormat,include_extra_locators); ui->userCertEdit->setToolTip(description); } diff --git a/retroshare-gui/src/gui/HomePage.h b/retroshare-gui/src/gui/HomePage.h index b90c1081e..784f56bd6 100644 --- a/retroshare-gui/src/gui/HomePage.h +++ b/retroshare-gui/src/gui/HomePage.h @@ -41,10 +41,10 @@ class HomePage : public MainPage public: explicit HomePage(QWidget *parent); ~HomePage(); - - virtual QIcon iconPixmap() const { return QIcon(":/icons/png/home.png") ; } //MainPage - virtual QString pageName() const { return tr("Home") ; } //MainPage - virtual QString helpText() const { return ""; } //MainPage + + virtual QIcon iconPixmap() const { return QIcon(":/icons/png/home.png") ; } //MainPage + virtual QString pageName() const { return tr("Home") ; } //MainPage + virtual QString helpText() const { return ""; } //MainPage private slots: void certContextMenu(QPoint); @@ -52,18 +52,20 @@ private slots: void runEmailClient(); void copyCert(); void saveCert(); - void addFriend(); - void webMail(); - void loadCert(); + void addFriend(); + void webMail(); + void loadCert(); void runStartWizard() ; void openWebHelp() ; void recommendFriends(); - void toggleIncludeAllIPs(); + void toggleIncludeAllIPs(); + void toggleUseShortFormat(); private: Ui::HomePage *ui; - - bool mIncludeAllIPs; + + bool mIncludeAllIPs; + bool mUseShortFormat; }; diff --git a/retroshare-gui/src/gui/connect/ConfCertDialog.cpp b/retroshare-gui/src/gui/connect/ConfCertDialog.cpp index 907e765cf..072c966d5 100644 --- a/retroshare-gui/src/gui/connect/ConfCertDialog.cpp +++ b/retroshare-gui/src/gui/connect/ConfCertDialog.cpp @@ -89,11 +89,13 @@ ConfCertDialog::ConfCertDialog(const RsPeerId& id, const RsPgpId &pgp_id, QWidge //ui._chat_CB->hide() ; setAttribute(Qt::WA_DeleteOnClose, true); + ui._shortFormat_CB->setChecked(true); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(applyDialog())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close())); connect(ui._shouldAddSignatures_CB, SIGNAL(toggled(bool)), this, SLOT(loadInvitePage())); connect(ui._includeIPHistory_CB, SIGNAL(toggled(bool)), this, SLOT(loadInvitePage())); + connect(ui._shortFormat_CB, SIGNAL(toggled(bool)), this, SLOT(loadInvitePage())); ui.avatar->setFrameType(AvatarWidget::NORMAL_FRAME); @@ -270,14 +272,14 @@ void ConfCertDialog::loadInvitePage() // ui.userCertificateText_2->setFont(font); // ui.userCertificateText_2->setText(QString::fromUtf8(pgp_key.c_str())); - std::string invite = rsPeers->GetRetroshareInvite(detail.id, - ui._shouldAddSignatures_CB->isChecked(), - ui._includeIPHistory_CB->isChecked() - ) ; + std::string invite ; - QString infotext = getCertificateDescription(detail,ui._shouldAddSignatures_CB->isChecked(), - ui._includeIPHistory_CB->isChecked() - ); + if(ui._shortFormat_CB->isChecked()) + rsPeers->getShortInvite(invite,detail.id,true,!ui._includeIPHistory_CB->isChecked() ); + else + invite = rsPeers->GetRetroshareInvite(detail.id, ui._shouldAddSignatures_CB->isChecked(), ui._includeIPHistory_CB->isChecked() ) ; + + QString infotext = getCertificateDescription(detail,ui._shouldAddSignatures_CB->isChecked(),ui._shortFormat_CB->isChecked(), ui._includeIPHistory_CB->isChecked() ); ui.userCertificateText->setToolTip(infotext) ; @@ -291,15 +293,20 @@ void ConfCertDialog::loadInvitePage() ui.userCertificateText->setText(QString::fromUtf8(invite.c_str())); } -QString ConfCertDialog::getCertificateDescription(const RsPeerDetails& detail,bool signatures_included,bool include_additional_locators) +QString ConfCertDialog::getCertificateDescription(const RsPeerDetails& detail,bool signatures_included,bool use_short_format,bool include_additional_locators) { //infotext += tr("

Use this certificate to make new friends. Send it by email, or give it hand to hand.

") ; QString infotext = QObject::tr("

This certificate contains:") ; infotext += "

    " ; - infotext += "
  • a Profile key"; + + if(use_short_format) + infotext += "
  • a Profile fingerprint"; + else + infotext += "
  • a Profile key"; + infotext += " (" + QString::fromUtf8(detail.name.c_str()) + "@" + detail.gpg_id.toStdString().c_str()+") " ; - if(signatures_included) + if(signatures_included && !use_short_format) infotext += tr("with")+" "+QString::number(detail.gpgSigners.size()-1)+" "+tr("external signatures
  • ") ; else infotext += "" ; diff --git a/retroshare-gui/src/gui/connect/ConfCertDialog.h b/retroshare-gui/src/gui/connect/ConfCertDialog.h index a52ac3cdb..019e46598 100644 --- a/retroshare-gui/src/gui/connect/ConfCertDialog.h +++ b/retroshare-gui/src/gui/connect/ConfCertDialog.h @@ -58,7 +58,7 @@ public: /* window will destroy itself! */ } static void loadAll(); - static QString getCertificateDescription(const RsPeerDetails& det,bool signatures_included,bool extra_locators_included); + static QString getCertificateDescription(const RsPeerDetails& det, bool signatures_included, bool use_short_format, bool extra_locators_included); signals: void configChanged(); diff --git a/retroshare-gui/src/gui/connect/ConfCertDialog.ui b/retroshare-gui/src/gui/connect/ConfCertDialog.ui index 324f0fcb8..5c11ff46c 100644 --- a/retroshare-gui/src/gui/connect/ConfCertDialog.ui +++ b/retroshare-gui/src/gui/connect/ConfCertDialog.ui @@ -6,8 +6,8 @@ 0 0 - 600 - 584 + 658 + 1120 @@ -389,6 +389,13 @@ + + + + short format + + + diff --git a/retroshare-gui/src/gui/settings/CryptoPage.cpp b/retroshare-gui/src/gui/settings/CryptoPage.cpp index 9092fa587..3ac626834 100755 --- a/retroshare-gui/src/gui/settings/CryptoPage.cpp +++ b/retroshare-gui/src/gui/settings/CryptoPage.cpp @@ -41,22 +41,25 @@ CryptoPage::CryptoPage(QWidget * parent, Qt::WindowFlags flags) : ConfigPage(parent, flags) { - /* Invoke the Qt Designer generated object setup routine */ - ui.setupUi(this); + /* Invoke the Qt Designer generated object setup routine */ + ui.setupUi(this); -// connect(ui.copykeyButton, SIGNAL(clicked()), this, SLOT(copyPublicKey())); - connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(fileSaveAs())); - connect(ui._includeSignatures_CB, SIGNAL(toggled(bool)), this, SLOT(load())); - connect(ui._includeAllIPs_CB, SIGNAL(toggled(bool)), this, SLOT(load())); - connect(ui._copyLink_PB, SIGNAL(clicked()), this, SLOT(copyRSLink())); - connect(ui.showStats_PB, SIGNAL(clicked()), this, SLOT(showStats())); + ui._shortFormat_CB->setChecked(true); - // hide profile manager as it causes bugs when generating a new profile. - //ui.profile_Button->hide() ; + // connect(ui.copykeyButton, SIGNAL(clicked()), this, SLOT(copyPublicKey())); + connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(fileSaveAs())); + connect(ui._includeSignatures_CB, SIGNAL(toggled(bool)), this, SLOT(load())); + connect(ui._shortFormat_CB, SIGNAL(toggled(bool)), this, SLOT(load())); + connect(ui._includeAllIPs_CB, SIGNAL(toggled(bool)), this, SLOT(load())); + connect(ui._copyLink_PB, SIGNAL(clicked()), this, SLOT(copyRSLink())); + connect(ui.showStats_PB, SIGNAL(clicked()), this, SLOT(showStats())); - connect(ui.createNewNode_PB,SIGNAL(clicked()), this, SLOT(profilemanager())); + // hide profile manager as it causes bugs when generating a new profile. + //ui.profile_Button->hide() ; - ui.onlinesince->setText(DateTime::formatLongDateTime(Rshare::startupTime())); + connect(ui.createNewNode_PB,SIGNAL(clicked()), this, SLOT(profilemanager())); + + ui.onlinesince->setText(DateTime::formatLongDateTime(Rshare::startupTime())); } void CryptoPage::profilemanager() @@ -97,16 +100,21 @@ CryptoPage::~CryptoPage() void CryptoPage::load() { - ui.certplainTextEdit->setPlainText( - QString::fromUtf8( - rsPeers->GetRetroshareInvite( rsPeers->getOwnId(), ui._includeSignatures_CB->isChecked(), ui._includeAllIPs_CB->isChecked() ).c_str() - ) ); + std::string cert ; + + if(ui._shortFormat_CB->isChecked()) + rsPeers->getShortInvite(cert,rsPeers->getOwnId(), true, !ui._includeAllIPs_CB->isChecked()); + else + cert = rsPeers->GetRetroshareInvite( rsPeers->getOwnId(), ui._includeSignatures_CB->isChecked(), ui._includeAllIPs_CB->isChecked() ); + + ui.certplainTextEdit->setPlainText( QString::fromUtf8( cert.c_str() ) ); RsPeerDetails detail; rsPeers->getPeerDetails(rsPeers->getOwnId(),detail); - ui.certplainTextEdit->setToolTip(ConfCertDialog::getCertificateDescription(detail, ui._includeSignatures_CB->isChecked(), ui._includeAllIPs_CB->isChecked() )); + ui.certplainTextEdit->setToolTip(ConfCertDialog::getCertificateDescription(detail, ui._includeSignatures_CB->isChecked(), ui._shortFormat_CB->isChecked(), ui._includeAllIPs_CB->isChecked() )); } + void CryptoPage::copyRSLink() { diff --git a/retroshare-gui/src/gui/settings/CryptoPage.ui b/retroshare-gui/src/gui/settings/CryptoPage.ui index f96b3935a..0e2af06f2 100755 --- a/retroshare-gui/src/gui/settings/CryptoPage.ui +++ b/retroshare-gui/src/gui/settings/CryptoPage.ui @@ -6,7 +6,7 @@ 0 0 - 989 + 1531 678 @@ -460,6 +460,13 @@ + + + + Short format + + + From 4bd5aaa9b28ad0bfd4084ca595d5d3eeca174dcc Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 9 Jun 2019 15:03:48 +0200 Subject: [PATCH 07/45] added parsing of short invites in connect friend wizard (not working yet) --- libretroshare/src/pgp/rscertificate.cc | 18 +++++-- libretroshare/src/pgp/rscertificate.h | 5 +- libretroshare/src/retroshare/rspeers.h | 2 +- libretroshare/src/rsserver/p3peers.cc | 13 ++++- libretroshare/src/rsserver/p3peers.h | 2 +- .../src/gui/connect/ConnectFriendWizard.cpp | 53 ++++++++++++++----- 6 files changed, 69 insertions(+), 24 deletions(-) diff --git a/libretroshare/src/pgp/rscertificate.cc b/libretroshare/src/pgp/rscertificate.cc index 11ada52a6..fff50fd61 100644 --- a/libretroshare/src/pgp/rscertificate.cc +++ b/libretroshare/src/pgp/rscertificate.cc @@ -552,14 +552,22 @@ unsigned short RsCertificate::loc_port_us() const return (int)ipv4_internal_ip_and_port[4]*256 + (int)ipv4_internal_ip_and_port[5] ; } -bool RsCertificate::cleanCertificate( - const std::string& input, std::string& output, Format& format, - int& error_code, bool check_content ) +bool RsCertificate::cleanCertificate( const std::string& input, std::string& output, Format& format, int& error_code, bool check_content ) { - if(cleanCertificate(input,output,error_code)) + if(cleanRadix64(input,output,error_code)) { + RsPeerDetails details; + + if(rsPeers->parseShortInvite(output,details)) + { + format = RS_CERTIFICATE_SHORT_RADIX; + return true; + } + format = RS_CERTIFICATE_RADIX; + if(!check_content) return true; + uint32_t errCode; auto crt = RsCertificate::fromString(input, errCode); error_code = static_cast(errCode); @@ -576,7 +584,7 @@ std::string RsCertificate::armouredPGPKey() const // Yeah, this is simple, and that is what's good about the radix format. Can't be broken ;-) // -bool RsCertificate::cleanCertificate(const std::string& instr,std::string& str,int& error_code) +bool RsCertificate::cleanRadix64(const std::string& instr,std::string& str,int& error_code) { error_code = RS_PEER_CERT_CLEANING_CODE_NO_ERROR ; diff --git a/libretroshare/src/pgp/rscertificate.h b/libretroshare/src/pgp/rscertificate.h index 7f80a30d1..2d506d03f 100644 --- a/libretroshare/src/pgp/rscertificate.h +++ b/libretroshare/src/pgp/rscertificate.h @@ -36,7 +36,7 @@ struct RsPeerDetails; class RsCertificate { public: - typedef enum { RS_CERTIFICATE_OLD_FORMAT, RS_CERTIFICATE_RADIX } Format; + typedef enum { RS_CERTIFICATE_OLD_FORMAT, RS_CERTIFICATE_RADIX, RS_CERTIFICATE_SHORT_RADIX } Format; /** * @brief Create certificate object from certificate string @@ -99,8 +99,7 @@ public: private: // new radix format - static bool cleanCertificate( const std::string& input, - std::string& output, int&); + static bool cleanRadix64( const std::string& input, std::string& output, int&); static void scan_ip( const std::string& ip_string, unsigned short port, unsigned char *destination_memory ); diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 7f1551f69..f15272397 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -717,7 +717,7 @@ public: uint32_t& errorCode ) = 0; // Certificate utils - virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code) = 0; + virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,int& error_code) = 0; virtual bool saveCertificateToFile(const RsPeerId& id, const std::string &fname) = 0; virtual std::string saveCertificateToString(const RsPeerId &id) = 0; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 1c68d5c71..eadc2fd75 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1536,11 +1536,20 @@ bool p3Peers::loadDetailsFromStringCert( const std::string &certstr, return true; } -bool p3Peers::cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code) +bool p3Peers::cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,int& error_code) { RsCertificate::Format format ; - return RsCertificate::cleanCertificate(certstr,cleanCert,format,error_code,true) ; + bool res = RsCertificate::cleanCertificate(certstr,cleanCert,format,error_code,true) ; + + if(format == RsCertificate::RS_CERTIFICATE_RADIX) + is_short_format = false; + else if(format == RsCertificate::RS_CERTIFICATE_SHORT_RADIX) + is_short_format = true; + else + return false ; + + return res; } bool p3Peers::saveCertificateToFile(const RsPeerId &id, const std::string &/*fname*/) diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index c6bc82704..5e1dd5fed 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -157,7 +157,7 @@ public: virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string); virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code); - virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code); + virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert, bool &is_short_format, int& error_code) override; virtual bool saveCertificateToFile(const RsPeerId &id, const std::string &fname); virtual std::string saveCertificateToString(const RsPeerId &id); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index b58e8f94d..2368b7bc3 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -299,8 +299,6 @@ void ConnectFriendWizard::setCertificate(const QString &certificate, bool friend { mCertificate = certificate.toUtf8().constData(); - // Cyril: I disabled this because it seems to be not used anymore. - //setStartId(friendRequest ? Page_FriendRequest : Page_Conclusion); setStartId(Page_Conclusion); if (friendRequest){ ui->cp_Label->show(); @@ -309,7 +307,31 @@ void ConnectFriendWizard::setCertificate(const QString &certificate, bool friend ui->ConclusionPage->setSubTitle(tr("Details about the request")); } } - } else { + } + else if(rsPeers->parseShortInvite(certificate.toUtf8().constData(),peerDetails)) + { + if(peerDetails.id == rsPeers->getOwnId()) + { + setField("errorMessage", tr("This is your own certificate! You would not want to make friend with yourself. Wouldn't you?") ) ; + error = false; + setStartId(Page_ErrorMessage); + } + else + { + mCertificate = certificate.toUtf8().constData(); + + setStartId(Page_Conclusion); + + if (friendRequest){ + ui->cp_Label->show(); + ui->requestinfolabel->show(); + setTitleText(ui->ConclusionPage, tr("Friend request")); + ui->ConclusionPage->setSubTitle(tr("Details about the request")); + } + } + } + else + { // error message setField("errorMessage", tr("Certificate Load Failed") + ": \n\n" + getErrorString(cert_load_error_code)) ; setStartId(Page_ErrorMessage); @@ -702,7 +724,8 @@ bool ConnectFriendWizard::validateCurrentPage() std::string certstr = ui->friendCertEdit->toPlainText().toUtf8().constData(); uint32_t cert_load_error_code; - if (rsPeers->loadDetailsFromStringCert(certstr, peerDetails, cert_load_error_code)) { + if (rsPeers->loadDetailsFromStringCert(certstr, peerDetails, cert_load_error_code) || rsPeers->parseShortInvite(certstr,peerDetails)) + { mCertificate = certstr; #ifdef FRIEND_WIZARD_DEBUG std::cerr << "ConnectFriendWizard got id : " << peerDetails.id << "; gpg_id : " << peerDetails.gpg_id << std::endl; @@ -742,7 +765,8 @@ bool ConnectFriendWizard::validateCurrentPage() } uint32_t cert_error_code; - if (rsPeers->loadDetailsFromStringCert(certstr, peerDetails, cert_error_code)) { + if (rsPeers->loadDetailsFromStringCert(certstr, peerDetails, cert_error_code) || rsPeers->parseShortInvite(certstr,peerDetails)) + { mCertificate = certstr; #ifdef FRIEND_WIZARD_DEBUG std::cerr << "ConnectFriendWizard got id : " << peerDetails.id << "; gpg_id : " << peerDetails.gpg_id << std::endl; @@ -1058,18 +1082,23 @@ void ConnectFriendWizard::cleanFriendCert() } else { std::string cleanCert; int error_code; + bool is_short_format; - if (rsPeers->cleanCertificate(cert, cleanCert, error_code)) { + if (rsPeers->cleanCertificate(cert, cleanCert, is_short_format, error_code)) + { certValid = true; - if (cert != cleanCert) { - disconnect(ui->friendCertEdit, SIGNAL(textChanged()), this, SLOT(friendCertChanged())); + + if (cert != cleanCert) + { QTextCursor textCursor = ui->friendCertEdit->textCursor(); - ui->friendCertEdit->setPlainText(QString::fromUtf8(cleanCert.c_str())); - ui->friendCertEdit->setTextCursor(textCursor); + + whileBlocking(ui->friendCertEdit)->setPlainText(QString::fromUtf8(cleanCert.c_str())); + whileBlocking(ui->friendCertEdit)->setTextCursor(textCursor); + ui->friendCertCleanLabel->setStyleSheet(""); - connect(ui->friendCertEdit, SIGNAL(textChanged()), this, SLOT(friendCertChanged())); } - errorMsg = tr("Certificate appears to be valid"); + errorMsg = tr("Valid certificate") + (is_short_format?" (Short format)":" (plain format with profile key)"); + ui->friendCertCleanLabel->setPixmap(QPixmap(":/images/accepted16.png")); } else { if (error_code > 0) { From fb52f6717c7b7b7d950c33a1a19c34fc5bb96f39 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 9 Jun 2019 23:49:31 +0200 Subject: [PATCH 08/45] fixed up addign friend from short invite --- libretroshare/src/pgp/pgphandler.cc | 5 +++ libretroshare/src/pgp/pgphandler.h | 1 + libretroshare/src/pqi/p3peermgr.cc | 29 ++++++++++----- libretroshare/src/pqi/p3peermgr.h | 5 ++- libretroshare/src/retroshare/rspeers.h | 10 ++++++ libretroshare/src/rsserver/p3peers.cc | 26 ++++++++++---- libretroshare/src/rsserver/p3peers.h | 1 + .../src/gui/connect/ConnectFriendWizard.cpp | 35 +++++++++++-------- .../src/gui/connect/ConnectFriendWizard.ui | 22 ++++++------ 9 files changed, 90 insertions(+), 44 deletions(-) diff --git a/libretroshare/src/pgp/pgphandler.cc b/libretroshare/src/pgp/pgphandler.cc index 87bb462e0..46e8b166c 100644 --- a/libretroshare/src/pgp/pgphandler.cc +++ b/libretroshare/src/pgp/pgphandler.cc @@ -1571,6 +1571,11 @@ void PGPHandler::locked_updateOwnSignatureFlag(PGPCertificateInfo& cert,const Rs cert._flags &= ~PGPCertificateInfo::PGP_CERTIFICATE_FLAG_HAS_SIGNED_ME ; } +RsPgpId PGPHandler::pgpIdFromFingerprint(const PGPFingerprintType& f) +{ + return RsPgpId(f.toByteArray() + _RsIdSize::PGP_FINGERPRINT - _RsIdSize::PGP_ID); +} + bool PGPHandler::getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const { RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. diff --git a/libretroshare/src/pgp/pgphandler.h b/libretroshare/src/pgp/pgphandler.h index e0b563a64..e6c16764e 100644 --- a/libretroshare/src/pgp/pgphandler.h +++ b/libretroshare/src/pgp/pgphandler.h @@ -153,6 +153,7 @@ class PGPHandler static void setPassphraseCallback(PassphraseCallback cb) ; static PassphraseCallback passphraseCallback() { return _passphrase_callback ; } + static RsPgpId pgpIdFromFingerprint(const PGPFingerprintType& f) ; // Gets info about the key. Who are the signers, what's the owner's name, etc. // diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 7f70dfe10..90ca5cecd 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1065,7 +1065,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg } -bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPeerDetails& dt ) +bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_id,const RsPeerDetails& dt ) { if(sslId.isNull() || sslId == getOwnId()) { @@ -1095,7 +1095,13 @@ bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPeerDetails return false; } - pstate.gpg_id.clear(); + if(pgp_id.isNull()) + { + RsErr() << "Null pgp id for friend added with skip_pgp_signature_validaiton flag. This is not allowed." << std::endl; + return false; + } + + pstate.gpg_id = pgp_id; pstate.id = sslId; if(!dt.name.empty()) pstate.name = dt.name; @@ -2460,14 +2466,19 @@ bool p3PeerMgrIMPL::loadList(std::list& load) #endif /* ************* */ // permission flags is used as a mask for the existing perms, so we set it to 0xffff - if(!addFriend( peer_id, peer_pgp_id, pitem->netMode, - pitem->vs_disc, pitem->vs_dht, - pitem->lastContact, RS_NODE_PERM_ALL )) + + RsPeerDetails det ; + if(!rsPeers->getGPGDetails(peer_pgp_id,det)) + { + // would be better to add flags into RsPeerNetItem so that we already have this information. However, it's possible that the PGP key + // has been added in the meantime, so the peer would be loaded with the right pGP key attached. + + RsInfo() << __PRETTY_FUNCTION__ << " loading SSL-only " << "friend: " << peer_id << " " << pitem->location << std::endl; + addSslOnlyFriend(peer_id,peer_pgp_id); + } + else if(!addFriend( peer_id, peer_pgp_id, pitem->netMode, pitem->vs_disc, pitem->vs_dht, pitem->lastContact, RS_NODE_PERM_ALL )) { - RsInfo() << __PRETTY_FUNCTION__ << " loading SSL-only " - << "friend: " << peer_id << " " << pitem->location - << std::endl; - addSslOnlyFriend(peer_id); + RsInfo() << __PRETTY_FUNCTION__ << " cannot add friend friend: " << peer_id << " " << pitem->location << ". Somthing's wrong." << std::endl; } setLocation(pitem->nodePeerId, pitem->location); } diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 1dbabbd22..131cec418 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -137,6 +137,7 @@ public: virtual bool addSslOnlyFriend( const RsPeerId& sslId, + const RsPgpId& pgpId, const RsPeerDetails& details = RsPeerDetails() ) = 0; virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId) = 0; @@ -256,9 +257,7 @@ public: uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL, rstime_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT)); - bool addSslOnlyFriend( - const RsPeerId& sslId, - const RsPeerDetails& details = RsPeerDetails() ) override; + bool addSslOnlyFriend(const RsPeerId& sslId, const RsPgpId &pgp_id, const RsPeerDetails& details = RsPeerDetails() ) override; virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId); virtual bool removeFriend(const RsPgpId &pgp_id); diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index f15272397..a077fd638 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -205,6 +205,14 @@ std::string RsPeerNetModeString(uint32_t netModel); std::string RsPeerLastConnectString(uint32_t lastConnect); +/* We should definitely split this into 2 sub-structures: + * PGP info (or profile info) with all info related to PGP keys + * peer info: all network related information + * + * Plus top level information: + * isOnlyPgpDetail (this could be obsolete if the methods to query about PGP info is a different function) + * peer Id + */ struct RsPeerDetails : RsSerializable { RsPeerDetails(); @@ -228,6 +236,7 @@ struct RsPeerDetails : RsSerializable uint32_t trustLvl; uint32_t validLvl; + bool skip_signature_validation; bool ownsign; /* we have signed the remote peer GPG key */ bool hasSignedMe; /* the remote peer has signed my GPG key */ @@ -519,6 +528,7 @@ public: */ virtual bool addSslOnlyFriend( const RsPeerId& sslId, + const RsPgpId& pgp_id, const RsPeerDetails& details = RsPeerDetails() ) = 0; /** diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index eadc2fd75..02615d9e6 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -765,9 +765,10 @@ bool p3Peers::addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePe return mPeerMgr->addFriend(ssl_id, gpg_id, RS_NET_MODE_UDP, RS_VS_DISC_FULL, RS_VS_DHT_FULL, now, perm_flags); } -bool p3Peers::addSslOnlyFriend( - const RsPeerId& sslId, const RsPeerDetails& details ) -{ return mPeerMgr->addSslOnlyFriend(sslId, details); } +bool p3Peers::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_id,const RsPeerDetails& details ) +{ + return mPeerMgr->addSslOnlyFriend(sslId, pgp_id,details); +} bool p3Peers::removeKeysFromPGPKeyring(const std::set& pgp_ids,std::string& backup_file,uint32_t& error_code) { @@ -1241,8 +1242,7 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d rsInvite = inviteUrl.getQueryV("rsInvite"); std::vector inviteBuf = Radix64::decode(*rsInvite); - RsGenericSerializer::SerializeContext ctx( - inviteBuf.data(), static_cast(inviteBuf.size())); + RsGenericSerializer::SerializeContext ctx( inviteBuf.data(), static_cast(inviteBuf.size())); RsGenericSerializer::SerializeJob j = RsGenericSerializer::DESERIALIZE; while(ctx.mOk && ctx.mOffset < ctx.mSize) @@ -1346,6 +1346,20 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d } } + // now check if the PGP key is available. If so, add it in the PeerDetails: + + RsPeerDetails pgp_det ; + if(getGPGDetails(PGPHandler::pgpIdFromFingerprint(details.fpr),pgp_det) && pgp_det.fpr == details.fpr) + { + details.issuer = pgp_det.issuer; + details.gpg_id = pgp_det.gpg_id; + details.gpgSigners = pgp_det.gpgSigners; + details.trustLvl = pgp_det.trustLvl; + details.validLvl = pgp_det.validLvl; + details.ownsign = pgp_det.ownsign; + details.hasSignedMe = pgp_det.hasSignedMe; + details.accept_connection = pgp_det.accept_connection; + } return ctx.mOk; } @@ -1730,7 +1744,7 @@ RsPeerDetails::RsPeerDetails() :isOnlyGPGdetail(false), name(""),email(""),location(""), org(""),authcode(""), - trustLvl(0), validLvl(0),ownsign(false), + trustLvl(0), validLvl(0),skip_signature_validation(false),ownsign(false), hasSignedMe(false),accept_connection(false), state(0),actAsServer(false), connectPort(0), diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index 5e1dd5fed..da679124f 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -97,6 +97,7 @@ public: /// @see RsPeers bool addSslOnlyFriend( const RsPeerId& sslId, + const RsPgpId& pgp_id, const RsPeerDetails& details = RsPeerDetails() ) override; virtual bool removeFriend(const RsPgpId& gpgid); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 2368b7bc3..57be98dd3 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -922,7 +922,7 @@ void ConnectFriendWizard::accept() return; } - if (!mCertificate.empty() && add_key_to_keyring) + if(!peerDetails.skip_signature_validation && !mCertificate.empty() && add_key_to_keyring) { RsPgpId pgp_id ; RsPeerId ssl_id ; @@ -940,28 +940,33 @@ void ConnectFriendWizard::accept() if(accept_connection && !peerDetails.gpg_id.isNull()) { std::cerr << "ConclusionPage::validatePage() accepting GPG key for connection." << std::endl; - rsPeers->addFriend(peerDetails.id, peerDetails.gpg_id,serviceFlags()) ; - rsPeers->setServicePermissionFlags(peerDetails.gpg_id,serviceFlags()) ; - if(ui->_addIPToWhiteList_CB_2->isChecked()) - { - sockaddr_storage addr ; - if(sockaddr_storage_ipv4_aton(addr,peerDetails.extAddr.c_str()) && sockaddr_storage_isValidNet(addr)) - { - std::cerr << "ConclusionPage::adding IP " << sockaddr_storage_tostring(addr) << " to whitelist." << std::endl; - rsBanList->addIpRange(addr,ui->_addIPToWhiteList_ComboBox_2->currentIndex(),RSBANLIST_TYPE_WHITELIST,std::string(tr("Added with certificate from %1").arg(ui->nameEdit->text()).toUtf8().constData())); - } - } + if(peerDetails.skip_signature_validation) + rsPeers->addSslOnlyFriend(peerDetails.id, peerDetails.gpg_id,peerDetails); + else + rsPeers->addFriend(peerDetails.id, peerDetails.gpg_id,serviceFlags()) ; + + rsPeers->setServicePermissionFlags(peerDetails.gpg_id,serviceFlags()) ; + + if(ui->_addIPToWhiteList_CB_2->isChecked()) + { + sockaddr_storage addr ; + if(sockaddr_storage_ipv4_aton(addr,peerDetails.extAddr.c_str()) && sockaddr_storage_isValidNet(addr)) + { + std::cerr << "ConclusionPage::adding IP " << sockaddr_storage_tostring(addr) << " to whitelist." << std::endl; + rsBanList->addIpRange(addr,ui->_addIPToWhiteList_ComboBox_2->currentIndex(),RSBANLIST_TYPE_WHITELIST,std::string(tr("Added with certificate from %1").arg(ui->nameEdit->text()).toUtf8().constData())); + } + } if(sign) { std::cerr << "ConclusionPage::validatePage() signing GPG key." << std::endl; rsPeers->signGPGCertificate(peerDetails.gpg_id); //bye default sign set accept_connection to true; rsPeers->setServicePermissionFlags(peerDetails.gpg_id,serviceFlags()) ; - } + } - if (!groupId.isEmpty()) - rsPeers->assignPeerToGroup(RsNodeGroupId(groupId.toStdString()), peerDetails.gpg_id, true); + if (!groupId.isEmpty()) + rsPeers->assignPeerToGroup(RsNodeGroupId(groupId.toStdString()), peerDetails.gpg_id, true); } if ((accept_connection) && (!peerDetails.id.isNull())) diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index 051e7f979..43af02fbe 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -6,8 +6,8 @@ 0 0 - 600 - 400 + 1100 + 604 @@ -45,7 +45,7 @@ - &Make friend with selected friends of my friends + Ma&ke friend with selected friends of my friends @@ -59,7 +59,7 @@ - &Send an Invitation by Web Mail Providers + Send an In&vitation by Web Mail Providers @@ -1502,6 +1502,12 @@ + + AvatarWidget + QLabel +
    gui/common/AvatarWidget.h
    + 1 +
    StyledLabel QLabel @@ -1513,12 +1519,6 @@
    gui/common/FriendSelectionWidget.h
    1
    - - AvatarWidget - QLabel -
    gui/common/AvatarWidget.h
    - 1 -
    DropLineEdit QLineEdit @@ -1537,8 +1537,8 @@
    - + From 76cf64f8d52bc220b96720ebb470e2bd5f86fd50 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 00:02:03 +0200 Subject: [PATCH 09/45] fixed compilation --- libretroshare/src/retroshare/rspeers.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index a077fd638..7e2bc898b 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -503,6 +503,9 @@ 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; + // 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. + /** * @brief Add trusted node * @jsonapi{development} @@ -523,12 +526,13 @@ public: * SSL+PGP friend. * @jsonapi{development} * @param[in] sslId SSL id of the node to add + * @param[in] pgpId PGP id of the node to add. Will be used for validation when the key is available. * @param[in] details Optional extra details known about the node to add * @return false if error occurred, true otherwise */ virtual bool addSslOnlyFriend( const RsPeerId& sslId, - const RsPgpId& pgp_id, + const RsPgpId& pgpId, const RsPeerDetails& details = RsPeerDetails() ) = 0; /** From a7141cbf6988113ec8311d3a61893aacbc28d3c9 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 00:03:07 +0200 Subject: [PATCH 10/45] removed unused startWizard and loadCert code in HomePage --- retroshare-gui/src/gui/HomePage.cpp | 25 +- retroshare-gui/src/gui/HomePage.h | 3 +- retroshare-gui/src/gui/HomePage.ui | 240 ++++++++---------- .../src/gui/connect/ConnectFriendWizard.ui | 2 +- 4 files changed, 120 insertions(+), 150 deletions(-) diff --git a/retroshare-gui/src/gui/HomePage.cpp b/retroshare-gui/src/gui/HomePage.cpp index de03141d3..385e6c075 100644 --- a/retroshare-gui/src/gui/HomePage.cpp +++ b/retroshare-gui/src/gui/HomePage.cpp @@ -56,7 +56,7 @@ HomePage::HomePage(QWidget *parent) : updateOwnCert(); connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addFriend())); - connect(ui->LoadCertFileButton, SIGNAL(clicked()), this, SLOT(loadCert())); + //connect(ui->LoadCertFileButton, SIGNAL(clicked()), this, SLOT(loadCert())); QAction *WebMailAction = new QAction(QIcon(),tr("Invite via WebMail"), this); connect(WebMailAction, SIGNAL(triggered()), this, SLOT(webMail())); @@ -76,11 +76,9 @@ HomePage::HomePage(QWidget *parent) : QObject::connect(ui->userCertEdit,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(certContextMenu(QPoint))); - connect(ui->runStartWizard_PB,SIGNAL(clicked()), this,SLOT(runStartWizard())) ; connect(ui->openwebhelp,SIGNAL(clicked()), this,SLOT(openWebHelp())) ; - ui->runStartWizard_PB->hide(); // until future rework - ui->LoadCertFileButton->hide(); // duplicates functionality => not good. + //ui->LoadCertFileButton->hide(); // duplicates functionality => not good. int S = QFontMetricsF(font()).height(); QString help_str = tr( @@ -251,18 +249,13 @@ void HomePage::webMail() connwiz.exec (); } -void HomePage::loadCert() -{ - ConnectFriendWizard connwiz (this); - - connwiz.setStartId(ConnectFriendWizard::Page_Cert); - connwiz.exec (); -} - -void HomePage::runStartWizard() -{ - QuickStartWizard(this).exec(); -} +// void HomePage::loadCert() +// { +// ConnectFriendWizard connwiz (this); +// +// connwiz.setStartId(ConnectFriendWizard::Page_Cert); +// connwiz.exec (); +// } void HomePage::openWebHelp() { diff --git a/retroshare-gui/src/gui/HomePage.h b/retroshare-gui/src/gui/HomePage.h index 784f56bd6..58a7c65b9 100644 --- a/retroshare-gui/src/gui/HomePage.h +++ b/retroshare-gui/src/gui/HomePage.h @@ -54,8 +54,7 @@ private slots: void saveCert(); void addFriend(); void webMail(); - void loadCert(); - void runStartWizard() ; + //void loadCert(); void openWebHelp() ; void recommendFriends(); void toggleIncludeAllIPs(); diff --git a/retroshare-gui/src/gui/HomePage.ui b/retroshare-gui/src/gui/HomePage.ui index da8d7b25d..fea881a6f 100644 --- a/retroshare-gui/src/gui/HomePage.ui +++ b/retroshare-gui/src/gui/HomePage.ui @@ -14,6 +14,25 @@ Form + + + + + 0 + 0 + + + + + + + :/images/logo/logo_web_nobackground.png + + + Qt::AlignCenter + + + @@ -52,7 +71,7 @@ ... - + :/icons/help_64.png:/icons/help_64.png @@ -141,134 +160,6 @@ private and secure decentralized communication platform. - - - - - 0 - 0 - - - - - - - :/images/logo/logo_web_nobackground.png - - - Qt::AlignCenter - - - - - - - Launch startup wizard - - - - :/images/tools_wizard.png:/images/tools_wizard.png - - - - - - - - - - - - - - 11 - - - - - - - Did you receive a certificate from a friend? - - - - - - - Add friends certificate - - - - :/icons/png/invite.png:/icons/png/invite.png - - - - 24 - 24 - - - - Qt::ToolButtonTextBesideIcon - - - false - - - - - - - Add certificate file - - - - :/icons/svg/folders1.svg:/icons/svg/folders1.svg - - - - 24 - 24 - - - - Qt::ToolButtonTextBesideIcon - - - false - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - @@ -316,18 +207,105 @@ private and secure decentralized communication platform.
    + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + + + 11 + + + + + + + Did you receive a certificate from a friend? + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add friends certificate + + + + :/icons/png/invite.png:/icons/png/invite.png + + + + 24 + 24 + + + + Qt::ToolButtonTextBesideIcon + + + false + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + label addFrame label_2 addframe - runStartWizard_PB frame helpframe - + diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index 43af02fbe..3e1f997f6 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -6,7 +6,7 @@ 0 0 - 1100 + 1134 604 From 6294aefc6d6fe8c1e08802aa8238808b40e129a0 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 00:12:20 +0200 Subject: [PATCH 11/45] removed unused intro page from ConnectFriendWizard --- .../src/gui/connect/ConnectFriendWizard.cpp | 20 +----- .../src/gui/connect/ConnectFriendWizard.h | 2 +- .../src/gui/connect/ConnectFriendWizard.ui | 65 +------------------ 3 files changed, 5 insertions(+), 82 deletions(-) diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 57be98dd3..b343db718 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -91,7 +91,7 @@ ConnectFriendWizard::ConnectFriendWizard(QWidget *parent) : setWizardStyle(ModernStyle); #endif - setStartId(Page_Intro); + setStartId(Page_Cert); // at this moment I don't know, what information should be in help // setOption(HaveHelpButton, true); @@ -106,8 +106,8 @@ ConnectFriendWizard::ConnectFriendWizard(QWidget *parent) : ui->ErrorMessagePage->registerField("errorMessage", ui->messageLabel, "text"); /* disable not used pages */ - ui->foffRadioButton->hide(); - ui->rsidRadioButton->hide(); + //ui->foffRadioButton->hide(); + //ui->rsidRadioButton->hide(); ui->cp_Label->hide(); ui->requestinfolabel->hide(); @@ -277,7 +277,6 @@ QString ConnectFriendWizard::getErrorString(uint32_t error_code) void ConnectFriendWizard::setCertificate(const QString &certificate, bool friendRequest) { if (certificate.isEmpty()) { - setStartId(Page_Intro); return; } @@ -383,9 +382,6 @@ static void fillGroups(ConnectFriendWizard *wizard, QComboBox *comboBox, const Q void ConnectFriendWizard::initializePage(int id) { switch ((Page) id) { - case Page_Intro: - ui->textRadioButton->setChecked(true); - break; case Page_Text: connect(ui->userCertHelpButton, SIGNAL( clicked()), this, SLOT(showHelpUserCert())); connect(ui->userCertIncludeSignaturesButton, SIGNAL(clicked()), this, SLOT(toggleSignatureState())); @@ -716,7 +712,6 @@ bool ConnectFriendWizard::validateCurrentPage() error = true; switch ((Page) currentId()) { - case Page_Intro: case Page_WebMail: break; case Page_Text: @@ -858,15 +853,6 @@ bool ConnectFriendWizard::validateCurrentPage() int ConnectFriendWizard::nextId() const { switch ((Page) currentId()) { - case Page_Intro: - if (ui->textRadioButton->isChecked()) return Page_Text; - if (ui->certRadioButton->isChecked()) return Page_Cert; - if (ui->foffRadioButton->isChecked()) return Page_Foff; - if (ui->rsidRadioButton->isChecked()) return Page_Rsid; - if (ui->webmailRadioButton->isChecked()) return Page_WebMail; - if (ui->emailRadioButton->isChecked()) return Page_Email; - if (ui->friendRecommendationsRadioButton->isChecked()) return Page_FriendRecommendations; - return ConnectFriendWizard::Page_Foff; case Page_Text: case Page_Cert: case Page_Rsid: diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h index 6d9a74e57..c4a030862 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h @@ -50,7 +50,7 @@ class ConnectFriendWizard : public QWizard Q_PROPERTY(QString titleColor READ titleColor WRITE setTitleColor) public: - enum Page { Page_Intro, Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_Foff, Page_Rsid, Page_WebMail, Page_Email, Page_FriendRequest, Page_FriendRecommendations }; + enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_Foff, Page_Rsid, Page_WebMail, Page_Email, Page_FriendRequest, Page_FriendRecommendations }; ConnectFriendWizard(QWidget *parent = 0); ~ConnectFriendWizard(); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index 3e1f997f6..30ba3a2bd 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -6,7 +6,7 @@ 0 0 - 1134 + 1100 604 @@ -17,69 +17,6 @@ :/images/logo/logo_16.png:/images/logo/logo_16.png - - - Add a new Friend - - - This wizard will help you to connect to your friend(s) to RetroShare network.<br>Select how you would like to add a friend: - - - ConnectFriendWizard::Page_Intro - - - - - - Enter the certificate manually - - - - - - - &You get a certificate file from your friend - - - - - - - Ma&ke friend with selected friends of my friends - - - - - - - Enter RetroShare ID manually - - - - - - - Send an In&vitation by Web Mail Providers - - - - - - - &Send an Invitation by Email - (Your friend will receive an email with instructions how to download RetroShare) - - - - - - - Recommend many friends to each other - - - - - RetroShare certificate From 0c510a55e942bfd48216f5260726dce3dc9a296c Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 00:20:01 +0200 Subject: [PATCH 12/45] removed unused RsId and Fof pages from ConnectFriendWizard --- .../src/gui/connect/ConnectFriendWizard.cpp | 45 +--------- .../src/gui/connect/ConnectFriendWizard.h | 6 +- .../src/gui/connect/ConnectFriendWizard.ui | 85 ------------------- 3 files changed, 4 insertions(+), 132 deletions(-) diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index b343db718..80e4f06c9 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -416,26 +416,6 @@ void ConnectFriendWizard::initializePage(int id) ui->CertificatePage->registerField("friendCertificateFile*", ui->friendFileNameEdit); break; - case Page_Foff: - ui->userSelectionCB->addItem(tr("Any peer I've not signed")); - ui->userSelectionCB->addItem(tr("Friends of my friends who already trust me")); - ui->userSelectionCB->addItem(tr("Signed peers showing as denied")); - - ui->selectedPeersTW->setHorizontalHeaderItem(0, new QTableWidgetItem(tr(""))); - ui->selectedPeersTW->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Peer name"))); - ui->selectedPeersTW->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Also signed by"))); - ui->selectedPeersTW->setHorizontalHeaderItem(3, new QTableWidgetItem(tr("Peer id"))); - - connect(ui->makeFriendButton, SIGNAL(clicked()), this, SLOT(signAllSelectedUsers())); - connect(ui->userSelectionCB, SIGNAL(activated(int)), this, SLOT(updatePeersList(int))); - - updatePeersList(ui->userSelectionCB->currentIndex()); - - ui->FofPage->setComplete(false); - break; - case Page_Rsid: - ui->RsidPage->registerField("friendRSID*", ui->friendRsidEdit); - break; case Page_WebMail: case Page_Email: @@ -782,25 +762,6 @@ bool ConnectFriendWizard::validateCurrentPage() } break; } - case Page_Foff: - break; - case Page_Rsid: - { - QString rsidstring = ui->friendRsidEdit->text(); - - if (rsidstring.isEmpty()) { - return false; - } - - // search for peer id in string - RsPeerId rsidstr = PeerDefs::idFromRsid(rsidstring, false); - - if (rsidstr.isNull() || !rsPeers->getPeerDetails(rsidstr, peerDetails)) { - setField("errorMessage", tr("This Peer %1 is not available in your Network").arg(rsidstring)); - error = false; - } - break; - } case Page_Email: { QString mailaddresses = ui->addressEdit->text(); @@ -855,9 +816,6 @@ int ConnectFriendWizard::nextId() const switch ((Page) currentId()) { case Page_Text: case Page_Cert: - case Page_Rsid: - return error ? ConnectFriendWizard::Page_Conclusion : ConnectFriendWizard::Page_ErrorMessage; - case Page_Foff: case Page_WebMail: case Page_Email: case Page_ErrorMessage: @@ -1215,6 +1173,7 @@ void ConnectFriendWizard::generateCertificateCalled() } } +#ifdef TO_BE_REMOVED //============================= FofPage ====================================== void ConnectFriendWizard::updatePeersList(int index) @@ -1350,6 +1309,8 @@ void ConnectFriendWizard::signAllSelectedUsers() //============================= RsidPage ===================================== +#endif + //============================ Emailpage ===================================== //========================= ErrorMessagePage ================================= diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h index c4a030862..8bba0ac53 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h @@ -50,7 +50,7 @@ class ConnectFriendWizard : public QWizard Q_PROPERTY(QString titleColor READ titleColor WRITE setTitleColor) public: - enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_Foff, Page_Rsid, Page_WebMail, Page_Email, Page_FriendRequest, Page_FriendRecommendations }; + enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_WebMail, Page_Email, Page_FriendRequest, Page_FriendRecommendations }; ConnectFriendWizard(QWidget *parent = 0); ~ConnectFriendWizard(); @@ -97,10 +97,6 @@ private slots: void loadFriendCert(); void generateCertificateCalled(); - /* FofPage */ - void updatePeersList(int index); - void signAllSelectedUsers(); - /* ConclusionPage */ void groupCurrentIndexChanged(int index); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index 30ba3a2bd..a3c06f4db 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -386,91 +386,6 @@ - - - Friends of friends - - - Select now who you want to make friends with. - - - ConnectFriendWizard::Page_Foff - - - - - - Show me: - - - - - - - - - - true - - - 4 - - - false - - - - - - - - - - - Make friend with these peers - - - - - - - - RetroShare ID - - - Use RetroShare ID for adding a Friend which is available in your network. - - - ConnectFriendWizard::Page_Rsid - - - - - - Add Friends RetroShare ID... - - - true - - - - - - - - Paste Friends RetroShare ID in the box below - - - - - - - Enter the RetroShare ID of your Friend, e.g. Peer@BDE8D16A46D938CF - - - - - RetroShare is better with Friends From c0436b781c551b102382c2786f113d4953e35d85 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 00:22:57 +0200 Subject: [PATCH 13/45] removed unused Email page from ConnectFriendWizard --- .../src/gui/connect/ConnectFriendWizard.cpp | 34 +---------- .../src/gui/connect/ConnectFriendWizard.h | 2 +- .../src/gui/connect/ConnectFriendWizard.ui | 56 +------------------ 3 files changed, 4 insertions(+), 88 deletions(-) diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 80e4f06c9..cf36b25d9 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -418,22 +418,6 @@ void ConnectFriendWizard::initializePage(int id) break; case Page_WebMail: - case Page_Email: - { - ui->EmailPage->registerField("addressEdit*", ui->addressEdit); - ui->EmailPage->registerField("subjectEdit*", ui->subjectEdit); - - ui->subjectEdit->setText(tr("RetroShare Invitation")); - ui->inviteTextEdit->setPlainText(GetStartedDialog::GetInviteText()); - - QString body = ui->inviteTextEdit->toPlainText(); - - body += "\n" + GetStartedDialog::GetCutBelowText(); - body += "\n\n" + QString::fromUtf8(rsPeers->GetRetroshareInvite().c_str()); - - ui->inviteTextEdit->setPlainText(body); - } - break; case Page_ErrorMessage: break; case Page_Conclusion: @@ -762,21 +746,6 @@ bool ConnectFriendWizard::validateCurrentPage() } break; } - case Page_Email: - { - QString mailaddresses = ui->addressEdit->text(); - if (mailaddresses.isEmpty()) { - return false; - } - - QString body = ui->inviteTextEdit->toPlainText(); - - body += "\n" + GetStartedDialog::GetCutBelowText(); - body += "\n\n" + QString::fromUtf8(rsPeers->GetRetroshareInvite().c_str()); - - sendMail (mailaddresses, ui->subjectEdit->text(), body); - } - break; case Page_ErrorMessage: break; case Page_Conclusion: @@ -817,7 +786,6 @@ int ConnectFriendWizard::nextId() const case Page_Text: case Page_Cert: case Page_WebMail: - case Page_Email: case Page_ErrorMessage: case Page_Conclusion: case Page_FriendRequest: @@ -1309,9 +1277,9 @@ void ConnectFriendWizard::signAllSelectedUsers() //============================= RsidPage ===================================== -#endif //============================ Emailpage ===================================== +#endif //========================= ErrorMessagePage ================================= diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h index 8bba0ac53..96778eb49 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h @@ -50,7 +50,7 @@ class ConnectFriendWizard : public QWizard Q_PROPERTY(QString titleColor READ titleColor WRITE setTitleColor) public: - enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_WebMail, Page_Email, Page_FriendRequest, Page_FriendRecommendations }; + enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_WebMail, Page_FriendRequest, Page_FriendRecommendations }; ConnectFriendWizard(QWidget *parent = 0); ~ConnectFriendWizard(); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index a3c06f4db..8ac6543f9 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -6,8 +6,8 @@ 0 0 - 1100 - 604 + 1161 + 817 @@ -577,58 +577,6 @@ - - - Invite Friends by Email - - - Enter your friends' email addresses (separate each one with a semicolon) - - - ConnectFriendWizard::Page_Email - - - - - - - - Your friends' email addresses: - - - - - - - Enter Friends Email addresses - - - - - - - - - - - Subject: - - - - - - - - - - - - true - - - - - Friend request From a55e8241edea7f41e33f389d0e5d49f0aebe85ac Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 00:29:22 +0200 Subject: [PATCH 14/45] removed unused FriendRequest page from ConnectFriendWizard --- .../src/gui/connect/ConnectFriendWizard.cpp | 82 +----- .../src/gui/connect/ConnectFriendWizard.h | 2 +- .../src/gui/connect/ConnectFriendWizard.ui | 233 +----------------- 3 files changed, 9 insertions(+), 308 deletions(-) diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index cf36b25d9..a55b4fa55 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -147,14 +147,14 @@ ConnectFriendWizard::ConnectFriendWizard(QWidget *parent) : switch (rsFiles->filePermDirectDL()) { case RS_FILE_PERM_DIRECT_DL_YES: - ui->_direct_transfer_CB->setIcon(QIcon(":/icons/warning_yellow_128.png")); - ui->_direct_transfer_CB->setToolTip(ui->_direct_transfer_CB->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to Yes."))); +// ui->_direct_transfer_CB->setIcon(QIcon(":/icons/warning_yellow_128.png")); +// ui->_direct_transfer_CB->setToolTip(ui->_direct_transfer_CB->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to Yes."))); ui->_direct_transfer_CB_2->setIcon(QIcon(":/icons/warning_yellow_128.png")); ui->_direct_transfer_CB_2->setToolTip(ui->_direct_transfer_CB_2->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to Yes."))); break ; case RS_FILE_PERM_DIRECT_DL_NO: - ui->_direct_transfer_CB->setIcon(QIcon(":/icons/warning_yellow_128.png")); - ui->_direct_transfer_CB->setToolTip(ui->_direct_transfer_CB->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to No."))); +// ui->_direct_transfer_CB->setIcon(QIcon(":/icons/warning_yellow_128.png")); +// ui->_direct_transfer_CB->setToolTip(ui->_direct_transfer_CB->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to No."))); ui->_direct_transfer_CB_2->setIcon(QIcon(":/icons/warning_yellow_128.png")); ui->_direct_transfer_CB_2->setToolTip(ui->_direct_transfer_CB_2->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to No."))); break ; @@ -571,63 +571,6 @@ void ConnectFriendWizard::initializePage(int id) } break; - case Page_FriendRequest: - { - std::cerr << "Friend request page id : " << peerDetails.id << "; gpg_id : " << peerDetails.gpg_id << std::endl; - - ui->fr_avatar->setFrameType(AvatarWidget::NORMAL_FRAME); - setPixmap(QWizard::LogoPixmap, QPixmap(":/images/user/user_request48.png")); - - ui->fr_signGPGCheckBox->setChecked(false); - - //set the radio button to sign the GPG key - if (peerDetails.accept_connection && !peerDetails.ownsign) { - //gpg key connection is already accepted, don't propose to accept it again - ui->fr_acceptNoSignGPGCheckBox->hide(); - ui->fr_signGPGCheckBox->show(); - ui->fr_acceptNoSignGPGCheckBox->setChecked(false); - } - if (!peerDetails.accept_connection && peerDetails.ownsign) { - //gpg key is already signed, don't propose to sign it again - ui->fr_acceptNoSignGPGCheckBox->setChecked(true); - ui->fr_signGPGCheckBox->hide(); - } - if (!peerDetails.accept_connection && !peerDetails.ownsign) { - ui->fr_acceptNoSignGPGCheckBox->setChecked(true); - ui->fr_signGPGCheckBox->show(); - ui->fr_acceptNoSignGPGCheckBox->show(); - } - if (peerDetails.accept_connection && peerDetails.ownsign) { - ui->fr_acceptNoSignGPGCheckBox->setChecked(false); - ui->fr_acceptNoSignGPGCheckBox->hide(); - ui->fr_signGPGCheckBox->hide(); - } - - ui->fr_nameEdit->setText(QString::fromUtf8(peerDetails.name.c_str())); - ui->fr_emailEdit->setText(QString::fromUtf8(peerDetails.email.c_str())); - - QString loc = QString::fromUtf8(peerDetails.location.c_str()); - if (!loc.isEmpty()) - { - loc += " ("; - loc += QString::fromStdString(peerDetails.id.toStdString()); - loc += ")"; - } - else - { - if (!peerDetails.id.isNull()) - { - loc += QString::fromStdString(peerDetails.id.toStdString()); - } - } - - ui->fr_nodeEdit->setText(loc); - - ui->fr_InfoTopLabel->setText(tr("You have a friend request from") + " " + QString::fromUtf8(peerDetails.name.c_str())); - - fillGroups(this, ui->fr_groupComboBox, groupId); - } - break; case Page_FriendRecommendations: ui->frec_recommendList->setHeaderText(tr("Recommend friends")); ui->frec_recommendList->setModus(FriendSelectionWidget::MODUS_CHECK); @@ -750,8 +693,6 @@ bool ConnectFriendWizard::validateCurrentPage() break; case Page_Conclusion: break; - case Page_FriendRequest: - break; case Page_FriendRecommendations: { std::set recommendIds; @@ -788,7 +729,6 @@ int ConnectFriendWizard::nextId() const case Page_WebMail: case Page_ErrorMessage: case Page_Conclusion: - case Page_FriendRequest: case Page_FriendRecommendations: return -1; } @@ -800,12 +740,7 @@ ServicePermissionFlags ConnectFriendWizard::serviceFlags() const { ServicePermissionFlags flags(0) ; - if (hasVisitedPage(Page_FriendRequest)) - { - if( ui->_direct_transfer_CB->isChecked()) flags |= RS_NODE_PERM_DIRECT_DL ; - if( ui->_allow_push_CB->isChecked()) flags |= RS_NODE_PERM_ALLOW_PUSH ; - if( ui->_require_WL_CB->isChecked()) flags |= RS_NODE_PERM_REQUIRE_WL ; - } else if (hasVisitedPage(Page_Conclusion)) { +if (hasVisitedPage(Page_Conclusion)) { if( ui->_direct_transfer_CB_2->isChecked()) flags |= RS_NODE_PERM_DIRECT_DL ; if( ui->_allow_push_CB_2->isChecked()) flags |= RS_NODE_PERM_ALLOW_PUSH ; if( ui->_require_WL_CB_2->isChecked()) flags |= RS_NODE_PERM_REQUIRE_WL ; @@ -824,12 +759,7 @@ void ConnectFriendWizard::accept() sign = ui->signGPGCheckBox->isChecked(); accept_connection = ui->acceptNoSignGPGCheckBox->isChecked(); add_key_to_keyring = ui->addKeyToKeyring_CB->isChecked() ; - } else if (hasVisitedPage(Page_FriendRequest)) { - std::cerr << "ConnectFriendWizard::accept() called with page friend request visited" << std::endl; - - sign = ui->fr_signGPGCheckBox->isChecked(); - accept_connection = ui->fr_acceptNoSignGPGCheckBox->isChecked(); - } else { + } else { QDialog::accept(); return; } diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h index 96778eb49..a5a58e4b8 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h @@ -50,7 +50,7 @@ class ConnectFriendWizard : public QWizard Q_PROPERTY(QString titleColor READ titleColor WRITE setTitleColor) public: - enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_WebMail, Page_FriendRequest, Page_FriendRecommendations }; + enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_WebMail, Page_FriendRecommendations }; ConnectFriendWizard(QWidget *parent = 0); ~ConnectFriendWizard(); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index 8ac6543f9..3fca728de 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -6,8 +6,8 @@ 0 0 - 1161 - 817 + 1100 + 604 @@ -577,229 +577,6 @@ - - - Friend request - - - Details about the request - - - ConnectFriendWizard::Page_FriendRequest - - - - 6 - - - 6 - - - - - - - - You have a friend request from - - - - - - - - - - 96 - 96 - - - - - 96 - 96 - - - - - - - - Peer details - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Name: - - - - - - - Name - - - - - - - Email: - - - - - - - Node: - - - - - - - Node - - - - - - - Email - - - - - - - - - - - - - - Options - - - - - - - - - 0 - 0 - - - - Add friend to group: - - - - - - - - 0 - 0 - - - - - - - - - - Authenticate friend (Sign PGP Key) - - - - - - - Add as friend to connect with - - - - - - - - - - Options - - - - - - Use as direct source, when available - - - - - - - Auto-download recommended files - - - - - - - Require whitelist clearance to connect - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - To accept the Friend Request, click the Finish button. - - - - - - - Qt::Vertical - - - - 488 - 118 - - - - - - Sorry, some error appeared @@ -1302,12 +1079,6 @@ - - AvatarWidget - QLabel -
    gui/common/AvatarWidget.h
    - 1 -
    StyledLabel QLabel From a04079daa0b444a73b2909e68b8179ae4c81d1e8 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 00:36:40 +0200 Subject: [PATCH 15/45] removed unused Cert page from ConnectFriendWizard --- .../src/gui/connect/ConnectFriendWizard.cpp | 92 +------------ .../src/gui/connect/ConnectFriendWizard.h | 6 +- .../src/gui/connect/ConnectFriendWizard.ui | 128 ------------------ 3 files changed, 5 insertions(+), 221 deletions(-) diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index a55b4fa55..775dcc32e 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -84,7 +84,7 @@ ConnectFriendWizard::ConnectFriendWizard(QWidget *parent) : // (csoler) I'm hiding this, since it is not needed anymore with the new Home page. ui->userFrame->hide(); - ui->userFileFrame->hide(); // in homepage dropmenu now +// ui->userFileFrame->hide(); // in homepage dropmenu now // this define comes from Qt example. I don't have mac, so it wasn't tested #ifndef Q_OS_MAC @@ -407,14 +407,6 @@ void ConnectFriendWizard::initializePage(int id) cleanFriendCert(); - break; - case Page_Cert: - connect(ui->userFileCreateButton, SIGNAL(clicked()), this, SLOT(generateCertificateCalled())); - connect(ui->friendFileNameOpenButton, SIGNAL(clicked()), this, SLOT(loadFriendCert())); - - ui->friendFileNameEdit->setAcceptFile(true); - - ui->CertificatePage->registerField("friendCertificateFile*", ui->friendFileNameEdit); break; case Page_WebMail: @@ -571,18 +563,6 @@ void ConnectFriendWizard::initializePage(int id) } break; - case Page_FriendRecommendations: - ui->frec_recommendList->setHeaderText(tr("Recommend friends")); - ui->frec_recommendList->setModus(FriendSelectionWidget::MODUS_CHECK); - ui->frec_recommendList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL); - ui->frec_recommendList->start(); - - ui->frec_toList->setHeaderText(tr("To")); - ui->frec_toList->setModus(FriendSelectionWidget::MODUS_CHECK); - ui->frec_toList->start(); - - ui->frec_messageEdit->setText(MessageComposer::recommendMessage()); - break; } } @@ -646,76 +626,10 @@ bool ConnectFriendWizard::validateCurrentPage() error = false; break; } - case Page_Cert: - { - QString fn = ui->friendFileNameEdit->text(); - if (QFile::exists(fn)) { - //Todo: move read from file to p3Peers::loadCertificateFromFile - - // read from file - std::string certstr; - QFile CertFile(fn); - if (CertFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - certstr = QString(CertFile.readAll()).toStdString(); - CertFile.close(); - } - - if (certstr.empty()) { - setField("errorMessage", QString(tr("Certificate Load Failed:can't read from file %1")).arg(fn+" ") ); - error = false; - break; - } - - uint32_t cert_error_code; - if (rsPeers->loadDetailsFromStringCert(certstr, peerDetails, cert_error_code) || rsPeers->parseShortInvite(certstr,peerDetails)) - { - mCertificate = certstr; -#ifdef FRIEND_WIZARD_DEBUG - std::cerr << "ConnectFriendWizard got id : " << peerDetails.id << "; gpg_id : " << peerDetails.gpg_id << std::endl; -#endif - - if(peerDetails.id == rsPeers->getOwnId()) - { - setField("errorMessage", tr("This is your own certificate! You would not want to make friend with yourself. Wouldn't you?") ) ; - error = false; - } - } else { - setField("errorMessage", QString(tr("Certificate Load Failed:something is wrong with %1")).arg(fn) + " : " + getErrorString(cert_error_code)); - error = false; - } - } else { - setField("errorMessage", QString(tr("Certificate Load Failed:file %1 not found")).arg(fn)); - error = false; - } - break; - } case Page_ErrorMessage: break; case Page_Conclusion: break; - case Page_FriendRecommendations: - { - std::set recommendIds; - ui->frec_recommendList->selectedIds(recommendIds, false); - - if (recommendIds.empty()) { - QMessageBox::warning(this, "RetroShare", tr("Please select at least one friend for recommendation."), QMessageBox::Ok, QMessageBox::Ok); - return false; - } - - std::set toIds; - ui->frec_toList->selectedIds(toIds, false); - - if (toIds.empty()) { - QMessageBox::warning(this, "RetroShare", tr("Please select at least one friend as recipient."), QMessageBox::Ok, QMessageBox::Ok); - return false; - } - - std::set::iterator toId; - for (toId = toIds.begin(); toId != toIds.end(); ++toId) { - MessageComposer::recommendFriend(recommendIds, *toId, ui->frec_messageEdit->toHtml(), true); - } - } } return true; @@ -725,11 +639,9 @@ int ConnectFriendWizard::nextId() const { switch ((Page) currentId()) { case Page_Text: - case Page_Cert: case Page_WebMail: case Page_ErrorMessage: case Page_Conclusion: - case Page_FriendRecommendations: return -1; } @@ -1027,6 +939,7 @@ void ConnectFriendWizard::saveCert() ts << ui->userCertEdit->document()->toPlainText(); } +#ifdef TO_BE_REMOVED //========================== CertificatePage ================================= void ConnectFriendWizard::loadFriendCert() @@ -1071,7 +984,6 @@ void ConnectFriendWizard::generateCertificateCalled() } } -#ifdef TO_BE_REMOVED //============================= FofPage ====================================== void ConnectFriendWizard::updatePeersList(int index) diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h index a5a58e4b8..39e8dcabb 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h @@ -50,7 +50,7 @@ class ConnectFriendWizard : public QWizard Q_PROPERTY(QString titleColor READ titleColor WRITE setTitleColor) public: - enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_WebMail, Page_FriendRecommendations }; + enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_WebMail }; ConnectFriendWizard(QWidget *parent = 0); ~ConnectFriendWizard(); @@ -94,8 +94,8 @@ private slots: ServicePermissionFlags serviceFlags() const ; /* CertificatePage */ - void loadFriendCert(); - void generateCertificateCalled(); + //void loadFriendCert(); + //void generateCertificateCalled(); /* ConclusionPage */ void groupCurrentIndexChanged(int index); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index 3fca728de..efaae261c 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -323,69 +323,6 @@ - - - Certificate files - - - Use PGP certificates saved in files. - - - ConnectFriendWizard::Page_Cert - - - - - - Import friend's certificate... - - - true - - - - - - You have to generate a file with your certificate and give it to your friend. Also, you can use a file generated before. - - - true - - - - - - - Export my certificate... - - - - - - - - - - Drag and Drop your friends's certificate in this Window or specify path in the box below - - - - - - - - - - - - Browse - - - - - - - RetroShare is better with Friends @@ -1023,60 +960,6 @@ - - - Friend Recommendations - - - Recommend many friends to each others - - - ConnectFriendWizard::Page_FriendRecommendations - - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - - - - - - Message: - - - - - - - - 0 - 0 - - - - - - @@ -1084,17 +967,6 @@ QLabel
    gui/common/StyledLabel.h
    - - FriendSelectionWidget - QWidget -
    gui/common/FriendSelectionWidget.h
    - 1 -
    - - DropLineEdit - QLineEdit -
    gui/common/DropLineEdit.h
    -
    ConnectFriendPage QWizardPage From 1f56ef310a300b34c608e4efb298ce08e6a28319 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 00:37:13 +0200 Subject: [PATCH 16/45] removed unused Cert page from ConnectFriendWizard --- retroshare-gui/src/gui/connect/ConnectFriendWizard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h index 39e8dcabb..44ebcacd7 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h @@ -50,7 +50,7 @@ class ConnectFriendWizard : public QWizard Q_PROPERTY(QString titleColor READ titleColor WRITE setTitleColor) public: - enum Page { Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion, Page_WebMail }; + enum Page { Page_Text, Page_ErrorMessage, Page_Conclusion, Page_WebMail }; ConnectFriendWizard(QWidget *parent = 0); ~ConnectFriendWizard(); From 38434f2d550035bc17577f6877d3694c106eb15d Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 00:38:11 +0200 Subject: [PATCH 17/45] removed unused Cert page from ConnectFriendWizard --- retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 775dcc32e..f77c533c6 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -91,7 +91,7 @@ ConnectFriendWizard::ConnectFriendWizard(QWidget *parent) : setWizardStyle(ModernStyle); #endif - setStartId(Page_Cert); + setStartId(Page_Text); // at this moment I don't know, what information should be in help // setOption(HaveHelpButton, true); From 57a548531cfb46a120694ce080b44e8425375dbe Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Jun 2019 15:15:15 +0200 Subject: [PATCH 18/45] fixed adding friend with short invite --- libretroshare/src/rsserver/p3peers.cc | 2 ++ .../src/gui/connect/ConnectFriendWizard.cpp | 31 +++++++++++-------- .../src/gui/connect/ConnectFriendWizard.h | 20 ++++++------ .../src/gui/connect/ConnectFriendWizard.ui | 6 ++-- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 02615d9e6..70db57b5c 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1360,6 +1360,8 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d details.hasSignedMe = pgp_det.hasSignedMe; details.accept_connection = pgp_det.accept_connection; } + else + details.skip_signature_validation = true; return ctx.mOk; } diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index f77c533c6..48de3b6a2 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -129,6 +129,8 @@ ConnectFriendWizard::ConnectFriendWizard(QWidget *parent) : body += "\n" + GetStartedDialog::GetCutBelowText(); body += "\n\n" + QString::fromUtf8(rsPeers->GetRetroshareInvite().c_str()); + mIsShortInvite = false; + std::string advsetting; if(rsConfig->getConfigurationOption(RS_CONFIG_ADVANCED, advsetting) && (advsetting == "YES")) { @@ -147,14 +149,10 @@ ConnectFriendWizard::ConnectFriendWizard(QWidget *parent) : switch (rsFiles->filePermDirectDL()) { case RS_FILE_PERM_DIRECT_DL_YES: -// ui->_direct_transfer_CB->setIcon(QIcon(":/icons/warning_yellow_128.png")); -// ui->_direct_transfer_CB->setToolTip(ui->_direct_transfer_CB->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to Yes."))); ui->_direct_transfer_CB_2->setIcon(QIcon(":/icons/warning_yellow_128.png")); ui->_direct_transfer_CB_2->setToolTip(ui->_direct_transfer_CB_2->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to Yes."))); break ; case RS_FILE_PERM_DIRECT_DL_NO: -// ui->_direct_transfer_CB->setIcon(QIcon(":/icons/warning_yellow_128.png")); -// ui->_direct_transfer_CB->setToolTip(ui->_direct_transfer_CB->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to No."))); ui->_direct_transfer_CB_2->setIcon(QIcon(":/icons/warning_yellow_128.png")); ui->_direct_transfer_CB_2->setToolTip(ui->_direct_transfer_CB_2->toolTip().append(tr("\nWarning: In your File-Transfer option, you select allow direct download to No."))); break ; @@ -309,6 +307,8 @@ void ConnectFriendWizard::setCertificate(const QString &certificate, bool friend } else if(rsPeers->parseShortInvite(certificate.toUtf8().constData(),peerDetails)) { + mIsShortInvite = true; + if(peerDetails.id == rsPeers->getOwnId()) { setField("errorMessage", tr("This is your own certificate! You would not want to make friend with yourself. Wouldn't you?") ) ; @@ -638,7 +638,7 @@ bool ConnectFriendWizard::validateCurrentPage() int ConnectFriendWizard::nextId() const { switch ((Page) currentId()) { - case Page_Text: + case Page_Text: return Page_Conclusion; case Page_WebMail: case Page_ErrorMessage: case Page_Conclusion: @@ -676,7 +676,9 @@ void ConnectFriendWizard::accept() return; } - if(!peerDetails.skip_signature_validation && !mCertificate.empty() && add_key_to_keyring) + // add the profile pgp key to keyring + + if(!mIsShortInvite && !mCertificate.empty() && add_key_to_keyring) { RsPgpId pgp_id ; RsPeerId ssl_id ; @@ -691,6 +693,11 @@ void ConnectFriendWizard::accept() bool runProgressDialog = false; + // add the peer as friend, either with or without pgp signature validation, depending on whether we have the key or not + // Note: that is different than having a short invite or not. + + // first, set data related to profile key. + if(accept_connection && !peerDetails.gpg_id.isNull()) { std::cerr << "ConclusionPage::validatePage() accepting GPG key for connection." << std::endl; @@ -723,6 +730,8 @@ void ConnectFriendWizard::accept() rsPeers->assignPeerToGroup(RsNodeGroupId(groupId.toStdString()), peerDetails.gpg_id, true); } + // Then set data related to node location + if ((accept_connection) && (!peerDetails.id.isNull())) { runProgressDialog = true; @@ -753,9 +762,7 @@ void ConnectFriendWizard::accept() rsPeers->setDynDNS(peerDetails.id, peerDetails.dyndns); } for(auto&& ipr : peerDetails.ipAddressList) - rsPeers->addPeerLocator( - peerDetails.id, - RsUrl(ipr.substr(0, ipr.find(' '))) ); + rsPeers->addPeerLocator( peerDetails.id, RsUrl(ipr.substr(0, ipr.find(' '))) ); } } @@ -768,7 +775,6 @@ void ConnectFriendWizard::accept() } NotifyQt::getInstance()->notifyListChange(NOTIFY_LIST_NEIGHBOURS,1) ; - QDialog::accept(); } @@ -841,9 +847,8 @@ void ConnectFriendWizard::cleanFriendCert() } else { std::string cleanCert; int error_code; - bool is_short_format; - if (rsPeers->cleanCertificate(cert, cleanCert, is_short_format, error_code)) + if (rsPeers->cleanCertificate(cert, cleanCert, mIsShortInvite, error_code)) { certValid = true; @@ -856,7 +861,7 @@ void ConnectFriendWizard::cleanFriendCert() ui->friendCertCleanLabel->setStyleSheet(""); } - errorMsg = tr("Valid certificate") + (is_short_format?" (Short format)":" (plain format with profile key)"); + errorMsg = tr("Valid certificate") + (mIsShortInvite?" (Short format)":" (plain format with profile key)"); ui->friendCertCleanLabel->setPixmap(QPixmap(":/images/accepted16.png")); } else { diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h index 44ebcacd7..5951fd7c2 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.h +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.h @@ -99,13 +99,13 @@ private slots: /* ConclusionPage */ void groupCurrentIndexChanged(int index); - + /* WebMailPage */ - void inviteGmail(); - void inviteYahoo(); - void inviteOutlook(); - void inviteAol(); - void inviteYandex(); + void inviteGmail(); + void inviteYahoo(); + void inviteOutlook(); + void inviteAol(); + void inviteYandex(); void toggleAdvanced(); @@ -115,12 +115,14 @@ private: void updateStylesheet(); void setTitleText(QWizardPage *page, const QString &title); bool AdvancedVisible; - + private: bool error; RsPeerDetails peerDetails; std::string mCertificate; + bool mIsShortInvite; + /* Stylesheet */ QString mBannerPixmap; int mTitleFontSize; @@ -137,9 +139,9 @@ private: /* ConclusionPage */ QString groupId; - + /* WebMailPage */ - QString subject; + QString subject; QString body; Ui::ConnectFriendWizard *ui; diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index efaae261c..8aadc22db 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -6,8 +6,8 @@ 0 0 - 1100 - 604 + 1139 + 1171 @@ -817,7 +817,7 @@ - <html><head/><body><p align="justify">Retroshare periodically checks your friend lists for browsable files matching your transfers, to establish a direct transfer. In this case, your friend knows you're downloading the file.</p><p align="justify">To prevent this behavior for this friend only, uncheck this box. You can still perform a direct transfer if you explicitly ask for it, by e.g. downloading from your friend's file list. This setting is applied to all locations of the same node.</p></body></html> + <html><head/><body><p align="justify">Retroshare periodically checks your friend lists for browsable files matching your transfers, to establish a direct transfer. In this case, your friend knows you're downloading the file.</p><p align="justify">To prevent this behavior for this friend only, uncheck this box. You can still perform a direct transfer if you explicitly ask for it, by e.g. downloading from your friend's file list. This setting is applied to all nodes with the same profile key.</p></body></html> Can be used as direct source From 805f7537279f5421d9c81016cacc44d07a423b2d Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 20 Jun 2019 21:59:56 +0200 Subject: [PATCH 19/45] fixed parsing of short invite --- libretroshare/src/rsserver/p3peers.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 70db57b5c..aaf3097a5 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1268,6 +1268,8 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d case RsShortInviteFieldType::PGP_FINGERPRINT: RS_SERIAL_PROCESS(details.fpr); + + details.gpg_id = PGPHandler::pgpIdFromFingerprint(details.fpr); break; case RsShortInviteFieldType::LOCATOR: @@ -1342,6 +1344,7 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d default: RsWarn() << __PRETTY_FUNCTION__ << " got unkown field type: " << static_cast(fieldType) << std::endl; + return false; break; } } From 6114d97c36e0c13c785766ef8afcab5427b93cdb Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 20 Jun 2019 22:07:08 +0200 Subject: [PATCH 20/45] removed CIRCLES-related dead code from friendlist --- retroshare-gui/src/gui/FriendsDialog.cpp | 8 -------- retroshare-gui/src/gui/FriendsDialog.h | 7 +------ 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index 545c75915..d121c4be4 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -44,16 +44,12 @@ #include "NetworkView.h" #include "NetworkDialog.h" #include "gui/Identity/IdDialog.h" -#ifdef RS_USE_CIRCLES -#include "gui/Circles/CirclesDialog.h" -#endif /* Images for Newsfeed icons */ //#define IMAGE_NEWSFEED "" //#define IMAGE_NEWSFEED_NEW ":/images/message-state-new.png" #define IMAGE_NETWORK2 ":/icons/png/netgraph.png" #define IMAGE_PEERS ":/icons/png/keyring.png" #define IMAGE_IDENTITY ":/images/identity/identities_32.png" -//#define IMAGE_CIRCLES ":/icons/png/circles.png" /****** * #define FRIENDS_DEBUG 1 @@ -192,10 +188,6 @@ void FriendsDialog::activatePage(FriendsDialog::Page page) { case FriendsDialog::IdTab: ui.tabWidget->setCurrentWidget(idDialog) ; break ; -#ifdef RS_USE_CIRCLES - case FriendsDialog::CirclesTab: ui.tabWidget->setCurrentWidget(circlesDialog) ; - break ; -#endif case FriendsDialog::NetworkTab: ui.tabWidget->setCurrentWidget(networkDialog) ; break ; case FriendsDialog::BroadcastTab: ui.tabWidget->setCurrentWidget(networkDialog) ; diff --git a/retroshare-gui/src/gui/FriendsDialog.h b/retroshare-gui/src/gui/FriendsDialog.h index 8383b18e4..7613e83d0 100644 --- a/retroshare-gui/src/gui/FriendsDialog.h +++ b/retroshare-gui/src/gui/FriendsDialog.h @@ -41,9 +41,7 @@ public: enum Page { /* Fixed numbers for load and save the last page */ IdTab = 0, /** Identities page. */ -#ifdef RS_USE_CIRCLES - CirclesTab = 1, /** Circles page. */ -#endif + // CirclesTab = 1, /** Circles page - DEPRECATED - please keep the numbering. */ NetworkTab = 2, /** Network page. */ NetworkViewTab = 3, /** Network new graph. */ BroadcastTab = 4 /** Old group chat page. */ @@ -71,9 +69,6 @@ public: NetworkDialog *networkDialog ; NetworkView *networkView ; -#ifdef RS_USE_CIRCLES - CirclesDialog *circlesDialog; -#endif IdDialog *idDialog; protected: From e132ce7072617bb50c4dc697f8db833afdd1f1cf Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 20 Jun 2019 23:09:40 +0200 Subject: [PATCH 21/45] attempt to add SSL-only friends in FriendList - does not work yet --- libretroshare/src/rsserver/p3peers.cc | 13 ++++++++++++- retroshare-gui/src/gui/common/FriendList.cpp | 19 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index aaf3097a5..699e7d540 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -295,7 +295,18 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) /* get from gpg (first), to fill in the sign and trust details */ /* don't return now, we've got fill in the ssl and connection info */ - getGPGDetails(ps.gpg_id, d); + + if(!getGPGDetails(ps.gpg_id, d)) + { + if(!ps.skip_pgp_signature_validation) + return false; + + d.gpg_id = ps.gpg_id ; + d.skip_signature_validation = true; + } + else + d.skip_signature_validation = false; + d.isOnlyGPGdetail = false; //get the ssl details diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index c496bb79e..7af5e68e4 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -592,7 +592,8 @@ void FriendList::insertPeers() std::list::iterator gpgIt; rsPeers->getGPGAcceptedList(gpgFriends); - //add own gpg id, if we have more than on node (ssl client) + // add own gpg id, if we have more than on node (ssl client) + std::list ownSslContacts; RsPgpId ownId = rsPeers->getGPGOwnId(); rsPeers->getAssociatedSSLIds(ownId, ownSslContacts); @@ -600,6 +601,22 @@ void FriendList::insertPeers() gpgFriends.push_back(ownId); } + // Also add SSL peers which PGP key is not available yet. + + std::list ssl_friends ; + rsPeers->getFriendList(ssl_friends); + + std::cerr << "List of accepted ssl peers: " << std::endl; + for(auto it(ssl_friends.begin());it!=ssl_friends.end();++it) + { + RsPeerDetails pd; + if(rsPeers->getPeerDetails(*it,pd) && pd.skip_signature_validation) + { + std::cerr << " adding " << *it << " - " << pd.gpg_id << std::endl; + gpgFriends.push_back(pd.gpg_id); + } + } + /* get a link to the table */ QTreeWidget *peerTreeWidget = ui->peerTreeWidget; From 9312d0cb3af5cea36b03eebe56982bc229a3ee02 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 21 Jun 2019 23:30:06 +0200 Subject: [PATCH 22/45] converted short invites to compact PGP format for increased robustness --- libretroshare/src/pgp/rscertificate.cc | 6 +- libretroshare/src/pgp/rscertificate.h | 4 +- libretroshare/src/retroshare/rspeers.h | 58 ++-- libretroshare/src/rsserver/p3peers.cc | 277 ++++++++++-------- libretroshare/src/rsserver/p3peers.h | 5 +- .../src/gui/connect/ConnectFriendWizard.cpp | 6 +- 6 files changed, 187 insertions(+), 169 deletions(-) diff --git a/libretroshare/src/pgp/rscertificate.cc b/libretroshare/src/pgp/rscertificate.cc index fff50fd61..f3007bb01 100644 --- a/libretroshare/src/pgp/rscertificate.cc +++ b/libretroshare/src/pgp/rscertificate.cc @@ -552,13 +552,13 @@ unsigned short RsCertificate::loc_port_us() const return (int)ipv4_internal_ip_and_port[4]*256 + (int)ipv4_internal_ip_and_port[5] ; } -bool RsCertificate::cleanCertificate( const std::string& input, std::string& output, Format& format, int& error_code, bool check_content ) +bool RsCertificate::cleanCertificate( const std::string& input, std::string& output, Format& format, uint32_t& error_code, bool check_content ) { if(cleanRadix64(input,output,error_code)) { RsPeerDetails details; - if(rsPeers->parseShortInvite(output,details)) + if(rsPeers->parseShortInvite(output,details,error_code)) { format = RS_CERTIFICATE_SHORT_RADIX; return true; @@ -584,7 +584,7 @@ std::string RsCertificate::armouredPGPKey() const // Yeah, this is simple, and that is what's good about the radix format. Can't be broken ;-) // -bool RsCertificate::cleanRadix64(const std::string& instr,std::string& str,int& error_code) +bool RsCertificate::cleanRadix64(const std::string& instr,std::string& str,uint32_t& error_code) { error_code = RS_PEER_CERT_CLEANING_CODE_NO_ERROR ; diff --git a/libretroshare/src/pgp/rscertificate.h b/libretroshare/src/pgp/rscertificate.h index 2d506d03f..1ba3db633 100644 --- a/libretroshare/src/pgp/rscertificate.h +++ b/libretroshare/src/pgp/rscertificate.h @@ -84,7 +84,7 @@ public: static bool cleanCertificate( const std::string& input, std::string& output, - RsCertificate::Format& format, int& error_code, bool check_content); + RsCertificate::Format& format, uint32_t& error_code, bool check_content); const std::set& locators() const { return mLocators; } @@ -99,7 +99,7 @@ public: private: // new radix format - static bool cleanRadix64( const std::string& input, std::string& output, int&); + static bool cleanRadix64(const std::string& input, std::string& output, uint32_t &); static void scan_ip( const std::string& ip_string, unsigned short port, unsigned char *destination_memory ); diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 7e2bc898b..b9076208b 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -130,6 +130,8 @@ const uint32_t CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR = 0x16 ; const uint32_t CERTIFICATE_PARSING_ERROR_UNKNOWN_SECTION_PTAG = 0x17 ; const uint32_t CERTIFICATE_PARSING_ERROR_MISSING_CHECKSUM = 0x18 ; const uint32_t CERTIFICATE_PARSING_ERROR_WRONG_VERSION = 0x19 ; +const uint32_t CERTIFICATE_PARSING_ERROR_MISSING_PGP_FINGERPRINT = 0x1a ; +const uint32_t CERTIFICATE_PARSING_ERROR_MISSING_LOCATION_ID = 0x1b ; const uint32_t PGP_KEYRING_REMOVAL_ERROR_NO_ERROR = 0x20 ; const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANT_REMOVE_SECRET_KEYS = 0x21 ; @@ -140,40 +142,40 @@ const uint32_t PGP_KEYRING_REMOVAL_ERROR_DATA_INCONSISTENCY = 0x24 ; /* LinkType Flags */ // CONNECTION -const uint32_t RS_NET_CONN_TRANS_MASK = 0x0000ffff; -const uint32_t RS_NET_CONN_TRANS_TCP_MASK = 0x0000000f; -const uint32_t RS_NET_CONN_TRANS_TCP_UNKNOWN = 0x00000001; -const uint32_t RS_NET_CONN_TRANS_TCP_LOCAL = 0x00000002; -const uint32_t RS_NET_CONN_TRANS_TCP_EXTERNAL = 0x00000004; +const uint32_t RS_NET_CONN_TRANS_MASK = 0x0000ffff; +const uint32_t RS_NET_CONN_TRANS_TCP_MASK = 0x0000000f; +const uint32_t RS_NET_CONN_TRANS_TCP_UNKNOWN = 0x00000001; +const uint32_t RS_NET_CONN_TRANS_TCP_LOCAL = 0x00000002; +const uint32_t RS_NET_CONN_TRANS_TCP_EXTERNAL = 0x00000004; -const uint32_t RS_NET_CONN_TRANS_UDP_MASK = 0x000000f0; -const uint32_t RS_NET_CONN_TRANS_UDP_UNKNOWN = 0x00000010; -const uint32_t RS_NET_CONN_TRANS_UDP_DIRECT = 0x00000020; -const uint32_t RS_NET_CONN_TRANS_UDP_PROXY = 0x00000040; -const uint32_t RS_NET_CONN_TRANS_UDP_RELAY = 0x00000080; +const uint32_t RS_NET_CONN_TRANS_UDP_MASK = 0x000000f0; +const uint32_t RS_NET_CONN_TRANS_UDP_UNKNOWN = 0x00000010; +const uint32_t RS_NET_CONN_TRANS_UDP_DIRECT = 0x00000020; +const uint32_t RS_NET_CONN_TRANS_UDP_PROXY = 0x00000040; +const uint32_t RS_NET_CONN_TRANS_UDP_RELAY = 0x00000080; -const uint32_t RS_NET_CONN_TRANS_OTHER_MASK = 0x00000f00; +const uint32_t RS_NET_CONN_TRANS_OTHER_MASK = 0x00000f00; -const uint32_t RS_NET_CONN_TRANS_UNKNOWN = 0x00001000; +const uint32_t RS_NET_CONN_TRANS_UNKNOWN = 0x00001000; -const uint32_t RS_NET_CONN_SPEED_MASK = 0x000f0000; -const uint32_t RS_NET_CONN_SPEED_UNKNOWN = 0x00000000; -const uint32_t RS_NET_CONN_SPEED_TRICKLE = 0x00010000; -const uint32_t RS_NET_CONN_SPEED_LOW = 0x00020000; -const uint32_t RS_NET_CONN_SPEED_NORMAL = 0x00040000; -const uint32_t RS_NET_CONN_SPEED_HIGH = 0x00080000; +const uint32_t RS_NET_CONN_SPEED_MASK = 0x000f0000; +const uint32_t RS_NET_CONN_SPEED_UNKNOWN = 0x00000000; +const uint32_t RS_NET_CONN_SPEED_TRICKLE = 0x00010000; +const uint32_t RS_NET_CONN_SPEED_LOW = 0x00020000; +const uint32_t RS_NET_CONN_SPEED_NORMAL = 0x00040000; +const uint32_t RS_NET_CONN_SPEED_HIGH = 0x00080000; -const uint32_t RS_NET_CONN_QUALITY_MASK = 0x00f00000; -const uint32_t RS_NET_CONN_QUALITY_UNKNOWN = 0x00000000; +const uint32_t RS_NET_CONN_QUALITY_MASK = 0x00f00000; +const uint32_t RS_NET_CONN_QUALITY_UNKNOWN = 0x00000000; // THIS INFO MUST BE SUPPLIED BY PEERMGR.... -const uint32_t RS_NET_CONN_TYPE_MASK = 0x0f000000; -const uint32_t RS_NET_CONN_TYPE_UNKNOWN = 0x00000000; -const uint32_t RS_NET_CONN_TYPE_ACQUAINTANCE = 0x01000000; -const uint32_t RS_NET_CONN_TYPE_FRIEND = 0x02000000; -const uint32_t RS_NET_CONN_TYPE_SERVER = 0x04000000; -const uint32_t RS_NET_CONN_TYPE_CLIENT = 0x08000000; +const uint32_t RS_NET_CONN_TYPE_MASK = 0x0f000000; +const uint32_t RS_NET_CONN_TYPE_UNKNOWN = 0x00000000; +const uint32_t RS_NET_CONN_TYPE_ACQUAINTANCE = 0x01000000; +const uint32_t RS_NET_CONN_TYPE_FRIEND = 0x02000000; +const uint32_t RS_NET_CONN_TYPE_SERVER = 0x04000000; +const uint32_t RS_NET_CONN_TYPE_CLIENT = 0x08000000; // working state of proxy @@ -685,7 +687,7 @@ public: * @return false if error occurred, true otherwise */ virtual bool parseShortInvite( - const std::string& invite, RsPeerDetails& details ) = 0; + const std::string& invite, RsPeerDetails& details,uint32_t& err_code ) = 0; /** * @brief Add trusted node from invite @@ -731,7 +733,7 @@ public: uint32_t& errorCode ) = 0; // Certificate utils - virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,int& error_code) = 0; + virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,uint32_t& error_code) = 0; virtual bool saveCertificateToFile(const RsPeerId& id, const std::string &fname) = 0; virtual std::string saveCertificateToString(const RsPeerId &id) = 0; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 699e7d540..013f67e0d 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -41,15 +41,8 @@ #include #include -const std::string CERT_SSL_ID = "--SSLID--"; -const std::string CERT_LOCATION = "--LOCATION--"; -const std::string CERT_LOCAL_IP = "--LOCAL--"; -const std::string CERT_EXT_IP = "--EXT--"; -const std::string CERT_DYNDNS = "--DYNDNS--"; - //static const int MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT = 30*24*3600 ; // 30 days. - #include "pqi/authssl.h" @@ -1147,9 +1140,31 @@ enum class RsShortInviteFieldType : uint8_t * trasport layer will be implemented */ HIDDEN_LOCATOR = 0x90, DNS_LOCATOR = 0x91, - EXT4_LOCATOR = 0x92, + EXT4_LOCATOR = 0x92 }; +static void addPacketHeader(RsShortInviteFieldType ptag, size_t size, unsigned char *& buf, uint32_t& offset, uint32_t& buf_size) +{ + // Check that the buffer has sufficient size. If not, increase it. + + while(offset + size + 6 >= buf_size) + { + unsigned char *newbuf = new unsigned char[2*buf_size] ; + + memcpy(newbuf, buf, buf_size) ; + buf_size *= 2 ; + delete[] buf ; + buf = newbuf ; + } + + // Write ptag and size + + buf[offset] = static_cast(ptag) ; + offset += 1 ; + + offset += PGPKeyParser::write_125Size(&buf[offset],size) ; +} + bool p3Peers::getShortInvite( std::string& invite, const RsPeerId& _sslId, bool formatRadix, bool bareBones, const std::string& baseUrl ) @@ -1160,22 +1175,19 @@ bool p3Peers::getShortInvite( RsPeerDetails tDetails; if(!getPeerDetails(sslId, tDetails)) return false; - std::vector inviteBuf(1000, 0); - RsGenericSerializer::SerializeContext ctx( - inviteBuf.data(), static_cast(inviteBuf.size())); - RsGenericSerializer::SerializeJob j = RsGenericSerializer::SERIALIZE; + uint32_t buf_size = 100; + uint32_t offset = 0; + unsigned char *buf = (unsigned char*)malloc(buf_size); - RsShortInviteFieldType tType = RsShortInviteFieldType::SSL_ID; - RS_SERIAL_PROCESS(tType); - RS_SERIAL_PROCESS(sslId); + addPacketHeader(RsShortInviteFieldType::SSL_ID,RsPeerId::SIZE_IN_BYTES,buf,offset,buf_size); + sslId.serialise(buf,buf_size,offset); - tType = RsShortInviteFieldType::PGP_FINGERPRINT; - RS_SERIAL_PROCESS(tType); - RS_SERIAL_PROCESS(tDetails.fpr); + addPacketHeader(RsShortInviteFieldType::PGP_FINGERPRINT,RsPgpFingerprint::SIZE_IN_BYTES,buf,offset,buf_size); + tDetails.fpr.serialise(buf,buf_size,offset); - tType = RsShortInviteFieldType::PEER_NAME; - RS_SERIAL_PROCESS(tType); - RS_SERIAL_PROCESS(tDetails.name); + addPacketHeader(RsShortInviteFieldType::PEER_NAME,tDetails.name.size(),buf,offset,buf_size); + memcpy(&buf[offset],tDetails.name.c_str(),tDetails.name.size()); + offset += tDetails.name.size(); if(!bareBones) { @@ -1186,46 +1198,63 @@ bool p3Peers::getShortInvite( sockaddr_storage tExt; if(tDetails.isHiddenNode) { - tType = RsShortInviteFieldType::HIDDEN_LOCATOR; - RS_SERIAL_PROCESS(tType); - RS_SERIAL_PROCESS(tDetails.hiddenType); - RS_SERIAL_PROCESS(tDetails.hiddenNodeAddress); - RS_SERIAL_PROCESS(tDetails.hiddenNodePort); + addPacketHeader(RsShortInviteFieldType::HIDDEN_LOCATOR,4 + 2 + tDetails.hiddenNodeAddress.size(),buf,offset,buf_size); + + buf[offset+0] = (uint8_t)((tDetails.hiddenType >> 24) & 0xff); + buf[offset+1] = (uint8_t)((tDetails.hiddenType >> 16) & 0xff); + buf[offset+2] = (uint8_t)((tDetails.hiddenType >> 8) & 0xff); + buf[offset+3] = (uint8_t)((tDetails.hiddenType ) & 0xff); + + buf[offset+4] = (uint8_t)((tDetails.hiddenNodePort >> 8) & 0xff); + buf[offset+5] = (uint8_t)((tDetails.hiddenNodePort ) & 0xff); + + memcpy(&buf[offset+6],tDetails.hiddenNodeAddress.c_str(),tDetails.hiddenNodeAddress.size()); + offset += 4 + 2 + tDetails.hiddenNodeAddress.size(); } - else if( !tDetails.dyndns.empty() && - (tDetails.extPort || tDetails.localPort) ) + else if( !tDetails.dyndns.empty() && (tDetails.extPort || tDetails.localPort) ) { - uint16_t tPort = tDetails.extPort ? - tDetails.extPort : tDetails.localPort; - tType = RsShortInviteFieldType::DNS_LOCATOR; - RS_SERIAL_PROCESS(tType); - RS_SERIAL_PROCESS(tDetails.dyndns); - RS_SERIAL_PROCESS(tPort); + uint16_t tPort = tDetails.extPort ? tDetails.extPort : tDetails.localPort; + + addPacketHeader(RsShortInviteFieldType::DNS_LOCATOR, 2 + tDetails.dyndns.size(),buf,offset,buf_size); + + buf[offset+0] = (uint8_t)((tPort >> 8) & 0xff); + buf[offset+1] = (uint8_t)((tPort ) & 0xff); + + memcpy(&buf[offset+2],tDetails.dyndns.c_str(),tDetails.dyndns.size()); + offset += 2 + tDetails.dyndns.size(); } else if( sockaddr_storage_inet_pton(tExt, tDetails.extAddr) && sockaddr_storage_isValidNet(tExt) && sockaddr_storage_ipv6_to_ipv4(tExt) && tDetails.extPort ) { - uint32_t t4Addr = - reinterpret_cast(tExt).sin_addr.s_addr; + uint32_t t4Addr = reinterpret_cast(tExt).sin_addr.s_addr; - tType = RsShortInviteFieldType::EXT4_LOCATOR; - RS_SERIAL_PROCESS(tType); - RS_SERIAL_PROCESS(t4Addr); - RS_SERIAL_PROCESS(tDetails.extPort); + addPacketHeader(RsShortInviteFieldType::EXT4_LOCATOR, 4 + 2,buf,offset,buf_size); + + buf[offset+0] = (uint8_t)((t4Addr >> 24) & 0xff); + buf[offset+1] = (uint8_t)((t4Addr >> 16) & 0xff); + buf[offset+2] = (uint8_t)((t4Addr >> 8) & 0xff); + buf[offset+3] = (uint8_t)((t4Addr ) & 0xff); + + buf[offset+4] = (uint8_t)((tDetails.extPort >> 8) & 0xff); + buf[offset+5] = (uint8_t)((tDetails.extPort ) & 0xff); + + offset += 4+2; } else if(!tDetails.ipAddressList.empty()) { const std::string& tLc = tDetails.ipAddressList.front(); std::string tLocator = tLc.substr(0, tLc.find_first_of(" ")-1); - tType = RsShortInviteFieldType::LOCATOR; - RS_SERIAL_PROCESS(tType); - RS_SERIAL_PROCESS(tLocator); + + addPacketHeader(RsShortInviteFieldType::LOCATOR, tLocator.size(),buf,offset,buf_size); + memcpy(&buf[offset],tLocator.c_str(),tLocator.size()); + + offset += tLocator.size(); } } - Radix64::encode(ctx.mData, static_cast(ctx.mOffset), invite); + Radix64::encode(buf, static_cast(offset), invite); if(!formatRadix) { @@ -1234,10 +1263,10 @@ bool p3Peers::getShortInvite( invite = inviteUrl.toString(); } - return ctx.mOk; + return true; } -bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& details ) +bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& details, uint32_t &err_code ) { if(inviteStrUrl.empty()) { @@ -1245,119 +1274,96 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d << std::endl; return false; } - - const std::string* rsInvite = &inviteStrUrl; + std::string rsInvite = inviteStrUrl; RsUrl inviteUrl(inviteStrUrl); + if(inviteUrl.hasQueryK("rsInvite")) - rsInvite = inviteUrl.getQueryV("rsInvite"); + rsInvite = *inviteUrl.getQueryV("rsInvite"); - std::vector inviteBuf = Radix64::decode(*rsInvite); - RsGenericSerializer::SerializeContext ctx( inviteBuf.data(), static_cast(inviteBuf.size())); - RsGenericSerializer::SerializeJob j = RsGenericSerializer::DESERIALIZE; + std::vector bf = Radix64::decode(rsInvite); + size_t size = bf.size(); - while(ctx.mOk && ctx.mOffset < ctx.mSize) + unsigned char* buf = bf.data(); + size_t total_s = 0; + + while(total_s < size) { - RsShortInviteFieldType fieldType; - RS_SERIAL_PROCESS(fieldType); + RsShortInviteFieldType ptag = RsShortInviteFieldType(buf[0]); + buf = &buf[1]; - if(!ctx.mOk) + unsigned char *buf2 = buf; + uint32_t s = 0; + + try { s = PGPKeyParser::read_125Size(buf); } + catch (...) { - RsWarn() << __PRETTY_FUNCTION__ << " failed to parse fieldType" - << std::endl; - break; + err_code = CERTIFICATE_PARSING_ERROR_SIZE_ERROR; + return false; } - switch (fieldType) + total_s += 1 + ( reinterpret_cast(buf) - reinterpret_cast(buf2) ); + + if(total_s > size) { - case RsShortInviteFieldType::SSL_ID: - RS_SERIAL_PROCESS(details.id); + err_code = CERTIFICATE_PARSING_ERROR_SIZE_ERROR; + return false; + } + + Dbg3() << __PRETTY_FUNCTION__ << " Read ptag: " + << static_cast(ptag) + << ", size " << s << ", total_s = " << total_s + << ", expected total = " << size << std::endl; + + switch(ptag) + { + case RsShortInviteFieldType::SSL_ID: + details.id = RsPeerId::fromBufferUnsafe(buf) ; break; + case RsShortInviteFieldType::PEER_NAME: - RS_SERIAL_PROCESS(details.name); + details.name = std::string((char*)buf,s); break; - case RsShortInviteFieldType::PGP_FINGERPRINT: - RS_SERIAL_PROCESS(details.fpr); - + case RsShortInviteFieldType::PGP_FINGERPRINT: + details.fpr = RsPgpFingerprint::fromBufferUnsafe(buf); details.gpg_id = PGPHandler::pgpIdFromFingerprint(details.fpr); break; case RsShortInviteFieldType::LOCATOR: - { - std::string locatorStr; - RS_SERIAL_PROCESS(locatorStr); - if(ctx.mOk) details.ipAddressList.push_back(locatorStr); - else RsWarn() << __PRETTY_FUNCTION__ << " failed to parse locator" - << std::endl; - break; - } + { + std::string locatorStr((char*)buf,s); + details.ipAddressList.push_back(locatorStr); + } + break; + case RsShortInviteFieldType::DNS_LOCATOR: - RS_SERIAL_PROCESS(details.dyndns); - if(!ctx.mOk) - { - RsWarn() << __PRETTY_FUNCTION__ << " failed to parse DNS " - << "locator host" << std::endl; - break; - } - - RS_SERIAL_PROCESS(details.extPort); - if(!ctx.mOk) RsWarn() << __PRETTY_FUNCTION__ << " failed to parse " - << "DNS locator port" << std::endl; - - break; + details.extPort = (((int)buf[0]) << 8) + buf[1]; + details.dyndns = std::string((char*)&buf[2],s-2); + break; case RsShortInviteFieldType::EXT4_LOCATOR: { - uint32_t t4Addr = 0; - RS_SERIAL_PROCESS(t4Addr); - if(!ctx.mOk) - { - RsWarn() << __PRETTY_FUNCTION__ << " failed to parse IPv4" - << std::endl; - break; - } + uint32_t t4Addr = (((uint32_t)buf[0]) << 24)+(((uint32_t)buf[1])<<16)+(((uint32_t)buf[2])<<8) + (uint32_t)buf[3]; sockaddr_in tExtAddr; tExtAddr.sin_addr.s_addr = t4Addr; + details.extAddr = rs_inet_ntoa(tExtAddr.sin_addr); + details.extPort = (((uint32_t)buf[4])<<8) + (uint32_t)buf[5]; + } + break; - RS_SERIAL_PROCESS(details.extPort); - if(!ctx.mOk) - RsWarn() << __PRETTY_FUNCTION__ << " failed to parse extPort" - << std::endl; + case RsShortInviteFieldType::HIDDEN_LOCATOR: + details.hiddenType = (((uint32_t)buf[0]) << 24)+(((uint32_t)buf[1])<<16)+(((uint32_t)buf[2])<<8) + (uint32_t)buf[3]; + details.hiddenNodePort = (((uint32_t)buf[4]) << 8)+ (uint32_t)buf[5]; + details.hiddenNodeAddress = std::string((char*)&buf[6],s-6); break; + } - case RsShortInviteFieldType::HIDDEN_LOCATOR: - RS_SERIAL_PROCESS(details.hiddenType); - if(!ctx.mOk) - { - RsWarn() << __PRETTY_FUNCTION__ << " failed to parse hiddenType" - << std::endl; - break; - } - - RS_SERIAL_PROCESS(details.hiddenNodeAddress); - if(!ctx.mOk) - { - RsWarn() << __PRETTY_FUNCTION__ << " failed to parse " - << "hiddenNodeAddress" << std::endl; - break; - } - - RS_SERIAL_PROCESS(details.hiddenNodePort); - if(!ctx.mOk) RsWarn() << __PRETTY_FUNCTION__ << " failed to parse " - << "hiddenNodePort" << std::endl; - - break; - - default: - RsWarn() << __PRETTY_FUNCTION__ << " got unkown field type: " - << static_cast(fieldType) << std::endl; - return false; - break; - } + buf = &buf[s]; + total_s += s; } // now check if the PGP key is available. If so, add it in the PeerDetails: @@ -1377,7 +1383,18 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d else details.skip_signature_validation = true; - return ctx.mOk; + if(details.gpg_id.isNull()) + { + err_code = CERTIFICATE_PARSING_ERROR_MISSING_PGP_FINGERPRINT; + return false; + } + if(details.id.isNull()) + { + err_code = CERTIFICATE_PARSING_ERROR_MISSING_LOCATION_ID; + return false; + } + err_code = CERTIFICATE_PARSING_ERROR_NO_ERROR; + return true; } bool p3Peers::acceptInvite( const std::string& invite, @@ -1566,7 +1583,7 @@ bool p3Peers::loadDetailsFromStringCert( const std::string &certstr, return true; } -bool p3Peers::cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,int& error_code) +bool p3Peers::cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,uint32_t& error_code) { RsCertificate::Format format ; diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index da679124f..792348766 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -145,8 +145,7 @@ public: const std::string& baseUrl = "https://retroshare.me/" ) override; /// @see RsPeers - bool parseShortInvite( - const std::string& invite, RsPeerDetails& details ) override; + bool parseShortInvite(const std::string& invite, RsPeerDetails& details, uint32_t &err_code ) override; /// @see RsPeers::acceptInvite virtual bool acceptInvite( @@ -158,7 +157,7 @@ public: virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string); virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code); - virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert, bool &is_short_format, int& error_code) override; + virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert, bool &is_short_format, uint32_t& error_code) override; virtual bool saveCertificateToFile(const RsPeerId &id, const std::string &fname); virtual std::string saveCertificateToString(const RsPeerId &id); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 48de3b6a2..3e4bc1ad6 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -305,7 +305,7 @@ void ConnectFriendWizard::setCertificate(const QString &certificate, bool friend } } } - else if(rsPeers->parseShortInvite(certificate.toUtf8().constData(),peerDetails)) + else if(rsPeers->parseShortInvite(certificate.toUtf8().constData(),peerDetails,cert_load_error_code)) { mIsShortInvite = true; @@ -606,7 +606,7 @@ bool ConnectFriendWizard::validateCurrentPage() std::string certstr = ui->friendCertEdit->toPlainText().toUtf8().constData(); uint32_t cert_load_error_code; - if (rsPeers->loadDetailsFromStringCert(certstr, peerDetails, cert_load_error_code) || rsPeers->parseShortInvite(certstr,peerDetails)) + if (rsPeers->loadDetailsFromStringCert(certstr, peerDetails, cert_load_error_code) || rsPeers->parseShortInvite(certstr,peerDetails,cert_load_error_code)) { mCertificate = certstr; #ifdef FRIEND_WIZARD_DEBUG @@ -846,7 +846,7 @@ void ConnectFriendWizard::cleanFriendCert() } else { std::string cleanCert; - int error_code; + uint32_t error_code; if (rsPeers->cleanCertificate(cert, cleanCert, mIsShortInvite, error_code)) { From a52451b72cb78a00588d48bde8c366da45ba669a Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 22 Jun 2019 18:44:32 +0200 Subject: [PATCH 23/45] moved SSL part of friend list into a separate function --- retroshare-gui/src/gui/common/FriendList.cpp | 590 ++++++++++--------- retroshare-gui/src/gui/common/FriendList.h | 2 + 2 files changed, 308 insertions(+), 284 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 7af5e68e4..62f27059c 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -553,6 +553,275 @@ static void getNameWidget(QTreeWidget *treeWidget, QTreeWidgetItem *item, Elided } } +struct PgpItemInfo +{ + PgpItemInfo() : gpg_connected(false),gpg_online(false),gpg_hasPrivateChat(false),bestPeerState(0),bestRSState(0) {} + + bool gpg_connected ; + bool gpg_online ; + bool gpg_hasPrivateChat ; + int bestPeerState ; + unsigned int bestRSState ; + QString bestCustomStateString;// for gpg item + std::list sslContacts; + QDateTime bestLastContact; + QString bestIP; + QPixmap bestAvatar; +}; + +void FriendList::manageProfileLocations(QTreeWidgetItem *gpgItem,const RsPgpId& gpg_id,PgpItemInfo& info) +{ + std::vector privateChatIds; + ChatUserNotify::getPeersWithWaitingChat(privateChatIds); + + int columnCount = ui->peerTreeWidget->columnCount(); + + for (auto sslIt ( info.sslContacts.begin()); sslIt != info.sslContacts.end(); ++sslIt) + { + QTreeWidgetItem *sslItem = NULL; + RsPeerId sslId = *sslIt; + + // find the corresponding sslItem child item of the gpg item + bool newChild = true; + int childCount = gpgItem->childCount(); + for (int childIndex = 0; childIndex < childCount; ++childIndex) { + // we assume, that only ssl items are child of the gpg item, so we don't need to test the type + if (getRsId(gpgItem->child(childIndex)) == sslId.toStdString()) { + sslItem = gpgItem->child(childIndex); + newChild = false; + break; + } + } + + RsPeerDetails sslDetail; + if (!rsPeers->getPeerDetails(sslId, sslDetail) || !rsPeers->isFriend(sslId)) { +#ifdef FRIENDS_DEBUG + std::cerr << "Removing widget from the view : id : " << sslId << std::endl; +#endif + // child has disappeared, remove it from the gpg_item + if (sslItem) { + gpgItem->removeChild(sslItem); + delete(sslItem); + } + continue; + } + + if (newChild) { + sslItem = new RSTreeWidgetItem(mCompareRole, TYPE_SSL); //set type to 1 for custom popup menu + +#ifdef FRIENDS_DEBUG + std::cerr << "FriendList::insertPeers() inserting sslItem." << std::endl; +#endif + + /* Add ssl child to the list. Add here, because for setHidden the item must be added */ + gpgItem->addChild(sslItem); + + /* Sort data */ + for (int i = 0; i < columnCount; ++i) { + sslItem->setData(i, ROLE_SORT_GROUP, 2); + sslItem->setData(i, ROLE_SORT_STANDARD_GROUP, 1); + } + } + + /* not displayed, used to find back the item */ + QString strID = QString::fromStdString(sslDetail.id.toStdString()); + sslItem->setData(COLUMN_DATA, ROLE_ID, strID); + sslItem->setText(COLUMN_ID, strID); + sslItem->setData(COLUMN_ID, ROLE_SORT_NAME, strID); + sslItem->setData(COLUMN_ID, ROLE_FILTER, strID); + + /* Custom state string */ + QString customStateString; + if (sslDetail.state & RS_PEER_STATE_CONNECTED) { + customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(sslDetail.id).c_str()); + } + + QPixmap sslAvatar; + AvatarDefs::getAvatarFromSslId(RsPeerId(sslDetail.id.toStdString()), sslAvatar); + + /* last contact */ + QDateTime sslLastContact = QDateTime::fromTime_t(sslDetail.lastConnect); + sslItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, QVariant(sslLastContact)); + sslItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT_NAME, QVariant(sslLastContact)); + if (sslLastContact > info.bestLastContact) { + info.bestLastContact = sslLastContact; + } + + /* IP */ + QString sslIP = (sslDetail.state & RS_PEER_STATE_CONNECTED) ? StatusDefs::connectStateIpString(sslDetail) : QString("---"); + sslItem->setText(COLUMN_IP, sslIP); + sslItem->setData(COLUMN_IP, ROLE_SORT_NAME, sslIP); + + /* change color and icon */ + QPixmap sslOverlayIcon; + QFont sslFont; + QColor sslColor; + int peerState = 0; + QString connectStateString; + if (sslDetail.state & RS_PEER_STATE_CONNECTED) + { + // get the status info for this ssl id + int rsState = 0; + + StatusInfo status_info ; + rsStatus->getStatus(sslDetail.id,status_info); + + rsState = status_info.status; + switch (rsState) { + case RS_STATUS_INACTIVE: + peerState = PEER_STATE_INACTIVE; + break; + + case RS_STATUS_ONLINE: + peerState = PEER_STATE_ONLINE; + break; + + case RS_STATUS_AWAY: + peerState = PEER_STATE_AWAY; + break; + + case RS_STATUS_BUSY: + peerState = PEER_STATE_BUSY; + break; + } + + /* find the best ssl contact for the gpg item */ + if (info.bestPeerState == 0 || peerState < info.bestPeerState) { + /* first ssl contact or higher state */ + info.bestPeerState = peerState; + info.bestRSState = rsState; + info.bestCustomStateString = customStateString; + info.bestIP = sslIP; + if (!sslAvatar.isNull()) { + info.bestAvatar = sslAvatar; + } + } else if (peerState == info.bestPeerState) { + /* equal state */ + if (info.bestCustomStateString.isEmpty() && !customStateString.isEmpty()) { + /* when customStateString is shown in name item, use sslId with customStateString. + second with a custom state string ... use second */ + info.bestPeerState = peerState; + info.bestRSState = rsState; + info.bestCustomStateString = customStateString; + } + if (info.bestAvatar.isNull() && !sslAvatar.isNull()) { + /* Use available avatar */ + info.bestAvatar = sslAvatar; + } + } + + sslItem->setHidden(false); + info.gpg_connected = true; + + sslOverlayIcon = QPixmap(StatusDefs::imageStatus(info.bestRSState)); + + connectStateString = StatusDefs::name(rsState); + + if (rsState == 0) { + sslFont.setBold(true); + sslColor = mTextColorStatus[RS_STATUS_ONLINE]; + } else { + sslFont = StatusDefs::font(rsState); + sslColor = mTextColorStatus[rsState]; + } + } else if (sslDetail.state & RS_PEER_STATE_ONLINE) { + sslItem->setHidden(mHideUnconnected); + info.gpg_online = true; + peerState = PEER_STATE_AVAILABLE; + + if (sslDetail.connectState) { + sslOverlayIcon = QPixmap(":/images/connect_creating.png"); + } else { + sslOverlayIcon = QPixmap(StatusDefs::imageStatus(RS_STATUS_ONLINE)); + } + + connectStateString = StatusDefs::name(RS_STATUS_ONLINE); + + sslFont.setBold(true); + sslColor = mTextColorStatus[RS_STATUS_ONLINE]; + } else { + peerState = PEER_STATE_OFFLINE; + sslItem->setHidden(mHideUnconnected); + if (sslDetail.connectState) { + sslOverlayIcon = QPixmap(":/images/connect_creating.png"); + } else { + sslOverlayIcon = QPixmap(StatusDefs::imageStatus(RS_STATUS_OFFLINE)); + } + + connectStateString = StatusDefs::connectStateWithoutTransportTypeString(sslDetail); + + sslFont.setBold(false); + sslColor = mTextColorStatus[RS_STATUS_OFFLINE]; + } + + /* Location */ + QString sslName = QString::fromUtf8(sslDetail.location.c_str()); + QString sslText; + + if (mShowState) { + if (!connectStateString.isEmpty()) { + sslText = connectStateString; + if (!customStateString.isEmpty()) { + sslText += " [" + customStateString + "]"; + } + } else { + if (!customStateString.isEmpty()) { + sslText = customStateString; + } + } + + sslItem->setToolTip(COLUMN_NAME, ""); + } else { + if (!customStateString.isEmpty()) { + sslText = customStateString; + } + + /* Show the state as tooltip */ + sslItem->setToolTip(COLUMN_NAME, connectStateString); + } + + /* Create or get ssl label */ + ElidedLabel *sslNameLabel = NULL; + ElidedLabel *sslTextLabel = NULL; + + getNameWidget(ui->peerTreeWidget, sslItem, sslNameLabel, sslTextLabel); + + if (sslNameLabel) { + sslNameLabel->setText(sslName); + sslNameLabel->setFont(sslFont); + + QPalette palette = sslNameLabel->palette(); + palette.setColor(sslNameLabel->foregroundRole(), sslColor); + + sslNameLabel->setPalette(palette); + } + if (sslTextLabel) { + sslTextLabel->setText(sslText); + sslTextLabel->setVisible(!sslText.isEmpty()); + } + + // Filter + sslItem->setData(COLUMN_NAME, ROLE_FILTER, sslName); + + if (std::find(privateChatIds.begin(), privateChatIds.end(), sslDetail.id) != privateChatIds.end()) { + // private chat is available + sslOverlayIcon = QPixmap(":/images/chat.png"); + info.gpg_hasPrivateChat = true; + } + sslItem->setIcon(COLUMN_NAME, createAvatar(sslAvatar, sslOverlayIcon)); + + /* Sort data */ + sslItem->setData(COLUMN_NAME, ROLE_SORT_NAME, sslName); + + for (int i = 0; i < columnCount; ++i) { + sslItem->setData(i, ROLE_SORT_STATE, peerState); + + sslItem->setTextColor(i, sslColor); + sslItem->setFont(i, sslFont); + } + } +} + /** * Get the list of peers from the RsIface. * Adds all friend gpg ids, with their nodes as children to the peerTreeWidget. @@ -570,8 +839,8 @@ void FriendList::insertPeers() int columnCount = ui->peerTreeWidget->columnCount(); - std::list statusInfo; - rsStatus->getStatusList(statusInfo); + //std::list statusInfo; + //rsStatus->getStatusList(statusInfo); if (!rsPeers) { /* not ready yet! */ @@ -580,9 +849,6 @@ void FriendList::insertPeers() } // get peers with waiting incoming chats - std::vector privateChatIds; - ChatUserNotify::getPeersWithWaitingChat(privateChatIds); - // get existing groups std::list groupInfoList; std::list::iterator groupIt; @@ -605,6 +871,7 @@ void FriendList::insertPeers() std::list ssl_friends ; rsPeers->getFriendList(ssl_friends); + std::set pgp_friends_without_validation; std::cerr << "List of accepted ssl peers: " << std::endl; for(auto it(ssl_friends.begin());it!=ssl_friends.end();++it) @@ -614,6 +881,7 @@ void FriendList::insertPeers() { std::cerr << " adding " << *it << " - " << pd.gpg_id << std::endl; gpgFriends.push_back(pd.gpg_id); + pgp_friends_without_validation.insert(pd.gpg_id); } } @@ -827,10 +1095,15 @@ void FriendList::insertPeers() delete (peerTreeWidget->takeTopLevelItem(peerTreeWidget->indexOfTopLevelItem(gpgItem))); } } - continue; + + // We still want to add the item if it is unvalidated, in which case getGPGDetails returns false. + + if(pgp_friends_without_validation.find(gpgId) == pgp_friends_without_validation.end()) + continue; } - if (gpgItem == NULL) { + if (gpgItem == NULL) + { // create gpg item and add it to tree gpgItem = new RSTreeWidgetItem(mCompareRole, TYPE_GPG); //set type to 0 for custom popup menu @@ -845,7 +1118,7 @@ void FriendList::insertPeers() gpgItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter); /* not displayed, used to find back the item */ - QString strID = QString::fromStdString(detail.gpg_id.toStdString()); + QString strID = QString::fromStdString(gpgId.toStdString()); gpgItem->setData(COLUMN_DATA, ROLE_ID, strID); gpgItem->setText(COLUMN_ID, strID); gpgItem->setData(COLUMN_ID, ROLE_SORT_NAME, strID); @@ -875,262 +1148,11 @@ void FriendList::insertPeers() } // update the childs (ssl certs) - bool gpg_connected = false; - bool gpg_online = false; - bool gpg_hasPrivateChat = false; - int bestPeerState = 0; // for gpg item - unsigned int bestRSState = 0; // for gpg item - QString bestCustomStateString;// for gpg item - std::list sslContacts; - QDateTime bestLastContact; - QString bestIP; - QPixmap bestAvatar; - rsPeers->getAssociatedSSLIds(detail.gpg_id, sslContacts); - for (std::list::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); ++sslIt) { - QTreeWidgetItem *sslItem = NULL; - RsPeerId sslId = *sslIt; + PgpItemInfo info; + rsPeers->getAssociatedSSLIds(detail.gpg_id, info.sslContacts); - // find the corresponding sslItem child item of the gpg item - bool newChild = true; - childCount = gpgItem->childCount(); - for (int childIndex = 0; childIndex < childCount; ++childIndex) { - // we assume, that only ssl items are child of the gpg item, so we don't need to test the type - if (getRsId(gpgItem->child(childIndex)) == sslId.toStdString()) { - sslItem = gpgItem->child(childIndex); - newChild = false; - break; - } - } - - RsPeerDetails sslDetail; - if (!rsPeers->getPeerDetails(sslId, sslDetail) || !rsPeers->isFriend(sslId)) { -#ifdef FRIENDS_DEBUG - std::cerr << "Removing widget from the view : id : " << sslId << std::endl; -#endif - // child has disappeared, remove it from the gpg_item - if (sslItem) { - gpgItem->removeChild(sslItem); - delete(sslItem); - } - continue; - } - - if (newChild) { - sslItem = new RSTreeWidgetItem(mCompareRole, TYPE_SSL); //set type to 1 for custom popup menu - -#ifdef FRIENDS_DEBUG - std::cerr << "FriendList::insertPeers() inserting sslItem." << std::endl; -#endif - - /* Add ssl child to the list. Add here, because for setHidden the item must be added */ - gpgItem->addChild(sslItem); - - /* Sort data */ - for (int i = 0; i < columnCount; ++i) { - sslItem->setData(i, ROLE_SORT_GROUP, 2); - sslItem->setData(i, ROLE_SORT_STANDARD_GROUP, 1); - } - } - - /* not displayed, used to find back the item */ - QString strID = QString::fromStdString(sslDetail.id.toStdString()); - sslItem->setData(COLUMN_DATA, ROLE_ID, strID); - sslItem->setText(COLUMN_ID, strID); - sslItem->setData(COLUMN_ID, ROLE_SORT_NAME, strID); - sslItem->setData(COLUMN_ID, ROLE_FILTER, strID); - - /* Custom state string */ - QString customStateString; - if (sslDetail.state & RS_PEER_STATE_CONNECTED) { - customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(sslDetail.id).c_str()); - } - - QPixmap sslAvatar; - AvatarDefs::getAvatarFromSslId(RsPeerId(sslDetail.id.toStdString()), sslAvatar); - - /* last contact */ - QDateTime sslLastContact = QDateTime::fromTime_t(sslDetail.lastConnect); - sslItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, QVariant(sslLastContact)); - sslItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT_NAME, QVariant(sslLastContact)); - if (sslLastContact > bestLastContact) { - bestLastContact = sslLastContact; - } - - /* IP */ - QString sslIP = (sslDetail.state & RS_PEER_STATE_CONNECTED) ? StatusDefs::connectStateIpString(sslDetail) : QString("---"); - sslItem->setText(COLUMN_IP, sslIP); - sslItem->setData(COLUMN_IP, ROLE_SORT_NAME, sslIP); - - /* change color and icon */ - QPixmap sslOverlayIcon; - QFont sslFont; - QColor sslColor; - int peerState = 0; - QString connectStateString; - if (sslDetail.state & RS_PEER_STATE_CONNECTED) { - // get the status info for this ssl id - int rsState = 0; - std::list::iterator it; - for (it = statusInfo.begin(); it != statusInfo.end(); ++it) { - if (it->id == sslId) { - rsState = it->status; - switch (rsState) { - case RS_STATUS_INACTIVE: - peerState = PEER_STATE_INACTIVE; - break; - - case RS_STATUS_ONLINE: - peerState = PEER_STATE_ONLINE; - break; - - case RS_STATUS_AWAY: - peerState = PEER_STATE_AWAY; - break; - - case RS_STATUS_BUSY: - peerState = PEER_STATE_BUSY; - break; - } - - /* find the best ssl contact for the gpg item */ - if (bestPeerState == 0 || peerState < bestPeerState) { - /* first ssl contact or higher state */ - bestPeerState = peerState; - bestRSState = rsState; - bestCustomStateString = customStateString; - bestIP = sslIP; - if (!sslAvatar.isNull()) { - bestAvatar = sslAvatar; - } - } else if (peerState == bestPeerState) { - /* equal state */ - if (bestCustomStateString.isEmpty() && !customStateString.isEmpty()) { - /* when customStateString is shown in name item, use sslId with customStateString. - second with a custom state string ... use second */ - bestPeerState = peerState; - bestRSState = rsState; - bestCustomStateString = customStateString; - } - if (bestAvatar.isNull() && !sslAvatar.isNull()) { - /* Use available avatar */ - bestAvatar = sslAvatar; - } - } - break; - } - } - - sslItem->setHidden(false); - gpg_connected = true; - - sslOverlayIcon = QPixmap(StatusDefs::imageStatus(bestRSState)); - - connectStateString = StatusDefs::name(rsState); - - if (rsState == 0) { - sslFont.setBold(true); - sslColor = mTextColorStatus[RS_STATUS_ONLINE]; - } else { - sslFont = StatusDefs::font(rsState); - sslColor = mTextColorStatus[rsState]; - } - } else if (sslDetail.state & RS_PEER_STATE_ONLINE) { - sslItem->setHidden(mHideUnconnected); - gpg_online = true; - peerState = PEER_STATE_AVAILABLE; - - if (sslDetail.connectState) { - sslOverlayIcon = QPixmap(":/images/connect_creating.png"); - } else { - sslOverlayIcon = QPixmap(StatusDefs::imageStatus(RS_STATUS_ONLINE)); - } - - connectStateString = StatusDefs::name(RS_STATUS_ONLINE); - - sslFont.setBold(true); - sslColor = mTextColorStatus[RS_STATUS_ONLINE]; - } else { - peerState = PEER_STATE_OFFLINE; - sslItem->setHidden(mHideUnconnected); - if (sslDetail.connectState) { - sslOverlayIcon = QPixmap(":/images/connect_creating.png"); - } else { - sslOverlayIcon = QPixmap(StatusDefs::imageStatus(RS_STATUS_OFFLINE)); - } - - connectStateString = StatusDefs::connectStateWithoutTransportTypeString(sslDetail); - - sslFont.setBold(false); - sslColor = mTextColorStatus[RS_STATUS_OFFLINE]; - } - - /* Location */ - QString sslName = QString::fromUtf8(sslDetail.location.c_str()); - QString sslText; - - if (mShowState) { - if (!connectStateString.isEmpty()) { - sslText = connectStateString; - if (!customStateString.isEmpty()) { - sslText += " [" + customStateString + "]"; - } - } else { - if (!customStateString.isEmpty()) { - sslText = customStateString; - } - } - - sslItem->setToolTip(COLUMN_NAME, ""); - } else { - if (!customStateString.isEmpty()) { - sslText = customStateString; - } - - /* Show the state as tooltip */ - sslItem->setToolTip(COLUMN_NAME, connectStateString); - } - - /* Create or get ssl label */ - ElidedLabel *sslNameLabel = NULL; - ElidedLabel *sslTextLabel = NULL; - - getNameWidget(ui->peerTreeWidget, sslItem, sslNameLabel, sslTextLabel); - - if (sslNameLabel) { - sslNameLabel->setText(sslName); - sslNameLabel->setFont(sslFont); - - QPalette palette = sslNameLabel->palette(); - palette.setColor(sslNameLabel->foregroundRole(), sslColor); - - sslNameLabel->setPalette(palette); - } - if (sslTextLabel) { - sslTextLabel->setText(sslText); - sslTextLabel->setVisible(!sslText.isEmpty()); - } - - // Filter - sslItem->setData(COLUMN_NAME, ROLE_FILTER, sslName); - - if (std::find(privateChatIds.begin(), privateChatIds.end(), sslDetail.id) != privateChatIds.end()) { - // private chat is available - sslOverlayIcon = QPixmap(":/images/chat.png"); - gpg_hasPrivateChat = true; - } - sslItem->setIcon(COLUMN_NAME, createAvatar(sslAvatar, sslOverlayIcon)); - - /* Sort data */ - sslItem->setData(COLUMN_NAME, ROLE_SORT_NAME, sslName); - - for (int i = 0; i < columnCount; ++i) { - sslItem->setData(i, ROLE_SORT_STATE, peerState); - - sslItem->setTextColor(i, sslColor); - sslItem->setFont(i, sslFont); - } - } + manageProfileLocations(gpgItem,detail.gpg_id,info); QString gpgName = QString::fromUtf8(detail.name.c_str()); QString gpgText; @@ -1140,38 +1162,38 @@ void FriendList::insertPeers() bool showInfoAtGpgItem = !gpgItem->isExpanded(); QPixmap gpgOverlayIcon; - if (gpg_connected) { + if (info.gpg_connected) { gpgItem->setHidden(false); ++onlineCount; - if (bestPeerState == 0) { + if (info.bestPeerState == 0) { // show as online - bestPeerState = PEER_STATE_ONLINE; - bestRSState = RS_STATUS_ONLINE; + info.bestPeerState = PEER_STATE_ONLINE; + info.bestRSState = RS_STATUS_ONLINE; } - gpgColor = mTextColorStatus[bestRSState]; - gpgFont = StatusDefs::font(bestRSState); + gpgColor = mTextColorStatus[info.bestRSState]; + gpgFont = StatusDefs::font(info.bestRSState); if (showInfoAtGpgItem) { - gpgOverlayIcon = QPixmap(StatusDefs::imageStatus(bestRSState)); + gpgOverlayIcon = QPixmap(StatusDefs::imageStatus(info.bestRSState)); if (mShowState) { - gpgText = StatusDefs::name(bestRSState); - if (!bestCustomStateString.isEmpty()) { - gpgText += " [" + bestCustomStateString + "]"; + gpgText = StatusDefs::name(info.bestRSState); + if (!info.bestCustomStateString.isEmpty()) { + gpgText += " [" + info.bestCustomStateString + "]"; } } else { - if (!bestCustomStateString.isEmpty()) { - gpgText = bestCustomStateString; + if (!info.bestCustomStateString.isEmpty()) { + gpgText = info.bestCustomStateString; } } } - } else if (gpg_online) { + } else if (info.gpg_online) { gpgItem->setHidden(mHideUnconnected); ++onlineCount; - bestPeerState = PEER_STATE_AVAILABLE; + info.bestPeerState = PEER_STATE_AVAILABLE; gpgFont.setBold(true); gpgColor = mTextColorStatus[RS_STATUS_ONLINE]; @@ -1184,7 +1206,7 @@ void FriendList::insertPeers() gpgOverlayIcon = QPixmap(IMAGE_AVAILABLE); } } else { - bestPeerState = PEER_STATE_OFFLINE; + info.bestPeerState = PEER_STATE_OFFLINE; gpgItem->setHidden(mHideUnconnected); gpgFont = StatusDefs::font(RS_STATUS_OFFLINE); @@ -1199,11 +1221,11 @@ void FriendList::insertPeers() } } - if (gpg_hasPrivateChat) { + if (info.gpg_hasPrivateChat) { gpgOverlayIcon = QPixmap(":/images/chat.png"); } - gpgItem->setIcon(COLUMN_NAME, createAvatar(bestAvatar.isNull() ? QPixmap(AVATAR_DEFAULT_IMAGE) : bestAvatar, gpgOverlayIcon)); + gpgItem->setIcon(COLUMN_NAME, createAvatar(info.bestAvatar.isNull() ? QPixmap(AVATAR_DEFAULT_IMAGE) : info.bestAvatar, gpgOverlayIcon)); /* Create or get gpg label */ ElidedLabel *gpgNameLabel = NULL; @@ -1228,16 +1250,16 @@ void FriendList::insertPeers() // Filter gpgItem->setData(COLUMN_NAME, ROLE_FILTER, gpgName); - gpgItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, showInfoAtGpgItem ? QVariant(bestLastContact) : ""); - gpgItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT_NAME, QVariant(bestLastContact)); - gpgItem->setText(COLUMN_IP, showInfoAtGpgItem ? bestIP : ""); - gpgItem->setData(COLUMN_IP, ROLE_SORT_NAME, bestIP); + gpgItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, showInfoAtGpgItem ? QVariant(info.bestLastContact) : ""); + gpgItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT_NAME, QVariant(info.bestLastContact)); + gpgItem->setText(COLUMN_IP, showInfoAtGpgItem ? info.bestIP : ""); + gpgItem->setData(COLUMN_IP, ROLE_SORT_NAME, info.bestIP); /* Sort data */ gpgItem->setData(COLUMN_NAME, ROLE_SORT_NAME, gpgName); for (int i = 0; i < columnCount; ++i) { - gpgItem->setData(i, ROLE_SORT_STATE, bestPeerState); + gpgItem->setData(i, ROLE_SORT_STATE, info.bestPeerState); gpgItem->setTextColor(i, gpgColor); gpgItem->setFont(i, gpgFont); diff --git a/retroshare-gui/src/gui/common/FriendList.h b/retroshare-gui/src/gui/common/FriendList.h index 4aed1c43b..3a5c15bbe 100644 --- a/retroshare-gui/src/gui/common/FriendList.h +++ b/retroshare-gui/src/gui/common/FriendList.h @@ -35,6 +35,7 @@ namespace Ui { class RSTreeWidgetItemCompareRole; class QTreeWidgetItem; class QToolButton; +struct PgpItemInfo; class FriendList : public RsAutoUpdatePage { @@ -137,6 +138,7 @@ private: bool importExportFriendlistFileDialog(QString &fileName, bool import); bool exportFriendlist(QString &fileName); bool importFriendlist(QString &fileName, bool &errorPeers, bool &errorGroups); + void manageProfileLocations(QTreeWidgetItem *gpgItem,const RsPgpId& gpg_id,PgpItemInfo& info); private slots: void groupsChanged(); From daec6b33c79dadd0557ee1cbbd373ec2cb499880 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 22 Jun 2019 22:07:23 +0200 Subject: [PATCH 24/45] arranged to show PGP id for friends from short invite. Name not available yet --- retroshare-gui/src/gui/common/FriendList.cpp | 26 ++++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 62f27059c..f5f56c362 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -871,7 +871,7 @@ void FriendList::insertPeers() std::list ssl_friends ; rsPeers->getFriendList(ssl_friends); - std::set pgp_friends_without_validation; + std::map > pgp_friends_without_validation; std::cerr << "List of accepted ssl peers: " << std::endl; for(auto it(ssl_friends.begin());it!=ssl_friends.end();++it) @@ -881,7 +881,7 @@ void FriendList::insertPeers() { std::cerr << " adding " << *it << " - " << pd.gpg_id << std::endl; gpgFriends.push_back(pd.gpg_id); - pgp_friends_without_validation.insert(pd.gpg_id); + pgp_friends_without_validation[pd.gpg_id].push_back(pd); } } @@ -1086,7 +1086,8 @@ void FriendList::insertPeers() } RsPeerDetails detail; - if ((!rsPeers->getGPGDetails(gpgId, detail) || !detail.accept_connection) && detail.gpg_id != ownId) { + if (pgp_friends_without_validation.find(gpgId) == pgp_friends_without_validation.end() && + (!rsPeers->getGPGDetails(gpgId, detail) || !detail.accept_connection) && detail.gpg_id != ownId) { // don't accept anymore connection, remove from the view if (gpgItem) { if (groupItem) { @@ -1097,9 +1098,7 @@ void FriendList::insertPeers() } // We still want to add the item if it is unvalidated, in which case getGPGDetails returns false. - - if(pgp_friends_without_validation.find(gpgId) == pgp_friends_without_validation.end()) - continue; + continue; } if (gpgItem == NULL) @@ -1150,9 +1149,20 @@ void FriendList::insertPeers() // update the childs (ssl certs) PgpItemInfo info; - rsPeers->getAssociatedSSLIds(detail.gpg_id, info.sslContacts); - manageProfileLocations(gpgItem,detail.gpg_id,info); + auto itt = pgp_friends_without_validation.find(gpgId); + if(itt != pgp_friends_without_validation.end()) + { + info.sslContacts.clear(); + for(auto itt2(itt->second.begin());itt2!=itt->second.end();++itt2) + info.sslContacts.push_back(itt2->id); + + detail.name = gpgId.toStdString() + tr(" (Unverified yet)").toStdString(); + } + else + rsPeers->getAssociatedSSLIds(gpgId, info.sslContacts); + + manageProfileLocations(gpgItem,gpgId,info); QString gpgName = QString::fromUtf8(detail.name.c_str()); QString gpgText; From dd90314c3d390934e75525b478bb2eacd422d575 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 8 Sep 2019 20:49:38 +0200 Subject: [PATCH 25/45] fixed missing type conversion --- libretroshare/src/pqi/p3servicecontrol.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/pqi/p3servicecontrol.cc b/libretroshare/src/pqi/p3servicecontrol.cc index d361f25bd..3cfe56c5c 100644 --- a/libretroshare/src/pqi/p3servicecontrol.cc +++ b/libretroshare/src/pqi/p3servicecontrol.cc @@ -760,7 +760,7 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId) recordFilterChanges_locked(peerId, originalFilter, peerFilter); using Evt_t = RsPeerStateChangedEvent; - std::shared_ptr lockedRsEvents = rsEvents; + std::shared_ptr lockedRsEvents ( rsEvents ); if(lockedRsEvents) lockedRsEvents->postEvent(std::unique_ptr(new Evt_t(peerId))); From c8064e1ddc13a1cf13d39d00e18ca2e3da3fa97e Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 8 Sep 2019 20:50:06 +0200 Subject: [PATCH 26/45] fixed missing parameter in jsonapi declaration --- libretroshare/src/retroshare/rspeers.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 51443f918..696ca2de7 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -681,9 +681,9 @@ public: /** * @brief Parse the give short invite to extract contained information * @jsonapi{development} - * @param[in] invite string containing the short invite to parse - * @param[out] details storage for the extracted information, consider it - * valid only if the function return true + * @param[in] invite string containing the short invite to parse + * @param[out] details storage for the extracted information, consider it + * @param[out] err_code storage for the error code * @return false if error occurred, true otherwise */ virtual bool parseShortInvite( From 3a58aa468f430f009d321f488533f3993b5ae9ef Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 10 Sep 2019 09:52:37 +0200 Subject: [PATCH 27/45] 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; From bbf92bd5f333beebae902780f89403c6eb0f2f66 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 10 Sep 2019 21:59:25 +0200 Subject: [PATCH 28/45] fixed remanent bug due causing the deletion of rsEvent --- libretroshare/src/pqi/p3servicecontrol.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/pqi/p3servicecontrol.cc b/libretroshare/src/pqi/p3servicecontrol.cc index 3cfe56c5c..9bf3b3c62 100644 --- a/libretroshare/src/pqi/p3servicecontrol.cc +++ b/libretroshare/src/pqi/p3servicecontrol.cc @@ -760,9 +760,8 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId) recordFilterChanges_locked(peerId, originalFilter, peerFilter); using Evt_t = RsPeerStateChangedEvent; - std::shared_ptr lockedRsEvents ( rsEvents ); - if(lockedRsEvents) - lockedRsEvents->postEvent(std::unique_ptr(new Evt_t(peerId))); + if(rsEvents) + rsEvents->postEvent(std::unique_ptr(new Evt_t(peerId))); return true; } From b0c7f8f0caac32fd80d813dba85be45d71a37a10 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 10 Sep 2019 22:01:06 +0200 Subject: [PATCH 29/45] fixed display of non validated nodes without fingerprint --- retroshare-gui/src/gui/common/FriendListModel.cpp | 13 ++++++++++--- retroshare-gui/src/gui/common/FriendListModel.h | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index 4c37b0927..de7ed2ab3 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -973,9 +973,16 @@ 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) +std::map::const_iterator RsFriendListModel::createInvalidatedProfile(const RsPgpId& _pgp_id,const RsPgpFingerprint& fpr,std::map& pgp_indices,std::vector& mProfiles) { - RsPgpId pgp_id = rsPeers->pgpIdFromFingerprint(fpr); + // This is necessary by the time the full fingerprint is used in PeerNetItem. + + RsPgpId pgp_id; + + if(!fpr.isNull()) + pgp_id = rsPeers->pgpIdFromFingerprint(fpr); + else + pgp_id = _pgp_id; auto it2 = pgp_indices.find(pgp_id); @@ -1087,7 +1094,7 @@ void RsFriendListModel::updateInternalData() { // 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); + it2 = createInvalidatedProfile(hnode.node_info.gpg_id,hnode.node_info.fpr,pgp_indices,mProfiles); } mProfiles[it2->second].child_node_indices.push_back(mLocations.size()); diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index c3df062cd..5e8d84930 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -164,9 +164,10 @@ private: std::vector& mProfiles, bool create); - std::map::const_iterator createInvalidatedProfile(const RsPgpFingerprint& pgp_id, - std::map& pgp_indices, - std::vector& mProfiles); + std::map::const_iterator createInvalidatedProfile(const RsPgpId& pgp_id, + const RsPgpFingerprint& fpr, + std::map& pgp_indices, + std::vector& mProfiles); QVariant sizeHintRole (const EntryIndex& e, int col) const; QVariant displayRole (const EntryIndex& e, int col) const; From a20ec1a8850939247930b36bbe9138e0ee025f29 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 14 Sep 2019 15:33:43 +0200 Subject: [PATCH 30/45] fixed exchange of PGP keys in binary format and update of PGP signature flags on short invites when the key is received --- .../gossipdiscovery/gossipdiscoveryitems.cc | 15 +- .../gossipdiscovery/gossipdiscoveryitems.h | 20 +- .../src/gossipdiscovery/p3gossipdiscovery.cc | 228 ++++++++++++------ .../src/gossipdiscovery/p3gossipdiscovery.h | 7 +- libretroshare/src/pgp/pgphandler.cc | 14 +- libretroshare/src/pgp/pgphandler.h | 2 + libretroshare/src/pqi/authgpg.cc | 13 + libretroshare/src/pqi/authgpg.h | 1 + libretroshare/src/pqi/p3peermgr.cc | 39 ++- libretroshare/src/pqi/p3peermgr.h | 6 +- libretroshare/src/retroshare/rspeers.h | 7 +- libretroshare/src/rsserver/p3peers.cc | 17 +- libretroshare/src/rsserver/p3peers.h | 1 + 13 files changed, 274 insertions(+), 96 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc index 9b62d45ba..c1e00616d 100644 --- a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc +++ b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc @@ -36,7 +36,8 @@ RsItem *RsDiscSerialiser::create_item( switch(static_cast(item_subtype)) { case RsGossipDiscoveryItemType::PGP_LIST: return new RsDiscPgpListItem(); - case RsGossipDiscoveryItemType::PGP_CERT: return new RsDiscPgpCertItem(); +// case RsGossipDiscoveryItemType::PGP_CERT: return new RsDiscPgpCertItem(); + case RsGossipDiscoveryItemType::PGP_CERT_BINARY: return new RsDiscPgpKeyItem(); case RsGossipDiscoveryItemType::CONTACT: return new RsDiscContactItem(); case RsGossipDiscoveryItemType::IDENTITY_LIST: return new RsDiscIdentityListItem(); @@ -78,6 +79,18 @@ void RsDiscPgpCertItem::serial_process(RsGenericSerializer::SerializeJob j,RsGen RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PGPCERT,pgpCert,"pgpCert") ; } +void RsDiscPgpKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,pgpKeyId,"pgpKeyId") ; + RsTypeSerializer::serial_process(j,ctx,pgpKeyData,"pgpKeyData") ; +} + +void RsDiscPgpKeyItem::clear() +{ + pgpKeyId.clear(); + pgpKeyData.TlvClear(); +} + void RsDiscContactItem::clear() { pgpId.clear(); diff --git a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h index 70bf5920a..c65b9c3a4 100644 --- a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h +++ b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h @@ -25,6 +25,7 @@ #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" #include "serialiser/rstlvaddrs.h" +#include "serialiser/rstlvbinary.h" #include "rsitems/rsserviceids.h" #include "rsitems/rsitem.h" #include "rsitems/itempriorities.h" @@ -34,11 +35,12 @@ enum class RsGossipDiscoveryItemType : uint8_t { PGP_LIST = 0x1, - PGP_CERT = 0x2, + PGP_CERT = 0x2, // deprecated CONTACT = 0x5, IDENTITY_LIST = 0x6, INVITE = 0x7, - INVITE_REQUEST = 0x8 + INVITE_REQUEST = 0x8, + PGP_CERT_BINARY = 0x9, }; class RsDiscItem: public RsItem @@ -96,6 +98,20 @@ public: std::string pgpCert; }; +class RsDiscPgpKeyItem: public RsDiscItem +{ +public: + + RsDiscPgpKeyItem() : RsDiscItem(RsGossipDiscoveryItemType::PGP_CERT_BINARY) + { setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_CERT); } + + void clear() override; + void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx) override; + + RsPgpId pgpKeyId; // duplicate information for practical reasons + RsTlvBinaryData pgpKeyData; +}; + class RsDiscContactItem: public RsDiscItem { public: diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index 0accc64c7..e1b435df3 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -32,6 +32,7 @@ /**** * #define P3DISC_DEBUG 1 ****/ +#define P3DISC_DEBUG 1 /*extern*/ std::shared_ptr rsGossipDiscovery(nullptr); @@ -261,11 +262,12 @@ int p3discovery2::handleIncoming() while(nullptr != (item = recvItem())) { RsDiscPgpListItem* pgplist = nullptr; - RsDiscPgpCertItem* pgpcert = nullptr; + RsDiscPgpCertItem* pgpcert = nullptr; // deprecated + RsDiscPgpKeyItem* pgpkey = nullptr; RsDiscContactItem* contact = nullptr; RsDiscIdentityListItem* gxsidlst = nullptr; - RsGossipDiscoveryInviteItem* invite = nullptr; - RsGossipDiscoveryInviteRequestItem* inviteReq = nullptr; +// RsGossipDiscoveryInviteItem* invite = nullptr; +// RsGossipDiscoveryInviteRequestItem* inviteReq = nullptr; ++nhandled; @@ -276,16 +278,18 @@ int p3discovery2::handleIncoming() { if (item->PeerId() == contact->sslId) recvOwnContactInfo(item->PeerId(), contact); - else processContactInfo(item->PeerId(), contact); + else + processContactInfo(item->PeerId(), contact); } - else if( (gxsidlst = dynamic_cast(item)) - != nullptr ) + else if( (gxsidlst = dynamic_cast(item)) != nullptr ) { recvIdentityList(item->PeerId(),gxsidlst->ownIdentityList); delete item; } - else if((pgpcert = dynamic_cast(item)) != nullptr) - recvPGPCertificate(item->PeerId(), pgpcert); +// else if((pgpcert = dynamic_cast(item)) != nullptr) +// recvPGPCertificate(item->PeerId(), pgpcert); + else if((pgpkey = dynamic_cast(item)) != nullptr) + recvPGPCertificate(item->PeerId(), pgpkey); else if((pgplist = dynamic_cast(item)) != nullptr) { if (pgplist->mode == RsGossipDiscoveryPgpListMode::FRIENDS) @@ -294,16 +298,15 @@ int p3discovery2::handleIncoming() recvPGPCertificateRequest(pgplist->PeerId(), pgplist); else delete item; } - else if( (invite = dynamic_cast(item)) - != nullptr ) - recvInvite(std::unique_ptr(invite)); - else if( (inviteReq = - dynamic_cast(item)) - != nullptr ) - { - sendInvite(inviteReq->mInviteId, item->PeerId()); - delete item; - } +// else if( (invite = dynamic_cast(item)) != nullptr ) +// recvInvite(std::unique_ptr(invite)); +// else if( (inviteReq = +// dynamic_cast(item)) +// != nullptr ) +// { +// sendInvite(inviteReq->mInviteId, item->PeerId()); +// delete item; +// } else { RsWarn() << __PRETTY_FUNCTION__ << " Received unknown item type! " @@ -365,6 +368,7 @@ void p3discovery2::sendOwnContactInfo(const SSLID &sslid) void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactItem *item) { + std::unique_ptr pitem(item); // ensures that item will be destroyed whichever door we leave through #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::recvOwnContactInfo()"; @@ -377,6 +381,21 @@ void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactIt std::cerr << " -> location : " << item->location << std::endl; std::cerr << std::endl; #endif + // Check that the "own" ID sent corresponds to the one we think it should be. + // Some of these checks may look superfluous but it's better to risk to check twice than not check at all. + + // was obtained using a short invite. , and that the friend is marked as "ignore PGP validation" because it + RsPeerDetails det ; + if(!rsPeers->getPeerDetails(fromId,det)) + { + std::cerr << "(EE) Cannot obtain details from " << fromId << " who is supposed to be a friend! Dropping the info." << std::endl; + return; + } + if(det.gpg_id != item->pgpId) + { + std::cerr << "(EE) peer " << fromId << " sent own details with PGP key ID " << item->pgpId << " which does not match the known key id " << det.gpg_id << ". Dropping the info." << std::endl; + return; + } // Peer Own Info replaces the existing info, because the // peer is the primary source of his own IPs. @@ -389,6 +408,17 @@ void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactIt updatePeerAddresses(item); + // if the peer is not validated, we stop the exchange here + + if(det.skip_signature_validation) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::recvOwnContactInfo() missing PGP key " << item->pgpId << " from short invite friend " << fromId << ". Requesting it." << std::endl; +#endif + requestPGPCertificate(det.gpg_id, fromId); + return; + } + // This information will be sent out to online peers, at the receipt of their PGPList. // It is important that PGPList is received after the OwnContactItem. // This should happen, but is not enforced by the protocol. @@ -422,17 +452,6 @@ void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactIt #endif } } - else - { -#ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::recvOwnContactInfo()"; - std::cerr << " ERROR missing PGP Entry: " << pgpId; - std::cerr << std::endl; -#endif - } - - // cleanup. - delete item; } void p3discovery2::recvIdentityList(const RsPeerId& pid,const std::list& ids) @@ -690,7 +709,7 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem * if (!AuthGPG::getAuthGPG()->isGPGId(*fit)) { #ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::processPGPList() requesting PgpId: " << *fit; + std::cerr << "p3discovery2::processPGPList() requesting certificate for PgpId: " << *fit; std::cerr << " from SslId: " << fromId; std::cerr << std::endl; #endif @@ -1023,30 +1042,97 @@ void p3discovery2::recvPGPCertificateRequest( } -void p3discovery2::sendPGPCertificate(const PGPID &aboutId, const SSLID &toId) +void p3discovery2::sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId) { - RsDiscPgpCertItem* item = new RsDiscPgpCertItem(); - item->pgpId = aboutId; - item->PeerId(toId); + //RsDiscPgpCertItem* item = new RsDiscPgpCertItem(); + //item->pgpId = aboutId; - Dbg4() << __PRETTY_FUNCTION__ << " queuing for Cert generation: " - << std::endl << *item << std::endl; + //Dbg4() << __PRETTY_FUNCTION__ << " queuing for Cert generation: " << std::endl << *item << std::endl; - { - RS_STACK_MUTEX(mDiscMtx); - mPendingDiscPgpCertOutList.push_back(item); - } + RsDiscPgpKeyItem *pgp_key_item = new RsDiscPgpKeyItem; + + pgp_key_item->PeerId(toId); + pgp_key_item->pgpKeyId = aboutId; + unsigned char *bin_data; + size_t bin_len; + + if(!AuthGPG::getAuthGPG()->exportPublicKey(aboutId,bin_data,bin_len,false,true)) + { + std::cerr << "(EE) cannot export public key " << aboutId << " requested by peer " << toId << std::endl; + return ; + } + + pgp_key_item->pgpKeyData.bin_data = bin_data; + pgp_key_item->pgpKeyData.bin_len = bin_len; + + sendItem(pgp_key_item); + + // (cyril) we shouldn't need to use a queue for that! There's no cost in getting a PGP cert from AuthGPG. + // { + // RS_STACK_MUTEX(mDiscMtx); + // mPendingDiscPgpCertOutList.push_back(item); + // } } -void p3discovery2::recvPGPCertificate( - const SSLID& /*fromId*/, RsDiscPgpCertItem* item ) +void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem* item ) { + // 1 - check that the cert structure is valid. + + RsPgpId cert_pgp_id; + std::string cert_name; + std::list cert_signers; + + if(!AuthGPG::getAuthGPG()->getGPGDetailsFromBinaryBlock( (unsigned char*)item->pgpKeyData.bin_data,item->pgpKeyData.bin_len, cert_pgp_id, cert_name, cert_signers )) + { + std::cerr << "(EE) cannot parse own PGP key sent by " << fromId << std::endl; + return; + } + + if(cert_pgp_id != item->pgpKeyId) + { + std::cerr << "(EE) received a PGP key from " << fromId << " which ID (" << cert_pgp_id << ") is different from the one anounced in the packet (" << item->pgpKeyId << ")!" << std::endl; + return; + } + + // 2 - check if the peer who is sending us a cert is already validated + + RsPeerDetails det; + if(!rsPeers->getPeerDetails(fromId,det)) + { + std::cerr << "(EE) cannot get peer details from friend " << fromId << ": this is very wrong!"<< std::endl; + return; + } + + // We treat own pgp keys right away when they are sent by a friend for which we dont have it. This way we can keep the skip_pgg_signature_validation consistent + + if(det.skip_signature_validation) + { #ifdef P3DISC_DEBUG - std::cerr << __PRETTY_FUNCTION__ << " queuing for Cert loading" << std::endl; + std::cerr << __PRETTY_FUNCTION__ << " Received own full certificate from short-invite friend " << fromId << std::endl; #endif - /* push this back to be processed by pgp when possible */ - RS_STACK_MUTEX(mDiscMtx); - mPendingDiscPgpCertInList.push_back(item); + // do some extra checks. Dont remove them. They cost nothing as compared to what they could avoid. + + if(item->pgpKeyId != det.gpg_id) + { + std::cerr << "(EE) received a PGP key with ID " << item->pgpKeyId << " from non validated peer " << fromId << ", which should only be allowed to send his own key " << det.gpg_id << std::endl; + return; + } + } + RsPgpId tmp_pgp_id; + std::string error_string; + +#ifdef P3DISC_DEBUG + std::cerr << __PRETTY_FUNCTION__ << "Received PGP key " << cert_pgp_id << " from from friend " << fromId << ". Adding to keyring." << std::endl; +#endif + // now that will add the key *and* set the skip_signature_validation flag at once + rsPeers->loadPgpKeyFromBinaryData((unsigned char*)item->pgpKeyData.bin_data,item->pgpKeyData.bin_len, tmp_pgp_id,error_string); // no error should occur at this point because we called loadDetailsFromStringCert() already + delete item; + + // Make sure we allow connections after the key is added. This is not the case otherwise. We only do that if the peer is non validated peer, since + // otherwise the connection should already be accepted. This only happens when the short invite peer sends its own PGP key. + + if(det.skip_signature_validation) + AuthGPG::getAuthGPG()->AllowConnection(det.gpg_id,true); } /************* from pqiServiceMonitor *******************/ @@ -1139,7 +1225,7 @@ bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list &proxy bool p3discovery2::getWaitingDiscCount(size_t &sendCount, size_t &recvCount) { RS_STACK_MUTEX(mDiscMtx); - sendCount = mPendingDiscPgpCertOutList.size(); + //sendCount = mPendingDiscPgpCertOutList.size(); recvCount = mPendingDiscPgpCertInList.size(); return true; @@ -1256,20 +1342,18 @@ void p3discovery2::rsEventsHandler(const RsEvent& event) switch(event.mType) { - case RsEventType::PEER_STATE_CHANGED: - { - const RsPeerId& sslId = - static_cast(event).mSslId; - if( rsPeers && rsPeers->isSslOnlyFriend(sslId) && - mServiceCtrl->isPeerConnected( - getServiceInfo().mServiceType, sslId ) ) - { - if(!requestInvite(sslId, sslId)) - RsErr() << __PRETTY_FUNCTION__ << " requestInvite to peer " - << sslId << " failed" << std::endl; - } - break; - } +// case RsEventType::PEER_STATE_CHANGED: +// { +// const RsPeerId& sslId = static_cast(event).mSslId; +// +// if( rsPeers && rsPeers->isSslOnlyFriend(sslId) && mServiceCtrl->isPeerConnected( getServiceInfo().mServiceType, sslId ) ) +// { +// if(!requestPGPCertificate(sslId, sslId)) +// RsErr() << __PRETTY_FUNCTION__ << " requestInvite to peer " +// << sslId << " failed" << std::endl; +// } +// break; +// } default: break; } } @@ -1292,17 +1376,17 @@ AuthGPGOperation *p3discovery2::getGPGOperation() } } - { - RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - - /* process disc reply in list */ - if (!mPendingDiscPgpCertOutList.empty()) { - RsDiscPgpCertItem *item = mPendingDiscPgpCertOutList.front(); - mPendingDiscPgpCertOutList.pop_front(); - - return new AuthGPGOperationLoadOrSave(false, item->pgpId, "", item); - } - } +// { +// RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ +// +// /* process disc reply in list */ +// if (!mPendingDiscPgpCertOutList.empty()) { +// RsDiscPgpCertItem *item = mPendingDiscPgpCertOutList.front(); +// mPendingDiscPgpCertOutList.pop_front(); +// +// return new AuthGPGOperationLoadOrSave(false, item->pgpId, "", item); +// } +// } return NULL; } diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h index 6c6864fb9..eaf148bb5 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h @@ -130,8 +130,9 @@ private: void recvPGPCertificateRequest( const RsPeerId& fromId, const RsDiscPgpListItem* item ); - void sendPGPCertificate(const PGPID &aboutId, const SSLID &toId); - void recvPGPCertificate(const SSLID &fromId, RsDiscPgpCertItem *item); + void sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId); + void recvPGPCertificate(const SSLID &fromId, RsDiscPgpCertItem *item); // deprecated + void recvPGPCertificate(const SSLID &fromId, RsDiscPgpKeyItem *item); void recvIdentityList(const RsPeerId& pid,const std::list& ids); bool setPeerVersion(const SSLID &peerId, const std::string &version); @@ -160,7 +161,7 @@ private: std::map mLocationMap; std::list mPendingDiscPgpCertInList; - std::list mPendingDiscPgpCertOutList; + //std::list mPendingDiscPgpCertOutList; protected: RS_SET_CONTEXT_DEBUG_LEVEL(1) diff --git a/libretroshare/src/pgp/pgphandler.cc b/libretroshare/src/pgp/pgphandler.cc index 46e8b166c..48915aa85 100644 --- a/libretroshare/src/pgp/pgphandler.cc +++ b/libretroshare/src/pgp/pgphandler.cc @@ -1037,7 +1037,17 @@ void PGPHandler::addNewKeyToOPSKeyring(ops_keyring_t *kr,const ops_keydata_t& ke kr->nkeys++ ; } +bool PGPHandler::LoadCertificateFromBinaryData(const unsigned char *data,uint32_t data_len,RsPgpId& id,std::string& error_string) +{ + return LoadCertificate(data,data_len,ops_false,id,error_string); +} + bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,RsPgpId& id,std::string& error_string) +{ + return LoadCertificate((unsigned char*)(pgp_cert.c_str()),pgp_cert.length(),ops_true,id,error_string); +} + +bool PGPHandler::LoadCertificate(const unsigned char *data,uint32_t data_len,bool armoured,RsPgpId& id,std::string& error_string) { RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures. #ifdef DEBUG_PGPHANDLER @@ -1046,9 +1056,9 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,RsPgpId& ops_keyring_t *tmp_keyring = allocateOPSKeyring(); ops_memory_t *mem = ops_memory_new() ; - ops_memory_add(mem,(unsigned char *)pgp_cert.c_str(),pgp_cert.length()) ; + ops_memory_add(mem,data,data_len) ; - if(!ops_keyring_read_from_mem(tmp_keyring,ops_true,mem)) + if(!ops_keyring_read_from_mem(tmp_keyring,armoured,mem)) { ops_keyring_free(tmp_keyring) ; free(tmp_keyring) ; diff --git a/libretroshare/src/pgp/pgphandler.h b/libretroshare/src/pgp/pgphandler.h index e6c16764e..fee240e6a 100644 --- a/libretroshare/src/pgp/pgphandler.h +++ b/libretroshare/src/pgp/pgphandler.h @@ -104,6 +104,7 @@ class PGPHandler bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, const int keynumbits, std::string& errString) ; bool LoadCertificateFromString(const std::string& pem, RsPgpId& gpg_id, std::string& error_string); + bool LoadCertificateFromBinaryData(const unsigned char *bin_data,uint32_t bin_data_len, RsPgpId& gpg_id, std::string& error_string); std::string SaveCertificateToString(const RsPgpId& id,bool include_signatures) const ; bool exportPublicKey(const RsPgpId& id,unsigned char *& mem,size_t& mem_size,bool armoured,bool include_signatures) const ; @@ -172,6 +173,7 @@ class PGPHandler bool syncDatabase() ; private: + bool LoadCertificate(const unsigned char *bin_data,uint32_t bin_data_len, bool armoured, RsPgpId& gpg_id, std::string& error_string); void initCertificateInfo(PGPCertificateInfo& cert,const ops_keydata_t *keydata,uint32_t i) ; // Returns true if the signatures have been updated diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index bf485a2ad..076cb66b5 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -534,6 +534,19 @@ bool AuthGPG::getGPGSignedList(std::list &ids) return PGPHandler::SaveCertificateToString(id,include_signatures) ; } +/* import to GnuPG and other Certificates */ +bool AuthGPG::LoadPGPKeyFromBinaryData(const unsigned char *data,uint32_t data_len, RsPgpId& gpg_id,std::string& error_string) +{ + RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/ + + if(PGPHandler::LoadCertificateFromBinaryData(data,data_len,gpg_id,error_string)) + { + updateOwnSignatureFlag(gpg_id,mOwnGpgId) ; + return true ; + } + + return false ; +} /* import to GnuPG and other Certificates */ bool AuthGPG::LoadCertificateFromString(const std::string &str, RsPgpId& gpg_id,std::string& error_string) diff --git a/libretroshare/src/pqi/authgpg.h b/libretroshare/src/pqi/authgpg.h index 11b7203dd..871830445 100644 --- a/libretroshare/src/pqi/authgpg.h +++ b/libretroshare/src/pqi/authgpg.h @@ -172,6 +172,7 @@ public: * ****/ virtual bool LoadCertificateFromString(const std::string &pem, RsPgpId& gpg_id,std::string& error_string); + virtual bool LoadPGPKeyFromBinaryData(const unsigned char *data,uint32_t data_len, RsPgpId& gpg_id,std::string& error_string); virtual std::string SaveCertificateToString(const RsPgpId &id,bool include_signatures) ; // Cached certificates. diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 90ca5cecd..57faff741 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -886,8 +886,7 @@ bool p3PeerMgrIMPL::haveOnceConnected() RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ /* check for existing */ - std::map::iterator it; - for(it = mFriendList.begin(); it != mFriendList.end(); ++it) + for(auto it = mFriendList.begin(); it != mFriendList.end(); ++it) { if (it->second.lastcontact > 0) { @@ -910,6 +909,28 @@ bool p3PeerMgrIMPL::haveOnceConnected() } +bool p3PeerMgrIMPL::notifyPgpKeyReceived(const RsPgpId& pgp_id) +{ + RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + + bool changed = false; + + for(auto it(mFriendList.begin());it!=mFriendList.end();++it) + { + if(it->second.gpg_id == pgp_id) + { + std::cerr << "(WW) notification that full key " << pgp_id << " is available. Reseting short invite flag for peer " << it->first << std::endl; + it->second.skip_pgp_signature_validation = false; + + changed = true; + } + } + + if(changed) + IndicateConfigChanged(); + + return true; +} /*******************************************************************/ /*******************************************************************/ @@ -946,16 +967,9 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg std::map::iterator it; if (mFriendList.end() != (it=mFriendList.find(id))) { -#ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::addFriend() Already Exists" << std::endl; -#endif - if(it->second.gpg_id.isNull()) // already exists as a SSL-only friend - { - it->second.gpg_id = input_gpg_id; - it->second.skip_pgp_signature_validation = false; - return true; - } - else if(it->second.gpg_id != input_gpg_id)// already exists as a friend with a different PGP id!! + // The friend may already be here, including with a short invite (meaning the PGP key is unknown). + + if(it->second.gpg_id != input_gpg_id)// already exists as a friend with a different PGP id!! { RsErr() << "Trying to add SSL id (" << id << ") that is already a friend with existing PGP key (" << it->second.gpg_id << ") but using a different PGP key (" << input_gpg_id << "). This is a bug!" << std::endl; return false; @@ -975,6 +989,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg return false; } + // after that, we know that we have the key, because AuthGPG wouldn't answer yes for a key it doesn't know. /* check if it is in others */ if (mOthersList.end() != (it = mOthersList.find(id))) diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 131cec418..f8cfa64ed 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -80,7 +80,6 @@ class peerState // have short invites. However, because this represent a significant security risk, we perform multiple consistency checks // whenever we use this flag, in particular: // flat is true <==> friend SSL cert is in the friend list, but PGP id is not in the friend list - // PGP id is undefined and therefore set to null bool skip_pgp_signature_validation; @@ -140,6 +139,9 @@ public: const RsPgpId& pgpId, const RsPeerDetails& details = RsPeerDetails() ) = 0; + // Calling this removed the skip_pgp_signature_validation flag on all peers which PGP key is the one supplied. + virtual bool notifyPgpKeyReceived(const RsPgpId& pgp_key_id) = 0; + virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId) = 0; virtual bool isFriend(const RsPeerId& ssl_id) = 0; virtual bool isSslOnlyFriend(const RsPeerId &ssl_id)=0; @@ -259,6 +261,8 @@ public: bool addSslOnlyFriend(const RsPeerId& sslId, const RsPgpId &pgp_id, const RsPeerDetails& details = RsPeerDetails() ) override; + virtual bool notifyPgpKeyReceived(const RsPgpId& pgp_key_id) override; + virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId); virtual bool removeFriend(const RsPgpId &pgp_id); diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index cb9f1ec27..383430541 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -74,7 +74,7 @@ const uint32_t RS_HIDDEN_TYPE_I2P = 0x0004; /* mask to match all valid hidden types */ const uint32_t RS_HIDDEN_TYPE_MASK = RS_HIDDEN_TYPE_I2P | RS_HIDDEN_TYPE_TOR; -/* Visibility */ +/* Visibility parameter for discovery */ const uint32_t RS_VS_DISC_OFF = 0x0000; const uint32_t RS_VS_DISC_MINIMAL = 0x0001; const uint32_t RS_VS_DISC_FULL = 0x0002; @@ -734,6 +734,11 @@ public: const std::string& cert, RsPeerDetails& certDetails, uint32_t& errorCode ) = 0; + virtual bool loadPgpKeyFromBinaryData( const unsigned char *bin_key_data, + uint32_t bin_key_len, + RsPgpId& gpg_id, + std::string& error_string )=0; + // Certificate utils virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,uint32_t& error_code) = 0; virtual bool saveCertificateToFile(const RsPeerId& id, const std::string &fname) = 0; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index c320c0260..393ae816e 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1526,12 +1526,25 @@ bool p3Peers::loadCertificateFromString( } RsPgpId gpgid; - bool res = AuthGPG::getAuthGPG()->LoadCertificateFromString( - crt->armouredPGPKey(), gpgid, error_string ); + bool res = AuthGPG::getAuthGPG()->LoadCertificateFromString( crt->armouredPGPKey(), gpgid, error_string ); gpg_id = gpgid; ssl_id = crt->sslid(); + // now get all friends who declare this key ID to be the one needed to check connections, and clear their "skip_pgp_signature_validation" flag + + if(res) + mPeerMgr->notifyPgpKeyReceived(gpgid); + + return res; +} +bool p3Peers::loadPgpKeyFromBinaryData( const unsigned char *bin_key_data,uint32_t bin_key_len, RsPgpId& gpg_id, std::string& error_string ) +{ + bool res = AuthGPG::getAuthGPG()->LoadPGPKeyFromBinaryData( bin_key_data,bin_key_len, gpg_id, error_string ); + + if(res) + mPeerMgr->notifyPgpKeyReceived(gpg_id); + return res; } diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index b5b8d09d5..ad6f2d056 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -157,6 +157,7 @@ public: virtual bool hasExportMinimal(); virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string); + virtual bool loadPgpKeyFromBinaryData( const unsigned char *bin_key_data,uint32_t bin_key_len, RsPgpId& gpg_id, std::string& error_string ); virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code); virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert, bool &is_short_format, uint32_t& error_code) override; From bea6769a4e23b9e20af738e6e302b8c0324e1472 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 14 Sep 2019 16:26:24 +0200 Subject: [PATCH 31/45] removed unused code from p3gossipdiscovery --- .../gossipdiscovery/gossipdiscoveryitems.cc | 39 +- .../gossipdiscovery/gossipdiscoveryitems.h | 44 +-- .../src/gossipdiscovery/p3gossipdiscovery.cc | 366 +++++++----------- .../src/gossipdiscovery/p3gossipdiscovery.h | 75 ++-- .../src/retroshare/rsgossipdiscovery.h | 32 +- libretroshare/src/rsserver/rsinit.cc | 2 +- 6 files changed, 172 insertions(+), 386 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc index c1e00616d..3d56e3bc9 100644 --- a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc +++ b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc @@ -36,15 +36,11 @@ RsItem *RsDiscSerialiser::create_item( switch(static_cast(item_subtype)) { case RsGossipDiscoveryItemType::PGP_LIST: return new RsDiscPgpListItem(); -// case RsGossipDiscoveryItemType::PGP_CERT: return new RsDiscPgpCertItem(); case RsGossipDiscoveryItemType::PGP_CERT_BINARY: return new RsDiscPgpKeyItem(); case RsGossipDiscoveryItemType::CONTACT: return new RsDiscContactItem(); - case RsGossipDiscoveryItemType::IDENTITY_LIST: - return new RsDiscIdentityListItem(); - case RsGossipDiscoveryItemType::INVITE: - return new RsGossipDiscoveryInviteItem(); - case RsGossipDiscoveryItemType::INVITE_REQUEST: - return new RsGossipDiscoveryInviteRequestItem(); + case RsGossipDiscoveryItemType::IDENTITY_LIST: return new RsDiscIdentityListItem(); + default: + return NULL; } return nullptr; @@ -66,19 +62,6 @@ void RsDiscPgpListItem::serial_process( RS_SERIAL_PROCESS(pgpIdSet); } -void RsDiscPgpCertItem::clear() -{ - pgpId.clear(); - pgpCert.clear(); -} - - -void RsDiscPgpCertItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) -{ - RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; - RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PGPCERT,pgpCert,"pgpCert") ; -} - void RsDiscPgpKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,pgpKeyId,"pgpKeyId") ; @@ -159,17 +142,9 @@ void RsDiscIdentityListItem::serial_process(RsGenericSerializer::SerializeJob j, RS_SERIAL_PROCESS(ownIdentityList); } - -RsGossipDiscoveryInviteItem::RsGossipDiscoveryInviteItem() : - RsDiscItem(RsGossipDiscoveryItemType::INVITE) -{ setPriorityLevel(QOS_PRIORITY_RS_DISC_ASK_INFO); } - -RsGossipDiscoveryInviteRequestItem::RsGossipDiscoveryInviteRequestItem() : - RsDiscItem(RsGossipDiscoveryItemType::INVITE_REQUEST) -{ setPriorityLevel(QOS_PRIORITY_RS_DISC_REPLY); } - -RsDiscItem::RsDiscItem(RsGossipDiscoveryItemType subtype) : - RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, - static_cast(subtype) ) {} +RsDiscItem::RsDiscItem(RsGossipDiscoveryItemType subtype) + : RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, static_cast(subtype) ) +{ +} RsDiscItem::~RsDiscItem() {} diff --git a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h index c65b9c3a4..5e147d2ba 100644 --- a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h +++ b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h @@ -38,8 +38,8 @@ enum class RsGossipDiscoveryItemType : uint8_t PGP_CERT = 0x2, // deprecated CONTACT = 0x5, IDENTITY_LIST = 0x6, - INVITE = 0x7, - INVITE_REQUEST = 0x8, + INVITE = 0x7, // deprecated + INVITE_REQUEST = 0x8, // deprecated PGP_CERT_BINARY = 0x9, }; @@ -82,22 +82,6 @@ public: RsTlvPgpIdSet pgpIdSet; }; -class RsDiscPgpCertItem: public RsDiscItem -{ -public: - - RsDiscPgpCertItem() : RsDiscItem(RsGossipDiscoveryItemType::PGP_CERT) - { setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_CERT); } - - void clear() override; - void serial_process( - RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx) override; - - RsPgpId pgpId; - std::string pgpCert; -}; - class RsDiscPgpKeyItem: public RsDiscItem { public: @@ -174,30 +158,6 @@ public: std::list ownIdentityList; }; -struct RsGossipDiscoveryInviteItem : RsDiscItem -{ - RsGossipDiscoveryInviteItem(); - - void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx ) override - { RS_SERIAL_PROCESS(mInvite); } - void clear() override { mInvite.clear(); } - - std::string mInvite; -}; - -struct RsGossipDiscoveryInviteRequestItem : RsDiscItem -{ - RsGossipDiscoveryInviteRequestItem(); - - void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx ) override - { RS_SERIAL_PROCESS(mInviteId); } - void clear() override { mInviteId.clear(); } - - RsPeerId mInviteId; -}; - class RsDiscSerialiser: public RsServiceSerializer { public: diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index e1b435df3..d0b3e54be 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -36,9 +36,6 @@ /*extern*/ std::shared_ptr rsGossipDiscovery(nullptr); -RsGossipDiscovery::~RsGossipDiscovery() {}; - - static bool populateContactInfo( const peerState &detail, RsDiscContactItem *pkt, bool include_ip_information ) @@ -88,9 +85,9 @@ static bool populateContactInfo( const peerState &detail, return true; } -void DiscPgpInfo::mergeFriendList(const std::set &friends) +void DiscPgpInfo::mergeFriendList(const std::set &friends) { - std::set::const_iterator it; + std::set::const_iterator it; for(it = friends.begin(); it != friends.end(); ++it) { mFriendSet.insert(*it); @@ -141,13 +138,13 @@ RsServiceInfo p3discovery2::getServiceInfo() p3discovery2::~p3discovery2() { rsEvents->unregisterEventsHandler(mRsEventsHandle); } -void p3discovery2::addFriend(const SSLID &sslId) +void p3discovery2::addFriend(const RsPeerId &sslId) { - PGPID pgpId = getPGPId(sslId); + RsPgpId pgpId = getPGPId(sslId); RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(pgpId); if (it == mFriendList.end()) { @@ -162,9 +159,9 @@ void p3discovery2::addFriend(const SSLID &sslId) } - /* now add SSLID */ + /* now add RsPeerId */ - std::map::iterator sit; + std::map::iterator sit; sit = it->second.mSslIds.find(sslId); if (sit == it->second.mSslIds.end()) { @@ -189,13 +186,13 @@ void p3discovery2::addFriend(const SSLID &sslId) } } -void p3discovery2::removeFriend(const SSLID &sslId) +void p3discovery2::removeFriend(const RsPeerId &sslId) { - PGPID pgpId = getPGPId(sslId); + RsPgpId pgpId = getPGPId(sslId); RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(pgpId); if (it == mFriendList.end()) { @@ -206,7 +203,7 @@ void p3discovery2::removeFriend(const SSLID &sslId) return; } - std::map::iterator sit; + std::map::iterator sit; sit = it->second.mSslIds.find(sslId); if (sit == it->second.mSslIds.end()) { @@ -241,9 +238,9 @@ void p3discovery2::removeFriend(const SSLID &sslId) } } -PGPID p3discovery2::getPGPId(const SSLID &id) +RsPgpId p3discovery2::getPGPId(const RsPeerId &id) { - PGPID pgpId; + RsPgpId pgpId; mPeerMgr->getGpgId(id, pgpId); return pgpId; } @@ -261,13 +258,10 @@ int p3discovery2::handleIncoming() // While messages read while(nullptr != (item = recvItem())) { - RsDiscPgpListItem* pgplist = nullptr; - RsDiscPgpCertItem* pgpcert = nullptr; // deprecated - RsDiscPgpKeyItem* pgpkey = nullptr; - RsDiscContactItem* contact = nullptr; + RsDiscPgpListItem* pgplist = nullptr; + RsDiscPgpKeyItem* pgpkey = nullptr; + RsDiscContactItem* contact = nullptr; RsDiscIdentityListItem* gxsidlst = nullptr; -// RsGossipDiscoveryInviteItem* invite = nullptr; -// RsGossipDiscoveryInviteRequestItem* inviteReq = nullptr; ++nhandled; @@ -286,8 +280,6 @@ int p3discovery2::handleIncoming() recvIdentityList(item->PeerId(),gxsidlst->ownIdentityList); delete item; } -// else if((pgpcert = dynamic_cast(item)) != nullptr) -// recvPGPCertificate(item->PeerId(), pgpcert); else if((pgpkey = dynamic_cast(item)) != nullptr) recvPGPCertificate(item->PeerId(), pgpkey); else if((pgplist = dynamic_cast(item)) != nullptr) @@ -298,19 +290,10 @@ int p3discovery2::handleIncoming() recvPGPCertificateRequest(pgplist->PeerId(), pgplist); else delete item; } -// else if( (invite = dynamic_cast(item)) != nullptr ) -// recvInvite(std::unique_ptr(invite)); -// else if( (inviteReq = -// dynamic_cast(item)) -// != nullptr ) -// { -// sendInvite(inviteReq->mInviteId, item->PeerId()); -// delete item; -// } else { - RsWarn() << __PRETTY_FUNCTION__ << " Received unknown item type! " - << std::endl << item << std::endl; + RsWarn() << __PRETTY_FUNCTION__ << " Received unknown item type " << (int)item->PacketSubType() << "! " << std::endl ; + RsWarn() << item << std::endl; delete item; } } @@ -318,7 +301,7 @@ int p3discovery2::handleIncoming() return nhandled; } -void p3discovery2::sendOwnContactInfo(const SSLID &sslid) +void p3discovery2::sendOwnContactInfo(const RsPeerId &sslid) { #ifdef P3DISC_DEBUG @@ -366,7 +349,7 @@ void p3discovery2::sendOwnContactInfo(const SSLID &sslid) } } -void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactItem *item) +void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContactItem *item) { std::unique_ptr pitem(item); // ensures that item will be destroyed whichever door we leave through @@ -429,11 +412,11 @@ void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactIt // Update mDiscStatus. RS_STACK_MUTEX(mDiscMtx); - PGPID pgpId = getPGPId(fromId); - std::map::iterator it = mFriendList.find(pgpId); + RsPgpId pgpId = getPGPId(fromId); + std::map::iterator it = mFriendList.find(pgpId); if (it != mFriendList.end()) { - std::map::iterator sit = it->second.mSslIds.find(fromId); + std::map::iterator sit = it->second.mSslIds.find(fromId); if (sit != it->second.mSslIds.end()) { sit->second.mDiscStatus = item->vs_disc; @@ -522,7 +505,7 @@ void p3discovery2::updatePeerAddressList(const RsDiscContactItem *item) // Starts the Discovery process. // should only be called it DISC2_STATUS_NOT_HIDDEN(OwnInfo.status). -void p3discovery2::sendPGPList(const SSLID &toId) +void p3discovery2::sendPGPList(const RsPeerId &toId) { updatePgpFriendList(); @@ -537,7 +520,7 @@ void p3discovery2::sendPGPList(const SSLID &toId) pkt->mode = RsGossipDiscoveryPgpListMode::FRIENDS; - std::map::const_iterator it; + std::map::const_iterator it; for(it = mFriendList.begin(); it != mFriendList.end(); ++it) { pkt->pgpIdSet.ids.insert(it->first); @@ -576,14 +559,14 @@ void p3discovery2::updatePgpFriendList() mLastPgpUpdate = time(NULL); - std::list pgpList; - std::set pgpSet; + std::list pgpList; + std::set pgpSet; - std::set::iterator sit; - std::list::iterator lit; - std::map::iterator it; + std::set::iterator sit; + std::list::iterator lit; + std::map::iterator it; - PGPID ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId(); + RsPgpId ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId(); AuthGPG::getAuthGPG()->getGPGAcceptedList(pgpList); pgpList.push_back(ownPgpId); @@ -593,8 +576,8 @@ void p3discovery2::updatePgpFriendList() pgpSet.insert(*lit); } - std::list pgpToAdd; - std::list pgpToRemove; + std::list pgpToAdd; + std::list pgpToRemove; sit = pgpSet.begin(); @@ -660,7 +643,7 @@ void p3discovery2::updatePgpFriendList() } -void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem *item) +void p3discovery2::processPGPList(const RsPeerId &fromId, const RsDiscPgpListItem *item) { RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ @@ -669,8 +652,8 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem * std::cerr << std::endl; #endif - std::map::iterator it; - PGPID fromPgpId = getPGPId(fromId); + std::map::iterator it; + RsPgpId fromPgpId = getPGPId(fromId); it = mFriendList.find(fromPgpId); if (it == mFriendList.end()) { @@ -703,7 +686,7 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem * if (requestUnknownPgpCerts) { - std::set::const_iterator fit; + std::set::const_iterator fit; for(fit = item->pgpIdSet.ids.begin(); fit != item->pgpIdSet.ids.end(); ++fit) { if (!AuthGPG::getAuthGPG()->isGPGId(*fit)) @@ -730,7 +713,7 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem * * -> Update Other Peers about B. * -> Update B about Other Peers. */ -void p3discovery2::updatePeers_locked(const SSLID &aboutId) +void p3discovery2::updatePeers_locked(const RsPeerId &aboutId) { #ifdef P3DISC_DEBUG @@ -738,9 +721,9 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) std::cerr << std::endl; #endif - PGPID aboutPgpId = getPGPId(aboutId); + RsPgpId aboutPgpId = getPGPId(aboutId); - std::map::const_iterator ait; + std::map::const_iterator ait; ait = mFriendList.find(aboutPgpId); if (ait == mFriendList.end()) { @@ -752,12 +735,12 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) return; } - std::set mutualFriends; - std::set onlineFriends; - std::set::const_iterator sit; + std::set mutualFriends; + std::set onlineFriends; + std::set::const_iterator sit; - const std::set &friendSet = ait->second.mFriendSet; - std::set::const_iterator fit; + const std::set &friendSet = ait->second.mFriendSet; + std::set::const_iterator fit; for(fit = friendSet.begin(); fit != friendSet.end(); ++fit) { @@ -766,7 +749,7 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) std::cerr << std::endl; #endif - std::map::const_iterator ffit; + std::map::const_iterator ffit; ffit = mFriendList.find(*fit); if (ffit == mFriendList.end()) { @@ -775,7 +758,7 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) std::cerr << "p3discovery2::updatePeer_locked() Ignoring not our friend"; std::cerr << std::endl; #endif - // Not our friend, or we have no Locations (SSL) for this PGPID (same difference) + // Not our friend, or we have no Locations (SSL) for this RsPgpId (same difference) continue; } @@ -788,16 +771,16 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) #endif mutualFriends.insert(*fit); - std::map::const_iterator mit; + std::map::const_iterator mit; for(mit = ffit->second.mSslIds.begin(); mit != ffit->second.mSslIds.end(); ++mit) { - SSLID sslid = mit->first; + RsPeerId sslid = mit->first; if (mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, sslid)) { // TODO IGNORE if sslid == aboutId, or sslid == ownId. #ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::updatePeer_locked() Adding Online SSLID: " << sslid; + std::cerr << "p3discovery2::updatePeer_locked() Adding Online RsPeerId: " << sslid; std::cerr << std::endl; #endif onlineFriends.insert(sslid); @@ -829,13 +812,13 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId) } } -void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toId) +void p3discovery2::sendContactInfo_locked(const RsPgpId &aboutId, const RsPeerId &toId) { #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::sendContactInfo_locked() aboutPGPId: " << aboutId << " toId: " << toId; std::cerr << std::endl; #endif - std::map::const_iterator it; + std::map::const_iterator it; it = mFriendList.find(aboutId); if (it == mFriendList.end()) { @@ -846,7 +829,7 @@ void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toI return; } - std::map::const_iterator sit; + std::map::const_iterator sit; for(sit = it->second.mSslIds.begin(); sit != it->second.mSslIds.end(); ++sit) { #ifdef P3DISC_DEBUG @@ -902,14 +885,14 @@ void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toI else { #ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::sendContactInfo_locked() SSLID Hidden"; + std::cerr << "p3discovery2::sendContactInfo_locked() RsPeerId Hidden"; std::cerr << std::endl; #endif } } } -void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactItem *item) +void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContactItem *item) { (void) fromId; // remove unused parameter warnings, debug only @@ -925,12 +908,12 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt return; } - std::map::iterator it; + std::map::iterator it; it = mFriendList.find(item->pgpId); if (it == mFriendList.end()) { #ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::processContactInfo(" << fromId << ") PGPID: "; + std::cerr << "p3discovery2::processContactInfo(" << fromId << ") RsPgpId: "; std::cerr << item->pgpId << " Not Friend."; std::cerr << std::endl; std::cerr << "p3discovery2::processContactInfo(" << fromId << ") THIS SHOULD NEVER HAPPEN!"; @@ -956,7 +939,7 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt } bool should_notify_discovery = false; - std::map::iterator sit; + std::map::iterator sit; sit = it->second.mSslIds.find(item->sslId); if (sit == it->second.mSslIds.end()) { @@ -1005,7 +988,7 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt /* we explictly request certificates, instead of getting them all the time */ -void p3discovery2::requestPGPCertificate(const PGPID &aboutId, const SSLID &toId) +void p3discovery2::requestPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId) { #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::requestPGPCertificate() aboutId: " << aboutId << " to: " << toId; @@ -1044,11 +1027,6 @@ void p3discovery2::recvPGPCertificateRequest( void p3discovery2::sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId) { - //RsDiscPgpCertItem* item = new RsDiscPgpCertItem(); - //item->pgpId = aboutId; - - //Dbg4() << __PRETTY_FUNCTION__ << " queuing for Cert generation: " << std::endl << *item << std::endl; - RsDiscPgpKeyItem *pgp_key_item = new RsDiscPgpKeyItem; pgp_key_item->PeerId(toId); @@ -1066,12 +1044,6 @@ void p3discovery2::sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &to pgp_key_item->pgpKeyData.bin_len = bin_len; sendItem(pgp_key_item); - - // (cyril) we shouldn't need to use a queue for that! There's no cost in getting a PGP cert from AuthGPG. - // { - // RS_STACK_MUTEX(mDiscMtx); - // mPendingDiscPgpCertOutList.push_back(item); - // } } void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem* item ) @@ -1190,8 +1162,8 @@ bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list &proxy RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it; - PGPID pgp_id = getPGPId(id); + std::map::const_iterator it; + RsPgpId pgp_id = getPGPId(id); it = mFriendList.find(pgp_id); if (it == mFriendList.end()) @@ -1200,9 +1172,9 @@ bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list &proxy return false; } - // For each of their friends that we know, grab that set of SSLIDs. - const std::set &friendSet = it->second.mFriendSet; - std::set::const_iterator fit; + // For each of their friends that we know, grab that set of RsPeerId. + const std::set &friendSet = it->second.mFriendSet; + std::set::const_iterator fit; for(fit = friendSet.begin(); fit != friendSet.end(); ++fit) { it = mFriendList.find(*fit); @@ -1211,7 +1183,7 @@ bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list &proxy continue; } - std::map::const_iterator sit; + std::map::const_iterator sit; for(sit = it->second.mSslIds.begin(); sit != it->second.mSslIds.end(); ++sit) { @@ -1225,51 +1197,13 @@ bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list &proxy bool p3discovery2::getWaitingDiscCount(size_t &sendCount, size_t &recvCount) { RS_STACK_MUTEX(mDiscMtx); - //sendCount = mPendingDiscPgpCertOutList.size(); - recvCount = mPendingDiscPgpCertInList.size(); + sendCount = 0;//mPendingDiscPgpCertOutList.size(); + recvCount = 0;//mPendingDiscPgpCertInList.size(); return true; } -bool p3discovery2::sendInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMsg ) -{ - RsPeers& mPeers = *rsPeers; - - std::string&& invite = mPeers.GetRetroshareInvite(inviteId); - - if(invite.empty()) - { - errorMsg = "Failure generating invite for peer: " + - inviteId.toStdString() + " are you sure is a friend?"; - RsErr() << __PRETTY_FUNCTION__ << " " << errorMsg << std::endl; - return false; - } - - RsGossipDiscoveryInviteItem* item = new RsGossipDiscoveryInviteItem; - item->PeerId(toSslId); - item->mInvite = mPeers.GetRetroshareInvite(inviteId, true, true); - - return sendItem(item); -} - -bool p3discovery2::requestInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& /*errorMsg*/ ) -{ - Dbg2() << __PRETTY_FUNCTION__ << " inviteId: " << inviteId - << " toSslId: " << toSslId << std::endl; - - RsGossipDiscoveryInviteRequestItem* item = - new RsGossipDiscoveryInviteRequestItem; - item->PeerId(toSslId); - item->mInviteId = inviteId; - - return sendItem(item); -} - -bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list &proxyPgpIds) +bool p3discovery2::getDiscPgpFriends(const RsPgpId &pgp_id, std::list &proxyPgpIds) { /* find id -> and extract the neighbour_of ids */ @@ -1278,7 +1212,7 @@ bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list &prox RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it; + std::map::const_iterator it; it = mFriendList.find(pgp_id); if (it == mFriendList.end()) { @@ -1286,7 +1220,7 @@ bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list &prox return false; } - std::set::const_iterator fit; + std::set::const_iterator fit; for(fit = it->second.mFriendSet.begin(); fit != it->second.mFriendSet.end(); ++fit) { proxyPgpIds.push_back(*fit); @@ -1294,11 +1228,11 @@ bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list &prox return true; } -bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version) +bool p3discovery2::getPeerVersion(const RsPeerId &peerId, std::string &version) { RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it; + std::map::const_iterator it; it = mLocationMap.find(peerId); if (it == mLocationMap.end()) { @@ -1310,11 +1244,11 @@ bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version) return true; } -bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &version) +bool p3discovery2::setPeerVersion(const RsPeerId &peerId, const std::string &version) { RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator it; + std::map::iterator it; it = mLocationMap.find(peerId); if (it == mLocationMap.end()) { @@ -1326,112 +1260,74 @@ bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &versio return true; } -void p3discovery2::recvInvite( - std::unique_ptr inviteItem ) -{ - typedef RsGossipDiscoveryFriendInviteReceivedEvent Evt_t; - if(rsEvents) - rsEvents->postEvent( - std::shared_ptr(new Evt_t(inviteItem->mInvite)) ); -} - void p3discovery2::rsEventsHandler(const RsEvent& event) { - Dbg3() << __PRETTY_FUNCTION__ << " " << static_cast(event.mType) - << std::endl; - - switch(event.mType) - { -// case RsEventType::PEER_STATE_CHANGED: -// { -// const RsPeerId& sslId = static_cast(event).mSslId; -// -// if( rsPeers && rsPeers->isSslOnlyFriend(sslId) && mServiceCtrl->isPeerConnected( getServiceInfo().mServiceType, sslId ) ) -// { -// if(!requestPGPCertificate(sslId, sslId)) -// RsErr() << __PRETTY_FUNCTION__ << " requestInvite to peer " -// << sslId << " failed" << std::endl; -// } -// break; -// } - default: break; - } + Dbg3() << __PRETTY_FUNCTION__ << " " << static_cast(event.mType) << std::endl; } /*************************************************************************************/ /* AuthGPGService */ /*************************************************************************************/ -AuthGPGOperation *p3discovery2::getGPGOperation() -{ - { - RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ - - /* process disc reply in list */ - if (!mPendingDiscPgpCertInList.empty()) { - RsDiscPgpCertItem *item = mPendingDiscPgpCertInList.front(); - mPendingDiscPgpCertInList.pop_front(); - - return new AuthGPGOperationLoadOrSave(true, item->pgpId, item->pgpCert, item); - } - } - -// { -// RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ +// AuthGPGOperation *p3discovery2::getGPGOperation() +// { +// { +// RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ // -// /* process disc reply in list */ -// if (!mPendingDiscPgpCertOutList.empty()) { -// RsDiscPgpCertItem *item = mPendingDiscPgpCertOutList.front(); -// mPendingDiscPgpCertOutList.pop_front(); +// /* process disc reply in list */ +// if (!mPendingDiscPgpCertInList.empty()) { +// RsDiscPgpCertItem *item = mPendingDiscPgpCertInList.front(); +// mPendingDiscPgpCertInList.pop_front(); // -// return new AuthGPGOperationLoadOrSave(false, item->pgpId, "", item); -// } -// } - return NULL; -} +// return new AuthGPGOperationLoadOrSave(true, item->pgpId, item->pgpCert, item); +// } +// } +// +// return NULL; +// } -void p3discovery2::setGPGOperation(AuthGPGOperation *operation) -{ - AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast(operation); - if (loadOrSave) - { - RsDiscPgpCertItem *item = (RsDiscPgpCertItem *) loadOrSave->m_userdata; - if (!item) - { - return; - } +// void p3discovery2::setGPGOperation(AuthGPGOperation *operation) +// { +// AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast(operation); +// if (loadOrSave) +// { +// RsDiscPgpCertItem *item = (RsDiscPgpCertItem *) loadOrSave->m_userdata; +// if (!item) +// { +// return; +// } +// +// if (loadOrSave->m_load) +// { +// +// #ifdef P3DISC_DEBUG +// std::cerr << "p3discovery2::setGPGOperation() Loaded Cert" << std::endl; +// item->print(std::cerr, 5); +// std::cerr << std::endl; +// #endif +// // It has already been processed by PGP. +// delete item; +// } +// else +// { +// // Attaching Certificate. +// item->pgpCert = loadOrSave->m_certGpg; +// +// #ifdef P3DISC_DEBUG +// std::cerr << "p3discovery2::setGPGOperation() Sending Message:" << std::endl; +// item->print(std::cerr, 5); +// #endif +// +// // Send off message +// sendItem(item); +// } +// return; +// } +// +// /* ignore other operations */ +// } - if (loadOrSave->m_load) - { - -#ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::setGPGOperation() Loaded Cert" << std::endl; - item->print(std::cerr, 5); - std::cerr << std::endl; -#endif - // It has already been processed by PGP. - delete item; - } - else - { - // Attaching Certificate. - item->pgpCert = loadOrSave->m_certGpg; - -#ifdef P3DISC_DEBUG - std::cerr << "p3discovery2::setGPGOperation() Sending Message:" << std::endl; - item->print(std::cerr, 5); -#endif - - // Send off message - sendItem(item); - } - return; - } - - /* ignore other operations */ -} - -RsGossipDiscoveryFriendInviteReceivedEvent:: -RsGossipDiscoveryFriendInviteReceivedEvent(const std::string& invite) : +// (cyril) do we still need this?? +RsGossipDiscoveryFriendInviteReceivedEvent::RsGossipDiscoveryFriendInviteReceivedEvent(const std::string& invite) : RsEvent(RsEventType::GOSSIP_DISCOVERY_INVITE_RECEIVED), mInvite(invite) {} diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h index eaf148bb5..d7e0270f6 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h @@ -36,9 +36,6 @@ class p3ServiceControl; -using PGPID RS_DEPRECATED_FOR(RsPgpId) = RsPgpId; -using SSLID RS_DEPRECATED_FOR(RsPeerId) = RsPeerId; - struct DiscSslInfo { DiscSslInfo() : mDiscStatus(0) {} @@ -56,16 +53,16 @@ struct DiscPgpInfo { DiscPgpInfo() {} - void mergeFriendList(const std::set &friends); + void mergeFriendList(const std::set &friends); - std::set mFriendSet; - std::map mSslIds; + std::set mFriendSet; + std::map mSslIds; }; class p3discovery2 : - public RsGossipDiscovery, public p3Service, public pqiServiceMonitor, - public AuthGPGService + public RsGossipDiscovery, public p3Service, public pqiServiceMonitor + //public AuthGPGService { public: @@ -87,57 +84,41 @@ virtual RsServiceInfo getServiceInfo(); bool getPeerVersion(const RsPeerId &id, std::string &version); bool getWaitingDiscCount(size_t &sendCount, size_t &recvCount); - /// @see RsGossipDiscovery - bool sendInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMsg = RS_DEFAULT_STORAGE_PARAM(std::string) - ) override; - - /// @see RsGossipDiscovery - bool requestInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMsg = RS_DEFAULT_STORAGE_PARAM(std::string) - ) override; - - /************* from AuthGPService ****************/ -virtual AuthGPGOperation *getGPGOperation(); -virtual void setGPGOperation(AuthGPGOperation *operation); + /************* from AuthGPService ****************/ + // virtual AuthGPGOperation *getGPGOperation(); + // virtual void setGPGOperation(AuthGPGOperation *operation); private: - PGPID getPGPId(const SSLID &id); + RsPgpId getPGPId(const RsPeerId &id); int handleIncoming(); void updatePgpFriendList(); - void addFriend(const SSLID &sslId); - void removeFriend(const SSLID &sslId); + void addFriend(const RsPeerId &sslId); + void removeFriend(const RsPeerId &sslId); void updatePeerAddresses(const RsDiscContactItem *item); void updatePeerAddressList(const RsDiscContactItem *item); - void sendOwnContactInfo(const SSLID &sslid); - void recvOwnContactInfo(const SSLID &fromId, const RsDiscContactItem *item); + void sendOwnContactInfo(const RsPeerId &sslid); + void recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContactItem *item); - void sendPGPList(const SSLID &toId); - void processPGPList(const SSLID &fromId, const RsDiscPgpListItem *item); + void sendPGPList(const RsPeerId &toId); + void processPGPList(const RsPeerId &fromId, const RsDiscPgpListItem *item); - void processContactInfo(const SSLID &fromId, const RsDiscContactItem *info); + void processContactInfo(const RsPeerId &fromId, const RsDiscContactItem *info); - void requestPGPCertificate(const PGPID &aboutId, const SSLID &toId); - - void recvPGPCertificateRequest( - const RsPeerId& fromId, const RsDiscPgpListItem* item ); + // send/recv information + void requestPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId); + void recvPGPCertificateRequest(const RsPeerId& fromId, const RsDiscPgpListItem* item ); void sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &toId); - void recvPGPCertificate(const SSLID &fromId, RsDiscPgpCertItem *item); // deprecated - void recvPGPCertificate(const SSLID &fromId, RsDiscPgpKeyItem *item); + void recvPGPCertificate(const RsPeerId &fromId, RsDiscPgpKeyItem *item); void recvIdentityList(const RsPeerId& pid,const std::list& ids); - bool setPeerVersion(const SSLID &peerId, const std::string &version); - - void recvInvite(std::unique_ptr inviteItem); + bool setPeerVersion(const RsPeerId &peerId, const std::string &version); void rsEventsHandler(const RsEvent& event); RsEventsHandlerId_t mRsEventsHandle; @@ -152,16 +133,18 @@ private: /* data */ RsMutex mDiscMtx; - void updatePeers_locked(const SSLID &aboutId); - void sendContactInfo_locked(const PGPID &aboutId, const SSLID &toId); + void updatePeers_locked(const RsPeerId &aboutId); + void sendContactInfo_locked(const RsPgpId &aboutId, const RsPeerId &toId); rstime_t mLastPgpUpdate; - std::map mFriendList; - std::map mLocationMap; + std::map mFriendList; + std::map mLocationMap; - std::list mPendingDiscPgpCertInList; - //std::list mPendingDiscPgpCertOutList; +// This was used to async the receiving of PGP keys, mainly because PGPHandler cross-checks all signatures, so receiving these keys in large loads can be costly +// Because discovery is not running in the main thread, there's no reason to re-async this into another process (e.g. AuthGPG) +// +// std::list mPendingDiscPgpCertInList; protected: RS_SET_CONTEXT_DEBUG_LEVEL(1) diff --git a/libretroshare/src/retroshare/rsgossipdiscovery.h b/libretroshare/src/retroshare/rsgossipdiscovery.h index cf748549c..89839995a 100644 --- a/libretroshare/src/retroshare/rsgossipdiscovery.h +++ b/libretroshare/src/retroshare/rsgossipdiscovery.h @@ -64,6 +64,8 @@ struct RsGossipDiscoveryFriendInviteReceivedEvent : RsEvent class RsGossipDiscovery { public: + virtual ~RsGossipDiscovery() {} + /** * @brief getDiscFriends get a list of all friends of a given friend * @jsonapi{development} @@ -101,34 +103,4 @@ public: * @return true on success false otherwise */ virtual bool getWaitingDiscCount(size_t& sendCount, size_t& recvCount) = 0; - - /** - * @brief Send RetroShare invite to given peer - * @jsonapi{development} - * @param[in] inviteId id of peer of which send the invite - * @param[in] toSslId ssl id of the destination peer - * @param[out] errorMessage Optional storage for the error message, - * meaningful only on failure. - * @return true on success false otherwise - */ - virtual bool sendInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) - ) = 0; - - /** - * @brief Request RetroShare certificate to given peer - * @jsonapi{development} - * @param[in] inviteId id of the peer of which request the invite - * @param[in] toSslId id of the destination of the request - * @param[out] errorMessage Optional storage for the error message, - * meaningful only on failure. - * @return true on success false otherwise - */ - virtual bool requestInvite( - const RsPeerId& inviteId, const RsPeerId& toSslId, - std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) - ) = 0; - - virtual ~RsGossipDiscovery(); }; diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index d2b60b992..7b571e48c 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1792,7 +1792,7 @@ int RsServer::StartupRetroShare() /* Add AuthGPG services */ /**************************************************************************/ - AuthGPG::getAuthGPG()->addService(mDisc); + //AuthGPG::getAuthGPG()->addService(mDisc); /**************************************************************************/ /* Force Any Last Configuration Options */ From b4fe1d48e5001988f0ee216ceb766838fcc577e8 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 16 Sep 2019 23:00:00 +0200 Subject: [PATCH 32/45] started documenting p3GossipDiscovery --- .../src/gossipdiscovery/p3gossipdiscovery.cc | 29 +++++++--- .../src/gossipdiscovery/p3gossipdiscovery.h | 54 ++++++++++++++++++- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index d0b3e54be..4ee9604f8 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -312,9 +312,13 @@ void p3discovery2::sendOwnContactInfo(const RsPeerId &sslid) if (mPeerMgr->getOwnNetStatus(detail)) { RsDiscContactItem *pkt = new RsDiscContactItem(); + /* Cyril: we dont send our own IP to an hidden node. It will not use it - * anyway. */ + * anyway. Furthermore, a Tor node is not supposed to have any mean to send the IPs of his friend nodes + * to other nodes. This would be a very serious security risk. */ + populateContactInfo(detail, pkt, !rsPeers->isHiddenNode(sslid)); + /* G10h4ck: sending IP information also to hidden nodes has proven very * helpful in the usecase of non hidden nodes, that share a common * hidden trusted node, to discover each other IP. @@ -323,7 +327,6 @@ void p3discovery2::sendOwnContactInfo(const RsPeerId &sslid) * permission matrix. Disabling this instead will make life more * difficult for average user, that moreover whould have no way to * revert an hardcoded policy. */ - //populateContactInfo(detail, pkt, true); pkt->version = RS_HUMAN_READABLE_VERSION; pkt->PeerId(sslid); @@ -406,8 +409,13 @@ void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContac // It is important that PGPList is received after the OwnContactItem. // This should happen, but is not enforced by the protocol. - // start peer list exchange. - sendPGPList(fromId); + // Start peer list exchange, if discovery is enabled + + peerState ps; + mPeerMgr->getOwnNetStatus(ps); + + if(ps.vs_disc != RS_VS_DISC_OFF) + sendPGPList(fromId); // Update mDiscStatus. RS_STACK_MUTEX(mDiscMtx); @@ -520,10 +528,17 @@ void p3discovery2::sendPGPList(const RsPeerId &toId) pkt->mode = RsGossipDiscoveryPgpListMode::FRIENDS; - std::map::const_iterator it; - for(it = mFriendList.begin(); it != mFriendList.end(); ++it) + for(auto it = mFriendList.begin(); it != mFriendList.end(); ++it) { - pkt->pgpIdSet.ids.insert(it->first); + // Check every friend, and only send his PGP key if the friend tells that he wants discovery. Because this info is done on the level of locations, + // we check each location and only send the key if at least one location allows it. + + for(auto it2(it->second.mSslIds.begin());it2!=it->second.mSslIds.end();++it2) + if(it2->second.mDiscStatus != RS_VS_DISC_OFF) + { + pkt->pgpIdSet.ids.insert(it->first); + break; + } } pkt->PeerId(toId); diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h index d7e0270f6..7975df289 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h @@ -22,6 +22,57 @@ *******************************************************************************/ #pragma once +// +// p3GossipDiscovery is reponsible for facilitating the circulation of public keys between friend nodes. +// +// The service locally holds a cache that stores: +// * the list of friend profiles, in each of which the list of locations with their own discovery flag (which means whether they allow discovery or not) +// * the list of friend nodes, with their version number +// +// Data flow +// ========= +// +// statusChange(std::list&) // called by pqiMonitor when peers are added,removed, or recently connected +// | +// +---- sendOwnContactInfo(RsPeerId) // [On connection] sends own PgpId, discovery flag, list of own signed GxsIds +// | | +// | +---->[to friend] +// | +// +---- addFriend() / removeFriend() // [New/Removed friend] updates the list of friends, along with their own discovery flag +// +// tick() +// | +// +------ handleIncoming() +// | +// +-- recvOwnContactInfo(RsPeerId) // update location, IP addresses of a peer. +// | | +// | +------(if the peer has short_invite flag) +// | | | +// | | +---------requestPGPKey()->[to friend] // requests the full PGP public key, so as to be +// | | // able to validate connections. +// | | +// | +------(if disc != RS_VS_DISC_OFF) +// | | +// | +---------sendPgpList()->[to friend] // sends own list of friend profiles for which at least one location +// | // accepts discovery +// +-- processContactInfo(item->PeerId(), contact); +// | +// +-- recvIdentityList(Gxs Identity List) +// | +// +-- recvPGPCertificate(item->PeerId(), pgpkey); +// | +// +-- processPGPList(pgplist->PeerId(), pgplist); +// | +// +-- recvPGPCertificateRequest(pgplist->PeerId(), pgplist); +// +// Notes: +// * Tor nodes never send their own IP, and normal nodes never send their IP to Tor nodes either. +// A Tor node may accidentally know the IP of a normal node when it adds its certificate. However, the IP is dropped and not saved in this case. +// Generally speaking, no IP information should leave or transit through a Tor node. +// +// * the decision to call recvOwnContactInfo() or processContactInfo() depends on whether the item's peer id is the one the info is about. This is +// a bit unsafe. We should probably have to different items here especially if the information is not exactly the same. +// #include #include "retroshare/rsgossipdiscovery.h" @@ -38,7 +89,7 @@ class p3ServiceControl; struct DiscSslInfo { - DiscSslInfo() : mDiscStatus(0) {} + DiscSslInfo() : mDiscStatus(RS_VS_DISC_OFF) {} // default is to not allow discovery, until the peer tells about it uint16_t mDiscStatus; }; @@ -123,7 +174,6 @@ private: void rsEventsHandler(const RsEvent& event); RsEventsHandlerId_t mRsEventsHandle; - p3PeerMgr *mPeerMgr; p3LinkMgr *mLinkMgr; p3NetMgr *mNetMgr; From 32b431272504ff5d98a5d82dc168542be0cb9def Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 17 Sep 2019 22:14:32 +0200 Subject: [PATCH 33/45] improved security checks in authssl by verifying that the supplied PGP id is the one the peer has been registered with --- libretroshare/src/pqi/authssl.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 6776ac2c1..f07bbef47 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1198,6 +1198,20 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) std::string sslCn = RsX509Cert::getCertIssuerString(*x509Cert); RsPgpId pgpId(sslCn); + RsPeerDetails det; + if(!rsPeers->getPeerDetails(sslId,det)) + { + std::cerr << "Nothing known about peer " << sslId << " trying to connect! Refusing connection." << std::endl; + return verificationFailed; + } + + bool isSslOnlyFriend = det.skip_signature_validation; + + if(det.gpg_id != pgpId) + { + std::cerr << "(EE) peer " << sslId << " trying to connect with issuer ID " << pgpId << " whereas key ID " << det.gpg_id << " was expected! Refusing connection." << std::endl; + return verificationFailed; + } if(sslId.isNull()) { @@ -1234,8 +1248,6 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } - bool isSslOnlyFriend = rsPeers->isSslOnlyFriend(sslId); - uint32_t auth_diagnostic; if(!isSslOnlyFriend && !AuthX509WithGPG(x509Cert, auth_diagnostic)) { @@ -1260,8 +1272,9 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } - if ( !isSslOnlyFriend && pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && - !AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) ) + if(isSslOnlyFriend && pgpId != + + if ( !isSslOnlyFriend && pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) ) { std::string errMsg = "Connection attempt signed by PGP key id: " + pgpId.toStdString() + " not accepted because it is not" From 44d6cb7be2d6d2e38659edd970c81174dea0f62d Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 17 Sep 2019 22:43:37 +0200 Subject: [PATCH 34/45] finished documentation/review of discovery --- .../src/gossipdiscovery/p3gossipdiscovery.cc | 117 ++++++++++-------- .../src/gossipdiscovery/p3gossipdiscovery.h | 25 +++- 2 files changed, 86 insertions(+), 56 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index 4ee9604f8..588d593ad 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -530,8 +530,8 @@ void p3discovery2::sendPGPList(const RsPeerId &toId) for(auto it = mFriendList.begin(); it != mFriendList.end(); ++it) { - // Check every friend, and only send his PGP key if the friend tells that he wants discovery. Because this info is done on the level of locations, - // we check each location and only send the key if at least one location allows it. + // Check every friend, and only send his PGP key if the friend tells that he wants discovery. Because this action over profiles depends on a node information, + // we check each node of a given progile and only send the profile key if at least one node allows it. for(auto it2(it->second.mSslIds.begin());it2!=it->second.mSslIds.end();++it2) if(it2->second.mDiscStatus != RS_VS_DISC_OFF) @@ -667,9 +667,8 @@ void p3discovery2::processPGPList(const RsPeerId &fromId, const RsDiscPgpListIte std::cerr << std::endl; #endif - std::map::iterator it; RsPgpId fromPgpId = getPGPId(fromId); - it = mFriendList.find(fromPgpId); + auto it = mFriendList.find(fromPgpId); if (it == mFriendList.end()) { #ifdef P3DISC_DEBUG @@ -686,9 +685,7 @@ void p3discovery2::processPGPList(const RsPeerId &fromId, const RsDiscPgpListIte peerState pstate; mPeerMgr->getOwnNetStatus(pstate); if (pstate.vs_disc != RS_VS_DISC_FULL) - { requestUnknownPgpCerts = false; - } uint32_t linkType = mLinkMgr->getLinkType(fromId); if ((linkType & RS_NET_CONN_SPEED_TRICKLE) || @@ -738,8 +735,7 @@ void p3discovery2::updatePeers_locked(const RsPeerId &aboutId) RsPgpId aboutPgpId = getPGPId(aboutId); - std::map::const_iterator ait; - ait = mFriendList.find(aboutPgpId); + auto ait = mFriendList.find(aboutPgpId); if (ait == mFriendList.end()) { @@ -755,8 +751,8 @@ void p3discovery2::updatePeers_locked(const RsPeerId &aboutId) std::set::const_iterator sit; const std::set &friendSet = ait->second.mFriendSet; - std::set::const_iterator fit; - for(fit = friendSet.begin(); fit != friendSet.end(); ++fit) + + for(auto fit = friendSet.begin(); fit != friendSet.end(); ++fit) { #ifdef P3DISC_DEBUG @@ -764,8 +760,8 @@ void p3discovery2::updatePeers_locked(const RsPeerId &aboutId) std::cerr << std::endl; #endif - std::map::const_iterator ffit; - ffit = mFriendList.find(*fit); + auto ffit = mFriendList.find(*fit); + if (ffit == mFriendList.end()) { @@ -786,9 +782,7 @@ void p3discovery2::updatePeers_locked(const RsPeerId &aboutId) #endif mutualFriends.insert(*fit); - std::map::const_iterator mit; - for(mit = ffit->second.mSslIds.begin(); - mit != ffit->second.mSslIds.end(); ++mit) + for(auto mit = ffit->second.mSslIds.begin(); mit != ffit->second.mSslIds.end(); ++mit) { RsPeerId sslid = mit->first; if (mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, sslid)) @@ -913,19 +907,21 @@ void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContac RS_STACK_MUTEX(mDiscMtx); + // This case is the node fromId sending information about ourselves to us. There's one good use of this: + // read the IP information the friend knows about us, and use it to extimate our external address. + if (item->sslId == rsPeers->getOwnId()) { if(sockaddr_storage_isExternalNet(item->currentConnectAddress.addr)) - mPeerMgr->addCandidateForOwnExternalAddress( - item->PeerId(), item->currentConnectAddress.addr); + mPeerMgr->addCandidateForOwnExternalAddress(item->PeerId(), item->currentConnectAddress.addr); delete item; return; } - std::map::iterator it; - it = mFriendList.find(item->pgpId); - if (it == mFriendList.end()) + auto it = mFriendList.find(item->pgpId); // is this the PGP id one of our friends? + + if (it == mFriendList.end()) // no it's not. { #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::processContactInfo(" << fromId << ") RsPgpId: "; @@ -946,53 +942,54 @@ void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContac mNetMgr->netAssistFriend(item->sslId,false); /* inform NetMgr that we know this peer */ - mNetMgr->netAssistKnownPeer(item->sslId, item->extAddrV4.addr, - NETASSIST_KNOWN_PEER_FOF | NETASSIST_KNOWN_PEER_OFFLINE); + mNetMgr->netAssistKnownPeer(item->sslId, item->extAddrV4.addr, NETASSIST_KNOWN_PEER_FOF | NETASSIST_KNOWN_PEER_OFFLINE); } delete item; return; } - bool should_notify_discovery = false; - std::map::iterator sit; - sit = it->second.mSslIds.find(item->sslId); - if (sit == it->second.mSslIds.end()) - { - /* insert! */ - DiscSslInfo sslInfo; - it->second.mSslIds[item->sslId] = sslInfo; - //sit = it->second.mSslIds.find(item->sslId); + // The peer the discovery info is about is a friend. We gather the nodes for that profile into the local structure and notify p3peerMgr. + if(!rsPeers->isGPGAccepted(item->pgpId)) // this is an additional check, because the friendship previously depends on the local cache. We need + return ; // fresh information here. + + bool should_notify_discovery = false; + auto sit= it->second.mSslIds.find(item->sslId); + + DiscSslInfo sslInfo& (it->second.mSslIds[item->sslId]); // This line inserts the entry while not removing already existing data + + if (!mPeerMgr->isFriend(item->sslId)) + { should_notify_discovery = true; - if (!mPeerMgr->isFriend(item->sslId)) - { - // Add with no disc by default. If friend already exists, it will do nothing - // NO DISC is important - otherwise, we'll just enter a nasty loop, - // where every addition triggers requests, then they are cleaned up, and readded... + // Add with no disc by default. If friend already exists, it will do nothing + // NO DISC is important - otherwise, we'll just enter a nasty loop, + // where every addition triggers requests, then they are cleaned up, and readded... - // This way we get their addresses, but don't advertise them until we get a - // connection. + // This way we get their addresses, but don't advertise them until we get a + // connection. #ifdef P3DISC_DEBUG - std::cerr << "--> Adding to friends list " << item->sslId << " - " << item->pgpId << std::endl; + std::cerr << "--> Adding to friends list " << item->sslId << " - " << item->pgpId << std::endl; #endif - // We pass RS_NODE_PERM_ALL because the PGP id is already a friend, so we should keep the existing - // permission flags. Therefore the mask needs to be 0xffff. + // We pass RS_NODE_PERM_ALL because the PGP id is already a friend, so we should keep the existing + // permission flags. Therefore the mask needs to be 0xffff. - // set last seen to RS_PEER_OFFLINE_NO_DISC minus 1 so that it won't be shared with other friends - // until a first connection is established + // set last seen to RS_PEER_OFFLINE_NO_DISC minus 1 so that it won't be shared with other friends + // until a first connection is established - mPeerMgr->addFriend( item->sslId, item->pgpId, item->netMode, - RS_VS_DISC_OFF, RS_VS_DHT_FULL, - time(NULL) - RS_PEER_OFFLINE_NO_DISC - 1, - RS_NODE_PERM_ALL ); - updatePeerAddresses(item); - } + // This code is a bit dangerous: we add a friend without the insurance that the PGP key that will validate this friend actually has + // the supplied PGP id. Of course, because it comes from a friend, we should trust that friend. Anyway, it is important that + // when connecting the handshake is always doen w.r.t. the known PGP key, and not the one that is indicated in the certificate issuer field. + + mPeerMgr->addFriend( item->sslId, item->pgpId, item->netMode, + RS_VS_DISC_OFF, RS_VS_DHT_FULL, + time(NULL) - RS_PEER_OFFLINE_NO_DISC - 1, + RS_NODE_PERM_ALL ); + + updatePeerAddresses(item); } - updatePeerAddressList(item); - RsServer::notify()->notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD); if(should_notify_discovery) @@ -1025,17 +1022,29 @@ void p3discovery2::requestPGPCertificate(const RsPgpId &aboutId, const RsPeerId sendItem(pkt); } -void p3discovery2::recvPGPCertificateRequest( - const RsPeerId& fromId, const RsDiscPgpListItem* item ) +void p3discovery2::recvPGPCertificateRequest( const RsPeerId& fromId, const RsDiscPgpListItem* item ) { #ifdef P3DISC_DEBUG std::cerr << __PRETTY_FUNCTION__ << " from " << fromId << std::endl; #endif + peerState ps; + mPeerMgr->getOwnNetStatus(ps); + + if(ps.vs_disc != RS_VS_DISC_OFF) + { + std::cerr << "(WW) refusing PGP certificate request from " << fromId << " because discovery is OFF" << std::endl; + return; + } RsPgpId ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId(); for(const RsPgpId& pgpId : item->pgpIdSet.ids) - if (pgpId == ownPgpId || AuthGPG::getAuthGPG()->isGPGAccepted(pgpId)) + if (pgpId == ownPgpId) sendPGPCertificate(pgpId, fromId); + else if(ps.vs_disc != RS_VS_DISC_OFF && AuthGPG::getAuthGPG()->isGPGAccepted(pgpId)) + sendPGPCertificate(pgpId, fromId); + else + std::cerr << "(WW) not sending certificate " << pgpId << " asked by friend " << fromId << " because this either this cert is not a friend, or discovery is off" << std::endl; + delete item; } diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h index 7975df289..95773df69 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.h @@ -38,7 +38,7 @@ // | | // | +---->[to friend] // | -// +---- addFriend() / removeFriend() // [New/Removed friend] updates the list of friends, along with their own discovery flag +// +---- locally add/remove cache info // [New/Removed friend] updates the list of friends, along with their own discovery flag // // tick() // | @@ -56,14 +56,35 @@ // | +---------sendPgpList()->[to friend] // sends own list of friend profiles for which at least one location // | // accepts discovery // +-- processContactInfo(item->PeerId(), contact); +// | | +// | +------ addFriend() // called on nodes signed by the PGP key mentionned in the disc info +// | | +// | +------ update local discovery info // | // +-- recvIdentityList(Gxs Identity List) +// | | +// | +------ mGixs->requestKey(*it,peers,use_info) ; // requestKey() takes care of requesting the GxsIds that are missing // | // +-- recvPGPCertificate(item->PeerId(), pgpkey); +// | | +// | +------(if peer has short invite flag) +// | | +// | +--------- add key to keyring, accept connections and notify peerMgr // | -// +-- processPGPList(pgplist->PeerId(), pgplist); +// +-- processPGPList(pgplist->PeerId(), pgplist); // list of PGP keys of a friend, received from himself +// | | +// | +------ requestPgpCertificate() // request missing keys only +// | | +// | +------ updatePeers_locked(fromId) +// | | +// | +--------- sendContactInfo_locked(from,to) // sends IP information about mutual friends to the origin of the info +// | | +// | +--------- sendContactInfo_locked(to,from) // sends IP information origin to online mutual friends // | // +-- recvPGPCertificateRequest(pgplist->PeerId(), pgplist); +// | +// +------ sendPGPCertificate() // only sends the ones we are friend with, and only send own cert +// // if discovery is off // // Notes: // * Tor nodes never send their own IP, and normal nodes never send their IP to Tor nodes either. From 654d760d8426e67f4bad5558224b2dc1c2a56248 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 19 Sep 2019 20:59:35 +0200 Subject: [PATCH 35/45] fixed comments from review of PR --- .../gossipdiscovery/gossipdiscoveryitems.cc | 10 +++++--- .../gossipdiscovery/gossipdiscoveryitems.h | 7 +++--- .../src/gossipdiscovery/p3gossipdiscovery.cc | 23 ++++++++----------- libretroshare/src/pqi/authssl.cc | 2 -- .../src/retroshare/rsgossipdiscovery.h | 2 +- libretroshare/src/rsserver/p3peers.cc | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc index 3d56e3bc9..bee4c9b59 100644 --- a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc +++ b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.cc @@ -40,7 +40,7 @@ RsItem *RsDiscSerialiser::create_item( case RsGossipDiscoveryItemType::CONTACT: return new RsDiscContactItem(); case RsGossipDiscoveryItemType::IDENTITY_LIST: return new RsDiscIdentityListItem(); default: - return NULL; + return nullptr; } return nullptr; @@ -65,13 +65,17 @@ void RsDiscPgpListItem::serial_process( void RsDiscPgpKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,pgpKeyId,"pgpKeyId") ; - RsTypeSerializer::serial_process(j,ctx,pgpKeyData,"pgpKeyData") ; + + RsTypeSerializer::TlvMemBlock_proxy prox(bin_data,bin_len) ; + RsTypeSerializer::serial_process(j,ctx,prox,"keyData") ; } void RsDiscPgpKeyItem::clear() { pgpKeyId.clear(); - pgpKeyData.TlvClear(); + free(bin_data); + bin_data = nullptr; + bin_len=0; } void RsDiscContactItem::clear() diff --git a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h index 5e147d2ba..f5e219b95 100644 --- a/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h +++ b/libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h @@ -38,8 +38,6 @@ enum class RsGossipDiscoveryItemType : uint8_t PGP_CERT = 0x2, // deprecated CONTACT = 0x5, IDENTITY_LIST = 0x6, - INVITE = 0x7, // deprecated - INVITE_REQUEST = 0x8, // deprecated PGP_CERT_BINARY = 0x9, }; @@ -89,11 +87,14 @@ public: RsDiscPgpKeyItem() : RsDiscItem(RsGossipDiscoveryItemType::PGP_CERT_BINARY) { setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_CERT); } + virtual ~RsDiscPgpKeyItem() { delete[](bin_data);bin_data=nullptr;bin_len=0;} + void clear() override; void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx) override; RsPgpId pgpKeyId; // duplicate information for practical reasons - RsTlvBinaryData pgpKeyData; + unsigned char *bin_data; // binry key data allocated with new unsigned char[] + uint32_t bin_len; }; class RsDiscContactItem: public RsDiscItem diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index 588d593ad..2001667f1 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -374,12 +374,12 @@ void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContac RsPeerDetails det ; if(!rsPeers->getPeerDetails(fromId,det)) { - std::cerr << "(EE) Cannot obtain details from " << fromId << " who is supposed to be a friend! Dropping the info." << std::endl; + RsErr() << "(EE) Cannot obtain details from " << fromId << " who is supposed to be a friend! Dropping the info." << std::endl; return; } if(det.gpg_id != item->pgpId) { - std::cerr << "(EE) peer " << fromId << " sent own details with PGP key ID " << item->pgpId << " which does not match the known key id " << det.gpg_id << ". Dropping the info." << std::endl; + RsErr() << "(EE) peer " << fromId << " sent own details with PGP key ID " << item->pgpId << " which does not match the known key id " << det.gpg_id << ". Dropping the info." << std::endl; return; } @@ -748,7 +748,6 @@ void p3discovery2::updatePeers_locked(const RsPeerId &aboutId) std::set mutualFriends; std::set onlineFriends; - std::set::const_iterator sit; const std::set &friendSet = ait->second.mFriendSet; @@ -803,17 +802,15 @@ void p3discovery2::updatePeers_locked(const RsPeerId &aboutId) std::cerr << std::endl; #endif // update aboutId about Other Peers. - for(fit = mutualFriends.begin(); fit != mutualFriends.end(); ++fit) - { + for(auto fit = mutualFriends.begin(); fit != mutualFriends.end(); ++fit) sendContactInfo_locked(*fit, aboutId); - } #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::updatePeer_locked() Updating Online Peers about " << aboutId; std::cerr << std::endl; #endif // update Other Peers about aboutPgpId. - for(sit = onlineFriends.begin(); sit != onlineFriends.end(); ++sit) + for(auto sit = onlineFriends.begin(); sit != onlineFriends.end(); ++sit) { // This could be more efficient, and only be specific about aboutId. // but we'll leave it like this for the moment. @@ -951,12 +948,12 @@ void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContac // The peer the discovery info is about is a friend. We gather the nodes for that profile into the local structure and notify p3peerMgr. if(!rsPeers->isGPGAccepted(item->pgpId)) // this is an additional check, because the friendship previously depends on the local cache. We need - return ; // fresh information here. + return ; // fresh information here. bool should_notify_discovery = false; auto sit= it->second.mSslIds.find(item->sslId); - DiscSslInfo sslInfo& (it->second.mSslIds[item->sslId]); // This line inserts the entry while not removing already existing data + DiscSslInfo& sslInfo(it->second.mSslIds[item->sslId]); // This line inserts the entry while not removing already existing data if (!mPeerMgr->isFriend(item->sslId)) { @@ -1064,8 +1061,8 @@ void p3discovery2::sendPGPCertificate(const RsPgpId &aboutId, const RsPeerId &to return ; } - pgp_key_item->pgpKeyData.bin_data = bin_data; - pgp_key_item->pgpKeyData.bin_len = bin_len; + pgp_key_item->bin_data = bin_data; + pgp_key_item->bin_len = bin_len; sendItem(pgp_key_item); } @@ -1078,7 +1075,7 @@ void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem* std::string cert_name; std::list cert_signers; - if(!AuthGPG::getAuthGPG()->getGPGDetailsFromBinaryBlock( (unsigned char*)item->pgpKeyData.bin_data,item->pgpKeyData.bin_len, cert_pgp_id, cert_name, cert_signers )) + if(!AuthGPG::getAuthGPG()->getGPGDetailsFromBinaryBlock( (unsigned char*)item->bin_data,item->bin_len, cert_pgp_id, cert_name, cert_signers )) { std::cerr << "(EE) cannot parse own PGP key sent by " << fromId << std::endl; return; @@ -1121,7 +1118,7 @@ void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem* std::cerr << __PRETTY_FUNCTION__ << "Received PGP key " << cert_pgp_id << " from from friend " << fromId << ". Adding to keyring." << std::endl; #endif // now that will add the key *and* set the skip_signature_validation flag at once - rsPeers->loadPgpKeyFromBinaryData((unsigned char*)item->pgpKeyData.bin_data,item->pgpKeyData.bin_len, tmp_pgp_id,error_string); // no error should occur at this point because we called loadDetailsFromStringCert() already + rsPeers->loadPgpKeyFromBinaryData((unsigned char*)item->bin_data,item->bin_len, tmp_pgp_id,error_string); // no error should occur at this point because we called loadDetailsFromStringCert() already delete item; // Make sure we allow connections after the key is added. This is not the case otherwise. We only do that if the peer is non validated peer, since diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index f07bbef47..6700a3fde 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1272,8 +1272,6 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } - if(isSslOnlyFriend && pgpId != - if ( !isSslOnlyFriend && pgpId != AuthGPG::getAuthGPG()->getGPGOwnId() && !AuthGPG::getAuthGPG()->isGPGAccepted(pgpId) ) { std::string errMsg = "Connection attempt signed by PGP key id: " + diff --git a/libretroshare/src/retroshare/rsgossipdiscovery.h b/libretroshare/src/retroshare/rsgossipdiscovery.h index 89839995a..c9dc9924a 100644 --- a/libretroshare/src/retroshare/rsgossipdiscovery.h +++ b/libretroshare/src/retroshare/rsgossipdiscovery.h @@ -64,7 +64,7 @@ struct RsGossipDiscoveryFriendInviteReceivedEvent : RsEvent class RsGossipDiscovery { public: - virtual ~RsGossipDiscovery() {} + virtual ~RsGossipDiscovery() = default; /** * @brief getDiscFriends get a list of all friends of a given friend diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 393ae816e..4197260cd 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -582,7 +582,7 @@ bool p3Peers::isSslOnlyFriend(const RsPeerId& sslId) { if(isPgpFriend(getGPGId(sslId))) { - RsErr() << "Peer " << sslId << " has SSL-friend-only flag but his PGP id is in the list of friends. This is inconsistent (Bug in the code). Returning false for security reasons." << std::endl; + RsErr() << __PRETTY_FUNCTION__ << ": Peer " << sslId << " has SSL-friend-only flag but his PGP id is in the list of friends. This is inconsistent (Bug in the code). Returning false for security reasons." << std::endl; return false; } return true; From 4fabf3deb1654250f7b3f168970cc74d48f782da Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 19 Sep 2019 21:14:57 +0200 Subject: [PATCH 36/45] renamed skip_signature_validation into more appropriate skip_pgp_signature_validation --- libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc | 7 ++++--- libretroshare/src/pqi/authssl.cc | 2 +- libretroshare/src/retroshare/rspeers.h | 2 +- libretroshare/src/rsserver/p3peers.cc | 8 ++++---- retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index 2001667f1..223d08c7f 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -396,7 +396,7 @@ void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContac // if the peer is not validated, we stop the exchange here - if(det.skip_signature_validation) + if(det.skip_pgp_signature_validation) { #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::recvOwnContactInfo() missing PGP key " << item->pgpId << " from short invite friend " << fromId << ". Requesting it." << std::endl; @@ -954,6 +954,7 @@ void p3discovery2::processContactInfo(const RsPeerId &fromId, const RsDiscContac auto sit= it->second.mSslIds.find(item->sslId); DiscSslInfo& sslInfo(it->second.mSslIds[item->sslId]); // This line inserts the entry while not removing already existing data + // do not remove it! if (!mPeerMgr->isFriend(item->sslId)) { @@ -1098,7 +1099,7 @@ void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem* // We treat own pgp keys right away when they are sent by a friend for which we dont have it. This way we can keep the skip_pgg_signature_validation consistent - if(det.skip_signature_validation) + if(det.skip_pgp_signature_validation) { #ifdef P3DISC_DEBUG std::cerr << __PRETTY_FUNCTION__ << " Received own full certificate from short-invite friend " << fromId << std::endl; @@ -1124,7 +1125,7 @@ void p3discovery2::recvPGPCertificate(const RsPeerId& fromId, RsDiscPgpKeyItem* // Make sure we allow connections after the key is added. This is not the case otherwise. We only do that if the peer is non validated peer, since // otherwise the connection should already be accepted. This only happens when the short invite peer sends its own PGP key. - if(det.skip_signature_validation) + if(det.skip_pgp_signature_validation) AuthGPG::getAuthGPG()->AllowConnection(det.gpg_id,true); } diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 6700a3fde..300bd6110 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1205,7 +1205,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } - bool isSslOnlyFriend = det.skip_signature_validation; + bool isSslOnlyFriend = det.skip_pgp_signature_validation; if(det.gpg_id != pgpId) { diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 383430541..b4b0a64d0 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -238,7 +238,7 @@ struct RsPeerDetails : RsSerializable uint32_t trustLvl; uint32_t validLvl; - bool skip_signature_validation; + bool skip_pgp_signature_validation; bool ownsign; /* we have signed the remote peer GPG key */ bool hasSignedMe; /* the remote peer has signed my GPG key */ diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 4197260cd..6b7592629 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -295,10 +295,10 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) return false; d.gpg_id = ps.gpg_id ; - d.skip_signature_validation = true; + d.skip_pgp_signature_validation = true; } else - d.skip_signature_validation = false; + d.skip_pgp_signature_validation = false; d.isOnlyGPGdetail = false; @@ -1386,7 +1386,7 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d details.accept_connection = pgp_det.accept_connection; } else - details.skip_signature_validation = true; + details.skip_pgp_signature_validation = true; if(details.gpg_id.isNull()) { @@ -1795,7 +1795,7 @@ RsPeerDetails::RsPeerDetails() :isOnlyGPGdetail(false), name(""),email(""),location(""), org(""),authcode(""), - trustLvl(0), validLvl(0),skip_signature_validation(false),ownsign(false), + trustLvl(0), validLvl(0),skip_pgp_signature_validation(false),ownsign(false), hasSignedMe(false),accept_connection(false), state(0),actAsServer(false), connectPort(0), diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 3e4bc1ad6..f4d1ba6ed 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -702,7 +702,7 @@ void ConnectFriendWizard::accept() { std::cerr << "ConclusionPage::validatePage() accepting GPG key for connection." << std::endl; - if(peerDetails.skip_signature_validation) + if(peerDetails.skip_pgp_signature_validation) rsPeers->addSslOnlyFriend(peerDetails.id, peerDetails.gpg_id,peerDetails); else rsPeers->addFriend(peerDetails.id, peerDetails.gpg_id,serviceFlags()) ; From ed864f9470d8c931bb7d3d4d74107bfa4e69e5a1 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Sep 2019 19:00:52 +0200 Subject: [PATCH 37/45] removed some debug info about PGP signature validation, and added the ability to accept fingerprint instead of ID in the handshake --- libretroshare/src/pqi/authssl.cc | 30 ++++++++++++++++--------- libretroshare/src/pqi/authssl.h | 4 +++- libretroshare/src/pqi/pqissl.cc | 3 +-- libretroshare/src/pqi/pqissllistener.cc | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 300bd6110..4037325f8 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -534,7 +534,7 @@ bool AuthSSLimpl::validateOwnCertificate(X509 *x509, EVP_PKEY *pkey) uint32_t diagnostic ; /* standard authentication */ - if (!AuthX509WithGPG(x509,diagnostic)) + if (!AuthX509WithGPG(x509,true,diagnostic)) { std::cerr << "Validate Own certificate ERROR: diagnostic = " << diagnostic << std::endl; return false; @@ -970,7 +970,7 @@ X509 *AuthSSLimpl::SignX509ReqWithGPG(X509_REQ *req, long /*days*/) } -bool AuthSSLimpl::AuthX509WithGPG(X509 *x509, uint32_t& diagnostic) +bool AuthSSLimpl::AuthX509WithGPG(X509 *x509,bool verbose, uint32_t& diagnostic) { RsPgpId issuer = RsX509Cert::getCertIssuer(*x509); RsPeerDetails pd; @@ -1127,11 +1127,12 @@ bool AuthSSLimpl::AuthX509WithGPG(X509 *x509, uint32_t& diagnostic) goto err; } - RsInfo() << __PRETTY_FUNCTION__ << " Verified: " << sigtypestring - << " signature of certificate sslId: " - << RsX509Cert::getCertSslId(*x509) - << ", Version " << std::hex << certificate_version << std::dec - << " using PGP key " << pd.fpr << " " << pd.name << std::endl; + if(verbose) + std::cerr<< " Verified: " << sigtypestring + << " signature of certificate sslId: " + << RsX509Cert::getCertSslId(*x509) + << ", Version " << std::hex << certificate_version << std::dec + << " using PGP key " << pd.fpr << " " << pd.name << std::endl; } EVP_MD_CTX_destroy(ctx); @@ -1196,8 +1197,17 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) RsPeerId sslId = RsX509Cert::getCertSslId(*x509Cert); std::string sslCn = RsX509Cert::getCertIssuerString(*x509Cert); + RsPgpId pgpId(sslCn); + if(sslCn.length() == 40) + { + RsPgpFingerprint pgpFpr(sslCn); // we also accept fingerprint format, so that in the future we can switch to fingerprints without backward compatibility issues + + if(!pgpFpr.isNull()) + pgpId = PGPHandler::pgpIdFromFingerprint(pgpFpr); // in the future, we drop PGP ids and keep the fingerprint all along + } + RsPeerDetails det; if(!rsPeers->getPeerDetails(sslId,det)) { @@ -1249,7 +1259,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) } uint32_t auth_diagnostic; - if(!isSslOnlyFriend && !AuthX509WithGPG(x509Cert, auth_diagnostic)) + if(!isSslOnlyFriend && !AuthX509WithGPG(x509Cert,true, auth_diagnostic)) { std::string errMsg = "Certificate was rejected because PGP " "signature verification failed with diagnostic: " @@ -1334,7 +1344,7 @@ bool AuthSSLimpl::parseX509DetailsFromFile( } uint32_t diagnostic = 0; - if(!AuthX509WithGPG(x509, diagnostic)) + if(!AuthX509WithGPG(x509,false, diagnostic)) { RsErr() << __PRETTY_FUNCTION__ << " AuthX509WithGPG failed with " << "diagnostic: " << diagnostic << std::endl; @@ -1748,7 +1758,7 @@ bool AuthSSLimpl::loadList(std::list& load) X509 *peer = loadX509FromPEM(kit->value); /* authenticate it */ uint32_t diagnos ; - if (AuthX509WithGPG(peer,diagnos)) + if (AuthX509WithGPG(peer,false,diagnos)) { LocalStoreCert(peer); } diff --git a/libretroshare/src/pqi/authssl.h b/libretroshare/src/pqi/authssl.h index 618d9f7b6..d7973e869 100644 --- a/libretroshare/src/pqi/authssl.h +++ b/libretroshare/src/pqi/authssl.h @@ -140,10 +140,12 @@ public: * @param[in] x509 pointer ti the X509 certificate to check * @param[out] diagnostic one of RS_SSL_HANDSHAKE_DIAGNOSTIC_* diagnostic * codes + * @param[in] verbose if true, prints the authentication result to screen. * @return true if correctly signed, false otherwise */ virtual bool AuthX509WithGPG( X509* x509, + bool verbose, uint32_t& diagnostic = RS_DEFAULT_STORAGE_PARAM(uint32_t) ) = 0; @@ -233,7 +235,7 @@ public: virtual X509* SignX509ReqWithGPG(X509_REQ *req, long days) override; /// @see AuthSSL - bool AuthX509WithGPG(X509 *x509, uint32_t& auth_diagnostic) override; + bool AuthX509WithGPG(X509 *x509, bool verbose, uint32_t& auth_diagnostic) override; /// @see AuthSSL int VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx) override; diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 556b81b9a..a10e7853a 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -1185,8 +1185,7 @@ int pqissl::Authorise_SSL_Connection() bool isSslOnlyFriend = rsPeers->isSslOnlyFriend(certPeerId); uint32_t authErrCode = 0; - if( !isSslOnlyFriend && - !AuthSSL::instance().AuthX509WithGPG(peercert, authErrCode) ) + if( !isSslOnlyFriend && !AuthSSL::instance().AuthX509WithGPG(peercert,false, authErrCode) ) { RsFatal() << __PRETTY_FUNCTION__ << " failure verifying peer " << "certificate signature. This should never happen at this " diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index e295a7784..3d62db9ea 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -790,7 +790,7 @@ int pqissllistener::completeConnection(int fd, IncomingSSLInfo& info) uint32_t authErrCode = 0; if( !isSslOnlyFriend && - !AuthSSL::instance().AuthX509WithGPG(peercert, authErrCode) ) + !AuthSSL::instance().AuthX509WithGPG(peercert,false, authErrCode) ) { RsFatal() << __PRETTY_FUNCTION__ << " failure verifying peer " << "certificate signature. This should never happen at this " From 6919711f48cb201e0b8791d8ad8829f2215849b5 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 21 Sep 2019 22:20:33 +0200 Subject: [PATCH 38/45] restricted check for matching PGP ids to short invites only, since otherwise the call to isGPGAccepted() will rule out wrong IDs anyway --- libretroshare/src/pqi/authssl.cc | 47 +++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 4037325f8..ad017ce2c 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1200,7 +1200,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) RsPgpId pgpId(sslCn); - if(sslCn.length() == 40) + if(sslCn.length() == RsPgpFingerprint::SIZE_IN_BYTES*2) { RsPgpFingerprint pgpFpr(sslCn); // we also accept fingerprint format, so that in the future we can switch to fingerprints without backward compatibility issues @@ -1208,21 +1208,6 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) pgpId = PGPHandler::pgpIdFromFingerprint(pgpFpr); // in the future, we drop PGP ids and keep the fingerprint all along } - RsPeerDetails det; - if(!rsPeers->getPeerDetails(sslId,det)) - { - std::cerr << "Nothing known about peer " << sslId << " trying to connect! Refusing connection." << std::endl; - return verificationFailed; - } - - bool isSslOnlyFriend = det.skip_pgp_signature_validation; - - if(det.gpg_id != pgpId) - { - std::cerr << "(EE) peer " << sslId << " trying to connect with issuer ID " << pgpId << " whereas key ID " << det.gpg_id << " was expected! Refusing connection." << std::endl; - return verificationFailed; - } - if(sslId.isNull()) { std::string errMsg = "x509Cert has invalid sslId!"; @@ -1258,6 +1243,36 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) return verificationFailed; } + bool isSslOnlyFriend = false; + + // For SSL only friends (ones added through short invites) we check that the fingerprint + // in the key (det.gpg_id) matches the one of the handshake. + { + RsPeerDetails det; + + if(rsPeers->getPeerDetails(sslId,det)) + bool isSslOnlyFriend = det.skip_pgp_signature_validation; + + if(det.skip_pgp_signature_validation && det.gpg_id != pgpId)// in the future, we should compare fingerprints instead + { + std::string errorMsg = "Peer " + sslId.toStdString() + " trying to connect with issuer ID " + pgpId.toStdString() + + " whereas key ID " + det.gpg_id.toStdString() + " was expected! Refusing connection." ; + + RsErr() << __PRETTY_FUNCTION__ << errorMsg << std::endl; + + if(rsEvents) + { + ev->mSslId = sslId; + ev->mSslCn = sslCn; + ev->mPgpId = pgpId; + ev->mErrorMsg = errorMsg; + rsEvents->postEvent(std::move(ev)); + } + + return verificationFailed; + } + } + uint32_t auth_diagnostic; if(!isSslOnlyFriend && !AuthX509WithGPG(x509Cert,true, auth_diagnostic)) { From 9c7edffc218948528cdab75f0762292a16b84a35 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 22 Sep 2019 16:34:01 +0200 Subject: [PATCH 39/45] fixed bug caused by shadowing a variable --- libretroshare/src/pqi/authssl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index ad017ce2c..a3ed8ccf4 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1251,7 +1251,7 @@ int AuthSSLimpl::VerifyX509Callback(int /*preverify_ok*/, X509_STORE_CTX* ctx) RsPeerDetails det; if(rsPeers->getPeerDetails(sslId,det)) - bool isSslOnlyFriend = det.skip_pgp_signature_validation; + isSslOnlyFriend = det.skip_pgp_signature_validation; if(det.skip_pgp_signature_validation && det.gpg_id != pgpId)// in the future, we should compare fingerprints instead { From 19ced52a027fb323ca7c3e027d56811397fa8223 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 22 Sep 2019 17:05:22 +0200 Subject: [PATCH 40/45] fixed bug caused by wrong reading of disc flag --- libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index 223d08c7f..d7cf5f1a7 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -1028,7 +1028,7 @@ void p3discovery2::recvPGPCertificateRequest( const RsPeerId& fromId, const RsDi peerState ps; mPeerMgr->getOwnNetStatus(ps); - if(ps.vs_disc != RS_VS_DISC_OFF) + if(ps.vs_disc == RS_VS_DISC_OFF) { std::cerr << "(WW) refusing PGP certificate request from " << fromId << " because discovery is OFF" << std::endl; return; From cdeee0198ee5e09095aae42626441078dea76fa4 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 22 Sep 2019 18:13:18 +0200 Subject: [PATCH 41/45] removed dependency of FriendDialog on RsAutoUpdatePage which is not needed anymore --- retroshare-gui/src/gui/FriendsDialog.cpp | 12 +----------- retroshare-gui/src/gui/FriendsDialog.h | 9 +-------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index 9907796c9..2d196978d 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -59,8 +59,7 @@ static FriendsDialog *instance = NULL; /** Constructor */ -FriendsDialog::FriendsDialog(QWidget *parent) - : RsAutoUpdatePage(1500,parent) +FriendsDialog::FriendsDialog(QWidget *parent) : MainPage(parent) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); @@ -192,11 +191,6 @@ void FriendsDialog::processSettings(bool bLoad) Settings->endGroup(); } -void FriendsDialog::showEvent(QShowEvent *event) -{ - RsAutoUpdatePage::showEvent(event); -} - void FriendsDialog::chatMessageReceived(const ChatMessage &msg) { if(msg.chat_id.isBroadcast()) @@ -226,10 +220,6 @@ void FriendsDialog::chatStatusReceived(const ChatId &chat_id, const QString &sta } } -void FriendsDialog::updateDisplay() -{ -} - void FriendsDialog::addFriend() { std::string groupId = ui.friendList->getSelectedGroupId(); diff --git a/retroshare-gui/src/gui/FriendsDialog.h b/retroshare-gui/src/gui/FriendsDialog.h index 7613e83d0..6eb9cdf7a 100644 --- a/retroshare-gui/src/gui/FriendsDialog.h +++ b/retroshare-gui/src/gui/FriendsDialog.h @@ -21,8 +21,6 @@ #ifndef _FRIENDSDIALOG_H #define _FRIENDSDIALOG_H -#include "retroshare-gui/RsAutoUpdatePage.h" - #include "ui_FriendsDialog.h" #define IMAGE_NETWORK ":/icons/png/network.png" @@ -33,7 +31,7 @@ class NetworkView; class IdDialog; class CirclesDialog; -class FriendsDialog : public RsAutoUpdatePage +class FriendsDialog : public MainPage { Q_OBJECT @@ -59,8 +57,6 @@ public: virtual UserNotify *getUserNotify(QObject *parent); - virtual void updateDisplay() ; // overloaded from RsAutoUpdatePage - static bool isGroupChatActive(); static void groupChatActivate(); @@ -71,9 +67,6 @@ public: IdDialog *idDialog; -protected: - void showEvent (QShowEvent *event); - private slots: void chatMessageReceived(const ChatMessage& msg); void chatStatusReceived(const ChatId& chat_id, const QString& status_string); From 282d2d324d4e2f7aa29673d23248af758dd8588f Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 22 Sep 2019 20:42:49 +0200 Subject: [PATCH 42/45] added missing notifications when adding friends --- libretroshare/src/rsserver/p3peers.cc | 36 ++++++++++++------- libretroshare/src/rsserver/p3peers.h | 2 +- .../src/gui/common/FriendListModel.cpp | 15 ++++---- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 6b7592629..4cedc4fcf 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -130,11 +130,12 @@ bool p3Peers::hasExportMinimal() } /* Updates ... */ -bool p3Peers::FriendsChanged() +bool p3Peers::FriendsChanged(bool add) { #ifdef P3PEERS_DEBUG std::cerr << "p3Peers::FriendsChanged()" << std::endl; #endif + RsServer::notify()->notifyListChange(NOTIFY_LIST_FRIENDS, add? NOTIFY_TYPE_ADD : NOTIFY_TYPE_DEL); /* TODO */ return false; @@ -289,16 +290,16 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) /* get from gpg (first), to fill in the sign and trust details */ /* don't return now, we've got fill in the ssl and connection info */ - if(!getGPGDetails(ps.gpg_id, d)) - { - if(!ps.skip_pgp_signature_validation) - return false; + if(!getGPGDetails(ps.gpg_id, d)) + { + if(!ps.skip_pgp_signature_validation) + return false; - d.gpg_id = ps.gpg_id ; - d.skip_pgp_signature_validation = true; - } - else - d.skip_pgp_signature_validation = false; + d.gpg_id = ps.gpg_id ; + d.skip_pgp_signature_validation = true; + } + else + d.skip_pgp_signature_validation = false; d.isOnlyGPGdetail = false; @@ -766,7 +767,9 @@ bool p3Peers::addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePe return true; } - /* otherwise - we install as ssl_id..... + FriendsChanged(true); + + /* otherwise - we install as ssl_id..... * If we are adding an SSL certificate. we flag lastcontact as now. * This will cause the SSL certificate to be retained for 30 days... and give the person a chance to connect! * */ @@ -776,7 +779,13 @@ bool p3Peers::addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePe bool p3Peers::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_id,const RsPeerDetails& details ) { - return mPeerMgr->addSslOnlyFriend(sslId, pgp_id,details); + if( mPeerMgr->addSslOnlyFriend(sslId, pgp_id,details)) + { + FriendsChanged(true); + return true; + } + else + return false; } bool p3Peers::removeKeysFromPGPKeyring(const std::set& pgp_ids,std::string& backup_file,uint32_t& error_code) @@ -1534,7 +1543,10 @@ bool p3Peers::loadCertificateFromString( // now get all friends who declare this key ID to be the one needed to check connections, and clear their "skip_pgp_signature_validation" flag if(res) + { mPeerMgr->notifyPgpKeyReceived(gpgid); + FriendsChanged(true); + } return res; } diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index ad6f2d056..e44e7d23a 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -48,7 +48,7 @@ public: virtual ~p3Peers() {} /* Updates ... */ - virtual bool FriendsChanged(); + virtual bool FriendsChanged(bool add); virtual bool OthersChanged(); /* Peer Details (Net & Auth) */ diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index de7ed2ab3..d0a20306a 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -37,6 +37,7 @@ #include "retroshare/rsmsgs.h" #define DEBUG_MODEL +//#define DEBUG_MODEL_INDEX #define IS_MESSAGE_UNREAD(flags) (flags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)) @@ -292,7 +293,7 @@ QModelIndex RsFriendListModel::index(int row, int column, const QModelIndex& par EntryIndex parent_index ; convertInternalIdToIndex(parent.internalId(),parent_index); -#ifdef DEBUG_MODEL +#ifdef DEBUG_MODEL_INDEX RsDbg() << "Index row=" << row << " col=" << column << " parent=" << parent << std::endl; #endif @@ -300,7 +301,7 @@ QModelIndex RsFriendListModel::index(int row, int column, const QModelIndex& par EntryIndex new_index = parent_index.child(row,mTopLevel); convertIndexToInternalId(new_index,ref); -#ifdef DEBUG_MODEL +#ifdef DEBUG_MODEL_INDEX RsDbg() << " returning " << createIndex(row,column,ref) << std::endl; #endif @@ -588,7 +589,7 @@ QVariant RsFriendListModel::onlineRole(const EntryIndex& e, int col) const QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const { -#ifdef DEBUG_MODEL +#ifdef DEBUG_MODEL_INDEX std::cerr << " font role " << e.type << ", (" << (int)e.group_index << ","<< (int)e.profile_index << ","<< (int)e.node_index << ") col="<< col<<": " << std::endl; #endif @@ -613,7 +614,7 @@ public: QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const { -#ifdef DEBUG_MODEL +#ifdef DEBUG_MODEL_INDEX std::cerr << " Display role " << e.type << ", (" << (int)e.group_index << ","<< (int)e.profile_index << ","<< (int)e.node_index << ") col="<< col<<": "; AutoEndel x; #endif @@ -640,7 +641,7 @@ QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const switch(col) { case COLUMN_THREAD_NAME: -#ifdef DEBUG_MODEL +#ifdef DEBUG_MODEL_INDEX std::cerr << group->group_info.name.c_str() ; #endif @@ -663,7 +664,7 @@ QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const if(!profile) return QVariant(); -#ifdef DEBUG_MODEL +#ifdef DEBUG_MODEL_INDEX std::cerr << profile->profile_info.name.c_str() ; #endif switch(col) @@ -683,7 +684,7 @@ QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const if(!node) return QVariant(); -#ifdef DEBUG_MODEL +#ifdef DEBUG_MODEL_INDEX std::cerr << node->node_info.location.c_str() ; #endif switch(col) From a04d56e84e30902f474d54abd7cdeecdc8b2c170 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 23 Sep 2019 19:44:20 +0200 Subject: [PATCH 43/45] fixed wrong default value for showUnconnected nodes --- retroshare-gui/src/gui/common/FriendListModel.cpp | 2 +- retroshare-gui/src/gui/common/NewFriendList.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index d0a20306a..d7d625121 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_MODEL +//#define DEBUG_MODEL //#define DEBUG_MODEL_INDEX #define IS_MESSAGE_UNREAD(flags) (flags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)) diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 04d3e444b..ef4417526 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -441,7 +441,7 @@ void NewFriendList::processSettings(bool load) if (load) // load settings { // states - setShowUnconnected(!Settings->value("hideUnconnected", mProxyModel->showOfflineNodes()).toBool()); + setShowUnconnected(!Settings->value("hideUnconnected", !mProxyModel->showOfflineNodes()).toBool()); setShowState(Settings->value("showState", mModel->getDisplayStatusString()).toBool()); setShowGroups(Settings->value("showGroups", mModel->getDisplayGroups()).toBool()); From d055887aa146523c2ade3708130a35b84225b5d1 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 23 Sep 2019 20:52:19 +0200 Subject: [PATCH 44/45] removed some dead code --- .../src/gui/common/NewFriendList.cpp | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index ef4417526..38e6ba3fd 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -458,15 +458,6 @@ void NewFriendList::processSettings(bool load) Settings->setArrayIndex(index); std::string gids = Settings->value("open").toString().toStdString(); - -// RsGroupInfo ginfo ; -// -// if(rsPeers->getGroupInfoByName(gids,ginfo)) // backward compatibility -// addGroupToExpand(ginfo.id) ; -// else if(rsPeers->getGroupInfo(RsNodeGroupId(gids),ginfo)) // backward compatibility -// addGroupToExpand(ginfo.id) ; -// else -// std::cerr << "(EE) Cannot find group info for openned group \"" << gids << "\"" << std::endl; } Settings->endArray(); } @@ -486,15 +477,6 @@ void NewFriendList::processSettings(bool load) // sort Settings->setValue("sortByState", mProxyModel->sortByState()); -// // open groups -// Settings->beginWriteArray("Groups"); -// int arrayIndex = 0; -// std::set expandedPeers; -// getExpandedGroups(expandedPeers); -// foreach (RsNodeGroupId groupId, expandedPeers) { -// Settings->setArrayIndex(arrayIndex++); -// Settings->setValue("open", QString::fromStdString(groupId.toStdString())); -// } Settings->endArray(); } } @@ -719,8 +701,6 @@ void NewFriendList::peerTreeWidgetCustomPopupMenu() contextMenu.addAction(ui->actionExportFriendlist); contextMenu.addAction(ui->actionImportFriendlist); - // contextMenu = ui->peerTreeWidget->createStandardContextMenu(contextMenu); - contextMenu.exec(QCursor::pos()); } From 24781a71f54bf0c786dfccc511902919a78f277c Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 23 Sep 2019 21:32:28 +0200 Subject: [PATCH 45/45] removed unused mOthersList from PeerMgr --- libretroshare/src/pqi/p3peermgr.cc | 219 +++++++++++--------------- libretroshare/src/pqi/p3peermgr.h | 3 - libretroshare/src/rsserver/p3peers.cc | 3 +- 3 files changed, 89 insertions(+), 136 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 57faff741..1adf191d1 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -840,19 +840,6 @@ bool p3PeerMgrIMPL::getFriendNetStatus(const RsPeerId &id, peerState &state) } -bool p3PeerMgrIMPL::getOthersNetStatus(const RsPeerId &id, peerState &state) -{ - RS_STACK_MUTEX(mPeerMtx); - - /* check for existing */ - std::map::iterator it; - it = mOthersList.find(id); - if (it == mOthersList.end()) return false; - - state = it->second; - return true; -} - int p3PeerMgrIMPL::getConnectAddresses( const RsPeerId &id, sockaddr_storage &lAddr, sockaddr_storage &eAddr, pqiIpAddrSet &histAddrs, std::string &dyndns ) @@ -978,6 +965,14 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg return true; /* (1) already exists */ } + // check that the PGP key is known + + if(!AuthGPG::getAuthGPG()->isGPGId(gpg_id)) + { + RsErr() << "Trying to add SSL id (" << id << ") to be validated with unknown PGP key (" << gpg_id << ". This is a bug!" << std::endl; + return false; + } + //Authentication is now tested at connection time, we don't store the ssl cert anymore // if (!AuthGPG::getAuthGPG()->isGPGAccepted(gpg_id) && gpg_id != AuthGPG::getAuthGPG()->getGPGOwnId()) @@ -992,71 +987,67 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg // after that, we know that we have the key, because AuthGPG wouldn't answer yes for a key it doesn't know. /* check if it is in others */ - if (mOthersList.end() != (it = mOthersList.find(id))) - { - /* (2) in mOthersList -> move over */ +// if (mOthersList.end() != (it = mOthersList.find(id))) +// { +// /* (2) in mOthersList -> move over */ +//#ifdef PEER_DEBUG +// std::cerr << "p3PeerMgrIMPL::addFriend() Move from Others" << std::endl; +//#endif +// if(!it->second.gpg_id.isNull() && it->second.gpg_id != input_gpg_id)// already exists as a friend with a different PGP id!! +// RsErr() << "Trying to add SSL id (" << id << ") that is already known (but not friend) with existing PGP key (" << it->second.gpg_id +// << ") but using a different PGP key (" << input_gpg_id << "). This looks like a bug! The friend will be added again with the new PGP key ID." << std::endl; +// +// mFriendList[id] = it->second; +// mOthersList.erase(it); +// +// it = mFriendList.find(id); +// +// /* setup connectivity parameters */ +// it->second.vs_disc = vs_disc; +// it->second.vs_dht = vs_dht; +// +// it->second.netMode = netMode; +// it->second.lastcontact = lastContact; +// +// it->second.gpg_id = input_gpg_id; +// it->second.skip_pgp_signature_validation = false; +// +// mStatusChanged = true; +// +// notifyLinkMgr = true; +// +// IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ +// } +// else + #ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::addFriend() Move from Others" << std::endl; + std::cerr << "p3PeerMgrIMPL::addFriend() Creating New Entry" << std::endl; #endif - mFriendList[id] = it->second; - mOthersList.erase(it); + /* create a new entry */ + peerState pstate; - it = mFriendList.find(id); + pstate.id = id; + pstate.gpg_id = gpg_id; + pstate.name = AuthGPG::getAuthGPG()->getGPGName(gpg_id); - /* setup connectivity parameters */ - it->second.vs_disc = vs_disc; - it->second.vs_dht = vs_dht; + pstate.vs_disc = vs_disc; + pstate.vs_dht = vs_dht; + pstate.netMode = netMode; + pstate.lastcontact = lastContact; - it->second.netMode = netMode; - it->second.lastcontact = lastContact; + pstate.gpg_id = input_gpg_id; + pstate.skip_pgp_signature_validation = false; - if(!it->second.gpg_id.isNull() && it->second.gpg_id != input_gpg_id)// already exists as a friend with a different PGP id!! - { - RsErr() << "Trying to add SSL id (" << id << ") that is already known (but not friend) with existing PGP key (" << it->second.gpg_id << ") but using a different PGP key (" << input_gpg_id << "). This is a bug!" << std::endl; - return false; - } + /* addr & timestamps -> auto cleared */ - it->second.gpg_id = input_gpg_id; - it->second.skip_pgp_signature_validation = false; + mFriendList[id] = pstate; - mStatusChanged = true; + mStatusChanged = true; - notifyLinkMgr = true; + notifyLinkMgr = true; - IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ - } - else - { -#ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::addFriend() Creating New Entry" << std::endl; -#endif - - /* create a new entry */ - peerState pstate; - - pstate.id = id; - pstate.gpg_id = gpg_id; - pstate.name = AuthGPG::getAuthGPG()->getGPGName(gpg_id); - - pstate.vs_disc = vs_disc; - pstate.vs_dht = vs_dht; - pstate.netMode = netMode; - pstate.lastcontact = lastContact; - - pstate.gpg_id = input_gpg_id; - pstate.skip_pgp_signature_validation = false; - - /* addr & timestamps -> auto cleared */ - - mFriendList[id] = pstate; - - mStatusChanged = true; - - notifyLinkMgr = true; - - IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ - } + IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ } if (notifyLinkMgr) @@ -1090,19 +1081,19 @@ bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_ peerState pstate; - { - RS_STACK_MUTEX(mPeerMtx); - - /* If in mOthersList -> move over */ - auto it = mOthersList.find(sslId); - if (it != mOthersList.end()) - { - pstate = it->second; - mOthersList.erase(it); - } - - - } // RS_STACK_MUTEX(mPeerMtx); +// { +// RS_STACK_MUTEX(mPeerMtx); +// +// /* If in mOthersList -> move over */ +// auto it = mOthersList.find(sslId); +// if (it != mOthersList.end()) +// { +// pstate = it->second; +// mOthersList.erase(it); +// } +// +// +// } // RS_STACK_MUTEX(mPeerMtx); if(!pstate.gpg_id.isNull() && AuthGPG::getAuthGPG()->isGPGAccepted(pstate.gpg_id)) { @@ -1196,7 +1187,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPgpId &id) sslid_toRemove.push_back(it->second.id); - mOthersList[it->second.id] = peer; + //mOthersList[it->second.id] = peer; mStatusChanged = true; //success = true; @@ -1271,7 +1262,7 @@ bool p3PeerMgrIMPL::removeFriend(const RsPeerId &id, bool removePgpId) if(removePgpId) pgpid_toRemove.push_back(it->second.gpg_id); - mOthersList[id] = peer; + //mOthersList[id] = peer; mStatusChanged = true; //success = true; @@ -1331,14 +1322,14 @@ void p3PeerMgrIMPL::printPeerLists(std::ostream &out) out << std::endl; } - out << "p3PeerMgrIMPL::printPeerLists() Others List"; - out << std::endl; - for(it = mOthersList.begin(); it != mOthersList.end(); ++it) - { - out << "\t SSL ID: " << it->second.id; - out << "\t GPG ID: " << it->second.gpg_id; - out << std::endl; - } +// out << "p3PeerMgrIMPL::printPeerLists() Others List"; +// out << std::endl; +// for(it = mOthersList.begin(); it != mOthersList.end(); ++it) +// { +// out << "\t SSL ID: " << it->second.id; +// out << "\t GPG ID: " << it->second.gpg_id; +// out << std::endl; +// } } return; @@ -1520,16 +1511,10 @@ bool p3PeerMgrIMPL::addPeerLocator(const RsPeerId &sslId, const RsUrl& locator) auto it = mFriendList.find(sslId); if (it == mFriendList.end()) { - it = mOthersList.find(sslId); - if (it == mOthersList.end()) - { #ifdef PEER_DEBUG - std::cerr << __PRETTY_FUNCTION__ << "cannot add address " - << "info, peer id: " << sslId << " not found in list" - << std::endl; + std::cerr << __PRETTY_FUNCTION__ << "cannot add address " << "info, peer id: " << sslId << " not found in list" << std::endl; #endif return false; - } } changed = it->second.ipAddrs.updateLocalAddrs(ip); @@ -1577,15 +1562,10 @@ bool p3PeerMgrIMPL::setLocalAddress( const RsPeerId &id, std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { - if (mOthersList.end() == (it = mOthersList.find(id))) - { #ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres " - << "info : peer id not found in friend list id: " - << id << std::endl; + std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres " << "info : peer id not found in friend list id: " << id << std::endl; #endif return false; - } } /* "it" points to peer */ @@ -1643,15 +1623,10 @@ bool p3PeerMgrIMPL::setExtAddress( const RsPeerId &id, std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { - if (mOthersList.end() == (it = mOthersList.find(id))) - { #ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres " - << "info : peer id not found in friend list id: " << id - << std::endl; + std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres " << "info : peer id not found in friend list id: " << id << std::endl; #endif return false; - } } /* "it" points to peer */ @@ -1698,13 +1673,10 @@ bool p3PeerMgrIMPL::setDynDNS(const RsPeerId &id, const std::string &dyndns) std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { - if (mOthersList.end() == (it = mOthersList.find(id))) - { #ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::setDynDNS() cannot add dyn dns info : peer id not found in friend list id: " << id << std::endl; + std::cerr << "p3PeerMgrIMPL::setDynDNS() cannot add dyn dns info : peer id not found in friend list id: " << id << std::endl; #endif - return false; - } + return false; } /* "it" points to peer */ @@ -1913,13 +1885,10 @@ bool p3PeerMgrIMPL::updateAddressList(const RsPeerId& id, const pqiIpAddrSet std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { - if (mOthersList.end() == (it = mOthersList.find(id))) - { #ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres info : peer id not found in friend list. id: " << id << std::endl; + std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres info : peer id not found in friend list. id: " << id << std::endl; #endif - return false; - } + return false; } /* "it" points to peer */ @@ -1958,11 +1927,8 @@ bool p3PeerMgrIMPL::updateCurrentAddress(const RsPeerId& id, const pqiIpAddre std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { - if (mOthersList.end() == (it = mOthersList.find(id))) - { std::cerr << "p3PeerMgrIMPL::updateCurrentAddress() ERROR peer id not found: " << id << std::endl; return false; - } } if (sockaddr_storage_isPrivateNet(addr.mAddr)) @@ -2005,11 +1971,8 @@ bool p3PeerMgrIMPL::updateLastContact(const RsPeerId& id) std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { - if (mOthersList.end() == (it = mOthersList.find(id))) - { std::cerr << "p3PeerMgrIMPL::updateLastContact() ERROR peer id not found: " << id << std::endl; return false; - } } it->second.lastcontact = time(NULL); @@ -2031,10 +1994,7 @@ bool p3PeerMgrIMPL::setNetworkMode(const RsPeerId &id, uint32_t netMode) std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { - if (mOthersList.end() == (it = mOthersList.find(id))) - { return false; - } } bool changed = false; @@ -2101,10 +2061,7 @@ bool p3PeerMgrIMPL::setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_ std::map::iterator it; if (mFriendList.end() == (it = mFriendList.find(id))) { - if (mOthersList.end() == (it = mOthersList.find(id))) - { return false; - } } else { diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index f8cfa64ed..d5451eaa9 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -208,7 +208,6 @@ virtual bool UpdateOwnAddress(const struct sockaddr_storage &local_addr, cons virtual bool getOwnNetStatus(peerState &state) = 0; virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state) = 0; -virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state) = 0; virtual bool getPeerName(const RsPeerId &ssl_id, std::string &name) = 0; virtual bool getGpgId(const RsPeerId &sslId, RsPgpId &gpgId) = 0; @@ -329,7 +328,6 @@ public: virtual bool getOwnNetStatus(peerState &state); virtual bool getFriendNetStatus(const RsPeerId &id, peerState &state); - virtual bool getOthersNetStatus(const RsPeerId &id, peerState &state); virtual bool getPeerName(const RsPeerId& ssl_id, std::string& name); virtual bool getGpgId(const RsPeerId& sslId, RsPgpId& gpgId); @@ -417,7 +415,6 @@ private: peerState mOwnState; std::map mFriendList; // - std::map mOthersList; std::map mReportedOwnAddresses ; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 4cedc4fcf..18d245663 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -713,9 +713,8 @@ RsPgpId p3Peers::getGPGId(const RsPeerId& sslid) return AuthGPG::getAuthGPG()->getGPGOwnId(); } peerState pcs; - if (mPeerMgr->getFriendNetStatus(sslid, pcs) || mPeerMgr->getOthersNetStatus(sslid, pcs)) { + if (mPeerMgr->getFriendNetStatus(sslid, pcs)) return pcs.gpg_id; - } return RsPgpId(); }