removed askForDeferredSelfSignature() and made IdEditDialog comply with this

This commit is contained in:
csoler 2020-04-02 22:24:14 +02:00
parent 0cc871da60
commit cd98f02246
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
14 changed files with 28 additions and 145 deletions

View File

@ -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);
}

View File

@ -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<RsPgpId> &ids);
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason);
};

View File

@ -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)
{

View File

@ -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 */) ;

View File

@ -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 */) {}

View File

@ -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<const void*>(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<const void*>(hash.toByteArray()),
hash.SIZE_IN_BYTES, signarray, &sign_size,
__PRETTY_FUNCTION__ )

View File

@ -28,6 +28,7 @@
#include "gui/gxs/GxsIdDetails.h"
#include "util/qtthreadsutils.h"
#include "util/misc.h"
#include "gui/notifyqt.h"
#include <retroshare/rsidentity.h>
#include <retroshare/rspeers.h>
@ -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. Check your profile password."));
}
#ifdef TO_REMOVE

View File

@ -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<std::string,SignatureEventData*>::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) ;

View File

@ -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();

View File

@ -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 ;

View File

@ -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;
}

View File

@ -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:

View File

@ -101,13 +101,4 @@ bool FakePgpAuxUtils::getGPGAllList(std::list<RsPgpId> &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;
}

View File

@ -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<RsPeerId> &ids);
virtual void addPeerIdToPgpList(const RsPeerId &id);