From 670475b67d44f6b4f8e95c5585cf03dae0c76318 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 27 Sep 2025 18:59:28 +0200 Subject: [PATCH] moved pgp passphrase handling to RsLoginHandler and removed irrelevant notify handles --- retroshare-gui/src/gui/GenCertDialog.cpp | 4 +- .../src/gui/Identity/IdEditDialog.cpp | 9 ++-- retroshare-gui/src/gui/StartDialog.cpp | 6 +-- .../src/gui/connect/ConnectFriendWizard.cpp | 3 +- .../src/gui/connect/PGPKeyDialog.cpp | 5 ++- retroshare-gui/src/gui/notifyqt.cpp | 41 +++++++++++-------- retroshare-gui/src/gui/notifyqt.h | 2 +- 7 files changed, 40 insertions(+), 30 deletions(-) diff --git a/retroshare-gui/src/gui/GenCertDialog.cpp b/retroshare-gui/src/gui/GenCertDialog.cpp index 7f836be89..3fe5321d3 100644 --- a/retroshare-gui/src/gui/GenCertDialog.cpp +++ b/retroshare-gui/src/gui/GenCertDialog.cpp @@ -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, diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp index f22bf238e..6e3b015b0 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -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)) diff --git a/retroshare-gui/src/gui/StartDialog.cpp b/retroshare-gui/src/gui/StartDialog.cpp index e53af6455..4f71b102f 100644 --- a/retroshare-gui/src/gui/StartDialog.cpp +++ b/retroshare-gui/src/gui/StartDialog.cpp @@ -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(); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 4b5d9d314..dcc1bb5ea 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -46,6 +46,7 @@ #include "gui/msgs/MessageComposer.h" #include +#include #include #include @@ -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; diff --git a/retroshare-gui/src/gui/connect/PGPKeyDialog.cpp b/retroshare-gui/src/gui/connect/PGPKeyDialog.cpp index 36b6057b4..3277dff30 100644 --- a/retroshare-gui/src/gui/connect/PGPKeyDialog.cpp +++ b/retroshare-gui/src/gui/connect/PGPKeyDialog.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -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); diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index 1a365cb65..26d6f3890 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -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

").arg(tr("Wrong password !")) : QString() ) + QString("%1
Profile: %2\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 event) return; } - auto ev6 = dynamic_cast(event.get()); + auto ev6 = dynamic_cast(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; diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index 5871c510a..4843c55dc 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -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 */