1
0

Compare commits

...

49 Commits

Author SHA1 Message Date
d3d94f5b7a Merge branch 'develop' 2025-02-03 19:01:26 +01:00
e2fa8ababc fix: set pb range when size of operas > 1 2025-02-03 18:56:26 +01:00
7ac78d887e fix: solve ui code generate issue 2025-02-03 18:24:32 +01:00
4606bb8aff fix: solve discovered issues 2025-02-03 18:04:49 +01:00
5acc1fda6f chore: remove setting 'basic/longer_expiration_date' 2025-02-03 17:37:37 +01:00
4eb12e9f85 chore: upgrade to v2.1.7 2025-02-03 17:27:30 +01:00
8dfd0c5a9b translation: update zh_CN and de_DE 2025-02-03 17:23:56 +01:00
dd8bca46a6 feat: allow switch ascii mode at file page options 2025-02-03 16:04:09 +01:00
39387a78e2 refactor: make some function names shorter 2025-02-02 21:03:21 +01:00
bec8f5e614 refactor: rewrite subkey generate dialog and fix some issues discovered 2025-02-02 19:43:46 +01:00
1e95a70ab3 feat: improve KeyGenerateDialog 2025-02-02 18:02:44 +01:00
cd4a1f749b fix: solve lower/upper case name conflict 2025-02-02 00:39:29 +01:00
d06c31abe7 feat: upgrade KeyGenDialog to meet easy and advanced requirements 2025-02-02 00:21:59 +01:00
e6b26c2fd5 fix: issues found on unit test mode 2025-02-01 20:08:19 +01:00
9379d105cd fix: use yyy-MM-dd format of create date on key list 2025-01-31 18:36:52 +01:00
0a8a116d2d refactor: code clean up 2025-01-28 00:14:21 +01:00
dbd145b5b6 fix: tiny fixes 2025-01-28 00:00:09 +01:00
7505b1131e refactor: clean up code and reduce duplication 2025-01-27 23:56:22 +01:00
992e861a86 fix: correct de_DE translations 2025-01-27 23:45:15 +01:00
341065b307 refactor: code clean up of main window 2025-01-27 23:32:29 +01:00
a66d868f50 refactor: reduce code duplication of gnupg operations 2025-01-27 23:12:00 +01:00
1b9715dd43 refactor: reduce code duplication of gnupg file operations 2025-01-27 21:44:32 +01:00
fb2e47db7b refactor: reduce code duplication 2025-01-27 19:59:29 +01:00
64311a8abf feat: upgrade gnupg info gathering module to v1.2.1 2025-01-27 18:22:15 +01:00
a0cafd633d feat: check gpg components before start 2025-01-27 18:21:01 +01:00
e17837f898 fix: 'kCrashCode' is not a member of 'GpgFrontend' 2025-01-27 17:07:22 +01:00
a5ab3a611c fix: member variable 'GpgOperaContext::ascii' is not initialized in the constructor 2025-01-27 16:55:30 +01:00
5d2b02097e refactor: clean up code 2025-01-27 16:51:27 +01:00
af1870fd42 fix: kill all gnupg daemons in a proper way 2025-01-27 16:39:09 +01:00
bd0bfe63e7 feat: allow changing sort options by ui at file page
Some checks failed
Develop CI Qt5 / build (push) Failing after 7m11s
Develop CI Qt6 / build (push) Failing after 11m13s
2025-01-26 20:51:16 +01:00
2572aba1de feat: users can choose which crypto tool bar buttons are displayed
Some checks failed
Develop CI Qt5 / build (push) Failing after 1m54s
Develop CI Qt6 / build (push) Has been cancelled
2025-01-26 20:39:51 +01:00
3aa7e32214 feat: add ui ability to switch batch mode
Some checks failed
Develop CI Qt5 / build (push) Failing after 3m29s
Develop CI Qt6 / build (push) Failing after 8m40s
2025-01-26 19:52:33 +01:00
731ec7339d fix: improve code compatibility 2025-01-26 19:40:43 +01:00
8e7d3d6ac7 fix: optimums unknown fpr verifying helper 2025-01-26 19:33:11 +01:00
92e1ed7b3f feat: allow file batch operations
Some checks failed
Develop CI Qt6 / build (push) Failing after 2m5s
Develop CI Qt5 / build (push) Failing after 3m4s
2025-01-26 19:18:10 +01:00
73bb05c4d9 fix: 'std::future' is defined in header '<future>' 2025-01-26 15:19:22 +01:00
eb0218680d feat: relative path by default at portable mode
Some checks failed
Develop CI Qt5 / build (push) Failing after 3m49s
Develop CI Qt6 / build (push) Failing after 9m35s
2025-01-22 00:05:16 +01:00
a81dc7a018 fix: create app config path if possible
Some checks failed
Develop CI Qt6 / build (push) Has been cancelled
Develop CI Qt5 / build (push) Has been cancelled
2025-01-22 00:02:07 +01:00
56140c6bdc fix: make app fully portable
Some checks failed
Develop CI Qt5 / build (push) Has been cancelled
Develop CI Qt6 / build (push) Has been cancelled
2025-01-21 23:59:35 +01:00
3931b64fdd feat: enhance key db functions
Some checks failed
Develop CI Qt5 / build (push) Failing after 5m52s
Develop CI Qt6 / build (push) Failing after 11m37s
1. allow using relative key db path
2. allow editing default key db
3. use a key db in own directory at portable mode
2025-01-21 23:44:36 +01:00
348102421a Merge branch 'develop' into dev/2.1.6/main 2025-01-21 21:25:28 +01:00
bdb1d7fc5a ts: correct Italian translation 2024-12-22 18:59:57 +01:00
0330dda5f6 ts: update Italian translation 2024-12-21 18:59:48 +01:00
8ddcf78c10 fix: avoid check action triggering the show of key detail dialog 2024-12-21 04:12:07 +01:00
78d76b4547 fix: ResizeToContents behaviors of key list 2024-12-21 03:36:30 +01:00
ba79d77f5f fix: symbols link error on mingw64 2024-12-20 21:04:06 +01:00
ee3491860f fix: adjust the width of key list cell correctly 2024-12-20 20:44:31 +01:00
bd190d9b58 fix: try to add all platform plugins for AppImage 2024-12-13 22:37:30 +01:00
f7a00c58d2 refactor: using qt containers instead of std containers
Some checks failed
Develop CI Qt5 / build (push) Failing after 1m55s
Develop CI Qt6 / build (push) Successful in 7m16s
2024-12-13 16:22:33 +01:00
177 changed files with 14224 additions and 13784 deletions

View File

@ -274,7 +274,7 @@ jobs:
wget -c -nv https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage
chmod u+x linuxdeployqt-continuous-x86_64.AppImage
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
./linuxdeployqt-continuous-x86_64.AppImage ${{github.workspace}}/build/artifacts/AppDir/usr/share/applications/*.desktop -no-translations -extra-plugins=iconengines -appimage -executable-dir=${{github.workspace}}/build/artifacts/AppDir/usr/modules/
./linuxdeployqt-continuous-x86_64.AppImage ${{github.workspace}}/build/artifacts/AppDir/usr/share/applications/*.desktop -no-translations -extra-plugins=iconengines,platforms -appimage -executable-dir=${{github.workspace}}/build/artifacts/AppDir/usr/modules/
echo "BUILD_TYPE_LOWER=${BUILD_TYPE,,}" >> ${GITHUB_ENV}
echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> ${GITHUB_ENV}
if: runner.os == 'Linux'

View File

@ -36,7 +36,7 @@ endif()
# define project
project(GpgFrontend
VERSION 2.1.6
VERSION 2.1.7
DESCRIPTION "GpgFrontend is a free, open-source, robust yet user-friendly, compact and cross-platform tool for OpenPGP encryption."
HOMEPAGE_URL "https://gpgfrontend.bktus.com"
LANGUAGES CXX)

View File

@ -108,6 +108,9 @@
<file alias="export-email.png">resource/lfs/icons/export-email.png</file>
<file alias="warning-filling.png">resource/lfs/icons/warning-filling.png</file>
<file alias="upgrade.png">resource/lfs/icons/upgrade.png</file>
<file alias="batch.png">resource/lfs/icons/batch.png</file>
<file alias="encr-sign.png">resource/lfs/icons/encr-sign.png</file>
<file alias="decr-verify.png">resource/lfs/icons/decr-verify.png</file>
</qresource>
<qresource prefix="/test/key">
<file alias="pv1.key">resource/lfs/test/data/pv1.key</file>

@ -1 +1 @@
Subproject commit bbbbbf535f153c59bffa47b88c54e9f5107aa648
Subproject commit 22ba38aac5edbf85cc879fd611ef79b9f818544a

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,8 @@
#include <memory>
#include "core/GpgConstants.h"
namespace GpgFrontend {
struct GpgFrontendContext;
@ -46,6 +48,8 @@ struct GpgFrontendContext {
bool gather_external_gnupg_info;
bool unit_test_mode;
int rtn = GpgFrontend::kCrashCode;
/**
* @brief Construct a new Gpg Frontend Context object
*

View File

@ -28,8 +28,7 @@
#include "GpgFrontendContext.h"
#include "core/GpgConstants.h"
#include "core/GpgCoreInit.h"
#include "core/module/ModuleInit.h"
#include "core/function/CacheManager.h"
#include "ui/GpgFrontendUIInit.h"
// main
@ -37,8 +36,6 @@
namespace GpgFrontend {
constexpr int kCrashCode = ~0; ///<
/**
* @brief
*
@ -79,26 +76,18 @@ auto StartApplication(const GFCxtWPtr& p_ctx) -> int {
// load module's translations
GpgFrontend::UI::InitModulesTranslations();
// finally create main window
return_from_event_loop_code = GpgFrontend::UI::RunGpgFrontendUI(app);
} while (return_from_event_loop_code == GpgFrontend::kRestartCode &&
restart_count++ < 99);
// first should shutdown the module system
GpgFrontend::Module::ShutdownGpgFrontendModules();
// clear cache of unsaved pages
GpgFrontend::CacheManager::GetInstance().SaveDurableCache(
"editor_unsaved_pages", QJsonDocument(QJsonArray()), true);
// then shutdown the core
GpgFrontend::DestroyGpgFrontendCore();
// deep restart mode
if (return_from_event_loop_code == GpgFrontend::kDeepRestartCode ||
return_from_event_loop_code == kCrashCode) {
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
};
// set return code
ctx->rtn = return_from_event_loop_code;
// exit the program
return return_from_event_loop_code;

View File

@ -39,6 +39,7 @@
#include "core/module/ModuleManager.h"
#include "core/thread/TaskRunnerGetter.h"
#include "core/utils/BuildInfoUtils.h"
#include "core/utils/GpgUtils.h"
// GpgFrontend
@ -160,7 +161,7 @@ auto PrintEnvInfo() -> int {
stream << '\n';
int index = 0;
auto key_dbs = GetKeyDatabaseInfoBySettings(default_database_path);
auto key_dbs = GetKeyDatabaseInfoBySettings();
for (const auto& key_database : key_dbs) {
stream << Tr("Key Database [") << index++ << "] " << Tr("Name: ")
<< key_database.name << " " << Tr("-> Path: ") << key_database.path
@ -232,6 +233,7 @@ auto RunTest(const GFCxtWPtr& p_ctx) -> int {
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Default)
->PostTask(task);
ctx->rtn = kNonRestartCode;
looper.exec();
return 0;
}

View File

@ -33,6 +33,7 @@ namespace GpgFrontend {
constexpr int kNonRestartCode = 0;
constexpr int kRestartCode = 1000; ///< only refresh ui
constexpr int kDeepRestartCode = 1001; // refresh core and ui
constexpr int kCrashCode = ~0; ///< application crash
// Channels
constexpr int kGpgFrontendDefaultChannel = 0; ///<

View File

@ -36,9 +36,7 @@
#include "core/function/gpg/GpgAdvancedOperator.h"
#include "core/function/gpg/GpgContext.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/model/SettingsObject.h"
#include "core/module/ModuleManager.h"
#include "core/struct/settings_object/KeyDatabaseListSO.h"
#include "core/thread/Task.h"
#include "core/thread/TaskRunnerGetter.h"
#include "core/utils/CommonUtils.h"
@ -47,19 +45,20 @@
namespace GpgFrontend {
void DestroyGpgFrontendCore() { SingletonStorageCollection::Destroy(); }
void DestroyGpgFrontendCore() {
// stop all task runner
Thread::TaskRunnerGetter::GetInstance().StopAllTeakRunner();
// destroy all singleton objects
SingletonStorageCollection::Destroy();
}
auto VerifyGpgconfPath(const QFileInfo& gnupg_install_fs_path) -> bool {
return gnupg_install_fs_path.isAbsolute() && gnupg_install_fs_path.exists() &&
gnupg_install_fs_path.isFile();
}
auto VerifyKeyDatabasePath(const QFileInfo& key_database_fs_path) -> bool {
return key_database_fs_path.isAbsolute() && key_database_fs_path.exists() &&
key_database_fs_path.isDir();
}
auto SearchGpgconfPath(const QList<QString>& candidate_paths) -> QString {
auto SearchGpgconfPath(const QStringList& candidate_paths) -> QString {
for (const auto& path : candidate_paths) {
if (VerifyGpgconfPath(QFileInfo(path))) {
// return a unify path
@ -69,33 +68,37 @@ auto SearchGpgconfPath(const QList<QString>& candidate_paths) -> QString {
return {};
}
auto SearchKeyDatabasePath(const QList<QString>& candidate_paths) -> QString {
for (const auto& path : candidate_paths) {
if (VerifyKeyDatabasePath(QFileInfo(path))) {
// return a unify path
return QFileInfo(path).absoluteFilePath();
}
}
return {};
}
auto GetDefaultKeyDatabasePath(const QString& gpgconf_path) -> QString {
if (gpgconf_path.isEmpty()) return {};
QString default_db_path;
QFileInfo info(gpgconf_path);
if (!info.exists() || !info.isFile()) return {};
// portable mode
if (GlobalSettingStation::GetInstance().IsProtableMode()) {
default_db_path =
GlobalSettingStation::GetInstance().GetAppDataPath() + "/db";
} else {
if (gpgconf_path.isEmpty()) return {};
auto* p = new QProcess(QCoreApplication::instance());
p->setProgram(info.absoluteFilePath());
p->setArguments({"--list-dirs", "homedir"});
p->start();
QFileInfo info(gpgconf_path);
if (!info.exists() || !info.isFile()) return {};
p->waitForFinished();
auto home_path = p->readAll().trimmed();
p->deleteLater();
auto* p = new QProcess(QCoreApplication::instance());
p->setProgram(info.absoluteFilePath());
p->setArguments({"--list-dirs", "homedir"});
p->start();
QFileInfo home_info(home_path);
return home_info.absoluteFilePath();
p->waitForFinished();
default_db_path = p->readAll().trimmed();
p->deleteLater();
}
QFileInfo info(default_db_path);
default_db_path = info.absoluteFilePath();
// update GRT
Module::UpsertRTValue("core", "gpgme.ctx.default_database_path",
default_db_path);
return default_db_path;
}
auto InitGpgME() -> bool {
@ -270,43 +273,56 @@ auto RefreshGpgMEBackendEngine(const QString& gpgconf_path,
return true;
}
auto GetGnuPGPathByGpgConf(const QString& gpgconf_install_fs_path) -> QString {
auto GetComponentPathsByGpgConf(const QString& gpgconf_install_fs_path)
-> bool {
auto* process = new QProcess(QCoreApplication::instance());
process->setProgram(gpgconf_install_fs_path);
process->setArguments({"--check-programs"});
process->start();
process->waitForFinished(1000);
process->waitForFinished(30000);
auto output_buffer = process->readAllStandardOutput();
process->deleteLater();
if (output_buffer.isEmpty()) return {};
if (output_buffer.isEmpty()) return false;
auto line_split_list = QString(output_buffer).split("\n");
for (const auto& line : line_split_list) {
auto info_split_list = line.split(":");
if (info_split_list.size() != 3) continue;
if (info_split_list.size() != 6) continue;
auto component_name = info_split_list[0].trimmed();
auto component_name = info_split_list[0].trimmed().toLower();
auto component_desc = info_split_list[1].trimmed();
auto component_path = info_split_list[2].trimmed();
auto exists = info_split_list[3].trimmed();
auto runnable = info_split_list[4].trimmed();
if (component_name.toLower() == "gpg") {
#if defined(_WIN32) || defined(WIN32)
// replace some special substrings on windows platform
component_path.replace("%3a", ":");
// replace some special substrings on windows platform
component_path.replace("%3a", ":");
#endif
QFileInfo file_info(component_path);
if (file_info.exists() && file_info.isFile()) {
return file_info.absoluteFilePath();
}
return {};
}
if (exists != "1" || runnable != "1") continue;
QFileInfo file_info(component_path);
if (!file_info.exists() || !file_info.isFile()) continue;
Module::UpsertRTValue(
"core", QString("gnupg.components.%1.checked").arg(component_name), 1);
Module::UpsertRTValue(
"core", QString("gnupg.components.%1.path").arg(component_name),
file_info.absoluteFilePath());
LOG_D() << "gpg components checked: " << component_name
<< "path: " << file_info.absoluteFilePath();
}
return "";
return true;
}
auto DecideGpgConfPath(const QString& default_gpgconf_path) -> QString {
auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
auto use_custom_gnupg_install_path =
settings.value("gnupg/use_custom_gnupg_install_path", false).toBool();
auto custom_gnupg_install_path =
@ -359,8 +375,15 @@ auto DecideGpgConfPath(const QString& default_gpgconf_path) -> QString {
return "";
}
auto DecideGnuPGPath(const QString& gpgconf_path) -> QString {
return GetGnuPGPathByGpgConf(gpgconf_path);
auto DecideGnuPGPath(const QString& default_gnupg_path) -> QString {
QFileInfo info(default_gnupg_path);
if (default_gnupg_path.isEmpty() || !info.exists() || !info.isFile()) {
return Module::RetrieveRTValueTypedOrDefault<>(
"core", "gnupg.components.gpg.path", QString{});
}
return default_gnupg_path;
}
auto InitBasicPath() -> bool {
@ -374,12 +397,23 @@ auto InitBasicPath() -> bool {
LOG_I() << "default gnupg path found by gpgme: " << default_gnupg_path;
auto target_gpgconf_path = DecideGpgConfPath(default_gpgconf_path);
auto target_gnupg_path = default_gnupg_path;
if (target_gpgconf_path != default_gpgconf_path) {
target_gnupg_path = DecideGnuPGPath(target_gpgconf_path);
if (!GetComponentPathsByGpgConf(default_gpgconf_path)) {
LOG_E() << "Cannot get components paths by gpgconf!"
<< "GpgFrontend cannot start under this situation!";
CoreSignalStation::GetInstance()->SignalBadGnupgEnv(
QCoreApplication::tr("Cannot get Infos from GpgConf"));
return false;
}
auto target_gnupg_path = default_gnupg_path;
if (target_gpgconf_path != default_gpgconf_path) {
target_gnupg_path = DecideGnuPGPath(target_gnupg_path);
}
LOG_I() << "gpgconf path used: " << target_gpgconf_path;
LOG_I() << "gnupg path provided by gpgconf: " << target_gnupg_path;
LOG_I() << "gnupg path used: " << target_gnupg_path;
if (target_gpgconf_path.isEmpty()) {
LOG_E() << "Cannot find gpgconf!"
@ -408,10 +442,12 @@ auto InitBasicPath() -> bool {
LOG_E() << "Cannot find default home path by gpgconf!"
<< "GpgFrontend cannot start under this situation!";
CoreSignalStation::GetInstance()->SignalBadGnupgEnv(
QCoreApplication::tr("Cannot Find Home Path"));
QCoreApplication::tr("Cannot Find Default Home Path"));
return false;
}
if (!QDir(default_home_path).exists()) QDir(default_home_path).mkpath(".");
RefreshGpgMEBackendEngine(target_gpgconf_path, target_gnupg_path,
default_home_path);
@ -425,45 +461,6 @@ auto InitBasicPath() -> bool {
return true;
}
auto GetKeyDatabasesBySettings(QString& default_home_path)
-> QList<KeyDatabaseItemSO> {
auto key_db_list_so = SettingsObject("key_database_list");
auto key_db_list = KeyDatabaseListSO(key_db_list_so);
auto key_dbs = key_db_list.key_databases;
#if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
key_dbs.removeIf(
[default_home_path](const KeyDatabaseItemSO& key_database) -> bool {
return key_database.path == default_home_path;
});
#else
for (auto iter = key_dbs.begin(); iter != key_dbs.end();) {
if (iter->path == default_home_path) {
iter = key_dbs.erase(iter);
} else {
++iter;
}
}
#endif
key_db_list_so.Store(key_db_list.ToJson());
return key_dbs;
}
auto GetKeyDatabaseInfoBySettings(QString& default_home_path)
-> QList<KeyDatabaseInfo> {
auto key_dbs = GetKeyDatabasesBySettings(default_home_path);
QList<KeyDatabaseInfo> infos;
for (const auto& key_db : key_dbs) {
KeyDatabaseInfo info;
info.name = key_db.name;
info.path = key_db.path;
info.channel = -1;
infos.append(info);
}
return infos;
}
auto InitGpgFrontendCore(CoreInitArgs args) -> int {
// initialize gpgme
if (!InitGpgME()) {
@ -491,7 +488,7 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
auto default_home_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.default_database_path", QString{});
auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
// read settings from config file
auto forbid_all_gnupg_connection =
@ -519,16 +516,16 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
return 0;
}
auto key_dbs = GetKeyDatabaseInfoBySettings();
// load default context
auto& default_ctx = GpgFrontend::GpgContext::CreateInstance(
kGpgFrontendDefaultChannel, [=]() -> ChannelObjectPtr {
GpgFrontend::GpgContextInitArgs args;
// set key database path
if (!default_home_path.isEmpty()) {
args.db_name = "DEFAULT";
args.db_path = default_home_path;
}
const auto& default_key_db_info = key_dbs.front();
args.db_name = default_key_db_info.name;
args.db_path = default_key_db_info.path;
args.offline_mode = forbid_all_gnupg_connection;
args.auto_import_missing_key = auto_import_missing_key;
@ -564,30 +561,12 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
CoreSignalStation::GetInstance()->SignalGoodGnupgEnv();
LOG_I() << "Basic ENV Checking Finished";
auto key_dbs = GetKeyDatabasesBySettings(default_home_path);
auto* task = new Thread::Task(
[=](const DataObjectPtr&) -> int {
// key database path
QList<KeyDatabaseItemSO> buffered_key_dbs;
// try to use user defined key database
if (!key_dbs.empty()) {
for (const auto& key_database : key_dbs) {
if (VerifyKeyDatabasePath(QFileInfo(key_database.path))) {
auto key_database_fs_path =
QFileInfo(key_database.path).absoluteFilePath();
LOG_D() << "load gpg key database: " << key_database.path;
buffered_key_dbs.append(key_database);
} else {
LOG_W() << "gpg key database path is not suitable: "
<< key_database.path;
}
}
}
int channel_index = kGpgFrontendDefaultChannel + 1;
for (const auto& key_db : buffered_key_dbs) {
for (int i = 1; i < key_dbs.size(); i++) {
const auto& key_db = key_dbs[i];
// init ctx, also checking the basic env
auto& ctx = GpgFrontend::GpgContext::CreateInstance(
channel_index, [=]() -> ChannelObjectPtr {
@ -616,7 +595,7 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
continue;
}
if (!GpgKeyGetter::GetInstance(ctx.GetChannel()).FetchKey()) {
if (!GpgKeyGetter::GetInstance(ctx.GetChannel()).FlushKeyCache()) {
FLOG_E() << "gpgme context init key cache failed, index:"
<< channel_index;
continue;
@ -642,7 +621,7 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
->PostTask(task);
if (!args.unit_test_mode && restart_all_gnupg_components_on_start) {
GpgAdvancedOperator::RestartGpgComponents();
GpgAdvancedOperator::RestartGpgComponents(nullptr);
}
return 0;
}
@ -658,7 +637,7 @@ void StartMonitorCoreInitializationStatus() {
"core", "env.state.basic", 0);
LOG_D() << "monitor: core env is still initializing, waiting...";
QThread::msleep(15);
QThread::msleep(100);
}
if (core_init_state < 0) return -1;

View File

@ -72,12 +72,4 @@ auto GPGFRONTEND_CORE_EXPORT InitGpgME() -> bool;
*/
auto GPGFRONTEND_CORE_EXPORT InitBasicPath() -> bool;
/**
* @brief Get the Key Databases By Settings object
*
* @return auto
*/
auto GPGFRONTEND_CORE_EXPORT GetKeyDatabaseInfoBySettings(
QString& default_home_path) -> QList<KeyDatabaseInfo>;
} // namespace GpgFrontend

View File

@ -85,7 +85,7 @@ auto ArchiveCloseWriteCallback(struct archive *, void *client_data) -> int {
}
void ArchiveFileOperator::NewArchive2DataExchanger(
const QString &target_directory, std::shared_ptr<GFDataExchanger> exchanger,
const QString &target_directory, QSharedPointer<GFDataExchanger> exchanger,
const OperationCallback &cb) {
RunIOOperaAsync(
[=](const DataObjectPtr &data_object) -> GFError {
@ -194,7 +194,7 @@ void ArchiveFileOperator::NewArchive2DataExchanger(
}
void ArchiveFileOperator::ExtractArchiveFromDataExchanger(
std::shared_ptr<GFDataExchanger> ex, const QString &target_path,
QSharedPointer<GFDataExchanger> ex, const QString &target_path,
const OperationCallback &cb) {
RunIOOperaAsync(
[=](const DataObjectPtr &data_object) -> GFError {

View File

@ -53,7 +53,7 @@ class GPGFRONTEND_CORE_EXPORT ArchiveFileOperator {
* @param files
*/
static void NewArchive2DataExchanger(const QString &target_directory,
std::shared_ptr<GFDataExchanger>,
QSharedPointer<GFDataExchanger>,
const OperationCallback &cb);
/**
@ -63,7 +63,7 @@ class GPGFRONTEND_CORE_EXPORT ArchiveFileOperator {
* @param base_path
*/
static void ExtractArchiveFromDataExchanger(
std::shared_ptr<GFDataExchanger> fd, const QString &target_path,
QSharedPointer<GFDataExchanger> fd, const QString &target_path,
const OperationCallback &cb);
};
} // namespace GpgFrontend

View File

@ -48,7 +48,7 @@ class GlobalSettingStation::Impl {
Module::UpsertRTValue("core", "env.state.portable", 1);
LOG_I() << "GpgFrontend runs in the portable mode now";
app_data_path_ = app_path_ + "/../";
app_data_path_ = QDir(app_path_ + "/../").canonicalPath();
app_config_path_ = app_data_path_ + "/config";
portable_mode_ = true;
@ -61,6 +61,11 @@ class GlobalSettingStation::Impl {
#if defined(_WIN32) || defined(WIN32)
LOG_I() << "app config path: " << app_config_path_;
if (!QDir(app_config_path_).exists()) QDir(app_config_path_).mkpath(".");
#else
if (IsProtableMode()) {
LOG_I() << "app config path: " << app_config_path_;
if (!QDir(app_config_path_).exists()) QDir(app_config_path_).mkpath(".");
}
#endif
if (!QDir(app_data_path_).exists()) QDir(app_data_path_).mkpath(".");
@ -74,6 +79,7 @@ class GlobalSettingStation::Impl {
#if defined(_WIN32) || defined(WIN32)
return QSettings(app_config_file_path(), QSettings::IniFormat);
#else
if (IsProtableMode()) return {app_config_file_path(), QSettings::IniFormat};
return QSettings();
#endif
}
@ -171,6 +177,8 @@ class GlobalSettingStation::Impl {
return exec_binary_path + "/modules";
}
[[nodiscard]] auto IsProtableMode() const -> bool { return portable_mode_; }
private:
[[nodiscard]] auto app_config_file_path() const -> QString {
return app_config_path_ + "/config.ini";
@ -244,4 +252,11 @@ auto GlobalSettingStation::GetConfigPath() const -> QString {
auto GlobalSettingStation::GetIntegratedModulePath() const -> QString {
return p_->GetIntegratedModulePath();
}
auto GlobalSettingStation::IsProtableMode() const -> bool {
return p_->IsProtableMode();
}
auto GetSettings() -> QSettings {
return GlobalSettingStation::GetInstance().GetSettings();
}
} // namespace GpgFrontend

View File

@ -131,8 +131,19 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
*/
[[nodiscard]] auto GetIntegratedModulePath() const -> QString;
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto IsProtableMode() const -> bool;
private:
class Impl;
SecureUniquePtr<Impl> p_;
};
auto GPGFRONTEND_CORE_EXPORT GetSettings() -> QSettings;
} // namespace GpgFrontend

View File

@ -141,11 +141,11 @@ class SingletonFunctionObject : public ChannelObject {
}
/**
* @brief Get all the channel ids
* @brief Get the All Channel Id object
*
* @return std::vector<int>
* @return QContainer<int>
*/
static auto GetAllChannelId() -> std::vector<int> {
static auto GetAllChannelId() -> QContainer<int> {
return SingletonStorageCollection::GetInstance(false)
->GetSingletonStorage(typeid(T))
->GetAllChannelId();

View File

@ -31,7 +31,8 @@
#include <shared_mutex>
#include "core/function/basic/ChannelObject.h"
#include "utils/MemoryUtils.h"
#include "core/typedef/CoreTypedef.h"
#include "core/utils/MemoryUtils.h"
namespace GpgFrontend {
@ -60,8 +61,8 @@ class SingletonStorage::Impl {
}
}
auto GetAllChannelId() -> std::vector<int> {
std::vector<int> channels;
auto GetAllChannelId() -> QContainer<int> {
QContainer<int> channels;
channels.reserve(instances_map_.size());
for (const auto& [key, value] : instances_map_) {
channels.push_back(key);
@ -119,7 +120,7 @@ auto SingletonStorage::FindObjectInChannel(int channel)
return p_->FindObjectInChannel(channel);
}
auto SingletonStorage::GetAllChannelId() -> std::vector<int> {
auto SingletonStorage::GetAllChannelId() -> QContainer<int> {
return p_->GetAllChannelId();
}

View File

@ -29,6 +29,7 @@
#pragma once
#include "core/function/SecureMemoryAllocator.h"
#include "core/typedef/GpgTypedef.h"
namespace GpgFrontend {
@ -66,11 +67,11 @@ class GPGFRONTEND_CORE_EXPORT SingletonStorage {
auto FindObjectInChannel(int channel) -> ChannelObject*;
/**
* @brief Get all the channel ids
* @brief Get the All Channel Id object
*
* @return std::vector<int>
* @return QContainer<int>
*/
auto GetAllChannelId() -> std::vector<int>;
auto GetAllChannelId() -> QContainer<int>;
/**
* @brief Set a new object in channel object

View File

@ -32,211 +32,89 @@
#include "GpgAdvancedOperator.h"
#include <utility>
#include "core/function/gpg/GpgCommandExecutor.h"
#include "core/module/ModuleManager.h"
#include "core/utils/GpgUtils.h"
void GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache(
OperationCallback cb) {
namespace GpgFrontend {
void ExecuteGpgCommand(const QString &operation, const QStringList &extra_args,
OperationCallback cb) {
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gpgconf_path", QString{});
if (gpgconf_path.isEmpty()) {
FLOG_W("cannot get valid gpgconf path from rt, abort.");
cb(-1, TransferParams());
if (cb) cb(-1, TransferParams());
return;
}
#if defined(__APPLE__) && defined(__MACH__)
FLOG_I("kill all gpg components in order to clear gpg password cache");
KillAllGpgComponents();
#else
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpgconf_path, QStringList{"--reload", "gpg-agent"},
[=](int exit_code, const QString & /*p_out*/,
const QString & /*p_err*/) {
cb(exit_code == 0 ? 0 : -1, TransferParams());
}});
#endif
}
auto key_dbs = GetGpgKeyDatabaseInfos();
auto total_tasks = static_cast<int>(key_dbs.size());
std::atomic<int> completed_tasks{0};
std::vector<int> results(total_tasks, 0);
void GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents(
OperationCallback cb) {
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gpgconf_path", QString{});
int task_index = 0;
for (const auto &key_db : key_dbs) {
const int current_index = task_index++;
const auto target_home_dir =
QDir::toNativeSeparators(QFileInfo(key_db.path).canonicalFilePath());
if (gpgconf_path.isEmpty()) {
FLOG_W("cannot get valid gpgconf path from rt, abort.");
cb(-1, TransferParams());
return;
}
QStringList arguments = QStringList{"--homedir", target_home_dir};
arguments.append(extra_args);
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpgconf_path, QStringList{"--reload"},
[=](int exit_code, const QString &, const QString &) {
FLOG_D("gpgconf reload exit code: %d", exit_code);
cb(exit_code == 0 ? 0 : -1, TransferParams());
}});
}
GpgCommandExecutor::ExecuteSync(
{gpgconf_path, arguments,
[=, &completed_tasks, &results](int exit_code, const QString &,
const QString &) {
FLOG_D("%s exit code: %d", qPrintable(operation), exit_code);
void GpgFrontend::GpgAdvancedOperator::KillAllGpgComponents() {
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gpgconf_path", QString{});
results[current_index] = exit_code;
if (gpgconf_path.isEmpty()) {
FLOG_W("cannot get valid gpgconf path from rt, abort.");
return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpgconf_path, QStringList{"--verbose", "--kill", "all"},
[=](int exit_code, const QString &p_out, const QString &p_err) {
bool success = true;
if (exit_code != 0) {
success = false;
LOG_W() << "gpgconf execute error, process stderr: " << p_err
<< ", process stdout: " << p_out;
return;
}
FLOG_D("gpgconf --kill --all execute result: %d", success);
}});
}
void GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() {
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gpgconf_path", QString{});
if (gpgconf_path.isEmpty()) {
FLOG_W("cannot get valid gpgconf path from rt, abort.");
return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpgconf_path, QStringList{"--verbose", "--kill", "all"},
[=](int exit_code, const QString &p_out, const QString &p_err) {
FLOG_D("gpgconf --kill all command got exit code: %d", exit_code);
bool success = true;
if (exit_code != 0) {
success = false;
LOG_W() << "gpgconf execute error, process stderr: " << p_err
<< ", process stdout: " << p_out;
return;
}
FLOG_D("gpgconf --kill --all execute result: %d", success);
if (!success) {
FLOG_W("restart all component after core initalized failed");
Module::UpsertRTValue(
"core", "gpg_advanced_operator.restart_gpg_components", false);
return;
}
#if defined(__APPLE__) && defined(__MACH__)
FLOG_I("getting gpg-agent to start automatically on macOS");
#else
StartGpgAgent([](int err, DataObjectPtr) {
if (err >= 0) {
Module::UpsertRTValue(
"core", "gpg_advanced_operator.restart_gpg_components", true);
return;
if (++completed_tasks == total_tasks && cb) {
int final_result =
std::all_of(results.begin(), results.end(),
[](int result) { return result >= 0; })
? 0
: -1;
cb(final_result, TransferParams());
}
});
#endif
}});
}});
}
}
void GpgFrontend::GpgAdvancedOperator::ResetConfigures(OperationCallback cb) {
void GpgAdvancedOperator::ClearGpgPasswordCache(OperationCallback cb) {
ExecuteGpgCommand("Clear GPG Password Cache", {"--reload", "gpg-agent"},
std::move(cb));
}
void GpgAdvancedOperator::ReloadGpgComponents(OperationCallback cb) {
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gpgconf_path", QString{});
if (gpgconf_path.isEmpty()) {
FLOG_W("cannot get valid gpgconf path from rt, abort.");
cb(-1, TransferParams());
return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpgconf_path, QStringList{"--apply-defaults"},
[=](int exit_code, const QString &, const QString &) {
FLOG_D("gpgconf apply-defaults exit code: %d", exit_code);
cb(exit_code == 0 ? 0 : -1, TransferParams());
}});
ExecuteGpgCommand("Reload GPG Components", {"--reload", "all"},
std::move(cb));
}
void GpgFrontend::GpgAdvancedOperator::StartGpgAgent(OperationCallback cb) {
if (!Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) {
cb(-1, TransferParams());
return;
}
const auto gpg_agent_path = Module::RetrieveRTValueTypedOrDefault<>(
kGnuPGInfoGatheringModuleID, "gnupg.gpg_agent_path", QString{});
const auto home_path = Module::RetrieveRTValueTypedOrDefault<>(
kGnuPGInfoGatheringModuleID, "gnupg.home_path", QString{});
if (gpg_agent_path.isEmpty()) {
FLOG_W("cannot get valid gpg agent path from rt, abort.");
cb(-1, TransferParams());
return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpg_agent_path, QStringList{"--homedir", home_path, "--daemon"},
[=](int exit_code, const QString &, const QString &) {
FLOG_D("gpg-agent daemon exit code: %d", exit_code);
cb(exit_code >= 0 ? 0 : -1, TransferParams());
}});
void GpgAdvancedOperator::KillAllGpgComponents(OperationCallback cb) {
ExecuteGpgCommand("Kill All GPG Components", {"--kill", "all"},
std::move(cb));
}
void GpgFrontend::GpgAdvancedOperator::StartDirmngr(OperationCallback cb) {
if (!Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) {
cb(-1, TransferParams());
return;
}
const auto dirmngr_path = Module::RetrieveRTValueTypedOrDefault<>(
kGnuPGInfoGatheringModuleID, "gnupg.dirmngr_path", QString{});
const auto home_path = Module::RetrieveRTValueTypedOrDefault<>(
kGnuPGInfoGatheringModuleID, "gnupg.home_path", QString{});
if (dirmngr_path.isEmpty()) {
FLOG_W("cannot get valid dirmngr path from rt, abort.");
cb(-1, TransferParams());
return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{dirmngr_path, QStringList{"--homedir", home_path, "--daemon"},
[=](int exit_code, const QString &, const QString &) {
FLOG_D("gpgconf daemon exit code: %d", exit_code);
cb(exit_code >= 0 ? 0 : -1, TransferParams());
}});
void GpgAdvancedOperator::ResetConfigures(OperationCallback cb) {
ExecuteGpgCommand("Reset Gnupg Configures", {"--apply-defaults"},
std::move(cb));
}
void GpgFrontend::GpgAdvancedOperator::StartKeyBoxd(OperationCallback cb) {
if (!Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) {
cb(-1, TransferParams());
return;
}
const auto keyboxd_path = Module::RetrieveRTValueTypedOrDefault<>(
kGnuPGInfoGatheringModuleID, "gnupg.keyboxd_path", QString{});
const auto home_path = Module::RetrieveRTValueTypedOrDefault<>(
kGnuPGInfoGatheringModuleID, "gnupg.home_path", QString{});
if (keyboxd_path.isEmpty()) {
FLOG_W("cannot get valid keyboxd path from rt, abort.");
cb(-1, TransferParams());
return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{keyboxd_path, QStringList{"--homedir", home_path, "--daemon"},
[=](int exit_code, const QString &, const QString &) {
FLOG_D("gpgconf daemon exit code: %d", exit_code);
cb(exit_code >= 0 ? 0 : -1, TransferParams());
}});
void GpgAdvancedOperator::LaunchGpgComponents(OperationCallback cb) {
ExecuteGpgCommand("Launch All GPG Components", {"--launch", "all"},
std::move(cb));
}
void GpgAdvancedOperator::RestartGpgComponents(OperationCallback cb) {
KillAllGpgComponents(nullptr);
LaunchGpgComponents(std::move(cb));
}
} // namespace GpgFrontend

View File

@ -60,7 +60,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
* @return true
* @return false
*/
static void RestartGpgComponents();
static void RestartGpgComponents(OperationCallback);
/**
* @brief
@ -76,29 +76,13 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
* @return true
* @return false
*/
static void StartGpgAgent(OperationCallback);
/**
* @brief
*
* @return true
* @return false
*/
static void StartDirmngr(OperationCallback);
/**
* @brief
*
* @return true
* @return false
*/
static void StartKeyBoxd(OperationCallback);
static void LaunchGpgComponents(OperationCallback);
/**
* @brief
*
*/
static void KillAllGpgComponents();
static void KillAllGpgComponents(OperationCallback);
};
} // namespace GpgFrontend

View File

@ -43,29 +43,49 @@ namespace GpgFrontend {
GpgBasicOperator::GpgBasicOperator(int channel)
: SingletonFunctionObject<GpgBasicOperator>(channel) {}
void SetSignersImpl(GpgContext& ctx_, const KeyArgsList& signers, bool ascii) {
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
gpgme_signers_clear(ctx);
for (const GpgKey& key : signers) {
LOG_D() << "signer's key fpr: " << key.GetFingerprint();
if (key.IsHasActualSignCap()) {
auto error = gpgme_signers_add(ctx, gpgme_key_t(key));
CheckGpgError(error);
}
}
if (signers.size() != gpgme_signers_count(ctx_.DefaultContext())) {
FLOG_D("not all signers added");
}
}
auto EncryptImpl(GpgContext& ctx_, const KeyArgsList& keys,
const GFBuffer& in_buffer, bool ascii,
const DataObjectPtr& data_object) -> GpgError {
auto recipients = Convert2RawGpgMEKeyList(keys);
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(
gpgme_op_encrypt(ctx, keys.isEmpty() ? nullptr : recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST, data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
data_out.Read2GFBuffer(),
});
return err;
}
void GpgBasicOperator::Encrypt(const KeyArgsList& keys,
const GFBuffer& in_buffer, bool ascii,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
if (keys.empty()) return GPG_ERR_CANCELED;
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
data_out.Read2GFBuffer()});
return err;
[=](const DataObjectPtr& data_object) {
return EncryptImpl(ctx_, keys, in_buffer, ascii, data_object);
},
cb, "gpgme_op_encrypt", "2.1.0");
}
@ -74,25 +94,8 @@ auto GpgBasicOperator::EncryptSync(const KeyArgsList& keys,
const GFBuffer& in_buffer, bool ascii)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
if (keys.empty()) return GPG_ERR_CANCELED;
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
data_out.Read2GFBuffer()});
return err;
[=](const DataObjectPtr& data_object) {
return EncryptImpl(ctx_, keys, in_buffer, ascii, data_object);
},
"gpgme_op_encrypt", "2.1.0");
}
@ -100,17 +103,8 @@ auto GpgBasicOperator::EncryptSync(const KeyArgsList& keys,
void GpgBasicOperator::EncryptSymmetric(const GFBuffer& in_buffer, bool ascii,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(
ctx, nullptr, GPGME_ENCRYPT_SYMMETRIC, data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
data_out.Read2GFBuffer()});
return err;
[=](const DataObjectPtr& data_object) {
return EncryptImpl(ctx_, {}, in_buffer, ascii, data_object);
},
cb, "gpgme_op_encrypt_symmetric", "2.1.0");
}
@ -119,35 +113,32 @@ auto GpgBasicOperator::EncryptSymmetricSync(const GFBuffer& in_buffer,
bool ascii)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(
ctx, nullptr, GPGME_ENCRYPT_SYMMETRIC, data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
data_out.Read2GFBuffer()});
return err;
[=](const DataObjectPtr& data_object) {
return EncryptImpl(ctx_, {}, in_buffer, ascii, data_object);
},
"gpgme_op_encrypt_symmetric", "2.1.0");
}
auto DecryptImpl(GpgContext& ctx_, const GFBuffer& in_buffer,
const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_buffer);
GpgData data_out;
auto err =
CheckGpgError(gpgme_op_decrypt(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap({
GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
data_out.Read2GFBuffer(),
});
return err;
}
void GpgBasicOperator::Decrypt(const GFBuffer& in_buffer,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_buffer);
GpgData data_out;
auto err = CheckGpgError(
gpgme_op_decrypt(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap(
{GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
data_out.Read2GFBuffer()});
return err;
[=](const DataObjectPtr& data_object) {
return DecryptImpl(ctx_, in_buffer, data_object);
},
cb, "gpgme_op_decrypt", "2.1.0");
}
@ -155,45 +146,43 @@ void GpgBasicOperator::Decrypt(const GFBuffer& in_buffer,
auto GpgBasicOperator::DecryptSync(const GFBuffer& in_buffer)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_buffer);
GpgData data_out;
auto err = CheckGpgError(
gpgme_op_decrypt(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap(
{GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
data_out.Read2GFBuffer()});
return err;
[=](const DataObjectPtr& data_object) {
return DecryptImpl(ctx_, in_buffer, data_object);
},
"gpgme_op_decrypt", "2.1.0");
}
auto VerifyImpl(GpgContext& ctx_, const GFBuffer& in_buffer,
const GFBuffer& sig_buffer,
const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(in_buffer);
GpgData data_out;
if (!sig_buffer.Empty()) {
GpgData sig_data(sig_buffer);
err = CheckGpgError(
gpgme_op_verify(ctx_.DefaultContext(), sig_data, data_in, nullptr));
} else {
err = CheckGpgError(
gpgme_op_verify(ctx_.DefaultContext(), data_in, nullptr, data_out));
}
data_object->Swap({
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
GFBuffer(),
});
return err;
}
void GpgBasicOperator::Verify(const GFBuffer& in_buffer,
const GFBuffer& sig_buffer,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(in_buffer);
GpgData data_out;
if (!sig_buffer.Empty()) {
GpgData sig_data(sig_buffer);
err = CheckGpgError(gpgme_op_verify(ctx_.DefaultContext(), sig_data,
data_in, nullptr));
} else {
err = CheckGpgError(gpgme_op_verify(ctx_.DefaultContext(), data_in,
nullptr, data_out));
}
data_object->Swap({
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
});
return err;
return VerifyImpl(ctx_, in_buffer, sig_buffer, data_object);
},
cb, "gpgme_op_verify", "2.1.0");
}
@ -202,51 +191,41 @@ auto GpgBasicOperator::VerifySync(const GFBuffer& in_buffer,
const GFBuffer& sig_buffer)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(in_buffer);
GpgData data_out;
if (!sig_buffer.Empty()) {
GpgData sig_data(sig_buffer);
err = CheckGpgError(gpgme_op_verify(ctx_.DefaultContext(), sig_data,
data_in, nullptr));
} else {
err = CheckGpgError(gpgme_op_verify(ctx_.DefaultContext(), data_in,
nullptr, data_out));
}
data_object->Swap({
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
});
return err;
[=](const DataObjectPtr& data_object) {
return VerifyImpl(ctx_, in_buffer, sig_buffer, data_object);
},
"gpgme_op_verify", "2.1.0");
}
auto SignImpl(GpgContext& ctx_, const KeyArgsList& signers,
const GFBuffer& in_buffer, GpgSignMode mode, bool ascii,
const DataObjectPtr& data_object) -> GpgError {
if (signers.empty()) return GPG_ERR_CANCELED;
GpgError err;
// Set Singers of this opera
SetSignersImpl(ctx_, signers, ascii);
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_sign(ctx, data_in, data_out, mode));
data_object->Swap({
GpgSignResult(gpgme_op_sign_result(ctx)),
data_out.Read2GFBuffer(),
});
return err;
}
void GpgBasicOperator::Sign(const KeyArgsList& signers,
const GFBuffer& in_buffer, GpgSignMode mode,
bool ascii, const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
if (signers.empty()) return GPG_ERR_CANCELED;
GpgError err;
// Set Singers of this opera
SetSigners(signers, ascii);
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_sign(ctx, data_in, data_out, mode));
data_object->Swap({GpgSignResult(gpgme_op_sign_result(ctx)),
data_out.Read2GFBuffer()});
return err;
[=](const DataObjectPtr& data_object) {
return SignImpl(ctx_, signers, in_buffer, mode, ascii, data_object);
},
cb, "gpgme_op_sign", "2.1.0");
}
@ -255,45 +234,36 @@ auto GpgBasicOperator::SignSync(
const KeyArgsList& signers, const GFBuffer& in_buffer, GpgSignMode mode,
bool ascii) -> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
if (signers.empty()) return GPG_ERR_CANCELED;
GpgError err;
// Set Singers of this opera
SetSigners(signers, ascii);
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_sign(ctx, data_in, data_out, mode));
data_object->Swap({GpgSignResult(gpgme_op_sign_result(ctx)),
data_out.Read2GFBuffer()});
return err;
[=](const DataObjectPtr& data_object) {
return SignImpl(ctx_, signers, in_buffer, mode, ascii, data_object);
},
"gpgme_op_sign", "2.1.0");
}
auto DecryptVerifyImpl(GpgContext& ctx_, const GFBuffer& in_buffer,
const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(in_buffer);
GpgData data_out;
err = CheckGpgError(
gpgme_op_decrypt_verify(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap({
GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
data_out.Read2GFBuffer(),
});
return err;
}
void GpgBasicOperator::DecryptVerify(const GFBuffer& in_buffer,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(in_buffer);
GpgData data_out;
err = CheckGpgError(
gpgme_op_decrypt_verify(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap(
{GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
data_out.Read2GFBuffer()});
return err;
[=](const DataObjectPtr& data_object) {
return DecryptVerifyImpl(ctx_, in_buffer, data_object);
},
cb, "gpgme_op_decrypt_verify", "2.1.0");
}
@ -302,52 +272,47 @@ auto GpgBasicOperator::DecryptVerifySync(const GFBuffer& in_buffer)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(in_buffer);
GpgData data_out;
err = CheckGpgError(
gpgme_op_decrypt_verify(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap(
{GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
data_out.Read2GFBuffer()});
return err;
return DecryptVerifyImpl(ctx_, in_buffer, data_object);
},
"gpgme_op_decrypt_verify", "2.1.0");
}
auto EncryptSignImpl(GpgContext& ctx_, const KeyArgsList& keys,
const KeyArgsList& signers, const GFBuffer& in_buffer,
bool ascii, const DataObjectPtr& data_object) -> GpgError {
if (keys.empty() || signers.empty()) return GPG_ERR_CANCELED;
GpgError err;
QContainer<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
SetSignersImpl(ctx_, signers, ascii);
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_encrypt_sign(
ctx, recipients.data(), GPGME_ENCRYPT_ALWAYS_TRUST, data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
GpgSignResult(gpgme_op_sign_result(ctx)),
data_out.Read2GFBuffer(),
});
return err;
}
void GpgBasicOperator::EncryptSign(const KeyArgsList& keys,
const KeyArgsList& signers,
const GFBuffer& in_buffer, bool ascii,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
if (keys.empty() || signers.empty()) return GPG_ERR_CANCELED;
GpgError err;
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
SetSigners(signers, ascii);
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_encrypt_sign(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
GpgSignResult(gpgme_op_sign_result(ctx)),
data_out.Read2GFBuffer()});
return err;
return EncryptSignImpl(ctx_, keys, signers, in_buffer, ascii,
data_object);
},
cb, "gpgme_op_encrypt_sign", "2.1.0");
}
@ -358,57 +323,24 @@ auto GpgBasicOperator::EncryptSignSync(const KeyArgsList& keys,
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
if (keys.empty() || signers.empty()) return GPG_ERR_CANCELED;
GpgError err;
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
SetSigners(signers, ascii);
GpgData data_in(in_buffer);
GpgData data_out;
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_encrypt_sign(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
GpgSignResult(gpgme_op_sign_result(ctx)),
data_out.Read2GFBuffer()});
return err;
return EncryptSignImpl(ctx_, keys, signers, in_buffer, ascii,
data_object);
},
"gpgme_op_encrypt_sign", "2.1.0");
}
void GpgBasicOperator::SetSigners(const KeyArgsList& signers, bool ascii) {
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
gpgme_signers_clear(ctx);
for (const GpgKey& key : signers) {
LOG_D() << "signer's key fpr: " << key.GetFingerprint();
if (key.IsHasActualSigningCapability()) {
auto error = gpgme_signers_add(ctx, gpgme_key_t(key));
CheckGpgError(error);
}
}
if (signers.size() != gpgme_signers_count(ctx_.DefaultContext())) {
FLOG_D("not all signers added");
}
SetSignersImpl(ctx_, signers, ascii);
}
auto GpgBasicOperator::GetSigners(bool ascii) -> std::unique_ptr<KeyArgsList> {
auto GpgBasicOperator::GetSigners(bool ascii) -> KeyArgsList {
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto count = gpgme_signers_count(ctx);
auto signers = std::make_unique<std::vector<GpgKey>>();
auto signers = KeyArgsList{};
for (auto i = 0U; i < count; i++) {
auto key = GpgKey(gpgme_signers_enum(ctx, i));
signers->push_back(GpgKey(std::move(key)));
signers.push_back(GpgKey(std::move(key)));
}
return signers;
}

View File

@ -226,7 +226,7 @@ class GPGFRONTEND_CORE_EXPORT GpgBasicOperator
*
* @return Intelligent pointer pointing to the private key list
*/
auto GetSigners(bool ascii) -> std::unique_ptr<KeyArgsList>;
auto GetSigners(bool ascii) -> KeyArgsList;
private:
GpgContext& ctx_ = GpgContext::GetInstance(

View File

@ -45,8 +45,8 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context)
Thread::Task::TaskCallback result_callback =
[cmd](int /*rtn*/, const DataObjectPtr &data_object) {
FLOG_D("data object args count of cmd executor result callback: %ld",
data_object->GetObjectSize());
LOG_D() << "data object args count of cmd executor result callback:"
<< data_object->GetObjectSize();
if (!data_object->Check<int, QString, GpgCommandExecutorCallback>()) {
FLOG_W("data object checking failed");

View File

@ -40,88 +40,19 @@
namespace GpgFrontend {
constexpr ssize_t kDataExchangerSize = 8192;
GpgFileOpera::GpgFileOpera(int channel)
: SingletonFunctionObject<GpgFileOpera>(channel) {}
void GpgFileOpera::EncryptFile(const KeyArgsList& keys, const QString& in_path,
bool ascii, const QString& out_path,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx))});
return err;
},
cb, "gpgme_op_encrypt", "2.1.0");
auto ExtractArchiveHelper(const QString& out_path)
-> QSharedPointer<GFDataExchanger> {
auto ex = CreateStandardGFDataExchanger();
ArchiveFileOperator::ExtractArchiveFromDataExchanger(
ex, out_path, [](GFError err, const DataObjectPtr&) {
FLOG_D("extract archive from data exchanger operation, err: %d", err);
});
return ex;
}
auto GpgFileOpera::EncryptFileSync(
const KeyArgsList& keys, const QString& in_path, bool ascii,
const QString& out_path) -> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx))});
return err;
},
"gpgme_op_encrypt", "2.1.0");
}
void GpgFileOpera::EncryptDirectory(const KeyArgsList& keys,
const QString& in_path, bool ascii,
const QString& out_path,
const GpgOperationCallback& cb) {
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
auto w_ex = std::weak_ptr<GFDataExchanger>(ex);
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
GpgData data_in(ex);
GpgData data_out(out_path, false);
FLOG_D("encrypt directory start");
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx))});
FLOG_D("encrypt directory finished, err: %d", err);
return err;
},
cb, "gpgme_op_encrypt", "2.1.0");
void CreateArchiveHelper(const QString& in_path,
const QSharedPointer<GFDataExchanger>& ex) {
auto w_ex = QWeakPointer<GFDataExchanger>(ex);
ArchiveFileOperator::NewArchive2DataExchanger(
in_path, ex, [=](GFError err, const DataObjectPtr&) {
@ -132,19 +63,99 @@ void GpgFileOpera::EncryptDirectory(const KeyArgsList& keys,
});
}
GpgFileOpera::GpgFileOpera(int channel)
: SingletonFunctionObject<GpgFileOpera>(channel) {}
auto EncryptFileGpgDataImpl(GpgContext& ctx_, const KeyArgsList& keys,
GpgData& data_in, bool ascii, GpgData& data_out,
const DataObjectPtr& data_object) -> GpgError {
auto recipients = Convert2RawGpgMEKeyList(keys);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(
gpgme_op_encrypt(ctx, keys.isEmpty() ? nullptr : recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST, data_in, data_out));
data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx))});
return err;
}
auto EncryptFileImpl(GpgContext& ctx_, const KeyArgsList& keys,
const QString& in_path, bool ascii,
const QString& out_path,
const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
return EncryptFileGpgDataImpl(ctx_, keys, data_in, ascii, data_out,
data_object);
}
void GpgFileOpera::EncryptFile(const KeyArgsList& keys, const QString& in_path,
bool ascii, const QString& out_path,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) {
return EncryptFileImpl(ctx_, keys, in_path, ascii, out_path,
data_object);
},
cb, "gpgme_op_encrypt", "2.1.0");
}
auto GpgFileOpera::EncryptFileSync(
const KeyArgsList& keys, const QString& in_path, bool ascii,
const QString& out_path) -> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) {
return EncryptFileImpl(ctx_, keys, in_path, ascii, out_path,
data_object);
},
"gpgme_op_encrypt", "2.1.0");
}
void GpgFileOpera::EncryptDirectory(const KeyArgsList& keys,
const QString& in_path, bool ascii,
const QString& out_path,
const GpgOperationCallback& cb) {
auto ex = CreateStandardGFDataExchanger();
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(ex);
GpgData data_out(out_path, false);
return EncryptFileGpgDataImpl(ctx_, keys, data_in, ascii, data_out,
data_object);
},
cb, "gpgme_op_encrypt", "2.1.0");
CreateArchiveHelper(in_path, ex);
}
auto DecryptFileGpgDataImpl(GpgContext& ctx_, GpgData& data_in,
GpgData& data_out,
const DataObjectPtr& data_object) -> GpgError {
auto err =
CheckGpgError(gpgme_op_decrypt(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap(
{GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext()))});
return err;
}
auto DecryptFileImpl(GpgContext& ctx_, const QString& in_path,
const QString& out_path,
const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
return DecryptFileGpgDataImpl(ctx_, data_in, data_out, data_object);
}
void GpgFileOpera::DecryptFile(const QString& in_path, const QString& out_path,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto err = CheckGpgError(
gpgme_op_decrypt(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap(
{GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext()))});
return err;
[=](const DataObjectPtr& data_object) {
return DecryptFileImpl(ctx_, in_path, out_path, data_object);
},
cb, "gpgme_op_decrypt", "2.1.0");
}
@ -153,16 +164,8 @@ auto GpgFileOpera::DecryptFileSync(const QString& in_path,
const QString& out_path)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto err = CheckGpgError(
gpgme_op_decrypt(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap(
{GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext()))});
return err;
[=](const DataObjectPtr& data_object) {
return DecryptFileImpl(ctx_, in_path, out_path, data_object);
},
"gpgme_op_decrypt", "2.1.0");
}
@ -170,49 +173,55 @@ auto GpgFileOpera::DecryptFileSync(const QString& in_path,
void GpgFileOpera::DecryptArchive(const QString& in_path,
const QString& out_path,
const GpgOperationCallback& cb) {
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
ArchiveFileOperator::ExtractArchiveFromDataExchanger(
ex, out_path, [](GFError err, const DataObjectPtr&) {
FLOG_D("extract archive from data exchanger operation, err: %d", err);
});
auto ex = ExtractArchiveHelper(out_path);
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(ex);
auto err = CheckGpgError(
gpgme_op_decrypt(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap(
{GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext()))});
return err;
return DecryptFileGpgDataImpl(ctx_, data_in, data_out, data_object);
},
cb, "gpgme_op_decrypt", "2.1.0");
}
auto SignFileGpgDataImpl(GpgContext& ctx_, GpgBasicOperator& basic_opera_,
const KeyArgsList& keys, GpgData& data_in, bool ascii,
GpgData& data_out,
const DataObjectPtr& data_object) -> GpgError {
GpgError err;
// Set Singers of this opera
basic_opera_.SetSigners(keys, ascii);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(
gpgme_op_sign(ctx, data_in, data_out, GPGME_SIG_MODE_DETACH));
data_object->Swap({
GpgSignResult(gpgme_op_sign_result(ctx)),
});
return err;
}
auto SignFileImpl(GpgContext& ctx_, GpgBasicOperator& basic_opera_,
const KeyArgsList& keys, const QString& in_path, bool ascii,
const QString& out_path,
const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
return SignFileGpgDataImpl(ctx_, basic_opera_, keys, data_in, ascii, data_out,
data_object);
}
void GpgFileOpera::SignFile(const KeyArgsList& keys, const QString& in_path,
bool ascii, const QString& out_path,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
// Set Singers of this opera
GpgBasicOperator::GetInstance(GetChannel()).SetSigners(keys, ascii);
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(
gpgme_op_sign(ctx, data_in, data_out, GPGME_SIG_MODE_DETACH));
data_object->Swap({
GpgSignResult(gpgme_op_sign_result(ctx)),
});
return err;
[=](const DataObjectPtr& data_object) {
return SignFileImpl(ctx_, basic_opera_, keys, in_path, ascii, out_path,
data_object);
},
cb, "gpgme_op_sign", "2.1.0");
}
@ -221,50 +230,42 @@ auto GpgFileOpera::SignFileSync(const KeyArgsList& keys, const QString& in_path,
bool ascii, const QString& out_path)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
// Set Singers of this opera
GpgBasicOperator::GetInstance(GetChannel()).SetSigners(keys, ascii);
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(
gpgme_op_sign(ctx, data_in, data_out, GPGME_SIG_MODE_DETACH));
data_object->Swap({
GpgSignResult(gpgme_op_sign_result(ctx)),
});
return err;
[=](const DataObjectPtr& data_object) {
return SignFileImpl(ctx_, basic_opera_, keys, in_path, ascii, out_path,
data_object);
},
"gpgme_op_sign", "2.1.0");
}
auto VerifyFileImpl(GpgContext& ctx_, const QString& data_path,
const QString& sign_path,
const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(data_path, true);
GpgData data_out;
if (!sign_path.isEmpty()) {
GpgData sig_data(sign_path, true);
err = CheckGpgError(
gpgme_op_verify(ctx_.DefaultContext(), sig_data, data_in, nullptr));
} else {
err = CheckGpgError(
gpgme_op_verify(ctx_.DefaultContext(), data_in, nullptr, data_out));
}
data_object->Swap({
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
});
return err;
}
void GpgFileOpera::VerifyFile(const QString& data_path,
const QString& sign_path,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(data_path, true);
GpgData data_out;
if (!sign_path.isEmpty()) {
GpgData sig_data(sign_path, true);
err = CheckGpgError(gpgme_op_verify(ctx_.DefaultContext(), sig_data,
data_in, nullptr));
} else {
err = CheckGpgError(gpgme_op_verify(ctx_.DefaultContext(), data_in,
nullptr, data_out));
}
data_object->Swap({
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
});
return err;
return VerifyFileImpl(ctx_, data_path, sign_path, data_object);
},
cb, "gpgme_op_verify", "2.1.0");
}
@ -274,57 +275,55 @@ auto GpgFileOpera::VerifyFileSync(const QString& data_path,
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(data_path, true);
GpgData data_out;
if (!sign_path.isEmpty()) {
GpgData sig_data(sign_path, true);
err = CheckGpgError(gpgme_op_verify(ctx_.DefaultContext(), sig_data,
data_in, nullptr));
} else {
err = CheckGpgError(gpgme_op_verify(ctx_.DefaultContext(), data_in,
nullptr, data_out));
}
data_object->Swap({
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
});
return err;
return VerifyFileImpl(ctx_, data_path, sign_path, data_object);
},
"gpgme_op_verify", "2.1.0");
}
auto EncryptSignFileGpgDataImpl(GpgContext& ctx_,
GpgBasicOperator& basic_opera_,
const KeyArgsList& keys,
const KeyArgsList& signer_keys,
GpgData& data_in, bool ascii, GpgData& data_out,
const DataObjectPtr& data_object) -> GpgError {
GpgError err;
auto recipients = Convert2RawGpgMEKeyList(keys);
basic_opera_.SetSigners(signer_keys, ascii);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_encrypt_sign(
ctx, recipients.data(), GPGME_ENCRYPT_ALWAYS_TRUST, data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
GpgSignResult(gpgme_op_sign_result(ctx)),
});
return err;
}
auto EncryptSignFileImpl(GpgContext& ctx_, GpgBasicOperator& basic_opera_,
const KeyArgsList& keys,
const KeyArgsList& signer_keys, const QString& in_path,
bool ascii, const QString& out_path,
const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
return EncryptSignFileGpgDataImpl(ctx_, basic_opera_, keys, signer_keys,
data_in, ascii, data_out, data_object);
}
void GpgFileOpera::EncryptSignFile(const KeyArgsList& keys,
const KeyArgsList& signer_keys,
const QString& in_path, bool ascii,
const QString& out_path,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
GpgBasicOperator::GetInstance(GetChannel())
.SetSigners(signer_keys, ascii);
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_encrypt_sign(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
GpgSignResult(gpgme_op_sign_result(ctx)),
});
return err;
[=](const DataObjectPtr& data_object) {
return EncryptSignFileImpl(ctx_, basic_opera_, keys, signer_keys,
in_path, ascii, out_path, data_object);
},
cb, "gpgme_op_encrypt_sign", "2.1.0");
}
@ -334,29 +333,9 @@ auto GpgFileOpera::EncryptSignFileSync(
const QString& in_path, bool ascii,
const QString& out_path) -> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
GpgBasicOperator::GetInstance(GetChannel())
.SetSigners(signer_keys, ascii);
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_encrypt_sign(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
GpgSignResult(gpgme_op_sign_result(ctx)),
});
return err;
[=](const DataObjectPtr& data_object) {
return EncryptSignFileImpl(ctx_, basic_opera_, keys, signer_keys,
in_path, ascii, out_path, data_object);
},
"gpgme_op_encrypt_sign", "2.1.0");
}
@ -366,43 +345,42 @@ void GpgFileOpera::EncryptSignDirectory(const KeyArgsList& keys,
const QString& in_path, bool ascii,
const QString& out_path,
const GpgOperationCallback& cb) {
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
auto w_ex = std::weak_ptr<GFDataExchanger>(ex);
auto ex = CreateStandardGFDataExchanger();
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
recipients.emplace_back(nullptr);
GpgBasicOperator::GetInstance(GetChannel())
.SetSigners(signer_keys, ascii);
GpgData data_in(ex);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
err = CheckGpgError(gpgme_op_encrypt_sign(ctx, recipients.data(),
GPGME_ENCRYPT_ALWAYS_TRUST,
data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
GpgSignResult(gpgme_op_sign_result(ctx)),
});
return err;
return EncryptSignFileGpgDataImpl(ctx_, basic_opera_, keys, signer_keys,
data_in, ascii, data_out,
data_object);
},
cb, "gpgme_op_encrypt_sign", "2.1.0");
ArchiveFileOperator::NewArchive2DataExchanger(
in_path, ex, [=](GFError err, const DataObjectPtr&) {
FLOG_D("new archive 2 fd operation, err: %d", err);
if (decltype(ex) p_ex = w_ex.lock(); err < 0 && p_ex != nullptr) {
ex->CloseWrite();
}
});
CreateArchiveHelper(in_path, ex);
}
auto DecryptVerifyFileGpgDataImpl(
GpgContext& ctx_, GpgData& data_in, GpgData& data_out,
const DataObjectPtr& data_object) -> GpgError {
auto err = CheckGpgError(
gpgme_op_decrypt_verify(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap({
GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
});
return err;
}
auto DecryptVerifyFileImpl(GpgContext& ctx_, const QString& in_path,
const QString& out_path,
const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
return DecryptVerifyFileGpgDataImpl(ctx_, data_in, data_out, data_object);
}
void GpgFileOpera::DecryptVerifyFile(const QString& in_path,
@ -410,20 +388,7 @@ void GpgFileOpera::DecryptVerifyFile(const QString& in_path,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
err = CheckGpgError(
gpgme_op_decrypt_verify(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap({
GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
});
return err;
return DecryptVerifyFileImpl(ctx_, in_path, out_path, data_object);
},
cb, "gpgme_op_decrypt_verify", "2.1.0");
}
@ -433,20 +398,7 @@ auto GpgFileOpera::DecryptVerifyFileSync(const QString& in_path,
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
err = CheckGpgError(
gpgme_op_decrypt_verify(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap({
GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
});
return err;
return DecryptVerifyFileImpl(ctx_, in_path, out_path, data_object);
},
"gpgme_op_decrypt_verify", "2.1.0");
}
@ -454,29 +406,14 @@ auto GpgFileOpera::DecryptVerifyFileSync(const QString& in_path,
void GpgFileOpera::DecryptVerifyArchive(const QString& in_path,
const QString& out_path,
const GpgOperationCallback& cb) {
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
ArchiveFileOperator::ExtractArchiveFromDataExchanger(
ex, out_path, [](GFError err, const DataObjectPtr&) {
FLOG_D("extract archive from ex operation, err: %d", err);
});
auto ex = ExtractArchiveHelper(out_path);
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgError err;
GpgData data_in(in_path, true);
GpgData data_out(ex);
err = CheckGpgError(
gpgme_op_decrypt_verify(ctx_.DefaultContext(), data_in, data_out));
data_object->Swap({
GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext())),
GpgVerifyResult(gpgme_op_verify_result(ctx_.DefaultContext())),
});
return err;
return DecryptVerifyFileGpgDataImpl(ctx_, data_in, data_out,
data_object);
},
cb, "gpgme_op_decrypt_verify", "2.1.0");
}
@ -486,17 +423,7 @@ void GpgFileOpera::EncryptFileSymmetric(const QString& in_path, bool ascii,
const GpgOperationCallback& cb) {
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(
ctx, nullptr, GPGME_ENCRYPT_SYMMETRIC, data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
});
return err;
return EncryptFileImpl(ctx_, {}, in_path, ascii, out_path, data_object);
},
cb, "gpgme_op_encrypt_symmetric", "2.1.0");
}
@ -506,73 +433,45 @@ auto GpgFileOpera::EncryptFileSymmetricSync(const QString& in_path, bool ascii,
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(in_path, true);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(
ctx, nullptr, GPGME_ENCRYPT_SYMMETRIC, data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
});
return err;
return EncryptFileImpl(ctx_, {}, in_path, ascii, out_path, data_object);
},
"gpgme_op_encrypt_symmetric", "2.1.0");
}
void GpgFileOpera::EncryptDerectorySymmetric(const QString& in_path, bool ascii,
void GpgFileOpera::EncryptDirectorySymmetric(const QString& in_path, bool ascii,
const QString& out_path,
const GpgOperationCallback& cb) {
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
auto ex = CreateStandardGFDataExchanger();
RunGpgOperaAsync(
[=](const DataObjectPtr& data_object) -> GpgError {
[=](const DataObjectPtr& data_object) {
GpgData data_in(ex);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(
ctx, nullptr, GPGME_ENCRYPT_SYMMETRIC, data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
});
return err;
return EncryptFileGpgDataImpl(ctx_, {}, data_in, ascii, data_out,
data_object);
},
cb, "gpgme_op_encrypt_symmetric", "2.1.0");
ArchiveFileOperator::NewArchive2DataExchanger(
in_path, ex, [=](GFError err, const DataObjectPtr&) {
FLOG_D("new archive 2 fd operation, err: %d", err);
});
CreateArchiveHelper(in_path, ex);
}
auto GpgFileOpera::EncryptDerectorySymmetricSync(
auto GpgFileOpera::EncryptDirectorySymmetricSync(
const QString& in_path, bool ascii,
const QString& out_path) -> std::tuple<GpgError, DataObjectPtr> {
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
ArchiveFileOperator::NewArchive2DataExchanger(
in_path, ex, [=](GFError err, const DataObjectPtr&) {
FLOG_D("new archive 2 fd operation, err: %d", err);
});
auto ex = CreateStandardGFDataExchanger();
return RunGpgOperaSync(
[=](const DataObjectPtr& data_object) -> GpgError {
GpgData data_in(ex);
GpgData data_out(out_path, false);
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
auto err = CheckGpgError(gpgme_op_encrypt(
ctx, nullptr, GPGME_ENCRYPT_SYMMETRIC, data_in, data_out));
data_object->Swap({
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
});
return err;
return EncryptFileGpgDataImpl(ctx_, {}, data_in, ascii, data_out,
data_object);
},
"gpgme_op_encrypt_symmetric", "2.1.0");
CreateArchiveHelper(in_path, ex);
}
} // namespace GpgFrontend

View File

@ -29,8 +29,8 @@
#pragma once
#include "core/function/basic/GpgFunctionObject.h"
#include "core/function/gpg/GpgBasicOperator.h"
#include "core/function/gpg/GpgContext.h"
#include "core/function/result_analyse/GpgResultAnalyse.h"
#include "core/typedef/GpgTypedef.h"
namespace GpgFrontend {
@ -123,7 +123,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera
* @param out_path
* @param cb
*/
void EncryptDerectorySymmetric(const QString& in_path, bool ascii,
void EncryptDirectorySymmetric(const QString& in_path, bool ascii,
const QString& out_path,
const GpgOperationCallback& cb);
@ -134,7 +134,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera
* @param ascii
* @param out_path
*/
auto EncryptDerectorySymmetricSync(const QString& in_path, bool ascii,
auto EncryptDirectorySymmetricSync(const QString& in_path, bool ascii,
const QString& out_path)
-> std::tuple<GpgError, DataObjectPtr>;
@ -296,6 +296,9 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera
private:
GpgContext& ctx_ = GpgContext::GetInstance(
SingletonFunctionObject::GetChannel()); ///< Corresponding context
GpgBasicOperator& basic_opera_ =
GpgBasicOperator::GetInstance(SingletonFunctionObject::GetChannel());
};
} // namespace GpgFrontend

View File

@ -73,17 +73,17 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> {
return GpgKey(std::move(p_key));
}
auto FetchKey() -> KeyLinkListPtr {
auto FetchKey() -> GpgKeyList {
if (keys_search_cache_.empty()) {
FlushKeyCache();
}
auto keys_list = std::make_unique<GpgKeyLinkList>();
auto keys_list = GpgKeyList{};
{
// get the lock
std::lock_guard<std::mutex> lock(keys_cache_mutex_);
for (const auto& key : keys_cache_) {
keys_list->push_back(key);
keys_list.push_back(key);
}
}
return keys_list;
@ -149,25 +149,17 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> {
return true;
}
auto GetKeys(const KeyIdArgsListPtr& ids) -> KeyListPtr {
auto keys = std::make_unique<KeyArgsList>();
for (const auto& key_id : *ids) keys->emplace_back(GetKey(key_id, true));
auto GetKeys(const KeyIdArgsList& ids) -> GpgKeyList {
auto keys = GpgKeyList{};
for (const auto& key_id : ids) keys.emplace_back(GetKey(key_id, true));
return keys;
}
auto GetKeysCopy(const KeyLinkListPtr& keys) -> KeyLinkListPtr {
auto GetKeysCopy(const GpgKeyList& keys) -> GpgKeyList {
// get the lock
std::lock_guard<std::mutex> lock(ctx_mutex_);
auto keys_copy = std::make_unique<GpgKeyLinkList>();
for (const auto& key : *keys) keys_copy->emplace_back(key);
return keys_copy;
}
auto GetKeysCopy(const KeyListPtr& keys) -> KeyListPtr {
// get the lock
std::lock_guard<std::mutex> lock(ctx_mutex_);
auto keys_copy = std::make_unique<KeyArgsList>();
for (const auto& key : *keys) keys_copy->emplace_back(key);
auto keys_copy = GpgKeyList{};
for (const auto& key : keys) keys_copy.emplace_back(key);
return keys_copy;
}
@ -243,19 +235,15 @@ auto GpgKeyGetter::GetPubkey(const QString& key_id, bool use_cache) -> GpgKey {
auto GpgKeyGetter::FlushKeyCache() -> bool { return p_->FlushKeyCache(); }
auto GpgKeyGetter::GetKeys(const KeyIdArgsListPtr& ids) -> KeyListPtr {
auto GpgKeyGetter::GetKeys(const KeyIdArgsList& ids) -> GpgKeyList {
return p_->GetKeys(ids);
}
auto GpgKeyGetter::GetKeysCopy(const KeyLinkListPtr& keys) -> KeyLinkListPtr {
auto GpgKeyGetter::GetKeysCopy(const GpgKeyList& keys) -> GpgKeyList {
return p_->GetKeysCopy(keys);
}
auto GpgKeyGetter::GetKeysCopy(const KeyListPtr& keys) -> KeyListPtr {
return p_->GetKeysCopy(keys);
}
auto GpgKeyGetter::FetchKey() -> KeyLinkListPtr { return p_->FetchKey(); }
auto GpgKeyGetter::FetchKey() -> GpgKeyList { return p_->FetchKey(); }
auto GpgKeyGetter::GetGpgKeyTableModel() -> QSharedPointer<GpgKeyTableModel> {
return p_->GetGpgKeyTableModel();

View File

@ -68,7 +68,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyGetter
* @param ids
* @return KeyListPtr
*/
auto GetKeys(const KeyIdArgsListPtr& key_ids) -> KeyListPtr;
auto GetKeys(const KeyIdArgsList& key_ids) -> GpgKeyList;
/**
* @brief Get the Pubkey object
@ -83,7 +83,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyGetter
*
* @return KeyLinkListPtr
*/
auto FetchKey() -> KeyLinkListPtr;
auto FetchKey() -> GpgKeyList;
/**
* @brief flush the keys in the cache
@ -97,15 +97,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyGetter
* @param keys
* @return KeyListPtr
*/
auto GetKeysCopy(const KeyListPtr& keys) -> KeyListPtr;
/**
* @brief Get the Keys Copy object
*
* @param keys
* @return KeyLinkListPtr
*/
auto GetKeysCopy(const KeyLinkListPtr& keys) -> KeyLinkListPtr;
auto GetKeysCopy(const GpgKeyList& keys) -> GpgKeyList;
/**
* @brief

View File

@ -82,7 +82,7 @@ auto GpgKeyImportExporter::ExportKey(const GpgKey& key, bool secret, bool ascii,
if (shortest) mode |= GPGME_EXPORT_MODE_MINIMAL;
if (ssh_mode) mode |= GPGME_EXPORT_MODE_SSH;
std::vector<gpgme_key_t> keys_array;
QContainer<gpgme_key_t> keys_array;
// Last entry data_in array has to be nullptr
keys_array.emplace_back(key);
@ -114,7 +114,7 @@ void GpgKeyImportExporter::ExportKeys(const KeyArgsList& keys, bool secret,
if (shortest) mode |= GPGME_EXPORT_MODE_MINIMAL;
if (ssh_mode) mode |= GPGME_EXPORT_MODE_SSH;
std::vector<gpgme_key_t> keys_array(keys.begin(), keys.end());
QContainer<gpgme_key_t> keys_array(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
keys_array.emplace_back(nullptr);
@ -144,7 +144,7 @@ void GpgKeyImportExporter::ExportAllKeys(const KeyArgsList& keys, bool secret,
if (keys.empty()) return GPG_ERR_CANCELED;
int mode = 0;
std::vector<gpgme_key_t> keys_array(keys.begin(), keys.end());
QContainer<gpgme_key_t> keys_array(keys.begin(), keys.end());
// Last entry data_in array has to be nullptr
keys_array.emplace_back(nullptr);

View File

@ -61,10 +61,10 @@ auto GpgKeyManager::SignKey(const GpgKey& target, KeyArgsList& keys,
}
auto GpgKeyManager::RevSign(const GpgKey& key,
const SignIdArgsListPtr& signature_id) -> bool {
const SignIdArgsList& signature_id) -> bool {
auto& key_getter = GpgKeyGetter::GetInstance(GetChannel());
for (const auto& sign_id : *signature_id) {
for (const auto& sign_id : signature_id) {
auto signing_key = key_getter.GetKey(sign_id.first);
assert(signing_key.IsGood());
@ -271,13 +271,8 @@ auto GpgKeyManager::RevokeSubkey(const GpgKey& key, int subkey_index,
}
// dealing with reason text
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 4)
auto reason_text_lines = SecureCreateSharedObject<QList<QString>>(
auto reason_text_lines = SecureCreateSharedObject<QStringList>(
reason_text.split('\n', Qt::SkipEmptyParts).toVector());
#else
auto reason_text_lines = SecureCreateSharedObject<QVector<QString>>(
reason_text.split('\n', Qt::SkipEmptyParts).toVector());
#endif
AutomatonNextStateHandler next_state_handler =
[](AutomatonState state, QString status, QString args) {

View File

@ -68,7 +68,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager
* @return false
*/
auto RevSign(const GpgFrontend::GpgKey& key,
const GpgFrontend::SignIdArgsListPtr& signature_id) -> bool;
const GpgFrontend::SignIdArgsList& signature_id) -> bool;
/**
* @brief Set the Expire object

View File

@ -28,14 +28,12 @@
#include "GpgKeyOpera.h"
#include <gpg-error.h>
#include "core/GpgModel.h"
#include "core/function/gpg/GpgCommandExecutor.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/model/DataObject.h"
#include "core/model/GpgGenKeyInfo.h"
#include "core/model/GpgGenerateKeyResult.h"
#include "core/model/GpgKeyGenerateInfo.h"
#include "core/module/ModuleManager.h"
#include "core/typedef/GpgTypedef.h"
#include "core/utils/AsyncUtils.h"
@ -51,9 +49,9 @@ GpgKeyOpera::GpgKeyOpera(int channel)
* Delete keys
* @param uidList key ids
*/
void GpgKeyOpera::DeleteKeys(KeyIdArgsListPtr key_ids) {
void GpgKeyOpera::DeleteKeys(KeyIdArgsList key_ids) {
GpgError err;
for (const auto& tmp : *key_ids) {
for (const auto& tmp : key_ids) {
auto key = GpgKeyGetter::GetInstance(GetChannel()).GetKey(tmp);
if (key.IsGood()) {
err = CheckGpgError(gpgme_op_delete_ext(
@ -112,15 +110,8 @@ void GpgKeyOpera::GenerateRevokeCert(const GpgKey& key,
<< "text:" << revocation_reason_text;
// dealing with reason text
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 4)
auto reason_text_lines =
GpgFrontend::SecureCreateSharedObject<QList<QString>>(
revocation_reason_text.split('\n', Qt::SkipEmptyParts).toVector());
#else
auto reason_text_lines =
GpgFrontend::SecureCreateSharedObject<QVector<QString>>(
revocation_reason_text.split('\n', Qt::SkipEmptyParts).toVector());
#endif
auto reason_text_lines = GpgFrontend::SecureCreateSharedObject<QStringList>(
revocation_reason_text.split('\n', Qt::SkipEmptyParts).toVector());
const auto app_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.app_path", QString{});
@ -170,337 +161,174 @@ void GpgKeyOpera::GenerateRevokeCert(const GpgKey& key,
}});
}
auto GenerateKeyImpl(GpgContext& ctx,
const QSharedPointer<KeyGenerateInfo>& params,
const DataObjectPtr& data_object) -> GpgError {
if (params == nullptr || params->GetAlgo() == KeyGenerateInfo::kNoneAlgo ||
params->IsSubKey()) {
return GPG_ERR_CANCELED;
}
const auto userid = params->GetUserid();
const auto algo = params->GetAlgo().Id();
unsigned long expires =
QDateTime::currentDateTime().secsTo(params->GetExpireTime());
GpgError err;
unsigned int flags = 0;
if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT;
if (params->IsAllowEncr()) flags |= GPGME_CREATE_ENCR;
if (params->IsAllowSign()) flags |= GPGME_CREATE_SIGN;
if (params->IsAllowAuth()) flags |= GPGME_CREATE_AUTH;
if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << "key generation args: " << userid << algo << expires << flags;
LOG_D() << "key generation flags" << params->IsAllowEncr()
<< params->IsAllowSign() << params->IsAllowAuth()
<< !params->IsSubKey();
err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(), algo.toUtf8(),
0, expires, nullptr, flags);
if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
data_object->Swap(
{GpgGenerateKeyResult{gpgme_op_genkey_result(ctx.DefaultContext())}});
} else {
data_object->Swap({GpgGenerateKeyResult{}});
}
return CheckGpgError(err);
}
/**
* Generate a new key pair
* @param params key generation args
* @return error information
*/
void GpgKeyOpera::GenerateKey(const std::shared_ptr<GenKeyInfo>& params,
void GpgKeyOpera::GenerateKey(const QSharedPointer<KeyGenerateInfo>& params,
const GpgOperationCallback& callback) {
RunGpgOperaAsync(
[&ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError {
auto userid = params->GetUserid();
auto algo = params->GetAlgo() + params->GetKeySizeStr();
LOG_D() << "params: " << params->GetAlgo() << params->GetKeySizeStr();
unsigned long expires =
QDateTime::currentDateTime().secsTo(params->GetExpireTime());
GpgError err;
unsigned int flags = 0;
if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT;
if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR;
if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN;
if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << "key generation args: " << userid << algo << expires
<< flags;
err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(),
algo.toUtf8(), 0, expires, nullptr, flags);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);
if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{
gpgme_op_genkey_result(ctx.DefaultContext())}});
} else {
data_object->Swap({GpgGenerateKeyResult{}});
}
return CheckGpgError(err);
[=](const DataObjectPtr& data_object) -> GpgError {
return GenerateKeyImpl(ctx_, params, data_object);
},
callback, "gpgme_op_createkey", "2.1.0");
}
auto GpgKeyOpera::GenerateKeySync(const std::shared_ptr<GenKeyInfo>& params)
auto GpgKeyOpera::GenerateKeySync(const QSharedPointer<KeyGenerateInfo>& params)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[=, &ctx = ctx_](const DataObjectPtr& data_object) -> GpgError {
auto userid = params->GetUserid();
auto algo = params->GetAlgo() + params->GetKeySizeStr();
LOG_D() << "params: " << params->GetAlgo() << params->GetKeySizeStr();
unsigned long expires =
QDateTime::currentDateTime().secsTo(params->GetExpireTime());
GpgError err;
unsigned int flags = 0;
if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT;
if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR;
if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN;
if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << "key generation args: " << userid << algo << expires
<< flags;
err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(),
algo.toUtf8(), 0, expires, nullptr, flags);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);
if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{
gpgme_op_genkey_result(ctx.DefaultContext())}});
} else {
data_object->Swap({GpgGenerateKeyResult{}});
}
return CheckGpgError(err);
[=](const DataObjectPtr& data_object) -> GpgError {
return GenerateKeyImpl(ctx_, params, data_object);
},
"gpgme_op_createkey", "2.1.0");
}
auto GenerateSubKeyImpl(GpgContext& ctx, const GpgKey& key,
const QSharedPointer<KeyGenerateInfo>& params,
const DataObjectPtr& data_object) -> GpgError {
if (params == nullptr || params->GetAlgo() == KeyGenerateInfo::kNoneAlgo ||
!params->IsSubKey()) {
return GPG_ERR_CANCELED;
}
auto algo = params->GetAlgo().Id();
unsigned long expires =
QDateTime::currentDateTime().secsTo(params->GetExpireTime());
unsigned int flags = 0;
if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT;
if (params->IsAllowEncr()) flags |= GPGME_CREATE_ENCR;
if (params->IsAllowSign()) flags |= GPGME_CREATE_SIGN;
if (params->IsAllowAuth()) flags |= GPGME_CREATE_AUTH;
if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << "subkey generation args: " << key.GetId() << algo << expires
<< flags;
auto err =
gpgme_op_createsubkey(ctx.DefaultContext(), static_cast<gpgme_key_t>(key),
algo.toLatin1(), 0, expires, flags);
if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{}});
return err;
}
data_object->Swap(
{GpgGenerateKeyResult{gpgme_op_genkey_result(ctx.DefaultContext())}});
return CheckGpgError(err);
}
void GpgKeyOpera::GenerateSubkey(const GpgKey& key,
const std::shared_ptr<GenKeyInfo>& params,
const QSharedPointer<KeyGenerateInfo>& params,
const GpgOperationCallback& callback) {
RunGpgOperaAsync(
[key, &ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError {
if (!params->IsSubKey()) return GPG_ERR_CANCELED;
LOG_D() << "generate subkey algo: " << params->GetAlgo()
<< "key size: " << params->GetKeySizeStr();
auto algo = params->GetAlgo() + params->GetKeySizeStr();
unsigned long expires =
QDateTime::currentDateTime().secsTo(params->GetExpireTime());
unsigned int flags = 0;
if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT;
if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR;
if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN;
if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << "subkey generation args: " << key.GetId() << algo << expires
<< flags;
auto err = gpgme_op_createsubkey(ctx.DefaultContext(),
static_cast<gpgme_key_t>(key),
algo.toLatin1(), 0, expires, flags);
if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{}});
return err;
}
data_object->Swap({GpgGenerateKeyResult{
gpgme_op_genkey_result(ctx.DefaultContext())}});
return CheckGpgError(err);
[=](const DataObjectPtr& data_object) -> GpgError {
return GenerateSubKeyImpl(ctx_, key, params, data_object);
},
callback, "gpgme_op_createsubkey", "2.1.13");
}
auto GpgKeyOpera::GenerateSubkeySync(const GpgKey& key,
const std::shared_ptr<GenKeyInfo>& params)
auto GpgKeyOpera::GenerateSubkeySync(
const GpgKey& key, const QSharedPointer<KeyGenerateInfo>& params)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[key, &ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError {
if (!params->IsSubKey()) return GPG_ERR_CANCELED;
LOG_D() << "generate subkey algo: " << params->GetAlgo()
<< " key size: " << params->GetKeySizeStr();
auto algo = params->GetAlgo() + params->GetKeySizeStr();
unsigned long expires =
QDateTime::currentDateTime().secsTo(params->GetExpireTime());
unsigned int flags = 0;
if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT;
if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR;
if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN;
if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << " args: " << key.GetId() << algo << expires << flags;
auto err = gpgme_op_createsubkey(ctx.DefaultContext(),
static_cast<gpgme_key_t>(key),
algo.toLatin1(), 0, expires, flags);
if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{}});
return err;
}
data_object->Swap({GpgGenerateKeyResult{
gpgme_op_genkey_result(ctx.DefaultContext())}});
return CheckGpgError(err);
[=](const DataObjectPtr& data_object) -> GpgError {
return GenerateSubKeyImpl(ctx_, key, params, data_object);
},
"gpgme_op_createsubkey", "2.1.13");
}
auto GenerateKeyWithSubkeyImpl(GpgContext& ctx, GpgKeyGetter& key_getter,
const QSharedPointer<KeyGenerateInfo>& p_params,
const QSharedPointer<KeyGenerateInfo>& s_params,
const DataObjectPtr& data_object) -> GpgError {
auto err = GenerateKeyImpl(ctx, p_params, data_object);
if (err != GPG_ERR_NO_ERROR) return err;
if (!data_object->Check<GpgGenerateKeyResult>()) return GPG_ERR_CANCELED;
auto result = ExtractParams<GpgGenerateKeyResult>(data_object, 0);
auto key = key_getter.GetKey(result.GetFingerprint());
if (!key.IsGood()) {
LOG_W() << "cannot get key which has been generated, fpr: "
<< result.GetFingerprint();
return GPG_ERR_CANCELED;
}
if (s_params == nullptr) return err;
data_object->Swap({});
err = GenerateSubKeyImpl(ctx, key, s_params, data_object);
auto s_result = ExtractParams<GpgGenerateKeyResult>(data_object, 0);
data_object->Swap({result, s_result});
return err;
}
void GpgKeyOpera::GenerateKeyWithSubkey(
const std::shared_ptr<GenKeyInfo>& params,
const std::shared_ptr<GenKeyInfo>& subkey_params,
const QSharedPointer<KeyGenerateInfo>& p_params,
const QSharedPointer<KeyGenerateInfo>& s_params,
const GpgOperationCallback& callback) {
RunGpgOperaAsync(
[&ctx = ctx_, params, subkey_params,
channel = GetChannel()](const DataObjectPtr& data_object) -> GpgError {
auto userid = params->GetUserid().toUtf8();
auto algo = (params->GetAlgo() + params->GetKeySizeStr()).toUtf8();
unsigned long expires =
QDateTime::currentDateTime().secsTo(params->GetExpireTime());
GpgError err;
unsigned int flags = 0;
if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT;
if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR;
if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN;
if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << "key generation args: " << userid << algo << expires
<< flags;
err = gpgme_op_createkey(ctx.DefaultContext(), userid, algo, 0, expires,
nullptr, flags);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);
if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{}});
return err;
}
auto genkey_result =
GpgGenerateKeyResult{gpgme_op_genkey_result(ctx.DefaultContext())};
if (subkey_params == nullptr || !subkey_params->IsSubKey()) {
data_object->Swap({genkey_result});
return err;
}
auto key = GpgKeyGetter::GetInstance(channel).GetKey(
genkey_result.GetFingerprint());
if (!key.IsGood()) {
LOG_W() << "cannot get key which has been generate, fpr: "
<< genkey_result.GetFingerprint();
return err;
}
algo = (subkey_params->GetAlgo() + subkey_params->GetKeySizeStr())
.toUtf8();
expires =
QDateTime::currentDateTime().secsTo(subkey_params->GetExpireTime());
flags = 0;
if (subkey_params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR;
if (subkey_params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN;
if (subkey_params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
if (subkey_params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (subkey_params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << "subkey generation args: " << key.GetId() << algo << expires
<< flags;
err = gpgme_op_createsubkey(ctx.DefaultContext(),
static_cast<gpgme_key_t>(key), algo, 0,
expires, flags);
if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
data_object->Swap(
{genkey_result, GpgGenerateKeyResult{gpgme_op_genkey_result(
ctx.DefaultContext())}});
} else {
data_object->Swap({genkey_result, GpgGenerateKeyResult{}});
}
return CheckGpgError(err);
[=](const DataObjectPtr& data_object) -> GpgError {
return GenerateKeyWithSubkeyImpl(ctx_, key_getter_, p_params, s_params,
data_object);
},
callback, "gpgme_op_createkey&gpgme_op_createsubkey", "2.1.0");
}
auto GpgKeyOpera::GenerateKeyWithSubkeySync(
const std::shared_ptr<GenKeyInfo>& params,
const std::shared_ptr<GenKeyInfo>& subkey_params)
const QSharedPointer<KeyGenerateInfo>& p_params,
const QSharedPointer<KeyGenerateInfo>& s_params)
-> std::tuple<GpgError, DataObjectPtr> {
return RunGpgOperaSync(
[&ctx = ctx_, params, subkey_params,
channel = GetChannel()](const DataObjectPtr& data_object) -> GpgError {
auto userid = params->GetUserid().toUtf8();
auto algo = (params->GetAlgo() + params->GetKeySizeStr()).toUtf8();
unsigned long expires =
QDateTime::currentDateTime().secsTo(params->GetExpireTime());
GpgError err;
unsigned int flags = 0;
if (!params->IsSubKey()) flags |= GPGME_CREATE_CERT;
if (params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR;
if (params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN;
if (params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << "key generation args: " << userid << algo << expires
<< flags;
err = gpgme_op_createkey(ctx.DefaultContext(), userid, algo, 0, expires,
nullptr, flags);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);
if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{}});
return err;
}
auto genkey_result =
GpgGenerateKeyResult{gpgme_op_genkey_result(ctx.DefaultContext())};
if (subkey_params == nullptr || !subkey_params->IsSubKey()) {
data_object->Swap({genkey_result});
return err;
}
auto key = GpgKeyGetter::GetInstance(channel).GetKey(
genkey_result.GetFingerprint());
if (!key.IsGood()) {
LOG_W() << "cannot get key which has been generate, fpr: "
<< genkey_result.GetFingerprint();
return err;
}
LOG_D() << "try to generate subkey of key: " << key.GetId()
<< ", algo :" << subkey_params->GetAlgo()
<< ", key size: " << subkey_params->GetKeySizeStr();
algo = (subkey_params->GetAlgo() + subkey_params->GetKeySizeStr())
.toUtf8();
expires =
QDateTime::currentDateTime().secsTo(subkey_params->GetExpireTime());
flags = 0;
if (subkey_params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR;
if (subkey_params->IsAllowSigning()) flags |= GPGME_CREATE_SIGN;
if (subkey_params->IsAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
if (subkey_params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
if (subkey_params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
LOG_D() << "subkey generation args: " << key.GetId() << algo << expires
<< flags;
err = gpgme_op_createsubkey(ctx.DefaultContext(),
static_cast<gpgme_key_t>(key), algo, 0,
expires, flags);
if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
data_object->Swap(
{genkey_result, GpgGenerateKeyResult{gpgme_op_genkey_result(
ctx.DefaultContext())}});
} else {
data_object->Swap({genkey_result, GpgGenerateKeyResult{}});
}
return CheckGpgError(err);
[=](const DataObjectPtr& data_object) -> GpgError {
return GenerateKeyWithSubkeyImpl(ctx_, key_getter_, p_params, s_params,
data_object);
},
"gpgme_op_createkey&gpgme_op_createsubkey", "2.1.0");
}
@ -532,8 +360,8 @@ auto GpgKeyOpera::ModifyTOFUPolicy(
}
void GpgKeyOpera::DeleteKey(const KeyId& key_id) {
auto keys = std::make_unique<KeyIdArgsList>();
keys->push_back(key_id);
DeleteKeys(std::move(keys));
auto keys = KeyIdArgsList{};
keys.push_back(key_id);
DeleteKeys(keys);
}
} // namespace GpgFrontend

View File

@ -31,6 +31,7 @@
#include <functional>
#include "core/function/gpg/GpgContext.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/typedef/GpgTypedef.h"
namespace GpgFrontend {
@ -38,7 +39,7 @@ namespace GpgFrontend {
* @brief
*
*/
class GenKeyInfo;
class KeyGenerateInfo;
/**
* @brief
@ -60,7 +61,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
*
* @param key_ids
*/
void DeleteKeys(KeyIdArgsListPtr key_ids);
void DeleteKeys(KeyIdArgsList key_ids);
/**
* @brief
@ -114,7 +115,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @param result
* @return GpgFrontend::GpgError
*/
void GenerateKey(const std::shared_ptr<GenKeyInfo>&,
void GenerateKey(const QSharedPointer<KeyGenerateInfo>&,
const GpgOperationCallback&);
/**
@ -122,7 +123,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
*
* @param params
*/
auto GenerateKeySync(const std::shared_ptr<GenKeyInfo>& params)
auto GenerateKeySync(const QSharedPointer<KeyGenerateInfo>& params)
-> std::tuple<GpgError, DataObjectPtr>;
/**
@ -133,7 +134,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @return GpgFrontend::GpgError
*/
void GenerateSubkey(const GpgKey& key,
const std::shared_ptr<GenKeyInfo>& params,
const QSharedPointer<KeyGenerateInfo>& params,
const GpgOperationCallback&);
/**
@ -143,7 +144,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @param params
*/
auto GenerateSubkeySync(const GpgKey& key,
const std::shared_ptr<GenKeyInfo>& params)
const QSharedPointer<KeyGenerateInfo>& params)
-> std::tuple<GpgError, DataObjectPtr>;
/**
@ -153,8 +154,8 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @param subkey_params
* @param callback
*/
void GenerateKeyWithSubkey(const std::shared_ptr<GenKeyInfo>& params,
const std::shared_ptr<GenKeyInfo>& subkey_params,
void GenerateKeyWithSubkey(const QSharedPointer<KeyGenerateInfo>& p_params,
const QSharedPointer<KeyGenerateInfo>& s_params,
const GpgOperationCallback& callback);
/**
@ -165,12 +166,15 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
* @param callback
*/
auto GenerateKeyWithSubkeySync(
const std::shared_ptr<GenKeyInfo>& params,
const std::shared_ptr<GenKeyInfo>& subkey_params)
const QSharedPointer<KeyGenerateInfo>& p_params,
const QSharedPointer<KeyGenerateInfo>& s_params)
-> std::tuple<GpgError, DataObjectPtr>;
private:
GpgContext& ctx_ =
GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///<
GpgKeyGetter& key_getter_ =
GpgKeyGetter::GetInstance(SingletonFunctionObject::GetChannel()); ///<
};
} // namespace GpgFrontend

View File

@ -155,15 +155,8 @@ auto GpgUIDOperator::RevokeUID(const GpgKey& key, int uid_index,
}
// dealing with reason text
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 4)
auto reason_text_lines =
GpgFrontend::SecureCreateSharedObject<QList<QString>>(
reason_text.split('\n', Qt::SkipEmptyParts).toVector());
#else
auto reason_text_lines =
GpgFrontend::SecureCreateSharedObject<QVector<QString>>(
reason_text.split('\n', Qt::SkipEmptyParts).toVector());
#endif
auto reason_text_lines = GpgFrontend::SecureCreateSharedObject<QStringList>(
reason_text.split('\n', Qt::SkipEmptyParts).toVector());
AutomatonNextStateHandler next_state_handler = [](AutomatonState state,
QString status,

View File

@ -27,10 +27,6 @@
*/
#pragma once
#include <sstream>
#include "core/typedef/GpgTypedef.h"
namespace GpgFrontend {
class GPGFRONTEND_CORE_EXPORT GpgResultAnalyse : public QObject {

View File

@ -256,6 +256,6 @@ auto GpgFrontend::GpgVerifyResultAnalyse::TakeChargeOfResult()
}
auto GpgFrontend::GpgVerifyResultAnalyse::GetUnknownSignatures() const
-> QList<QString> {
-> QStringList {
return unknown_signer_fpr_list_;
}

View File

@ -65,9 +65,9 @@ class GPGFRONTEND_CORE_EXPORT GpgVerifyResultAnalyse : public GpgResultAnalyse {
/**
* @brief Get the Unknown Signatures object
*
* @return QList<QString>
* @return QStringList
*/
[[nodiscard]] auto GetUnknownSignatures() const -> QList<QString>;
[[nodiscard]] auto GetUnknownSignatures() const -> QStringList;
protected:
/**
@ -99,7 +99,7 @@ class GPGFRONTEND_CORE_EXPORT GpgVerifyResultAnalyse : public GpgResultAnalyse {
GpgError error_; ///<
GpgVerifyResult result_; ///<
QList<QString> unknown_signer_fpr_list_;
QStringList unknown_signer_fpr_list_;
};
} // namespace GpgFrontend

View File

@ -28,7 +28,7 @@
#include "DataObject.h"
#include <stack>
#include "core/typedef/CoreTypedef.h"
namespace GpgFrontend {
@ -50,7 +50,7 @@ class DataObject::Impl {
auto GetObjectSize() -> size_t { return params_.size(); }
private:
std::vector<std::any> params_;
QContainer<std::any> params_;
};
DataObject::DataObject() : p_(SecureCreateUniqueObject<Impl>()) {}

View File

@ -33,13 +33,11 @@
#include <typeinfo>
#include "core/GpgFrontendCoreExport.h"
#include "core/typedef/CoreTypedef.h"
#include "core/utils/MemoryUtils.h"
namespace GpgFrontend {
class DataObject;
using DataObjectPtr = std::shared_ptr<DataObject>; ///<
class GPGFRONTEND_CORE_EXPORT DataObject {
public:
DataObject();
@ -66,7 +64,7 @@ class GPGFRONTEND_CORE_EXPORT DataObject {
auto Check() -> bool {
if (sizeof...(Args) != GetObjectSize()) return false;
std::vector<std::type_info const*> type_list = {&typeid(Args)...};
QContainer<std::type_info const*> type_list = {&typeid(Args)...};
for (size_t i = 0; i < type_list.size(); ++i) {
if (std::type_index(*type_list[i]) !=
std::type_index((*this)[i].type())) {

View File

@ -28,10 +28,14 @@
#pragma once
#include <cstddef>
#include <queue>
namespace GpgFrontend {
constexpr ssize_t kDataExchangerSize =
static_cast<const ssize_t>(1024 * 1024 * 8); // 8 MB
class GFDataExchanger {
public:
explicit GFDataExchanger(ssize_t size);
@ -50,4 +54,8 @@ class GFDataExchanger {
std::atomic_bool close_ = false;
};
inline auto CreateStandardGFDataExchanger() -> QSharedPointer<GFDataExchanger> {
return QSharedPointer<GFDataExchanger>::create(kDataExchangerSize);
}
} // namespace GpgFrontend

View File

@ -104,7 +104,7 @@ GpgData::GpgData(const QString& path, bool read) {
data_ref_ = std::unique_ptr<struct gpgme_data, DataRefDeleter>(data);
}
GpgData::GpgData(std::shared_ptr<GFDataExchanger> ex)
GpgData::GpgData(QSharedPointer<GFDataExchanger> ex)
: data_cbs_(), data_ex_(std::move(ex)) {
gpgme_data_t data;

View File

@ -71,7 +71,7 @@ class GPGFRONTEND_CORE_EXPORT GpgData {
*
* @param fd
*/
explicit GpgData(std::shared_ptr<GFDataExchanger>);
explicit GpgData(QSharedPointer<GFDataExchanger>);
/**
* @brief Construct a new Gpg Data object
@ -124,7 +124,7 @@ class GPGFRONTEND_CORE_EXPORT GpgData {
int fd_ = -1;
struct gpgme_data_cbs data_cbs_;
std::shared_ptr<GFDataExchanger> data_ex_;
QSharedPointer<GFDataExchanger> data_ex_;
};
} // namespace GpgFrontend

View File

@ -48,8 +48,8 @@ auto GpgDecryptResult::GetRaw() -> gpgme_decrypt_result_t {
return result_ref_.get();
}
auto GpgDecryptResult::Recipients() -> std::vector<GpgRecipient> {
std::vector<GpgRecipient> result;
auto GpgDecryptResult::Recipients() -> QContainer<GpgRecipient> {
QContainer<GpgRecipient> result;
for (auto* reci = result_ref_->recipients; reci != nullptr;
reci = reci->next) {
try {

View File

@ -39,7 +39,7 @@ class GPGFRONTEND_CORE_EXPORT GpgDecryptResult {
auto GetRaw() -> gpgme_decrypt_result_t;
auto Recipients() -> std::vector<GpgRecipient>;
auto Recipients() -> QContainer<GpgRecipient>;
explicit GpgDecryptResult(gpgme_decrypt_result_t);

View File

@ -48,8 +48,8 @@ auto GpgEncryptResult::GetRaw() -> gpgme_encrypt_result_t {
}
auto GpgEncryptResult::InvalidRecipients()
-> std::vector<std::tuple<QString, GpgError>> {
std::vector<std::tuple<QString, GpgError>> result;
-> QContainer<std::tuple<QString, GpgError>> {
QContainer<std::tuple<QString, GpgError>> result;
for (auto* invalid_key = result_ref_->invalid_recipients;
invalid_key != nullptr; invalid_key = invalid_key->next) {
try {

View File

@ -38,7 +38,7 @@ class GPGFRONTEND_CORE_EXPORT GpgEncryptResult {
auto GetRaw() -> gpgme_encrypt_result_t;
auto InvalidRecipients() -> std::vector<std::tuple<QString, GpgError>>;
auto InvalidRecipients() -> QContainer<std::tuple<QString, GpgError>>;
explicit GpgEncryptResult(gpgme_encrypt_result_t);

View File

@ -1,593 +0,0 @@
/**
* Copyright (C) 2021-2024 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
*
*/
#include "GpgGenKeyInfo.h"
#include <cassert>
#include "module/ModuleManager.h"
#include "utils/CommonUtils.h"
namespace GpgFrontend {
void GenKeyInfo::SetAlgo(const QString &t_algo_args) {
auto algo_args = t_algo_args.toLower();
// reset all options
reset_options();
if (!this->subkey_) {
this->SetAllowCertification(true);
} else {
this->SetAllowCertification(false);
}
this->allow_change_certification_ = false;
if (algo_args == "rsa") {
/**
* RSA is the worlds premier asymmetric cryptographic algorithm,
* and is built on the difficulty of factoring extremely large composites.
* GnuPG supports RSA with key sizes of between 1024 and 4096 bits.
*/
suggest_min_key_size_ = 1024;
suggest_max_key_size_ = 4096;
suggest_size_addition_step_ = 1024;
SetKeyLength(2048);
} else if (algo_args == "dsa") {
/**
* Algorithm (DSA) as a government standard for digital signatures.
* Originally, it supported key lengths between 512 and 1024 bits.
* Recently, NIST has declared 512-bit keys obsolete:
* now, DSA is available in 1024, 2048 and 3072-bit lengths.
*/
SetAllowEncryption(false);
allow_change_encryption_ = false;
suggest_min_key_size_ = 1024;
suggest_max_key_size_ = 3072;
suggest_size_addition_step_ = 1024;
SetKeyLength(2048);
} else if (algo_args == "elg") {
/**
* GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths
* ranging from 1024 to 4096 bits.
*/
SetAllowEncryption(true);
SetAllowAuthentication(false);
allow_change_authentication_ = false;
SetAllowSigning(false);
allow_change_signing_ = false;
suggest_min_key_size_ = 1024;
suggest_max_key_size_ = 4096;
suggest_size_addition_step_ = 1024;
SetKeyLength(3072);
} else if (algo_args == "ed25519") {
SetAllowEncryption(false);
allow_change_encryption_ = false;
suggest_min_key_size_ = -1;
suggest_max_key_size_ = -1;
suggest_size_addition_step_ = -1;
SetKeyLength(-1);
} else if (algo_args == "cv25519" || algo_args == "x448") {
SetAllowAuthentication(false);
allow_change_authentication_ = false;
SetAllowSigning(false);
allow_change_signing_ = false;
suggest_min_key_size_ = -1;
suggest_max_key_size_ = -1;
suggest_size_addition_step_ = -1;
SetKeyLength(-1);
} else if (algo_args == "ed448") {
SetAllowEncryption(false);
allow_change_encryption_ = false;
// it should allow signing or it's bug
SetAllowSigning(true);
allow_change_signing_ = true;
suggest_min_key_size_ = -1;
suggest_max_key_size_ = -1;
suggest_size_addition_step_ = -1;
SetKeyLength(-1);
} else if (algo_args == "nistp256" || algo_args == "nistp384" ||
algo_args == "nistp521" || algo_args == "brainpoolp256r1" ||
algo_args == "brainpoolp384r1" || algo_args == "brainpoolp512r1" ||
algo_args == "secp256k1") {
if (!subkey_) { // for primary key is always ecdsa
SetAllowEncryption(false);
allow_change_encryption_ = false;
} else { // for subkey key is always ecdh
SetAllowAuthentication(false);
allow_change_authentication_ = false;
SetAllowSigning(false);
allow_change_signing_ = false;
}
suggest_min_key_size_ = -1;
suggest_max_key_size_ = -1;
suggest_size_addition_step_ = -1;
SetKeyLength(-1);
} else {
LOG_W() << "unsupported genkey algo arguments: " << algo_args;
return;
}
this->algo_ = algo_args;
}
void GenKeyInfo::reset_options() {
allow_change_encryption_ = true;
SetAllowEncryption(true);
allow_change_certification_ = true;
SetAllowCertification(true);
allow_change_signing_ = true;
SetAllowSigning(true);
allow_change_authentication_ = true;
SetAllowAuthentication(true);
passphrase_.clear();
}
auto GenKeyInfo::GetKeySizeStr() const -> QString {
if (key_size_ > 0) {
return QString::number(key_size_);
}
return {};
}
void GenKeyInfo::SetKeyLength(int m_key_size) {
if (m_key_size < suggest_min_key_size_ ||
m_key_size > suggest_max_key_size_) {
return;
}
GenKeyInfo::key_size_ = m_key_size;
}
void GenKeyInfo::SetExpireTime(const QDateTime &m_expired) {
if (!IsNonExpired()) {
GenKeyInfo::expired_ = m_expired;
}
}
void GenKeyInfo::SetNonExpired(bool m_non_expired) {
if (!m_non_expired) this->expired_ = QDateTime::fromSecsSinceEpoch(0);
GenKeyInfo::non_expired_ = m_non_expired;
}
void GenKeyInfo::SetAllowEncryption(bool m_allow_encryption) {
if (allow_change_encryption_) {
GenKeyInfo::allow_encryption_ = m_allow_encryption;
}
}
void GenKeyInfo::SetAllowCertification(bool m_allow_certification) {
if (allow_change_certification_) {
GenKeyInfo::allow_certification_ = m_allow_certification;
}
}
GenKeyInfo::GenKeyInfo(bool m_is_sub_key) : subkey_(m_is_sub_key) {
assert(!GetSupportedKeyAlgo().empty());
SetAlgo(std::get<0>(GetSupportedKeyAlgo()[0]));
}
auto GenKeyInfo::GetSupportedKeyAlgo()
-> const std::vector<GenKeyInfo::KeyGenAlgo> & {
static std::vector<GenKeyInfo::KeyGenAlgo> k_support_key_algo = {
{"RSA", "RSA", ""},
{"DSA", "DSA", ""},
};
static bool initialized = false;
if (!initialized) {
const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gnupg_version", QString{"2.0.0"});
if (GFCompareSoftwareVersion(gnupg_version, "2.0.0") < 0) {
// do nothing
} else if (GFCompareSoftwareVersion(gnupg_version, "2.3.0") < 0) {
k_support_key_algo = {
{"RSA", "RSA", ""},
{"DSA", "DSA", ""},
{"EdDSA (ED25519)", "ED25519", ""},
{"ECDSA (NIST P-256)", "NISTP256", ""},
{"ECDSA (NIST P-384)", "NISTP384", ""},
{"ECDSA (NIST P-521)", "NISTP521", ""},
};
} else {
k_support_key_algo = {
{"RSA", "RSA", ""},
{"DSA", "DSA", ""},
{"EdDSA (ED448)", "ED448", ""},
{"EdDSA (ED25519)", "ED25519", ""},
{"ECDSA (SECP256K1)", "SECP256K1", ""},
{"ECDSA (NIST P-256)", "NISTP256", ""},
{"ECDSA (NIST P-384)", "NISTP384", ""},
{"ECDSA (NIST P-521)", "NISTP521", ""},
{"ECDSA (BrainPooL P-256)", "BRAINPOOLP256R1", ""},
{"ECDSA (BrainPooL P-384)", "BRAINPOOLP384R1", ""},
{"ECDSA (BrainPooL P-512)", "BRAINPOOLP512R1", ""},
};
}
initialized = true;
}
return k_support_key_algo;
}
auto GenKeyInfo::GetSupportedSubkeyAlgo()
-> const std::vector<GenKeyInfo::KeyGenAlgo> & {
static std::vector<GenKeyInfo::KeyGenAlgo> k_support_subkey_algo = {
{"RSA", "", "RSA"},
{"DSA", "", "DSA"},
{"ELG-E", "", "ELG"},
};
static bool initialized = false;
if (!initialized) {
const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gnupg_version", QString{"2.0.0"});
if (GFCompareSoftwareVersion(gnupg_version, "2.0.0") < 0) {
// do nothing
} else if (GFCompareSoftwareVersion(gnupg_version, "2.3.0") < 0) {
k_support_subkey_algo = {
{"RSA", "", "RSA"},
{"DSA", "", "DSA"},
{"ELG-E", "", "ELG"},
{"EdDSA (ED25519)", "", "ED25519"},
{"ECDH (CV25519)", "", "CV25519"},
{"ECDH (NIST P-256)", "", "NISTP256"},
{"ECDH (NIST P-384)", "", "NISTP384"},
{"ECDH (NIST P-521)", "", "NISTP521"},
};
} else {
k_support_subkey_algo = {
{"RSA", "", "RSA"},
{"DSA", "", "DSA"},
{"ELG-E", "", "ELG"},
{"EdDSA (ED25519)", "", "ED25519"},
{"ECDH (CV25519)", "", "CV25519"},
{"ECDH (SECP256K1)", "", "SECP256K1"},
{"EdDSA (ED448)", "", "ED448"},
{"ECDH (X448)", "", "X448"},
{"ECDH (NIST P-256)", "", "NISTP256"},
{"ECDH (NIST P-384)", "", "NISTP384"},
{"ECDH (NIST P-521)", "", "NISTP521"},
{"ECDH (BrainPooL P-256)", "", "BRAINPOOLP256R1"},
{"ECDH (BrainPooL P-384)", "", "BRAINPOOLP384R1"},
{"ECDH (BrainPooL P-512)", "", "BRAINPOOLP512R1"},
};
}
initialized = true;
}
return k_support_subkey_algo;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsSubKey() const -> bool { return subkey_; }
/**
* @brief Set the Is Sub Key object
*
* @param m_sub_key
*/
void GenKeyInfo::SetIsSubKey(bool m_sub_key) {
GenKeyInfo::subkey_ = m_sub_key;
}
/**
* @brief Get the Userid object
*
* @return QString
*/
[[nodiscard]] auto GenKeyInfo::GetUserid() const -> QString {
return QString("%1(%2)<%3>").arg(name_).arg(comment_).arg(email_);
}
/**
* @brief Set the Name object
*
* @param m_name
*/
void GenKeyInfo::SetName(const QString &m_name) { this->name_ = m_name; }
/**
* @brief Set the Email object
*
* @param m_email
*/
void GenKeyInfo::SetEmail(const QString &m_email) { this->email_ = m_email; }
/**
* @brief Set the Comment object
*
* @param m_comment
*/
void GenKeyInfo::SetComment(const QString &m_comment) {
this->comment_ = m_comment;
}
/**
* @brief Get the Name object
*
* @return QString
*/
[[nodiscard]] auto GenKeyInfo::GetName() const -> QString { return name_; }
/**
* @brief Get the Email object
*
* @return QString
*/
[[nodiscard]] auto GenKeyInfo::GetEmail() const -> QString { return email_; }
/**
* @brief Get the Comment object
*
* @return QString
*/
[[nodiscard]] auto GenKeyInfo::GetComment() const -> QString {
return comment_;
}
/**
* @brief Get the Algo object
*
* @return const QString&
*/
[[nodiscard]] auto GenKeyInfo::GetAlgo() const -> const QString & {
return algo_;
}
/**
* @brief Get the Key Size object
*
* @return int
*/
[[nodiscard]] auto GenKeyInfo::GetKeyLength() const -> int { return key_size_; }
/**
* @brief Get the Expired object
*
* @return const QDateTime&
*/
[[nodiscard]] auto GenKeyInfo::GetExpireTime() const -> const QDateTime & {
return expired_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsNonExpired() const -> bool {
return non_expired_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsNoPassPhrase() const -> bool {
return this->no_passphrase_;
}
/**
* @brief Set the Non Pass Phrase object
*
* @param m_non_pass_phrase
*/
void GenKeyInfo::SetNonPassPhrase(bool m_non_pass_phrase) {
GenKeyInfo::no_passphrase_ = m_non_pass_phrase;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsAllowSigning() const -> bool {
return allow_signing_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsAllowNoPassPhrase() const -> bool {
return allow_no_pass_phrase_;
}
/**
* @brief Set the Allow Signing object
*
* @param m_allow_signing
*/
void GenKeyInfo::SetAllowSigning(bool m_allow_signing) {
if (allow_change_signing_) GenKeyInfo::allow_signing_ = m_allow_signing;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsAllowEncryption() const -> bool {
return allow_encryption_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsAllowCertification() const -> bool {
return allow_certification_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsAllowAuthentication() const -> bool {
return allow_authentication_;
}
/**
* @brief Set the Allow Authentication object
*
* @param m_allow_authentication
*/
void GenKeyInfo::SetAllowAuthentication(bool m_allow_authentication) {
if (allow_change_authentication_) {
GenKeyInfo::allow_authentication_ = m_allow_authentication;
}
}
/**
* @brief Get the Pass Phrase object
*
* @return const QString&
*/
[[nodiscard]] auto GenKeyInfo::GetPassPhrase() const -> const QString & {
return passphrase_;
}
/**
* @brief Set the Pass Phrase object
*
* @param m_pass_phrase
*/
void GenKeyInfo::SetPassPhrase(const QString &m_pass_phrase) {
GenKeyInfo::passphrase_ = m_pass_phrase;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsAllowChangeSigning() const -> bool {
return allow_change_signing_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsAllowChangeEncryption() const -> bool {
return allow_change_encryption_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsAllowChangeCertification() const -> bool {
return allow_change_certification_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto GenKeyInfo::IsAllowChangeAuthentication() const -> bool {
return allow_change_authentication_;
}
/**
* @brief Get the Suggest Max Key Size object
*
* @return int
*/
[[nodiscard]] auto GenKeyInfo::GetSuggestMaxKeySize() const -> int {
return suggest_max_key_size_;
}
/**
* @brief Get the Suggest Min Key Size object
*
* @return int
*/
[[nodiscard]] auto GenKeyInfo::GetSuggestMinKeySize() const -> int {
return suggest_min_key_size_;
}
/**
* @brief Get the Size Change Step object
*
* @return int
*/
[[nodiscard]] auto GenKeyInfo::GetSizeChangeStep() const -> int {
return suggest_size_addition_step_;
}
} // namespace GpgFrontend

View File

@ -28,8 +28,6 @@
#include "core/model/GpgKey.h"
#include <mutex>
namespace GpgFrontend {
GpgKey::GpgKey(gpgme_key_t &&key) : key_ref_(key) {}
@ -149,21 +147,13 @@ auto GpgKey::GetPrimaryKeyLength() const -> unsigned int {
return key_ref_->subkeys->length;
}
auto GpgKey::IsHasEncryptionCapability() const -> bool {
return key_ref_->can_encrypt;
}
auto GpgKey::IsHasEncrCap() const -> bool { return key_ref_->can_encrypt; }
auto GpgKey::IsHasSigningCapability() const -> bool {
return key_ref_->can_sign;
}
auto GpgKey::IsHasSignCap() const -> bool { return key_ref_->can_sign; }
auto GpgKey::IsHasCertificationCapability() const -> bool {
return key_ref_->can_certify;
}
auto GpgKey::IsHasCertCap() const -> bool { return key_ref_->can_certify; }
auto GpgKey::IsHasAuthenticationCapability() const -> bool {
return key_ref_->can_authenticate;
}
auto GpgKey::IsHasAuthCap() const -> bool { return key_ref_->can_authenticate; }
auto GpgKey::IsHasCardKey() const -> bool {
auto subkeys = GetSubKeys();
@ -184,8 +174,8 @@ auto GpgKey::IsHasMasterKey() const -> bool {
return key_ref_->subkeys->secret;
}
auto GpgKey::GetSubKeys() const -> std::unique_ptr<std::vector<GpgSubKey>> {
auto p_keys = std::make_unique<std::vector<GpgSubKey>>();
auto GpgKey::GetSubKeys() const -> std::unique_ptr<QContainer<GpgSubKey>> {
auto p_keys = std::make_unique<QContainer<GpgSubKey>>();
auto *next = key_ref_->subkeys;
while (next != nullptr) {
p_keys->push_back(GpgSubKey(next));
@ -194,8 +184,8 @@ auto GpgKey::GetSubKeys() const -> std::unique_ptr<std::vector<GpgSubKey>> {
return p_keys;
}
auto GpgKey::GetUIDs() const -> std::unique_ptr<std::vector<GpgUID>> {
auto p_uids = std::make_unique<std::vector<GpgUID>>();
auto GpgKey::GetUIDs() const -> std::unique_ptr<QContainer<GpgUID>> {
auto p_uids = std::make_unique<QContainer<GpgUID>>();
auto *uid_next = key_ref_->uids;
while (uid_next != nullptr) {
p_uids->push_back(GpgUID(uid_next));
@ -204,24 +194,24 @@ auto GpgKey::GetUIDs() const -> std::unique_ptr<std::vector<GpgUID>> {
return p_uids;
}
auto GpgKey::IsHasActualSigningCapability() const -> bool {
auto GpgKey::IsHasActualSignCap() const -> bool {
auto subkeys = GetSubKeys();
return std::any_of(
subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool {
return subkey.IsSecretKey() && subkey.IsHasSigningCapability() &&
!subkey.IsDisabled() && !subkey.IsRevoked() &&
!subkey.IsExpired();
});
return std::any_of(subkeys->begin(), subkeys->end(),
[](const GpgSubKey &subkey) -> bool {
return subkey.IsSecretKey() && subkey.IsHasSignCap() &&
!subkey.IsDisabled() && !subkey.IsRevoked() &&
!subkey.IsExpired();
});
}
auto GpgKey::IsHasActualAuthenticationCapability() const -> bool {
auto GpgKey::IsHasActualAuthCap() const -> bool {
auto subkeys = GetSubKeys();
return std::any_of(
subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool {
return subkey.IsSecretKey() && subkey.IsHasAuthenticationCapability() &&
!subkey.IsDisabled() && !subkey.IsRevoked() &&
!subkey.IsExpired();
});
return std::any_of(subkeys->begin(), subkeys->end(),
[](const GpgSubKey &subkey) -> bool {
return subkey.IsSecretKey() && subkey.IsHasAuthCap() &&
!subkey.IsDisabled() && !subkey.IsRevoked() &&
!subkey.IsExpired();
});
}
/**
@ -229,7 +219,7 @@ auto GpgKey::IsHasActualAuthenticationCapability() const -> bool {
* @param key target key
* @return if key certify
*/
auto GpgKey::IsHasActualCertificationCapability() const -> bool {
auto GpgKey::IsHasActualCertCap() const -> bool {
return IsHasMasterKey() && !IsExpired() && !IsRevoked() && !IsDisabled();
}
@ -238,13 +228,13 @@ auto GpgKey::IsHasActualCertificationCapability() const -> bool {
* @param key target key
* @return if key encrypt
*/
auto GpgKey::IsHasActualEncryptionCapability() const -> bool {
auto GpgKey::IsHasActualEncrCap() const -> bool {
auto subkeys = GetSubKeys();
return std::any_of(
subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool {
return subkey.IsHasEncryptionCapability() && !subkey.IsDisabled() &&
!subkey.IsRevoked() && !subkey.IsExpired();
});
return std::any_of(subkeys->begin(), subkeys->end(),
[](const GpgSubKey &subkey) -> bool {
return subkey.IsHasEncrCap() && !subkey.IsDisabled() &&
!subkey.IsRevoked() && !subkey.IsExpired();
});
}
void GpgKey::KeyRefDeleter::operator()(gpgme_key_t _key) {

View File

@ -152,7 +152,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasEncryptionCapability() const -> bool;
[[nodiscard]] auto IsHasEncrCap() const -> bool;
/**
* @brief
@ -161,7 +161,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasActualEncryptionCapability() const -> bool;
[[nodiscard]] auto IsHasActualEncrCap() const -> bool;
/**
* @brief
@ -169,7 +169,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasSigningCapability() const -> bool;
[[nodiscard]] auto IsHasSignCap() const -> bool;
/**
* @brief
@ -177,7 +177,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasActualSigningCapability() const -> bool;
[[nodiscard]] auto IsHasActualSignCap() const -> bool;
/**
* @brief
@ -185,7 +185,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasCertificationCapability() const -> bool;
[[nodiscard]] auto IsHasCertCap() const -> bool;
/**
* @brief
@ -193,7 +193,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasActualCertificationCapability() const -> bool;
[[nodiscard]] auto IsHasActualCertCap() const -> bool;
/**
* @brief
@ -201,7 +201,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasAuthenticationCapability() const -> bool;
[[nodiscard]] auto IsHasAuthCap() const -> bool;
/**
* @brief
@ -209,7 +209,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasActualAuthenticationCapability() const -> bool;
[[nodiscard]] auto IsHasActualAuthCap() const -> bool;
/**
* @brief
@ -262,17 +262,17 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
/**
* @brief
*
* @return std::unique_ptr<std::vector<GpgSubKey>>
* @return std::unique_ptr<QContainer<GpgSubKey>>
*/
[[nodiscard]] auto GetSubKeys() const
-> std::unique_ptr<std::vector<GpgSubKey>>;
-> std::unique_ptr<QContainer<GpgSubKey>>;
/**
* @brief
*
* @return std::unique_ptr<std::vector<GpgUID>>
* @return std::unique_ptr<QContainer<GpgUID>>
*/
[[nodiscard]] auto GetUIDs() const -> std::unique_ptr<std::vector<GpgUID>>;
[[nodiscard]] auto GetUIDs() const -> std::unique_ptr<QContainer<GpgUID>>;
/**
* @brief Construct a new Gpg Key object

View File

@ -0,0 +1,500 @@
/**
* Copyright (C) 2021-2024 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
*
*/
#include "GpgKeyGenerateInfo.h"
#include <cassert>
#include "module/ModuleManager.h"
#include "utils/CommonUtils.h"
namespace GpgFrontend {
const KeyAlgo KeyGenerateInfo::kNoneAlgo = {
"none", KeyGenerateInfo::tr("None"), "None", 0, 0, "0.0.0"};
const QContainer<KeyAlgo> KeyGenerateInfo::kPrimaryKeyAlgos = {
kNoneAlgo,
/**
* Algorithm (DSA) as a government standard for digital signatures.
* Originally, it supported key lengths between 512 and 1024 bits.
* Recently, NIST has declared 512-bit keys obsolete:
* now, DSA is available in 1024, 2048 and 3072-bit lengths.
*/
{"rsa1024", "RSA", "RSA", 1024, kENCRYPT | kSIGN | kAUTH | kCERT, "2.2.0"},
{"rsa2048", "RSA", "RSA", 2048, kENCRYPT | kSIGN | kAUTH | kCERT, "2.2.0"},
{"rsa3072", "RSA", "RSA", 3072, kENCRYPT | kSIGN | kAUTH | kCERT, "2.2.0"},
{"rsa4096", "RSA", "RSA", 4096, kENCRYPT | kSIGN | kAUTH | kCERT, "2.2.0"},
{"dsa1024", "DSA", "DSA", 1024, kSIGN | kAUTH | kCERT, "2.2.0"},
{"dsa2048", "DSA", "DSA", 2048, kSIGN | kAUTH | kCERT, "2.2.0"},
{"dsa3072", "DSA", "DSA", 3072, kSIGN | kAUTH | kCERT, "2.2.0"},
{"ed25519", "ED25519", "EdDSA", 256, kSIGN | kAUTH | kCERT, "2.2.0"},
{"nistp256", "NIST", "ECDSA", 256, kSIGN | kAUTH | kCERT, "2.2.0"},
{"nistp384", "NIST", "ECDSA", 384, kSIGN | kAUTH | kCERT, "2.2.0"},
{"nistp521", "NIST", "ECDSA", 521, kSIGN | kAUTH | kCERT, "2.2.0"},
{"brainpoolp256r1", "BrainPooL", "ECDSA", 256, kSIGN | kAUTH | kCERT,
"2.3.0"},
{"brainpoolp384r1", "BrainPooL", "ECDSA", 384, kSIGN | kAUTH | kCERT,
"2.3.0"},
{"brainpoolp512r1", "BrainPooL", "ECDSA", 512, kSIGN | kAUTH | kCERT,
"2.3.0"},
{"ed448", "ED448", "EdDSA", 448, kSIGN | kAUTH | kCERT, "2.3.0"},
{"secp256k1", "ED448", "EdDSA", 256, kSIGN | kAUTH | kCERT, "2.3.0"},
};
const QContainer<KeyAlgo> KeyGenerateInfo::kSubKeyAlgos = {
kNoneAlgo,
{"rsa1024", "RSA", "RSA", 1024, kENCRYPT | kSIGN | kAUTH, "2.2.0"},
{"rsa2048", "RSA", "RSA", 2048, kENCRYPT | kSIGN | kAUTH, "2.2.0"},
{"rsa3072", "RSA", "RSA", 3072, kENCRYPT | kSIGN | kAUTH, "2.2.0"},
{"rsa4096", "RSA", "RSA", 4096, kENCRYPT | kSIGN | kAUTH, "2.2.0"},
{"dsa1024", "DSA", "DSA", 1024, kSIGN | kAUTH, "2.2.0"},
{"dsa2048", "DSA", "DSA", 2048, kSIGN | kAUTH, "2.2.0"},
{"dsa3072", "DSA", "DSA", 3072, kSIGN | kAUTH, "2.2.0"},
{"ed25519", "ED25519", "EdDSA", 256, kSIGN | kAUTH, "2.2.0"},
{"cv25519", "CV25519", "ECDH", 256, kENCRYPT, "2.2.0"},
{"nistp256", "NIST", "ECDH", 256, kENCRYPT, "2.2.0"},
{"nistp384", "NIST", "ECDH", 384, kENCRYPT, "2.2.0"},
{"nistp521", "NIST", "ECDH", 521, kENCRYPT, "2.2.0"},
{"brainpoolp256r1", "BrainPooL", "ECDH", 256, kENCRYPT, "2.3.0"},
{"brainpoolp384r1", "BrainPooL", "ECDH", 384, kENCRYPT, "2.3.0"},
{"brainpoolp512r1", "BrainPooL", "ECDH", 512, kENCRYPT, "2.3.0"},
{"x448", "X448", "ECDH", 448, kENCRYPT, "2.3.0"},
{"secp256k1", "SECP256K1", "ECDH", 256, kENCRYPT, "2.3.0"},
/**
* GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths
* ranging from 1024 to 4096 bits.
*/
{"elg1024", "ELG-E", "ELG-E", 1024, kENCRYPT, "2.2.0"},
{"elg2048", "ELG-E", "ELG-E", 2048, kENCRYPT, "2.2.0"},
{"elg3072", "ELG-E", "ELG-E", 3072, kENCRYPT, "2.2.0"},
{"elg4096", "ELG-E", "ELG-E", 4096, kENCRYPT, "2.2.0"},
};
auto KeyGenerateInfo::GetSupportedKeyAlgo() -> QContainer<KeyAlgo> {
const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gnupg_version", QString{"2.0.0"});
QContainer<KeyAlgo> algos;
for (const auto &algo : kPrimaryKeyAlgos) {
if (!algo.IsSupported(gnupg_version)) continue;
algos.append(algo);
}
std::sort(algos.begin(), algos.end(), [](const KeyAlgo &a, const KeyAlgo &b) {
return a.Name() < b.Name() && a.KeyLength() < b.KeyLength();
});
return algos;
}
auto KeyGenerateInfo::GetSupportedSubkeyAlgo() -> QContainer<KeyAlgo> {
const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gnupg_version", QString{"2.0.0"});
QContainer<KeyAlgo> algos;
for (const auto &algo : kSubKeyAlgos) {
if (!algo.IsSupported(gnupg_version)) continue;
algos.append(algo);
}
std::sort(algos.begin(), algos.end(), [](const KeyAlgo &a, const KeyAlgo &b) {
return a.Name() < b.Name() && a.KeyLength() < b.KeyLength();
});
return algos;
}
KeyGenerateInfo::KeyGenerateInfo(bool is_subkey)
: subkey_(is_subkey),
algo_(kNoneAlgo),
expired_(QDateTime::currentDateTime().toLocalTime().addYears(2)) {}
auto KeyGenerateInfo::SearchPrimaryKeyAlgo(const QString &algo_id)
-> std::tuple<bool, KeyAlgo> {
auto it =
std::find_if(kPrimaryKeyAlgos.cbegin(), kPrimaryKeyAlgos.cend(),
[=](const KeyAlgo &algo) { return algo.Id() == algo_id; });
if (it != kPrimaryKeyAlgos.cend()) {
return {true, *it};
}
return {false, KeyAlgo{}};
}
auto KeyGenerateInfo::SearchSubKeyAlgo(const QString &algo_id)
-> std::tuple<bool, KeyAlgo> {
auto it =
std::find_if(kSubKeyAlgos.cbegin(), kSubKeyAlgos.cend(),
[=](const KeyAlgo &algo) { return algo.Id() == algo_id; });
if (it != kSubKeyAlgos.cend()) {
return {true, *it};
}
return {false, KeyAlgo{}};
}
void KeyGenerateInfo::SetAlgo(const KeyAlgo &algo) {
// reset all options
reset_options();
this->SetAllowCert(algo.CanCert());
this->allow_change_certification_ = false;
SetAllowEncr(algo.CanEncrypt());
allow_change_encryption_ = algo.CanEncrypt();
SetAllowSign(algo.CanSign());
allow_change_signing_ = algo.CanSign();
SetAllowAuth(algo.CanAuth());
allow_change_authentication_ = algo.CanAuth();
this->algo_ = algo;
}
void KeyGenerateInfo::reset_options() {
allow_change_encryption_ = true;
SetAllowEncr(true);
allow_change_certification_ = true;
SetAllowCert(true);
allow_change_signing_ = true;
SetAllowSign(true);
allow_change_authentication_ = true;
SetAllowAuth(true);
}
void KeyGenerateInfo::SetExpireTime(const QDateTime &m_expired) {
KeyGenerateInfo::expired_ = m_expired;
}
void KeyGenerateInfo::SetNonExpired(bool m_non_expired) {
if (!m_non_expired) this->expired_ = QDateTime::fromSecsSinceEpoch(0);
KeyGenerateInfo::non_expired_ = m_non_expired;
}
void KeyGenerateInfo::SetAllowEncr(bool m_allow_encryption) {
if (allow_change_encryption_) {
KeyGenerateInfo::allow_encryption_ = m_allow_encryption;
}
}
void KeyGenerateInfo::SetAllowCert(bool m_allow_certification) {
if (allow_change_certification_) {
KeyGenerateInfo::allow_certification_ = m_allow_certification;
}
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsSubKey() const -> bool { return subkey_; }
/**
* @brief Set the Is Sub Key object
*
* @param m_sub_key
*/
void KeyGenerateInfo::SetIsSubKey(bool m_sub_key) {
KeyGenerateInfo::subkey_ = m_sub_key;
}
/**
* @brief Get the Userid object
*
* @return QString
*/
[[nodiscard]] auto KeyGenerateInfo::GetUserid() const -> QString {
return QString("%1(%2)<%3>").arg(name_).arg(comment_).arg(email_);
}
/**
* @brief Set the Name object
*
* @param m_name
*/
void KeyGenerateInfo::SetName(const QString &m_name) { this->name_ = m_name; }
/**
* @brief Set the Email object
*
* @param m_email
*/
void KeyGenerateInfo::SetEmail(const QString &m_email) {
this->email_ = m_email;
}
/**
* @brief Set the Comment object
*
* @param m_comment
*/
void KeyGenerateInfo::SetComment(const QString &m_comment) {
this->comment_ = m_comment;
}
/**
* @brief Get the Name object
*
* @return QString
*/
[[nodiscard]] auto KeyGenerateInfo::GetName() const -> QString { return name_; }
/**
* @brief Get the Email object
*
* @return QString
*/
[[nodiscard]] auto KeyGenerateInfo::GetEmail() const -> QString {
return email_;
}
/**
* @brief Get the Comment object
*
* @return QString
*/
[[nodiscard]] auto KeyGenerateInfo::GetComment() const -> QString {
return comment_;
}
/**
* @brief Get the Algo object
*
* @return const QString&
*/
[[nodiscard]] auto KeyGenerateInfo::GetAlgo() const -> const KeyAlgo & {
return algo_;
}
/**
* @brief Get the Key Size object
*
* @return int
*/
[[nodiscard]] auto KeyGenerateInfo::GetKeyLength() const -> int {
return algo_.KeyLength();
}
/**
* @brief Get the Expired object
*
* @return const QDateTime&
*/
[[nodiscard]] auto KeyGenerateInfo::GetExpireTime() const -> const QDateTime & {
return expired_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsNonExpired() const -> bool {
return non_expired_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsNoPassPhrase() const -> bool {
return this->no_passphrase_;
}
/**
* @brief Set the Non Pass Phrase object
*
* @param m_non_pass_phrase
*/
void KeyGenerateInfo::SetNonPassPhrase(bool m_non_pass_phrase) {
KeyGenerateInfo::no_passphrase_ = m_non_pass_phrase;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsAllowSign() const -> bool {
return allow_signing_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsAllowNoPassPhrase() const -> bool {
return allow_no_pass_phrase_;
}
/**
* @brief Set the Allow Signing object
*
* @param m_allow_signing
*/
void KeyGenerateInfo::SetAllowSign(bool m_allow_signing) {
if (allow_change_signing_) KeyGenerateInfo::allow_signing_ = m_allow_signing;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsAllowEncr() const -> bool {
return allow_encryption_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsAllowCert() const -> bool {
return allow_certification_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsAllowAuth() const -> bool {
return allow_authentication_;
}
/**
* @brief Set the Allow Authentication object
*
* @param m_allow_authentication
*/
void KeyGenerateInfo::SetAllowAuth(bool m_allow_authentication) {
if (allow_change_authentication_) {
KeyGenerateInfo::allow_authentication_ = m_allow_authentication;
}
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsAllowModifySign() const -> bool {
return allow_change_signing_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsAllowModifyEncr() const -> bool {
return allow_change_encryption_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsAllowModifyCert() const -> bool {
return allow_change_certification_;
}
/**
* @brief
*
* @return true
* @return false
*/
[[nodiscard]] auto KeyGenerateInfo::IsAllowModifyAuth() const -> bool {
return allow_change_authentication_;
}
KeyAlgo::KeyAlgo(QString id, QString name, QString type, int length, int opera,
QString supported_version)
: id_(std::move(id)),
name_(std::move(name)),
type_(std::move(type)),
length_(length),
supported_version_(std::move(supported_version)) {
encrypt_ = ((opera & kENCRYPT) != 0);
sign_ = ((opera & kSIGN) != 0);
auth_ = ((opera & kAUTH) != 0);
cert_ = ((opera & kCERT) != 0);
};
auto KeyAlgo::Id() const -> QString { return id_; }
auto KeyAlgo::Name() const -> QString { return name_; }
auto KeyAlgo::KeyLength() const -> int { return length_; }
auto KeyAlgo::Type() const -> QString { return type_; }
auto KeyAlgo::CanEncrypt() const -> bool { return encrypt_; }
auto KeyAlgo::CanSign() const -> bool { return sign_; }
auto KeyAlgo::CanAuth() const -> bool { return auth_; }
auto KeyAlgo::CanCert() const -> bool { return cert_; }
auto KeyAlgo::IsSupported(const QString &version) const -> bool {
return GFCompareSoftwareVersion(version, supported_version_) >= 0;
}
auto KeyAlgo::operator==(const KeyAlgo &o) const -> bool {
return this->id_ == o.id_;
}
} // namespace GpgFrontend

View File

@ -29,12 +29,59 @@
#pragma once
#include "core/GpgFrontendCoreExport.h"
#include "core/typedef/CoreTypedef.h"
namespace GpgFrontend {
class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
class GPGFRONTEND_CORE_EXPORT KeyAlgo {
public:
using KeyGenAlgo = std::tuple<QString, QString, QString>;
KeyAlgo() = default;
KeyAlgo(QString id, QString name, QString type, int length, int opera,
QString supported_version);
KeyAlgo(const KeyAlgo &) = default;
auto operator=(const KeyAlgo &) -> KeyAlgo & = default;
auto operator==(const KeyAlgo &o) const -> bool;
[[nodiscard]] auto Id() const -> QString;
[[nodiscard]] auto Name() const -> QString;
[[nodiscard]] auto KeyLength() const -> int;
[[nodiscard]] auto Type() const -> QString;
[[nodiscard]] auto CanEncrypt() const -> bool;
[[nodiscard]] auto CanSign() const -> bool;
[[nodiscard]] auto CanAuth() const -> bool;
[[nodiscard]] auto CanCert() const -> bool;
[[nodiscard]] auto IsSupported(const QString &version) const -> bool;
private:
QString id_;
QString name_;
QString type_;
int length_;
bool encrypt_;
bool sign_;
bool auth_;
bool cert_;
QString supported_version_;
};
class GPGFRONTEND_CORE_EXPORT KeyGenerateInfo : public QObject {
Q_OBJECT
public:
static const KeyAlgo kNoneAlgo;
static const QContainer<KeyAlgo> kPrimaryKeyAlgos;
static const QContainer<KeyAlgo> kSubKeyAlgos;
/**
* @brief Construct a new Gen Key Info object
@ -42,21 +89,39 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @param m_is_sub_key
* @param m_standalone
*/
explicit GenKeyInfo(bool m_is_sub_key = false);
explicit KeyGenerateInfo(bool is_subkey = false);
/**
* @brief Get the Supported Key Algo object
*
* @return const std::vector<QString>&
* @return const QContainer<KeyGenAlgo>&
*/
static auto GetSupportedKeyAlgo() -> const std::vector<KeyGenAlgo> &;
static auto GetSupportedKeyAlgo() -> QContainer<KeyAlgo>;
/**
* @brief Get the Supported Subkey Algo object
*
* @return const std::vector<QString>&
* @return const QContainer<KeyGenAlgo>&
*/
static auto GetSupportedSubkeyAlgo() -> const std::vector<KeyGenAlgo> &;
static auto GetSupportedSubkeyAlgo() -> QContainer<KeyAlgo>;
/**
* @brief
*
* @param algo_id
* @return std::tuple<bool, KeyAlgo>
*/
static auto SearchPrimaryKeyAlgo(const QString &algo_id)
-> std::tuple<bool, KeyAlgo>;
/**
* @brief
*
* @param algo_id
* @return std::tuple<bool, KeyAlgo>
*/
static auto SearchSubKeyAlgo(const QString &algo_id)
-> std::tuple<bool, KeyAlgo>;
/**
* @brief
@ -71,7 +136,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
*
* @param m_sub_key
*/
void SetIsSubKey(bool m_sub_key);
void SetIsSubKey(bool);
/**
* @brief Get the Userid object
@ -85,21 +150,21 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
*
* @param m_name
*/
void SetName(const QString &m_name);
void SetName(const QString &name);
/**
* @brief Set the Email object
*
* @param m_email
*/
void SetEmail(const QString &m_email);
void SetEmail(const QString &email);
/**
* @brief Set the Comment object
*
* @param m_comment
*/
void SetComment(const QString &m_comment);
void SetComment(const QString &comment);
/**
* @brief Get the Name object
@ -127,21 +192,14 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
*
* @return const QString&
*/
[[nodiscard]] auto GetAlgo() const -> const QString &;
[[nodiscard]] auto GetAlgo() const -> const KeyAlgo &;
/**
* @brief Set the Algo object
*
* @param m_algo
*/
void SetAlgo(const QString &);
/**
* @brief Get the Key Size Str object
*
* @return QString
*/
[[nodiscard]] auto GetKeySizeStr() const -> QString;
void SetAlgo(const KeyAlgo &);
/**
* @brief Get the Key Size object
@ -150,13 +208,6 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
*/
[[nodiscard]] auto GetKeyLength() const -> int;
/**
* @brief Set the Key Size object
*
* @param m_key_size
*/
void SetKeyLength(int m_key_size);
/**
* @brief Get the Expired object
*
@ -207,7 +258,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @return true
* @return false
*/
[[nodiscard]] auto IsAllowSigning() const -> bool;
[[nodiscard]] auto IsAllowSign() const -> bool;
/**
* @brief
@ -222,7 +273,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
*
* @param m_allow_signing
*/
void SetAllowSigning(bool m_allow_signing);
void SetAllowSign(bool m_allow_signing);
/**
* @brief
@ -230,14 +281,14 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @return true
* @return false
*/
[[nodiscard]] auto IsAllowEncryption() const -> bool;
[[nodiscard]] auto IsAllowEncr() const -> bool;
/**
* @brief Set the Allow Encryption object
*
* @param m_allow_encryption
*/
void SetAllowEncryption(bool m_allow_encryption);
void SetAllowEncr(bool m_allow_encryption);
/**
* @brief
@ -245,14 +296,14 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @return true
* @return false
*/
[[nodiscard]] auto IsAllowCertification() const -> bool;
[[nodiscard]] auto IsAllowCert() const -> bool;
/**
* @brief Set the Allow Certification object
*
* @param m_allow_certification
*/
void SetAllowCertification(bool m_allow_certification);
void SetAllowCert(bool m_allow_certification);
/**
* @brief
@ -260,28 +311,14 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @return true
* @return false
*/
[[nodiscard]] auto IsAllowAuthentication() const -> bool;
[[nodiscard]] auto IsAllowAuth() const -> bool;
/**
* @brief Set the Allow Authentication object
*
* @param m_allow_authentication
*/
void SetAllowAuthentication(bool m_allow_authentication);
/**
* @brief Get the Pass Phrase object
*
* @return const QString&
*/
[[nodiscard]] auto GetPassPhrase() const -> const QString &;
/**
* @brief Set the Pass Phrase object
*
* @param m_pass_phrase
*/
void SetPassPhrase(const QString &m_pass_phrase);
void SetAllowAuth(bool m_allow_authentication);
/**
* @brief
@ -289,7 +326,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @return true
* @return false
*/
[[nodiscard]] auto IsAllowChangeSigning() const -> bool;
[[nodiscard]] auto IsAllowModifySign() const -> bool;
/**
* @brief
@ -297,7 +334,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @return true
* @return false
*/
[[nodiscard]] auto IsAllowChangeEncryption() const -> bool;
[[nodiscard]] auto IsAllowModifyEncr() const -> bool;
/**
* @brief
@ -305,7 +342,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @return true
* @return false
*/
[[nodiscard]] auto IsAllowChangeCertification() const -> bool;
[[nodiscard]] auto IsAllowModifyCert() const -> bool;
/**
* @brief
@ -313,28 +350,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
* @return true
* @return false
*/
[[nodiscard]] auto IsAllowChangeAuthentication() const -> bool;
/**
* @brief Get the Suggest Max Key Size object
*
* @return int
*/
[[nodiscard]] auto GetSuggestMaxKeySize() const -> int;
/**
* @brief Get the Suggest Min Key Size object
*
* @return int
*/
[[nodiscard]] auto GetSuggestMinKeySize() const -> int;
/**
* @brief Get the Size Change Step object
*
* @return int
*/
[[nodiscard]] auto GetSizeChangeStep() const -> int;
[[nodiscard]] auto IsAllowModifyAuth() const -> bool;
private:
bool subkey_ = false; ///<
@ -342,20 +358,13 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
QString email_; ///<
QString comment_; ///<
QString algo_; ///<
int key_size_ = 2048;
QDateTime expired_ = QDateTime::currentDateTime().addYears(2);
KeyAlgo algo_; ///<
QDateTime expired_;
bool non_expired_ = false; ///<
bool no_passphrase_ = false; ///<
bool allow_no_pass_phrase_ = true; ///<
int suggest_max_key_size_ = 4096; ///<
int suggest_size_addition_step_ = 1024; ///<
int suggest_min_key_size_ = 1024; ///<
QString passphrase_; ///<
bool allow_encryption_ = true; ///<
bool allow_change_encryption_ = true; ///<
bool allow_certification_ = true; ///<

View File

@ -34,47 +34,60 @@ GpgKeySignature::GpgKeySignature() = default;
GpgKeySignature::~GpgKeySignature() = default;
GpgKeySignature::GpgKeySignature(gpgme_key_sig_t sig)
: signature_ref_(sig, [&](gpgme_key_sig_t signature) {}) {}
GpgKeySignature::GpgKeySignature(gpgme_key_sig_t sig) : signature_ref_(sig) {}
GpgKeySignature::GpgKeySignature(GpgKeySignature &&) noexcept = default;
GpgKeySignature::GpgKeySignature(const GpgKeySignature &) = default;
auto GpgKeySignature::operator=(const GpgKeySignature &) -> GpgKeySignature & =
default;
GpgKeySignature &GpgKeySignature::operator=(GpgKeySignature &&) noexcept =
default;
auto GpgKeySignature::IsRevoked() const -> bool {
return signature_ref_->revoked;
}
bool GpgKeySignature::IsRevoked() const { return signature_ref_->revoked; }
auto GpgKeySignature::IsExpired() const -> bool {
return signature_ref_->expired;
}
bool GpgKeySignature::IsExpired() const { return signature_ref_->expired; }
auto GpgKeySignature::IsInvalid() const -> bool {
return signature_ref_->invalid;
}
bool GpgKeySignature::IsInvalid() const { return signature_ref_->invalid; }
bool GpgKeySignature::IsExportable() const {
auto GpgKeySignature::IsExportable() const -> bool {
return signature_ref_->exportable;
}
gpgme_error_t GpgKeySignature::GetStatus() const {
auto GpgKeySignature::GetStatus() const -> gpgme_error_t {
return signature_ref_->status;
}
QString GpgKeySignature::GetKeyID() const { return signature_ref_->keyid; }
auto GpgKeySignature::GetKeyID() const -> QString {
return signature_ref_->keyid;
}
QString GpgKeySignature::GetPubkeyAlgo() const {
auto GpgKeySignature::GetPubkeyAlgo() const -> QString {
return gpgme_pubkey_algo_name(signature_ref_->pubkey_algo);
}
QDateTime GpgKeySignature::GetCreateTime() const {
auto GpgKeySignature::GetCreateTime() const -> QDateTime {
return QDateTime::fromSecsSinceEpoch(signature_ref_->timestamp);
}
QDateTime GpgKeySignature::GetExpireTime() const {
auto GpgKeySignature::GetExpireTime() const -> QDateTime {
return QDateTime::fromSecsSinceEpoch(signature_ref_->expires);
}
QString GpgKeySignature::GetUID() const { return signature_ref_->uid; }
auto GpgKeySignature::GetUID() const -> QString { return signature_ref_->uid; }
QString GpgKeySignature::GetName() const { return signature_ref_->name; }
auto GpgKeySignature::GetName() const -> QString {
return signature_ref_->name;
}
QString GpgKeySignature::GetEmail() const { return signature_ref_->email; }
auto GpgKeySignature::GetEmail() const -> QString {
return signature_ref_->email;
}
auto GpgKeySignature::GetComment() const -> QString {
return signature_ref_->comment;
}
QString GpgKeySignature::GetComment() const { return signature_ref_->comment; }
} // namespace GpgFrontend

View File

@ -160,34 +160,17 @@ class GPGFRONTEND_CORE_EXPORT GpgKeySignature {
* @brief Construct a new Gpg Key Signature object
*
*/
GpgKeySignature(GpgKeySignature &&) noexcept;
/**
* @brief Construct a new Gpg Key Signature object
*
*/
GpgKeySignature(const GpgKeySignature &) = delete;
GpgKeySignature(const GpgKeySignature &);
/**
* @brief
*
* @return GpgKeySignature&
*/
auto operator=(GpgKeySignature &&) noexcept -> GpgKeySignature &;
/**
* @brief
*
* @return GpgKeySignature&
*/
auto operator=(const GpgKeySignature &) -> GpgKeySignature & = delete;
auto operator=(const GpgKeySignature &) -> GpgKeySignature &;
private:
using KeySignatrueRefHandler =
std::unique_ptr<struct _gpgme_key_sig,
std::function<void(gpgme_key_sig_t)>>; ///<
KeySignatrueRefHandler signature_ref_ = nullptr; ///<
gpgme_key_sig_t signature_ref_ = nullptr; ///<
};
} // namespace GpgFrontend

View File

@ -28,8 +28,6 @@
#include "GpgKeyTableModel.h"
#include <utility>
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/model/GpgKey.h"
@ -62,75 +60,88 @@ auto GpgKeyTableModel::data(const QModelIndex &index,
int role) const -> QVariant {
if (!index.isValid() || buffered_keys_.empty()) return {};
if (role == Qt::TextAlignmentRole) {
return Qt::AlignCenter;
}
if (role == Qt::CheckStateRole) {
if (index.column() == 0) {
return key_check_state_[index.row()] ? Qt::Checked : Qt::Unchecked;
}
return {};
}
const auto &key = buffered_keys_.at(index.row());
if (role == Qt::DisplayRole) {
const auto &key = buffered_keys_.at(index.row());
switch (index.column()) {
case 0: {
return index.row();
switch (index.column()) {
case 0: {
return index.row();
}
case 1: {
QString type_sym;
type_sym += key.IsPrivateKey() ? "pub/sec" : "pub";
if (key.IsPrivateKey() && !key.IsHasMasterKey()) type_sym += "#";
if (key.IsHasCardKey()) type_sym += "^";
return type_sym;
}
case 2: {
return key.GetName();
}
case 3: {
return key.GetEmail();
}
case 4: {
QString usage_sym;
if (key.IsHasActualCertCap()) usage_sym += "C";
if (key.IsHasActualEncrCap()) usage_sym += "E";
if (key.IsHasActualSignCap()) usage_sym += "S";
if (key.IsHasActualAuthCap()) usage_sym += "A";
return usage_sym;
}
case 5: {
return key.GetOwnerTrust();
}
case 6: {
return key.GetId();
}
case 7: {
return QLocale().toString(key.GetCreateTime(), "yyyy-MM-dd");
}
case 8: {
return key.GetKeyAlgo();
}
case 9: {
return static_cast<int>(key.GetSubKeys()->size());
}
case 10: {
return key.GetComment();
}
default:
return {};
}
case 1: {
QString type_sym;
type_sym += key.IsPrivateKey() ? "pub/sec" : "pub";
if (key.IsPrivateKey() && !key.IsHasMasterKey()) type_sym += "#";
if (key.IsHasCardKey()) type_sym += "^";
return type_sym;
}
case 2: {
return key.GetName();
}
case 3: {
return key.GetEmail();
}
case 4: {
QString usage_sym;
if (key.IsHasActualCertificationCapability()) usage_sym += "C";
if (key.IsHasActualEncryptionCapability()) usage_sym += "E";
if (key.IsHasActualSigningCapability()) usage_sym += "S";
if (key.IsHasActualAuthenticationCapability()) usage_sym += "A";
return usage_sym;
}
case 5: {
return key.GetOwnerTrust();
}
case 6: {
return key.GetId();
}
case 7: {
return key.GetCreateTime();
}
case 8: {
return key.GetKeyAlgo();
}
case 9: {
return static_cast<int>(key.GetSubKeys()->size());
}
case 10: {
return key.GetComment();
}
default:
return {};
}
if (role == Qt::TextAlignmentRole) {
switch (index.column()) {
case 0:
case 1:
case 4:
case 5:
case 6:
case 7:
case 9:
return Qt::AlignCenter;
default:
return {};
}
}
return {};
}
auto GpgKeyTableModel::headerData(int section, Qt::Orientation orientation,
int role) const -> QVariant {
if (role != Qt::DisplayRole) return {};
if (orientation == Qt::Horizontal) {
return column_headers_[section];
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
return column_headers_[section];
}
}
return {};
}
@ -138,7 +149,7 @@ auto GpgKeyTableModel::flags(const QModelIndex &index) const -> Qt::ItemFlags {
if (!index.isValid()) return Qt::NoItemFlags;
if (index.column() == 0) {
return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
@ -157,8 +168,8 @@ auto GpgKeyTableModel::setData(const QModelIndex &index, const QVariant &value,
return false;
}
auto GpgKeyTableModel::GetAllKeyIds() -> GpgKeyIDList {
GpgKeyIDList keys;
auto GpgKeyTableModel::GetAllKeyIds() -> KeyIdArgsList {
KeyIdArgsList keys;
for (auto &key : buffered_keys_) {
keys.push_back(key.GetId());
}

View File

@ -186,7 +186,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableModel : public QAbstractTableModel {
*
* @return auto
*/
auto GetAllKeyIds() -> GpgKeyIDList;
auto GetAllKeyIds() -> KeyIdArgsList;
/**
* @brief Get the Key ID By Row object
@ -216,11 +216,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableModel : public QAbstractTableModel {
QStringList column_headers_;
int gpg_context_channel_;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 4)
QList<bool> key_check_state_;
#else
QVector<bool> key_check_state_;
#endif
QContainer<bool> key_check_state_;
};
} // namespace GpgFrontend

View File

@ -47,8 +47,8 @@ auto GpgSignResult::GetRaw() -> gpgme_sign_result_t {
}
auto GpgSignResult::InvalidSigners()
-> std::vector<std::tuple<QString, GpgError>> {
std::vector<std::tuple<QString, GpgError>> result;
-> QContainer<std::tuple<QString, GpgError>> {
QContainer<std::tuple<QString, GpgError>> result;
for (auto* invalid_key = result_ref_->invalid_signers; invalid_key != nullptr;
invalid_key = invalid_key->next) {
try {

View File

@ -41,7 +41,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSignResult {
auto HashAlgo() -> QString;
auto InvalidSigners() -> std::vector<std::tuple<QString, GpgError>>;
auto InvalidSigners() -> QContainer<std::tuple<QString, GpgError>>;
explicit GpgSignResult(gpgme_sign_result_t);

View File

@ -30,27 +30,15 @@
namespace GpgFrontend {
/**
* @brief Construct a new Gpg Signature object
*
*/
GpgSignature::GpgSignature(GpgSignature &&) noexcept = default;
GpgSignature::GpgSignature() = default;
/**
* @brief
*
* @return GpgSignature&
*/
auto GpgSignature::operator=(GpgSignature &&) noexcept -> GpgSignature & =
default;
GpgSignature::GpgSignature(gpgme_signature_t sig) : signature_ref_(sig) {}
/**
* @brief Construct a new Gpg Signature:: Gpg Signature object
*
* @param sig
*/
GpgSignature::GpgSignature(gpgme_signature_t sig)
: signature_ref_(sig, [&](gpgme_signature_t signature) {}) {}
GpgSignature::~GpgSignature() = default;
GpgSignature::GpgSignature(const GpgSignature &) = default;
auto GpgSignature::operator=(const GpgSignature &) -> GpgSignature & = default;
/**
* @brief
@ -124,16 +112,4 @@ auto GpgSignature::GetFingerprint() const -> QString {
return signature_ref_->fpr != nullptr ? signature_ref_->fpr : "";
}
/**
* @brief Construct a new Gpg Signature object
*
*/
GpgSignature::GpgSignature() = default;
/**
* @brief Destroy the Gpg Signature object
*
*/
GpgSignature::~GpgSignature() = default;
} // namespace GpgFrontend

View File

@ -117,33 +117,16 @@ class GPGFRONTEND_CORE_EXPORT GpgSignature {
* @brief Construct a new Gpg Signature object
*
*/
GpgSignature(GpgSignature &&) noexcept;
/**
* @brief Construct a new Gpg Signature object
*
*/
GpgSignature(const GpgSignature &) = delete;
GpgSignature(const GpgSignature &);
/**
* @brief
*
* @return GpgSignature&
*/
auto operator=(GpgSignature &&) noexcept -> GpgSignature &;
/**
* @brief
*
* @return GpgSignature&
*/
auto operator=(const GpgSignature &) -> GpgSignature & = delete;
auto operator=(const GpgSignature &) -> GpgSignature &;
private:
using KeySignatrueRefHandler =
std::unique_ptr<struct _gpgme_signature,
std::function<void(gpgme_signature_t)>>; ///<
KeySignatrueRefHandler signature_ref_ = nullptr; ///<
gpgme_signature_t signature_ref_ = nullptr; ///<
};
} // namespace GpgFrontend

View File

@ -31,17 +31,11 @@ namespace GpgFrontend {
GpgSubKey::GpgSubKey() = default;
GpgSubKey::GpgSubKey(gpgme_subkey_t subkey)
: subkey_ref_(subkey, [&](gpgme_subkey_t subkey) {}) {}
GpgSubKey::GpgSubKey(gpgme_subkey_t subkey) : subkey_ref_(subkey) {}
GpgSubKey::GpgSubKey(GpgSubKey&& o) noexcept {
swap(subkey_ref_, o.subkey_ref_);
}
GpgSubKey::GpgSubKey(const GpgSubKey&) = default;
auto GpgSubKey::operator=(GpgSubKey&& o) noexcept -> GpgSubKey& {
swap(subkey_ref_, o.subkey_ref_);
return *this;
};
auto GpgSubKey::operator=(const GpgSubKey&) -> GpgSubKey& = default;
auto GpgSubKey::operator==(const GpgSubKey& o) const -> bool {
return GetFingerprint() == o.GetFingerprint();
@ -56,7 +50,7 @@ auto GpgSubKey::GetPubkeyAlgo() const -> QString {
}
auto GpgSubKey::GetKeyAlgo() const -> QString {
auto* buffer = gpgme_pubkey_algo_string(subkey_ref_.get());
auto* buffer = gpgme_pubkey_algo_string(subkey_ref_);
auto algo = QString(buffer);
gpgme_free(buffer);
return algo.toUpper();
@ -66,19 +60,17 @@ auto GpgSubKey::GetKeyLength() const -> unsigned int {
return subkey_ref_->length;
}
auto GpgSubKey::IsHasEncryptionCapability() const -> bool {
auto GpgSubKey::IsHasEncrCap() const -> bool {
return subkey_ref_->can_encrypt;
}
auto GpgSubKey::IsHasSigningCapability() const -> bool {
return subkey_ref_->can_sign;
}
auto GpgSubKey::IsHasSignCap() const -> bool { return subkey_ref_->can_sign; }
auto GpgSubKey::IsHasCertificationCapability() const -> bool {
auto GpgSubKey::IsHasCertCap() const -> bool {
return subkey_ref_->can_certify;
}
auto GpgSubKey::IsHasAuthenticationCapability() const -> bool {
auto GpgSubKey::IsHasAuthCap() const -> bool {
return subkey_ref_->can_authenticate;
}

View File

@ -81,7 +81,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasEncryptionCapability() const -> bool;
[[nodiscard]] auto IsHasEncrCap() const -> bool;
/**
* @brief
@ -89,7 +89,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasSigningCapability() const -> bool;
[[nodiscard]] auto IsHasSignCap() const -> bool;
/**
* @brief
@ -97,7 +97,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasCertificationCapability() const -> bool;
[[nodiscard]] auto IsHasCertCap() const -> bool;
/**
* @brief
@ -105,7 +105,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
* @return true
* @return false
*/
[[nodiscard]] auto IsHasAuthenticationCapability() const -> bool;
[[nodiscard]] auto IsHasAuthCap() const -> bool;
/**
* @brief
@ -185,30 +185,15 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
/**
* @brief Construct a new Gpg Sub Key object
*
* @param o
*/
GpgSubKey(GpgSubKey&& o) noexcept;
/**
* @brief Construct a new Gpg Sub Key object
*
*/
GpgSubKey(const GpgSubKey&) = delete;
/**
* @brief
*
* @param o
* @return GpgSubKey&
*/
auto operator=(GpgSubKey&& o) noexcept -> GpgSubKey&;
GpgSubKey(const GpgSubKey&);
/**
* @brief
*
* @return GpgSubKey&
*/
auto operator=(const GpgSubKey&) -> GpgSubKey& = delete;
auto operator=(const GpgSubKey&) -> GpgSubKey&;
/**
* @brief
@ -220,11 +205,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
auto operator==(const GpgSubKey& o) const -> bool;
private:
using SubkeyRefHandler =
std::unique_ptr<struct _gpgme_subkey,
std::function<void(gpgme_subkey_t)>>; ///<
SubkeyRefHandler subkey_ref_ = nullptr; ///<
gpgme_subkey_t subkey_ref_ = nullptr; ///<
};
} // namespace GpgFrontend

View File

@ -33,16 +33,11 @@ namespace GpgFrontend {
GpgTOFUInfo::GpgTOFUInfo() = default;
GpgTOFUInfo::GpgTOFUInfo(gpgme_tofu_info_t tofu_info)
: tofu_info_ref_(tofu_info, [&](gpgme_tofu_info_t tofu_info) {}) {}
: tofu_info_ref_(tofu_info) {}
GpgTOFUInfo::GpgTOFUInfo(GpgTOFUInfo&& o) noexcept {
swap(tofu_info_ref_, o.tofu_info_ref_);
}
GpgTOFUInfo::GpgTOFUInfo(const GpgTOFUInfo&) = default;
auto GpgTOFUInfo::operator=(GpgTOFUInfo&& o) noexcept -> GpgTOFUInfo& {
swap(tofu_info_ref_, o.tofu_info_ref_);
return *this;
};
auto GpgTOFUInfo::operator=(const GpgTOFUInfo&) -> GpgTOFUInfo& = default;
auto GpgTOFUInfo::GetValidity() const -> unsigned {
return tofu_info_ref_->validity;
@ -64,29 +59,14 @@ auto GpgTOFUInfo::GetSignFirst() const -> unsigned long {
return tofu_info_ref_->signfirst;
}
/**
* @brief
*
* @return unsigned long
*/
auto GpgTOFUInfo::GetSignLast() const -> unsigned long {
return tofu_info_ref_->signlast;
}
/**
* @brief
*
* @return unsigned long
*/
auto GpgTOFUInfo::GetEncrLast() const -> unsigned long {
return tofu_info_ref_->encrlast;
}
/**
* @brief
*
* @return QString
*/
auto GpgTOFUInfo::GetDescription() const -> QString {
return tofu_info_ref_->description;
}

View File

@ -110,37 +110,18 @@ class GPGFRONTEND_CORE_EXPORT GpgTOFUInfo {
/**
* @brief Construct a new Gpg T O F U Info object
*
* @param o
*/
GpgTOFUInfo(GpgTOFUInfo&& o) noexcept;
/**
* @brief Construct a new Gpg T O F U Info object
*
*/
GpgTOFUInfo(const GpgTOFUInfo&) = delete;
/**
* @brief
*
* @param o
* @return GpgTOFUInfo&
*/
auto operator=(GpgTOFUInfo&& o) noexcept -> GpgTOFUInfo&;
GpgTOFUInfo(const GpgTOFUInfo&);
/**
* @brief
*
* @return GpgTOFUInfo&
*/
auto operator=(const GpgTOFUInfo&) -> GpgTOFUInfo& = delete;
auto operator=(const GpgTOFUInfo&) -> GpgTOFUInfo&;
private:
using SubkeyRefHandler =
std::unique_ptr<struct _gpgme_tofu_info,
std::function<void(gpgme_tofu_info_t)>>; ///<
SubkeyRefHandler tofu_info_ref_ = nullptr; ///<
gpgme_tofu_info_t tofu_info_ref_ = nullptr; ///<
};
} // namespace GpgFrontend

View File

@ -32,10 +32,11 @@ namespace GpgFrontend {
GpgUID::GpgUID() = default;
GpgUID::GpgUID(gpgme_user_id_t uid)
: uid_ref_(uid, [&](gpgme_user_id_t uid) {}) {}
GpgUID::GpgUID(gpgme_user_id_t uid) : uid_ref_(uid) {}
GpgUID::GpgUID(GpgUID &&o) noexcept { swap(uid_ref_, o.uid_ref_); }
GpgUID::GpgUID(const GpgUID &) = default;
auto GpgUID::operator=(const GpgUID &) -> GpgUID & = default;
auto GpgUID::GetName() const -> QString { return uid_ref_->name; }
@ -49,8 +50,8 @@ auto GpgUID::GetRevoked() const -> bool { return uid_ref_->revoked; }
auto GpgUID::GetInvalid() const -> bool { return uid_ref_->invalid; }
auto GpgUID::GetTofuInfos() const -> std::unique_ptr<std::vector<GpgTOFUInfo>> {
auto infos = std::make_unique<std::vector<GpgTOFUInfo>>();
auto GpgUID::GetTofuInfos() const -> std::unique_ptr<QContainer<GpgTOFUInfo>> {
auto infos = std::make_unique<QContainer<GpgTOFUInfo>>();
auto *info_next = uid_ref_->tofu;
while (info_next != nullptr) {
infos->push_back(GpgTOFUInfo(info_next));
@ -60,8 +61,8 @@ auto GpgUID::GetTofuInfos() const -> std::unique_ptr<std::vector<GpgTOFUInfo>> {
}
auto GpgUID::GetSignatures() const
-> std::unique_ptr<std::vector<GpgKeySignature>> {
auto sigs = std::make_unique<std::vector<GpgKeySignature>>();
-> std::unique_ptr<QContainer<GpgKeySignature>> {
auto sigs = std::make_unique<QContainer<GpgKeySignature>>();
auto *sig_next = uid_ref_->signatures;
while (sig_next != nullptr) {
sigs->push_back(GpgKeySignature(sig_next));

View File

@ -85,18 +85,18 @@ class GPGFRONTEND_CORE_EXPORT GpgUID {
/**
* @brief
*
* @return std::unique_ptr<std::vector<GpgTOFUInfo>>
* @return std::unique_ptr<QContainer<GpgTOFUInfo>>
*/
[[nodiscard]] auto GetTofuInfos() const
-> std::unique_ptr<std::vector<GpgTOFUInfo>>;
-> std::unique_ptr<QContainer<GpgTOFUInfo>>;
/**
* @brief
*
* @return std::unique_ptr<std::vector<GpgKeySignature>>
* @return std::unique_ptr<QContainer<GpgKeySignature>>
*/
[[nodiscard]] auto GetSignatures() const
-> std::unique_ptr<std::vector<GpgKeySignature>>;
-> std::unique_ptr<QContainer<GpgKeySignature>>;
/**
* @brief Construct a new Gpg U I D object
@ -111,40 +111,21 @@ class GPGFRONTEND_CORE_EXPORT GpgUID {
*/
explicit GpgUID(gpgme_user_id_t uid);
/**
* @brief Construct a new Gpg U I D object
*
* @param o
*/
GpgUID(GpgUID &&o) noexcept;
/**
* @brief Construct a new Gpg U I D object
*
*/
GpgUID(const GpgUID &) = delete;
/**
* @brief
*
* @param o
* @return GpgUID&
*/
auto operator=(GpgUID &&o) noexcept -> GpgUID &;
GpgUID(const GpgUID &);
/**
* @brief
*
* @return GpgUID&
*/
auto operator=(const GpgUID &) -> GpgUID & = delete;
auto operator=(const GpgUID &) -> GpgUID &;
private:
using UidRefHandler =
std::unique_ptr<struct _gpgme_user_id,
std::function<void(gpgme_user_id_t)>>; ///<
UidRefHandler uid_ref_ = nullptr; ///<
gpgme_user_id_t uid_ref_ = nullptr; ///<
};
} // namespace GpgFrontend

View File

@ -49,8 +49,8 @@ auto GpgVerifyResult::GetRaw() const -> gpgme_verify_result_t {
return result_ref_.get();
}
auto GpgVerifyResult::GetSignature() const -> std::vector<GpgSignature> {
std::vector<GpgSignature> sigatures;
auto GpgVerifyResult::GetSignature() const -> QContainer<GpgSignature> {
QContainer<GpgSignature> sigatures;
auto* signature = result_ref_->signatures;
while (signature != nullptr) {

View File

@ -39,7 +39,7 @@ class GPGFRONTEND_CORE_EXPORT GpgVerifyResult {
[[nodiscard]] auto GetRaw() const -> gpgme_verify_result_t;
[[nodiscard]] auto GetSignature() const -> std::vector<GpgSignature>;
[[nodiscard]] auto GetSignature() const -> QContainer<GpgSignature>;
explicit GpgVerifyResult(gpgme_verify_result_t);

View File

@ -34,6 +34,7 @@ struct KeyDatabaseInfo {
int channel;
QString name;
QString path;
QString origin_path;
KeyDatabaseInfo() = default;
};

View File

@ -43,7 +43,7 @@ class Event;
using EventReference = std::shared_ptr<Event>;
using EventIdentifier = QString;
using EventTriggerIdentifier = QString;
using Evnets = std::vector<Event>;
using Evnets = QContainer<Event>;
class GPGFRONTEND_CORE_EXPORT Event {
public:

View File

@ -352,7 +352,7 @@ class GlobalModuleContext::Impl {
bool registered;
bool activate;
bool integrated;
QList<QString> listening_event_ids;
QStringList listening_event_ids;
};
using ModuleRegisterInfoPtr = std::shared_ptr<ModuleRegisterInfo>;

View File

@ -107,10 +107,10 @@ class GlobalRegisterTable::Impl {
return rtn;
}
auto ListChildKeys(const Namespace& n, const Key& k) -> std::vector<Key> {
auto ListChildKeys(const Namespace& n, const Key& k) -> QContainer<Key> {
QStringList const segments = (n + "." + k).split('.');
std::vector<Key> rtn;
QContainer<Key> rtn;
{
std::shared_lock lock(lock_);
@ -302,8 +302,7 @@ auto GlobalRegisterTable::ListenPublish(QObject* o, Namespace n, Key k,
return p_->ListenPublish(o, n, k, c);
}
auto GlobalRegisterTable::ListChildKeys(Namespace n,
Key k) -> std::vector<Key> {
auto GlobalRegisterTable::ListChildKeys(Namespace n, Key k) -> QContainer<Key> {
return p_->ListChildKeys(n, k);
}

View File

@ -33,6 +33,7 @@
#include <optional>
#include "core/function/SecureMemoryAllocator.h"
#include "core/typedef/CoreTypedef.h"
namespace GpgFrontend::Module {
@ -55,7 +56,7 @@ class GlobalRegisterTable : public QObject {
auto ListenPublish(QObject *, Namespace, Key, LPCallback) -> bool;
auto ListChildKeys(Namespace n, Key k) -> std::vector<Key>;
auto ListChildKeys(Namespace n, Key k) -> QContainer<Key>;
signals:
void SignalPublish(Namespace, Key, int, std::any);

View File

@ -78,10 +78,7 @@ auto LoadExternalMods() -> QMap<QString, bool> {
void LoadGpgFrontendModules(ModuleInitArgs) {
// give user ability to give up all modules
auto disable_loading_all_modules =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("basic/disable_loading_all_modules", false)
.toBool();
GetSettings().value("basic/disable_loading_all_modules", false).toBool();
if (disable_loading_all_modules) return;
// must init at default thread before core

View File

@ -220,7 +220,7 @@ class ModuleManager::Impl {
return grt_->ListenPublish(o, n, k, c);
}
auto ListRTChildKeys(const QString& n, const QString& k) -> std::vector<Key> {
auto ListRTChildKeys(const QString& n, const QString& k) -> QContainer<Key> {
return grt_->ListChildKeys(n, k);
}
@ -271,7 +271,7 @@ auto ListenRTPublishEvent(QObject* o, Namespace n, Key k,
}
auto ListRTChildKeys(const QString& namespace_,
const QString& key) -> std::vector<Key> {
const QString& key) -> QContainer<Key> {
return ModuleManager::GetInstance().ListRTChildKeys(namespace_, key);
}
@ -341,7 +341,7 @@ auto ModuleManager::ListenRTPublish(QObject* o, Namespace n, Key k,
}
auto ModuleManager::ListRTChildKeys(const QString& n,
const QString& k) -> std::vector<Key> {
const QString& k) -> QContainer<Key> {
return p_->ListRTChildKeys(n, k);
}

View File

@ -101,7 +101,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager
auto ListenRTPublish(QObject*, Namespace, Key, LPCallback) -> bool;
auto ListRTChildKeys(const QString&, const QString&) -> std::vector<Key>;
auto ListRTChildKeys(const QString&, const QString&) -> QContainer<Key>;
auto GRT() -> GlobalRegisterTable*;
@ -175,10 +175,10 @@ auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key,
*
* @param namespace_
* @param key
* @return std::vector<Key>
* @return QContainer<Key>
*/
auto GPGFRONTEND_CORE_EXPORT ListRTChildKeys(
const QString& namespace_, const QString& key) -> std::vector<Key>;
const QString& namespace_, const QString& key) -> QContainer<Key>;
template <typename T>
auto RetrieveRTValueTyped(const QString& namespace_,

View File

@ -31,7 +31,7 @@
namespace GpgFrontend {
struct FavoriteKeyPairsByKeyDatabaseCO {
QList<QString> key_ids;
QStringList key_ids;
FavoriteKeyPairsByKeyDatabaseCO() = default;

View File

@ -35,12 +35,14 @@ namespace GpgFrontend {
struct KeyDatabaseItemSO {
QString name;
QString path;
int channel;
KeyDatabaseItemSO() = default;
explicit KeyDatabaseItemSO(KeyDatabaseInfo i) {
name = i.name;
path = i.path;
path = i.origin_path.isEmpty() ? i.path : i.origin_path;
channel = i.channel;
}
explicit KeyDatabaseItemSO(const QJsonObject& j) {
@ -50,12 +52,16 @@ struct KeyDatabaseItemSO {
if (const auto v = j["path"]; v.isString()) {
path = v.toString();
}
if (const auto v = j["channel"]; v.isDouble()) {
channel = v.toInt();
}
}
[[nodiscard]] auto ToJson() const -> QJsonObject {
QJsonObject j;
j["name"] = name;
j["path"] = path;
j["channel"] = channel;
return j;
}
};

View File

@ -28,22 +28,25 @@
#pragma once
#include "core/model/DataObject.h"
namespace GpgFrontend {
using GFError = uint32_t;
using ByteArray = QByteArray; ///<
using ByteArrayPtr = std::shared_ptr<ByteArray>; ///<
using StdBypeArrayPtr = std::shared_ptr<ByteArray>; ///<
using BypeArrayRef = ByteArray&; ///<
using ConstBypeArrayRef = const ByteArray&; ///<
using BypeArrayConstRef = const ByteArray&; ///<
using StringArgsPtr = std::unique_ptr<std::vector<QString>>; ///<
using StringArgsRef = std::vector<QString>&; ///<
///
///
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
template <typename T>
using QContainer = QVector<T>;
#else
template <typename T>
using QContainer = QList<T>;
#endif
using GFError = uint32_t;
using ByteArray = QByteArray; ///<
using BypeArrayRef = ByteArray&; ///<
using BypeArrayConstRef = const ByteArray&; ///<
using StringArgsPtr = QStringList; ///<
using StringArgsRef = QStringList&; ///<
class DataObject;
using DataObjectPtr = std::shared_ptr<DataObject>; ///<
using OperaRunnable = std::function<GFError(DataObjectPtr)>;
using OperationCallback = std::function<void(GFError, DataObjectPtr)>;
} // namespace GpgFrontend

View File

@ -30,7 +30,10 @@
#include <gpgme.h>
#include <future>
#include "core/model/DataObject.h"
#include "core/typedef/CoreTypedef.h"
namespace GpgFrontend {
@ -41,25 +44,16 @@ class GpgTOFUInfo;
using GpgError = gpgme_error_t; ///< gpgme error
using GpgErrorCode = gpg_err_code_t;
using GpgErrorDesc = std::pair<QString, QString>;
using GpgErrorDesc = QPair<QString, QString>;
using KeyId = QString; ///<
using SubkeyId = QString; ///<
using KeyIdArgsList = std::vector<KeyId>; ///<
using KeyIdArgsListPtr = std::unique_ptr<KeyIdArgsList>; ///<
using UIDArgsList = std::vector<QString>; ///<
using UIDArgsListPtr = std::unique_ptr<UIDArgsList>; ///<
using SignIdArgsList = std::vector<std::pair<QString, QString>>; ///<
using SignIdArgsListPtr = std::unique_ptr<SignIdArgsList>; ///<
using KeyFprArgsListPtr = std::unique_ptr<std::vector<QString>>; ///<
using KeyArgsList = std::vector<GpgKey>; ///<
using KeyListPtr = std::shared_ptr<KeyArgsList>; ///<
using GpgKeyLinkList = std::list<GpgKey>; ///<
using KeyLinkListPtr = std::unique_ptr<GpgKeyLinkList>; ///<
using KeyPtr = std::unique_ptr<GpgKey>; ///<
using KeyPtrArgsList = const std::initializer_list<KeyPtr>; ///<
using GpgKeyList = QList<GpgKey>; ///<
using GpgKeyIDList = QList<QString>; ///<
using KeyId = QString;
using SubkeyId = QString;
using KeyIdArgsList = QStringList; ///<
using UIDArgsList = QStringList; ///<
using SignIdArgsList = QContainer<QPair<QString, QString>>; ///<
using KeyArgsList = QContainer<GpgKey>; ///<
using GpgKeyLinkList = QContainer<GpgKey>; ///<
using GpgKeyList = QContainer<GpgKey>; ///<
using GpgSignMode = gpgme_sig_mode_t;
@ -68,11 +62,14 @@ using GpgOperationCallback = std::function<void(GpgError, DataObjectPtr)>;
using GpgOperationFuture = std::future<std::tuple<GpgError, DataObjectPtr>>;
enum GpgOperation {
kENCRYPT,
kDECRYPT,
kSIGN,
kVERIFY,
kENCRYPT_SIGN,
kDECRYPT_VERIFY
kNONE = 0,
kENCRYPT = 1 << 0,
kDECRYPT = 1 << 1,
kSIGN = 1 << 2,
kVERIFY = 1 << 3,
kENCRYPT_SIGN = 1 << 4,
kDECRYPT_VERIFY = 1 << 5,
kAUTH = 1 << 6,
kCERT = 1 << 7,
};
} // namespace GpgFrontend

View File

@ -28,6 +28,8 @@
#include "CommonUtils.h"
#include "core/utils/MemoryUtils.h"
namespace GpgFrontend {
auto BeautifyFingerprint(QString fingerprint) -> QString {

View File

@ -28,15 +28,19 @@
#include "GpgUtils.h"
#include "core/function/GlobalSettingStation.h"
#include "core/model/GpgKey.h"
#include "core/model/KeyDatabaseInfo.h"
#include "core/model/SettingsObject.h"
#include "core/module/ModuleManager.h"
#include "core/struct/settings_object/KeyDatabaseListSO.h"
namespace GpgFrontend {
inline auto Trim(QString& s) -> QString { return s.trimmed(); }
auto GetGpgmeErrorString(size_t buffer_size, gpgme_error_t err) -> QString {
std::vector<char> buffer(buffer_size);
QContainer<char> buffer(buffer_size);
gpgme_error_t const ret = gpgme_strerror_r(err, buffer.data(), buffer.size());
if (ret == ERANGE && buffer_size < 1024) {
@ -218,4 +222,115 @@ auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseName(int channel) -> QString {
if (channel >= info.size()) return {};
return info[channel].name;
}
auto GetKeyDatabasesBySettings() -> QContainer<KeyDatabaseItemSO> {
auto key_db_list_so = SettingsObject("key_database_list");
auto key_db_list = KeyDatabaseListSO(key_db_list_so);
auto& key_dbs = key_db_list.key_databases;
if (key_dbs.empty()) {
KeyDatabaseItemSO key_db;
auto home_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.default_database_path", QString{});
if (GlobalSettingStation::GetInstance().IsProtableMode()) {
home_path = QDir(GlobalSettingStation::GetInstance().GetAppDir())
.relativeFilePath(home_path);
}
key_db.channel = 0;
key_db.name = "DEFAULT";
key_db.path = home_path;
key_dbs.append(key_db);
}
// Sort by channel
std::sort(key_dbs.begin(), key_dbs.end(),
[](const auto& a, const auto& b) { return a.channel < b.channel; });
// Resolve duplicate channels by incrementing
for (auto it = key_dbs.begin(); it != key_dbs.end(); ++it) {
auto next_it = std::next(it);
while (next_it != key_dbs.end() && next_it->channel == it->channel) {
next_it->channel = it->channel + 1;
++next_it;
}
}
key_db_list_so.Store(key_db_list.ToJson());
return key_db_list.key_databases;
}
auto VerifyKeyDatabasePath(const QFileInfo& key_database_fs_path) -> bool {
return key_database_fs_path.isAbsolute() && key_database_fs_path.exists() &&
key_database_fs_path.isDir();
}
auto SearchKeyDatabasePath(const QStringList& candidate_paths) -> QString {
for (const auto& path : candidate_paths) {
if (VerifyKeyDatabasePath(QFileInfo(path))) {
// return a unify path
return QFileInfo(path).absoluteFilePath();
}
}
return {};
}
auto GetCanonicalKeyDatabasePath(const QDir& app_path,
const QString& path) -> QString {
auto target_path = path;
if (!QDir::isAbsolutePath(target_path)) {
target_path = app_path.absoluteFilePath(target_path);
LOG_D() << "convert relative path: " << path
<< "to absolute path: " << target_path;
}
auto info = QFileInfo(target_path);
if (VerifyKeyDatabasePath(info)) {
auto key_database_fs_path = info.canonicalFilePath();
LOG_D() << "load gpg key database:" << key_database_fs_path;
return key_database_fs_path;
}
LOG_W() << "gpg key database path is invalid: " << path;
return {};
}
auto GetKeyDatabaseInfoBySettings() -> QList<KeyDatabaseInfo> {
auto key_dbs = GetKeyDatabasesBySettings();
QContainer<KeyDatabaseInfo> key_db_infos;
const auto app_path = QDir(GlobalSettingStation::GetInstance().GetAppDir());
// try to use user defined key database
for (const auto& key_database : key_dbs) {
auto key_database_fs_path =
GetCanonicalKeyDatabasePath(app_path, key_database.path);
if (key_database_fs_path.isEmpty()) continue;
KeyDatabaseInfo key_db_info;
key_db_info.name = key_database.name;
key_db_info.path = key_database_fs_path;
key_db_info.origin_path = key_database.path;
key_db_infos.append(key_db_info);
LOG_D() << "plan to load gpg key database:" << key_database_fs_path;
}
return key_db_infos;
}
auto GPGFRONTEND_CORE_EXPORT Convert2RawGpgMEKeyList(
const QContainer<GpgKey>& keys) -> QContainer<gpgme_key_t> {
QContainer<gpgme_key_t> recipients(keys.begin(), keys.end());
recipients.emplace_back(nullptr);
return recipients;
}
} // namespace GpgFrontend

View File

@ -30,6 +30,7 @@
#include "core/function/result_analyse/GpgResultAnalyse.h"
#include "core/model/KeyDatabaseInfo.h"
#include "core/struct/settings_object/KeyDatabaseItemSO.h"
#include "core/typedef/CoreTypedef.h"
#include "core/typedef/GpgTypedef.h"
@ -106,6 +107,32 @@ auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFile(const QString& path,
auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFileForArchive(
const QString& path, GpgOperation opera, bool ascii) -> QString;
/**
* @brief
*
* @param app_path
* @param path
* @return QString
*/
auto GPGFRONTEND_CORE_EXPORT GetCanonicalKeyDatabasePath(
const QDir& app_path, const QString& path) -> QString;
/**
* @brief Get the Key Databases By Settings object
*
* @return QContainer<KeyDatabaseItemSO>
*/
auto GPGFRONTEND_CORE_EXPORT GetKeyDatabasesBySettings()
-> QContainer<KeyDatabaseItemSO>;
/**
* @brief
*
* @return QList<KeyDatabaseInfo>
*/
auto GPGFRONTEND_CORE_EXPORT GetKeyDatabaseInfoBySettings()
-> QList<KeyDatabaseInfo>;
/**
* @brief
*
@ -120,4 +147,13 @@ auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseInfos() -> QList<KeyDatabaseInfo>;
*/
auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseName(int channel) -> QString;
/**
* @brief
*
* @param keys
* @return QContainer<gpgme_key_t>
*/
auto GPGFRONTEND_CORE_EXPORT Convert2RawGpgMEKeyList(
const QContainer<GpgKey>& keys) -> QContainer<gpgme_key_t>;
} // namespace GpgFrontend

View File

@ -57,16 +57,12 @@ int setenv(const char *name, const char *value, int overwrite) {
void InitGlobalPathEnv() {
// read settings
bool use_custom_gnupg_install_path =
GlobalSettingStation::GetInstance()
.GetSettings()
GetSettings()
.value("gnupg/use_custom_gnupg_install_path", false)
.toBool();
QString custom_gnupg_install_path =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("gnupg/custom_gnupg_install_path")
.toString();
GetSettings().value("gnupg/custom_gnupg_install_path").toString();
// add custom gnupg install path into env $PATH
if (use_custom_gnupg_install_path && !custom_gnupg_install_path.isEmpty()) {
@ -79,10 +75,7 @@ void InitGlobalPathEnv() {
QString modified_path_value = getenv("PATH");
}
if (GlobalSettingStation::GetInstance()
.GetSettings()
.value("gnupg/enable_gpgme_debug_log", false)
.toBool()) {
if (GetSettings().value("gnupg/enable_gpgme_debug_log", false).toBool()) {
qputenv("GPGME_DEBUG",
QString("9:%1").arg(QDir::currentPath() + "/gpgme.log").toUtf8());
}
@ -142,8 +135,7 @@ void InitGlobalBasicEnv(const GFCxtWPtr &p_ctx, bool gui_mode) {
*/
void InitLocale() {
// get the instance of the GlobalSettingStation
auto settings =
GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
auto settings = GpgFrontend::GetSettings();
// read from settings file
auto lang = settings.value("basic/lang").toString();
@ -184,18 +176,30 @@ void ShutdownGlobalBasicEnv(const GFCxtWPtr &p_ctx) {
}
auto clear_gpg_password_cache =
GlobalSettingStation::GetInstance()
.GetSettings()
.value("basic/clear_gpg_password_cache", false)
GetSettings().value("basic/clear_gpg_password_cache", false).toBool();
auto kill_all_gnupg_daemon_at_close =
GetSettings()
.value("gnupg/kill_all_gnupg_daemon_at_close", false)
.toBool();
// clear password cache
if (!ctx->unit_test_mode && clear_gpg_password_cache) {
GpgAdvancedOperator::ClearGpgPasswordCache([](int, DataObjectPtr) {});
if (ctx->unit_test_mode || kill_all_gnupg_daemon_at_close) {
GpgAdvancedOperator::KillAllGpgComponents(nullptr);
} else if (!ctx->unit_test_mode && clear_gpg_password_cache) {
GpgAdvancedOperator::ClearGpgPasswordCache(nullptr);
}
Thread::TaskRunnerGetter::GetInstance().StopAllTeakRunner();
// first should shutdown the module system
GpgFrontend::Module::ShutdownGpgFrontendModules();
DestroyGpgFrontendCore();
// then shutdown the core
GpgFrontend::DestroyGpgFrontendCore();
// deep restart mode
if (ctx->rtn == GpgFrontend::kDeepRestartCode ||
ctx->rtn == GpgFrontend::kCrashCode) {
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
};
}
} // namespace GpgFrontend

View File

@ -171,7 +171,7 @@ TEST_F(GpgCoreTest, CoreSignVerifyNormalTest) {
GpgBasicOperator::GetInstance().VerifySync(sign_out_buffer, GFBuffer());
ASSERT_EQ(CheckGpgError(err_0), GPG_ERR_NO_ERROR);
ASSERT_TRUE((data_object_0->Check<GpgVerifyResult>()));
ASSERT_TRUE((data_object_0->Check<GpgVerifyResult, GFBuffer>()));
auto verify_result = ExtractParams<GpgVerifyResult>(data_object_0, 0);
ASSERT_FALSE(verify_result.GetSignature().empty());
ASSERT_EQ(verify_result.GetSignature().at(0).GetFingerprint(),
@ -198,7 +198,7 @@ TEST_F(GpgCoreTest, CoreSignVerifyDetachTest) {
GpgBasicOperator::GetInstance().VerifySync(sign_text, sign_out_buffer);
ASSERT_EQ(CheckGpgError(err_0), GPG_ERR_NO_ERROR);
ASSERT_TRUE((data_object_0->Check<GpgVerifyResult>()));
ASSERT_TRUE((data_object_0->Check<GpgVerifyResult, GFBuffer>()));
auto verify_result = ExtractParams<GpgVerifyResult>(data_object_0, 0);
ASSERT_FALSE(verify_result.GetSignature().empty());
ASSERT_EQ(verify_result.GetSignature().at(0).GetFingerprint(),
@ -241,7 +241,7 @@ TEST_F(GpgCoreTest, CoreEncryptSignDecrVerifyTest) {
auto encrypt_text = GFBuffer(QString("Hello GpgFrontend!"));
ASSERT_TRUE(sign_key.IsPrivateKey());
ASSERT_TRUE(sign_key.IsHasActualSigningCapability());
ASSERT_TRUE(sign_key.IsHasActualSignCap());
auto [err, data_object] = GpgBasicOperator::GetInstance().EncryptSignSync(
{encrypt_key}, {sign_key}, encrypt_text, true);

View File

@ -232,7 +232,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSignDecrVerifyTest) {
auto output_file = GetTempFilePath();
ASSERT_TRUE(sign_key.IsPrivateKey());
ASSERT_TRUE(sign_key.IsHasActualSigningCapability());
ASSERT_TRUE(sign_key.IsHasActualSignCap());
auto [err, data_object] = GpgFileOpera::GetInstance().EncryptSignFileSync(
{encrypt_key}, {sign_key}, input_file, true, output_file);
@ -279,7 +279,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSignDecrVerifyBinaryTest) {
auto output_file = GetTempFilePath();
ASSERT_TRUE(sign_key.IsPrivateKey());
ASSERT_TRUE(sign_key.IsHasActualSigningCapability());
ASSERT_TRUE(sign_key.IsHasActualSignCap());
auto [err, data_object] = GpgFileOpera::GetInstance().EncryptSignFileSync(
{encrypt_key}, {sign_key}, input_file, false, output_file);

View File

@ -69,14 +69,14 @@ TEST_F(GpgCoreTest, GpgKeyTest) {
ASSERT_EQ(key.GetSubKeys()->size(), 2);
ASSERT_EQ(key.GetUIDs()->size(), 1);
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_FALSE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_FALSE(key.IsHasAuthenticationCapability());
ASSERT_FALSE(key.IsHasActualCertificationCapability());
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
ASSERT_FALSE(key.IsHasActualSigningCapability());
ASSERT_FALSE(key.IsHasActualAuthenticationCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_FALSE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_FALSE(key.IsHasAuthCap());
ASSERT_FALSE(key.IsHasActualCertCap());
ASSERT_FALSE(key.IsHasActualEncrCap());
ASSERT_FALSE(key.IsHasActualSignCap());
ASSERT_FALSE(key.IsHasActualAuthCap());
ASSERT_EQ(key.GetName(), "GpgFrontendTest");
ASSERT_TRUE(key.GetComment().isEmpty());
@ -133,10 +133,10 @@ TEST_F(GpgCoreTest, GpgSubKeyTest) {
ASSERT_EQ(sub_key.GetKeyLength(), 3072);
ASSERT_EQ(sub_key.GetKeyAlgo(), "RSA3072");
ASSERT_EQ(sub_key.GetPubkeyAlgo(), "RSA");
ASSERT_FALSE(sub_key.IsHasCertificationCapability());
ASSERT_FALSE(sub_key.IsHasAuthenticationCapability());
ASSERT_FALSE(sub_key.IsHasSigningCapability());
ASSERT_TRUE(sub_key.IsHasEncryptionCapability());
ASSERT_FALSE(sub_key.IsHasCertCap());
ASSERT_FALSE(sub_key.IsHasAuthCap());
ASSERT_FALSE(sub_key.IsHasSignCap());
ASSERT_TRUE(sub_key.IsHasEncrCap());
ASSERT_EQ(sub_key.GetExpireTime(),
QDateTime::fromString("2023-09-05T04:00:00Z", Qt::ISODate));
@ -189,8 +189,8 @@ TEST_F(GpgCoreTest, GpgKeyGetterTest) {
ASSERT_TRUE(key.IsGood());
auto keys = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel).FetchKey();
EXPECT_GT(keys->size(), 0);
ASSERT_TRUE(find(keys->begin(), keys->end(), key) != keys->end());
EXPECT_GT(keys.size(), 0);
ASSERT_TRUE(std::find(keys.begin(), keys.end(), key) != keys.end());
}
} // namespace GpgFrontend::Test

View File

@ -29,26 +29,49 @@
#include "GpgCoreTest.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/model/GpgGenKeyInfo.h"
#include "core/model/GpgGenerateKeyResult.h"
#include "core/model/GpgKey.h"
#include "core/model/GpgKeyGenerateInfo.h"
#include "core/utils/GpgUtils.h"
#include "core/utils/MemoryUtils.h"
namespace GpgFrontend::Test {
TEST_F(GpgCoreTest, SearchPrimaryKeyAlgoTest) {
auto [find, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048");
ASSERT_TRUE(find);
ASSERT_EQ(algo.Id(), "rsa2048");
ASSERT_EQ(algo.Id(), "rsa2048");
ASSERT_EQ(algo.Name(), "RSA");
ASSERT_EQ(algo.Type(), "RSA");
ASSERT_EQ(algo.KeyLength(), 2048);
}
TEST_F(GpgCoreTest, SearchSubKeyAlgoTest) {
auto [find, algo] = KeyGenerateInfo::SearchSubKeyAlgo("rsa2048");
ASSERT_TRUE(find);
ASSERT_EQ(algo.Id(), "rsa2048");
ASSERT_EQ(algo.Name(), "RSA");
ASSERT_EQ(algo.Type(), "RSA");
ASSERT_EQ(algo.KeyLength(), 2048);
}
TEST_F(GpgCoreTest, GenerateKeyRSA2048Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_0");
keygen_info->SetEmail("bar@gpgfrontend.bktus.com");
keygen_info->SetComment("foobar");
keygen_info->SetAlgo("rsa");
keygen_info->SetKeyLength(2048);
keygen_info->SetNonExpired(true);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_0");
p_info->SetEmail("bar@gpgfrontend.bktus.com");
p_info->SetComment("foobar");
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "rsa2048");
p_info->SetAlgo(algo);
p_info->SetNonExpired(true);
p_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeySync(keygen_info);
.GenerateKeySync(p_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -69,37 +92,41 @@ TEST_F(GpgCoreTest, GenerateKeyRSA2048Test) {
ASSERT_EQ(key.GetPrimaryKeyLength(), 2048);
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_TRUE(key.IsHasAuthenticationCapability());
ASSERT_TRUE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_TRUE(key.IsHasAuthCap());
ASSERT_TRUE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_TRUE(key.IsHasActualCertificationCapability());
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
ASSERT_TRUE(key.IsHasActualEncryptionCapability());
ASSERT_TRUE(key.IsHasActualSigningCapability());
ASSERT_TRUE(key.IsHasActualCertCap());
ASSERT_TRUE(key.IsHasActualAuthCap());
ASSERT_TRUE(key.IsHasActualEncrCap());
ASSERT_TRUE(key.IsHasActualSignCap());
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.DeleteKey(result.GetFingerprint());
}
TEST_F(GpgCoreTest, GenerateKeyRSA4096Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_1");
keygen_info->SetEmail("bar@gpgfrontend.bktus.com");
keygen_info->SetComment("hello gpgfrontend");
keygen_info->SetAlgo("rsa");
keygen_info->SetKeyLength(4096);
keygen_info->SetNonExpired(false);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_1");
p_info->SetEmail("bar@gpgfrontend.bktus.com");
p_info->SetComment("hello gpgfrontend");
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa4096");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "rsa4096");
p_info->SetAlgo(algo);
p_info->SetNonExpired(false);
p_info->SetNonPassPhrase(true);
auto expire_time =
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
keygen_info->SetExpireTime(expire_time);
keygen_info->SetNonPassPhrase(false);
p_info->SetExpireTime(expire_time);
p_info->SetNonPassPhrase(false);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeySync(keygen_info);
.GenerateKeySync(p_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -119,22 +146,26 @@ TEST_F(GpgCoreTest, GenerateKeyRSA4096Test) {
}
TEST_F(GpgCoreTest, GenerateKeyDSA2048Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_1");
keygen_info->SetEmail("bar_1@gpgfrontend.bktus.com");
keygen_info->SetComment("hello gpgfrontend");
keygen_info->SetAlgo("dsa");
keygen_info->SetKeyLength(2048);
keygen_info->SetNonExpired(false);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_1");
p_info->SetEmail("bar_1@gpgfrontend.bktus.com");
p_info->SetComment("hello gpgfrontend");
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("dsa2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "dsa2048");
p_info->SetAlgo(algo);
p_info->SetNonExpired(false);
p_info->SetNonPassPhrase(true);
auto expire_time =
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
keygen_info->SetExpireTime(expire_time);
keygen_info->SetNonPassPhrase(false);
p_info->SetExpireTime(expire_time);
p_info->SetNonPassPhrase(false);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeySync(keygen_info);
.GenerateKeySync(p_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
@ -154,36 +185,41 @@ TEST_F(GpgCoreTest, GenerateKeyDSA2048Test) {
ASSERT_EQ(key.GetPrimaryKeyLength(), 2048);
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_TRUE(key.IsHasAuthenticationCapability());
ASSERT_FALSE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_TRUE(key.IsHasAuthCap());
ASSERT_FALSE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_TRUE(key.IsHasActualCertificationCapability());
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
ASSERT_TRUE(key.IsHasActualSigningCapability());
ASSERT_TRUE(key.IsHasActualCertCap());
ASSERT_TRUE(key.IsHasActualAuthCap());
ASSERT_FALSE(key.IsHasActualEncrCap());
ASSERT_TRUE(key.IsHasActualSignCap());
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.DeleteKey(result.GetFingerprint());
}
TEST_F(GpgCoreTest, GenerateKeyED25519Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_4");
keygen_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
keygen_info->SetComment("hello gpgfrontend");
keygen_info->SetAlgo("ed25519");
keygen_info->SetNonExpired(false);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_4");
p_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
p_info->SetComment("hello gpgfrontend");
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
p_info->SetAlgo(algo);
p_info->SetNonExpired(false);
p_info->SetNonPassPhrase(true);
auto expire_time =
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
keygen_info->SetExpireTime(expire_time);
keygen_info->SetNonPassPhrase(false);
p_info->SetExpireTime(expire_time);
p_info->SetNonPassPhrase(false);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeySync(keygen_info);
.GenerateKeySync(p_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
@ -203,37 +239,46 @@ TEST_F(GpgCoreTest, GenerateKeyED25519Test) {
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_TRUE(key.IsHasAuthenticationCapability());
ASSERT_FALSE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_TRUE(key.IsHasAuthCap());
ASSERT_FALSE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_TRUE(key.IsHasActualCertificationCapability());
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
ASSERT_TRUE(key.IsHasActualSigningCapability());
ASSERT_TRUE(key.IsHasActualCertCap());
ASSERT_TRUE(key.IsHasActualAuthCap());
ASSERT_FALSE(key.IsHasActualEncrCap());
ASSERT_TRUE(key.IsHasActualSignCap());
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.DeleteKey(result.GetFingerprint());
}
TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_ec");
keygen_info->SetEmail("ec_bar@gpgfrontend.bktus.com");
keygen_info->SetComment("ecccc");
keygen_info->SetAlgo("ed25519");
keygen_info->SetNonExpired(true);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_ec");
p_info->SetEmail("ec_bar@gpgfrontend.bktus.com");
p_info->SetComment("ecccc");
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("cv25519");
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
p_info->SetAlgo(algo);
auto [err, data_object] =
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeyWithSubkeySync(keygen_info, subkeygen_info);
p_info->SetNonExpired(true);
p_info->SetNonPassPhrase(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
std::tie(found, algo) = KeyGenerateInfo::SearchSubKeyAlgo("cv25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "cv25519");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
s_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeyWithSubkeySync(p_info, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_TRUE(
@ -255,10 +300,10 @@ TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_TRUE(key.IsHasAuthenticationCapability());
ASSERT_TRUE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_TRUE(key.IsHasAuthCap());
ASSERT_TRUE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_FALSE(key.GetSubKeys()->empty());
ASSERT_EQ(key.GetSubKeys()->size(), 2);
@ -270,36 +315,45 @@ TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
ASSERT_EQ(subkey.GetKeyLength(), 255);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_FALSE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_FALSE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_FALSE(subkey.IsHasSignCap());
ASSERT_TRUE(key.IsHasActualCertificationCapability());
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
ASSERT_TRUE(key.IsHasActualEncryptionCapability());
ASSERT_TRUE(key.IsHasActualSigningCapability());
ASSERT_TRUE(key.IsHasActualCertCap());
ASSERT_TRUE(key.IsHasActualAuthCap());
ASSERT_TRUE(key.IsHasActualEncrCap());
ASSERT_TRUE(key.IsHasActualSignCap());
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel).DeleteKey(fpr);
}
TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_ec2");
keygen_info->SetEmail("ec2_bar@gpgfrontend.bktus.com");
keygen_info->SetComment("ecccc");
keygen_info->SetAlgo("ed25519");
keygen_info->SetNonExpired(true);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_ec2");
p_info->SetEmail("ec2_bar@gpgfrontend.bktus.com");
p_info->SetComment("ecccc");
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("nistp256");
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
p_info->SetAlgo(algo);
auto [err, data_object] =
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeyWithSubkeySync(keygen_info, subkeygen_info);
p_info->SetNonExpired(true);
p_info->SetNonPassPhrase(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
std::tie(found, algo) = KeyGenerateInfo::SearchSubKeyAlgo("nistp256");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "nistp256");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
s_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeyWithSubkeySync(p_info, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_TRUE(
@ -321,10 +375,10 @@ TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_TRUE(key.IsHasAuthenticationCapability());
ASSERT_TRUE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_TRUE(key.IsHasAuthCap());
ASSERT_TRUE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_FALSE(key.GetSubKeys()->empty());
ASSERT_EQ(key.GetSubKeys()->size(), 2);
@ -336,36 +390,45 @@ TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
ASSERT_EQ(subkey.GetKeyLength(), 256);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_FALSE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_FALSE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_FALSE(subkey.IsHasSignCap());
ASSERT_TRUE(key.IsHasActualCertificationCapability());
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
ASSERT_TRUE(key.IsHasActualEncryptionCapability());
ASSERT_TRUE(key.IsHasActualSigningCapability());
ASSERT_TRUE(key.IsHasActualCertCap());
ASSERT_TRUE(key.IsHasActualAuthCap());
ASSERT_TRUE(key.IsHasActualEncrCap());
ASSERT_TRUE(key.IsHasActualSignCap());
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel).DeleteKey(fpr);
}
TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_ec3");
keygen_info->SetEmail("ec3_bar@gpgfrontend.bktus.com");
keygen_info->SetComment("ecccc3");
keygen_info->SetAlgo("ed25519");
keygen_info->SetNonExpired(true);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_ec3");
p_info->SetEmail("ec3_bar@gpgfrontend.bktus.com");
p_info->SetComment("ecccc3");
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("brainpoolp256r1");
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
p_info->SetAlgo(algo);
auto [err, data_object] =
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeyWithSubkeySync(keygen_info, subkeygen_info);
p_info->SetNonExpired(true);
p_info->SetNonPassPhrase(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
std::tie(found, algo) = KeyGenerateInfo::SearchSubKeyAlgo("brainpoolp256r1");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "brainpoolp256r1");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
s_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeyWithSubkeySync(p_info, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_TRUE(
@ -387,10 +450,10 @@ TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_TRUE(key.IsHasAuthenticationCapability());
ASSERT_TRUE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_TRUE(key.IsHasAuthCap());
ASSERT_TRUE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_FALSE(key.GetSubKeys()->empty());
ASSERT_EQ(key.GetSubKeys()->size(), 2);
@ -402,35 +465,40 @@ TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
ASSERT_EQ(subkey.GetKeyLength(), 256);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_FALSE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_FALSE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_FALSE(subkey.IsHasSignCap());
ASSERT_TRUE(key.IsHasActualCertificationCapability());
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
ASSERT_TRUE(key.IsHasActualEncryptionCapability());
ASSERT_TRUE(key.IsHasActualSigningCapability());
ASSERT_TRUE(key.IsHasActualCertCap());
ASSERT_TRUE(key.IsHasActualAuthCap());
ASSERT_TRUE(key.IsHasActualEncrCap());
ASSERT_TRUE(key.IsHasActualSignCap());
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel).DeleteKey(fpr);
}
TEST_F(GpgCoreTest, GenerateKeyNISTP256Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_4");
keygen_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
keygen_info->SetComment("hello gpgfrontend");
keygen_info->SetAlgo("nistp256");
keygen_info->SetNonExpired(false);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_4");
p_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
p_info->SetComment("hello gpgfrontend");
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("nistp256");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "nistp256");
p_info->SetAlgo(algo);
p_info->SetNonExpired(false);
p_info->SetNonPassPhrase(true);
auto expire_time =
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
keygen_info->SetExpireTime(expire_time);
keygen_info->SetNonPassPhrase(false);
p_info->SetExpireTime(expire_time);
p_info->SetNonPassPhrase(false);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeySync(keygen_info);
.GenerateKeySync(p_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
@ -451,36 +519,41 @@ TEST_F(GpgCoreTest, GenerateKeyNISTP256Test) {
ASSERT_EQ(key.GetPrimaryKeyLength(), 256);
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_TRUE(key.IsHasAuthenticationCapability());
ASSERT_FALSE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_TRUE(key.IsHasAuthCap());
ASSERT_FALSE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_TRUE(key.IsHasActualCertificationCapability());
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
ASSERT_TRUE(key.IsHasActualSigningCapability());
ASSERT_TRUE(key.IsHasActualCertCap());
ASSERT_TRUE(key.IsHasActualAuthCap());
ASSERT_FALSE(key.IsHasActualEncrCap());
ASSERT_TRUE(key.IsHasActualSignCap());
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.DeleteKey(result.GetFingerprint());
}
TEST_F(GpgCoreTest, GenerateKeyED448Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_4");
keygen_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
keygen_info->SetComment("hello gpgfrontend");
keygen_info->SetAlgo("ed448");
keygen_info->SetNonExpired(false);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_4");
p_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
p_info->SetComment("hello gpgfrontend");
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed448");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed448");
p_info->SetAlgo(algo);
p_info->SetNonExpired(false);
p_info->SetNonPassPhrase(true);
auto expire_time =
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
keygen_info->SetExpireTime(expire_time);
keygen_info->SetNonPassPhrase(false);
p_info->SetExpireTime(expire_time);
p_info->SetNonPassPhrase(false);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeySync(keygen_info);
.GenerateKeySync(p_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
@ -501,36 +574,41 @@ TEST_F(GpgCoreTest, GenerateKeyED448Test) {
ASSERT_EQ(key.GetPrimaryKeyLength(), 448);
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_TRUE(key.IsHasAuthenticationCapability());
ASSERT_FALSE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_TRUE(key.IsHasAuthCap());
ASSERT_FALSE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_TRUE(key.IsHasActualCertificationCapability());
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
ASSERT_TRUE(key.IsHasActualSigningCapability());
ASSERT_TRUE(key.IsHasActualCertCap());
ASSERT_TRUE(key.IsHasActualAuthCap());
ASSERT_FALSE(key.IsHasActualEncrCap());
ASSERT_TRUE(key.IsHasActualSignCap());
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.DeleteKey(result.GetFingerprint());
}
TEST_F(GpgCoreTest, GenerateKeySECP256K1Test) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
keygen_info->SetName("foo_4");
keygen_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
keygen_info->SetComment("hello gpgfrontend");
keygen_info->SetAlgo("secp256k1");
keygen_info->SetNonExpired(false);
keygen_info->SetNonPassPhrase(true);
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
p_info->SetName("foo_4");
p_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
p_info->SetComment("hello gpgfrontend");
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("secp256k1");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "secp256k1");
p_info->SetAlgo(algo);
p_info->SetNonExpired(false);
p_info->SetNonPassPhrase(true);
auto expire_time =
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
keygen_info->SetExpireTime(expire_time);
keygen_info->SetNonPassPhrase(false);
p_info->SetExpireTime(expire_time);
p_info->SetNonPassPhrase(false);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateKeySync(keygen_info);
.GenerateKeySync(p_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
@ -551,15 +629,15 @@ TEST_F(GpgCoreTest, GenerateKeySECP256K1Test) {
ASSERT_EQ(key.GetPrimaryKeyLength(), 256);
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
ASSERT_TRUE(key.IsHasCertificationCapability());
ASSERT_TRUE(key.IsHasAuthenticationCapability());
ASSERT_FALSE(key.IsHasEncryptionCapability());
ASSERT_TRUE(key.IsHasSigningCapability());
ASSERT_TRUE(key.IsHasCertCap());
ASSERT_TRUE(key.IsHasAuthCap());
ASSERT_FALSE(key.IsHasEncrCap());
ASSERT_TRUE(key.IsHasSignCap());
ASSERT_TRUE(key.IsHasActualCertificationCapability());
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
ASSERT_TRUE(key.IsHasActualSigningCapability());
ASSERT_TRUE(key.IsHasActualCertCap());
ASSERT_TRUE(key.IsHasActualAuthCap());
ASSERT_FALSE(key.IsHasActualEncrCap());
ASSERT_TRUE(key.IsHasActualSignCap());
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.DeleteKey(result.GetFingerprint());

View File

@ -29,27 +29,31 @@
#include "GpgCoreTest.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/model/GpgGenKeyInfo.h"
#include "core/model/GpgGenerateKeyResult.h"
#include "core/model/GpgKey.h"
#include "core/model/GpgKeyGenerateInfo.h"
#include "core/utils/GpgUtils.h"
#include "core/utils/MemoryUtils.h"
namespace GpgFrontend::Test {
TEST_F(GpgCoreTest, GenerateSubkeyRSA2048Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
auto p_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
ASSERT_TRUE(p_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("rsa");
subkeygen_info->SetKeyLength(2048);
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("rsa2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "rsa2048");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
s_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
.GenerateSubkeySync(p_key, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -70,25 +74,29 @@ TEST_F(GpgCoreTest, GenerateSubkeyRSA2048Test) {
ASSERT_EQ(subkey.GetKeyLength(), 2048);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_TRUE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_TRUE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_TRUE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_TRUE(subkey.IsHasSignCap());
}
TEST_F(GpgCoreTest, GenerateSubkeyDSA2048Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
auto p_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
ASSERT_TRUE(p_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("dsa");
subkeygen_info->SetKeyLength(2048);
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("dsa2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "dsa2048");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
s_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
.GenerateSubkeySync(p_key, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -109,25 +117,29 @@ TEST_F(GpgCoreTest, GenerateSubkeyDSA2048Test) {
ASSERT_EQ(subkey.GetKeyLength(), 2048);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_TRUE(subkey.IsHasAuthenticationCapability());
ASSERT_FALSE(subkey.IsHasEncryptionCapability());
ASSERT_TRUE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_TRUE(subkey.IsHasAuthCap());
ASSERT_FALSE(subkey.IsHasEncrCap());
ASSERT_TRUE(subkey.IsHasSignCap());
}
TEST_F(GpgCoreTest, GenerateSubkeyELG2048Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
auto p_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
ASSERT_TRUE(p_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("elg");
subkeygen_info->SetKeyLength(2048);
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("elg2048");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "elg2048");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
s_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
.GenerateSubkeySync(p_key, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -148,24 +160,29 @@ TEST_F(GpgCoreTest, GenerateSubkeyELG2048Test) {
ASSERT_EQ(subkey.GetKeyLength(), 2048);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_FALSE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_FALSE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_FALSE(subkey.IsHasSignCap());
}
TEST_F(GpgCoreTest, GenerateSubkeyED25519Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
auto p_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
ASSERT_TRUE(p_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("ed25519");
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("ed25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "ed25519");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
s_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
.GenerateSubkeySync(p_key, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -186,24 +203,29 @@ TEST_F(GpgCoreTest, GenerateSubkeyED25519Test) {
ASSERT_EQ(subkey.GetKeyLength(), 255);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_TRUE(subkey.IsHasAuthenticationCapability());
ASSERT_FALSE(subkey.IsHasEncryptionCapability());
ASSERT_TRUE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_TRUE(subkey.IsHasAuthCap());
ASSERT_FALSE(subkey.IsHasEncrCap());
ASSERT_TRUE(subkey.IsHasSignCap());
}
TEST_F(GpgCoreTest, GenerateSubkeyCV25519Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
auto p_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
ASSERT_TRUE(p_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("cv25519");
subkeygen_info->SetNonExpired(true);
subkeygen_info->SetNonPassPhrase(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("cv25519");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "cv25519");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
s_info->SetNonPassPhrase(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
.GenerateSubkeySync(p_key, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -224,23 +246,28 @@ TEST_F(GpgCoreTest, GenerateSubkeyCV25519Test) {
ASSERT_EQ(subkey.GetKeyLength(), 255);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_FALSE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_FALSE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_FALSE(subkey.IsHasSignCap());
}
TEST_F(GpgCoreTest, GenerateSubkeyNISTP256Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
auto p_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
ASSERT_TRUE(p_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("nistp256");
subkeygen_info->SetNonExpired(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("nistp256");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "nistp256");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
.GenerateSubkeySync(p_key, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -261,23 +288,28 @@ TEST_F(GpgCoreTest, GenerateSubkeyNISTP256Test) {
ASSERT_EQ(subkey.GetKeyLength(), 256);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_FALSE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_FALSE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_FALSE(subkey.IsHasSignCap());
}
TEST_F(GpgCoreTest, GenerateSubkeyBRAINPOOLP256R1Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
auto p_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
ASSERT_TRUE(p_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("brainpoolp256r1");
subkeygen_info->SetNonExpired(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("brainpoolp256r1");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "brainpoolp256r1");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
.GenerateSubkeySync(p_key, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -298,23 +330,28 @@ TEST_F(GpgCoreTest, GenerateSubkeyBRAINPOOLP256R1Test) {
ASSERT_EQ(subkey.GetKeyLength(), 256);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_FALSE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_FALSE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_FALSE(subkey.IsHasSignCap());
}
TEST_F(GpgCoreTest, GenerateSubkeyX448Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
auto p_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
ASSERT_TRUE(p_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("x448");
subkeygen_info->SetNonExpired(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("x448");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "x448");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
.GenerateSubkeySync(p_key, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -335,23 +372,28 @@ TEST_F(GpgCoreTest, GenerateSubkeyX448Test) {
ASSERT_EQ(subkey.GetKeyLength(), 448);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_FALSE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_FALSE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_FALSE(subkey.IsHasSignCap());
}
TEST_F(GpgCoreTest, GenerateSubkeySECP256K1Test) {
auto main_key = GpgKeyGetter::GetInstance().GetKey(
auto p_key = GpgKeyGetter::GetInstance().GetKey(
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
ASSERT_TRUE(main_key.IsGood());
ASSERT_TRUE(p_key.IsGood());
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
subkeygen_info->SetAlgo("secp256k1");
subkeygen_info->SetNonExpired(true);
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("secp256k1");
ASSERT_TRUE(found);
ASSERT_EQ(algo.Id(), "secp256k1");
s_info->SetAlgo(algo);
s_info->SetNonExpired(true);
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
.GenerateSubkeySync(main_key, subkeygen_info);
.GenerateSubkeySync(p_key, s_info);
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(data_object->GetObjectSize(), 1);
@ -372,10 +414,10 @@ TEST_F(GpgCoreTest, GenerateSubkeySECP256K1Test) {
ASSERT_EQ(subkey.GetKeyLength(), 256);
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
ASSERT_FALSE(subkey.IsHasCertificationCapability());
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
ASSERT_FALSE(subkey.IsHasSigningCapability());
ASSERT_FALSE(subkey.IsHasCertCap());
ASSERT_FALSE(subkey.IsHasAuthCap());
ASSERT_TRUE(subkey.IsHasEncrCap());
ASSERT_FALSE(subkey.IsHasSignCap());
}
} // namespace GpgFrontend::Test

View File

@ -38,6 +38,7 @@ aux_source_directory(dialog/import_export UI_SOURCE)
aux_source_directory(dialog/controller UI_SOURCE)
aux_source_directory(dialog UI_SOURCE)
aux_source_directory(function UI_SOURCE)
aux_source_directory(model UI_SOURCE)
# define libgpgfrontend_ui
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

View File

@ -127,7 +127,7 @@ void InitGpgFrontendUI(QApplication* /*app*/) {
// init locale
InitUITranslations();
auto settings = GlobalSettingStation::GetInstance().GetSettings();
auto settings = GetSettings();
auto theme = settings.value("appearance/theme").toString();
#if defined(_WIN32) || defined(WIN32)

View File

@ -75,7 +75,7 @@ class UISignalStation : public QObject {
* @brief
*
*/
void SignalMainWindowlUpdateBasicalOperaMenu(unsigned int);
void SignalMainWindowUpdateBasicOperaMenu(unsigned int);
/**
* @brief

View File

@ -51,23 +51,12 @@
#include "ui/dialog/controller/GnuPGControllerDialog.h"
#include "ui/dialog/import_export/KeyServerImportDialog.h"
#include "ui/struct/settings_object/KeyServerSO.h"
#include "ui/widgets/TextEdit.h"
namespace GpgFrontend::UI {
QScopedPointer<CommonUtils> CommonUtils::instance =
QScopedPointer<CommonUtils>(nullptr);
void show_verify_details(QWidget *parent, int channel,
InfoBoardWidget *info_board, GpgError error,
const GpgVerifyResult &verify_result) {
// take out result
info_board->ResetOptionActionsMenu();
info_board->AddOptionalAction(
QCoreApplication::tr("Show Verify Details"),
[=]() { VerifyDetailsDialog(parent, channel, error, verify_result); });
}
void ImportUnknownKeyFromKeyserver(
QWidget *parent, int channel, const GpgVerifyResultAnalyse &verify_result) {
QMessageBox::StandardButton reply;
@ -80,10 +69,10 @@ void ImportUnknownKeyFromKeyserver(
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
auto dialog = KeyServerImportDialog(channel, parent);
auto key_ids = std::make_unique<KeyIdArgsList>();
auto key_ids = KeyIdArgsList{};
auto *signature = verify_result.GetSignatures();
while (signature != nullptr) {
key_ids->push_back(signature->fpr);
key_ids.push_back(signature->fpr);
signature = signature->next;
}
dialog.show();
@ -91,35 +80,6 @@ void ImportUnknownKeyFromKeyserver(
}
}
void process_operation(QWidget *parent, const QString &waiting_title,
const Thread::Task::TaskRunnable func,
const Thread::Task::TaskCallback callback,
DataObjectPtr data_object) {
auto *dialog = new WaitingDialog(waiting_title, parent);
auto *process_task = new Thread::Task(std::move(func), waiting_title,
data_object, std::move(callback));
QApplication::connect(process_task, &Thread::Task::SignalTaskEnd, dialog,
&QDialog::close);
QApplication::connect(process_task, &Thread::Task::SignalTaskEnd, dialog,
&QDialog::deleteLater);
// a looper to wait for the operation
QEventLoop looper;
QApplication::connect(process_task, &Thread::Task::SignalTaskEnd, &looper,
&QEventLoop::quit);
// post process task to task runner
Thread::TaskRunnerGetter::GetInstance()
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_GPG)
->PostTask(process_task);
// block until task finished
// this is to keep reference vaild until task finished
looper.exec();
}
auto CommonUtils::GetInstance() -> CommonUtils * {
if (!instance) {
instance.reset(new CommonUtils());
@ -194,28 +154,6 @@ CommonUtils::CommonUtils() : QWidget(nullptr) {
});
}
void CommonUtils::WaitForOpera(QWidget *parent,
const QString &waiting_dialog_title,
const OperaWaitingCb &opera) {
QEventLoop looper;
QPointer<WaitingDialog> const dialog =
new WaitingDialog(waiting_dialog_title, parent);
connect(dialog, &QDialog::finished, &looper, &QEventLoop::quit);
connect(dialog, &QDialog::finished, dialog, &QDialog::deleteLater);
dialog->show();
QTimer::singleShot(64, parent, [=]() {
opera([dialog]() {
if (dialog != nullptr) {
dialog->close();
dialog->accept();
}
});
});
looper.exec();
}
void CommonUtils::RaiseMessageBox(QWidget *parent, GpgError err) {
GpgErrorDesc desc = DescribeGpgErrCode(err);
GpgErrorCode err_code = CheckGpgError2ErrCode(err);
@ -326,7 +264,7 @@ void CommonUtils::SlotExecuteGpgCommand(
const QStringList &arguments,
const std::function<void(QProcess *)> &interact_func) {
QEventLoop looper;
auto *dialog = new WaitingDialog(tr("Processing"), nullptr);
auto *dialog = new WaitingDialog(tr("Processing"), false);
dialog->show();
auto *gpg_process = new QProcess(&looper);
gpg_process->setProcessChannelMode(QProcess::MergedChannels);
@ -628,7 +566,7 @@ void CommonUtils::ImportKeyFromKeyServer(int channel,
}
void CommonUtils::ImportKeyByKeyServerSyncModule(QWidget *parent, int channel,
const QList<QString> &fprs) {
const QStringList &fprs) {
if (!Module::IsModuleActivate(kKeyServerSyncModuleID)) {
return;
}

Some files were not shown because too many files have changed in this diff Show More