From 418c42bd1108b79cf9ad297d3d096858a7f47733 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Mon, 2 Jul 2018 13:50:02 +0200 Subject: [PATCH] Extra locators in cert invite made optional --- libretroshare/src/retroshare/rspeers.h | 23 +++++++++++++-- libretroshare/src/rsserver/p3peers.cc | 41 +++++++++++++++----------- libretroshare/src/rsserver/p3peers.h | 10 +++++-- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 89131e8bf..7824daa11 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -386,11 +386,30 @@ public: virtual bool resetOwnExternalAddressList() = 0; virtual bool getAllowServerIPDetermination() = 0 ; + /** + * @brief Get RetroShare invite of the given peer + * @param[in] sslId Id of the peer of which we want to generate an invite + * @param[in] includeSignatures true to add key signatures to the invite + * @param[in] includeExtraLocators false to avoid to add extra locators + * @return invite string + */ + virtual std::string GetRetroshareInvite( + const RsPeerId& sslId, bool includeSignatures = false, + bool includeExtraLocators = true ) = 0; + + /** + * @brief Get RetroShare invite of our own peer + * @param[in] includeSignatures true to add key signatures to the invite + * @param[in] includeExtraLocators false to avoid to add extra locators + * @return invite string + */ + virtual std::string GetRetroshareInvite( + bool includeSignatures = false, + bool includeExtraLocators = true ) = 0; + /* Auth Stuff */ - virtual std::string GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures) = 0; virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures) = 0; virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0; - virtual std::string GetRetroshareInvite(bool include_signatures) = 0; virtual bool hasExportMinimal() = 0; // Add keys to the keyring diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 60d724179..36509c33b 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1048,9 +1048,11 @@ bool p3Peers::setProxyServer(const uint32_t type, const std::string &addr_str, c //=========================================================================== /* Auth Stuff */ -std::string p3Peers::GetRetroshareInvite(bool include_signatures) +std::string p3Peers::GetRetroshareInvite( + bool include_signatures, bool includeExtraLocators ) { - return GetRetroshareInvite(getOwnId(),include_signatures); + return GetRetroshareInvite( + getOwnId(), include_signatures, includeExtraLocators ); } std::string p3Peers::getPGPKey(const RsPgpId& pgp_id,bool include_signatures) { @@ -1101,37 +1103,42 @@ bool p3Peers::GetPGPBase64StringAndCheckSum( const RsPgpId& gpg_id, return true ; } -std::string p3Peers::GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures) +std::string p3Peers::GetRetroshareInvite( + const RsPeerId& ssl_id, bool include_signatures, + bool includeExtraLocators ) { #ifdef P3PEERS_DEBUG - std::cerr << "p3Peers::GetRetroshareInvite()" << std::endl; + std::cerr << __PRETTY_FUNCTION__ << std::endl; #endif //add the sslid, location, ip local and external address after the signature - RsPeerDetails Detail; - std::string invite ; + RsPeerDetails detail; + std::string invite; - if (getPeerDetails(ssl_id, Detail)) + if (getPeerDetails(ssl_id, detail)) { - unsigned char *mem_block = NULL; + if(!includeExtraLocators) detail.ipAddressList.clear(); + + unsigned char *mem_block = nullptr; size_t mem_block_size = 0; - if(!AuthGPG::getAuthGPG()->exportPublicKey(RsPgpId(Detail.gpg_id),mem_block,mem_block_size,false,include_signatures)) + if(!AuthGPG::getAuthGPG()->exportPublicKey( + RsPgpId(detail.gpg_id), mem_block, mem_block_size, false, + include_signatures )) { - std::cerr << "Cannot output certificate for id \"" << Detail.gpg_id << "\". Sorry." << std::endl; - return "" ; + std::cerr << "Cannot output certificate for id \"" << detail.gpg_id + << "\". Sorry." << std::endl; + return ""; } - RsCertificate cert( Detail,mem_block,mem_block_size ) ; - - delete[] mem_block ; - - return cert.toStdString() ; + RsCertificate cert(detail, mem_block, mem_block_size); + delete[] mem_block; + return cert.toStdString(); } #ifdef P3PEERS_DEBUG - std::cerr << "p3Peers::GetRetroshareInvite() returns : \n" << invite << std::endl; + std::cerr << __PRETTY_FUNCTION__ << " returns : \n" << invite << std::endl; #endif return invite; } diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index 43d45f8a7..d2333c420 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -115,11 +115,15 @@ public: /* Auth Stuff */ // Get the invitation (GPG cert + local/ext address + SSL id for the given peer) - virtual std::string GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures); - virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures) ; + virtual std::string GetRetroshareInvite( + const RsPeerId& ssl_id, bool include_signatures = false, + bool includeExtraLocators = true ); + virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures); // same but for own id - virtual std::string GetRetroshareInvite(bool include_signatures); + virtual std::string GetRetroshareInvite( + bool include_signatures = false, + bool includeExtraLocators = true ); virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum); virtual bool hasExportMinimal();