diff --git a/krfb/invitationsrfbserver.h b/krfb/invitationsrfbserver.h --- a/krfb/invitationsrfbserver.h +++ b/krfb/invitationsrfbserver.h @@ -50,6 +50,8 @@ bool start() override; void stop() override; void toggleUnattendedAccess(bool allow); + void openKWallet(); + void closeKWallet(); protected: InvitationsRfbServer(); diff --git a/krfb/invitationsrfbserver.cpp b/krfb/invitationsrfbserver.cpp --- a/krfb/invitationsrfbserver.cpp +++ b/krfb/invitationsrfbserver.cpp @@ -53,16 +53,11 @@ instance->setListeningPort(KrfbConfig::port()); instance->setPasswordRequired(true); + instance->m_wallet = nullptr; if (KrfbConfig::noWallet()) { - instance->walletOpened(false); - } - else { - instance->m_wallet = Wallet::openWallet( - Wallet::NetworkWallet(), 0, Wallet::Asynchronous); - if(instance->m_wallet) { - connect(instance->m_wallet, &KWallet::Wallet::walletOpened, - instance, &InvitationsRfbServer::walletOpened); - } + instance->walletOpened(false); + } else { + instance->openKWallet(); } } @@ -125,19 +120,12 @@ InvitationsRfbServer::~InvitationsRfbServer() { stop(); - KConfigGroup krfbConfig(KSharedConfig::openConfig(),"Security"); - krfbConfig.writeEntry("allowUnattendedAccess",m_allowUnattendedAccess); - if(!KrfbConfig::noWallet()) { - if (m_wallet && m_wallet->isOpen()) { - if( (m_wallet->currentFolder()=="krfb") || - ((m_wallet->hasFolder("krfb") || m_wallet->createFolder("krfb")) && - m_wallet->setFolder("krfb")) ) { - - m_wallet->writePassword("desktopSharingPassword",m_desktopPassword); - m_wallet->writePassword("unattendedAccessPassword",m_unattendedPassword); - } - } + KConfigGroup krfbConfig(KSharedConfig::openConfig(), "Security"); + krfbConfig.writeEntry("allowUnattendedAccess", m_allowUnattendedAccess); + + if (!KrfbConfig::noWallet() && m_wallet) { + closeKWallet(); } else { krfbConfig.writeEntry("desktopPassword", KStringHandler::obscure(m_desktopPassword)); @@ -153,6 +141,29 @@ return new PendingInvitationsRfbClient(client, this); } +void InvitationsRfbServer::openKWallet() +{ + m_wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Asynchronous); + if (m_wallet) { + connect(instance->m_wallet, &KWallet::Wallet::walletOpened, + this, &InvitationsRfbServer::walletOpened); + } +} + +void InvitationsRfbServer::closeKWallet() +{ + if (m_wallet && m_wallet->isOpen()) { + if ((m_wallet->currentFolder() == "krfb") || + ((m_wallet->hasFolder("krfb") || m_wallet->createFolder("krfb")) && + m_wallet->setFolder("krfb")) ) { + m_wallet->writePassword("desktopSharingPassword", m_desktopPassword); + m_wallet->writePassword("unattendedAccessPassword", m_unattendedPassword); + } + delete m_wallet; // closes the wallet + m_wallet = nullptr; + } +} + void InvitationsRfbServer::walletOpened(bool opened) { QString desktopPassword; diff --git a/krfb/mainwindow.cpp b/krfb/mainwindow.cpp --- a/krfb/mainwindow.cpp +++ b/krfb/mainwindow.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,20 @@ public: Security(QWidget *parent = nullptr) : QWidget(parent) { setupUi(this); + walletWarning = new KMessageWidget(this); + walletWarning->setText(i18n("Storing passwords in config file is insecure!")); + walletWarning->setCloseButtonVisible(false); + walletWarning->setMessageType(KMessageWidget::Warning); + walletWarning->hide(); + vboxLayout->addWidget(walletWarning); + + // show warning when "noWallet" checkbox is unchecked + QObject::connect(kcfg_noWallet, &QCheckBox::toggled, [this](bool checked){ + walletWarning->setVisible(!checked); + }); } + + KMessageWidget *walletWarning = nullptr; }; class ConfigFramebuffer: public QWidget, public Ui::Framebuffer @@ -226,10 +240,12 @@ void MainWindow::showConfiguration() { static QString s_prevFramebufferPlugin; + static bool s_prevNoWallet; // ^^ needs to be static, because lambda will be called long time // after showConfiguration() ends, so auto variable would go out of scope // save previously selected framebuffer plugin config s_prevFramebufferPlugin = KrfbConfig::preferredFrameBufferPlugin(); + s_prevNoWallet = KrfbConfig::noWallet(); if (KConfigDialog::showDialog("settings")) { return; @@ -246,6 +262,19 @@ KMessageBox::information(this, i18n("To apply framebuffer plugin setting, " "you need to restart the program.")); } + // check if kwallet config has changed + if (s_prevNoWallet != KrfbConfig::noWallet()) { + // try to apply settings immediately + if (KrfbConfig::noWallet()) { + InvitationsRfbServer::instance->closeKWallet(); + } else { + InvitationsRfbServer::instance->openKWallet(); + // erase stored passwords from krfbconfig file + KConfigGroup securityConfigGroup(KSharedConfig::openConfig(), "Security"); + securityConfigGroup.deleteEntry("desktopPassword"); + securityConfigGroup.deleteEntry("unattendedPassword"); + } + } }); } diff --git a/krfb/ui/configsecurity.ui b/krfb/ui/configsecurity.ui --- a/krfb/ui/configsecurity.ui +++ b/krfb/ui/configsecurity.ui @@ -21,6 +21,13 @@ + + + + Do not store passwords using KDE wallet + + +