Commit 60a035d4 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Request start of GnuPG agent if connecting to it fails

The DeviceInfoWatcher needs a running GnuPG agent, so that it can
watch for changes of the smartcard devices. Request the start of the
GnuPG agent if connecting to the agent failed for the first time
(since the start or since the last successful connection).

This fixes the problem that the GnuPG agent wasn't started if the
user's keyring was empty which made it impossible to use a fresh
GNUPGHOME with a smartcard.

Moreover, the DeviceInfoWatcher will trigger a restart of the GnuPG
agent if it was shut down by the user with the new "Restart Background
Processes" action.

GnuPG-bug-id: 5775
parent 3dc21aa2
Pipeline #137128 failed with stage
in 2 minutes and 17 seconds
......@@ -231,6 +231,8 @@ void KleopatraApplication::init()
}
add_resources();
DN::setAttributeOrder(Settings{}.attributeOrder());
connect(&d->readerStatus, &SmartCard::ReaderStatus::startOfGpgAgentRequested,
this, &KleopatraApplication::startGpgAgent);
d->setupKeyCache();
d->setUpSysTrayIcon();
d->setUpFilterManager();
......@@ -696,3 +698,8 @@ void KleopatraApplication::blockUrl(const QUrl &url)
KMessageBox::sorry(mainWindow(),i18n ("Opening an external link is administratively prohibited."),
i18n ("Prohibited"));
}
void KleopatraApplication::startGpgAgent()
{
Kleo::launchGpgAgent();
}
......@@ -60,6 +60,9 @@ void DeviceInfoWatcher::Worker::start()
return;
} else if (err.code() == GPG_ERR_ASS_CONNECT_FAILED) {
mFailedConnectionAttempts++;
if (mFailedConnectionAttempts == 1) {
Q_EMIT startOfGpgAgentRequested();
}
if (mFailedConnectionAttempts < maxConnectionAttempts) {
qCInfo(KLEOPATRA_LOG) << "DeviceInfoWatcher::Worker::start: Connecting to the agent failed. Retrying in" << mRetryDelay.count() << "ms";
QThread::msleep(mRetryDelay.count());
......@@ -116,6 +119,8 @@ void DeviceInfoWatcher::Private::start()
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
connect(worker, &DeviceInfoWatcher::Worker::statusChanged,
q, &DeviceInfoWatcher::statusChanged);
connect(worker, &DeviceInfoWatcher::Worker::startOfGpgAgentRequested,
q, &DeviceInfoWatcher::startOfGpgAgentRequested);
workerThread.start();
}
......
......@@ -26,6 +26,7 @@ public:
Q_SIGNALS:
void statusChanged(const QByteArray &details);
void startOfGpgAgentRequested();
private:
class Worker;
......
......@@ -35,6 +35,7 @@ public Q_SLOTS:
Q_SIGNALS:
void statusChanged(const QByteArray &details);
void startOfGpgAgentRequested();
private:
Q_INVOKABLE void poll();
......
......@@ -934,6 +934,8 @@ void ReaderStatus::startMonitoring()
{
d->start();
if (DeviceInfoWatcher::isSupported()) {
connect(&d->devInfoWatcher, &DeviceInfoWatcher::startOfGpgAgentRequested,
this, &ReaderStatus::startOfGpgAgentRequested);
d->devInfoWatcher.start();
}
}
......
......@@ -72,6 +72,7 @@ Q_SIGNALS:
void cardAdded(const std::string &serialNumber, const std::string &appName);
void cardChanged(const std::string &serialNumber, const std::string &appName);
void cardRemoved(const std::string &serialNumber, const std::string &appName);
void startOfGpgAgentRequested();
private:
class Private;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment