Compare commits

...

3 Commits

17 changed files with 335 additions and 309 deletions

View File

@ -43,17 +43,45 @@
#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 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__))
#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__))
inline auto QStrDup(QString str) -> char* { return DUP(str.toUtf8()); }
@ -179,6 +207,12 @@ 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());
@ -261,3 +295,22 @@ 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...);
}

47
include/GFModuleDeclare.h Normal file
View File

@ -0,0 +1,47 @@
/**
* 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; \
};

49
include/GFModuleDefine.h Normal file
View File

@ -0,0 +1,49 @@
/**
* 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)}}); \
}

View File

@ -43,11 +43,12 @@
#include <optional>
#include "GFModuleCommonUtils.hpp"
#include "GFModuleDefine.h"
#include "GpgInfo.h"
class GTrC {
Q_DECLARE_TR_FUNCTIONS(GTrC)
};
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.gnupg_info_gathering",
"GatherGnupgInfo", "1.0.0",
"Try gathering gnupg informations.", "Saturneric")
extern auto CalculateBinaryChacksum(const QString &path)
-> std::optional<QString>;
@ -68,25 +69,6 @@ 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");
@ -98,25 +80,21 @@ auto GFRegisterModule() -> int {
}
auto GFActiveModule() -> int {
MLogDebug("gnupg info gathering module activating");
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_GATHERING_GNUPG_INFO"));
LISTEN("REQUEST_GATHERING_GNUPG_INFO");
return 0;
}
auto GFExecuteModule(GFModuleEvent *event) -> int {
MLogDebug(QString("gnupg info gathering module executing, event id: %1")
.arg(event->id));
EXECUTE_MODULE() {
FLOG_DEBUG("gnupg info gathering module executing, event id: %1",
event["event_id"]);
StartGatheringGnuPGInfo();
GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1,
ConvertMapToParams({{"ret", "0"}}));
MLogDebug("gnupg external info gathering done");
return 0;
CB_SUCC(event);
}
END_EXECUTE_MODULE()
auto GFDeactiveModule() -> int { return 0; }
auto GFDeactivateModule() -> int { return 0; }
auto GFUnregisterModule() -> int {
MLogDebug("gnupg info gathering module unregistering");

View File

@ -28,29 +28,6 @@
#pragma once
#include <GFSDKModule.h>
#include "GFModuleDeclare.h"
#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;
};
GF_MODULE_API_DECLARE

View File

@ -28,154 +28,132 @@
#include "PaperKeyModule.h"
#include <unistd.h>
#include <QtCore>
#include "GFModuleCommonUtils.hpp"
#include "GFSDKBuildInfo.h"
#include "GFModuleDefine.h"
#include "extract.h"
#include "restore.h"
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"}});
}
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.paper_key", "PaperKey",
"1.0.0", "Integrated PaperKey Functions.", "Saturneric")
auto GFRegisterModule() -> int {
MLogDebug("paper key module registering");
LOG_DEBUG("paper key module registering");
return 0;
}
auto GFActiveModule() -> int {
MLogDebug("paper key module activating");
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_KEY_2_PAPER_KEY"));
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_PAPER_KEY_2_KEY"));
LISTEN("REQUEST_TRANS_KEY_2_PAPER_KEY");
LISTEN("REQUEST_TRANS_PAPER_KEY_2_KEY");
return 0;
}
auto GFExecuteModule(GFModuleEvent *p_event) -> int {
MLogDebug(
QString("paper key module executing, event id: %1").arg(p_event->id));
auto event = ConvertEventToMap(p_event);
EXECUTE_MODULE() {
FLOG_DEBUG("paper key module executing, event id: %1", event["event_id"]);
if (event["event_id"] == "REQUEST_TRANS_KEY_2_PAPER_KEY") {
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;
}
if (event["secret_key"].isEmpty()) CB_ERR(event, -1, "secret key is empty");
QByteArray secret_key_data =
QByteArray::fromBase64(event["secret_key"].toUtf8());
QByteArray secret_key_rdata =
QByteArray::fromBase64(event["secret_key"].toLatin1());
QTemporaryFile secret_key_t_file;
if (!secret_key_t_file.open()) {
qWarning() << "Unable to open temporary file";
MLogWarn("unable to open temporary file");
return -1;
}
if (!secret_key_t_file.open())
CB_ERR(event, -1, "unable to open temporary file");
secret_key_t_file.write(secret_key_data);
secret_key_t_file.write(secret_key_rdata);
secret_key_t_file.flush();
secret_key_t_file.seek(0);
secret_key_t_file.reset();
FILE *file = fdopen(secret_key_t_file.handle(), "rb");
if (file == nullptr) {
qDebug() << "Unable to convert QTemporaryFile to FILE*";
return -1;
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*");
QTemporaryFile paper_key_t_file;
if (!paper_key_t_file.open())
CB_ERR(event, -1, "unable to open temporary file");
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;
}
extract(file, event["output_path"].toUtf8(), AUTO);
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;
}
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");
QByteArray public_key_data =
QByteArray::fromBase64(event["public_key"].toUtf8());
QByteArray::fromBase64(event["public_key"].toLatin1());
QTemporaryFile public_key_t_file;
if (!public_key_t_file.open()) {
GFModuleTriggerModuleEventCallback(
ConvertMapToEvent(event), GFGetModuleID(), 1,
ConvertMapToParams(
{{"ret", "-1"}, {"reason", "unable to open temporary file"}}));
return -1;
}
if (!public_key_t_file.open())
CB_ERR(event, -1, "unable to open temporary file");
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) {
GFModuleTriggerModuleEventCallback(
ConvertMapToEvent(event), GFGetModuleID(), 1,
ConvertMapToParams(
{{"ret", "-1"},
{"reason", "unable to convert QTemporaryFile to FILE*"}}));
return -1;
}
if (pubring == nullptr)
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
QByteArray secrets_data =
QByteArray::fromBase64(event["paper_key_secrets"].toUtf8());
QByteArray::fromBase64(event["paper_key_secrets"].toLatin1());
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;
QTemporaryFile secrets_data_t_file;
if (!secrets_data_t_file.open())
CB_ERR(event, -1, "unable to open temporary file");
secrets_data_t_file.write(secrets_data);
secrets_data_t_file.flush();
secrets_data_t_file.reset();
FILE *secrets_fp = fdopen(secrets_data_t_file.handle(), "r");
if (secrets_fp == nullptr)
CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*");
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;
}
secrets_data_file.write(public_key_data);
secrets_data_file.flush();
secrets_data_file.seek(0);
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;
}
restore(pubring, secrets, AUTO, )
}
GFModuleTriggerModuleEventCallback(ConvertMapToEvent(event), GFGetModuleID(),
1, ConvertMapToParams({{"ret", "0"}}));
return 0;
CB_SUCC(event);
}
END_EXECUTE_MODULE()
auto GFDeactiveModule() -> int { return 0; }
auto GFDeactivateModule() -> int { return 0; }
auto GFUnregisterModule() -> int {
MLogDebug("paper key module unregistering");

View File

@ -28,29 +28,6 @@
#pragma once
#include <GFSDKModule.h>
#include "GFModuleDeclare.h"
#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;
};
GF_MODULE_API_DECLARE

View File

@ -26,7 +26,7 @@
extern int verbose;
int extract(FILE *input, const char *outname, enum data_type output_type) {
int extract(FILE *input, FILE *output, enum data_type output_type) {
struct packet *packet;
int offset;
unsigned char fingerprint[20];
@ -51,7 +51,7 @@ int extract(FILE *input, const char *outname, enum data_type output_type) {
fprintf(stderr, "\n");
}
output_start(outname, output_type, fingerprint);
output_start(output, output_type, fingerprint);
output_bytes(&version, 1);
output_bytes(packet->buf, 1);
output_bytes(fingerprint, 20);
@ -83,6 +83,7 @@ int extract(FILE *input, const char *outname, enum data_type output_type) {
}
output_finish();
output_end();
if (input == stdin) {
/* Consume everything else on input */

View File

@ -22,5 +22,4 @@
#include "output.h"
auto extract(FILE *input, const char *outname,
enum data_type output_type) -> int;
auto extract(FILE *input, FILE *output, enum data_type output_type) -> int;

View File

@ -147,6 +147,42 @@ 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) {
@ -286,9 +322,13 @@ ssize_t output_openpgp_header(unsigned char tag, size_t length) {
return output_bytes(encoded, bytes);
}
void output_finish(void) {
output_bytes(nullptr, 0);
if (output != nullptr && output != stdout) fclose(output);
void output_finish(void) { output_bytes(nullptr, 0); }
void output_end() {
if (output != nullptr) {
fflush(output);
fclose(output);
}
}
void set_binary_mode(FILE *stream) {

View File

@ -29,9 +29,11 @@ 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();

View File

@ -98,7 +98,7 @@ static void free_keys(struct key *key) {
}
auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
const char *outname) -> int {
FILE *output) -> 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(outname, RAW, NULL);
output_start(output, RAW, NULL);
while ((pubkey = parse(pubring, 0, 0))) {
unsigned char ptag;
@ -168,6 +168,7 @@ 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;

View File

@ -22,6 +22,6 @@
#include "output.h"
auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
const char *outname) -> int;
FILE *output) -> int;
#endif /* !_RESTORE_H_ */

View File

@ -33,27 +33,12 @@
#include <qthread.h>
#include "GFModuleCommonUtils.hpp"
#include "GFSDKBuildInfo.h"
#include "GFModuleDefine.h"
#include "GpgPassphraseContext.h"
#include "RaisePinentry.h"
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"}});
}
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.pinentry", "Pinentry",
"1.0.0", "A simple tiny pinentry.", "Saturneric")
auto GFRegisterModule() -> int {
MLogDebug("pinentry module registering");
@ -62,9 +47,7 @@ auto GFRegisterModule() -> int {
}
auto GFActiveModule() -> int {
MLogDebug("pinentry module activating");
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_PIN_ENTRY"));
LISTEN("REQUEST_PIN_ENTRY");
return 0;
}
@ -74,6 +57,13 @@ 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(
@ -86,7 +76,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
p, &RaisePinentry::SignalUserInputPassphraseCallback, p,
[event](const QSharedPointer<GpgPassphraseContext> &c) {
GFModuleTriggerModuleEventCallback(
ConvertMapToEvent(event), GFGetModuleID(), 1,
ConvertMapToEvent(event), GFGetModuleID(),
ConvertMapToParams({{"passphrase", c->GetPassphrase()}}));
});
@ -97,7 +87,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int {
return 0;
}
auto GFDeactiveModule() -> int { return 0; }
auto GFDeactivateModule() -> int { return 0; }
auto GFUnregisterModule() -> int {
MLogDebug("pinentry module unregistering");

View File

@ -28,29 +28,6 @@
#pragma once
#include <GFSDKModule.h>
#include "GFModuleDeclare.h"
#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;
};
GF_MODULE_API_DECLARE

View File

@ -38,32 +38,13 @@
#include <QtNetwork>
#include "GFModuleCommonUtils.hpp"
#include "GFModuleDefine.h"
#include "SoftwareVersion.h"
#include "UpdateTab.h"
#include "VersionCheckTask.h"
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"}});
}
GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.VersionChecking", "Pinentry",
"1.0.0", "Try checking GpgFrontend version.", "Saturneric")
auto GFRegisterModule() -> int {
MLogInfo("version checking module registering");
@ -73,15 +54,15 @@ auto GFRegisterModule() -> int {
auto GFActiveModule() -> int {
MLogInfo("version checking module activating");
GFModuleListenEvent(GFGetModuleID(), DUP("APPLICATION_LOADED"));
GFModuleListenEvent(GFGetModuleID(), DUP("CHECK_APPLICATION_VERSION"));
LISTEN("APPLICATION_LOADED");
LISTEN("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();
MLogInfoS("version checking module loading, locale: %s, path: %s",
FLOG_INFO("version checking module loading, locale: %1, path: %2",
GFAppActiveLocale(), f_n.data());
auto b = f.readAll();
GFAppRegisterTranslator(AllocBufferAndCopy(b), b.size());
@ -94,23 +75,22 @@ auto GFActiveModule() -> int {
return 0;
}
auto GFExecuteModule(GFModuleEvent* event) -> int {
MLogInfoS("version checking module executing, event id: %s", event->id);
EXECUTE_MODULE() {
FLOG_INFO("version checking module executing, event id: %s",
event["event_id"]);
auto* task = new VersionCheckTask();
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion,
QThread::currentThread(), [event](const SoftwareVersion&) {
GFModuleTriggerModuleEventCallback(
event, GFGetModuleID(), 1,
ConvertMapToParams({{"ret", "0"}}));
});
QThread::currentThread(),
[event](const SoftwareVersion&) { CB_SUCC(event); });
QObject::connect(task, &VersionCheckTask::SignalUpgradeVersion, task,
&QObject::deleteLater);
task->Run();
return 0;
}
END_EXECUTE_MODULE()
auto GFDeactiveModule() -> int { return 0; }
auto GFDeactivateModule() -> int { return 0; }
auto GFUnregisterModule() -> int { return 0; }

View File

@ -28,29 +28,6 @@
#pragma once
#include <GFSDKModule.h>
#include "GFModuleDeclare.h"
#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;
};
GF_MODULE_API_DECLARE