added pgp passphrase temporary caching in order to avoid re-asking for password at location creation time

This commit is contained in:
csoler 2017-02-12 15:27:13 +01:00
parent f3824f2348
commit ccacba797f
5 changed files with 45 additions and 1 deletions

View File

@ -245,8 +245,37 @@ void p3Notify::notifyDownloadComplete (const std::string& fileHash )
void p3Notify::notifyDownloadCompleteCount (uint32_t count ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadCompleteCount (count) ; }
void p3Notify::notifyHistoryChanged (uint32_t msgId , int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHistoryChanged (msgId,type) ; }
bool p3Notify::cachePgpPassphrase(const std::string& s)
{
clearPgpPassphrase() ;
cached_pgp_passphrase = s ;
std::cerr << "(WW) Caching PGP passphrase." << std::endl;
return true ;
}
bool p3Notify::clearPgpPassphrase()
{
std::cerr << "(WW) Clearing PGP passphrase." << std::endl;
// Just whipe out the memory instead of just releasing it.
for(uint32_t i=0;i<cached_pgp_passphrase.length();++i)
cached_pgp_passphrase[i] = 0 ;
cached_pgp_passphrase.clear();
return true ;
}
bool p3Notify::askForPassword (const std::string& title , const std::string& key_details , bool prev_is_bad , std::string& password,bool *cancelled)
{
if(!prev_is_bad && !cached_pgp_passphrase.empty())
{
password = cached_pgp_passphrase ;
if(cancelled)
*cancelled = false ;
return true ;
}
FOR_ALL_NOTIFY_CLIENTS
if( (*it)->askForPassword(title,key_details,prev_is_bad,password,*cancelled))
return true ;

View File

@ -124,6 +124,9 @@ class p3Notify: public RsNotify
bool askForPassword (const std::string& title, const std::string& /* key_details */, bool /* prev_is_bad */, std::string&, bool *cancelled /* password */ ) ;
bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */) ;
virtual bool cachePgpPassphrase (const std::string& /* pgp_passphrase */) ;
virtual bool clearPgpPassphrase () ;
private:
RsMutex noteMtx;
@ -134,6 +137,8 @@ class p3Notify: public RsNotify
std::list<RsFeedItem> pendingNewsFeed;
std::list<NotifyClient*> notifyClients ;
std::string cached_pgp_passphrase ;
};

View File

@ -199,6 +199,9 @@ class RsNotify
virtual bool NotifyLogMessage(uint32_t &sysid, uint32_t &type, std::string &title, std::string &msg) = 0;
virtual bool GetFeedItem(RsFeedItem &item) = 0;
virtual bool cachePgpPassphrase (const std::string& /* pgp_passphrase */) { return false ; }
virtual bool clearPgpPassphrase () { return false ; }
};
class NotifyClient

View File

@ -36,6 +36,7 @@
#include <retroshare/rsidentity.h>
#include <retroshare/rsinit.h>
#include <retroshare/rsnotify.h>
#include <rsserver/rsaccounts.h>
#include <util/rsrandom.h>
@ -469,6 +470,10 @@ void GenCertDialog::genPerson()
err_string);
setCursor(Qt::ArrowCursor) ;
// now cache the PGP password so that it's not asked again for immediately signing the key
rsNotify->cachePgpPassphrase(ui.password_input->text().toUtf8().constData()) ;
}
//generate a random ssl password
@ -484,6 +489,8 @@ void GenCertDialog::genPerson()
std::cout << "RsAccounts::GenerateSSLCertificate" << std::endl;
bool okGen = RsAccounts::GenerateSSLCertificate(PGPId, "", genLoc, "", isHiddenLoc, sslPasswd, sslId, err);
rsNotify->clearPgpPassphrase() ;
if (okGen)
{
/* complete the process */

View File

@ -278,7 +278,7 @@ bool NotifyQt::askForPassword(const std::string& title, const std::string& key_d
dialog.setWindowTitle(QString::fromStdString(title));
}
dialog.setLabelText((prev_is_bad ? QString("%1\n\n").arg(tr("Wrong password !")) : QString()) + QString("%1:\n %2").arg(tr("Please enter your PGP password for key"), QString::fromUtf8(key_details.c_str())));
dialog.setLabelText((prev_is_bad ? QString("%1\n\n").arg(tr("Wrong password !")) : QString()) + QString("%1:\n\n (%2)\n\n").arg(tr("Please enter your Retroshare password"), QString::fromUtf8(key_details.c_str())));
dialog.setTextEchoMode(QLineEdit::Password);
dialog.setModal(true);