aboutsummaryrefslogtreecommitdiffstats
path: root/src/m_key_server_sync/KeyServerSyncModule.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-11-17 18:22:07 +0000
committersaturneric <[email protected]>2024-11-17 18:22:07 +0000
commit99a5cb5ab598d66b090f01750877ed5b1835ec05 (patch)
tree4faff2a7c2bf74e4c8520dce8d2df4c99330ef6b /src/m_key_server_sync/KeyServerSyncModule.cpp
parentfeat: upgrade version to v2.1.5 (diff)
downloadModules-99a5cb5ab598d66b090f01750877ed5b1835ec05.tar.gz
Modules-99a5cb5ab598d66b090f01750877ed5b1835ec05.zip
feat: add key server sync module
Diffstat (limited to 'src/m_key_server_sync/KeyServerSyncModule.cpp')
-rw-r--r--src/m_key_server_sync/KeyServerSyncModule.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/m_key_server_sync/KeyServerSyncModule.cpp b/src/m_key_server_sync/KeyServerSyncModule.cpp
new file mode 100644
index 0000000..2247e3d
--- /dev/null
+++ b/src/m_key_server_sync/KeyServerSyncModule.cpp
@@ -0,0 +1,137 @@
+/**
+ * Copyright (C) 2021-2024 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "KeyServerSyncModule.h"
+
+#include <QtCore>
+
+#include "GFModuleDefine.h"
+#include "VKSInterface.h"
+
+GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.key_server_sync",
+ "KeyServerSync", "1.0.0",
+ "Sync Information From Trusted Key Server.", "Saturneric")
+
+auto GFRegisterModule() -> int {
+ LOG_DEBUG("key server sync module registering");
+
+ return 0;
+}
+
+auto GFActiveModule() -> int {
+ LISTEN("REQUEST_GET_PUBLIC_KEY_BY_FINGERPRINT");
+ LISTEN("REQUEST_GET_PUBLIC_KEY_BY_KEY_ID");
+ return 0;
+}
+
+EXECUTE_MODULE() {
+ FLOG_DEBUG("key server sync module executing, event id: %1",
+ event["event_id"]);
+
+ if (event["event_id"] == "REQUEST_GET_PUBLIC_KEY_BY_FINGERPRINT") {
+ if (event["fingerprint"].isEmpty())
+ CB_ERR(event, -1, "fingerprint is empty");
+
+ QByteArray fingerprint = event["fingerprint"].toLatin1();
+ FLOG_DEBUG("try to get key info of fingerprint: %1", fingerprint);
+
+ auto* vks = new VKSInterface();
+ vks->GetByFingerprint(fingerprint);
+ QObject::connect(vks, &VKSInterface::SignalKeyRetrieved,
+ QThread::currentThread(), [event](const QString& key) {
+ CB(event, GFGetModuleID(),
+ {
+ {"ret", QString::number(0)},
+ {"key_data", key},
+ });
+ });
+ QObject::connect(vks, &VKSInterface::SignalKeyRetrieved, vks,
+ &VKSInterface::deleteLater);
+
+ QObject::connect(vks, &VKSInterface::SignalErrorOccurred,
+ QThread::currentThread(),
+ [event](const QString& error, const QString& data) {
+ CB(event, GFGetModuleID(),
+ {
+ {"ret", QString::number(-1)},
+ {"error_msg", error},
+ {"reply_data", data},
+ });
+ });
+ QObject::connect(vks, &VKSInterface::SignalKeyRetrieved, vks,
+ &VKSInterface::deleteLater);
+
+ return 0;
+ }
+
+ if (event["event_id"] == "REQUEST_GET_PUBLIC_KEY_BY_KEY_ID") {
+ if (event["key_id"].isEmpty()) CB_ERR(event, -1, "key_id is empty");
+
+ QByteArray key_id = event["key_id"].toLatin1();
+ FLOG_DEBUG("try to get key info of key id: %1", key_id);
+
+ auto* vks = new VKSInterface();
+ vks->GetByKeyId(key_id);
+ QObject::connect(vks, &VKSInterface::SignalKeyRetrieved,
+ QThread::currentThread(), [event](const QString& key) {
+ CB(event, GFGetModuleID(),
+ {
+ {"ret", QString::number(0)},
+ {"key_data", key},
+ });
+ });
+ QObject::connect(vks, &VKSInterface::SignalKeyRetrieved, vks,
+ &VKSInterface::deleteLater);
+
+ QObject::connect(vks, &VKSInterface::SignalErrorOccurred,
+ QThread::currentThread(),
+ [event](const QString& error, const QString& data) {
+ CB(event, GFGetModuleID(),
+ {
+ {"ret", QString::number(-1)},
+ {"error_msg", error},
+ {"reply_data", data},
+ });
+ });
+ QObject::connect(vks, &VKSInterface::SignalKeyRetrieved, vks,
+ &VKSInterface::deleteLater);
+
+ return 0;
+ }
+
+ CB_SUCC(event);
+}
+END_EXECUTE_MODULE()
+
+auto GFDeactivateModule() -> int { return 0; }
+
+auto GFUnregisterModule() -> int {
+ MLogDebug("paper key module unregistering");
+
+ return 0;
+} \ No newline at end of file