From cd98f022467521c4a11abe556d3785565b0cad52 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 2 Apr 2020 22:24:14 +0200 Subject: [PATCH] removed askForDeferredSelfSignature() and made IdEditDialog comply with this --- libretroshare/src/pgp/pgpauxutils.cc | 8 --- libretroshare/src/pgp/pgpauxutils.h | 6 -- libretroshare/src/pqi/p3notify.cc | 8 --- libretroshare/src/pqi/p3notify.h | 1 - libretroshare/src/retroshare/rsnotify.h | 1 - libretroshare/src/services/p3idservice.cc | 20 +------ .../src/gui/Identity/IdEditDialog.cpp | 31 ++++++++-- retroshare-gui/src/gui/notifyqt.cpp | 58 ------------------- retroshare-gui/src/gui/notifyqt.h | 15 ----- retroshare-gui/src/main.cpp | 5 -- .../gxs/nxs_test/nxsdummyservices.cc | 9 --- .../gxs/nxs_test/nxsdummyservices.h | 1 - .../services/gxs/FakePgpAuxUtils.cc | 9 --- .../services/gxs/FakePgpAuxUtils.h | 1 - 14 files changed, 28 insertions(+), 145 deletions(-) diff --git a/libretroshare/src/pgp/pgpauxutils.cc b/libretroshare/src/pgp/pgpauxutils.cc index a6a592c2c..d7229e848 100644 --- a/libretroshare/src/pgp/pgpauxutils.cc +++ b/libretroshare/src/pgp/pgpauxutils.cc @@ -67,14 +67,6 @@ bool PgpAuxUtilsImpl::parseSignature(unsigned char *sign, unsigned int signlen, return AuthGPG::getAuthGPG()->parseSignature(sign,signlen,issuer); } -bool PgpAuxUtilsImpl::askForDeferredSelfSignature(const void *data, - const uint32_t len, - unsigned char *sign, - unsigned int *signlen, - int& signature_result , std::string reason) -{ - return RsServer::notify()->askForDeferredSelfSignature(data, len, sign, signlen, signature_result, reason); -} diff --git a/libretroshare/src/pgp/pgpauxutils.h b/libretroshare/src/pgp/pgpauxutils.h index 604a5d6e0..4b188e3ae 100644 --- a/libretroshare/src/pgp/pgpauxutils.h +++ b/libretroshare/src/pgp/pgpauxutils.h @@ -41,10 +41,6 @@ class PgpAuxUtils virtual bool parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const =0; virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint) = 0; - - /** @deprecated this method depends on retroshare-gui to work */ - RS_DEPRECATED_FOR("AuthGPG::SignDataBin") - virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason) = 0; }; class PgpAuxUtilsImpl: public PgpAuxUtils @@ -59,8 +55,6 @@ public: virtual bool getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const; virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint); virtual bool getGPGAllList(std::list &ids); - virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason); - }; diff --git a/libretroshare/src/pqi/p3notify.cc b/libretroshare/src/pqi/p3notify.cc index 7a5dc8c45..772a7e9bb 100644 --- a/libretroshare/src/pqi/p3notify.cc +++ b/libretroshare/src/pqi/p3notify.cc @@ -293,14 +293,6 @@ bool p3Notify::askForPluginConfirmation (const std::string& plugin_filen return false ; } -bool p3Notify::askForDeferredSelfSignature (const void * data , const uint32_t len , unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason /*=""*/) -{ - FOR_ALL_NOTIFY_CLIENTS - if( (*it)->askForDeferredSelfSignature(data,len,sign,signlen,signature_result, reason)) - return true ; - - return false ; -} void p3Notify::registerNotifyClient(NotifyClient *cl) { diff --git a/libretroshare/src/pqi/p3notify.h b/libretroshare/src/pqi/p3notify.h index 46fb69c8e..3d78cdf8c 100644 --- a/libretroshare/src/pqi/p3notify.h +++ b/libretroshare/src/pqi/p3notify.h @@ -114,7 +114,6 @@ class p3Notify: public RsNotify void notifyPeerStatusChangedSummary () ; void notifyDiscInfoChanged () ; - bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */, int& signature_result , std::string reason = "") ; void notifyDownloadComplete (const std::string& /* fileHash */) ; void notifyDownloadCompleteCount (uint32_t /* count */) ; void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) ; diff --git a/libretroshare/src/retroshare/rsnotify.h b/libretroshare/src/retroshare/rsnotify.h index d69357cdb..bc9ef2971 100644 --- a/libretroshare/src/retroshare/rsnotify.h +++ b/libretroshare/src/retroshare/rsnotify.h @@ -237,7 +237,6 @@ public: virtual void notifyPeerStatusChangedSummary () {} virtual void notifyDiscInfoChanged () {} - virtual bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */,int& signature_result , std::string /*reason = ""*/) { signature_result = false ;return true; } virtual void notifyDownloadComplete (const std::string& /* fileHash */) {} virtual void notifyDownloadCompleteCount (uint32_t /* count */) {} virtual void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) {} diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index fe0cba89f..b3e30d8ca 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -3522,25 +3522,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup( unsigned int sign_size = MAX_SIGN_SIZE; memset(signarray,0,MAX_SIGN_SIZE) ; // just in case. - /* -10 is never returned by askForDeferredSelfSignature therefore we can - * use it to properly detect and handle the case libretroshare is being - * used outside retroshare-gui */ - int result = -10; - - /* This method is DEPRECATED we call it only for retrocompatibility with - * retroshare-gui, when called from something different then - * retroshare-gui for example retroshare-service it miserably fail! */ - mPgpUtils->askForDeferredSelfSignature( - static_cast(hash.toByteArray()), - hash.SIZE_IN_BYTES, signarray, &sign_size, result, - __PRETTY_FUNCTION__ ); - - /* If askForDeferredSelfSignature left result untouched it means - * libretroshare is being used by something different then - * retroshare-gui so try calling AuthGPG::getAuthGPG()->SignDataBin - * directly */ - if( result == -10 ) - result = AuthGPG::getAuthGPG()->SignDataBin( + int result = AuthGPG::getAuthGPG()->SignDataBin( static_cast(hash.toByteArray()), hash.SIZE_IN_BYTES, signarray, &sign_size, __PRETTY_FUNCTION__ ) diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp index b55c3fa58..a015b73e2 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -28,6 +28,7 @@ #include "gui/gxs/GxsIdDetails.h" #include "util/qtthreadsutils.h" #include "util/misc.h" +#include "gui/notifyqt.h" #include #include @@ -539,18 +540,40 @@ void IdEditDialog::createId() params.mImage.clear(); RsGxsId keyId; + std::string gpg_password; - if(rsIdentity->createIdentity(keyId,params.nickname,params.mImage,!params.isPgpLinked)) + if(params.isPgpLinked) + { + std::string gpg_name = rsPeers->getGPGName(rsPeers->getGPGOwnId()); + bool cancelled; + + if(!NotifyQt::getInstance()->askForPassword(tr("Profile password needed.").toStdString(), + gpg_name + " (" + rsPeers->getOwnId().toStdString() + ")", + false, + gpg_password,cancelled)) + { + QMessageBox::critical(NULL,tr("Identity creation failed"),tr("Cannot create an identity linked to your profile without your profile password.")); + return; + } + + } + + if(rsIdentity->createIdentity(keyId,params.nickname,params.mImage,!params.isPgpLinked,gpg_password)) { ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); RsIdentityDetails det; - rsIdentity->getIdDetails(keyId,det); - setupExistingId((RsGxsGroupId)keyId); + if(rsIdentity->getIdDetails(keyId,det)) + { + QMessageBox::information(NULL,tr("Identity creation success"),tr("Your new identity was successfuly created.")); + close(); + } + else + QMessageBox::critical(NULL,tr("Identity creation failed"),tr("Cannot create identity. Something went wrong.")); } else - QMessageBox::critical(NULL,tr("Identity creation failed"),tr("Cannot create identity. Something went wrong.")); + QMessageBox::critical(NULL,tr("Identity creation failed"),tr("Cannot create identity. Something went wrong. Check your profile password.")); } #ifdef TO_REMOVE diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index a9bdd2705..6a4e11d68 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -199,51 +199,6 @@ class SignatureEventData std::string reason ; }; -bool NotifyQt::askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason /*=""*/) -{ - { - QMutexLocker m(&_mutex) ; - - std::cerr << "NotifyQt:: deferred signature event requeted. " << std::endl; - - // Look into the queue - - Sha1CheckSum chksum = RsDirUtil::sha1sum((uint8_t*)data,len) ; - - std::map::iterator it = _deferred_signature_queue.find(chksum.toStdString()) ; - signature_result = SELF_SIGNATURE_RESULT_PENDING ; - - if(it != _deferred_signature_queue.end()) - { - signature_result = it->second->signature_result ; - - if(it->second->signature_result != SELF_SIGNATURE_RESULT_PENDING) // found it. Copy the result, and remove from the queue. - { - // We should check for the exact data match, for the sake of being totally secure. - // - std::cerr << "Found into queue: returning it" << std::endl; - - memcpy(sign,it->second->sign,*it->second->signlen) ; - *signlen = *(it->second->signlen) ; - - delete it->second ; - _deferred_signature_queue.erase(it) ; - } - return true ; // already registered, but not done yet. - } - - // Not found. Store in the queue and emit a signal. - // - std::cerr << "NotifyQt:: deferred signature event requeted. Pushing into queue" << std::endl; - - SignatureEventData *edta = new SignatureEventData(data,len,*signlen, reason) ; - - _deferred_signature_queue[chksum.toStdString()] = edta ; - } - emit deferredSignatureHandlingRequested() ; - return true; -} - void NotifyQt::handleSignatureEvent() { std::cerr << "NotifyQt:: performing a deferred signature in the main GUI thread." << std::endl; @@ -780,19 +735,6 @@ void NotifyQt::notifyListPreChange(int list, int /*type*/) return; } - /* New Timer Based Update scheme ... - * means correct thread seperation - * - * uses Flags, to detect changes - */ - -void NotifyQt::resetCachedPassphrases() -{ - std::cerr << "Clearing PGP passphrase." << std::endl; - - rsNotify->clearPgpPassphrase() ; -} - void NotifyQt::enable() { QMutexLocker m(&_mutex) ; diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index 19bd20bba..1dbd56285 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -94,20 +94,6 @@ class NotifyQt: public QObject, public NotifyClient virtual bool askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad, std::string& password, bool &cancelled); virtual bool askForPluginConfirmation(const std::string& plugin_filename, const std::string& plugin_file_hash,bool first_time); - // Queues the signature event so that it canhappen in the main GUI thread (to ask for passwd). - // To use this function: call is multiple times as soon as it returns true. - // - // Dont' use a while, if you're in a mutexed part, otherwize it will lock. You need to call the function - // and periodically exit the locked code between calls to allow the signature to happen. - // - // Returns: - // false = the signature is registered, but the result is not there yet. Call again soon. - // true = signature done. Data is ready. signature_result takes the following values: - // 1: signature success - // 2: signature failed. Wrong passwd, user pressed cancel, etc. - // - virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, int& signature_result, std::string reason = "") ; - /* Notify from GUI */ void notifyChatFontChanged(); void notifyChatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType); @@ -176,7 +162,6 @@ class NotifyQt: public QObject, public NotifyClient public slots: void UpdateGUI(); /* called by timer */ void SetDisableAll(bool bValue); - void resetCachedPassphrases() ; private slots: void runningTick(); diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index f0130ac86..490878e57 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -580,11 +580,6 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO); #endif #endif // RS_JSONAPI - // This is done using a timer, because the passphrase request from notify is asynchrouneous and therefore clearing the - // passphrase here makes it request for a passphrase when creating the default chat identity. - - QTimer::singleShot(10000, notify, SLOT(resetCachedPassphrases())) ; - /* dive into the endless loop */ int ti = rshare.exec(); delete w ; diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.cc index c752c67c2..925e90be2 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.cc @@ -164,15 +164,6 @@ bool rs_nxs_test::RsDummyPgpUtils::VerifySignBin(const void* /*data*/, return true; } -bool rs_nxs_test::RsDummyPgpUtils::askForDeferredSelfSignature(const void* /*data*/, - const uint32_t /*len*/, - unsigned char* /*sign*/, - unsigned int* /*signlen*/, - int& /*signature_result*/, - std::string /*reason*/ - ) { - return true; -} diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.h b/tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.h index 56da81fcb..aee8f989e 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.h +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.h @@ -170,7 +170,6 @@ namespace rs_nxs_test bool parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const; bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint); - bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, int& signature_result , std::string reason = ""); private: diff --git a/tests/unittests/libretroshare/services/gxs/FakePgpAuxUtils.cc b/tests/unittests/libretroshare/services/gxs/FakePgpAuxUtils.cc index d24bcca4e..2d274897a 100644 --- a/tests/unittests/libretroshare/services/gxs/FakePgpAuxUtils.cc +++ b/tests/unittests/libretroshare/services/gxs/FakePgpAuxUtils.cc @@ -101,13 +101,4 @@ bool FakePgpAuxUtils::getGPGAllList(std::list &ids) return true; } -bool FakePgpAuxUtils::askForDeferredSelfSignature(const void* /*data*/, const uint32_t /*len*/, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string /*reason = ""*/ ) -{ - for(unsigned int i = 0; i < *signlen; i++) - { - sign[i] = 0; - } - signature_result = 1; - return true; -} diff --git a/tests/unittests/libretroshare/services/gxs/FakePgpAuxUtils.h b/tests/unittests/libretroshare/services/gxs/FakePgpAuxUtils.h index 0cb48dbff..63b20b85d 100644 --- a/tests/unittests/libretroshare/services/gxs/FakePgpAuxUtils.h +++ b/tests/unittests/libretroshare/services/gxs/FakePgpAuxUtils.h @@ -33,7 +33,6 @@ public: virtual bool parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const; virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint); - virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, int& signature_result , std::string reason); virtual void addPeerListToPgpList(const std::list &ids); virtual void addPeerIdToPgpList(const RsPeerId &id);