From 116c7f1aec9190b7d16a0f90dd173ac6f63e005c Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 30 Sep 2025 21:03:02 +0200 Subject: [PATCH] fixed passwd handling in retroshare-service --- retroshare-gui/src/gui/notifyqt.cpp | 36 ++++++++++---------- retroshare-gui/src/gui/notifyqt.h | 9 ++--- retroshare-gui/src/main.cpp | 4 +-- retroshare-service/src/retroshare-service.cc | 31 +++++++++++++++-- 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index c1d9b441e..606fa5178 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -112,7 +112,7 @@ NotifyQt::NotifyQt() : cDialog(NULL) mEventHandlerId = 0; rsEvents->registerEventsHandler( [this](std::shared_ptr event) { - if(event->mType == RsEventType::SYSTEM_ERROR && dynamic_cast(event.get())->mEventCode == RsSystemEventCode::PASSWORD_REQUESTED) + if(event->mType == RsEventType::SYSTEM && dynamic_cast(event.get())->mEventCode == RsSystemEventCode::PASSWORD_REQUESTED) sync_handleIncomingEvent(event); else RsQThreadUtils::postToObject([=](){ async_handleIncomingEvent(event); }, this ); @@ -165,7 +165,6 @@ void NotifyQt::notifyOwnAvatarChanged() #endif emit ownAvatarChanged() ; } -#endif class SignatureEventData { @@ -237,8 +236,9 @@ void NotifyQt::handleSignatureEvent() working = false ; } } +#endif -bool NotifyQt::graphical_askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad, std::string& password,bool& cancelled) +bool NotifyQt::GUI_askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad) { RsAutoUpdatePage::lockAllEvents() ; @@ -272,19 +272,18 @@ bool NotifyQt::graphical_askForPassword(const std::string& title, const std::str , Q_ARG(QLineEdit::EchoMode, textEchoMode) , Q_ARG(bool, modal) ); - cancelled = false ; + //cancelled = false ; RsAutoUpdatePage::unlockAllEvents() ; if (ret.execReturn == QDialog::Rejected) { RsLoginHelper::clearPgpPassphrase(); - password.clear() ; - cancelled = true ; + //cancelled = true ; return true ; } if (ret.execReturn == QDialog::Accepted) { - password = ret.textValue.toUtf8().constData(); + auto password = ret.textValue.toUtf8().constData(); RsLoginHelper::cachePgpPassphrase(password); return true; } @@ -292,7 +291,7 @@ bool NotifyQt::graphical_askForPassword(const std::string& title, const std::str RsLoginHelper::clearPgpPassphrase(); return false; } -bool NotifyQt::askForPluginConfirmation(const std::string& plugin_file_name, const std::string& plugin_file_hash, bool first_time) +bool NotifyQt::GUI_askForPluginConfirmation(const std::string& plugin_file_name, const RsFileHash& plugin_file_hash, bool first_time) { // By default, when no information is known about plugins, just dont load them. They will be enabled from the GUI by the user. @@ -307,7 +306,7 @@ bool NotifyQt::askForPluginConfirmation(const std::string& plugin_file_name, con QString text ; text += tr( "RetroShare has detected an unregistered plugin. This happens in two cases:
  • Your RetroShare executable has changed.
  • The plugin has changed
Click on Yes to authorize this plugin, or No to deny it. You can change your mind later in Options -> Plugins, then restart." ) ; text += "
    " ; - text += "
  • Hash:\t" + QString::fromStdString(plugin_file_hash) + "
  • " ; + text += "
  • Hash:\t" + QString::fromStdString(plugin_file_hash.toStdString()) + "
  • " ; text += "
  • File:\t" + QString::fromStdString(plugin_file_name) + "
  • "; text += "
" ; @@ -319,10 +318,13 @@ bool NotifyQt::askForPluginConfirmation(const std::string& plugin_file_name, con RsAutoUpdatePage::unlockAllEvents() ; - if (ret == QMessageBox::Yes) - return true ; - else - return false; + if (ret == QMessageBox::Yes) + return true; + else + { + rsPlugins->disablePlugin(plugin_file_hash); + return false; + } } #ifdef TO_REMOVE @@ -694,11 +696,9 @@ void NotifyQt::sync_handleIncomingEvent(std::shared_ptr event) auto ev6 = dynamic_cast(event.get()); if(ev6->mEventCode == 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); - } + GUI_askForPassword(ev6->passwd_request_title, ev6->passwd_request_key_details, ev6->passwd_request_prev_is_bad); + else if(ev6->mEventCode == RsSystemEventCode::NEW_PLUGIN_FOUND) + GUI_askForPluginConfirmation(ev6->plugin_file_name, ev6->plugin_file_hash, ev6->plugin_first_time); } void NotifyQt::async_handleIncomingEvent(std::shared_ptr event) diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index a669864c6..042fd7ef9 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -47,7 +47,7 @@ class SignatureEventData ; struct TurtleFileInfo; struct TurtleGxsInfo; -class NotifyQt: public QObject, public NotifyClient +class NotifyQt: public QObject { Q_OBJECT public: @@ -86,8 +86,9 @@ class NotifyQt: public QObject, public NotifyClient // virtual void notifyHistoryChanged(uint32_t msgId, int type); // virtual void notifyDiscInfoChanged() ; - 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); + + virtual bool GUI_askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad); + virtual bool GUI_askForPluginConfirmation(const std::string& plugin_filename, const RsFileHash& plugin_file_hash,bool first_time); /* Notify from GUI */ void notifyChatFontChanged(); @@ -146,7 +147,7 @@ class NotifyQt: public QObject, public NotifyClient private slots: void runningTick(); - void handleSignatureEvent() ; +// void handleSignatureEvent() ; // void handleChatLobbyTimeShift(int) ; private: diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 022ae227c..031c917b3 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -346,8 +346,8 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO); // RsControl::earlyInitNotificationSystem() ; - NotifyQt *notify = NotifyQt::Create(); - rsNotify->registerNotifyClient(notify); + //NotifyQt *notify = NotifyQt::Create(); + //rsNotify->registerNotifyClient(notify); /* RetroShare Core Objects */ RsInit::InitRsConfig(); diff --git a/retroshare-service/src/retroshare-service.cc b/retroshare-service/src/retroshare-service.cc index ac82593da..4ca2c8a7a 100644 --- a/retroshare-service/src/retroshare-service.cc +++ b/retroshare-service/src/retroshare-service.cc @@ -71,7 +71,29 @@ std::string colored(int color,const std::string& s) } } +static void eventHandler(std::shared_ptr e) +{ + auto fe = dynamic_cast(e.get()); + + if(!fe) + return; + #ifdef RS_SERVICE_TERMINAL_LOGIN + if(fe->mEventCode == RsSystemEventCode::PASSWORD_REQUESTED) + { + std::string question1 = fe->passwd_request_title + colored(COLOR_GREEN,"Please enter your PGP password for key:\n ") + fe->passwd_request_key_details + " :"; + std::string password = RsUtil::rs_getpass(question1.c_str()) ; + + if(!password.empty()) + RsLoginHelper::cachePgpPassphrase(password); + } +#endif + + // We should also handle plugin loading +} + + +#ifdef TO_REMOVE class RsServiceNotify: public NotifyClient { public: @@ -86,7 +108,7 @@ public: password = RsUtil::rs_getpass(question1.c_str()) ; cancel = false ; - return !password.empty(); + return !password.empty(); } }; #endif // def RS_SERVICE_TERMINAL_LOGIN @@ -149,6 +171,9 @@ int main(int argc, char* argv[]) RsInit::InitRsConfig(); RsControl::earlyInitNotificationSystem(); + RsEventsHandlerId_t EventHandlerId = 0; + rsEvents->registerEventsHandler(eventHandler,EventHandlerId, RsEventType::SYSTEM); + #ifdef __APPLE__ // TODO: is this still needed with argstream? /* HACK to avoid stupid OSX Finder behaviour @@ -330,8 +355,8 @@ int main(int argc, char* argv[]) return -EINVAL; } - RsServiceNotify* notify = new RsServiceNotify(); - rsNotify->registerNotifyClient(notify); + //RsServiceNotify* notify = new RsServiceNotify(); + //rsNotify->registerNotifyClient(notify); // supply empty passwd so that it is properly asked 3 times on console RsInit::LoadCertificateStatus result = rsLoginHelper->attemptLogin(ssl_id, "");