moved pgp passphrase handling to RsLoginHandler and removed irrelevant notify handles

This commit is contained in:
csoler 2025-09-27 18:59:28 +02:00
parent 5592c667ae
commit 670475b67d
7 changed files with 40 additions and 30 deletions

View file

@ -656,7 +656,7 @@ void GenCertDialog::genPerson()
// Normally we should clear the cached passphrase as soon as possible. However,some other GUI components may still need it at start.
// (csoler) This is really bad: we have to guess that 30 secs will be enough. I have no better way to do this.
QTimer::singleShot(30000, []() { rsNotify->clearPgpPassphrase(); } );
QTimer::singleShot(30000, []() { RsLoginHelper::clearPgpPassphrase(); } );
accept();
}
@ -664,7 +664,7 @@ void GenCertDialog::genPerson()
else
{
// Now clear the cached passphrase
rsNotify->clearPgpPassphrase();
RsLoginHelper::clearPgpPassphrase();
/* Message Dialog */
QMessageBox::warning(this,

View file

@ -33,6 +33,7 @@
#include "retroshare/rsidentity.h"
#include "retroshare/rspeers.h"
#include "retroshare/rsinit.h"
#include "gui/common/FilesDefs.h"
#include "util/imageutil.h"
#include "util/RsQtVersion.h"
@ -596,9 +597,9 @@ void IdEditDialog::createId()
std::string gpg_name = rsPeers->getGPGName(rsPeers->getGPGOwnId());
bool cancelled;
rsNotify->clearPgpPassphrase(); // just in case
RsLoginHelper::clearPgpPassphrase(); // just in case
if(!NotifyQt::getInstance()->askForPassword(tr("Profile password needed.").toStdString(),
if(!RsLoginHelper::askForPassword(tr("Profile password needed.").toStdString(),
gpg_name + " (" + rsPeers->getOwnId().toStdString() + ")",
false,
gpg_password,cancelled))
@ -670,9 +671,9 @@ void IdEditDialog::updateId()
std::string gpg_name = rsPeers->getGPGName(rsPeers->getGPGOwnId());
bool cancelled;
rsNotify->clearPgpPassphrase(); // just in case
RsLoginHelper::clearPgpPassphrase(); // just in case
if(!NotifyQt::getInstance()->askForPassword(tr("Profile password needed.").toStdString(),
if(!RsLoginHelper::askForPassword(tr("Profile password needed.").toStdString(),
gpg_name + " (" + rsPeers->getOwnId().toStdString() + ")",
false,
gpg_password,cancelled))

View file

@ -119,13 +119,11 @@ void StartDialog::loadPerson()
RsPeerId accountId = RsPeerId((data.toString()).toStdString());
// Cache the passphrase, so that it is not asked again.
rsNotify->cachePgpPassphrase(ui.password_input->text().toUtf8().constData()) ;
rsNotify->setDisableAskPassword(true);
RsLoginHelper::cachePgpPassphrase(ui.password_input->text().toUtf8().constData()) ;
bool res = RsApplication::loadCertificate(accountId, ui.autologin_checkbox->isChecked()) ;
rsNotify->setDisableAskPassword(false);
rsNotify->clearPgpPassphrase();
RsLoginHelper::clearPgpPassphrase();
if(res)
accept();

View file

@ -46,6 +46,7 @@
#include "gui/msgs/MessageComposer.h"
#include <retroshare/rsiface.h>
#include <retroshare/rsinit.h>
#include <retroshare/rsbanlist.h>
#include <retroshare/rsconfig.h>
@ -767,7 +768,7 @@ void ConnectFriendWizard::accept()
bool cancelled;
std::string pgp_password;
if(!NotifyQt::getInstance()->askForPassword(tr("Profile password needed.").toStdString(), pgp_name + " (" + rsPeers->getOwnId().toStdString() + ")", prev_is_bad, pgp_password,cancelled))
if(!RsLoginHelper::askForPassword(tr("Profile password needed.").toStdString(), pgp_name + " (" + rsPeers->getOwnId().toStdString() + ")", prev_is_bad, pgp_password,cancelled))
{
QMessageBox::critical(NULL,tr("Identity creation failed"),tr("Cannot create an identity linked to your profile without your profile password."));
return;

View file

@ -32,6 +32,7 @@
#include <retroshare/rspeers.h>
#include <retroshare/rsdisc.h>
#include <retroshare/rsmsgs.h>
#include <retroshare/rsinit.h>
#include <retroshare-gui/mainpage.h>
@ -364,13 +365,13 @@ void PGPKeyDialog::signGPGKey()
bool cancelled;
std::string gpg_password;
if(!NotifyQt::getInstance()->askForPassword(tr("Profile password needed.").toStdString(), gpg_name + " (" + rsPeers->getOwnId().toStdString() + ")", false, gpg_password,cancelled))
if(!RsLoginHelper::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;
}
rsNotify->clearPgpPassphrase(); // just in case
RsLoginHelper::clearPgpPassphrase(); // just in case
if(!rsPeers->signGPGCertificate(pgpId,gpg_password))
QMessageBox::warning ( NULL, tr("Signature Failure"), tr("Check the password!"), QMessageBox::Ok);

View file

@ -26,6 +26,7 @@
#include <retroshare/rspeers.h>
#include <retroshare/rsidentity.h>
#include <retroshare/rsmsgs.h>
#include <retroshare/rsinit.h>
#include <util/rsdir.h>
#include <util/qtthreadsutils.h>
@ -231,27 +232,25 @@ void NotifyQt::handleSignatureEvent()
}
}
bool NotifyQt::askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad, std::string& password,bool& cancelled)
bool NotifyQt::graphical_askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad, std::string& password,bool& cancelled)
{
RsAutoUpdatePage::lockAllEvents() ;
QString windowTitle;
if (title == "") {
if (title == "")
windowTitle = tr("Passphrase required");
} else if (title == "AuthSSLimpl::SignX509ReqWithGPG()") {
else if (title == "AuthSSLimpl::SignX509ReqWithGPG()")
windowTitle = tr("You need to sign your node's certificate.");
} else if (title == "p3IdService::service_CreateGroup()") {
else if (title == "p3IdService::service_CreateGroup()")
windowTitle = tr("You need to sign your forum/chatrooms identity.");
} else {
else
windowTitle = QString::fromStdString(title);
}
QString labelText = ( prev_is_bad ? QString("%1<br/><br/>").arg(tr("Wrong password !")) : QString() )
+ QString("<b>%1</b><br/>Profile: <i>%2</i>\n")
.arg( tr("Please enter your Retroshare passphrase")
, QString::fromUtf8(key_details.c_str()) );
QLineEdit::EchoMode textEchoMode = QLineEdit::Password;
bool modal = true;
@ -267,12 +266,12 @@ bool NotifyQt::askForPassword(const std::string& title, const std::string& key_d
, Q_ARG(QLineEdit::EchoMode, textEchoMode)
, Q_ARG(bool, modal)
);
cancelled = false ;
RsAutoUpdatePage::unlockAllEvents() ;
if (ret.execReturn == QDialog::Rejected) {
RsLoginHelper::clearPgpPassphrase();
password.clear() ;
cancelled = true ;
return true ;
@ -280,10 +279,12 @@ bool NotifyQt::askForPassword(const std::string& title, const std::string& key_d
if (ret.execReturn == QDialog::Accepted) {
password = ret.textValue.toUtf8().constData();
return true;
RsLoginHelper::cachePgpPassphrase(password);
return true;
}
return false;
RsLoginHelper::clearPgpPassphrase();
return false;
}
bool NotifyQt::askForPluginConfirmation(const std::string& plugin_file_name, const std::string& plugin_file_hash, bool first_time)
{
@ -835,25 +836,33 @@ void NotifyQt::handleIncomingEvent(std::shared_ptr<const RsEvent> event)
return;
}
auto ev6 = dynamic_cast<const RsSystemErrorEvent*>(event.get());
auto ev6 = dynamic_cast<const RsSystemEvent*>(event.get());
if(ev6)
{
switch(ev6->mEventCode)
{
case RsSystemErrorEventCode::TIME_SHIFT_PROBLEM:
case RsSystemEventCode::TIME_SHIFT_PROBLEM:
displayErrorMessage(RS_SYS_WARNING,tr("System time mismatch"),tr("Time shift problem notification. Make sure your machine is on time, because it will break chat rooms."));
break;
case RsSystemErrorEventCode::DISK_SPACE_ERROR:
case RsSystemEventCode::DISK_SPACE_ERROR:
displayDiskSpaceWarning(ev6->mDiskErrorLocation,ev6->mDiskErrorSizeLimit);
break;
case RsSystemErrorEventCode::DATA_STREAMING_ERROR:
case RsSystemErrorEventCode::GENERAL_ERROR:
case RsSystemEventCode::DATA_STREAMING_ERROR:
case RsSystemEventCode::GENERAL_ERROR:
displayErrorMessage(RS_SYS_WARNING,tr("Internal error"),QString::fromUtf8(ev6->mErrorMsg.c_str()));
break;
case RsSystemEventCode::PASSWORD_REQUESTED:
{
std::string password;
bool cancelled;
graphical_askForPassword(ev6->passwd_request_title, ev6->passwd_request_key_details, ev6->passwd_request_prev_is_bad, password,cancelled);
break;
}
default: break;
}
return;

View file

@ -86,7 +86,7 @@ class NotifyQt: public QObject, public NotifyClient
// virtual void notifyHistoryChanged(uint32_t msgId, int type);
// virtual void notifyDiscInfoChanged() ;
virtual bool askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad, std::string& password, bool &cancelled);
virtual bool graphical_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);
/* Notify from GUI */