Commit 7ad4d6dc authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

DefaultKeyGenerationJob: add API to specify custom passphrase

parent 10889c17
......@@ -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")
......
......@@ -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);
......
......@@ -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;
......
Supports Markdown
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