diff options
author | Saturn&Eric <[email protected]> | 2021-07-19 20:13:05 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-07-19 20:13:05 +0000 |
commit | 837e9748bb6bc5b3255b0475b8bbb3106e061b9c (patch) | |
tree | 67acd04b79d0ce779fc2ade5bb3e43a872f660cd /src/gpg/GpgContext.cpp | |
parent | Merge pull request #13 from saturneric/develop (diff) | |
parent | Add multi-language support. (diff) | |
download | GpgFrontend-1.2.2.tar.gz GpgFrontend-1.2.2.zip |
Merge pull request #14 from saturneric/developv1.2.2
Version 1.2.2
Diffstat (limited to 'src/gpg/GpgContext.cpp')
-rw-r--r-- | src/gpg/GpgContext.cpp | 73 |
1 files changed, 62 insertions, 11 deletions
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index 7ec521a7..0462433d 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -24,6 +24,7 @@ #include "gpg/GpgContext.h" +#include <functional> #include <unistd.h> /* contains read/write */ #ifdef _WIN32 @@ -72,8 +73,10 @@ namespace GpgME { << engineInfo->home_dir << engineInfo->version; if (engineInfo->protocol == GPGME_PROTOCOL_GPGCONF && strcmp(engineInfo->version, "1.0.0") != 0) find_gpgconf = true; - if (engineInfo->protocol == GPGME_PROTOCOL_OpenPGP && strcmp(engineInfo->version, "1.0.0") != 0) + if (engineInfo->protocol == GPGME_PROTOCOL_OpenPGP && strcmp(engineInfo->version, "1.0.0") != 0) { + gpgExec = engineInfo->file_name; find_openpgp = true; + } if (engineInfo->protocol == GPGME_PROTOCOL_CMS && strcmp(engineInfo->version, "1.0.0") != 0) find_cms = true; if (engineInfo->protocol == GPGME_PROTOCOL_ASSUAN) @@ -625,20 +628,31 @@ namespace GpgME { } /** return type should be gpgme_error_t*/ - void GpgContext::executeGpgCommand(const QStringList &arguments, QByteArray *stdOut, QByteArray *stdErr) { + QProcess * GpgContext::executeGpgCommand(const QStringList &arguments, QByteArray *stdOut, QByteArray *stdErr, + const std::function<void(QProcess *)> &interactFunc) { QStringList args; - args << "--homedir" << gpgKeys << "--batch" << arguments; + args << arguments; + + auto *gpgProcess = new QProcess(this); + qDebug() << "gpgExec" << gpgExec << args; - qDebug() << args; - QProcess gpg; - // qDebug() << "engine->file_name" << engine->file_name; + gpgProcess->setReadChannel(QProcess::StandardOutput); + connect(gpgProcess, SIGNAL(finished(int,QProcess::ExitStatus)), + gpgProcess, SLOT(deleteLater())); + connect(gpgProcess, &QProcess::readyReadStandardOutput, this, [gpgProcess, interactFunc]() { + qDebug() << "Function Called" << &gpgProcess; + // interactFunc(gpgProcess); + }); - gpg.start(gpgBin, args); - gpg.waitForFinished(); + gpgProcess->start(gpgExec, args); - *stdOut = gpg.readAllStandardOutput(); - *stdErr = gpg.readAllStandardError(); - qDebug() << *stdOut; + if (gpgProcess->waitForStarted()){ + qDebug() << "Gpg Process Started Success"; + } else { + qDebug() << "Gpg Process Started Failed"; + } + + return gpgProcess; } /*** @@ -1180,4 +1194,41 @@ namespace GpgME { } return true; } + + QProcess * GpgContext::generateRevokeCert(const GpgKey &key, const QString &outputFileName) { + QByteArray out, stdErr; + auto process = executeGpgCommand({ + "--command-fd", + "0", + "--status-fd", "1", + "-o", + outputFileName, + "--gen-revoke", + key.fpr + }, &out, &stdErr, + [](QProcess *proc) { + qDebug() << "Function Called" << proc; + while (proc->canReadLine()) { + const QString line = QString::fromUtf8(proc->readLine()).trimmed(); + // Command-fd is a stable interface, while this is all kind of hacky we + // are on a deadline :-/ + if (line == QLatin1String("[GNUPG:] GET_BOOL gen_revoke.okay")) { + proc->write("y\n"); + } else if (line == QLatin1String("[GNUPG:] GET_LINE ask_revocation_reason.code")) { + proc->write("0\n"); + } else if (line == QLatin1String("[GNUPG:] GET_LINE ask_revocation_reason.text")) { + proc->write("\n"); + } else if (line == QLatin1String("[GNUPG:] GET_BOOL openfile.overwrite.okay")) { + // We asked before + proc->write("y\n"); + } else if (line == QLatin1String("[GNUPG:] GET_BOOL ask_revocation_reason.okay")) { + proc->write("y\n"); + } + } + }); + + qDebug() << "GenerateRevokeCert Process" << process; + + return process; + } } |