fixed passwd handling in retroshare-service

This commit is contained in:
csoler 2025-09-30 21:03:02 +02:00
parent 3f21b4bf65
commit 116c7f1aec
4 changed files with 53 additions and 27 deletions

View file

@ -112,7 +112,7 @@ NotifyQt::NotifyQt() : cDialog(NULL)
mEventHandlerId = 0; mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
{ {
if(event->mType == RsEventType::SYSTEM_ERROR && dynamic_cast<const RsSystemEvent*>(event.get())->mEventCode == RsSystemEventCode::PASSWORD_REQUESTED) if(event->mType == RsEventType::SYSTEM && dynamic_cast<const RsSystemEvent*>(event.get())->mEventCode == RsSystemEventCode::PASSWORD_REQUESTED)
sync_handleIncomingEvent(event); sync_handleIncomingEvent(event);
else else
RsQThreadUtils::postToObject([=](){ async_handleIncomingEvent(event); }, this ); RsQThreadUtils::postToObject([=](){ async_handleIncomingEvent(event); }, this );
@ -165,7 +165,6 @@ void NotifyQt::notifyOwnAvatarChanged()
#endif #endif
emit ownAvatarChanged() ; emit ownAvatarChanged() ;
} }
#endif
class SignatureEventData class SignatureEventData
{ {
@ -237,8 +236,9 @@ void NotifyQt::handleSignatureEvent()
working = false ; 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() ; RsAutoUpdatePage::lockAllEvents() ;
@ -272,19 +272,18 @@ bool NotifyQt::graphical_askForPassword(const std::string& title, const std::str
, Q_ARG(QLineEdit::EchoMode, textEchoMode) , Q_ARG(QLineEdit::EchoMode, textEchoMode)
, Q_ARG(bool, modal) , Q_ARG(bool, modal)
); );
cancelled = false ; //cancelled = false ;
RsAutoUpdatePage::unlockAllEvents() ; RsAutoUpdatePage::unlockAllEvents() ;
if (ret.execReturn == QDialog::Rejected) { if (ret.execReturn == QDialog::Rejected) {
RsLoginHelper::clearPgpPassphrase(); RsLoginHelper::clearPgpPassphrase();
password.clear() ; //cancelled = true ;
cancelled = true ;
return true ; return true ;
} }
if (ret.execReturn == QDialog::Accepted) { if (ret.execReturn == QDialog::Accepted) {
password = ret.textValue.toUtf8().constData(); auto password = ret.textValue.toUtf8().constData();
RsLoginHelper::cachePgpPassphrase(password); RsLoginHelper::cachePgpPassphrase(password);
return true; return true;
} }
@ -292,7 +291,7 @@ bool NotifyQt::graphical_askForPassword(const std::string& title, const std::str
RsLoginHelper::clearPgpPassphrase(); RsLoginHelper::clearPgpPassphrase();
return false; 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. // 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 ; QString text ;
text += tr( "RetroShare has detected an unregistered plugin. This happens in two cases:<UL><LI>Your RetroShare executable has changed.</LI><LI>The plugin has changed</LI></UL>Click on Yes to authorize this plugin, or No to deny it. You can change your mind later in Options -> Plugins, then restart." ) ; text += tr( "RetroShare has detected an unregistered plugin. This happens in two cases:<UL><LI>Your RetroShare executable has changed.</LI><LI>The plugin has changed</LI></UL>Click on Yes to authorize this plugin, or No to deny it. You can change your mind later in Options -> Plugins, then restart." ) ;
text += "<UL>" ; text += "<UL>" ;
text += "<LI>Hash:\t" + QString::fromStdString(plugin_file_hash) + "</LI>" ; text += "<LI>Hash:\t" + QString::fromStdString(plugin_file_hash.toStdString()) + "</LI>" ;
text += "<LI>File:\t" + QString::fromStdString(plugin_file_name) + "</LI>"; text += "<LI>File:\t" + QString::fromStdString(plugin_file_name) + "</LI>";
text += "</UL>" ; text += "</UL>" ;
@ -319,10 +318,13 @@ bool NotifyQt::askForPluginConfirmation(const std::string& plugin_file_name, con
RsAutoUpdatePage::unlockAllEvents() ; RsAutoUpdatePage::unlockAllEvents() ;
if (ret == QMessageBox::Yes) if (ret == QMessageBox::Yes)
return true ; return true;
else else
return false; {
rsPlugins->disablePlugin(plugin_file_hash);
return false;
}
} }
#ifdef TO_REMOVE #ifdef TO_REMOVE
@ -694,11 +696,9 @@ void NotifyQt::sync_handleIncomingEvent(std::shared_ptr<const RsEvent> event)
auto ev6 = dynamic_cast<const RsSystemEvent*>(event.get()); auto ev6 = dynamic_cast<const RsSystemEvent*>(event.get());
if(ev6->mEventCode == RsSystemEventCode::PASSWORD_REQUESTED) if(ev6->mEventCode == RsSystemEventCode::PASSWORD_REQUESTED)
{ GUI_askForPassword(ev6->passwd_request_title, ev6->passwd_request_key_details, ev6->passwd_request_prev_is_bad);
std::string password; else if(ev6->mEventCode == RsSystemEventCode::NEW_PLUGIN_FOUND)
bool cancelled; GUI_askForPluginConfirmation(ev6->plugin_file_name, ev6->plugin_file_hash, ev6->plugin_first_time);
graphical_askForPassword(ev6->passwd_request_title, ev6->passwd_request_key_details, ev6->passwd_request_prev_is_bad, password,cancelled);
}
} }
void NotifyQt::async_handleIncomingEvent(std::shared_ptr<const RsEvent> event) void NotifyQt::async_handleIncomingEvent(std::shared_ptr<const RsEvent> event)

View file

@ -47,7 +47,7 @@ class SignatureEventData ;
struct TurtleFileInfo; struct TurtleFileInfo;
struct TurtleGxsInfo; struct TurtleGxsInfo;
class NotifyQt: public QObject, public NotifyClient class NotifyQt: public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -86,8 +86,9 @@ class NotifyQt: public QObject, public NotifyClient
// virtual void notifyHistoryChanged(uint32_t msgId, int type); // virtual void notifyHistoryChanged(uint32_t msgId, int type);
// virtual void notifyDiscInfoChanged() ; // 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 */ /* Notify from GUI */
void notifyChatFontChanged(); void notifyChatFontChanged();
@ -146,7 +147,7 @@ class NotifyQt: public QObject, public NotifyClient
private slots: private slots:
void runningTick(); void runningTick();
void handleSignatureEvent() ; // void handleSignatureEvent() ;
// void handleChatLobbyTimeShift(int) ; // void handleChatLobbyTimeShift(int) ;
private: private:

View file

@ -346,8 +346,8 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
// //
RsControl::earlyInitNotificationSystem() ; RsControl::earlyInitNotificationSystem() ;
NotifyQt *notify = NotifyQt::Create(); //NotifyQt *notify = NotifyQt::Create();
rsNotify->registerNotifyClient(notify); //rsNotify->registerNotifyClient(notify);
/* RetroShare Core Objects */ /* RetroShare Core Objects */
RsInit::InitRsConfig(); RsInit::InitRsConfig();

View file

@ -71,7 +71,29 @@ std::string colored(int color,const std::string& s)
} }
} }
static void eventHandler(std::shared_ptr<const RsEvent> e)
{
auto fe = dynamic_cast<const RsSystemEvent*>(e.get());
if(!fe)
return;
#ifdef RS_SERVICE_TERMINAL_LOGIN #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 class RsServiceNotify: public NotifyClient
{ {
public: public:
@ -86,7 +108,7 @@ public:
password = RsUtil::rs_getpass(question1.c_str()) ; password = RsUtil::rs_getpass(question1.c_str()) ;
cancel = false ; cancel = false ;
return !password.empty(); return !password.empty();
} }
}; };
#endif // def RS_SERVICE_TERMINAL_LOGIN #endif // def RS_SERVICE_TERMINAL_LOGIN
@ -149,6 +171,9 @@ int main(int argc, char* argv[])
RsInit::InitRsConfig(); RsInit::InitRsConfig();
RsControl::earlyInitNotificationSystem(); RsControl::earlyInitNotificationSystem();
RsEventsHandlerId_t EventHandlerId = 0;
rsEvents->registerEventsHandler(eventHandler,EventHandlerId, RsEventType::SYSTEM);
#ifdef __APPLE__ #ifdef __APPLE__
// TODO: is this still needed with argstream? // TODO: is this still needed with argstream?
/* HACK to avoid stupid OSX Finder behaviour /* HACK to avoid stupid OSX Finder behaviour
@ -330,8 +355,8 @@ int main(int argc, char* argv[])
return -EINVAL; return -EINVAL;
} }
RsServiceNotify* notify = new RsServiceNotify(); //RsServiceNotify* notify = new RsServiceNotify();
rsNotify->registerNotifyClient(notify); //rsNotify->registerNotifyClient(notify);
// supply empty passwd so that it is properly asked 3 times on console // supply empty passwd so that it is properly asked 3 times on console
RsInit::LoadCertificateStatus result = rsLoginHelper->attemptLogin(ssl_id, ""); RsInit::LoadCertificateStatus result = rsLoginHelper->attemptLogin(ssl_id, "");