aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/function/gpg
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-10-18 18:15:36 +0000
committersaturneric <[email protected]>2024-10-18 18:15:36 +0000
commitc3a23900281c2024f7d4507ac84b0fe700fbf6dd (patch)
treeb8f611ef7b4121ffe9f0df60eb3b3c3896c444b5 /src/core/function/gpg
parentfeat: add filter option of 'comment' at key list of main window (diff)
downloadGpgFrontend-c3a23900281c2024f7d4507ac84b0fe700fbf6dd.tar.gz
GpgFrontend-c3a23900281c2024f7d4507ac84b0fe700fbf6dd.zip
feat: set reason code and text at revoke-certification
Diffstat (limited to 'src/core/function/gpg')
-rw-r--r--src/core/function/gpg/GpgCommandExecutor.cpp6
-rw-r--r--src/core/function/gpg/GpgCommandExecutor.h6
-rw-r--r--src/core/function/gpg/GpgKeyOpera.cpp22
-rw-r--r--src/core/function/gpg/GpgKeyOpera.h4
4 files changed, 28 insertions, 10 deletions
diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp
index 74df1d5a..555c710d 100644
--- a/src/core/function/gpg/GpgCommandExecutor.cpp
+++ b/src/core/function/gpg/GpgCommandExecutor.cpp
@@ -66,7 +66,7 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context)
FLOG_D("process runner called, data object size: %lu",
data_object->GetObjectSize());
- if (!data_object->Check<QString, QStringList, GpgCommandExecutorInteractor,
+ if (!data_object->Check<QString, QStringList, GpgCommandExecutorInterator,
GpgCommandExecutorCallback>()) {
FLOG_W("data object checking failed");
return -1;
@@ -76,7 +76,7 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context)
auto cmd = ExtractParams<QString>(data_object, 0);
auto arguments = ExtractParams<QStringList>(data_object, 1);
auto interact_func =
- ExtractParams<GpgCommandExecutorInteractor>(data_object, 2);
+ ExtractParams<GpgCommandExecutorInterator>(data_object, 2);
auto callback = ExtractParams<GpgCommandExecutorCallback>(data_object, 3);
const QString joined_argument = arguments.join(" ");
@@ -225,7 +225,7 @@ void GpgCommandExecutor::ExecuteConcurrentlySync(ExecuteContexts contexts) {
GpgCommandExecutor::ExecuteContext::ExecuteContext(
QString cmd, QStringList arguments, GpgCommandExecutorCallback callback,
- Module::TaskRunnerPtr task_runner, GpgCommandExecutorInteractor int_func)
+ Module::TaskRunnerPtr task_runner, GpgCommandExecutorInterator int_func)
: cmd(std::move(cmd)),
arguments(std::move(arguments)),
cb_func(std::move(callback)),
diff --git a/src/core/function/gpg/GpgCommandExecutor.h b/src/core/function/gpg/GpgCommandExecutor.h
index e3b03c10..cb35e686 100644
--- a/src/core/function/gpg/GpgCommandExecutor.h
+++ b/src/core/function/gpg/GpgCommandExecutor.h
@@ -33,7 +33,7 @@
namespace GpgFrontend {
using GpgCommandExecutorCallback = std::function<void(int, QString, QString)>;
-using GpgCommandExecutorInteractor = std::function<void(QProcess *)>;
+using GpgCommandExecutorInterator = std::function<void(QProcess *)>;
/**
* @brief Extra commands related to GPG
@@ -45,7 +45,7 @@ class GPGFRONTEND_CORE_EXPORT GpgCommandExecutor {
QString cmd;
QStringList arguments;
GpgCommandExecutorCallback cb_func;
- GpgCommandExecutorInteractor int_func;
+ GpgCommandExecutorInterator int_func;
Module::TaskRunnerPtr task_runner = nullptr;
ExecuteContext(
@@ -53,7 +53,7 @@ class GPGFRONTEND_CORE_EXPORT GpgCommandExecutor {
GpgCommandExecutorCallback callback = [](int, const QString &,
const QString &) {},
Module::TaskRunnerPtr task_runner = nullptr,
- GpgCommandExecutorInteractor int_func = [](QProcess *) {});
+ GpgCommandExecutorInterator int_func = [](QProcess *) {});
};
using ExecuteContexts = QList<ExecuteContext>;
diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp
index 332ed1b3..0d84017f 100644
--- a/src/core/function/gpg/GpgKeyOpera.cpp
+++ b/src/core/function/gpg/GpgKeyOpera.cpp
@@ -103,7 +103,17 @@ auto GpgKeyOpera::SetExpire(const GpgKey& key, const SubkeyId& subkey_fpr,
* @return the process doing this job
*/
void GpgKeyOpera::GenerateRevokeCert(const GpgKey& key,
- const QString& output_path) {
+ const QString& output_path,
+ int revocation_reason_code,
+ const QString& revocation_reason_text) {
+ LOG_D() << "revoke code:" << revocation_reason_code
+ << "text:" << revocation_reason_text;
+
+ // dealing with reason text
+ auto reason_text_lines =
+ GpgFrontend::SecureCreateSharedObject<QList<QString>>(
+ revocation_reason_text.split('\n', Qt::SkipEmptyParts).toVector());
+
const auto app_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.app_path", QString{});
// get all components
@@ -121,17 +131,23 @@ void GpgKeyOpera::GenerateRevokeCert(const GpgKey& key,
}
},
nullptr,
- [](QProcess* proc) -> void {
+ [revocation_reason_code, reason_text_lines](QProcess* proc) -> void {
// Code From Gpg4Win
while (proc->canReadLine()) {
const QString line = QString::fromUtf8(proc->readLine()).trimmed();
+ LOG_D() << "gpg revoke proc line:" << line;
+
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");
+ proc->write(
+ QString("%1%\n").arg(revocation_reason_code).toLatin1());
} else if (line == QLatin1String("[GNUPG:] GET_LINE "
"ask_revocation_reason.text")) {
+ if (!reason_text_lines->isEmpty()) {
+ proc->write(reason_text_lines->takeFirst().toUtf8());
+ }
proc->write("\n");
} else if (line ==
QLatin1String(
diff --git a/src/core/function/gpg/GpgKeyOpera.h b/src/core/function/gpg/GpgKeyOpera.h
index 0504ad93..7b8a01a1 100644
--- a/src/core/function/gpg/GpgKeyOpera.h
+++ b/src/core/function/gpg/GpgKeyOpera.h
@@ -86,7 +86,9 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @param key
* @param output_file_name
*/
- void GenerateRevokeCert(const GpgKey& key, const QString& output_path);
+ void GenerateRevokeCert(const GpgKey& key, const QString& output_path,
+ int revocation_reason_code,
+ const QString& revocation_reason_text);
/**
* @brief