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 UDUP(v) UnStrDup(v)
#define QDUP(v) QStrDup(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 MLogDebug(const QString& s) { GFModuleLogDebug(s.toUtf8()); }
inline void MLogInfo(const QString& s) { GFModuleLogInfo(s.toUtf8()); } inline void MLogInfo(const QString& s) { GFModuleLogInfo(s.toUtf8()); }
inline void MLogWarn(const QString& s) { GFModuleLogWarn(s.toUtf8()); } inline void MLogWarn(const QString& s) { GFModuleLogWarn(s.toUtf8()); }
inline void MLogError(const QString& s) { GFModuleLogError(s.toUtf8()); } inline void MLogError(const QString& s) { GFModuleLogError(s.toUtf8()); }
#define MLogDebugS(format, ...) \ #define LOG_DEBUG(format) MLogDebug(FormatString(QString(format)))
MLogDebug(QString::asprintf(format, __VA_ARGS__)) #define LOG_INFO(format) MLogDebug(FormatString(QString(format)))
#define MLogInfoS(format, ...) MLogInfo(QString::asprintf(format, __VA_ARGS__)) #define LOG_WARN(format) MLogDebug(FormatString(QString(format)))
#define MLogWarnS(format, ...) MLogWarn(QString::asprintf(format, __VA_ARGS__)) #define LOG_ERROR(format) MLogDebug(FormatString(QString(format)))
#define MLogErrorS(format, ...) \
MLogError(QString::asprintf(format, __VA_ARGS__)) #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()); } inline auto QStrDup(QString str) -> char* { return DUP(str.toUtf8()); }
@ -179,6 +207,12 @@ inline auto ConvertMapToEvent(QMap<QString, QString> event_map)
return event; 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* { inline auto AllocBufferAndCopy(const QByteArray& b) -> char* {
auto* p = static_cast<char*>(GFAllocateMemory(sizeof(char) * b.size())); auto* p = static_cast<char*>(GFAllocateMemory(sizeof(char) * b.size()));
memcpy(p, b.constData(), b.size()); memcpy(p, b.constData(), b.size());
@ -261,3 +295,22 @@ inline auto CharArrayToQStringList(char** pl_components,
GFFreeMemory(pl_components); GFFreeMemory(pl_components);
return list; 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 <optional>
#include "GFModuleCommonUtils.hpp" #include "GFModuleCommonUtils.hpp"
#include "GFModuleDefine.h"
#include "GpgInfo.h" #include "GpgInfo.h"
class GTrC { GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.gnupg_info_gathering",
Q_DECLARE_TR_FUNCTIONS(GTrC) "GatherGnupgInfo", "1.0.0",
}; "Try gathering gnupg informations.", "Saturneric")
extern auto CalculateBinaryChacksum(const QString &path) extern auto CalculateBinaryChacksum(const QString &path)
-> std::optional<QString>; -> std::optional<QString>;
@ -68,25 +69,6 @@ using Context = struct {
GpgComponentInfo component_info; 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 { auto GFRegisterModule() -> int {
MLogDebug("gnupg info gathering module registering"); MLogDebug("gnupg info gathering module registering");
@ -98,25 +80,21 @@ auto GFRegisterModule() -> int {
} }
auto GFActiveModule() -> int { auto GFActiveModule() -> int {
MLogDebug("gnupg info gathering module activating"); LISTEN("REQUEST_GATHERING_GNUPG_INFO");
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_GATHERING_GNUPG_INFO"));
return 0; return 0;
} }
auto GFExecuteModule(GFModuleEvent *event) -> int { EXECUTE_MODULE() {
MLogDebug(QString("gnupg info gathering module executing, event id: %1") FLOG_DEBUG("gnupg info gathering module executing, event id: %1",
.arg(event->id)); event["event_id"]);
StartGatheringGnuPGInfo(); StartGatheringGnuPGInfo();
GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1, CB_SUCC(event);
ConvertMapToParams({{"ret", "0"}}));
MLogDebug("gnupg external info gathering done");
return 0;
} }
END_EXECUTE_MODULE()
auto GFDeactiveModule() -> int { return 0; } auto GFDeactivateModule() -> int { return 0; }
auto GFUnregisterModule() -> int { auto GFUnregisterModule() -> int {
MLogDebug("gnupg info gathering module unregistering"); MLogDebug("gnupg info gathering module unregistering");

View File

@ -28,29 +28,6 @@
#pragma once #pragma once
#include <GFSDKModule.h> #include "GFModuleDeclare.h"
#include "GFModuleExport.h" 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 GFDeactiveModule() -> int;
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
};

View File

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

View File

@ -28,29 +28,6 @@
#pragma once #pragma once
#include <GFSDKModule.h> #include "GFModuleDeclare.h"
#include "GFModuleExport.h" 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 GFDeactiveModule() -> int;
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
};

View File

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

View File

@ -22,5 +22,4 @@
#include "output.h" #include "output.h"
auto extract(FILE *input, const char *outname, auto extract(FILE *input, FILE *output, enum data_type output_type) -> int;
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); 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, int output_start(const char *name, enum data_type type,
unsigned char fingerprint[20]) { unsigned char fingerprint[20]) {
if (name) { if (name) {
@ -286,9 +322,13 @@ ssize_t output_openpgp_header(unsigned char tag, size_t length) {
return output_bytes(encoded, bytes); return output_bytes(encoded, bytes);
} }
void output_finish(void) { void output_finish(void) { output_bytes(nullptr, 0); }
output_bytes(nullptr, 0);
if (output != nullptr && output != stdout) fclose(output); void output_end() {
if (output != nullptr) {
fflush(output);
fclose(output);
}
} }
void set_binary_mode(FILE *stream) { 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); void output_file_format(FILE *stream, const char *prefix);
int output_start(const char *name, enum data_type type, int output_start(const char *name, enum data_type type,
unsigned char fingerprint[20]); 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); ssize_t output_bytes(const unsigned char *buf, size_t length);
#define output_packet(_packet) output_bytes((_packet)->buf, (_packet)->len) #define output_packet(_packet) output_bytes((_packet)->buf, (_packet)->len)
ssize_t output_length16(size_t length); ssize_t output_length16(size_t length);
ssize_t output_openpgp_header(unsigned char tag, size_t length); ssize_t output_openpgp_header(unsigned char tag, size_t length);
void output_finish(void); void output_finish(void);
void set_binary_mode(FILE *stream); 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, auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
const char *outname) -> int { FILE *output) -> int {
struct packet *secret; struct packet *secret;
if (input_type == AUTO) { if (input_type == AUTO) {
@ -128,7 +128,7 @@ auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
keys = extract_keys(secret); keys = extract_keys(secret);
if (keys) { if (keys) {
output_start(outname, RAW, NULL); output_start(output, RAW, NULL);
while ((pubkey = parse(pubring, 0, 0))) { while ((pubkey = parse(pubring, 0, 0))) {
unsigned char ptag; unsigned char ptag;
@ -168,6 +168,7 @@ auto restore(FILE *pubring, FILE *secrets, enum data_type input_type,
} }
free_keys(keys); free_keys(keys);
output_end();
} else { } else {
fprintf(stderr, "Unable to parse secret data\n"); fprintf(stderr, "Unable to parse secret data\n");
return 1; return 1;

View File

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

View File

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

View File

@ -28,29 +28,6 @@
#pragma once #pragma once
#include <GFSDKModule.h> #include "GFModuleDeclare.h"
#include "GFModuleExport.h" 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 GFDeactiveModule() -> int;
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
};

View File

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

View File

@ -28,29 +28,6 @@
#pragma once #pragma once
#include <GFSDKModule.h> #include "GFModuleDeclare.h"
#include "GFModuleExport.h" 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 GFDeactiveModule() -> int;
auto GF_MODULE_EXPORT GFUnregisterModule() -> int;
};