Commit 16fabab2 authored by Rolf Eike Beer's avatar Rolf Eike Beer Committed by Rolf Eike Beer

do not show error when KEY_CONSIDERED line is emitted by GnuPG when changing key disable

parent c59aa135
......@@ -2281,7 +2281,7 @@ void KeysManager::slotedit()
return;
if (terminalkey)
return;
if ((m_delkey != Q_NULLPTR) && m_delkey->keys().contains(nd->toKeyNode()))
if ((m_delkey != Q_NULLPTR) && m_delkey->keys.contains(nd->toKeyNode()))
return;
KProcess *kp = new KProcess(this);
......@@ -2400,7 +2400,7 @@ void KeysManager::deleteseckey()
void KeysManager::secretKeyDeleted(int retcode)
{
KGpgKeyNode *delkey = m_delkey->keys().at(0);
KGpgKeyNode *delkey = m_delkey->keys.at(0);
if (retcode == 0) {
KMessageBox::information(this, i18n("Key <b>%1</b> deleted.", delkey->getBeautifiedFingerprint()), i18n("Delete key"));
imodel->delNode(delkey);
......@@ -2530,8 +2530,7 @@ void KeysManager::confirmdeletekey()
void KeysManager::slotDelKeyDone(int res)
{
if (res == 0) {
const auto keys = m_delkey->keys();
for (KGpgKeyNode *kn : keys)
for (KGpgKeyNode *kn : m_delkey->keys)
imodel->delNode(kn);
}
......
......@@ -68,7 +68,7 @@ bool KGpgChangeKey::apply()
m_step = 0;
m_failed = 0;
nextStep(0);
nextStep(KGpgTransaction::TS_OK);
return true;
}
......
......@@ -49,5 +49,8 @@ KGpgChangeDisable::preStart()
bool
KGpgChangeDisable::nextLine(const QString &line)
{
if(keyConsidered(line, QStringList(getKeyid())))
return false;
return KGpgEditKeyTransaction::nextLine(line);
}
......@@ -25,6 +25,8 @@ class KGpgChangeDisable: public KGpgEditKeyTransaction {
Q_OBJECT
Q_DISABLE_COPY(KGpgChangeDisable)
KGpgChangeDisable() Q_DECL_EQ_DELETE;
public:
KGpgChangeDisable(QObject *parent, const QString &keyid, const bool disable);
virtual ~KGpgChangeDisable();
......
......@@ -18,16 +18,28 @@
#include <QString>
#include <QStringList>
static QStringList keyFingerprints(const KGpgKeyNode::List &keys)
{
QStringList ret;
foreach (const KGpgKeyNode *key, keys)
ret << key->getFingerprint();
return ret;
}
KGpgDelKey::KGpgDelKey(QObject *parent, KGpgKeyNode *key)
: KGpgTransaction(parent)
, keys({key})
, fingerprints(keyFingerprints(keys))
{
m_keys << key;
setCmdLine();
}
KGpgDelKey::KGpgDelKey(QObject *parent, const KGpgKeyNode::List &keys)
: KGpgTransaction(parent),
m_keys(keys)
: KGpgTransaction(parent)
, keys(keys)
, fingerprints(keyFingerprints(keys))
{
setCmdLine();
}
......@@ -36,32 +48,11 @@ KGpgDelKey::~KGpgDelKey()
{
}
KGpgKeyNode::List
KGpgDelKey::keys() const
{
return m_keys;
}
bool
KGpgDelKey::nextLine(const QString &line)
{
if (line.startsWith(QLatin1String("[GNUPG:] KEY_CONSIDERED "))) {
const QStringList &parts = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
if (parts.count() < 3) {
setSuccess(KGpgTransaction::TS_MSG_SEQUENCE);
} else {
const QString &fpr = parts[2];
bool mine = false;
foreach (const KGpgKeyNode *key, m_keys) {
mine = (key->getFingerprint() == fpr);
if (mine)
break;
}
if (!mine)
setSuccess(KGpgTransaction::TS_MSG_SEQUENCE);
}
if (keyConsidered(line, fingerprints)) {
// nothing
} else if (!line.startsWith(QLatin1String("[GNUPG:] GOT_IT")))
setSuccess(KGpgTransaction::TS_MSG_SEQUENCE);
......@@ -84,10 +75,7 @@ bool
KGpgDelKey::preStart()
{
GPGProc *proc = getProcess();
QStringList args = proc->program();
foreach (const KGpgKeyNode *key, m_keys)
args << key->getFingerprint();
const QStringList args = proc->program() + fingerprints;
proc->setProgram(args);
......
......@@ -35,9 +35,13 @@ public:
/**
* @brief the keys that were requested to be removed
* @return the list of key nodes
*/
KGpgKeyNode::List keys() const;
const KGpgKeyNode::List keys;
/**
* @brief the fingerprints of everything in keys
*/
const QStringList fingerprints;
protected:
bool nextLine(const QString &line) Q_DECL_OVERRIDE;
......@@ -45,7 +49,6 @@ protected:
bool preStart() Q_DECL_OVERRIDE;
private:
KGpgKeyNode::List m_keys;
int m_argscount;
void setCmdLine();
......
......@@ -396,3 +396,17 @@ void
KGpgTransaction::newPassphraseEntered()
{
}
bool KGpgTransaction::keyConsidered(const QString& line, const QStringList &fingerprints)
{
if (!line.startsWith(QLatin1String("[GNUPG:] KEY_CONSIDERED ")))
return false;
const QStringList &parts = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
if (parts.count() < 3)
setSuccess(KGpgTransaction::TS_MSG_SEQUENCE);
else if (!fingerprints.contains(parts[2], Qt::CaseInsensitive))
setSuccess(KGpgTransaction::TS_MSG_SEQUENCE);
return true;
}
......@@ -20,8 +20,9 @@
class GPGProc;
class KGpgSignTransactionHelper;
class KGpgTransactionPrivate;
class QUrl;
class QByteArray;
class QStringList;
class QUrl;
/**
* @brief Process one GnuPG operation
......@@ -445,7 +446,19 @@ protected:
* take care to display the message asking the user for the passphrase
* and the number of tries left.
*/
bool askPassphrase(const QString &message = QString());
bool askPassphrase(const QString &message = QString());
/**
* @brief handle if this a KEY_CONSIDERED line
* @param line the line from GnuPG output
* @param fingerprints the fingerprints of the expected keys
* @returns if this is a KEY_CONSIDERED line
*
* In case this is a KEY_CONSIDERED line (i.e. the return value is true),
* but either it was malformed or the given fingerprint does not match any
* key in fingerprints, the success value will be set to TS_MSG_SEQUENCE.
*/
bool keyConsidered(const QString &line, const QStringList &fingerprints);
};
#endif // KGPGTRANSACTION_H
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