Compare commits
No commits in common. "b38441115629e765ec5c4d82b0ca5c9ad7738c88" and "c27c541257585878e4db705559c5cb953dc860b7" have entirely different histories.
b384411156
...
c27c541257
@ -43,45 +43,17 @@
|
||||
#define UDUP(v) UnStrDup(v)
|
||||
#define QDUP(v) QStrDup(v)
|
||||
|
||||
#define LISTEN(event) GFModuleListenEvent(GFGetModuleID(), DUP(event))
|
||||
|
||||
#define EXECUTE_MODULE() \
|
||||
auto GFExecuteModule(GFModuleEvent* p_event) -> int { \
|
||||
auto event = ConvertEventToMap(p_event);
|
||||
|
||||
#define END_EXECUTE_MODULE() }
|
||||
|
||||
#define CB_SUCC(event) \
|
||||
{ \
|
||||
CB(event, GFGetModuleID(), {{"ret", "0"}}); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
#define CB_ERR(event, ret, err) \
|
||||
{ \
|
||||
CB(event, GFGetModuleID(), \
|
||||
{{"ret", QString::number(ret)}, {"err", QString(err)}}); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
inline void MLogDebug(const QString& s) { GFModuleLogDebug(s.toUtf8()); }
|
||||
inline void MLogInfo(const QString& s) { GFModuleLogInfo(s.toUtf8()); }
|
||||
inline void MLogWarn(const QString& s) { GFModuleLogWarn(s.toUtf8()); }
|
||||
inline void MLogError(const QString& s) { GFModuleLogError(s.toUtf8()); }
|
||||
|
||||
#define LOG_DEBUG(format) MLogDebug(FormatString(QString(format)))
|
||||
#define LOG_INFO(format) MLogDebug(FormatString(QString(format)))
|
||||
#define LOG_WARN(format) MLogDebug(FormatString(QString(format)))
|
||||
#define LOG_ERROR(format) MLogDebug(FormatString(QString(format)))
|
||||
|
||||
#define FLOG_DEBUG(format, ...) \
|
||||
MLogDebug(FormatString(QString(format), __VA_ARGS__))
|
||||
#define FLOG_INFO(format, ...) \
|
||||
MLogInfo(FormatString(QString(format), __VA_ARGS__))
|
||||
#define FLOG_WARN(format, ...) \
|
||||
MLogWarn(FormatString(QString(format), __VA_ARGS__))
|
||||
#define FLOG_ERROR(format, ...) \
|
||||
MLogError(FormatString(QString(format), __VA_ARGS__))
|
||||
#define MLogDebugS(format, ...) \
|
||||
MLogDebug(QString::asprintf(format, __VA_ARGS__))
|
||||
#define MLogInfoS(format, ...) MLogInfo(QString::asprintf(format, __VA_ARGS__))
|
||||
#define MLogWarnS(format, ...) MLogWarn(QString::asprintf(format, __VA_ARGS__))
|
||||
#define MLogErrorS(format, ...) \
|
||||
MLogError(QString::asprintf(format, __VA_ARGS__))
|
||||
|
||||
inline auto QStrDup(QString str) -> char* { return DUP(str.toUtf8()); }
|
||||
|
||||
@ -207,12 +179,6 @@ inline auto ConvertMapToEvent(QMap<QString, QString> event_map)
|
||||
return event;
|
||||
}
|
||||
|
||||
inline void CB(const QMap<QString, QString>& event, const char* module,
|
||||
const QMap<QString, QString>& params) {
|
||||
GFModuleTriggerModuleEventCallback(ConvertMapToEvent(event), module,
|
||||
ConvertMapToParams(params));
|
||||
}
|
||||
|
||||
inline auto AllocBufferAndCopy(const QByteArray& b) -> char* {
|
||||
auto* p = static_cast<char*>(GFAllocateMemory(sizeof(char) * b.size()));
|
||||
memcpy(p, b.constData(), b.size());
|
||||
@ -295,22 +261,3 @@ inline auto CharArrayToQStringList(char** pl_components,
|
||||
GFFreeMemory(pl_components);
|
||||
return list;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto FormatStringHelper(const QString& format, T arg) -> QString {
|
||||
return format.arg(arg);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
auto FormatStringHelper(const QString& format, T arg, Args... args) -> QString {
|
||||
return FormatStringHelper(format.arg(arg), args...);
|
||||
}
|
||||
|
||||
inline auto FormatStringHelper(const QString& format) -> QString {
|
||||
return format;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
auto FormatString(const QString& format, Args... args) -> QString {
|
||||
return FormatStringHelper(format, args...);
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2021 Saturneric <eric@bktus.com>
|
||||
*
|
||||
* 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 <eric@bktus.com> starting on May 12, 2021.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <GFSDKModule.h>
|
||||
|
||||
#include "GFModuleExport.h"
|
||||
|
||||
#define GF_MODULE_API_DECLARE \
|
||||
extern "C" { \
|
||||
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *; \
|
||||
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *; \
|
||||
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *; \
|
||||
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *; \
|
||||
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *; \
|
||||
auto GF_MODULE_EXPORT GFRegisterModule() -> int; \
|
||||
auto GF_MODULE_EXPORT GFActiveModule() -> int; \
|
||||
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int; \
|
||||
auto GF_MODULE_EXPORT GFDeactivateModule() -> int; \
|
||||
auto GF_MODULE_EXPORT GFUnregisterModule() -> int; \
|
||||
};
|
@ -1,49 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2021 Saturneric <eric@bktus.com>
|
||||
*
|
||||
* 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 <eric@bktus.com> starting on May 12, 2021.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GFModuleCommonUtils.hpp"
|
||||
#include "GFSDKBuildInfo.h"
|
||||
|
||||
#define GF_MODULE_API_DEFINE(id, name, ver, desc, author) \
|
||||
class GTrC { \
|
||||
Q_DECLARE_TR_FUNCTIONS(GTrC) \
|
||||
}; \
|
||||
auto GFGetModuleGFSDKVersion() -> const char* { \
|
||||
return DUP(GF_SDK_VERSION_STR); \
|
||||
} \
|
||||
auto GFGetModuleQtEnvVersion() -> const char* { \
|
||||
return DUP(QT_VERSION_STR); \
|
||||
} \
|
||||
auto GFGetModuleID() -> const char* { return DUP((id)); } \
|
||||
auto GFGetModuleVersion() -> const char* { return DUP((ver)); } \
|
||||
auto GFGetModuleMetaData() -> GFModuleMetaData* { \
|
||||
return QMapToGFModuleMetaDataList( \
|
||||
{{"Name", (name)}, {"Description", (desc)}, {"Author", (author)}}); \
|
||||
}
|
@ -43,12 +43,11 @@
|
||||
#include <optional>
|
||||
|
||||
#include "GFModuleCommonUtils.hpp"
|
||||
#include "GFModuleDefine.h"
|
||||
#include "GpgInfo.h"
|
||||
|
||||
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.gnupg_info_gathering",
|
||||
"GatherGnupgInfo", "1.0.0",
|
||||
"Try gathering gnupg informations.", "Saturneric")
|
||||
class GTrC {
|
||||
Q_DECLARE_TR_FUNCTIONS(GTrC)
|
||||
};
|
||||
|
||||
extern auto CalculateBinaryChacksum(const QString &path)
|
||||
-> std::optional<QString>;
|
||||
@ -69,6 +68,25 @@ using Context = struct {
|
||||
GpgComponentInfo component_info;
|
||||
};
|
||||
|
||||
auto GFGetModuleGFSDKVersion() -> const char * {
|
||||
return DUP(GF_SDK_VERSION_STR);
|
||||
}
|
||||
|
||||
auto GFGetModuleQtEnvVersion() -> const char * { return DUP(QT_VERSION_STR); }
|
||||
|
||||
auto GFGetModuleID() -> const char * {
|
||||
return DUP("com.bktus.gpgfrontend.module.gnupg_info_gathering");
|
||||
}
|
||||
|
||||
auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); }
|
||||
|
||||
auto GFGetModuleMetaData() -> GFModuleMetaData * {
|
||||
return QMapToGFModuleMetaDataList(
|
||||
{{"Name", "GatherGnupgInfo"},
|
||||
{"Description", "Try gathering gnupg informations."},
|
||||
{"Author", "Saturneric"}});
|
||||
}
|
||||
|
||||
auto GFRegisterModule() -> int {
|
||||
MLogDebug("gnupg info gathering module registering");
|
||||
|
||||
@ -80,21 +98,25 @@ auto GFRegisterModule() -> int {
|
||||
}
|
||||
|
||||
auto GFActiveModule() -> int {
|
||||
LISTEN("REQUEST_GATHERING_GNUPG_INFO");
|
||||
MLogDebug("gnupg info gathering module activating");
|
||||
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_GATHERING_GNUPG_INFO"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXECUTE_MODULE() {
|
||||
FLOG_DEBUG("gnupg info gathering module executing, event id: %1",
|
||||
event["event_id"]);
|
||||
auto GFExecuteModule(GFModuleEvent *event) -> int {
|
||||
MLogDebug(QString("gnupg info gathering module executing, event id: %1")
|
||||
.arg(event->id));
|
||||
|
||||
StartGatheringGnuPGInfo();
|
||||
|
||||
CB_SUCC(event);
|
||||
}
|
||||
END_EXECUTE_MODULE()
|
||||
GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1,
|
||||
ConvertMapToParams({{"ret", "0"}}));
|
||||
|
||||
auto GFDeactivateModule() -> int { return 0; }
|
||||
MLogDebug("gnupg external info gathering done");
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto GFDeactiveModule() -> int { return 0; }
|
||||
|
||||
auto GFUnregisterModule() -> int {
|
||||
MLogDebug("gnupg info gathering module unregistering");
|
||||
|
@ -28,6 +28,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GFModuleDeclare.h"
|
||||
#include <GFSDKModule.h>
|
||||
|
||||
GF_MODULE_API_DECLARE
|
||||
#include "GFModuleExport.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFRegisterModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFActiveModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFDeactiveModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
|
||||
};
|
@ -28,132 +28,154 @@
|
||||
|
||||
#include "PaperKeyModule.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
#include "GFModuleDefine.h"
|
||||
#include "GFModuleCommonUtils.hpp"
|
||||
#include "GFSDKBuildInfo.h"
|
||||
#include "extract.h"
|
||||
#include "restore.h"
|
||||
|
||||
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.paper_key", "PaperKey",
|
||||
"1.0.0", "Integrated PaperKey Functions.", "Saturneric")
|
||||
auto GFGetModuleGFSDKVersion() -> const char * {
|
||||
return DUP(GF_SDK_VERSION_STR);
|
||||
}
|
||||
|
||||
auto GFGetModuleQtEnvVersion() -> const char * { return DUP(QT_VERSION_STR); }
|
||||
|
||||
auto GFGetModuleID() -> const char * {
|
||||
return DUP("com.bktus.gpgfrontend.module.paper_key");
|
||||
}
|
||||
|
||||
auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); }
|
||||
|
||||
auto GFGetModuleMetaData() -> GFModuleMetaData * {
|
||||
return QMapToGFModuleMetaDataList(
|
||||
{{"Name", "PaperKey"},
|
||||
{"Description", "Integrated PaperKey Functions."},
|
||||
{"Author", "Saturneric"}});
|
||||
}
|
||||
|
||||
auto GFRegisterModule() -> int {
|
||||
LOG_DEBUG("paper key module registering");
|
||||
MLogDebug("paper key module registering");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto GFActiveModule() -> int {
|
||||
LISTEN("REQUEST_TRANS_KEY_2_PAPER_KEY");
|
||||
LISTEN("REQUEST_TRANS_PAPER_KEY_2_KEY");
|
||||
MLogDebug("paper key module activating");
|
||||
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_KEY_2_PAPER_KEY"));
|
||||
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_PAPER_KEY_2_KEY"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXECUTE_MODULE() {
|
||||
FLOG_DEBUG("paper key module executing, event id: %1", event["event_id"]);
|
||||
auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
||||
MLogDebug(
|
||||
QString("paper key module executing, event id: %1").arg(p_event->id));
|
||||
|
||||
auto event = ConvertEventToMap(p_event);
|
||||
|
||||
if (event["event_id"] == "REQUEST_TRANS_KEY_2_PAPER_KEY") {
|
||||
if (event["secret_key"].isEmpty()) CB_ERR(event, -1, "secret key is empty");
|
||||
if (event["secret_key"].isEmpty() || event["output_path"].isEmpty()) {
|
||||
GFModuleTriggerModuleEventCallback(
|
||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
||||
ConvertMapToParams(
|
||||
{{"ret", "-1"},
|
||||
{"reason", "secret key or output path is empty"}}));
|
||||
return -1;
|
||||
}
|
||||
|
||||
QByteArray secret_key_rdata =
|
||||
QByteArray::fromBase64(event["secret_key"].toLatin1());
|
||||
QByteArray secret_key_data =
|
||||
QByteArray::fromBase64(event["secret_key"].toUtf8());
|
||||
|
||||
QTemporaryFile secret_key_t_file;
|
||||
if (!secret_key_t_file.open())
|
||||
CB_ERR(event, -1, "unable to open temporary file");
|
||||
if (!secret_key_t_file.open()) {
|
||||
qWarning() << "Unable to open temporary file";
|
||||
MLogWarn("unable to open temporary file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
secret_key_t_file.write(secret_key_rdata);
|
||||
secret_key_t_file.write(secret_key_data);
|
||||
secret_key_t_file.flush();
|
||||
secret_key_t_file.reset();
|
||||
secret_key_t_file.seek(0);
|
||||
|
||||
FILE *secret_key_file = fdopen(secret_key_t_file.handle(), "rb");
|
||||
if (secret_key_file == nullptr)
|
||||
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
|
||||
FILE *file = fdopen(secret_key_t_file.handle(), "rb");
|
||||
if (file == nullptr) {
|
||||
qDebug() << "Unable to convert QTemporaryFile to FILE*";
|
||||
return -1;
|
||||
}
|
||||
|
||||
QTemporaryFile paper_key_t_file;
|
||||
if (!paper_key_t_file.open())
|
||||
CB_ERR(event, -1, "unable to open temporary file");
|
||||
extract(file, event["output_path"].toUtf8(), AUTO);
|
||||
|
||||
FILE *paper_key_fp = fdopen(dup(paper_key_t_file.handle()), "w");
|
||||
if (paper_key_fp == nullptr)
|
||||
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
|
||||
|
||||
auto ret = extract(secret_key_file, paper_key_fp, BASE16);
|
||||
paper_key_t_file.flush();
|
||||
paper_key_t_file.reset();
|
||||
|
||||
CB(event, GFGetModuleID(),
|
||||
{
|
||||
{"ret", QString::number(ret)},
|
||||
{"paper_key", QString::fromLatin1(paper_key_t_file.readAll())},
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (event["event_id"] == "REQUEST_TRANS_PAPER_KEY_2_KEY") {
|
||||
if (event["public_key"].isEmpty() || event["paper_key_secrets"].isEmpty())
|
||||
CB_ERR(event, -1, "public key or paper key secrets is empty");
|
||||
fclose(file);
|
||||
} else if (event["event_id"] == "REQUEST_TRANS_PAPER_KEY_2_KEY") {
|
||||
if (event["public_key"].isEmpty() || event["paper_key_secrets"].isEmpty()) {
|
||||
GFModuleTriggerModuleEventCallback(
|
||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
||||
ConvertMapToParams(
|
||||
{{"ret", "-1"},
|
||||
{"reason", "public key or paper key secrets is empty"}}));
|
||||
return -1;
|
||||
}
|
||||
|
||||
QByteArray public_key_data =
|
||||
QByteArray::fromBase64(event["public_key"].toLatin1());
|
||||
QByteArray::fromBase64(event["public_key"].toUtf8());
|
||||
|
||||
QTemporaryFile public_key_t_file;
|
||||
if (!public_key_t_file.open())
|
||||
CB_ERR(event, -1, "unable to open temporary file");
|
||||
if (!public_key_t_file.open()) {
|
||||
GFModuleTriggerModuleEventCallback(
|
||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
||||
ConvertMapToParams(
|
||||
{{"ret", "-1"}, {"reason", "unable to open temporary file"}}));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public_key_t_file.write(public_key_data);
|
||||
public_key_t_file.flush();
|
||||
public_key_t_file.seek(0);
|
||||
|
||||
FILE *pubring = fdopen(public_key_t_file.handle(), "rb");
|
||||
if (pubring == nullptr)
|
||||
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
|
||||
if (pubring == nullptr) {
|
||||
GFModuleTriggerModuleEventCallback(
|
||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
||||
ConvertMapToParams(
|
||||
{{"ret", "-1"},
|
||||
{"reason", "unable to convert QTemporaryFile to FILE*"}}));
|
||||
return -1;
|
||||
}
|
||||
|
||||
QByteArray secrets_data =
|
||||
QByteArray::fromBase64(event["paper_key_secrets"].toLatin1());
|
||||
QByteArray::fromBase64(event["paper_key_secrets"].toUtf8());
|
||||
|
||||
QTemporaryFile secrets_data_t_file;
|
||||
if (!secrets_data_t_file.open())
|
||||
CB_ERR(event, -1, "unable to open temporary file");
|
||||
QTemporaryFile secrets_data_file;
|
||||
if (!secrets_data_file.open()) {
|
||||
GFModuleTriggerModuleEventCallback(
|
||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
||||
ConvertMapToParams(
|
||||
{{"ret", "-1"}, {"reason", "unable to open temporary file"}}));
|
||||
return -1;
|
||||
}
|
||||
|
||||
secrets_data_t_file.write(secrets_data);
|
||||
secrets_data_t_file.flush();
|
||||
secrets_data_t_file.reset();
|
||||
secrets_data_file.write(public_key_data);
|
||||
secrets_data_file.flush();
|
||||
secrets_data_file.seek(0);
|
||||
|
||||
FILE *secrets_fp = fdopen(secrets_data_t_file.handle(), "r");
|
||||
if (secrets_fp == nullptr)
|
||||
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
|
||||
FILE *secrets = fdopen(secrets_data_file.handle(), "rb");
|
||||
if (secrets == nullptr) {
|
||||
GFModuleTriggerModuleEventCallback(
|
||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
||||
ConvertMapToParams(
|
||||
{{"ret", "-1"},
|
||||
{"reason", "unable to convert QTemporaryFile to FILE*"}}));
|
||||
return -1;
|
||||
}
|
||||
|
||||
QTemporaryFile secret_key_t_file;
|
||||
if (!secret_key_t_file.open())
|
||||
CB_ERR(event, -1, "unable to open temporary file");
|
||||
|
||||
FILE *secret_key_fp = fdopen(dup(secret_key_t_file.handle()), "wb");
|
||||
if (secret_key_fp == nullptr)
|
||||
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
|
||||
|
||||
auto ret = restore(pubring, secrets_fp, AUTO, secret_key_fp);
|
||||
secret_key_t_file.reset();
|
||||
FLOG_DEBUG("secret key temp file size: %1, ret: %2",
|
||||
secret_key_t_file.size(), ret);
|
||||
|
||||
CB(event, GFGetModuleID(),
|
||||
{
|
||||
{"ret", QString::number(ret)},
|
||||
{"secret_key",
|
||||
QString::fromLocal8Bit(secret_key_t_file.readAll().toBase64())},
|
||||
});
|
||||
|
||||
return ret;
|
||||
restore(pubring, secrets, AUTO, )
|
||||
}
|
||||
|
||||
CB_SUCC(event);
|
||||
GFModuleTriggerModuleEventCallback(ConvertMapToEvent(event), GFGetModuleID(),
|
||||
1, ConvertMapToParams({{"ret", "0"}}));
|
||||
return 0;
|
||||
}
|
||||
END_EXECUTE_MODULE()
|
||||
|
||||
auto GFDeactivateModule() -> int { return 0; }
|
||||
auto GFDeactiveModule() -> int { return 0; }
|
||||
|
||||
auto GFUnregisterModule() -> int {
|
||||
MLogDebug("paper key module unregistering");
|
||||
|
@ -28,6 +28,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GFModuleDeclare.h"
|
||||
#include <GFSDKModule.h>
|
||||
|
||||
GF_MODULE_API_DECLARE
|
||||
#include "GFModuleExport.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFRegisterModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFActiveModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFDeactiveModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
|
||||
};
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
extern int verbose;
|
||||
|
||||
int extract(FILE *input, FILE *output, enum data_type output_type) {
|
||||
int extract(FILE *input, const char *outname, enum data_type output_type) {
|
||||
struct packet *packet;
|
||||
int offset;
|
||||
unsigned char fingerprint[20];
|
||||
@ -51,7 +51,7 @@ int extract(FILE *input, FILE *output, enum data_type output_type) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
output_start(output, output_type, fingerprint);
|
||||
output_start(outname, output_type, fingerprint);
|
||||
output_bytes(&version, 1);
|
||||
output_bytes(packet->buf, 1);
|
||||
output_bytes(fingerprint, 20);
|
||||
@ -83,7 +83,6 @@ int extract(FILE *input, FILE *output, enum data_type output_type) {
|
||||
}
|
||||
|
||||
output_finish();
|
||||
output_end();
|
||||
|
||||
if (input == stdin) {
|
||||
/* Consume everything else on input */
|
||||
|
@ -22,4 +22,5 @@
|
||||
|
||||
#include "output.h"
|
||||
|
||||
auto extract(FILE *input, FILE *output, enum data_type output_type) -> int;
|
||||
auto extract(FILE *input, const char *outname,
|
||||
enum data_type output_type) -> int;
|
||||
|
@ -147,42 +147,6 @@ void output_file_format(FILE *stream, const char *prefix) {
|
||||
fprintf(stream, "%smay simply be copied from the public key.\n", prefix);
|
||||
}
|
||||
|
||||
int output_start(FILE *fp, enum data_type type, unsigned char fingerprint[20]) {
|
||||
output = fp;
|
||||
if (!output) return -1;
|
||||
|
||||
output_type = type;
|
||||
|
||||
switch (type) {
|
||||
case RAW:
|
||||
break;
|
||||
|
||||
case AUTO:
|
||||
case BASE16: {
|
||||
time_t now = time(NULL);
|
||||
|
||||
line_items = (output_width - 5 - 6) / 3;
|
||||
fprintf(output, "# Secret portions of key ");
|
||||
print_bytes(output, fingerprint, 20);
|
||||
fprintf(output, "\n");
|
||||
fprintf(output, "# Base16 data extracted %.24s\n", ctime(&now));
|
||||
fprintf(output,
|
||||
"# Created with "
|
||||
"Paper Key Module of GpgFrontend"
|
||||
" by Saturneric\n#\n");
|
||||
output_file_format(output, "# ");
|
||||
fprintf(output,
|
||||
"#\n# Each base16 line ends with a CRC-24 of that line.\n");
|
||||
fprintf(output,
|
||||
"# The entire block of data ends with a CRC-24 of the entire "
|
||||
"block of data.\n\n");
|
||||
// if (comment != nullptr) fprintf(output, "# %s\n\n", comment);
|
||||
} break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int output_start(const char *name, enum data_type type,
|
||||
unsigned char fingerprint[20]) {
|
||||
if (name) {
|
||||
@ -322,13 +286,9 @@ ssize_t output_openpgp_header(unsigned char tag, size_t length) {
|
||||
return output_bytes(encoded, bytes);
|
||||
}
|
||||
|
||||
void output_finish(void) { output_bytes(nullptr, 0); }
|
||||
|
||||
void output_end() {
|
||||
if (output != nullptr) {
|
||||
fflush(output);
|
||||
fclose(output);
|
||||
}
|
||||
void output_finish(void) {
|
||||
output_bytes(nullptr, 0);
|
||||
if (output != nullptr && output != stdout) fclose(output);
|
||||
}
|
||||
|
||||
void set_binary_mode(FILE *stream) {
|
||||
|
@ -29,11 +29,9 @@ void print_bytes(FILE *stream, const unsigned char *buf, size_t length);
|
||||
void output_file_format(FILE *stream, const char *prefix);
|
||||
int output_start(const char *name, enum data_type type,
|
||||
unsigned char fingerprint[20]);
|
||||
int output_start(FILE *fp, enum data_type type, unsigned char fingerprint[20]);
|
||||
ssize_t output_bytes(const unsigned char *buf, size_t length);
|
||||
#define output_packet(_packet) output_bytes((_packet)->buf, (_packet)->len)
|
||||
ssize_t output_length16(size_t length);
|
||||
ssize_t output_openpgp_header(unsigned char tag, size_t length);
|
||||
void output_finish(void);
|
||||
void set_binary_mode(FILE *stream);
|
||||
void output_end();
|
||||
|
@ -98,7 +98,7 @@ static void free_keys(struct key *key) {
|
||||
}
|
||||
|
||||
auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
|
||||
FILE *output) -> int {
|
||||
const char *outname) -> int {
|
||||
struct packet *secret;
|
||||
|
||||
if (input_type == AUTO) {
|
||||
@ -128,7 +128,7 @@ auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
|
||||
|
||||
keys = extract_keys(secret);
|
||||
if (keys) {
|
||||
output_start(output, RAW, NULL);
|
||||
output_start(outname, RAW, NULL);
|
||||
|
||||
while ((pubkey = parse(pubring, 0, 0))) {
|
||||
unsigned char ptag;
|
||||
@ -168,7 +168,6 @@ auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
|
||||
}
|
||||
|
||||
free_keys(keys);
|
||||
output_end();
|
||||
} else {
|
||||
fprintf(stderr, "Unable to parse secret data\n");
|
||||
return 1;
|
||||
|
@ -22,6 +22,6 @@
|
||||
#include "output.h"
|
||||
|
||||
auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
|
||||
FILE *output) -> int;
|
||||
const char *outname) -> int;
|
||||
|
||||
#endif /* !_RESTORE_H_ */
|
||||
|
@ -33,12 +33,27 @@
|
||||
#include <qthread.h>
|
||||
|
||||
#include "GFModuleCommonUtils.hpp"
|
||||
#include "GFModuleDefine.h"
|
||||
#include "GFSDKBuildInfo.h"
|
||||
#include "GpgPassphraseContext.h"
|
||||
#include "RaisePinentry.h"
|
||||
|
||||
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.pinentry", "Pinentry",
|
||||
"1.0.0", "A simple tiny pinentry.", "Saturneric")
|
||||
auto GFGetModuleGFSDKVersion() -> const char * {
|
||||
return DUP(GF_SDK_VERSION_STR);
|
||||
}
|
||||
|
||||
auto GFGetModuleQtEnvVersion() -> const char * { return DUP(QT_VERSION_STR); }
|
||||
|
||||
auto GFGetModuleID() -> const char * {
|
||||
return DUP("com.bktus.gpgfrontend.module.pinentry");
|
||||
}
|
||||
|
||||
auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); }
|
||||
|
||||
auto GFGetModuleMetaData() -> GFModuleMetaData * {
|
||||
return QMapToGFModuleMetaDataList({{"Name", "Pinentry"},
|
||||
{"Description", "A simple tiny pinentry."},
|
||||
{"Author", "Saturneric"}});
|
||||
}
|
||||
|
||||
auto GFRegisterModule() -> int {
|
||||
MLogDebug("pinentry module registering");
|
||||
@ -47,7 +62,9 @@ auto GFRegisterModule() -> int {
|
||||
}
|
||||
|
||||
auto GFActiveModule() -> int {
|
||||
LISTEN("REQUEST_PIN_ENTRY");
|
||||
MLogDebug("pinentry module activating");
|
||||
|
||||
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_PIN_ENTRY"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -57,13 +74,6 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
||||
|
||||
auto event = ConvertEventToMap(p_event);
|
||||
|
||||
if (event["prev_was_bad"].isEmpty() || event["ask_for_new"].isEmpty()) {
|
||||
GFModuleTriggerModuleEventCallback(
|
||||
ConvertMapToEvent(event), GFGetModuleID(),
|
||||
ConvertMapToParams({{"ret", "-1"}, {"passphrase", ""}}));
|
||||
return -1;
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
QApplication::instance()->thread(), [p_event, event]() -> int {
|
||||
auto *p = new RaisePinentry(
|
||||
@ -76,7 +86,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
||||
p, &RaisePinentry::SignalUserInputPassphraseCallback, p,
|
||||
[event](const QSharedPointer<GpgPassphraseContext> &c) {
|
||||
GFModuleTriggerModuleEventCallback(
|
||||
ConvertMapToEvent(event), GFGetModuleID(),
|
||||
ConvertMapToEvent(event), GFGetModuleID(), 1,
|
||||
ConvertMapToParams({{"passphrase", c->GetPassphrase()}}));
|
||||
});
|
||||
|
||||
@ -87,7 +97,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto GFDeactivateModule() -> int { return 0; }
|
||||
auto GFDeactiveModule() -> int { return 0; }
|
||||
|
||||
auto GFUnregisterModule() -> int {
|
||||
MLogDebug("pinentry module unregistering");
|
||||
|
@ -28,6 +28,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GFModuleDeclare.h"
|
||||
#include <GFSDKModule.h>
|
||||
|
||||
GF_MODULE_API_DECLARE
|
||||
#include "GFModuleExport.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFRegisterModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFActiveModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFDeactiveModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
|
||||
};
|
@ -38,13 +38,32 @@
|
||||
#include <QtNetwork>
|
||||
|
||||
#include "GFModuleCommonUtils.hpp"
|
||||
#include "GFModuleDefine.h"
|
||||
#include "SoftwareVersion.h"
|
||||
#include "UpdateTab.h"
|
||||
#include "VersionCheckTask.h"
|
||||
|
||||
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.VersionChecking", "Pinentry",
|
||||
"1.0.0", "Try checking GpgFrontend version.", "Saturneric")
|
||||
class GTrC {
|
||||
Q_DECLARE_TR_FUNCTIONS(GTrC)
|
||||
};
|
||||
|
||||
auto GFGetModuleGFSDKVersion() -> const char* {
|
||||
return DUP(GF_SDK_VERSION_STR);
|
||||
}
|
||||
|
||||
auto GFGetModuleQtEnvVersion() -> const char* { return DUP(QT_VERSION_STR); }
|
||||
|
||||
auto GFGetModuleID() -> const char* {
|
||||
return DUP("com.bktus.gpgfrontend.module.version_checking");
|
||||
}
|
||||
|
||||
auto GFGetModuleVersion() -> const char* { return DUP("1.0.0"); }
|
||||
|
||||
auto GFGetModuleMetaData() -> GFModuleMetaData* {
|
||||
return QMapToGFModuleMetaDataList(
|
||||
{{"Name", "VersionChecking"},
|
||||
{"Description", "Try checking GpgFrontend version."},
|
||||
{"Author", "Saturneric"}});
|
||||
}
|
||||
|
||||
auto GFRegisterModule() -> int {
|
||||
MLogInfo("version checking module registering");
|
||||
@ -54,15 +73,15 @@ auto GFRegisterModule() -> int {
|
||||
auto GFActiveModule() -> int {
|
||||
MLogInfo("version checking module activating");
|
||||
|
||||
LISTEN("APPLICATION_LOADED");
|
||||
LISTEN("CHECK_APPLICATION_VERSION");
|
||||
GFModuleListenEvent(GFGetModuleID(), DUP("APPLICATION_LOADED"));
|
||||
GFModuleListenEvent(GFGetModuleID(), DUP("CHECK_APPLICATION_VERSION"));
|
||||
|
||||
// load translations
|
||||
QFile f(
|
||||
QString(":/i18n/ModuleVersionChecking.%1.qm").arg(GFAppActiveLocale()));
|
||||
if (f.exists() && f.open(QIODevice::ReadOnly)) {
|
||||
auto f_n = f.fileName().toUtf8();
|
||||
FLOG_INFO("version checking module loading, locale: %1, path: %2",
|
||||
MLogInfoS("version checking module loading, locale: %s, path: %s",
|
||||
GFAppActiveLocale(), f_n.data());
|
||||
auto b = f.readAll();
|
||||
GFAppRegisterTranslator(AllocBufferAndCopy(b), b.size());
|
||||
@ -75,22 +94,23 @@ auto GFActiveModule() -> int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXECUTE_MODULE() {
|
||||
FLOG_INFO("version checking module executing, event id: %s",
|
||||
event["event_id"]);
|
||||
auto GFExecuteModule(GFModuleEvent* event) -> int {
|
||||
MLogInfoS("version checking module executing, event id: %s", event->id);
|
||||
|
||||
auto* task = new VersionCheckTask();
|
||||
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion,
|
||||
QThread::currentThread(),
|
||||
[event](const SoftwareVersion&) { CB_SUCC(event); });
|
||||
QThread::currentThread(), [event](const SoftwareVersion&) {
|
||||
GFModuleTriggerModuleEventCallback(
|
||||
event, GFGetModuleID(), 1,
|
||||
ConvertMapToParams({{"ret", "0"}}));
|
||||
});
|
||||
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion, task,
|
||||
&QObject::deleteLater);
|
||||
task->Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
END_EXECUTE_MODULE()
|
||||
|
||||
auto GFDeactivateModule() -> int { return 0; }
|
||||
auto GFDeactiveModule() -> int { return 0; }
|
||||
|
||||
auto GFUnregisterModule() -> int { return 0; }
|
@ -28,6 +28,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GFModuleDeclare.h"
|
||||
#include <GFSDKModule.h>
|
||||
|
||||
GF_MODULE_API_DECLARE
|
||||
#include "GFModuleExport.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleID() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *;
|
||||
|
||||
auto GF_MODULE_EXPORT GFRegisterModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFActiveModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFDeactiveModule() -> int;
|
||||
|
||||
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user