summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-09-30 13:00:56 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-09-30 13:01:12 (GMT)
commit7ad4d6dc2a0b3a3b0ea604f9ad2c8dd3a4191310 (patch)
tree2f6886e72d98b6c647cab78360cab92e13a949ea
parent10889c17e3058737545c08a14437e637a90e2657 (diff)
DefaultKeyGenerationJob: add API to specify custom passphrase
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/kleo/defaultkeygenerationjob.cpp21
-rw-r--r--src/kleo/defaultkeygenerationjob.h9
3 files changed, 27 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56d512b..0379817 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,7 @@ include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
-set(PIM_VERSION "5.3.44")
+set(PIM_VERSION "5.3.45")
set(LIBKLEO_LIB_VERSION ${PIM_VERSION})
set(QT_REQUIRED_VERSION "5.6.0")
set(GPGMEPP_LIB_VERSION "5.3.40")
diff --git a/src/kleo/defaultkeygenerationjob.cpp b/src/kleo/defaultkeygenerationjob.cpp
index a436a50..c1d9a78 100644
--- a/src/kleo/defaultkeygenerationjob.cpp
+++ b/src/kleo/defaultkeygenerationjob.cpp
@@ -40,6 +40,7 @@ public:
}
}
+ QString passphrase;
QPointer<KeyGenerationJob> job;
};
}
@@ -73,19 +74,31 @@ void DefaultKeyGenerationJob::slotCancel()
}
}
+void DefaultKeyGenerationJob::setPassphrase(const QString &passphrase)
+{
+ // null QString = ask for passphrase
+ // empty QString = empty passphrase
+ // non-empty QString = passphrase
+ d->passphrase = passphrase.isNull() ? QLatin1String("") : passphrase;
+}
+
GpgME::Error DefaultKeyGenerationJob::start(const QString &email, const QString &name)
{
+ const QString passphrase = d->passphrase.isNull() ? QStringLiteral("%ask-passphrase") :
+ d->passphrase.isEmpty() ? QStringLiteral("%no-protection") :
+ d->passphrase;
+
const QString args = QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
- "%ask-passphrase\n"
+ "%1\n"
"key-type: RSA\n"
"key-length: 2048\n"
"key-usage: sign\n"
"subkey-type: RSA\n"
"subkey-length: 2048\n"
"subkey-usage: encrypt\n"
- "name-email: %1\n"
- "name-real: %2\n"
- "</GnupgKeyParms>").arg(email, name);
+ "name-email: %2\n"
+ "name-real: %3\n"
+ "</GnupgKeyParms>").arg(passphrase, email, name);
d->job = CryptoBackendFactory::instance()->openpgp()->keyGenerationJob();
d->job->installEventFilter(this);
diff --git a/src/kleo/defaultkeygenerationjob.h b/src/kleo/defaultkeygenerationjob.h
index ddff01a..357f51a 100644
--- a/src/kleo/defaultkeygenerationjob.h
+++ b/src/kleo/defaultkeygenerationjob.h
@@ -41,6 +41,15 @@ public:
explicit DefaultKeyGenerationJob(QObject *parent = Q_NULLPTR);
~DefaultKeyGenerationJob();
+ /**
+ * Set key passphrase
+ *
+ * Use this method to specify custom passphrase, including an empty
+ * one. If no passphrase (not even empty) is specified, gpg me will
+ * automatically prompt for passphrase using Pinentry dialog.
+ */
+ void setPassphrase(const QString &passphrase);
+
GpgME::Error start(const QString &email, const QString &name);
QString auditLogAsHtml() const Q_DECL_OVERRIDE;