Compare commits
49 Commits
8bcb25c0dd
...
d3d94f5b7a
Author | SHA1 | Date | |
---|---|---|---|
d3d94f5b7a | |||
e2fa8ababc | |||
7ac78d887e | |||
4606bb8aff | |||
5acc1fda6f | |||
4eb12e9f85 | |||
8dfd0c5a9b | |||
dd8bca46a6 | |||
39387a78e2 | |||
bec8f5e614 | |||
1e95a70ab3 | |||
cd4a1f749b | |||
d06c31abe7 | |||
e6b26c2fd5 | |||
9379d105cd | |||
0a8a116d2d | |||
dbd145b5b6 | |||
7505b1131e | |||
992e861a86 | |||
341065b307 | |||
a66d868f50 | |||
1b9715dd43 | |||
fb2e47db7b | |||
64311a8abf | |||
a0cafd633d | |||
e17837f898 | |||
a5ab3a611c | |||
5d2b02097e | |||
af1870fd42 | |||
bd0bfe63e7 | |||
2572aba1de | |||
3aa7e32214 | |||
731ec7339d | |||
8e7d3d6ac7 | |||
92e1ed7b3f | |||
73bb05c4d9 | |||
eb0218680d | |||
a81dc7a018 | |||
56140c6bdc | |||
3931b64fdd | |||
348102421a | |||
bdb1d7fc5a | |||
0330dda5f6 | |||
8ddcf78c10 | |||
78d76b4547 | |||
ba79d77f5f | |||
ee3491860f | |||
bd190d9b58 | |||
f7a00c58d2 |
2
.github/workflows/testing-nightly.yml
vendored
2
.github/workflows/testing-nightly.yml
vendored
@ -274,7 +274,7 @@ jobs:
|
|||||||
wget -c -nv https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage
|
wget -c -nv https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage
|
||||||
chmod u+x linuxdeployqt-continuous-x86_64.AppImage
|
chmod u+x linuxdeployqt-continuous-x86_64.AppImage
|
||||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
|
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 "BUILD_TYPE_LOWER=${BUILD_TYPE,,}" >> ${GITHUB_ENV}
|
||||||
echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> ${GITHUB_ENV}
|
echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> ${GITHUB_ENV}
|
||||||
if: runner.os == 'Linux'
|
if: runner.os == 'Linux'
|
||||||
|
@ -36,7 +36,7 @@ endif()
|
|||||||
|
|
||||||
# define project
|
# define project
|
||||||
project(GpgFrontend
|
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."
|
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"
|
HOMEPAGE_URL "https://gpgfrontend.bktus.com"
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
|
@ -108,6 +108,9 @@
|
|||||||
<file alias="export-email.png">resource/lfs/icons/export-email.png</file>
|
<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="warning-filling.png">resource/lfs/icons/warning-filling.png</file>
|
||||||
<file alias="upgrade.png">resource/lfs/icons/upgrade.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>
|
||||||
<qresource prefix="/test/key">
|
<qresource prefix="/test/key">
|
||||||
<file alias="pv1.key">resource/lfs/test/data/pv1.key</file>
|
<file alias="pv1.key">resource/lfs/test/data/pv1.key</file>
|
||||||
|
2
modules
2
modules
@ -1 +1 @@
|
|||||||
Subproject commit bbbbbf535f153c59bffa47b88c54e9f5107aa648
|
Subproject commit 22ba38aac5edbf85cc879fd611ef79b9f818544a
|
BIN
resource/lfs/icons/batch.png
Normal file
BIN
resource/lfs/icons/batch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
BIN
resource/lfs/icons/decr-verify.png
Normal file
BIN
resource/lfs/icons/decr-verify.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
BIN
resource/lfs/icons/encr-sign.png
Normal file
BIN
resource/lfs/icons/encr-sign.png
Normal file
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
@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "core/GpgConstants.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
struct GpgFrontendContext;
|
struct GpgFrontendContext;
|
||||||
@ -46,6 +48,8 @@ struct GpgFrontendContext {
|
|||||||
bool gather_external_gnupg_info;
|
bool gather_external_gnupg_info;
|
||||||
bool unit_test_mode;
|
bool unit_test_mode;
|
||||||
|
|
||||||
|
int rtn = GpgFrontend::kCrashCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Gpg Frontend Context object
|
* @brief Construct a new Gpg Frontend Context object
|
||||||
*
|
*
|
||||||
|
23
src/app.cpp
23
src/app.cpp
@ -28,8 +28,7 @@
|
|||||||
|
|
||||||
#include "GpgFrontendContext.h"
|
#include "GpgFrontendContext.h"
|
||||||
#include "core/GpgConstants.h"
|
#include "core/GpgConstants.h"
|
||||||
#include "core/GpgCoreInit.h"
|
#include "core/function/CacheManager.h"
|
||||||
#include "core/module/ModuleInit.h"
|
|
||||||
#include "ui/GpgFrontendUIInit.h"
|
#include "ui/GpgFrontendUIInit.h"
|
||||||
|
|
||||||
// main
|
// main
|
||||||
@ -37,8 +36,6 @@
|
|||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
constexpr int kCrashCode = ~0; ///<
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
@ -79,26 +76,18 @@ auto StartApplication(const GFCxtWPtr& p_ctx) -> int {
|
|||||||
// load module's translations
|
// load module's translations
|
||||||
GpgFrontend::UI::InitModulesTranslations();
|
GpgFrontend::UI::InitModulesTranslations();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// finally create main window
|
// finally create main window
|
||||||
return_from_event_loop_code = GpgFrontend::UI::RunGpgFrontendUI(app);
|
return_from_event_loop_code = GpgFrontend::UI::RunGpgFrontendUI(app);
|
||||||
|
|
||||||
} while (return_from_event_loop_code == GpgFrontend::kRestartCode &&
|
} while (return_from_event_loop_code == GpgFrontend::kRestartCode &&
|
||||||
restart_count++ < 99);
|
restart_count++ < 99);
|
||||||
|
|
||||||
// first should shutdown the module system
|
// clear cache of unsaved pages
|
||||||
GpgFrontend::Module::ShutdownGpgFrontendModules();
|
GpgFrontend::CacheManager::GetInstance().SaveDurableCache(
|
||||||
|
"editor_unsaved_pages", QJsonDocument(QJsonArray()), true);
|
||||||
|
|
||||||
// then shutdown the core
|
// set return code
|
||||||
GpgFrontend::DestroyGpgFrontendCore();
|
ctx->rtn = return_from_event_loop_code;
|
||||||
|
|
||||||
// deep restart mode
|
|
||||||
if (return_from_event_loop_code == GpgFrontend::kDeepRestartCode ||
|
|
||||||
return_from_event_loop_code == kCrashCode) {
|
|
||||||
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
|
|
||||||
};
|
|
||||||
|
|
||||||
// exit the program
|
// exit the program
|
||||||
return return_from_event_loop_code;
|
return return_from_event_loop_code;
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "core/module/ModuleManager.h"
|
#include "core/module/ModuleManager.h"
|
||||||
#include "core/thread/TaskRunnerGetter.h"
|
#include "core/thread/TaskRunnerGetter.h"
|
||||||
#include "core/utils/BuildInfoUtils.h"
|
#include "core/utils/BuildInfoUtils.h"
|
||||||
|
#include "core/utils/GpgUtils.h"
|
||||||
|
|
||||||
// GpgFrontend
|
// GpgFrontend
|
||||||
|
|
||||||
@ -160,7 +161,7 @@ auto PrintEnvInfo() -> int {
|
|||||||
stream << '\n';
|
stream << '\n';
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
auto key_dbs = GetKeyDatabaseInfoBySettings(default_database_path);
|
auto key_dbs = GetKeyDatabaseInfoBySettings();
|
||||||
for (const auto& key_database : key_dbs) {
|
for (const auto& key_database : key_dbs) {
|
||||||
stream << Tr("Key Database [") << index++ << "] " << Tr("Name: ")
|
stream << Tr("Key Database [") << index++ << "] " << Tr("Name: ")
|
||||||
<< key_database.name << " " << Tr("-> Path: ") << key_database.path
|
<< key_database.name << " " << Tr("-> Path: ") << key_database.path
|
||||||
@ -232,6 +233,7 @@ auto RunTest(const GFCxtWPtr& p_ctx) -> int {
|
|||||||
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Default)
|
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Default)
|
||||||
->PostTask(task);
|
->PostTask(task);
|
||||||
|
|
||||||
|
ctx->rtn = kNonRestartCode;
|
||||||
looper.exec();
|
looper.exec();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ namespace GpgFrontend {
|
|||||||
constexpr int kNonRestartCode = 0;
|
constexpr int kNonRestartCode = 0;
|
||||||
constexpr int kRestartCode = 1000; ///< only refresh ui
|
constexpr int kRestartCode = 1000; ///< only refresh ui
|
||||||
constexpr int kDeepRestartCode = 1001; // refresh core and ui
|
constexpr int kDeepRestartCode = 1001; // refresh core and ui
|
||||||
|
constexpr int kCrashCode = ~0; ///< application crash
|
||||||
|
|
||||||
// Channels
|
// Channels
|
||||||
constexpr int kGpgFrontendDefaultChannel = 0; ///<
|
constexpr int kGpgFrontendDefaultChannel = 0; ///<
|
||||||
|
@ -36,9 +36,7 @@
|
|||||||
#include "core/function/gpg/GpgAdvancedOperator.h"
|
#include "core/function/gpg/GpgAdvancedOperator.h"
|
||||||
#include "core/function/gpg/GpgContext.h"
|
#include "core/function/gpg/GpgContext.h"
|
||||||
#include "core/function/gpg/GpgKeyGetter.h"
|
#include "core/function/gpg/GpgKeyGetter.h"
|
||||||
#include "core/model/SettingsObject.h"
|
|
||||||
#include "core/module/ModuleManager.h"
|
#include "core/module/ModuleManager.h"
|
||||||
#include "core/struct/settings_object/KeyDatabaseListSO.h"
|
|
||||||
#include "core/thread/Task.h"
|
#include "core/thread/Task.h"
|
||||||
#include "core/thread/TaskRunnerGetter.h"
|
#include "core/thread/TaskRunnerGetter.h"
|
||||||
#include "core/utils/CommonUtils.h"
|
#include "core/utils/CommonUtils.h"
|
||||||
@ -47,19 +45,20 @@
|
|||||||
|
|
||||||
namespace GpgFrontend {
|
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 {
|
auto VerifyGpgconfPath(const QFileInfo& gnupg_install_fs_path) -> bool {
|
||||||
return gnupg_install_fs_path.isAbsolute() && gnupg_install_fs_path.exists() &&
|
return gnupg_install_fs_path.isAbsolute() && gnupg_install_fs_path.exists() &&
|
||||||
gnupg_install_fs_path.isFile();
|
gnupg_install_fs_path.isFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto VerifyKeyDatabasePath(const QFileInfo& key_database_fs_path) -> bool {
|
auto SearchGpgconfPath(const QStringList& candidate_paths) -> QString {
|
||||||
return key_database_fs_path.isAbsolute() && key_database_fs_path.exists() &&
|
|
||||||
key_database_fs_path.isDir();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto SearchGpgconfPath(const QList<QString>& candidate_paths) -> QString {
|
|
||||||
for (const auto& path : candidate_paths) {
|
for (const auto& path : candidate_paths) {
|
||||||
if (VerifyGpgconfPath(QFileInfo(path))) {
|
if (VerifyGpgconfPath(QFileInfo(path))) {
|
||||||
// return a unify path
|
// return a unify path
|
||||||
@ -69,33 +68,37 @@ auto SearchGpgconfPath(const QList<QString>& candidate_paths) -> QString {
|
|||||||
return {};
|
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 {
|
auto GetDefaultKeyDatabasePath(const QString& gpgconf_path) -> QString {
|
||||||
if (gpgconf_path.isEmpty()) return {};
|
QString default_db_path;
|
||||||
|
|
||||||
QFileInfo info(gpgconf_path);
|
// portable mode
|
||||||
if (!info.exists() || !info.isFile()) return {};
|
if (GlobalSettingStation::GetInstance().IsProtableMode()) {
|
||||||
|
default_db_path =
|
||||||
|
GlobalSettingStation::GetInstance().GetAppDataPath() + "/db";
|
||||||
|
} else {
|
||||||
|
if (gpgconf_path.isEmpty()) return {};
|
||||||
|
|
||||||
auto* p = new QProcess(QCoreApplication::instance());
|
QFileInfo info(gpgconf_path);
|
||||||
p->setProgram(info.absoluteFilePath());
|
if (!info.exists() || !info.isFile()) return {};
|
||||||
p->setArguments({"--list-dirs", "homedir"});
|
|
||||||
p->start();
|
|
||||||
|
|
||||||
p->waitForFinished();
|
auto* p = new QProcess(QCoreApplication::instance());
|
||||||
auto home_path = p->readAll().trimmed();
|
p->setProgram(info.absoluteFilePath());
|
||||||
p->deleteLater();
|
p->setArguments({"--list-dirs", "homedir"});
|
||||||
|
p->start();
|
||||||
|
|
||||||
QFileInfo home_info(home_path);
|
p->waitForFinished();
|
||||||
return home_info.absoluteFilePath();
|
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 {
|
auto InitGpgME() -> bool {
|
||||||
@ -270,43 +273,56 @@ auto RefreshGpgMEBackendEngine(const QString& gpgconf_path,
|
|||||||
return true;
|
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());
|
auto* process = new QProcess(QCoreApplication::instance());
|
||||||
process->setProgram(gpgconf_install_fs_path);
|
process->setProgram(gpgconf_install_fs_path);
|
||||||
|
process->setArguments({"--check-programs"});
|
||||||
process->start();
|
process->start();
|
||||||
process->waitForFinished(1000);
|
process->waitForFinished(30000);
|
||||||
|
|
||||||
auto output_buffer = process->readAllStandardOutput();
|
auto output_buffer = process->readAllStandardOutput();
|
||||||
process->deleteLater();
|
process->deleteLater();
|
||||||
|
|
||||||
if (output_buffer.isEmpty()) return {};
|
if (output_buffer.isEmpty()) return false;
|
||||||
|
|
||||||
auto line_split_list = QString(output_buffer).split("\n");
|
auto line_split_list = QString(output_buffer).split("\n");
|
||||||
for (const auto& line : line_split_list) {
|
for (const auto& line : line_split_list) {
|
||||||
auto info_split_list = line.split(":");
|
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_desc = info_split_list[1].trimmed();
|
||||||
auto component_path = info_split_list[2].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)
|
#if defined(_WIN32) || defined(WIN32)
|
||||||
// replace some special substrings on windows platform
|
// replace some special substrings on windows platform
|
||||||
component_path.replace("%3a", ":");
|
component_path.replace("%3a", ":");
|
||||||
#endif
|
#endif
|
||||||
QFileInfo file_info(component_path);
|
|
||||||
if (file_info.exists() && file_info.isFile()) {
|
if (exists != "1" || runnable != "1") continue;
|
||||||
return file_info.absoluteFilePath();
|
|
||||||
}
|
QFileInfo file_info(component_path);
|
||||||
return {};
|
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 DecideGpgConfPath(const QString& default_gpgconf_path) -> QString {
|
||||||
auto settings = GlobalSettingStation::GetInstance().GetSettings();
|
auto settings = GetSettings();
|
||||||
auto use_custom_gnupg_install_path =
|
auto use_custom_gnupg_install_path =
|
||||||
settings.value("gnupg/use_custom_gnupg_install_path", false).toBool();
|
settings.value("gnupg/use_custom_gnupg_install_path", false).toBool();
|
||||||
auto custom_gnupg_install_path =
|
auto custom_gnupg_install_path =
|
||||||
@ -359,8 +375,15 @@ auto DecideGpgConfPath(const QString& default_gpgconf_path) -> QString {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto DecideGnuPGPath(const QString& gpgconf_path) -> QString {
|
auto DecideGnuPGPath(const QString& default_gnupg_path) -> QString {
|
||||||
return GetGnuPGPathByGpgConf(gpgconf_path);
|
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 {
|
auto InitBasicPath() -> bool {
|
||||||
@ -374,12 +397,23 @@ auto InitBasicPath() -> bool {
|
|||||||
LOG_I() << "default gnupg path found by gpgme: " << default_gnupg_path;
|
LOG_I() << "default gnupg path found by gpgme: " << default_gnupg_path;
|
||||||
|
|
||||||
auto target_gpgconf_path = DecideGpgConfPath(default_gpgconf_path);
|
auto target_gpgconf_path = DecideGpgConfPath(default_gpgconf_path);
|
||||||
auto target_gnupg_path = default_gnupg_path;
|
|
||||||
if (target_gpgconf_path != default_gpgconf_path) {
|
if (!GetComponentPathsByGpgConf(default_gpgconf_path)) {
|
||||||
target_gnupg_path = DecideGnuPGPath(target_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() << "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()) {
|
if (target_gpgconf_path.isEmpty()) {
|
||||||
LOG_E() << "Cannot find gpgconf!"
|
LOG_E() << "Cannot find gpgconf!"
|
||||||
@ -408,10 +442,12 @@ auto InitBasicPath() -> bool {
|
|||||||
LOG_E() << "Cannot find default home path by gpgconf!"
|
LOG_E() << "Cannot find default home path by gpgconf!"
|
||||||
<< "GpgFrontend cannot start under this situation!";
|
<< "GpgFrontend cannot start under this situation!";
|
||||||
CoreSignalStation::GetInstance()->SignalBadGnupgEnv(
|
CoreSignalStation::GetInstance()->SignalBadGnupgEnv(
|
||||||
QCoreApplication::tr("Cannot Find Home Path"));
|
QCoreApplication::tr("Cannot Find Default Home Path"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!QDir(default_home_path).exists()) QDir(default_home_path).mkpath(".");
|
||||||
|
|
||||||
RefreshGpgMEBackendEngine(target_gpgconf_path, target_gnupg_path,
|
RefreshGpgMEBackendEngine(target_gpgconf_path, target_gnupg_path,
|
||||||
default_home_path);
|
default_home_path);
|
||||||
|
|
||||||
@ -425,45 +461,6 @@ auto InitBasicPath() -> bool {
|
|||||||
return true;
|
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 {
|
auto InitGpgFrontendCore(CoreInitArgs args) -> int {
|
||||||
// initialize gpgme
|
// initialize gpgme
|
||||||
if (!InitGpgME()) {
|
if (!InitGpgME()) {
|
||||||
@ -491,7 +488,7 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
|
|||||||
auto default_home_path = Module::RetrieveRTValueTypedOrDefault<>(
|
auto default_home_path = Module::RetrieveRTValueTypedOrDefault<>(
|
||||||
"core", "gpgme.ctx.default_database_path", QString{});
|
"core", "gpgme.ctx.default_database_path", QString{});
|
||||||
|
|
||||||
auto settings = GlobalSettingStation::GetInstance().GetSettings();
|
auto settings = GetSettings();
|
||||||
|
|
||||||
// read settings from config file
|
// read settings from config file
|
||||||
auto forbid_all_gnupg_connection =
|
auto forbid_all_gnupg_connection =
|
||||||
@ -519,16 +516,16 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto key_dbs = GetKeyDatabaseInfoBySettings();
|
||||||
|
|
||||||
// load default context
|
// load default context
|
||||||
auto& default_ctx = GpgFrontend::GpgContext::CreateInstance(
|
auto& default_ctx = GpgFrontend::GpgContext::CreateInstance(
|
||||||
kGpgFrontendDefaultChannel, [=]() -> ChannelObjectPtr {
|
kGpgFrontendDefaultChannel, [=]() -> ChannelObjectPtr {
|
||||||
GpgFrontend::GpgContextInitArgs args;
|
GpgFrontend::GpgContextInitArgs args;
|
||||||
|
|
||||||
// set key database path
|
const auto& default_key_db_info = key_dbs.front();
|
||||||
if (!default_home_path.isEmpty()) {
|
args.db_name = default_key_db_info.name;
|
||||||
args.db_name = "DEFAULT";
|
args.db_path = default_key_db_info.path;
|
||||||
args.db_path = default_home_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
args.offline_mode = forbid_all_gnupg_connection;
|
args.offline_mode = forbid_all_gnupg_connection;
|
||||||
args.auto_import_missing_key = auto_import_missing_key;
|
args.auto_import_missing_key = auto_import_missing_key;
|
||||||
@ -564,30 +561,12 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
|
|||||||
CoreSignalStation::GetInstance()->SignalGoodGnupgEnv();
|
CoreSignalStation::GetInstance()->SignalGoodGnupgEnv();
|
||||||
LOG_I() << "Basic ENV Checking Finished";
|
LOG_I() << "Basic ENV Checking Finished";
|
||||||
|
|
||||||
auto key_dbs = GetKeyDatabasesBySettings(default_home_path);
|
|
||||||
|
|
||||||
auto* task = new Thread::Task(
|
auto* task = new Thread::Task(
|
||||||
[=](const DataObjectPtr&) -> int {
|
[=](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;
|
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
|
// init ctx, also checking the basic env
|
||||||
auto& ctx = GpgFrontend::GpgContext::CreateInstance(
|
auto& ctx = GpgFrontend::GpgContext::CreateInstance(
|
||||||
channel_index, [=]() -> ChannelObjectPtr {
|
channel_index, [=]() -> ChannelObjectPtr {
|
||||||
@ -616,7 +595,7 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GpgKeyGetter::GetInstance(ctx.GetChannel()).FetchKey()) {
|
if (!GpgKeyGetter::GetInstance(ctx.GetChannel()).FlushKeyCache()) {
|
||||||
FLOG_E() << "gpgme context init key cache failed, index:"
|
FLOG_E() << "gpgme context init key cache failed, index:"
|
||||||
<< channel_index;
|
<< channel_index;
|
||||||
continue;
|
continue;
|
||||||
@ -642,7 +621,7 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
|
|||||||
->PostTask(task);
|
->PostTask(task);
|
||||||
|
|
||||||
if (!args.unit_test_mode && restart_all_gnupg_components_on_start) {
|
if (!args.unit_test_mode && restart_all_gnupg_components_on_start) {
|
||||||
GpgAdvancedOperator::RestartGpgComponents();
|
GpgAdvancedOperator::RestartGpgComponents(nullptr);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -658,7 +637,7 @@ void StartMonitorCoreInitializationStatus() {
|
|||||||
"core", "env.state.basic", 0);
|
"core", "env.state.basic", 0);
|
||||||
|
|
||||||
LOG_D() << "monitor: core env is still initializing, waiting...";
|
LOG_D() << "monitor: core env is still initializing, waiting...";
|
||||||
QThread::msleep(15);
|
QThread::msleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core_init_state < 0) return -1;
|
if (core_init_state < 0) return -1;
|
||||||
|
@ -72,12 +72,4 @@ auto GPGFRONTEND_CORE_EXPORT InitGpgME() -> bool;
|
|||||||
*/
|
*/
|
||||||
auto GPGFRONTEND_CORE_EXPORT InitBasicPath() -> 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
|
} // namespace GpgFrontend
|
||||||
|
@ -85,7 +85,7 @@ auto ArchiveCloseWriteCallback(struct archive *, void *client_data) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ArchiveFileOperator::NewArchive2DataExchanger(
|
void ArchiveFileOperator::NewArchive2DataExchanger(
|
||||||
const QString &target_directory, std::shared_ptr<GFDataExchanger> exchanger,
|
const QString &target_directory, QSharedPointer<GFDataExchanger> exchanger,
|
||||||
const OperationCallback &cb) {
|
const OperationCallback &cb) {
|
||||||
RunIOOperaAsync(
|
RunIOOperaAsync(
|
||||||
[=](const DataObjectPtr &data_object) -> GFError {
|
[=](const DataObjectPtr &data_object) -> GFError {
|
||||||
@ -194,7 +194,7 @@ void ArchiveFileOperator::NewArchive2DataExchanger(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ArchiveFileOperator::ExtractArchiveFromDataExchanger(
|
void ArchiveFileOperator::ExtractArchiveFromDataExchanger(
|
||||||
std::shared_ptr<GFDataExchanger> ex, const QString &target_path,
|
QSharedPointer<GFDataExchanger> ex, const QString &target_path,
|
||||||
const OperationCallback &cb) {
|
const OperationCallback &cb) {
|
||||||
RunIOOperaAsync(
|
RunIOOperaAsync(
|
||||||
[=](const DataObjectPtr &data_object) -> GFError {
|
[=](const DataObjectPtr &data_object) -> GFError {
|
||||||
|
@ -53,7 +53,7 @@ class GPGFRONTEND_CORE_EXPORT ArchiveFileOperator {
|
|||||||
* @param files
|
* @param files
|
||||||
*/
|
*/
|
||||||
static void NewArchive2DataExchanger(const QString &target_directory,
|
static void NewArchive2DataExchanger(const QString &target_directory,
|
||||||
std::shared_ptr<GFDataExchanger>,
|
QSharedPointer<GFDataExchanger>,
|
||||||
const OperationCallback &cb);
|
const OperationCallback &cb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,7 +63,7 @@ class GPGFRONTEND_CORE_EXPORT ArchiveFileOperator {
|
|||||||
* @param base_path
|
* @param base_path
|
||||||
*/
|
*/
|
||||||
static void ExtractArchiveFromDataExchanger(
|
static void ExtractArchiveFromDataExchanger(
|
||||||
std::shared_ptr<GFDataExchanger> fd, const QString &target_path,
|
QSharedPointer<GFDataExchanger> fd, const QString &target_path,
|
||||||
const OperationCallback &cb);
|
const OperationCallback &cb);
|
||||||
};
|
};
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -48,7 +48,7 @@ class GlobalSettingStation::Impl {
|
|||||||
Module::UpsertRTValue("core", "env.state.portable", 1);
|
Module::UpsertRTValue("core", "env.state.portable", 1);
|
||||||
LOG_I() << "GpgFrontend runs in the portable mode now";
|
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";
|
app_config_path_ = app_data_path_ + "/config";
|
||||||
|
|
||||||
portable_mode_ = true;
|
portable_mode_ = true;
|
||||||
@ -61,6 +61,11 @@ class GlobalSettingStation::Impl {
|
|||||||
#if defined(_WIN32) || defined(WIN32)
|
#if defined(_WIN32) || defined(WIN32)
|
||||||
LOG_I() << "app config path: " << app_config_path_;
|
LOG_I() << "app config path: " << app_config_path_;
|
||||||
if (!QDir(app_config_path_).exists()) QDir(app_config_path_).mkpath(".");
|
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
|
#endif
|
||||||
|
|
||||||
if (!QDir(app_data_path_).exists()) QDir(app_data_path_).mkpath(".");
|
if (!QDir(app_data_path_).exists()) QDir(app_data_path_).mkpath(".");
|
||||||
@ -74,6 +79,7 @@ class GlobalSettingStation::Impl {
|
|||||||
#if defined(_WIN32) || defined(WIN32)
|
#if defined(_WIN32) || defined(WIN32)
|
||||||
return QSettings(app_config_file_path(), QSettings::IniFormat);
|
return QSettings(app_config_file_path(), QSettings::IniFormat);
|
||||||
#else
|
#else
|
||||||
|
if (IsProtableMode()) return {app_config_file_path(), QSettings::IniFormat};
|
||||||
return QSettings();
|
return QSettings();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -171,6 +177,8 @@ class GlobalSettingStation::Impl {
|
|||||||
return exec_binary_path + "/modules";
|
return exec_binary_path + "/modules";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto IsProtableMode() const -> bool { return portable_mode_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] auto app_config_file_path() const -> QString {
|
[[nodiscard]] auto app_config_file_path() const -> QString {
|
||||||
return app_config_path_ + "/config.ini";
|
return app_config_path_ + "/config.ini";
|
||||||
@ -244,4 +252,11 @@ auto GlobalSettingStation::GetConfigPath() const -> QString {
|
|||||||
auto GlobalSettingStation::GetIntegratedModulePath() const -> QString {
|
auto GlobalSettingStation::GetIntegratedModulePath() const -> QString {
|
||||||
return p_->GetIntegratedModulePath();
|
return p_->GetIntegratedModulePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto GlobalSettingStation::IsProtableMode() const -> bool {
|
||||||
|
return p_->IsProtableMode();
|
||||||
|
}
|
||||||
|
auto GetSettings() -> QSettings {
|
||||||
|
return GlobalSettingStation::GetInstance().GetSettings();
|
||||||
|
}
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
@ -131,8 +131,19 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] auto GetIntegratedModulePath() const -> QString;
|
[[nodiscard]] auto GetIntegratedModulePath() const -> QString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return true
|
||||||
|
* @return false
|
||||||
|
*/
|
||||||
|
[[nodiscard]] auto IsProtableMode() const -> bool;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Impl;
|
class Impl;
|
||||||
SecureUniquePtr<Impl> p_;
|
SecureUniquePtr<Impl> p_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto GPGFRONTEND_CORE_EXPORT GetSettings() -> QSettings;
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -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)
|
return SingletonStorageCollection::GetInstance(false)
|
||||||
->GetSingletonStorage(typeid(T))
|
->GetSingletonStorage(typeid(T))
|
||||||
->GetAllChannelId();
|
->GetAllChannelId();
|
||||||
|
@ -31,7 +31,8 @@
|
|||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
|
||||||
#include "core/function/basic/ChannelObject.h"
|
#include "core/function/basic/ChannelObject.h"
|
||||||
#include "utils/MemoryUtils.h"
|
#include "core/typedef/CoreTypedef.h"
|
||||||
|
#include "core/utils/MemoryUtils.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
@ -60,8 +61,8 @@ class SingletonStorage::Impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GetAllChannelId() -> std::vector<int> {
|
auto GetAllChannelId() -> QContainer<int> {
|
||||||
std::vector<int> channels;
|
QContainer<int> channels;
|
||||||
channels.reserve(instances_map_.size());
|
channels.reserve(instances_map_.size());
|
||||||
for (const auto& [key, value] : instances_map_) {
|
for (const auto& [key, value] : instances_map_) {
|
||||||
channels.push_back(key);
|
channels.push_back(key);
|
||||||
@ -119,7 +120,7 @@ auto SingletonStorage::FindObjectInChannel(int channel)
|
|||||||
return p_->FindObjectInChannel(channel);
|
return p_->FindObjectInChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto SingletonStorage::GetAllChannelId() -> std::vector<int> {
|
auto SingletonStorage::GetAllChannelId() -> QContainer<int> {
|
||||||
return p_->GetAllChannelId();
|
return p_->GetAllChannelId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/function/SecureMemoryAllocator.h"
|
#include "core/function/SecureMemoryAllocator.h"
|
||||||
|
#include "core/typedef/GpgTypedef.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
@ -66,11 +67,11 @@ class GPGFRONTEND_CORE_EXPORT SingletonStorage {
|
|||||||
auto FindObjectInChannel(int channel) -> ChannelObject*;
|
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
|
* @brief Set a new object in channel object
|
||||||
|
@ -32,211 +32,89 @@
|
|||||||
|
|
||||||
#include "GpgAdvancedOperator.h"
|
#include "GpgAdvancedOperator.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "core/function/gpg/GpgCommandExecutor.h"
|
#include "core/function/gpg/GpgCommandExecutor.h"
|
||||||
#include "core/module/ModuleManager.h"
|
#include "core/module/ModuleManager.h"
|
||||||
|
#include "core/utils/GpgUtils.h"
|
||||||
|
|
||||||
void GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache(
|
namespace GpgFrontend {
|
||||||
OperationCallback cb) {
|
|
||||||
|
void ExecuteGpgCommand(const QString &operation, const QStringList &extra_args,
|
||||||
|
OperationCallback cb) {
|
||||||
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
|
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
|
||||||
"core", "gpgme.ctx.gpgconf_path", QString{});
|
"core", "gpgme.ctx.gpgconf_path", QString{});
|
||||||
|
|
||||||
if (gpgconf_path.isEmpty()) {
|
if (gpgconf_path.isEmpty()) {
|
||||||
FLOG_W("cannot get valid gpgconf path from rt, abort.");
|
FLOG_W("cannot get valid gpgconf path from rt, abort.");
|
||||||
cb(-1, TransferParams());
|
if (cb) cb(-1, TransferParams());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
auto key_dbs = GetGpgKeyDatabaseInfos();
|
||||||
FLOG_I("kill all gpg components in order to clear gpg password cache");
|
auto total_tasks = static_cast<int>(key_dbs.size());
|
||||||
KillAllGpgComponents();
|
std::atomic<int> completed_tasks{0};
|
||||||
#else
|
std::vector<int> results(total_tasks, 0);
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
void GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents(
|
int task_index = 0;
|
||||||
OperationCallback cb) {
|
for (const auto &key_db : key_dbs) {
|
||||||
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
|
const int current_index = task_index++;
|
||||||
"core", "gpgme.ctx.gpgconf_path", QString{});
|
const auto target_home_dir =
|
||||||
|
QDir::toNativeSeparators(QFileInfo(key_db.path).canonicalFilePath());
|
||||||
|
|
||||||
if (gpgconf_path.isEmpty()) {
|
QStringList arguments = QStringList{"--homedir", target_home_dir};
|
||||||
FLOG_W("cannot get valid gpgconf path from rt, abort.");
|
arguments.append(extra_args);
|
||||||
cb(-1, TransferParams());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GpgFrontend::GpgCommandExecutor::ExecuteSync(
|
GpgCommandExecutor::ExecuteSync(
|
||||||
{gpgconf_path, QStringList{"--reload"},
|
{gpgconf_path, arguments,
|
||||||
[=](int exit_code, const QString &, const QString &) {
|
[=, &completed_tasks, &results](int exit_code, const QString &,
|
||||||
FLOG_D("gpgconf reload exit code: %d", exit_code);
|
const QString &) {
|
||||||
cb(exit_code == 0 ? 0 : -1, TransferParams());
|
FLOG_D("%s exit code: %d", qPrintable(operation), exit_code);
|
||||||
}});
|
|
||||||
}
|
|
||||||
|
|
||||||
void GpgFrontend::GpgAdvancedOperator::KillAllGpgComponents() {
|
results[current_index] = exit_code;
|
||||||
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
|
|
||||||
"core", "gpgme.ctx.gpgconf_path", QString{});
|
|
||||||
|
|
||||||
if (gpgconf_path.isEmpty()) {
|
if (++completed_tasks == total_tasks && cb) {
|
||||||
FLOG_W("cannot get valid gpgconf path from rt, abort.");
|
int final_result =
|
||||||
return;
|
std::all_of(results.begin(), results.end(),
|
||||||
}
|
[](int result) { return result >= 0; })
|
||||||
|
? 0
|
||||||
GpgFrontend::GpgCommandExecutor::ExecuteSync(
|
: -1;
|
||||||
{gpgconf_path, QStringList{"--verbose", "--kill", "all"},
|
cb(final_result, TransferParams());
|
||||||
[=](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;
|
|
||||||
}
|
}
|
||||||
});
|
}});
|
||||||
#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<>(
|
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
|
||||||
"core", "gpgme.ctx.gpgconf_path", QString{});
|
"core", "gpgme.ctx.gpgconf_path", QString{});
|
||||||
|
ExecuteGpgCommand("Reload GPG Components", {"--reload", "all"},
|
||||||
if (gpgconf_path.isEmpty()) {
|
std::move(cb));
|
||||||
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());
|
|
||||||
}});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpgFrontend::GpgAdvancedOperator::StartGpgAgent(OperationCallback cb) {
|
void GpgAdvancedOperator::KillAllGpgComponents(OperationCallback cb) {
|
||||||
if (!Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) {
|
ExecuteGpgCommand("Kill All GPG Components", {"--kill", "all"},
|
||||||
cb(-1, TransferParams());
|
std::move(cb));
|
||||||
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 GpgFrontend::GpgAdvancedOperator::StartDirmngr(OperationCallback cb) {
|
void GpgAdvancedOperator::ResetConfigures(OperationCallback cb) {
|
||||||
if (!Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) {
|
ExecuteGpgCommand("Reset Gnupg Configures", {"--apply-defaults"},
|
||||||
cb(-1, TransferParams());
|
std::move(cb));
|
||||||
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 GpgFrontend::GpgAdvancedOperator::StartKeyBoxd(OperationCallback cb) {
|
void GpgAdvancedOperator::LaunchGpgComponents(OperationCallback cb) {
|
||||||
if (!Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) {
|
ExecuteGpgCommand("Launch All GPG Components", {"--launch", "all"},
|
||||||
cb(-1, TransferParams());
|
std::move(cb));
|
||||||
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::RestartGpgComponents(OperationCallback cb) {
|
||||||
|
KillAllGpgComponents(nullptr);
|
||||||
|
LaunchGpgComponents(std::move(cb));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace GpgFrontend
|
@ -60,7 +60,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
static void RestartGpgComponents();
|
static void RestartGpgComponents(OperationCallback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -76,29 +76,13 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
static void StartGpgAgent(OperationCallback);
|
static void LaunchGpgComponents(OperationCallback);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
|
||||||
static void StartDirmngr(OperationCallback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @return true
|
|
||||||
* @return false
|
|
||||||
*/
|
|
||||||
static void StartKeyBoxd(OperationCallback);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void KillAllGpgComponents();
|
static void KillAllGpgComponents(OperationCallback);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -43,29 +43,49 @@ namespace GpgFrontend {
|
|||||||
GpgBasicOperator::GpgBasicOperator(int channel)
|
GpgBasicOperator::GpgBasicOperator(int channel)
|
||||||
: SingletonFunctionObject<GpgBasicOperator>(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,
|
void GpgBasicOperator::Encrypt(const KeyArgsList& keys,
|
||||||
const GFBuffer& in_buffer, bool ascii,
|
const GFBuffer& in_buffer, bool ascii,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
if (keys.empty()) return GPG_ERR_CANCELED;
|
return EncryptImpl(ctx_, keys, in_buffer, ascii, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_encrypt", "2.1.0");
|
cb, "gpgme_op_encrypt", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -74,25 +94,8 @@ auto GpgBasicOperator::EncryptSync(const KeyArgsList& keys,
|
|||||||
const GFBuffer& in_buffer, bool ascii)
|
const GFBuffer& in_buffer, bool ascii)
|
||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
if (keys.empty()) return GPG_ERR_CANCELED;
|
return EncryptImpl(ctx_, keys, in_buffer, ascii, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_encrypt", "2.1.0");
|
"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,
|
void GpgBasicOperator::EncryptSymmetric(const GFBuffer& in_buffer, bool ascii,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgData data_in(in_buffer);
|
return EncryptImpl(ctx_, {}, in_buffer, ascii, data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_encrypt_symmetric", "2.1.0");
|
cb, "gpgme_op_encrypt_symmetric", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -119,35 +113,32 @@ auto GpgBasicOperator::EncryptSymmetricSync(const GFBuffer& in_buffer,
|
|||||||
bool ascii)
|
bool ascii)
|
||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgData data_in(in_buffer);
|
return EncryptImpl(ctx_, {}, in_buffer, ascii, data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_encrypt_symmetric", "2.1.0");
|
"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,
|
void GpgBasicOperator::Decrypt(const GFBuffer& in_buffer,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgData data_in(in_buffer);
|
return DecryptImpl(ctx_, in_buffer, data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_decrypt", "2.1.0");
|
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)
|
auto GpgBasicOperator::DecryptSync(const GFBuffer& in_buffer)
|
||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgData data_in(in_buffer);
|
return DecryptImpl(ctx_, in_buffer, data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_decrypt", "2.1.0");
|
"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,
|
void GpgBasicOperator::Verify(const GFBuffer& in_buffer,
|
||||||
const GFBuffer& sig_buffer,
|
const GFBuffer& sig_buffer,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgError err;
|
return VerifyImpl(ctx_, in_buffer, sig_buffer, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_verify", "2.1.0");
|
cb, "gpgme_op_verify", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -202,51 +191,41 @@ auto GpgBasicOperator::VerifySync(const GFBuffer& in_buffer,
|
|||||||
const GFBuffer& sig_buffer)
|
const GFBuffer& sig_buffer)
|
||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgError err;
|
return VerifyImpl(ctx_, in_buffer, sig_buffer, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_verify", "2.1.0");
|
"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,
|
void GpgBasicOperator::Sign(const KeyArgsList& signers,
|
||||||
const GFBuffer& in_buffer, GpgSignMode mode,
|
const GFBuffer& in_buffer, GpgSignMode mode,
|
||||||
bool ascii, const GpgOperationCallback& cb) {
|
bool ascii, const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
if (signers.empty()) return GPG_ERR_CANCELED;
|
return SignImpl(ctx_, signers, in_buffer, mode, ascii, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_sign", "2.1.0");
|
cb, "gpgme_op_sign", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -255,45 +234,36 @@ auto GpgBasicOperator::SignSync(
|
|||||||
const KeyArgsList& signers, const GFBuffer& in_buffer, GpgSignMode mode,
|
const KeyArgsList& signers, const GFBuffer& in_buffer, GpgSignMode mode,
|
||||||
bool ascii) -> std::tuple<GpgError, DataObjectPtr> {
|
bool ascii) -> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
if (signers.empty()) return GPG_ERR_CANCELED;
|
return SignImpl(ctx_, signers, in_buffer, mode, ascii, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_sign", "2.1.0");
|
"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,
|
void GpgBasicOperator::DecryptVerify(const GFBuffer& in_buffer,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgError err;
|
return DecryptVerifyImpl(ctx_, in_buffer, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_decrypt_verify", "2.1.0");
|
cb, "gpgme_op_decrypt_verify", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -302,52 +272,47 @@ auto GpgBasicOperator::DecryptVerifySync(const GFBuffer& in_buffer)
|
|||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgError err;
|
return DecryptVerifyImpl(ctx_, in_buffer, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_decrypt_verify", "2.1.0");
|
"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,
|
void GpgBasicOperator::EncryptSign(const KeyArgsList& keys,
|
||||||
const KeyArgsList& signers,
|
const KeyArgsList& signers,
|
||||||
const GFBuffer& in_buffer, bool ascii,
|
const GFBuffer& in_buffer, bool ascii,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
if (keys.empty() || signers.empty()) return GPG_ERR_CANCELED;
|
return EncryptSignImpl(ctx_, keys, signers, in_buffer, ascii,
|
||||||
|
data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_encrypt_sign", "2.1.0");
|
cb, "gpgme_op_encrypt_sign", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -358,57 +323,24 @@ auto GpgBasicOperator::EncryptSignSync(const KeyArgsList& keys,
|
|||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
if (keys.empty() || signers.empty()) return GPG_ERR_CANCELED;
|
return EncryptSignImpl(ctx_, keys, signers, in_buffer, ascii,
|
||||||
|
data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_encrypt_sign", "2.1.0");
|
"gpgme_op_encrypt_sign", "2.1.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpgBasicOperator::SetSigners(const KeyArgsList& signers, bool ascii) {
|
void GpgBasicOperator::SetSigners(const KeyArgsList& signers, bool ascii) {
|
||||||
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
|
SetSignersImpl(ctx_, signers, ascii);
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgBasicOperator::GetSigners(bool ascii) -> std::unique_ptr<KeyArgsList> {
|
auto GpgBasicOperator::GetSigners(bool ascii) -> KeyArgsList {
|
||||||
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
|
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
|
||||||
|
|
||||||
auto count = gpgme_signers_count(ctx);
|
auto count = gpgme_signers_count(ctx);
|
||||||
auto signers = std::make_unique<std::vector<GpgKey>>();
|
auto signers = KeyArgsList{};
|
||||||
for (auto i = 0U; i < count; i++) {
|
for (auto i = 0U; i < count; i++) {
|
||||||
auto key = GpgKey(gpgme_signers_enum(ctx, 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;
|
return signers;
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ class GPGFRONTEND_CORE_EXPORT GpgBasicOperator
|
|||||||
*
|
*
|
||||||
* @return Intelligent pointer pointing to the private key list
|
* @return Intelligent pointer pointing to the private key list
|
||||||
*/
|
*/
|
||||||
auto GetSigners(bool ascii) -> std::unique_ptr<KeyArgsList>;
|
auto GetSigners(bool ascii) -> KeyArgsList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GpgContext& ctx_ = GpgContext::GetInstance(
|
GpgContext& ctx_ = GpgContext::GetInstance(
|
||||||
|
@ -45,8 +45,8 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context)
|
|||||||
|
|
||||||
Thread::Task::TaskCallback result_callback =
|
Thread::Task::TaskCallback result_callback =
|
||||||
[cmd](int /*rtn*/, const DataObjectPtr &data_object) {
|
[cmd](int /*rtn*/, const DataObjectPtr &data_object) {
|
||||||
FLOG_D("data object args count of cmd executor result callback: %ld",
|
LOG_D() << "data object args count of cmd executor result callback:"
|
||||||
data_object->GetObjectSize());
|
<< data_object->GetObjectSize();
|
||||||
|
|
||||||
if (!data_object->Check<int, QString, GpgCommandExecutorCallback>()) {
|
if (!data_object->Check<int, QString, GpgCommandExecutorCallback>()) {
|
||||||
FLOG_W("data object checking failed");
|
FLOG_W("data object checking failed");
|
||||||
|
@ -40,88 +40,19 @@
|
|||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
constexpr ssize_t kDataExchangerSize = 8192;
|
auto ExtractArchiveHelper(const QString& out_path)
|
||||||
|
-> QSharedPointer<GFDataExchanger> {
|
||||||
GpgFileOpera::GpgFileOpera(int channel)
|
auto ex = CreateStandardGFDataExchanger();
|
||||||
: SingletonFunctionObject<GpgFileOpera>(channel) {}
|
ArchiveFileOperator::ExtractArchiveFromDataExchanger(
|
||||||
|
ex, out_path, [](GFError err, const DataObjectPtr&) {
|
||||||
void GpgFileOpera::EncryptFile(const KeyArgsList& keys, const QString& in_path,
|
FLOG_D("extract archive from data exchanger operation, err: %d", err);
|
||||||
bool ascii, const QString& out_path,
|
});
|
||||||
const GpgOperationCallback& cb) {
|
return 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(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 GpgFileOpera::EncryptFileSync(
|
void CreateArchiveHelper(const QString& in_path,
|
||||||
const KeyArgsList& keys, const QString& in_path, bool ascii,
|
const QSharedPointer<GFDataExchanger>& ex) {
|
||||||
const QString& out_path) -> std::tuple<GpgError, DataObjectPtr> {
|
auto w_ex = QWeakPointer<GFDataExchanger>(ex);
|
||||||
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");
|
|
||||||
|
|
||||||
ArchiveFileOperator::NewArchive2DataExchanger(
|
ArchiveFileOperator::NewArchive2DataExchanger(
|
||||||
in_path, ex, [=](GFError err, const DataObjectPtr&) {
|
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,
|
void GpgFileOpera::DecryptFile(const QString& in_path, const QString& out_path,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgData data_in(in_path, true);
|
return DecryptFileImpl(ctx_, in_path, out_path, data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_decrypt", "2.1.0");
|
cb, "gpgme_op_decrypt", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -153,16 +164,8 @@ auto GpgFileOpera::DecryptFileSync(const QString& in_path,
|
|||||||
const QString& out_path)
|
const QString& out_path)
|
||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgData data_in(in_path, true);
|
return DecryptFileImpl(ctx_, in_path, out_path, data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_decrypt", "2.1.0");
|
"gpgme_op_decrypt", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -170,49 +173,55 @@ auto GpgFileOpera::DecryptFileSync(const QString& in_path,
|
|||||||
void GpgFileOpera::DecryptArchive(const QString& in_path,
|
void GpgFileOpera::DecryptArchive(const QString& in_path,
|
||||||
const QString& out_path,
|
const QString& out_path,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
|
auto ex = ExtractArchiveHelper(out_path);
|
||||||
|
|
||||||
ArchiveFileOperator::ExtractArchiveFromDataExchanger(
|
|
||||||
ex, out_path, [](GFError err, const DataObjectPtr&) {
|
|
||||||
FLOG_D("extract archive from data exchanger operation, err: %d", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgData data_in(in_path, true);
|
GpgData data_in(in_path, true);
|
||||||
GpgData data_out(ex);
|
GpgData data_out(ex);
|
||||||
|
|
||||||
auto err = CheckGpgError(
|
return DecryptFileGpgDataImpl(ctx_, data_in, data_out, data_object);
|
||||||
gpgme_op_decrypt(ctx_.DefaultContext(), data_in, data_out));
|
|
||||||
|
|
||||||
data_object->Swap(
|
|
||||||
{GpgDecryptResult(gpgme_op_decrypt_result(ctx_.DefaultContext()))});
|
|
||||||
return err;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_decrypt", "2.1.0");
|
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,
|
void GpgFileOpera::SignFile(const KeyArgsList& keys, const QString& in_path,
|
||||||
bool ascii, const QString& out_path,
|
bool ascii, const QString& out_path,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgError err;
|
return SignFileImpl(ctx_, basic_opera_, keys, in_path, ascii, out_path,
|
||||||
|
data_object);
|
||||||
// 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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_sign", "2.1.0");
|
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)
|
bool ascii, const QString& out_path)
|
||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgError err;
|
return SignFileImpl(ctx_, basic_opera_, keys, in_path, ascii, out_path,
|
||||||
|
data_object);
|
||||||
// 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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_sign", "2.1.0");
|
"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,
|
void GpgFileOpera::VerifyFile(const QString& data_path,
|
||||||
const QString& sign_path,
|
const QString& sign_path,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgError err;
|
return VerifyFileImpl(ctx_, data_path, sign_path, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_verify", "2.1.0");
|
cb, "gpgme_op_verify", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -274,57 +275,55 @@ auto GpgFileOpera::VerifyFileSync(const QString& data_path,
|
|||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgError err;
|
return VerifyFileImpl(ctx_, data_path, sign_path, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_verify", "2.1.0");
|
"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,
|
void GpgFileOpera::EncryptSignFile(const KeyArgsList& keys,
|
||||||
const KeyArgsList& signer_keys,
|
const KeyArgsList& signer_keys,
|
||||||
const QString& in_path, bool ascii,
|
const QString& in_path, bool ascii,
|
||||||
const QString& out_path,
|
const QString& out_path,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgError err;
|
return EncryptSignFileImpl(ctx_, basic_opera_, keys, signer_keys,
|
||||||
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
|
in_path, ascii, out_path, data_object);
|
||||||
|
|
||||||
// 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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_encrypt_sign", "2.1.0");
|
cb, "gpgme_op_encrypt_sign", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -334,29 +333,9 @@ auto GpgFileOpera::EncryptSignFileSync(
|
|||||||
const QString& in_path, bool ascii,
|
const QString& in_path, bool ascii,
|
||||||
const QString& out_path) -> std::tuple<GpgError, DataObjectPtr> {
|
const QString& out_path) -> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgError err;
|
return EncryptSignFileImpl(ctx_, basic_opera_, keys, signer_keys,
|
||||||
std::vector<gpgme_key_t> recipients(keys.begin(), keys.end());
|
in_path, ascii, out_path, data_object);
|
||||||
|
|
||||||
// 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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_encrypt_sign", "2.1.0");
|
"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& in_path, bool ascii,
|
||||||
const QString& out_path,
|
const QString& out_path,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
|
auto ex = CreateStandardGFDataExchanger();
|
||||||
auto w_ex = std::weak_ptr<GFDataExchanger>(ex);
|
|
||||||
|
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](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_in(ex);
|
||||||
GpgData data_out(out_path, false);
|
GpgData data_out(out_path, false);
|
||||||
|
|
||||||
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
|
return EncryptSignFileGpgDataImpl(ctx_, basic_opera_, keys, signer_keys,
|
||||||
err = CheckGpgError(gpgme_op_encrypt_sign(ctx, recipients.data(),
|
data_in, ascii, data_out,
|
||||||
GPGME_ENCRYPT_ALWAYS_TRUST,
|
data_object);
|
||||||
data_in, data_out));
|
|
||||||
|
|
||||||
data_object->Swap({
|
|
||||||
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
|
|
||||||
GpgSignResult(gpgme_op_sign_result(ctx)),
|
|
||||||
});
|
|
||||||
return err;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_encrypt_sign", "2.1.0");
|
cb, "gpgme_op_encrypt_sign", "2.1.0");
|
||||||
|
|
||||||
ArchiveFileOperator::NewArchive2DataExchanger(
|
CreateArchiveHelper(in_path, ex);
|
||||||
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) {
|
auto DecryptVerifyFileGpgDataImpl(
|
||||||
ex->CloseWrite();
|
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,
|
void GpgFileOpera::DecryptVerifyFile(const QString& in_path,
|
||||||
@ -410,20 +388,7 @@ void GpgFileOpera::DecryptVerifyFile(const QString& in_path,
|
|||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgError err;
|
return DecryptVerifyFileImpl(ctx_, in_path, out_path, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_decrypt_verify", "2.1.0");
|
cb, "gpgme_op_decrypt_verify", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -433,20 +398,7 @@ auto GpgFileOpera::DecryptVerifyFileSync(const QString& in_path,
|
|||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgError err;
|
return DecryptVerifyFileImpl(ctx_, in_path, out_path, data_object);
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_decrypt_verify", "2.1.0");
|
"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,
|
void GpgFileOpera::DecryptVerifyArchive(const QString& in_path,
|
||||||
const QString& out_path,
|
const QString& out_path,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
|
auto ex = ExtractArchiveHelper(out_path);
|
||||||
|
|
||||||
ArchiveFileOperator::ExtractArchiveFromDataExchanger(
|
|
||||||
ex, out_path, [](GFError err, const DataObjectPtr&) {
|
|
||||||
FLOG_D("extract archive from ex operation, err: %d", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgError err;
|
|
||||||
|
|
||||||
GpgData data_in(in_path, true);
|
GpgData data_in(in_path, true);
|
||||||
GpgData data_out(ex);
|
GpgData data_out(ex);
|
||||||
|
return DecryptVerifyFileGpgDataImpl(ctx_, data_in, data_out,
|
||||||
err = CheckGpgError(
|
data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_decrypt_verify", "2.1.0");
|
cb, "gpgme_op_decrypt_verify", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -486,17 +423,7 @@ void GpgFileOpera::EncryptFileSymmetric(const QString& in_path, bool ascii,
|
|||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgData data_in(in_path, true);
|
return EncryptFileImpl(ctx_, {}, in_path, ascii, out_path, data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_encrypt_symmetric", "2.1.0");
|
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> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgData data_in(in_path, true);
|
return EncryptFileImpl(ctx_, {}, in_path, ascii, out_path, data_object);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_encrypt_symmetric", "2.1.0");
|
"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 QString& out_path,
|
||||||
const GpgOperationCallback& cb) {
|
const GpgOperationCallback& cb) {
|
||||||
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
|
auto ex = CreateStandardGFDataExchanger();
|
||||||
|
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) {
|
||||||
GpgData data_in(ex);
|
GpgData data_in(ex);
|
||||||
GpgData data_out(out_path, false);
|
GpgData data_out(out_path, false);
|
||||||
|
|
||||||
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
|
return EncryptFileGpgDataImpl(ctx_, {}, data_in, ascii, data_out,
|
||||||
auto err = CheckGpgError(gpgme_op_encrypt(
|
data_object);
|
||||||
ctx, nullptr, GPGME_ENCRYPT_SYMMETRIC, data_in, data_out));
|
|
||||||
data_object->Swap({
|
|
||||||
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
|
|
||||||
});
|
|
||||||
|
|
||||||
return err;
|
|
||||||
},
|
},
|
||||||
cb, "gpgme_op_encrypt_symmetric", "2.1.0");
|
cb, "gpgme_op_encrypt_symmetric", "2.1.0");
|
||||||
|
|
||||||
ArchiveFileOperator::NewArchive2DataExchanger(
|
CreateArchiveHelper(in_path, ex);
|
||||||
in_path, ex, [=](GFError err, const DataObjectPtr&) {
|
|
||||||
FLOG_D("new archive 2 fd operation, err: %d", err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgFileOpera::EncryptDerectorySymmetricSync(
|
auto GpgFileOpera::EncryptDirectorySymmetricSync(
|
||||||
const QString& in_path, bool ascii,
|
const QString& in_path, bool ascii,
|
||||||
const QString& out_path) -> std::tuple<GpgError, DataObjectPtr> {
|
const QString& out_path) -> std::tuple<GpgError, DataObjectPtr> {
|
||||||
auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize);
|
auto ex = CreateStandardGFDataExchanger();
|
||||||
|
|
||||||
ArchiveFileOperator::NewArchive2DataExchanger(
|
|
||||||
in_path, ex, [=](GFError err, const DataObjectPtr&) {
|
|
||||||
FLOG_D("new archive 2 fd operation, err: %d", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
GpgData data_in(ex);
|
GpgData data_in(ex);
|
||||||
GpgData data_out(out_path, false);
|
GpgData data_out(out_path, false);
|
||||||
|
|
||||||
auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext();
|
return EncryptFileGpgDataImpl(ctx_, {}, data_in, ascii, data_out,
|
||||||
auto err = CheckGpgError(gpgme_op_encrypt(
|
data_object);
|
||||||
ctx, nullptr, GPGME_ENCRYPT_SYMMETRIC, data_in, data_out));
|
|
||||||
data_object->Swap({
|
|
||||||
GpgEncryptResult(gpgme_op_encrypt_result(ctx)),
|
|
||||||
});
|
|
||||||
|
|
||||||
return err;
|
|
||||||
},
|
},
|
||||||
"gpgme_op_encrypt_symmetric", "2.1.0");
|
"gpgme_op_encrypt_symmetric", "2.1.0");
|
||||||
|
|
||||||
|
CreateArchiveHelper(in_path, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
@ -29,8 +29,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/function/basic/GpgFunctionObject.h"
|
#include "core/function/basic/GpgFunctionObject.h"
|
||||||
|
#include "core/function/gpg/GpgBasicOperator.h"
|
||||||
#include "core/function/gpg/GpgContext.h"
|
#include "core/function/gpg/GpgContext.h"
|
||||||
#include "core/function/result_analyse/GpgResultAnalyse.h"
|
|
||||||
#include "core/typedef/GpgTypedef.h"
|
#include "core/typedef/GpgTypedef.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
@ -123,7 +123,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera
|
|||||||
* @param out_path
|
* @param out_path
|
||||||
* @param cb
|
* @param cb
|
||||||
*/
|
*/
|
||||||
void EncryptDerectorySymmetric(const QString& in_path, bool ascii,
|
void EncryptDirectorySymmetric(const QString& in_path, bool ascii,
|
||||||
const QString& out_path,
|
const QString& out_path,
|
||||||
const GpgOperationCallback& cb);
|
const GpgOperationCallback& cb);
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera
|
|||||||
* @param ascii
|
* @param ascii
|
||||||
* @param out_path
|
* @param out_path
|
||||||
*/
|
*/
|
||||||
auto EncryptDerectorySymmetricSync(const QString& in_path, bool ascii,
|
auto EncryptDirectorySymmetricSync(const QString& in_path, bool ascii,
|
||||||
const QString& out_path)
|
const QString& out_path)
|
||||||
-> std::tuple<GpgError, DataObjectPtr>;
|
-> std::tuple<GpgError, DataObjectPtr>;
|
||||||
|
|
||||||
@ -296,6 +296,9 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera
|
|||||||
private:
|
private:
|
||||||
GpgContext& ctx_ = GpgContext::GetInstance(
|
GpgContext& ctx_ = GpgContext::GetInstance(
|
||||||
SingletonFunctionObject::GetChannel()); ///< Corresponding context
|
SingletonFunctionObject::GetChannel()); ///< Corresponding context
|
||||||
|
|
||||||
|
GpgBasicOperator& basic_opera_ =
|
||||||
|
GpgBasicOperator::GetInstance(SingletonFunctionObject::GetChannel());
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -73,17 +73,17 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> {
|
|||||||
return GpgKey(std::move(p_key));
|
return GpgKey(std::move(p_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FetchKey() -> KeyLinkListPtr {
|
auto FetchKey() -> GpgKeyList {
|
||||||
if (keys_search_cache_.empty()) {
|
if (keys_search_cache_.empty()) {
|
||||||
FlushKeyCache();
|
FlushKeyCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto keys_list = std::make_unique<GpgKeyLinkList>();
|
auto keys_list = GpgKeyList{};
|
||||||
{
|
{
|
||||||
// get the lock
|
// get the lock
|
||||||
std::lock_guard<std::mutex> lock(keys_cache_mutex_);
|
std::lock_guard<std::mutex> lock(keys_cache_mutex_);
|
||||||
for (const auto& key : keys_cache_) {
|
for (const auto& key : keys_cache_) {
|
||||||
keys_list->push_back(key);
|
keys_list.push_back(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return keys_list;
|
return keys_list;
|
||||||
@ -149,25 +149,17 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GetKeys(const KeyIdArgsListPtr& ids) -> KeyListPtr {
|
auto GetKeys(const KeyIdArgsList& ids) -> GpgKeyList {
|
||||||
auto keys = std::make_unique<KeyArgsList>();
|
auto keys = GpgKeyList{};
|
||||||
for (const auto& key_id : *ids) keys->emplace_back(GetKey(key_id, true));
|
for (const auto& key_id : ids) keys.emplace_back(GetKey(key_id, true));
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GetKeysCopy(const KeyLinkListPtr& keys) -> KeyLinkListPtr {
|
auto GetKeysCopy(const GpgKeyList& keys) -> GpgKeyList {
|
||||||
// get the lock
|
// get the lock
|
||||||
std::lock_guard<std::mutex> lock(ctx_mutex_);
|
std::lock_guard<std::mutex> lock(ctx_mutex_);
|
||||||
auto keys_copy = std::make_unique<GpgKeyLinkList>();
|
auto keys_copy = GpgKeyList{};
|
||||||
for (const auto& key : *keys) keys_copy->emplace_back(key);
|
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);
|
|
||||||
return keys_copy;
|
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::FlushKeyCache() -> bool { return p_->FlushKeyCache(); }
|
||||||
|
|
||||||
auto GpgKeyGetter::GetKeys(const KeyIdArgsListPtr& ids) -> KeyListPtr {
|
auto GpgKeyGetter::GetKeys(const KeyIdArgsList& ids) -> GpgKeyList {
|
||||||
return p_->GetKeys(ids);
|
return p_->GetKeys(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKeyGetter::GetKeysCopy(const KeyLinkListPtr& keys) -> KeyLinkListPtr {
|
auto GpgKeyGetter::GetKeysCopy(const GpgKeyList& keys) -> GpgKeyList {
|
||||||
return p_->GetKeysCopy(keys);
|
return p_->GetKeysCopy(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKeyGetter::GetKeysCopy(const KeyListPtr& keys) -> KeyListPtr {
|
auto GpgKeyGetter::FetchKey() -> GpgKeyList { return p_->FetchKey(); }
|
||||||
return p_->GetKeysCopy(keys);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GpgKeyGetter::FetchKey() -> KeyLinkListPtr { return p_->FetchKey(); }
|
|
||||||
|
|
||||||
auto GpgKeyGetter::GetGpgKeyTableModel() -> QSharedPointer<GpgKeyTableModel> {
|
auto GpgKeyGetter::GetGpgKeyTableModel() -> QSharedPointer<GpgKeyTableModel> {
|
||||||
return p_->GetGpgKeyTableModel();
|
return p_->GetGpgKeyTableModel();
|
||||||
|
@ -68,7 +68,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyGetter
|
|||||||
* @param ids
|
* @param ids
|
||||||
* @return KeyListPtr
|
* @return KeyListPtr
|
||||||
*/
|
*/
|
||||||
auto GetKeys(const KeyIdArgsListPtr& key_ids) -> KeyListPtr;
|
auto GetKeys(const KeyIdArgsList& key_ids) -> GpgKeyList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Pubkey object
|
* @brief Get the Pubkey object
|
||||||
@ -83,7 +83,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyGetter
|
|||||||
*
|
*
|
||||||
* @return KeyLinkListPtr
|
* @return KeyLinkListPtr
|
||||||
*/
|
*/
|
||||||
auto FetchKey() -> KeyLinkListPtr;
|
auto FetchKey() -> GpgKeyList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief flush the keys in the cache
|
* @brief flush the keys in the cache
|
||||||
@ -97,15 +97,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyGetter
|
|||||||
* @param keys
|
* @param keys
|
||||||
* @return KeyListPtr
|
* @return KeyListPtr
|
||||||
*/
|
*/
|
||||||
auto GetKeysCopy(const KeyListPtr& keys) -> KeyListPtr;
|
auto GetKeysCopy(const GpgKeyList& keys) -> GpgKeyList;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the Keys Copy object
|
|
||||||
*
|
|
||||||
* @param keys
|
|
||||||
* @return KeyLinkListPtr
|
|
||||||
*/
|
|
||||||
auto GetKeysCopy(const KeyLinkListPtr& keys) -> KeyLinkListPtr;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
@ -82,7 +82,7 @@ auto GpgKeyImportExporter::ExportKey(const GpgKey& key, bool secret, bool ascii,
|
|||||||
if (shortest) mode |= GPGME_EXPORT_MODE_MINIMAL;
|
if (shortest) mode |= GPGME_EXPORT_MODE_MINIMAL;
|
||||||
if (ssh_mode) mode |= GPGME_EXPORT_MODE_SSH;
|
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
|
// Last entry data_in array has to be nullptr
|
||||||
keys_array.emplace_back(key);
|
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 (shortest) mode |= GPGME_EXPORT_MODE_MINIMAL;
|
||||||
if (ssh_mode) mode |= GPGME_EXPORT_MODE_SSH;
|
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
|
// Last entry data_in array has to be nullptr
|
||||||
keys_array.emplace_back(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;
|
if (keys.empty()) return GPG_ERR_CANCELED;
|
||||||
|
|
||||||
int mode = 0;
|
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
|
// Last entry data_in array has to be nullptr
|
||||||
keys_array.emplace_back(nullptr);
|
keys_array.emplace_back(nullptr);
|
||||||
|
@ -61,10 +61,10 @@ auto GpgKeyManager::SignKey(const GpgKey& target, KeyArgsList& keys,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKeyManager::RevSign(const GpgKey& key,
|
auto GpgKeyManager::RevSign(const GpgKey& key,
|
||||||
const SignIdArgsListPtr& signature_id) -> bool {
|
const SignIdArgsList& signature_id) -> bool {
|
||||||
auto& key_getter = GpgKeyGetter::GetInstance(GetChannel());
|
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);
|
auto signing_key = key_getter.GetKey(sign_id.first);
|
||||||
assert(signing_key.IsGood());
|
assert(signing_key.IsGood());
|
||||||
|
|
||||||
@ -271,13 +271,8 @@ auto GpgKeyManager::RevokeSubkey(const GpgKey& key, int subkey_index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dealing with reason text
|
// dealing with reason text
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 4)
|
auto reason_text_lines = SecureCreateSharedObject<QStringList>(
|
||||||
auto reason_text_lines = SecureCreateSharedObject<QList<QString>>(
|
|
||||||
reason_text.split('\n', Qt::SkipEmptyParts).toVector());
|
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 =
|
AutomatonNextStateHandler next_state_handler =
|
||||||
[](AutomatonState state, QString status, QString args) {
|
[](AutomatonState state, QString status, QString args) {
|
||||||
|
@ -68,7 +68,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager
|
|||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
auto RevSign(const GpgFrontend::GpgKey& key,
|
auto RevSign(const GpgFrontend::GpgKey& key,
|
||||||
const GpgFrontend::SignIdArgsListPtr& signature_id) -> bool;
|
const GpgFrontend::SignIdArgsList& signature_id) -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the Expire object
|
* @brief Set the Expire object
|
||||||
|
@ -28,14 +28,12 @@
|
|||||||
|
|
||||||
#include "GpgKeyOpera.h"
|
#include "GpgKeyOpera.h"
|
||||||
|
|
||||||
#include <gpg-error.h>
|
|
||||||
|
|
||||||
#include "core/GpgModel.h"
|
#include "core/GpgModel.h"
|
||||||
#include "core/function/gpg/GpgCommandExecutor.h"
|
#include "core/function/gpg/GpgCommandExecutor.h"
|
||||||
#include "core/function/gpg/GpgKeyGetter.h"
|
#include "core/function/gpg/GpgKeyGetter.h"
|
||||||
#include "core/model/DataObject.h"
|
#include "core/model/DataObject.h"
|
||||||
#include "core/model/GpgGenKeyInfo.h"
|
|
||||||
#include "core/model/GpgGenerateKeyResult.h"
|
#include "core/model/GpgGenerateKeyResult.h"
|
||||||
|
#include "core/model/GpgKeyGenerateInfo.h"
|
||||||
#include "core/module/ModuleManager.h"
|
#include "core/module/ModuleManager.h"
|
||||||
#include "core/typedef/GpgTypedef.h"
|
#include "core/typedef/GpgTypedef.h"
|
||||||
#include "core/utils/AsyncUtils.h"
|
#include "core/utils/AsyncUtils.h"
|
||||||
@ -51,9 +49,9 @@ GpgKeyOpera::GpgKeyOpera(int channel)
|
|||||||
* Delete keys
|
* Delete keys
|
||||||
* @param uidList key ids
|
* @param uidList key ids
|
||||||
*/
|
*/
|
||||||
void GpgKeyOpera::DeleteKeys(KeyIdArgsListPtr key_ids) {
|
void GpgKeyOpera::DeleteKeys(KeyIdArgsList key_ids) {
|
||||||
GpgError err;
|
GpgError err;
|
||||||
for (const auto& tmp : *key_ids) {
|
for (const auto& tmp : key_ids) {
|
||||||
auto key = GpgKeyGetter::GetInstance(GetChannel()).GetKey(tmp);
|
auto key = GpgKeyGetter::GetInstance(GetChannel()).GetKey(tmp);
|
||||||
if (key.IsGood()) {
|
if (key.IsGood()) {
|
||||||
err = CheckGpgError(gpgme_op_delete_ext(
|
err = CheckGpgError(gpgme_op_delete_ext(
|
||||||
@ -112,15 +110,8 @@ void GpgKeyOpera::GenerateRevokeCert(const GpgKey& key,
|
|||||||
<< "text:" << revocation_reason_text;
|
<< "text:" << revocation_reason_text;
|
||||||
|
|
||||||
// dealing with reason text
|
// dealing with reason text
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 4)
|
auto reason_text_lines = GpgFrontend::SecureCreateSharedObject<QStringList>(
|
||||||
auto reason_text_lines =
|
revocation_reason_text.split('\n', Qt::SkipEmptyParts).toVector());
|
||||||
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
|
|
||||||
|
|
||||||
const auto app_path = Module::RetrieveRTValueTypedOrDefault<>(
|
const auto app_path = Module::RetrieveRTValueTypedOrDefault<>(
|
||||||
"core", "gpgme.ctx.app_path", QString{});
|
"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
|
* Generate a new key pair
|
||||||
* @param params key generation args
|
* @param params key generation args
|
||||||
* @return error information
|
* @return error information
|
||||||
*/
|
*/
|
||||||
void GpgKeyOpera::GenerateKey(const std::shared_ptr<GenKeyInfo>& params,
|
void GpgKeyOpera::GenerateKey(const QSharedPointer<KeyGenerateInfo>& params,
|
||||||
const GpgOperationCallback& callback) {
|
const GpgOperationCallback& callback) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[&ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
auto userid = params->GetUserid();
|
return GenerateKeyImpl(ctx_, params, data_object);
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
callback, "gpgme_op_createkey", "2.1.0");
|
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> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[=, &ctx = ctx_](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
auto userid = params->GetUserid();
|
return GenerateKeyImpl(ctx_, params, data_object);
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
"gpgme_op_createkey", "2.1.0");
|
"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,
|
void GpgKeyOpera::GenerateSubkey(const GpgKey& key,
|
||||||
const std::shared_ptr<GenKeyInfo>& params,
|
const QSharedPointer<KeyGenerateInfo>& params,
|
||||||
const GpgOperationCallback& callback) {
|
const GpgOperationCallback& callback) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[key, &ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
if (!params->IsSubKey()) return GPG_ERR_CANCELED;
|
return GenerateSubKeyImpl(ctx_, key, params, data_object);
|
||||||
|
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
callback, "gpgme_op_createsubkey", "2.1.13");
|
callback, "gpgme_op_createsubkey", "2.1.13");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKeyOpera::GenerateSubkeySync(const GpgKey& key,
|
auto GpgKeyOpera::GenerateSubkeySync(
|
||||||
const std::shared_ptr<GenKeyInfo>& params)
|
const GpgKey& key, const QSharedPointer<KeyGenerateInfo>& params)
|
||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[key, &ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError {
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
if (!params->IsSubKey()) return GPG_ERR_CANCELED;
|
return GenerateSubKeyImpl(ctx_, key, params, data_object);
|
||||||
|
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
"gpgme_op_createsubkey", "2.1.13");
|
"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(
|
void GpgKeyOpera::GenerateKeyWithSubkey(
|
||||||
const std::shared_ptr<GenKeyInfo>& params,
|
const QSharedPointer<KeyGenerateInfo>& p_params,
|
||||||
const std::shared_ptr<GenKeyInfo>& subkey_params,
|
const QSharedPointer<KeyGenerateInfo>& s_params,
|
||||||
const GpgOperationCallback& callback) {
|
const GpgOperationCallback& callback) {
|
||||||
RunGpgOperaAsync(
|
RunGpgOperaAsync(
|
||||||
[&ctx = ctx_, params, subkey_params,
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
channel = GetChannel()](const DataObjectPtr& data_object) -> GpgError {
|
return GenerateKeyWithSubkeyImpl(ctx_, key_getter_, p_params, s_params,
|
||||||
auto userid = params->GetUserid().toUtf8();
|
data_object);
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
callback, "gpgme_op_createkey&gpgme_op_createsubkey", "2.1.0");
|
callback, "gpgme_op_createkey&gpgme_op_createsubkey", "2.1.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKeyOpera::GenerateKeyWithSubkeySync(
|
auto GpgKeyOpera::GenerateKeyWithSubkeySync(
|
||||||
const std::shared_ptr<GenKeyInfo>& params,
|
const QSharedPointer<KeyGenerateInfo>& p_params,
|
||||||
const std::shared_ptr<GenKeyInfo>& subkey_params)
|
const QSharedPointer<KeyGenerateInfo>& s_params)
|
||||||
-> std::tuple<GpgError, DataObjectPtr> {
|
-> std::tuple<GpgError, DataObjectPtr> {
|
||||||
return RunGpgOperaSync(
|
return RunGpgOperaSync(
|
||||||
[&ctx = ctx_, params, subkey_params,
|
[=](const DataObjectPtr& data_object) -> GpgError {
|
||||||
channel = GetChannel()](const DataObjectPtr& data_object) -> GpgError {
|
return GenerateKeyWithSubkeyImpl(ctx_, key_getter_, p_params, s_params,
|
||||||
auto userid = params->GetUserid().toUtf8();
|
data_object);
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
"gpgme_op_createkey&gpgme_op_createsubkey", "2.1.0");
|
"gpgme_op_createkey&gpgme_op_createsubkey", "2.1.0");
|
||||||
}
|
}
|
||||||
@ -532,8 +360,8 @@ auto GpgKeyOpera::ModifyTOFUPolicy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GpgKeyOpera::DeleteKey(const KeyId& key_id) {
|
void GpgKeyOpera::DeleteKey(const KeyId& key_id) {
|
||||||
auto keys = std::make_unique<KeyIdArgsList>();
|
auto keys = KeyIdArgsList{};
|
||||||
keys->push_back(key_id);
|
keys.push_back(key_id);
|
||||||
DeleteKeys(std::move(keys));
|
DeleteKeys(keys);
|
||||||
}
|
}
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "core/function/gpg/GpgContext.h"
|
#include "core/function/gpg/GpgContext.h"
|
||||||
|
#include "core/function/gpg/GpgKeyGetter.h"
|
||||||
#include "core/typedef/GpgTypedef.h"
|
#include "core/typedef/GpgTypedef.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
@ -38,7 +39,7 @@ namespace GpgFrontend {
|
|||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class GenKeyInfo;
|
class KeyGenerateInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -60,7 +61,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
|
|||||||
*
|
*
|
||||||
* @param key_ids
|
* @param key_ids
|
||||||
*/
|
*/
|
||||||
void DeleteKeys(KeyIdArgsListPtr key_ids);
|
void DeleteKeys(KeyIdArgsList key_ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -114,7 +115,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
|
|||||||
* @param result
|
* @param result
|
||||||
* @return GpgFrontend::GpgError
|
* @return GpgFrontend::GpgError
|
||||||
*/
|
*/
|
||||||
void GenerateKey(const std::shared_ptr<GenKeyInfo>&,
|
void GenerateKey(const QSharedPointer<KeyGenerateInfo>&,
|
||||||
const GpgOperationCallback&);
|
const GpgOperationCallback&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,7 +123,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
|
|||||||
*
|
*
|
||||||
* @param params
|
* @param params
|
||||||
*/
|
*/
|
||||||
auto GenerateKeySync(const std::shared_ptr<GenKeyInfo>& params)
|
auto GenerateKeySync(const QSharedPointer<KeyGenerateInfo>& params)
|
||||||
-> std::tuple<GpgError, DataObjectPtr>;
|
-> std::tuple<GpgError, DataObjectPtr>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,7 +134,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
|
|||||||
* @return GpgFrontend::GpgError
|
* @return GpgFrontend::GpgError
|
||||||
*/
|
*/
|
||||||
void GenerateSubkey(const GpgKey& key,
|
void GenerateSubkey(const GpgKey& key,
|
||||||
const std::shared_ptr<GenKeyInfo>& params,
|
const QSharedPointer<KeyGenerateInfo>& params,
|
||||||
const GpgOperationCallback&);
|
const GpgOperationCallback&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,7 +144,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
|
|||||||
* @param params
|
* @param params
|
||||||
*/
|
*/
|
||||||
auto GenerateSubkeySync(const GpgKey& key,
|
auto GenerateSubkeySync(const GpgKey& key,
|
||||||
const std::shared_ptr<GenKeyInfo>& params)
|
const QSharedPointer<KeyGenerateInfo>& params)
|
||||||
-> std::tuple<GpgError, DataObjectPtr>;
|
-> std::tuple<GpgError, DataObjectPtr>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,8 +154,8 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
|
|||||||
* @param subkey_params
|
* @param subkey_params
|
||||||
* @param callback
|
* @param callback
|
||||||
*/
|
*/
|
||||||
void GenerateKeyWithSubkey(const std::shared_ptr<GenKeyInfo>& params,
|
void GenerateKeyWithSubkey(const QSharedPointer<KeyGenerateInfo>& p_params,
|
||||||
const std::shared_ptr<GenKeyInfo>& subkey_params,
|
const QSharedPointer<KeyGenerateInfo>& s_params,
|
||||||
const GpgOperationCallback& callback);
|
const GpgOperationCallback& callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,12 +166,15 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera
|
|||||||
* @param callback
|
* @param callback
|
||||||
*/
|
*/
|
||||||
auto GenerateKeyWithSubkeySync(
|
auto GenerateKeyWithSubkeySync(
|
||||||
const std::shared_ptr<GenKeyInfo>& params,
|
const QSharedPointer<KeyGenerateInfo>& p_params,
|
||||||
const std::shared_ptr<GenKeyInfo>& subkey_params)
|
const QSharedPointer<KeyGenerateInfo>& s_params)
|
||||||
-> std::tuple<GpgError, DataObjectPtr>;
|
-> std::tuple<GpgError, DataObjectPtr>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GpgContext& ctx_ =
|
GpgContext& ctx_ =
|
||||||
GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///<
|
GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///<
|
||||||
|
|
||||||
|
GpgKeyGetter& key_getter_ =
|
||||||
|
GpgKeyGetter::GetInstance(SingletonFunctionObject::GetChannel()); ///<
|
||||||
};
|
};
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -155,15 +155,8 @@ auto GpgUIDOperator::RevokeUID(const GpgKey& key, int uid_index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dealing with reason text
|
// dealing with reason text
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 4)
|
auto reason_text_lines = GpgFrontend::SecureCreateSharedObject<QStringList>(
|
||||||
auto reason_text_lines =
|
reason_text.split('\n', Qt::SkipEmptyParts).toVector());
|
||||||
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
|
|
||||||
|
|
||||||
AutomatonNextStateHandler next_state_handler = [](AutomatonState state,
|
AutomatonNextStateHandler next_state_handler = [](AutomatonState state,
|
||||||
QString status,
|
QString status,
|
||||||
|
@ -27,10 +27,6 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "core/typedef/GpgTypedef.h"
|
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
class GPGFRONTEND_CORE_EXPORT GpgResultAnalyse : public QObject {
|
class GPGFRONTEND_CORE_EXPORT GpgResultAnalyse : public QObject {
|
||||||
|
@ -256,6 +256,6 @@ auto GpgFrontend::GpgVerifyResultAnalyse::TakeChargeOfResult()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GpgFrontend::GpgVerifyResultAnalyse::GetUnknownSignatures() const
|
auto GpgFrontend::GpgVerifyResultAnalyse::GetUnknownSignatures() const
|
||||||
-> QList<QString> {
|
-> QStringList {
|
||||||
return unknown_signer_fpr_list_;
|
return unknown_signer_fpr_list_;
|
||||||
}
|
}
|
||||||
|
@ -65,9 +65,9 @@ class GPGFRONTEND_CORE_EXPORT GpgVerifyResultAnalyse : public GpgResultAnalyse {
|
|||||||
/**
|
/**
|
||||||
* @brief Get the Unknown Signatures object
|
* @brief Get the Unknown Signatures object
|
||||||
*
|
*
|
||||||
* @return QList<QString>
|
* @return QStringList
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto GetUnknownSignatures() const -> QList<QString>;
|
[[nodiscard]] auto GetUnknownSignatures() const -> QStringList;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@ -99,7 +99,7 @@ class GPGFRONTEND_CORE_EXPORT GpgVerifyResultAnalyse : public GpgResultAnalyse {
|
|||||||
|
|
||||||
GpgError error_; ///<
|
GpgError error_; ///<
|
||||||
GpgVerifyResult result_; ///<
|
GpgVerifyResult result_; ///<
|
||||||
QList<QString> unknown_signer_fpr_list_;
|
QStringList unknown_signer_fpr_list_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include "DataObject.h"
|
#include "DataObject.h"
|
||||||
|
|
||||||
#include <stack>
|
#include "core/typedef/CoreTypedef.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class DataObject::Impl {
|
|||||||
auto GetObjectSize() -> size_t { return params_.size(); }
|
auto GetObjectSize() -> size_t { return params_.size(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::any> params_;
|
QContainer<std::any> params_;
|
||||||
};
|
};
|
||||||
|
|
||||||
DataObject::DataObject() : p_(SecureCreateUniqueObject<Impl>()) {}
|
DataObject::DataObject() : p_(SecureCreateUniqueObject<Impl>()) {}
|
||||||
|
@ -33,13 +33,11 @@
|
|||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
#include "core/GpgFrontendCoreExport.h"
|
#include "core/GpgFrontendCoreExport.h"
|
||||||
|
#include "core/typedef/CoreTypedef.h"
|
||||||
#include "core/utils/MemoryUtils.h"
|
#include "core/utils/MemoryUtils.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
class DataObject;
|
|
||||||
using DataObjectPtr = std::shared_ptr<DataObject>; ///<
|
|
||||||
|
|
||||||
class GPGFRONTEND_CORE_EXPORT DataObject {
|
class GPGFRONTEND_CORE_EXPORT DataObject {
|
||||||
public:
|
public:
|
||||||
DataObject();
|
DataObject();
|
||||||
@ -66,7 +64,7 @@ class GPGFRONTEND_CORE_EXPORT DataObject {
|
|||||||
auto Check() -> bool {
|
auto Check() -> bool {
|
||||||
if (sizeof...(Args) != GetObjectSize()) return false;
|
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) {
|
for (size_t i = 0; i < type_list.size(); ++i) {
|
||||||
if (std::type_index(*type_list[i]) !=
|
if (std::type_index(*type_list[i]) !=
|
||||||
std::type_index((*this)[i].type())) {
|
std::type_index((*this)[i].type())) {
|
||||||
|
@ -28,10 +28,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
|
constexpr ssize_t kDataExchangerSize =
|
||||||
|
static_cast<const ssize_t>(1024 * 1024 * 8); // 8 MB
|
||||||
|
|
||||||
class GFDataExchanger {
|
class GFDataExchanger {
|
||||||
public:
|
public:
|
||||||
explicit GFDataExchanger(ssize_t size);
|
explicit GFDataExchanger(ssize_t size);
|
||||||
@ -50,4 +54,8 @@ class GFDataExchanger {
|
|||||||
std::atomic_bool close_ = false;
|
std::atomic_bool close_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline auto CreateStandardGFDataExchanger() -> QSharedPointer<GFDataExchanger> {
|
||||||
|
return QSharedPointer<GFDataExchanger>::create(kDataExchangerSize);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
@ -104,7 +104,7 @@ GpgData::GpgData(const QString& path, bool read) {
|
|||||||
data_ref_ = std::unique_ptr<struct gpgme_data, DataRefDeleter>(data);
|
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)) {
|
: data_cbs_(), data_ex_(std::move(ex)) {
|
||||||
gpgme_data_t data;
|
gpgme_data_t data;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class GPGFRONTEND_CORE_EXPORT GpgData {
|
|||||||
*
|
*
|
||||||
* @param fd
|
* @param fd
|
||||||
*/
|
*/
|
||||||
explicit GpgData(std::shared_ptr<GFDataExchanger>);
|
explicit GpgData(QSharedPointer<GFDataExchanger>);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Gpg Data object
|
* @brief Construct a new Gpg Data object
|
||||||
@ -124,7 +124,7 @@ class GPGFRONTEND_CORE_EXPORT GpgData {
|
|||||||
int fd_ = -1;
|
int fd_ = -1;
|
||||||
|
|
||||||
struct gpgme_data_cbs data_cbs_;
|
struct gpgme_data_cbs data_cbs_;
|
||||||
std::shared_ptr<GFDataExchanger> data_ex_;
|
QSharedPointer<GFDataExchanger> data_ex_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -48,8 +48,8 @@ auto GpgDecryptResult::GetRaw() -> gpgme_decrypt_result_t {
|
|||||||
return result_ref_.get();
|
return result_ref_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgDecryptResult::Recipients() -> std::vector<GpgRecipient> {
|
auto GpgDecryptResult::Recipients() -> QContainer<GpgRecipient> {
|
||||||
std::vector<GpgRecipient> result;
|
QContainer<GpgRecipient> result;
|
||||||
for (auto* reci = result_ref_->recipients; reci != nullptr;
|
for (auto* reci = result_ref_->recipients; reci != nullptr;
|
||||||
reci = reci->next) {
|
reci = reci->next) {
|
||||||
try {
|
try {
|
||||||
|
@ -39,7 +39,7 @@ class GPGFRONTEND_CORE_EXPORT GpgDecryptResult {
|
|||||||
|
|
||||||
auto GetRaw() -> gpgme_decrypt_result_t;
|
auto GetRaw() -> gpgme_decrypt_result_t;
|
||||||
|
|
||||||
auto Recipients() -> std::vector<GpgRecipient>;
|
auto Recipients() -> QContainer<GpgRecipient>;
|
||||||
|
|
||||||
explicit GpgDecryptResult(gpgme_decrypt_result_t);
|
explicit GpgDecryptResult(gpgme_decrypt_result_t);
|
||||||
|
|
||||||
|
@ -48,8 +48,8 @@ auto GpgEncryptResult::GetRaw() -> gpgme_encrypt_result_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GpgEncryptResult::InvalidRecipients()
|
auto GpgEncryptResult::InvalidRecipients()
|
||||||
-> std::vector<std::tuple<QString, GpgError>> {
|
-> QContainer<std::tuple<QString, GpgError>> {
|
||||||
std::vector<std::tuple<QString, GpgError>> result;
|
QContainer<std::tuple<QString, GpgError>> result;
|
||||||
for (auto* invalid_key = result_ref_->invalid_recipients;
|
for (auto* invalid_key = result_ref_->invalid_recipients;
|
||||||
invalid_key != nullptr; invalid_key = invalid_key->next) {
|
invalid_key != nullptr; invalid_key = invalid_key->next) {
|
||||||
try {
|
try {
|
||||||
|
@ -38,7 +38,7 @@ class GPGFRONTEND_CORE_EXPORT GpgEncryptResult {
|
|||||||
|
|
||||||
auto GetRaw() -> gpgme_encrypt_result_t;
|
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);
|
explicit GpgEncryptResult(gpgme_encrypt_result_t);
|
||||||
|
|
||||||
|
@ -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 world’s 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
|
|
@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
#include "core/model/GpgKey.h"
|
#include "core/model/GpgKey.h"
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
GpgKey::GpgKey(gpgme_key_t &&key) : key_ref_(key) {}
|
GpgKey::GpgKey(gpgme_key_t &&key) : key_ref_(key) {}
|
||||||
@ -149,21 +147,13 @@ auto GpgKey::GetPrimaryKeyLength() const -> unsigned int {
|
|||||||
return key_ref_->subkeys->length;
|
return key_ref_->subkeys->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKey::IsHasEncryptionCapability() const -> bool {
|
auto GpgKey::IsHasEncrCap() const -> bool { return key_ref_->can_encrypt; }
|
||||||
return key_ref_->can_encrypt;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GpgKey::IsHasSigningCapability() const -> bool {
|
auto GpgKey::IsHasSignCap() const -> bool { return key_ref_->can_sign; }
|
||||||
return key_ref_->can_sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GpgKey::IsHasCertificationCapability() const -> bool {
|
auto GpgKey::IsHasCertCap() const -> bool { return key_ref_->can_certify; }
|
||||||
return key_ref_->can_certify;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GpgKey::IsHasAuthenticationCapability() const -> bool {
|
auto GpgKey::IsHasAuthCap() const -> bool { return key_ref_->can_authenticate; }
|
||||||
return key_ref_->can_authenticate;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GpgKey::IsHasCardKey() const -> bool {
|
auto GpgKey::IsHasCardKey() const -> bool {
|
||||||
auto subkeys = GetSubKeys();
|
auto subkeys = GetSubKeys();
|
||||||
@ -184,8 +174,8 @@ auto GpgKey::IsHasMasterKey() const -> bool {
|
|||||||
return key_ref_->subkeys->secret;
|
return key_ref_->subkeys->secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKey::GetSubKeys() const -> std::unique_ptr<std::vector<GpgSubKey>> {
|
auto GpgKey::GetSubKeys() const -> std::unique_ptr<QContainer<GpgSubKey>> {
|
||||||
auto p_keys = std::make_unique<std::vector<GpgSubKey>>();
|
auto p_keys = std::make_unique<QContainer<GpgSubKey>>();
|
||||||
auto *next = key_ref_->subkeys;
|
auto *next = key_ref_->subkeys;
|
||||||
while (next != nullptr) {
|
while (next != nullptr) {
|
||||||
p_keys->push_back(GpgSubKey(next));
|
p_keys->push_back(GpgSubKey(next));
|
||||||
@ -194,8 +184,8 @@ auto GpgKey::GetSubKeys() const -> std::unique_ptr<std::vector<GpgSubKey>> {
|
|||||||
return p_keys;
|
return p_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKey::GetUIDs() const -> std::unique_ptr<std::vector<GpgUID>> {
|
auto GpgKey::GetUIDs() const -> std::unique_ptr<QContainer<GpgUID>> {
|
||||||
auto p_uids = std::make_unique<std::vector<GpgUID>>();
|
auto p_uids = std::make_unique<QContainer<GpgUID>>();
|
||||||
auto *uid_next = key_ref_->uids;
|
auto *uid_next = key_ref_->uids;
|
||||||
while (uid_next != nullptr) {
|
while (uid_next != nullptr) {
|
||||||
p_uids->push_back(GpgUID(uid_next));
|
p_uids->push_back(GpgUID(uid_next));
|
||||||
@ -204,24 +194,24 @@ auto GpgKey::GetUIDs() const -> std::unique_ptr<std::vector<GpgUID>> {
|
|||||||
return p_uids;
|
return p_uids;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKey::IsHasActualSigningCapability() const -> bool {
|
auto GpgKey::IsHasActualSignCap() const -> bool {
|
||||||
auto subkeys = GetSubKeys();
|
auto subkeys = GetSubKeys();
|
||||||
return std::any_of(
|
return std::any_of(subkeys->begin(), subkeys->end(),
|
||||||
subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool {
|
[](const GpgSubKey &subkey) -> bool {
|
||||||
return subkey.IsSecretKey() && subkey.IsHasSigningCapability() &&
|
return subkey.IsSecretKey() && subkey.IsHasSignCap() &&
|
||||||
!subkey.IsDisabled() && !subkey.IsRevoked() &&
|
!subkey.IsDisabled() && !subkey.IsRevoked() &&
|
||||||
!subkey.IsExpired();
|
!subkey.IsExpired();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKey::IsHasActualAuthenticationCapability() const -> bool {
|
auto GpgKey::IsHasActualAuthCap() const -> bool {
|
||||||
auto subkeys = GetSubKeys();
|
auto subkeys = GetSubKeys();
|
||||||
return std::any_of(
|
return std::any_of(subkeys->begin(), subkeys->end(),
|
||||||
subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool {
|
[](const GpgSubKey &subkey) -> bool {
|
||||||
return subkey.IsSecretKey() && subkey.IsHasAuthenticationCapability() &&
|
return subkey.IsSecretKey() && subkey.IsHasAuthCap() &&
|
||||||
!subkey.IsDisabled() && !subkey.IsRevoked() &&
|
!subkey.IsDisabled() && !subkey.IsRevoked() &&
|
||||||
!subkey.IsExpired();
|
!subkey.IsExpired();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,7 +219,7 @@ auto GpgKey::IsHasActualAuthenticationCapability() const -> bool {
|
|||||||
* @param key target key
|
* @param key target key
|
||||||
* @return if key certify
|
* @return if key certify
|
||||||
*/
|
*/
|
||||||
auto GpgKey::IsHasActualCertificationCapability() const -> bool {
|
auto GpgKey::IsHasActualCertCap() const -> bool {
|
||||||
return IsHasMasterKey() && !IsExpired() && !IsRevoked() && !IsDisabled();
|
return IsHasMasterKey() && !IsExpired() && !IsRevoked() && !IsDisabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,13 +228,13 @@ auto GpgKey::IsHasActualCertificationCapability() const -> bool {
|
|||||||
* @param key target key
|
* @param key target key
|
||||||
* @return if key encrypt
|
* @return if key encrypt
|
||||||
*/
|
*/
|
||||||
auto GpgKey::IsHasActualEncryptionCapability() const -> bool {
|
auto GpgKey::IsHasActualEncrCap() const -> bool {
|
||||||
auto subkeys = GetSubKeys();
|
auto subkeys = GetSubKeys();
|
||||||
return std::any_of(
|
return std::any_of(subkeys->begin(), subkeys->end(),
|
||||||
subkeys->begin(), subkeys->end(), [](const GpgSubKey &subkey) -> bool {
|
[](const GpgSubKey &subkey) -> bool {
|
||||||
return subkey.IsHasEncryptionCapability() && !subkey.IsDisabled() &&
|
return subkey.IsHasEncrCap() && !subkey.IsDisabled() &&
|
||||||
!subkey.IsRevoked() && !subkey.IsExpired();
|
!subkey.IsRevoked() && !subkey.IsExpired();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpgKey::KeyRefDeleter::operator()(gpgme_key_t _key) {
|
void GpgKey::KeyRefDeleter::operator()(gpgme_key_t _key) {
|
||||||
|
@ -152,7 +152,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasEncryptionCapability() const -> bool;
|
[[nodiscard]] auto IsHasEncrCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -161,7 +161,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasActualEncryptionCapability() const -> bool;
|
[[nodiscard]] auto IsHasActualEncrCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -169,7 +169,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasSigningCapability() const -> bool;
|
[[nodiscard]] auto IsHasSignCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -177,7 +177,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasActualSigningCapability() const -> bool;
|
[[nodiscard]] auto IsHasActualSignCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -185,7 +185,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasCertificationCapability() const -> bool;
|
[[nodiscard]] auto IsHasCertCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -193,7 +193,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasActualCertificationCapability() const -> bool;
|
[[nodiscard]] auto IsHasActualCertCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -201,7 +201,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasAuthenticationCapability() const -> bool;
|
[[nodiscard]] auto IsHasAuthCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -209,7 +209,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasActualAuthenticationCapability() const -> bool;
|
[[nodiscard]] auto IsHasActualAuthCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -262,17 +262,17 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
|
|||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* @return std::unique_ptr<std::vector<GpgSubKey>>
|
* @return std::unique_ptr<QContainer<GpgSubKey>>
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto GetSubKeys() const
|
[[nodiscard]] auto GetSubKeys() const
|
||||||
-> std::unique_ptr<std::vector<GpgSubKey>>;
|
-> std::unique_ptr<QContainer<GpgSubKey>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @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
|
* @brief Construct a new Gpg Key object
|
||||||
|
500
src/core/model/GpgKeyGenerateInfo.cpp
Normal file
500
src/core/model/GpgKeyGenerateInfo.cpp
Normal 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
|
@ -29,12 +29,59 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/GpgFrontendCoreExport.h"
|
#include "core/GpgFrontendCoreExport.h"
|
||||||
|
#include "core/typedef/CoreTypedef.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
class GPGFRONTEND_CORE_EXPORT KeyAlgo {
|
||||||
public:
|
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
|
* @brief Construct a new Gen Key Info object
|
||||||
@ -42,21 +89,39 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
* @param m_is_sub_key
|
* @param m_is_sub_key
|
||||||
* @param m_standalone
|
* @param m_standalone
|
||||||
*/
|
*/
|
||||||
explicit GenKeyInfo(bool m_is_sub_key = false);
|
explicit KeyGenerateInfo(bool is_subkey = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Supported Key Algo object
|
* @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
|
* @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
|
* @brief
|
||||||
@ -71,7 +136,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
*
|
*
|
||||||
* @param m_sub_key
|
* @param m_sub_key
|
||||||
*/
|
*/
|
||||||
void SetIsSubKey(bool m_sub_key);
|
void SetIsSubKey(bool);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Userid object
|
* @brief Get the Userid object
|
||||||
@ -85,21 +150,21 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
*
|
*
|
||||||
* @param m_name
|
* @param m_name
|
||||||
*/
|
*/
|
||||||
void SetName(const QString &m_name);
|
void SetName(const QString &name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the Email object
|
* @brief Set the Email object
|
||||||
*
|
*
|
||||||
* @param m_email
|
* @param m_email
|
||||||
*/
|
*/
|
||||||
void SetEmail(const QString &m_email);
|
void SetEmail(const QString &email);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the Comment object
|
* @brief Set the Comment object
|
||||||
*
|
*
|
||||||
* @param m_comment
|
* @param m_comment
|
||||||
*/
|
*/
|
||||||
void SetComment(const QString &m_comment);
|
void SetComment(const QString &comment);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Name object
|
* @brief Get the Name object
|
||||||
@ -127,21 +192,14 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
*
|
*
|
||||||
* @return const QString&
|
* @return const QString&
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto GetAlgo() const -> const QString &;
|
[[nodiscard]] auto GetAlgo() const -> const KeyAlgo &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the Algo object
|
* @brief Set the Algo object
|
||||||
*
|
*
|
||||||
* @param m_algo
|
* @param m_algo
|
||||||
*/
|
*/
|
||||||
void SetAlgo(const QString &);
|
void SetAlgo(const KeyAlgo &);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the Key Size Str object
|
|
||||||
*
|
|
||||||
* @return QString
|
|
||||||
*/
|
|
||||||
[[nodiscard]] auto GetKeySizeStr() const -> QString;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Key Size object
|
* @brief Get the Key Size object
|
||||||
@ -150,13 +208,6 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] auto GetKeyLength() const -> int;
|
[[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
|
* @brief Get the Expired object
|
||||||
*
|
*
|
||||||
@ -207,7 +258,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsAllowSigning() const -> bool;
|
[[nodiscard]] auto IsAllowSign() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -222,7 +273,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
*
|
*
|
||||||
* @param m_allow_signing
|
* @param m_allow_signing
|
||||||
*/
|
*/
|
||||||
void SetAllowSigning(bool m_allow_signing);
|
void SetAllowSign(bool m_allow_signing);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -230,14 +281,14 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsAllowEncryption() const -> bool;
|
[[nodiscard]] auto IsAllowEncr() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the Allow Encryption object
|
* @brief Set the Allow Encryption object
|
||||||
*
|
*
|
||||||
* @param m_allow_encryption
|
* @param m_allow_encryption
|
||||||
*/
|
*/
|
||||||
void SetAllowEncryption(bool m_allow_encryption);
|
void SetAllowEncr(bool m_allow_encryption);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -245,14 +296,14 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsAllowCertification() const -> bool;
|
[[nodiscard]] auto IsAllowCert() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the Allow Certification object
|
* @brief Set the Allow Certification object
|
||||||
*
|
*
|
||||||
* @param m_allow_certification
|
* @param m_allow_certification
|
||||||
*/
|
*/
|
||||||
void SetAllowCertification(bool m_allow_certification);
|
void SetAllowCert(bool m_allow_certification);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -260,28 +311,14 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsAllowAuthentication() const -> bool;
|
[[nodiscard]] auto IsAllowAuth() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the Allow Authentication object
|
* @brief Set the Allow Authentication object
|
||||||
*
|
*
|
||||||
* @param m_allow_authentication
|
* @param m_allow_authentication
|
||||||
*/
|
*/
|
||||||
void SetAllowAuthentication(bool m_allow_authentication);
|
void SetAllowAuth(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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -289,7 +326,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsAllowChangeSigning() const -> bool;
|
[[nodiscard]] auto IsAllowModifySign() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -297,7 +334,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsAllowChangeEncryption() const -> bool;
|
[[nodiscard]] auto IsAllowModifyEncr() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -305,7 +342,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsAllowChangeCertification() const -> bool;
|
[[nodiscard]] auto IsAllowModifyCert() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -313,28 +350,7 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsAllowChangeAuthentication() const -> bool;
|
[[nodiscard]] auto IsAllowModifyAuth() 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;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool subkey_ = false; ///<
|
bool subkey_ = false; ///<
|
||||||
@ -342,20 +358,13 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
|
|||||||
QString email_; ///<
|
QString email_; ///<
|
||||||
QString comment_; ///<
|
QString comment_; ///<
|
||||||
|
|
||||||
QString algo_; ///<
|
KeyAlgo algo_; ///<
|
||||||
int key_size_ = 2048;
|
QDateTime expired_;
|
||||||
QDateTime expired_ = QDateTime::currentDateTime().addYears(2);
|
|
||||||
bool non_expired_ = false; ///<
|
bool non_expired_ = false; ///<
|
||||||
|
|
||||||
bool no_passphrase_ = false; ///<
|
bool no_passphrase_ = false; ///<
|
||||||
bool allow_no_pass_phrase_ = true; ///<
|
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_encryption_ = true; ///<
|
||||||
bool allow_change_encryption_ = true; ///<
|
bool allow_change_encryption_ = true; ///<
|
||||||
bool allow_certification_ = true; ///<
|
bool allow_certification_ = true; ///<
|
@ -34,47 +34,60 @@ GpgKeySignature::GpgKeySignature() = default;
|
|||||||
|
|
||||||
GpgKeySignature::~GpgKeySignature() = default;
|
GpgKeySignature::~GpgKeySignature() = default;
|
||||||
|
|
||||||
GpgKeySignature::GpgKeySignature(gpgme_key_sig_t sig)
|
GpgKeySignature::GpgKeySignature(gpgme_key_sig_t sig) : signature_ref_(sig) {}
|
||||||
: signature_ref_(sig, [&](gpgme_key_sig_t signature) {}) {}
|
|
||||||
|
|
||||||
GpgKeySignature::GpgKeySignature(GpgKeySignature &&) noexcept = default;
|
GpgKeySignature::GpgKeySignature(const GpgKeySignature &) = default;
|
||||||
|
auto GpgKeySignature::operator=(const GpgKeySignature &) -> GpgKeySignature & =
|
||||||
|
default;
|
||||||
|
|
||||||
GpgKeySignature &GpgKeySignature::operator=(GpgKeySignature &&) noexcept =
|
auto GpgKeySignature::IsRevoked() const -> bool {
|
||||||
default;
|
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; }
|
auto GpgKeySignature::IsExportable() const -> bool {
|
||||||
|
|
||||||
bool GpgKeySignature::IsExportable() const {
|
|
||||||
return signature_ref_->exportable;
|
return signature_ref_->exportable;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpgme_error_t GpgKeySignature::GetStatus() const {
|
auto GpgKeySignature::GetStatus() const -> gpgme_error_t {
|
||||||
return signature_ref_->status;
|
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);
|
return gpgme_pubkey_algo_name(signature_ref_->pubkey_algo);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime GpgKeySignature::GetCreateTime() const {
|
auto GpgKeySignature::GetCreateTime() const -> QDateTime {
|
||||||
return QDateTime::fromSecsSinceEpoch(signature_ref_->timestamp);
|
return QDateTime::fromSecsSinceEpoch(signature_ref_->timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime GpgKeySignature::GetExpireTime() const {
|
auto GpgKeySignature::GetExpireTime() const -> QDateTime {
|
||||||
return QDateTime::fromSecsSinceEpoch(signature_ref_->expires);
|
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
|
} // namespace GpgFrontend
|
@ -160,34 +160,17 @@ class GPGFRONTEND_CORE_EXPORT GpgKeySignature {
|
|||||||
* @brief Construct a new Gpg Key Signature object
|
* @brief Construct a new Gpg Key Signature object
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
GpgKeySignature(GpgKeySignature &&) noexcept;
|
GpgKeySignature(const GpgKeySignature &);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Construct a new Gpg Key Signature object
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
GpgKeySignature(const GpgKeySignature &) = delete;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* @return GpgKeySignature&
|
* @return GpgKeySignature&
|
||||||
*/
|
*/
|
||||||
auto operator=(GpgKeySignature &&) noexcept -> GpgKeySignature &;
|
auto operator=(const GpgKeySignature &) -> GpgKeySignature &;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @return GpgKeySignature&
|
|
||||||
*/
|
|
||||||
auto operator=(const GpgKeySignature &) -> GpgKeySignature & = delete;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using KeySignatrueRefHandler =
|
gpgme_key_sig_t signature_ref_ = nullptr; ///<
|
||||||
std::unique_ptr<struct _gpgme_key_sig,
|
|
||||||
std::function<void(gpgme_key_sig_t)>>; ///<
|
|
||||||
|
|
||||||
KeySignatrueRefHandler signature_ref_ = nullptr; ///<
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
#include "GpgKeyTableModel.h"
|
#include "GpgKeyTableModel.h"
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "core/function/gpg/GpgKeyGetter.h"
|
#include "core/function/gpg/GpgKeyGetter.h"
|
||||||
#include "core/model/GpgKey.h"
|
#include "core/model/GpgKey.h"
|
||||||
|
|
||||||
@ -62,75 +60,88 @@ auto GpgKeyTableModel::data(const QModelIndex &index,
|
|||||||
int role) const -> QVariant {
|
int role) const -> QVariant {
|
||||||
if (!index.isValid() || buffered_keys_.empty()) return {};
|
if (!index.isValid() || buffered_keys_.empty()) return {};
|
||||||
|
|
||||||
if (role == Qt::TextAlignmentRole) {
|
|
||||||
return Qt::AlignCenter;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (role == Qt::CheckStateRole) {
|
if (role == Qt::CheckStateRole) {
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
return key_check_state_[index.row()] ? Qt::Checked : Qt::Unchecked;
|
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()) {
|
switch (index.column()) {
|
||||||
case 0: {
|
case 0: {
|
||||||
return index.row();
|
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,
|
auto GpgKeyTableModel::headerData(int section, Qt::Orientation orientation,
|
||||||
int role) const -> QVariant {
|
int role) const -> QVariant {
|
||||||
if (role != Qt::DisplayRole) return {};
|
if (role == Qt::DisplayRole) {
|
||||||
|
if (orientation == Qt::Horizontal) {
|
||||||
if (orientation == Qt::Horizontal) {
|
return column_headers_[section];
|
||||||
return column_headers_[section];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +149,7 @@ auto GpgKeyTableModel::flags(const QModelIndex &index) const -> Qt::ItemFlags {
|
|||||||
if (!index.isValid()) return Qt::NoItemFlags;
|
if (!index.isValid()) return Qt::NoItemFlags;
|
||||||
|
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
|
return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
@ -157,8 +168,8 @@ auto GpgKeyTableModel::setData(const QModelIndex &index, const QVariant &value,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgKeyTableModel::GetAllKeyIds() -> GpgKeyIDList {
|
auto GpgKeyTableModel::GetAllKeyIds() -> KeyIdArgsList {
|
||||||
GpgKeyIDList keys;
|
KeyIdArgsList keys;
|
||||||
for (auto &key : buffered_keys_) {
|
for (auto &key : buffered_keys_) {
|
||||||
keys.push_back(key.GetId());
|
keys.push_back(key.GetId());
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableModel : public QAbstractTableModel {
|
|||||||
*
|
*
|
||||||
* @return auto
|
* @return auto
|
||||||
*/
|
*/
|
||||||
auto GetAllKeyIds() -> GpgKeyIDList;
|
auto GetAllKeyIds() -> KeyIdArgsList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Key ID By Row object
|
* @brief Get the Key ID By Row object
|
||||||
@ -216,11 +216,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableModel : public QAbstractTableModel {
|
|||||||
QStringList column_headers_;
|
QStringList column_headers_;
|
||||||
int gpg_context_channel_;
|
int gpg_context_channel_;
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 4)
|
QContainer<bool> key_check_state_;
|
||||||
QList<bool> key_check_state_;
|
|
||||||
#else
|
|
||||||
QVector<bool> key_check_state_;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
@ -47,8 +47,8 @@ auto GpgSignResult::GetRaw() -> gpgme_sign_result_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GpgSignResult::InvalidSigners()
|
auto GpgSignResult::InvalidSigners()
|
||||||
-> std::vector<std::tuple<QString, GpgError>> {
|
-> QContainer<std::tuple<QString, GpgError>> {
|
||||||
std::vector<std::tuple<QString, GpgError>> result;
|
QContainer<std::tuple<QString, GpgError>> result;
|
||||||
for (auto* invalid_key = result_ref_->invalid_signers; invalid_key != nullptr;
|
for (auto* invalid_key = result_ref_->invalid_signers; invalid_key != nullptr;
|
||||||
invalid_key = invalid_key->next) {
|
invalid_key = invalid_key->next) {
|
||||||
try {
|
try {
|
||||||
|
@ -41,7 +41,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSignResult {
|
|||||||
|
|
||||||
auto HashAlgo() -> QString;
|
auto HashAlgo() -> QString;
|
||||||
|
|
||||||
auto InvalidSigners() -> std::vector<std::tuple<QString, GpgError>>;
|
auto InvalidSigners() -> QContainer<std::tuple<QString, GpgError>>;
|
||||||
|
|
||||||
explicit GpgSignResult(gpgme_sign_result_t);
|
explicit GpgSignResult(gpgme_sign_result_t);
|
||||||
|
|
||||||
|
@ -30,27 +30,15 @@
|
|||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
/**
|
GpgSignature::GpgSignature() = default;
|
||||||
* @brief Construct a new Gpg Signature object
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
GpgSignature::GpgSignature(GpgSignature &&) noexcept = default;
|
|
||||||
|
|
||||||
/**
|
GpgSignature::GpgSignature(gpgme_signature_t sig) : signature_ref_(sig) {}
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @return GpgSignature&
|
|
||||||
*/
|
|
||||||
auto GpgSignature::operator=(GpgSignature &&) noexcept -> GpgSignature & =
|
|
||||||
default;
|
|
||||||
|
|
||||||
/**
|
GpgSignature::~GpgSignature() = default;
|
||||||
* @brief Construct a new Gpg Signature:: Gpg Signature object
|
|
||||||
*
|
GpgSignature::GpgSignature(const GpgSignature &) = default;
|
||||||
* @param sig
|
|
||||||
*/
|
auto GpgSignature::operator=(const GpgSignature &) -> GpgSignature & = default;
|
||||||
GpgSignature::GpgSignature(gpgme_signature_t sig)
|
|
||||||
: signature_ref_(sig, [&](gpgme_signature_t signature) {}) {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -124,16 +112,4 @@ auto GpgSignature::GetFingerprint() const -> QString {
|
|||||||
return signature_ref_->fpr != nullptr ? signature_ref_->fpr : "";
|
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
|
} // namespace GpgFrontend
|
||||||
|
@ -117,33 +117,16 @@ class GPGFRONTEND_CORE_EXPORT GpgSignature {
|
|||||||
* @brief Construct a new Gpg Signature object
|
* @brief Construct a new Gpg Signature object
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
GpgSignature(GpgSignature &&) noexcept;
|
GpgSignature(const GpgSignature &);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Construct a new Gpg Signature object
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
GpgSignature(const GpgSignature &) = delete;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* @return GpgSignature&
|
* @return GpgSignature&
|
||||||
*/
|
*/
|
||||||
auto operator=(GpgSignature &&) noexcept -> GpgSignature &;
|
auto operator=(const GpgSignature &) -> GpgSignature &;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @return GpgSignature&
|
|
||||||
*/
|
|
||||||
auto operator=(const GpgSignature &) -> GpgSignature & = delete;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using KeySignatrueRefHandler =
|
gpgme_signature_t signature_ref_ = nullptr; ///<
|
||||||
std::unique_ptr<struct _gpgme_signature,
|
|
||||||
std::function<void(gpgme_signature_t)>>; ///<
|
|
||||||
|
|
||||||
KeySignatrueRefHandler signature_ref_ = nullptr; ///<
|
|
||||||
};
|
};
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -31,17 +31,11 @@ namespace GpgFrontend {
|
|||||||
|
|
||||||
GpgSubKey::GpgSubKey() = default;
|
GpgSubKey::GpgSubKey() = default;
|
||||||
|
|
||||||
GpgSubKey::GpgSubKey(gpgme_subkey_t subkey)
|
GpgSubKey::GpgSubKey(gpgme_subkey_t subkey) : subkey_ref_(subkey) {}
|
||||||
: subkey_ref_(subkey, [&](gpgme_subkey_t subkey) {}) {}
|
|
||||||
|
|
||||||
GpgSubKey::GpgSubKey(GpgSubKey&& o) noexcept {
|
GpgSubKey::GpgSubKey(const GpgSubKey&) = default;
|
||||||
swap(subkey_ref_, o.subkey_ref_);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GpgSubKey::operator=(GpgSubKey&& o) noexcept -> GpgSubKey& {
|
auto GpgSubKey::operator=(const GpgSubKey&) -> GpgSubKey& = default;
|
||||||
swap(subkey_ref_, o.subkey_ref_);
|
|
||||||
return *this;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto GpgSubKey::operator==(const GpgSubKey& o) const -> bool {
|
auto GpgSubKey::operator==(const GpgSubKey& o) const -> bool {
|
||||||
return GetFingerprint() == o.GetFingerprint();
|
return GetFingerprint() == o.GetFingerprint();
|
||||||
@ -56,7 +50,7 @@ auto GpgSubKey::GetPubkeyAlgo() const -> QString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GpgSubKey::GetKeyAlgo() 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);
|
auto algo = QString(buffer);
|
||||||
gpgme_free(buffer);
|
gpgme_free(buffer);
|
||||||
return algo.toUpper();
|
return algo.toUpper();
|
||||||
@ -66,19 +60,17 @@ auto GpgSubKey::GetKeyLength() const -> unsigned int {
|
|||||||
return subkey_ref_->length;
|
return subkey_ref_->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgSubKey::IsHasEncryptionCapability() const -> bool {
|
auto GpgSubKey::IsHasEncrCap() const -> bool {
|
||||||
return subkey_ref_->can_encrypt;
|
return subkey_ref_->can_encrypt;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgSubKey::IsHasSigningCapability() const -> bool {
|
auto GpgSubKey::IsHasSignCap() const -> bool { return subkey_ref_->can_sign; }
|
||||||
return subkey_ref_->can_sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GpgSubKey::IsHasCertificationCapability() const -> bool {
|
auto GpgSubKey::IsHasCertCap() const -> bool {
|
||||||
return subkey_ref_->can_certify;
|
return subkey_ref_->can_certify;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgSubKey::IsHasAuthenticationCapability() const -> bool {
|
auto GpgSubKey::IsHasAuthCap() const -> bool {
|
||||||
return subkey_ref_->can_authenticate;
|
return subkey_ref_->can_authenticate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasEncryptionCapability() const -> bool;
|
[[nodiscard]] auto IsHasEncrCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -89,7 +89,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasSigningCapability() const -> bool;
|
[[nodiscard]] auto IsHasSignCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -97,7 +97,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasCertificationCapability() const -> bool;
|
[[nodiscard]] auto IsHasCertCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -105,7 +105,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
|
|||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto IsHasAuthenticationCapability() const -> bool;
|
[[nodiscard]] auto IsHasAuthCap() const -> bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -185,30 +185,15 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
|
|||||||
/**
|
/**
|
||||||
* @brief Construct a new Gpg Sub Key object
|
* @brief Construct a new Gpg Sub Key object
|
||||||
*
|
*
|
||||||
* @param o
|
|
||||||
*/
|
*/
|
||||||
GpgSubKey(GpgSubKey&& o) noexcept;
|
GpgSubKey(const GpgSubKey&);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Construct a new Gpg Sub Key object
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
GpgSubKey(const GpgSubKey&) = delete;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param o
|
|
||||||
* @return GpgSubKey&
|
|
||||||
*/
|
|
||||||
auto operator=(GpgSubKey&& o) noexcept -> GpgSubKey&;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* @return GpgSubKey&
|
* @return GpgSubKey&
|
||||||
*/
|
*/
|
||||||
auto operator=(const GpgSubKey&) -> GpgSubKey& = delete;
|
auto operator=(const GpgSubKey&) -> GpgSubKey&;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -220,11 +205,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey {
|
|||||||
auto operator==(const GpgSubKey& o) const -> bool;
|
auto operator==(const GpgSubKey& o) const -> bool;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using SubkeyRefHandler =
|
gpgme_subkey_t subkey_ref_ = nullptr; ///<
|
||||||
std::unique_ptr<struct _gpgme_subkey,
|
|
||||||
std::function<void(gpgme_subkey_t)>>; ///<
|
|
||||||
|
|
||||||
SubkeyRefHandler subkey_ref_ = nullptr; ///<
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -33,16 +33,11 @@ namespace GpgFrontend {
|
|||||||
GpgTOFUInfo::GpgTOFUInfo() = default;
|
GpgTOFUInfo::GpgTOFUInfo() = default;
|
||||||
|
|
||||||
GpgTOFUInfo::GpgTOFUInfo(gpgme_tofu_info_t tofu_info)
|
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 {
|
GpgTOFUInfo::GpgTOFUInfo(const GpgTOFUInfo&) = default;
|
||||||
swap(tofu_info_ref_, o.tofu_info_ref_);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GpgTOFUInfo::operator=(GpgTOFUInfo&& o) noexcept -> GpgTOFUInfo& {
|
auto GpgTOFUInfo::operator=(const GpgTOFUInfo&) -> GpgTOFUInfo& = default;
|
||||||
swap(tofu_info_ref_, o.tofu_info_ref_);
|
|
||||||
return *this;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto GpgTOFUInfo::GetValidity() const -> unsigned {
|
auto GpgTOFUInfo::GetValidity() const -> unsigned {
|
||||||
return tofu_info_ref_->validity;
|
return tofu_info_ref_->validity;
|
||||||
@ -64,29 +59,14 @@ auto GpgTOFUInfo::GetSignFirst() const -> unsigned long {
|
|||||||
return tofu_info_ref_->signfirst;
|
return tofu_info_ref_->signfirst;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @return unsigned long
|
|
||||||
*/
|
|
||||||
auto GpgTOFUInfo::GetSignLast() const -> unsigned long {
|
auto GpgTOFUInfo::GetSignLast() const -> unsigned long {
|
||||||
return tofu_info_ref_->signlast;
|
return tofu_info_ref_->signlast;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @return unsigned long
|
|
||||||
*/
|
|
||||||
auto GpgTOFUInfo::GetEncrLast() const -> unsigned long {
|
auto GpgTOFUInfo::GetEncrLast() const -> unsigned long {
|
||||||
return tofu_info_ref_->encrlast;
|
return tofu_info_ref_->encrlast;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @return QString
|
|
||||||
*/
|
|
||||||
auto GpgTOFUInfo::GetDescription() const -> QString {
|
auto GpgTOFUInfo::GetDescription() const -> QString {
|
||||||
return tofu_info_ref_->description;
|
return tofu_info_ref_->description;
|
||||||
}
|
}
|
||||||
|
@ -110,37 +110,18 @@ class GPGFRONTEND_CORE_EXPORT GpgTOFUInfo {
|
|||||||
/**
|
/**
|
||||||
* @brief Construct a new Gpg T O F U Info object
|
* @brief Construct a new Gpg T O F U Info object
|
||||||
*
|
*
|
||||||
* @param o
|
|
||||||
*/
|
*/
|
||||||
GpgTOFUInfo(GpgTOFUInfo&& o) noexcept;
|
GpgTOFUInfo(const GpgTOFUInfo&);
|
||||||
|
|
||||||
/**
|
|
||||||
* @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&;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* @return GpgTOFUInfo&
|
* @return GpgTOFUInfo&
|
||||||
*/
|
*/
|
||||||
auto operator=(const GpgTOFUInfo&) -> GpgTOFUInfo& = delete;
|
auto operator=(const GpgTOFUInfo&) -> GpgTOFUInfo&;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using SubkeyRefHandler =
|
gpgme_tofu_info_t tofu_info_ref_ = nullptr; ///<
|
||||||
std::unique_ptr<struct _gpgme_tofu_info,
|
|
||||||
std::function<void(gpgme_tofu_info_t)>>; ///<
|
|
||||||
|
|
||||||
SubkeyRefHandler tofu_info_ref_ = nullptr; ///<
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -32,10 +32,11 @@ namespace GpgFrontend {
|
|||||||
|
|
||||||
GpgUID::GpgUID() = default;
|
GpgUID::GpgUID() = default;
|
||||||
|
|
||||||
GpgUID::GpgUID(gpgme_user_id_t uid)
|
GpgUID::GpgUID(gpgme_user_id_t uid) : uid_ref_(uid) {}
|
||||||
: uid_ref_(uid, [&](gpgme_user_id_t 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; }
|
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::GetInvalid() const -> bool { return uid_ref_->invalid; }
|
||||||
|
|
||||||
auto GpgUID::GetTofuInfos() const -> std::unique_ptr<std::vector<GpgTOFUInfo>> {
|
auto GpgUID::GetTofuInfos() const -> std::unique_ptr<QContainer<GpgTOFUInfo>> {
|
||||||
auto infos = std::make_unique<std::vector<GpgTOFUInfo>>();
|
auto infos = std::make_unique<QContainer<GpgTOFUInfo>>();
|
||||||
auto *info_next = uid_ref_->tofu;
|
auto *info_next = uid_ref_->tofu;
|
||||||
while (info_next != nullptr) {
|
while (info_next != nullptr) {
|
||||||
infos->push_back(GpgTOFUInfo(info_next));
|
infos->push_back(GpgTOFUInfo(info_next));
|
||||||
@ -60,8 +61,8 @@ auto GpgUID::GetTofuInfos() const -> std::unique_ptr<std::vector<GpgTOFUInfo>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GpgUID::GetSignatures() const
|
auto GpgUID::GetSignatures() const
|
||||||
-> std::unique_ptr<std::vector<GpgKeySignature>> {
|
-> std::unique_ptr<QContainer<GpgKeySignature>> {
|
||||||
auto sigs = std::make_unique<std::vector<GpgKeySignature>>();
|
auto sigs = std::make_unique<QContainer<GpgKeySignature>>();
|
||||||
auto *sig_next = uid_ref_->signatures;
|
auto *sig_next = uid_ref_->signatures;
|
||||||
while (sig_next != nullptr) {
|
while (sig_next != nullptr) {
|
||||||
sigs->push_back(GpgKeySignature(sig_next));
|
sigs->push_back(GpgKeySignature(sig_next));
|
||||||
|
@ -85,18 +85,18 @@ class GPGFRONTEND_CORE_EXPORT GpgUID {
|
|||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* @return std::unique_ptr<std::vector<GpgTOFUInfo>>
|
* @return std::unique_ptr<QContainer<GpgTOFUInfo>>
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto GetTofuInfos() const
|
[[nodiscard]] auto GetTofuInfos() const
|
||||||
-> std::unique_ptr<std::vector<GpgTOFUInfo>>;
|
-> std::unique_ptr<QContainer<GpgTOFUInfo>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* @return std::unique_ptr<std::vector<GpgKeySignature>>
|
* @return std::unique_ptr<QContainer<GpgKeySignature>>
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto GetSignatures() const
|
[[nodiscard]] auto GetSignatures() const
|
||||||
-> std::unique_ptr<std::vector<GpgKeySignature>>;
|
-> std::unique_ptr<QContainer<GpgKeySignature>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Gpg U I D object
|
* @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);
|
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
|
* @brief
|
||||||
*
|
*
|
||||||
* @param o
|
|
||||||
* @return GpgUID&
|
|
||||||
*/
|
*/
|
||||||
auto operator=(GpgUID &&o) noexcept -> GpgUID &;
|
GpgUID(const GpgUID &);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* @return GpgUID&
|
* @return GpgUID&
|
||||||
*/
|
*/
|
||||||
auto operator=(const GpgUID &) -> GpgUID & = delete;
|
auto operator=(const GpgUID &) -> GpgUID &;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using UidRefHandler =
|
gpgme_user_id_t uid_ref_ = nullptr; ///<
|
||||||
std::unique_ptr<struct _gpgme_user_id,
|
|
||||||
std::function<void(gpgme_user_id_t)>>; ///<
|
|
||||||
|
|
||||||
UidRefHandler uid_ref_ = nullptr; ///<
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
||||||
|
@ -49,8 +49,8 @@ auto GpgVerifyResult::GetRaw() const -> gpgme_verify_result_t {
|
|||||||
return result_ref_.get();
|
return result_ref_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GpgVerifyResult::GetSignature() const -> std::vector<GpgSignature> {
|
auto GpgVerifyResult::GetSignature() const -> QContainer<GpgSignature> {
|
||||||
std::vector<GpgSignature> sigatures;
|
QContainer<GpgSignature> sigatures;
|
||||||
|
|
||||||
auto* signature = result_ref_->signatures;
|
auto* signature = result_ref_->signatures;
|
||||||
while (signature != nullptr) {
|
while (signature != nullptr) {
|
||||||
|
@ -39,7 +39,7 @@ class GPGFRONTEND_CORE_EXPORT GpgVerifyResult {
|
|||||||
|
|
||||||
[[nodiscard]] auto GetRaw() const -> gpgme_verify_result_t;
|
[[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);
|
explicit GpgVerifyResult(gpgme_verify_result_t);
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ struct KeyDatabaseInfo {
|
|||||||
int channel;
|
int channel;
|
||||||
QString name;
|
QString name;
|
||||||
QString path;
|
QString path;
|
||||||
|
QString origin_path;
|
||||||
|
|
||||||
KeyDatabaseInfo() = default;
|
KeyDatabaseInfo() = default;
|
||||||
};
|
};
|
||||||
|
@ -43,7 +43,7 @@ class Event;
|
|||||||
using EventReference = std::shared_ptr<Event>;
|
using EventReference = std::shared_ptr<Event>;
|
||||||
using EventIdentifier = QString;
|
using EventIdentifier = QString;
|
||||||
using EventTriggerIdentifier = QString;
|
using EventTriggerIdentifier = QString;
|
||||||
using Evnets = std::vector<Event>;
|
using Evnets = QContainer<Event>;
|
||||||
|
|
||||||
class GPGFRONTEND_CORE_EXPORT Event {
|
class GPGFRONTEND_CORE_EXPORT Event {
|
||||||
public:
|
public:
|
||||||
|
@ -352,7 +352,7 @@ class GlobalModuleContext::Impl {
|
|||||||
bool registered;
|
bool registered;
|
||||||
bool activate;
|
bool activate;
|
||||||
bool integrated;
|
bool integrated;
|
||||||
QList<QString> listening_event_ids;
|
QStringList listening_event_ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ModuleRegisterInfoPtr = std::shared_ptr<ModuleRegisterInfo>;
|
using ModuleRegisterInfoPtr = std::shared_ptr<ModuleRegisterInfo>;
|
||||||
|
@ -107,10 +107,10 @@ class GlobalRegisterTable::Impl {
|
|||||||
return rtn;
|
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('.');
|
QStringList const segments = (n + "." + k).split('.');
|
||||||
|
|
||||||
std::vector<Key> rtn;
|
QContainer<Key> rtn;
|
||||||
{
|
{
|
||||||
std::shared_lock lock(lock_);
|
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);
|
return p_->ListenPublish(o, n, k, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GlobalRegisterTable::ListChildKeys(Namespace n,
|
auto GlobalRegisterTable::ListChildKeys(Namespace n, Key k) -> QContainer<Key> {
|
||||||
Key k) -> std::vector<Key> {
|
|
||||||
return p_->ListChildKeys(n, k);
|
return p_->ListChildKeys(n, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "core/function/SecureMemoryAllocator.h"
|
#include "core/function/SecureMemoryAllocator.h"
|
||||||
|
#include "core/typedef/CoreTypedef.h"
|
||||||
|
|
||||||
namespace GpgFrontend::Module {
|
namespace GpgFrontend::Module {
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ class GlobalRegisterTable : public QObject {
|
|||||||
|
|
||||||
auto ListenPublish(QObject *, Namespace, Key, LPCallback) -> bool;
|
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:
|
signals:
|
||||||
void SignalPublish(Namespace, Key, int, std::any);
|
void SignalPublish(Namespace, Key, int, std::any);
|
||||||
|
@ -78,10 +78,7 @@ auto LoadExternalMods() -> QMap<QString, bool> {
|
|||||||
void LoadGpgFrontendModules(ModuleInitArgs) {
|
void LoadGpgFrontendModules(ModuleInitArgs) {
|
||||||
// give user ability to give up all modules
|
// give user ability to give up all modules
|
||||||
auto disable_loading_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;
|
if (disable_loading_all_modules) return;
|
||||||
|
|
||||||
// must init at default thread before core
|
// must init at default thread before core
|
||||||
|
@ -220,7 +220,7 @@ class ModuleManager::Impl {
|
|||||||
return grt_->ListenPublish(o, n, k, c);
|
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);
|
return grt_->ListChildKeys(n, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +271,7 @@ auto ListenRTPublishEvent(QObject* o, Namespace n, Key k,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto ListRTChildKeys(const QString& namespace_,
|
auto ListRTChildKeys(const QString& namespace_,
|
||||||
const QString& key) -> std::vector<Key> {
|
const QString& key) -> QContainer<Key> {
|
||||||
return ModuleManager::GetInstance().ListRTChildKeys(namespace_, 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,
|
auto ModuleManager::ListRTChildKeys(const QString& n,
|
||||||
const QString& k) -> std::vector<Key> {
|
const QString& k) -> QContainer<Key> {
|
||||||
return p_->ListRTChildKeys(n, k);
|
return p_->ListRTChildKeys(n, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager
|
|||||||
|
|
||||||
auto ListenRTPublish(QObject*, Namespace, Key, LPCallback) -> bool;
|
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*;
|
auto GRT() -> GlobalRegisterTable*;
|
||||||
|
|
||||||
@ -175,10 +175,10 @@ auto GPGFRONTEND_CORE_EXPORT ListenRTPublishEvent(QObject*, Namespace, Key,
|
|||||||
*
|
*
|
||||||
* @param namespace_
|
* @param namespace_
|
||||||
* @param key
|
* @param key
|
||||||
* @return std::vector<Key>
|
* @return QContainer<Key>
|
||||||
*/
|
*/
|
||||||
auto GPGFRONTEND_CORE_EXPORT ListRTChildKeys(
|
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>
|
template <typename T>
|
||||||
auto RetrieveRTValueTyped(const QString& namespace_,
|
auto RetrieveRTValueTyped(const QString& namespace_,
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
struct FavoriteKeyPairsByKeyDatabaseCO {
|
struct FavoriteKeyPairsByKeyDatabaseCO {
|
||||||
QList<QString> key_ids;
|
QStringList key_ids;
|
||||||
|
|
||||||
FavoriteKeyPairsByKeyDatabaseCO() = default;
|
FavoriteKeyPairsByKeyDatabaseCO() = default;
|
||||||
|
|
||||||
|
@ -35,12 +35,14 @@ namespace GpgFrontend {
|
|||||||
struct KeyDatabaseItemSO {
|
struct KeyDatabaseItemSO {
|
||||||
QString name;
|
QString name;
|
||||||
QString path;
|
QString path;
|
||||||
|
int channel;
|
||||||
|
|
||||||
KeyDatabaseItemSO() = default;
|
KeyDatabaseItemSO() = default;
|
||||||
|
|
||||||
explicit KeyDatabaseItemSO(KeyDatabaseInfo i) {
|
explicit KeyDatabaseItemSO(KeyDatabaseInfo i) {
|
||||||
name = i.name;
|
name = i.name;
|
||||||
path = i.path;
|
path = i.origin_path.isEmpty() ? i.path : i.origin_path;
|
||||||
|
channel = i.channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit KeyDatabaseItemSO(const QJsonObject& j) {
|
explicit KeyDatabaseItemSO(const QJsonObject& j) {
|
||||||
@ -50,12 +52,16 @@ struct KeyDatabaseItemSO {
|
|||||||
if (const auto v = j["path"]; v.isString()) {
|
if (const auto v = j["path"]; v.isString()) {
|
||||||
path = v.toString();
|
path = v.toString();
|
||||||
}
|
}
|
||||||
|
if (const auto v = j["channel"]; v.isDouble()) {
|
||||||
|
channel = v.toInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto ToJson() const -> QJsonObject {
|
[[nodiscard]] auto ToJson() const -> QJsonObject {
|
||||||
QJsonObject j;
|
QJsonObject j;
|
||||||
j["name"] = name;
|
j["name"] = name;
|
||||||
j["path"] = path;
|
j["path"] = path;
|
||||||
|
j["channel"] = channel;
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -28,22 +28,25 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/model/DataObject.h"
|
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
using GFError = uint32_t;
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
using ByteArray = QByteArray; ///<
|
template <typename T>
|
||||||
using ByteArrayPtr = std::shared_ptr<ByteArray>; ///<
|
using QContainer = QVector<T>;
|
||||||
using StdBypeArrayPtr = std::shared_ptr<ByteArray>; ///<
|
#else
|
||||||
using BypeArrayRef = ByteArray&; ///<
|
template <typename T>
|
||||||
using ConstBypeArrayRef = const ByteArray&; ///<
|
using QContainer = QList<T>;
|
||||||
using BypeArrayConstRef = const ByteArray&; ///<
|
#endif
|
||||||
using StringArgsPtr = std::unique_ptr<std::vector<QString>>; ///<
|
|
||||||
using StringArgsRef = std::vector<QString>&; ///<
|
|
||||||
///
|
|
||||||
///
|
|
||||||
|
|
||||||
|
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 OperaRunnable = std::function<GFError(DataObjectPtr)>;
|
||||||
using OperationCallback = std::function<void(GFError, DataObjectPtr)>;
|
using OperationCallback = std::function<void(GFError, DataObjectPtr)>;
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
@ -30,7 +30,10 @@
|
|||||||
|
|
||||||
#include <gpgme.h>
|
#include <gpgme.h>
|
||||||
|
|
||||||
|
#include <future>
|
||||||
|
|
||||||
#include "core/model/DataObject.h"
|
#include "core/model/DataObject.h"
|
||||||
|
#include "core/typedef/CoreTypedef.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
@ -41,25 +44,16 @@ class GpgTOFUInfo;
|
|||||||
|
|
||||||
using GpgError = gpgme_error_t; ///< gpgme error
|
using GpgError = gpgme_error_t; ///< gpgme error
|
||||||
using GpgErrorCode = gpg_err_code_t;
|
using GpgErrorCode = gpg_err_code_t;
|
||||||
using GpgErrorDesc = std::pair<QString, QString>;
|
using GpgErrorDesc = QPair<QString, QString>;
|
||||||
|
|
||||||
using KeyId = QString; ///<
|
using KeyId = QString;
|
||||||
using SubkeyId = QString; ///<
|
using SubkeyId = QString;
|
||||||
using KeyIdArgsList = std::vector<KeyId>; ///<
|
using KeyIdArgsList = QStringList; ///<
|
||||||
using KeyIdArgsListPtr = std::unique_ptr<KeyIdArgsList>; ///<
|
using UIDArgsList = QStringList; ///<
|
||||||
using UIDArgsList = std::vector<QString>; ///<
|
using SignIdArgsList = QContainer<QPair<QString, QString>>; ///<
|
||||||
using UIDArgsListPtr = std::unique_ptr<UIDArgsList>; ///<
|
using KeyArgsList = QContainer<GpgKey>; ///<
|
||||||
using SignIdArgsList = std::vector<std::pair<QString, QString>>; ///<
|
using GpgKeyLinkList = QContainer<GpgKey>; ///<
|
||||||
using SignIdArgsListPtr = std::unique_ptr<SignIdArgsList>; ///<
|
using GpgKeyList = QContainer<GpgKey>; ///<
|
||||||
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 GpgSignMode = gpgme_sig_mode_t;
|
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>>;
|
using GpgOperationFuture = std::future<std::tuple<GpgError, DataObjectPtr>>;
|
||||||
|
|
||||||
enum GpgOperation {
|
enum GpgOperation {
|
||||||
kENCRYPT,
|
kNONE = 0,
|
||||||
kDECRYPT,
|
kENCRYPT = 1 << 0,
|
||||||
kSIGN,
|
kDECRYPT = 1 << 1,
|
||||||
kVERIFY,
|
kSIGN = 1 << 2,
|
||||||
kENCRYPT_SIGN,
|
kVERIFY = 1 << 3,
|
||||||
kDECRYPT_VERIFY
|
kENCRYPT_SIGN = 1 << 4,
|
||||||
|
kDECRYPT_VERIFY = 1 << 5,
|
||||||
|
kAUTH = 1 << 6,
|
||||||
|
kCERT = 1 << 7,
|
||||||
};
|
};
|
||||||
} // namespace GpgFrontend
|
} // namespace GpgFrontend
|
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#include "CommonUtils.h"
|
#include "CommonUtils.h"
|
||||||
|
|
||||||
|
#include "core/utils/MemoryUtils.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
auto BeautifyFingerprint(QString fingerprint) -> QString {
|
auto BeautifyFingerprint(QString fingerprint) -> QString {
|
||||||
|
@ -28,15 +28,19 @@
|
|||||||
|
|
||||||
#include "GpgUtils.h"
|
#include "GpgUtils.h"
|
||||||
|
|
||||||
|
#include "core/function/GlobalSettingStation.h"
|
||||||
|
#include "core/model/GpgKey.h"
|
||||||
#include "core/model/KeyDatabaseInfo.h"
|
#include "core/model/KeyDatabaseInfo.h"
|
||||||
|
#include "core/model/SettingsObject.h"
|
||||||
#include "core/module/ModuleManager.h"
|
#include "core/module/ModuleManager.h"
|
||||||
|
#include "core/struct/settings_object/KeyDatabaseListSO.h"
|
||||||
|
|
||||||
namespace GpgFrontend {
|
namespace GpgFrontend {
|
||||||
|
|
||||||
inline auto Trim(QString& s) -> QString { return s.trimmed(); }
|
inline auto Trim(QString& s) -> QString { return s.trimmed(); }
|
||||||
|
|
||||||
auto GetGpgmeErrorString(size_t buffer_size, gpgme_error_t err) -> QString {
|
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());
|
gpgme_error_t const ret = gpgme_strerror_r(err, buffer.data(), buffer.size());
|
||||||
if (ret == ERANGE && buffer_size < 1024) {
|
if (ret == ERANGE && buffer_size < 1024) {
|
||||||
@ -218,4 +222,115 @@ auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseName(int channel) -> QString {
|
|||||||
if (channel >= info.size()) return {};
|
if (channel >= info.size()) return {};
|
||||||
return info[channel].name;
|
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
|
} // namespace GpgFrontend
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "core/function/result_analyse/GpgResultAnalyse.h"
|
#include "core/function/result_analyse/GpgResultAnalyse.h"
|
||||||
#include "core/model/KeyDatabaseInfo.h"
|
#include "core/model/KeyDatabaseInfo.h"
|
||||||
|
#include "core/struct/settings_object/KeyDatabaseItemSO.h"
|
||||||
#include "core/typedef/CoreTypedef.h"
|
#include "core/typedef/CoreTypedef.h"
|
||||||
#include "core/typedef/GpgTypedef.h"
|
#include "core/typedef/GpgTypedef.h"
|
||||||
|
|
||||||
@ -106,6 +107,32 @@ auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFile(const QString& path,
|
|||||||
auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFileForArchive(
|
auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFileForArchive(
|
||||||
const QString& path, GpgOperation opera, bool ascii) -> QString;
|
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
|
* @brief
|
||||||
*
|
*
|
||||||
@ -120,4 +147,13 @@ auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseInfos() -> QList<KeyDatabaseInfo>;
|
|||||||
*/
|
*/
|
||||||
auto GPGFRONTEND_CORE_EXPORT GetGpgKeyDatabaseName(int channel) -> QString;
|
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
|
} // namespace GpgFrontend
|
44
src/init.cpp
44
src/init.cpp
@ -57,16 +57,12 @@ int setenv(const char *name, const char *value, int overwrite) {
|
|||||||
void InitGlobalPathEnv() {
|
void InitGlobalPathEnv() {
|
||||||
// read settings
|
// read settings
|
||||||
bool use_custom_gnupg_install_path =
|
bool use_custom_gnupg_install_path =
|
||||||
GlobalSettingStation::GetInstance()
|
GetSettings()
|
||||||
.GetSettings()
|
|
||||||
.value("gnupg/use_custom_gnupg_install_path", false)
|
.value("gnupg/use_custom_gnupg_install_path", false)
|
||||||
.toBool();
|
.toBool();
|
||||||
|
|
||||||
QString custom_gnupg_install_path =
|
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
|
// add custom gnupg install path into env $PATH
|
||||||
if (use_custom_gnupg_install_path && !custom_gnupg_install_path.isEmpty()) {
|
if (use_custom_gnupg_install_path && !custom_gnupg_install_path.isEmpty()) {
|
||||||
@ -79,10 +75,7 @@ void InitGlobalPathEnv() {
|
|||||||
QString modified_path_value = getenv("PATH");
|
QString modified_path_value = getenv("PATH");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GlobalSettingStation::GetInstance()
|
if (GetSettings().value("gnupg/enable_gpgme_debug_log", false).toBool()) {
|
||||||
.GetSettings()
|
|
||||||
.value("gnupg/enable_gpgme_debug_log", false)
|
|
||||||
.toBool()) {
|
|
||||||
qputenv("GPGME_DEBUG",
|
qputenv("GPGME_DEBUG",
|
||||||
QString("9:%1").arg(QDir::currentPath() + "/gpgme.log").toUtf8());
|
QString("9:%1").arg(QDir::currentPath() + "/gpgme.log").toUtf8());
|
||||||
}
|
}
|
||||||
@ -142,8 +135,7 @@ void InitGlobalBasicEnv(const GFCxtWPtr &p_ctx, bool gui_mode) {
|
|||||||
*/
|
*/
|
||||||
void InitLocale() {
|
void InitLocale() {
|
||||||
// get the instance of the GlobalSettingStation
|
// get the instance of the GlobalSettingStation
|
||||||
auto settings =
|
auto settings = GpgFrontend::GetSettings();
|
||||||
GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
|
|
||||||
|
|
||||||
// read from settings file
|
// read from settings file
|
||||||
auto lang = settings.value("basic/lang").toString();
|
auto lang = settings.value("basic/lang").toString();
|
||||||
@ -184,18 +176,30 @@ void ShutdownGlobalBasicEnv(const GFCxtWPtr &p_ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto clear_gpg_password_cache =
|
auto clear_gpg_password_cache =
|
||||||
GlobalSettingStation::GetInstance()
|
GetSettings().value("basic/clear_gpg_password_cache", false).toBool();
|
||||||
.GetSettings()
|
|
||||||
.value("basic/clear_gpg_password_cache", false)
|
auto kill_all_gnupg_daemon_at_close =
|
||||||
|
GetSettings()
|
||||||
|
.value("gnupg/kill_all_gnupg_daemon_at_close", false)
|
||||||
.toBool();
|
.toBool();
|
||||||
// clear password cache
|
|
||||||
if (!ctx->unit_test_mode && clear_gpg_password_cache) {
|
if (ctx->unit_test_mode || kill_all_gnupg_daemon_at_close) {
|
||||||
GpgAdvancedOperator::ClearGpgPasswordCache([](int, DataObjectPtr) {});
|
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
|
} // namespace GpgFrontend
|
||||||
|
@ -171,7 +171,7 @@ TEST_F(GpgCoreTest, CoreSignVerifyNormalTest) {
|
|||||||
GpgBasicOperator::GetInstance().VerifySync(sign_out_buffer, GFBuffer());
|
GpgBasicOperator::GetInstance().VerifySync(sign_out_buffer, GFBuffer());
|
||||||
|
|
||||||
ASSERT_EQ(CheckGpgError(err_0), GPG_ERR_NO_ERROR);
|
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);
|
auto verify_result = ExtractParams<GpgVerifyResult>(data_object_0, 0);
|
||||||
ASSERT_FALSE(verify_result.GetSignature().empty());
|
ASSERT_FALSE(verify_result.GetSignature().empty());
|
||||||
ASSERT_EQ(verify_result.GetSignature().at(0).GetFingerprint(),
|
ASSERT_EQ(verify_result.GetSignature().at(0).GetFingerprint(),
|
||||||
@ -198,7 +198,7 @@ TEST_F(GpgCoreTest, CoreSignVerifyDetachTest) {
|
|||||||
GpgBasicOperator::GetInstance().VerifySync(sign_text, sign_out_buffer);
|
GpgBasicOperator::GetInstance().VerifySync(sign_text, sign_out_buffer);
|
||||||
|
|
||||||
ASSERT_EQ(CheckGpgError(err_0), GPG_ERR_NO_ERROR);
|
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);
|
auto verify_result = ExtractParams<GpgVerifyResult>(data_object_0, 0);
|
||||||
ASSERT_FALSE(verify_result.GetSignature().empty());
|
ASSERT_FALSE(verify_result.GetSignature().empty());
|
||||||
ASSERT_EQ(verify_result.GetSignature().at(0).GetFingerprint(),
|
ASSERT_EQ(verify_result.GetSignature().at(0).GetFingerprint(),
|
||||||
@ -241,7 +241,7 @@ TEST_F(GpgCoreTest, CoreEncryptSignDecrVerifyTest) {
|
|||||||
auto encrypt_text = GFBuffer(QString("Hello GpgFrontend!"));
|
auto encrypt_text = GFBuffer(QString("Hello GpgFrontend!"));
|
||||||
|
|
||||||
ASSERT_TRUE(sign_key.IsPrivateKey());
|
ASSERT_TRUE(sign_key.IsPrivateKey());
|
||||||
ASSERT_TRUE(sign_key.IsHasActualSigningCapability());
|
ASSERT_TRUE(sign_key.IsHasActualSignCap());
|
||||||
|
|
||||||
auto [err, data_object] = GpgBasicOperator::GetInstance().EncryptSignSync(
|
auto [err, data_object] = GpgBasicOperator::GetInstance().EncryptSignSync(
|
||||||
{encrypt_key}, {sign_key}, encrypt_text, true);
|
{encrypt_key}, {sign_key}, encrypt_text, true);
|
||||||
|
@ -232,7 +232,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSignDecrVerifyTest) {
|
|||||||
auto output_file = GetTempFilePath();
|
auto output_file = GetTempFilePath();
|
||||||
|
|
||||||
ASSERT_TRUE(sign_key.IsPrivateKey());
|
ASSERT_TRUE(sign_key.IsPrivateKey());
|
||||||
ASSERT_TRUE(sign_key.IsHasActualSigningCapability());
|
ASSERT_TRUE(sign_key.IsHasActualSignCap());
|
||||||
|
|
||||||
auto [err, data_object] = GpgFileOpera::GetInstance().EncryptSignFileSync(
|
auto [err, data_object] = GpgFileOpera::GetInstance().EncryptSignFileSync(
|
||||||
{encrypt_key}, {sign_key}, input_file, true, output_file);
|
{encrypt_key}, {sign_key}, input_file, true, output_file);
|
||||||
@ -279,7 +279,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSignDecrVerifyBinaryTest) {
|
|||||||
auto output_file = GetTempFilePath();
|
auto output_file = GetTempFilePath();
|
||||||
|
|
||||||
ASSERT_TRUE(sign_key.IsPrivateKey());
|
ASSERT_TRUE(sign_key.IsPrivateKey());
|
||||||
ASSERT_TRUE(sign_key.IsHasActualSigningCapability());
|
ASSERT_TRUE(sign_key.IsHasActualSignCap());
|
||||||
|
|
||||||
auto [err, data_object] = GpgFileOpera::GetInstance().EncryptSignFileSync(
|
auto [err, data_object] = GpgFileOpera::GetInstance().EncryptSignFileSync(
|
||||||
{encrypt_key}, {sign_key}, input_file, false, output_file);
|
{encrypt_key}, {sign_key}, input_file, false, output_file);
|
||||||
|
@ -69,14 +69,14 @@ TEST_F(GpgCoreTest, GpgKeyTest) {
|
|||||||
ASSERT_EQ(key.GetSubKeys()->size(), 2);
|
ASSERT_EQ(key.GetSubKeys()->size(), 2);
|
||||||
ASSERT_EQ(key.GetUIDs()->size(), 1);
|
ASSERT_EQ(key.GetUIDs()->size(), 1);
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_FALSE(key.IsHasEncryptionCapability());
|
ASSERT_FALSE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
ASSERT_FALSE(key.IsHasAuthenticationCapability());
|
ASSERT_FALSE(key.IsHasAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasActualCertificationCapability());
|
ASSERT_FALSE(key.IsHasActualCertCap());
|
||||||
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
|
ASSERT_FALSE(key.IsHasActualEncrCap());
|
||||||
ASSERT_FALSE(key.IsHasActualSigningCapability());
|
ASSERT_FALSE(key.IsHasActualSignCap());
|
||||||
ASSERT_FALSE(key.IsHasActualAuthenticationCapability());
|
ASSERT_FALSE(key.IsHasActualAuthCap());
|
||||||
|
|
||||||
ASSERT_EQ(key.GetName(), "GpgFrontendTest");
|
ASSERT_EQ(key.GetName(), "GpgFrontendTest");
|
||||||
ASSERT_TRUE(key.GetComment().isEmpty());
|
ASSERT_TRUE(key.GetComment().isEmpty());
|
||||||
@ -133,10 +133,10 @@ TEST_F(GpgCoreTest, GpgSubKeyTest) {
|
|||||||
ASSERT_EQ(sub_key.GetKeyLength(), 3072);
|
ASSERT_EQ(sub_key.GetKeyLength(), 3072);
|
||||||
ASSERT_EQ(sub_key.GetKeyAlgo(), "RSA3072");
|
ASSERT_EQ(sub_key.GetKeyAlgo(), "RSA3072");
|
||||||
ASSERT_EQ(sub_key.GetPubkeyAlgo(), "RSA");
|
ASSERT_EQ(sub_key.GetPubkeyAlgo(), "RSA");
|
||||||
ASSERT_FALSE(sub_key.IsHasCertificationCapability());
|
ASSERT_FALSE(sub_key.IsHasCertCap());
|
||||||
ASSERT_FALSE(sub_key.IsHasAuthenticationCapability());
|
ASSERT_FALSE(sub_key.IsHasAuthCap());
|
||||||
ASSERT_FALSE(sub_key.IsHasSigningCapability());
|
ASSERT_FALSE(sub_key.IsHasSignCap());
|
||||||
ASSERT_TRUE(sub_key.IsHasEncryptionCapability());
|
ASSERT_TRUE(sub_key.IsHasEncrCap());
|
||||||
ASSERT_EQ(sub_key.GetExpireTime(),
|
ASSERT_EQ(sub_key.GetExpireTime(),
|
||||||
QDateTime::fromString("2023-09-05T04:00:00Z", Qt::ISODate));
|
QDateTime::fromString("2023-09-05T04:00:00Z", Qt::ISODate));
|
||||||
|
|
||||||
@ -189,8 +189,8 @@ TEST_F(GpgCoreTest, GpgKeyGetterTest) {
|
|||||||
ASSERT_TRUE(key.IsGood());
|
ASSERT_TRUE(key.IsGood());
|
||||||
auto keys = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel).FetchKey();
|
auto keys = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel).FetchKey();
|
||||||
|
|
||||||
EXPECT_GT(keys->size(), 0);
|
EXPECT_GT(keys.size(), 0);
|
||||||
ASSERT_TRUE(find(keys->begin(), keys->end(), key) != keys->end());
|
ASSERT_TRUE(std::find(keys.begin(), keys.end(), key) != keys.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace GpgFrontend::Test
|
} // namespace GpgFrontend::Test
|
@ -29,26 +29,49 @@
|
|||||||
#include "GpgCoreTest.h"
|
#include "GpgCoreTest.h"
|
||||||
#include "core/function/gpg/GpgKeyGetter.h"
|
#include "core/function/gpg/GpgKeyGetter.h"
|
||||||
#include "core/function/gpg/GpgKeyOpera.h"
|
#include "core/function/gpg/GpgKeyOpera.h"
|
||||||
#include "core/model/GpgGenKeyInfo.h"
|
|
||||||
#include "core/model/GpgGenerateKeyResult.h"
|
#include "core/model/GpgGenerateKeyResult.h"
|
||||||
#include "core/model/GpgKey.h"
|
#include "core/model/GpgKey.h"
|
||||||
|
#include "core/model/GpgKeyGenerateInfo.h"
|
||||||
#include "core/utils/GpgUtils.h"
|
#include "core/utils/GpgUtils.h"
|
||||||
#include "core/utils/MemoryUtils.h"
|
#include "core/utils/MemoryUtils.h"
|
||||||
|
|
||||||
namespace GpgFrontend::Test {
|
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) {
|
TEST_F(GpgCoreTest, GenerateKeyRSA2048Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_0");
|
p_info->SetName("foo_0");
|
||||||
keygen_info->SetEmail("bar@gpgfrontend.bktus.com");
|
p_info->SetEmail("bar@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("foobar");
|
p_info->SetComment("foobar");
|
||||||
keygen_info->SetAlgo("rsa");
|
|
||||||
keygen_info->SetKeyLength(2048);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa2048");
|
||||||
keygen_info->SetNonExpired(true);
|
ASSERT_TRUE(found);
|
||||||
keygen_info->SetNonPassPhrase(true);
|
ASSERT_EQ(algo.Id(), "rsa2048");
|
||||||
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
p_info->SetNonExpired(true);
|
||||||
|
p_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.GenerateKeySync(keygen_info);
|
.GenerateKeySync(p_info);
|
||||||
|
|
||||||
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -69,37 +92,41 @@ TEST_F(GpgCoreTest, GenerateKeyRSA2048Test) {
|
|||||||
ASSERT_EQ(key.GetPrimaryKeyLength(), 2048);
|
ASSERT_EQ(key.GetPrimaryKeyLength(), 2048);
|
||||||
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_TRUE(key.IsHasAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasAuthCap());
|
||||||
ASSERT_TRUE(key.IsHasEncryptionCapability());
|
ASSERT_TRUE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasActualCertificationCapability());
|
ASSERT_TRUE(key.IsHasActualCertCap());
|
||||||
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasActualAuthCap());
|
||||||
ASSERT_TRUE(key.IsHasActualEncryptionCapability());
|
ASSERT_TRUE(key.IsHasActualEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasActualSigningCapability());
|
ASSERT_TRUE(key.IsHasActualSignCap());
|
||||||
|
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.DeleteKey(result.GetFingerprint());
|
.DeleteKey(result.GetFingerprint());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateKeyRSA4096Test) {
|
TEST_F(GpgCoreTest, GenerateKeyRSA4096Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_1");
|
p_info->SetName("foo_1");
|
||||||
keygen_info->SetEmail("bar@gpgfrontend.bktus.com");
|
p_info->SetEmail("bar@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("hello gpgfrontend");
|
p_info->SetComment("hello gpgfrontend");
|
||||||
keygen_info->SetAlgo("rsa");
|
|
||||||
keygen_info->SetKeyLength(4096);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("rsa4096");
|
||||||
keygen_info->SetNonExpired(false);
|
ASSERT_TRUE(found);
|
||||||
keygen_info->SetNonPassPhrase(true);
|
ASSERT_EQ(algo.Id(), "rsa4096");
|
||||||
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
p_info->SetNonExpired(false);
|
||||||
|
p_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto expire_time =
|
auto expire_time =
|
||||||
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
||||||
keygen_info->SetExpireTime(expire_time);
|
p_info->SetExpireTime(expire_time);
|
||||||
keygen_info->SetNonPassPhrase(false);
|
p_info->SetNonPassPhrase(false);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.GenerateKeySync(keygen_info);
|
.GenerateKeySync(p_info);
|
||||||
|
|
||||||
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -119,22 +146,26 @@ TEST_F(GpgCoreTest, GenerateKeyRSA4096Test) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateKeyDSA2048Test) {
|
TEST_F(GpgCoreTest, GenerateKeyDSA2048Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_1");
|
p_info->SetName("foo_1");
|
||||||
keygen_info->SetEmail("bar_1@gpgfrontend.bktus.com");
|
p_info->SetEmail("bar_1@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("hello gpgfrontend");
|
p_info->SetComment("hello gpgfrontend");
|
||||||
keygen_info->SetAlgo("dsa");
|
|
||||||
keygen_info->SetKeyLength(2048);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("dsa2048");
|
||||||
keygen_info->SetNonExpired(false);
|
ASSERT_TRUE(found);
|
||||||
keygen_info->SetNonPassPhrase(true);
|
ASSERT_EQ(algo.Id(), "dsa2048");
|
||||||
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
p_info->SetNonExpired(false);
|
||||||
|
p_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto expire_time =
|
auto expire_time =
|
||||||
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
||||||
keygen_info->SetExpireTime(expire_time);
|
p_info->SetExpireTime(expire_time);
|
||||||
keygen_info->SetNonPassPhrase(false);
|
p_info->SetNonPassPhrase(false);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.GenerateKeySync(keygen_info);
|
.GenerateKeySync(p_info);
|
||||||
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
||||||
@ -154,36 +185,41 @@ TEST_F(GpgCoreTest, GenerateKeyDSA2048Test) {
|
|||||||
ASSERT_EQ(key.GetPrimaryKeyLength(), 2048);
|
ASSERT_EQ(key.GetPrimaryKeyLength(), 2048);
|
||||||
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_TRUE(key.IsHasAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasEncryptionCapability());
|
ASSERT_FALSE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasActualCertificationCapability());
|
ASSERT_TRUE(key.IsHasActualCertCap());
|
||||||
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasActualAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
|
ASSERT_FALSE(key.IsHasActualEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasActualSigningCapability());
|
ASSERT_TRUE(key.IsHasActualSignCap());
|
||||||
|
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.DeleteKey(result.GetFingerprint());
|
.DeleteKey(result.GetFingerprint());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateKeyED25519Test) {
|
TEST_F(GpgCoreTest, GenerateKeyED25519Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_4");
|
p_info->SetName("foo_4");
|
||||||
keygen_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
|
p_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("hello gpgfrontend");
|
p_info->SetComment("hello gpgfrontend");
|
||||||
keygen_info->SetAlgo("ed25519");
|
|
||||||
keygen_info->SetNonExpired(false);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
|
||||||
keygen_info->SetNonPassPhrase(true);
|
ASSERT_TRUE(found);
|
||||||
|
ASSERT_EQ(algo.Id(), "ed25519");
|
||||||
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
p_info->SetNonExpired(false);
|
||||||
|
p_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto expire_time =
|
auto expire_time =
|
||||||
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
||||||
keygen_info->SetExpireTime(expire_time);
|
p_info->SetExpireTime(expire_time);
|
||||||
keygen_info->SetNonPassPhrase(false);
|
p_info->SetNonPassPhrase(false);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.GenerateKeySync(keygen_info);
|
.GenerateKeySync(p_info);
|
||||||
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
||||||
@ -203,37 +239,46 @@ TEST_F(GpgCoreTest, GenerateKeyED25519Test) {
|
|||||||
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
|
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
|
||||||
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_TRUE(key.IsHasAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasEncryptionCapability());
|
ASSERT_FALSE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasActualCertificationCapability());
|
ASSERT_TRUE(key.IsHasActualCertCap());
|
||||||
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasActualAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
|
ASSERT_FALSE(key.IsHasActualEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasActualSigningCapability());
|
ASSERT_TRUE(key.IsHasActualSignCap());
|
||||||
|
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.DeleteKey(result.GetFingerprint());
|
.DeleteKey(result.GetFingerprint());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
|
TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_ec");
|
p_info->SetName("foo_ec");
|
||||||
keygen_info->SetEmail("ec_bar@gpgfrontend.bktus.com");
|
p_info->SetEmail("ec_bar@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("ecccc");
|
p_info->SetComment("ecccc");
|
||||||
keygen_info->SetAlgo("ed25519");
|
|
||||||
keygen_info->SetNonExpired(true);
|
|
||||||
keygen_info->SetNonPassPhrase(true);
|
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
|
||||||
subkeygen_info->SetAlgo("cv25519");
|
ASSERT_TRUE(found);
|
||||||
subkeygen_info->SetNonExpired(true);
|
ASSERT_EQ(algo.Id(), "ed25519");
|
||||||
subkeygen_info->SetNonPassPhrase(true);
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
auto [err, data_object] =
|
p_info->SetNonExpired(true);
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
p_info->SetNonPassPhrase(true);
|
||||||
.GenerateKeyWithSubkeySync(keygen_info, subkeygen_info);
|
|
||||||
|
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_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
@ -255,10 +300,10 @@ TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
|
|||||||
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
|
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
|
||||||
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_TRUE(key.IsHasAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasAuthCap());
|
||||||
ASSERT_TRUE(key.IsHasEncryptionCapability());
|
ASSERT_TRUE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_FALSE(key.GetSubKeys()->empty());
|
ASSERT_FALSE(key.GetSubKeys()->empty());
|
||||||
ASSERT_EQ(key.GetSubKeys()->size(), 2);
|
ASSERT_EQ(key.GetSubKeys()->size(), 2);
|
||||||
@ -270,36 +315,45 @@ TEST_F(GpgCoreTest, GenerateKeyED25519CV25519Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 255);
|
ASSERT_EQ(subkey.GetKeyLength(), 255);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
|
ASSERT_FALSE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_FALSE(subkey.IsHasSigningCapability());
|
ASSERT_FALSE(subkey.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasActualCertificationCapability());
|
ASSERT_TRUE(key.IsHasActualCertCap());
|
||||||
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasActualAuthCap());
|
||||||
ASSERT_TRUE(key.IsHasActualEncryptionCapability());
|
ASSERT_TRUE(key.IsHasActualEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasActualSigningCapability());
|
ASSERT_TRUE(key.IsHasActualSignCap());
|
||||||
|
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel).DeleteKey(fpr);
|
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel).DeleteKey(fpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
|
TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_ec2");
|
p_info->SetName("foo_ec2");
|
||||||
keygen_info->SetEmail("ec2_bar@gpgfrontend.bktus.com");
|
p_info->SetEmail("ec2_bar@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("ecccc");
|
p_info->SetComment("ecccc");
|
||||||
keygen_info->SetAlgo("ed25519");
|
|
||||||
keygen_info->SetNonExpired(true);
|
|
||||||
keygen_info->SetNonPassPhrase(true);
|
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
|
||||||
subkeygen_info->SetAlgo("nistp256");
|
ASSERT_TRUE(found);
|
||||||
subkeygen_info->SetNonExpired(true);
|
ASSERT_EQ(algo.Id(), "ed25519");
|
||||||
subkeygen_info->SetNonPassPhrase(true);
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
auto [err, data_object] =
|
p_info->SetNonExpired(true);
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
p_info->SetNonPassPhrase(true);
|
||||||
.GenerateKeyWithSubkeySync(keygen_info, subkeygen_info);
|
|
||||||
|
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_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
@ -321,10 +375,10 @@ TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
|
|||||||
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
|
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
|
||||||
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_TRUE(key.IsHasAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasAuthCap());
|
||||||
ASSERT_TRUE(key.IsHasEncryptionCapability());
|
ASSERT_TRUE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_FALSE(key.GetSubKeys()->empty());
|
ASSERT_FALSE(key.GetSubKeys()->empty());
|
||||||
ASSERT_EQ(key.GetSubKeys()->size(), 2);
|
ASSERT_EQ(key.GetSubKeys()->size(), 2);
|
||||||
@ -336,36 +390,45 @@ TEST_F(GpgCoreTest, GenerateKeyED25519NISTP256Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
|
ASSERT_FALSE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_FALSE(subkey.IsHasSigningCapability());
|
ASSERT_FALSE(subkey.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasActualCertificationCapability());
|
ASSERT_TRUE(key.IsHasActualCertCap());
|
||||||
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasActualAuthCap());
|
||||||
ASSERT_TRUE(key.IsHasActualEncryptionCapability());
|
ASSERT_TRUE(key.IsHasActualEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasActualSigningCapability());
|
ASSERT_TRUE(key.IsHasActualSignCap());
|
||||||
|
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel).DeleteKey(fpr);
|
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel).DeleteKey(fpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
|
TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_ec3");
|
p_info->SetName("foo_ec3");
|
||||||
keygen_info->SetEmail("ec3_bar@gpgfrontend.bktus.com");
|
p_info->SetEmail("ec3_bar@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("ecccc3");
|
p_info->SetComment("ecccc3");
|
||||||
keygen_info->SetAlgo("ed25519");
|
|
||||||
keygen_info->SetNonExpired(true);
|
|
||||||
keygen_info->SetNonPassPhrase(true);
|
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed25519");
|
||||||
subkeygen_info->SetAlgo("brainpoolp256r1");
|
ASSERT_TRUE(found);
|
||||||
subkeygen_info->SetNonExpired(true);
|
ASSERT_EQ(algo.Id(), "ed25519");
|
||||||
subkeygen_info->SetNonPassPhrase(true);
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
auto [err, data_object] =
|
p_info->SetNonExpired(true);
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
p_info->SetNonPassPhrase(true);
|
||||||
.GenerateKeyWithSubkeySync(keygen_info, subkeygen_info);
|
|
||||||
|
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_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
@ -387,10 +450,10 @@ TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
|
|||||||
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
|
ASSERT_EQ(key.GetPrimaryKeyLength(), 255);
|
||||||
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(key.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_TRUE(key.IsHasAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasAuthCap());
|
||||||
ASSERT_TRUE(key.IsHasEncryptionCapability());
|
ASSERT_TRUE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_FALSE(key.GetSubKeys()->empty());
|
ASSERT_FALSE(key.GetSubKeys()->empty());
|
||||||
ASSERT_EQ(key.GetSubKeys()->size(), 2);
|
ASSERT_EQ(key.GetSubKeys()->size(), 2);
|
||||||
@ -402,35 +465,40 @@ TEST_F(GpgCoreTest, GenerateKeyED25519BRAINPOOLP256R1Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
|
ASSERT_FALSE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_FALSE(subkey.IsHasSigningCapability());
|
ASSERT_FALSE(subkey.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasActualCertificationCapability());
|
ASSERT_TRUE(key.IsHasActualCertCap());
|
||||||
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasActualAuthCap());
|
||||||
ASSERT_TRUE(key.IsHasActualEncryptionCapability());
|
ASSERT_TRUE(key.IsHasActualEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasActualSigningCapability());
|
ASSERT_TRUE(key.IsHasActualSignCap());
|
||||||
|
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel).DeleteKey(fpr);
|
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel).DeleteKey(fpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateKeyNISTP256Test) {
|
TEST_F(GpgCoreTest, GenerateKeyNISTP256Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_4");
|
p_info->SetName("foo_4");
|
||||||
keygen_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
|
p_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("hello gpgfrontend");
|
p_info->SetComment("hello gpgfrontend");
|
||||||
keygen_info->SetAlgo("nistp256");
|
|
||||||
keygen_info->SetNonExpired(false);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("nistp256");
|
||||||
keygen_info->SetNonPassPhrase(true);
|
ASSERT_TRUE(found);
|
||||||
|
ASSERT_EQ(algo.Id(), "nistp256");
|
||||||
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
p_info->SetNonExpired(false);
|
||||||
|
p_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto expire_time =
|
auto expire_time =
|
||||||
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
||||||
keygen_info->SetExpireTime(expire_time);
|
p_info->SetExpireTime(expire_time);
|
||||||
keygen_info->SetNonPassPhrase(false);
|
p_info->SetNonPassPhrase(false);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.GenerateKeySync(keygen_info);
|
.GenerateKeySync(p_info);
|
||||||
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
||||||
@ -451,36 +519,41 @@ TEST_F(GpgCoreTest, GenerateKeyNISTP256Test) {
|
|||||||
ASSERT_EQ(key.GetPrimaryKeyLength(), 256);
|
ASSERT_EQ(key.GetPrimaryKeyLength(), 256);
|
||||||
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_TRUE(key.IsHasAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasEncryptionCapability());
|
ASSERT_FALSE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasActualCertificationCapability());
|
ASSERT_TRUE(key.IsHasActualCertCap());
|
||||||
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasActualAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
|
ASSERT_FALSE(key.IsHasActualEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasActualSigningCapability());
|
ASSERT_TRUE(key.IsHasActualSignCap());
|
||||||
|
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.DeleteKey(result.GetFingerprint());
|
.DeleteKey(result.GetFingerprint());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateKeyED448Test) {
|
TEST_F(GpgCoreTest, GenerateKeyED448Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_4");
|
p_info->SetName("foo_4");
|
||||||
keygen_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
|
p_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("hello gpgfrontend");
|
p_info->SetComment("hello gpgfrontend");
|
||||||
keygen_info->SetAlgo("ed448");
|
|
||||||
keygen_info->SetNonExpired(false);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("ed448");
|
||||||
keygen_info->SetNonPassPhrase(true);
|
ASSERT_TRUE(found);
|
||||||
|
ASSERT_EQ(algo.Id(), "ed448");
|
||||||
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
p_info->SetNonExpired(false);
|
||||||
|
p_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto expire_time =
|
auto expire_time =
|
||||||
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
||||||
keygen_info->SetExpireTime(expire_time);
|
p_info->SetExpireTime(expire_time);
|
||||||
keygen_info->SetNonPassPhrase(false);
|
p_info->SetNonPassPhrase(false);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.GenerateKeySync(keygen_info);
|
.GenerateKeySync(p_info);
|
||||||
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
||||||
@ -501,36 +574,41 @@ TEST_F(GpgCoreTest, GenerateKeyED448Test) {
|
|||||||
ASSERT_EQ(key.GetPrimaryKeyLength(), 448);
|
ASSERT_EQ(key.GetPrimaryKeyLength(), 448);
|
||||||
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_TRUE(key.IsHasAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasEncryptionCapability());
|
ASSERT_FALSE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasActualCertificationCapability());
|
ASSERT_TRUE(key.IsHasActualCertCap());
|
||||||
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasActualAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
|
ASSERT_FALSE(key.IsHasActualEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasActualSigningCapability());
|
ASSERT_TRUE(key.IsHasActualSignCap());
|
||||||
|
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.DeleteKey(result.GetFingerprint());
|
.DeleteKey(result.GetFingerprint());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateKeySECP256K1Test) {
|
TEST_F(GpgCoreTest, GenerateKeySECP256K1Test) {
|
||||||
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
|
auto p_info = QSharedPointer<KeyGenerateInfo>::create();
|
||||||
keygen_info->SetName("foo_4");
|
p_info->SetName("foo_4");
|
||||||
keygen_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
|
p_info->SetEmail("bar_ed@gpgfrontend.bktus.com");
|
||||||
keygen_info->SetComment("hello gpgfrontend");
|
p_info->SetComment("hello gpgfrontend");
|
||||||
keygen_info->SetAlgo("secp256k1");
|
|
||||||
keygen_info->SetNonExpired(false);
|
auto [found, algo] = KeyGenerateInfo::SearchPrimaryKeyAlgo("secp256k1");
|
||||||
keygen_info->SetNonPassPhrase(true);
|
ASSERT_TRUE(found);
|
||||||
|
ASSERT_EQ(algo.Id(), "secp256k1");
|
||||||
|
p_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
p_info->SetNonExpired(false);
|
||||||
|
p_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto expire_time =
|
auto expire_time =
|
||||||
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600));
|
||||||
keygen_info->SetExpireTime(expire_time);
|
p_info->SetExpireTime(expire_time);
|
||||||
keygen_info->SetNonPassPhrase(false);
|
p_info->SetNonPassPhrase(false);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.GenerateKeySync(keygen_info);
|
.GenerateKeySync(p_info);
|
||||||
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
ASSERT_TRUE(data_object->Check<GpgGenerateKeyResult>());
|
||||||
@ -551,15 +629,15 @@ TEST_F(GpgCoreTest, GenerateKeySECP256K1Test) {
|
|||||||
ASSERT_EQ(key.GetPrimaryKeyLength(), 256);
|
ASSERT_EQ(key.GetPrimaryKeyLength(), 256);
|
||||||
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
ASSERT_GT(key.GetExpireTime(), QDateTime::currentDateTime());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasCertificationCapability());
|
ASSERT_TRUE(key.IsHasCertCap());
|
||||||
ASSERT_TRUE(key.IsHasAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasEncryptionCapability());
|
ASSERT_FALSE(key.IsHasEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasSigningCapability());
|
ASSERT_TRUE(key.IsHasSignCap());
|
||||||
|
|
||||||
ASSERT_TRUE(key.IsHasActualCertificationCapability());
|
ASSERT_TRUE(key.IsHasActualCertCap());
|
||||||
ASSERT_TRUE(key.IsHasActualAuthenticationCapability());
|
ASSERT_TRUE(key.IsHasActualAuthCap());
|
||||||
ASSERT_FALSE(key.IsHasActualEncryptionCapability());
|
ASSERT_FALSE(key.IsHasActualEncrCap());
|
||||||
ASSERT_TRUE(key.IsHasActualSigningCapability());
|
ASSERT_TRUE(key.IsHasActualSignCap());
|
||||||
|
|
||||||
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
||||||
.DeleteKey(result.GetFingerprint());
|
.DeleteKey(result.GetFingerprint());
|
||||||
|
@ -29,27 +29,31 @@
|
|||||||
#include "GpgCoreTest.h"
|
#include "GpgCoreTest.h"
|
||||||
#include "core/function/gpg/GpgKeyGetter.h"
|
#include "core/function/gpg/GpgKeyGetter.h"
|
||||||
#include "core/function/gpg/GpgKeyOpera.h"
|
#include "core/function/gpg/GpgKeyOpera.h"
|
||||||
#include "core/model/GpgGenKeyInfo.h"
|
|
||||||
#include "core/model/GpgGenerateKeyResult.h"
|
#include "core/model/GpgGenerateKeyResult.h"
|
||||||
#include "core/model/GpgKey.h"
|
#include "core/model/GpgKey.h"
|
||||||
|
#include "core/model/GpgKeyGenerateInfo.h"
|
||||||
#include "core/utils/GpgUtils.h"
|
#include "core/utils/GpgUtils.h"
|
||||||
#include "core/utils/MemoryUtils.h"
|
#include "core/utils/MemoryUtils.h"
|
||||||
|
|
||||||
namespace GpgFrontend::Test {
|
namespace GpgFrontend::Test {
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateSubkeyRSA2048Test) {
|
TEST_F(GpgCoreTest, GenerateSubkeyRSA2048Test) {
|
||||||
auto main_key = GpgKeyGetter::GetInstance().GetKey(
|
auto p_key = GpgKeyGetter::GetInstance().GetKey(
|
||||||
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
||||||
ASSERT_TRUE(main_key.IsGood());
|
ASSERT_TRUE(p_key.IsGood());
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
|
||||||
subkeygen_info->SetAlgo("rsa");
|
|
||||||
subkeygen_info->SetKeyLength(2048);
|
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("rsa2048");
|
||||||
subkeygen_info->SetNonExpired(true);
|
ASSERT_TRUE(found);
|
||||||
subkeygen_info->SetNonPassPhrase(true);
|
ASSERT_EQ(algo.Id(), "rsa2048");
|
||||||
|
s_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
s_info->SetNonExpired(true);
|
||||||
|
s_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
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(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -70,25 +74,29 @@ TEST_F(GpgCoreTest, GenerateSubkeyRSA2048Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 2048);
|
ASSERT_EQ(subkey.GetKeyLength(), 2048);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_TRUE(subkey.IsHasAuthenticationCapability());
|
ASSERT_TRUE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_TRUE(subkey.IsHasSigningCapability());
|
ASSERT_TRUE(subkey.IsHasSignCap());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateSubkeyDSA2048Test) {
|
TEST_F(GpgCoreTest, GenerateSubkeyDSA2048Test) {
|
||||||
auto main_key = GpgKeyGetter::GetInstance().GetKey(
|
auto p_key = GpgKeyGetter::GetInstance().GetKey(
|
||||||
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
||||||
ASSERT_TRUE(main_key.IsGood());
|
ASSERT_TRUE(p_key.IsGood());
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
|
||||||
subkeygen_info->SetAlgo("dsa");
|
|
||||||
subkeygen_info->SetKeyLength(2048);
|
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("dsa2048");
|
||||||
subkeygen_info->SetNonExpired(true);
|
ASSERT_TRUE(found);
|
||||||
subkeygen_info->SetNonPassPhrase(true);
|
ASSERT_EQ(algo.Id(), "dsa2048");
|
||||||
|
s_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
s_info->SetNonExpired(true);
|
||||||
|
s_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
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(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -109,25 +117,29 @@ TEST_F(GpgCoreTest, GenerateSubkeyDSA2048Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 2048);
|
ASSERT_EQ(subkey.GetKeyLength(), 2048);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_TRUE(subkey.IsHasAuthenticationCapability());
|
ASSERT_TRUE(subkey.IsHasAuthCap());
|
||||||
ASSERT_FALSE(subkey.IsHasEncryptionCapability());
|
ASSERT_FALSE(subkey.IsHasEncrCap());
|
||||||
ASSERT_TRUE(subkey.IsHasSigningCapability());
|
ASSERT_TRUE(subkey.IsHasSignCap());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateSubkeyELG2048Test) {
|
TEST_F(GpgCoreTest, GenerateSubkeyELG2048Test) {
|
||||||
auto main_key = GpgKeyGetter::GetInstance().GetKey(
|
auto p_key = GpgKeyGetter::GetInstance().GetKey(
|
||||||
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
||||||
ASSERT_TRUE(main_key.IsGood());
|
ASSERT_TRUE(p_key.IsGood());
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
|
||||||
subkeygen_info->SetAlgo("elg");
|
|
||||||
subkeygen_info->SetKeyLength(2048);
|
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("elg2048");
|
||||||
subkeygen_info->SetNonExpired(true);
|
ASSERT_TRUE(found);
|
||||||
subkeygen_info->SetNonPassPhrase(true);
|
ASSERT_EQ(algo.Id(), "elg2048");
|
||||||
|
s_info->SetAlgo(algo);
|
||||||
|
|
||||||
|
s_info->SetNonExpired(true);
|
||||||
|
s_info->SetNonPassPhrase(true);
|
||||||
|
|
||||||
auto [err, data_object] = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel)
|
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(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -148,24 +160,29 @@ TEST_F(GpgCoreTest, GenerateSubkeyELG2048Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 2048);
|
ASSERT_EQ(subkey.GetKeyLength(), 2048);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
|
ASSERT_FALSE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_FALSE(subkey.IsHasSigningCapability());
|
ASSERT_FALSE(subkey.IsHasSignCap());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateSubkeyED25519Test) {
|
TEST_F(GpgCoreTest, GenerateSubkeyED25519Test) {
|
||||||
auto main_key = GpgKeyGetter::GetInstance().GetKey(
|
auto p_key = GpgKeyGetter::GetInstance().GetKey(
|
||||||
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
||||||
ASSERT_TRUE(main_key.IsGood());
|
ASSERT_TRUE(p_key.IsGood());
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
|
||||||
subkeygen_info->SetAlgo("ed25519");
|
|
||||||
subkeygen_info->SetNonExpired(true);
|
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("ed25519");
|
||||||
subkeygen_info->SetNonPassPhrase(true);
|
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)
|
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(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -186,24 +203,29 @@ TEST_F(GpgCoreTest, GenerateSubkeyED25519Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 255);
|
ASSERT_EQ(subkey.GetKeyLength(), 255);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_TRUE(subkey.IsHasAuthenticationCapability());
|
ASSERT_TRUE(subkey.IsHasAuthCap());
|
||||||
ASSERT_FALSE(subkey.IsHasEncryptionCapability());
|
ASSERT_FALSE(subkey.IsHasEncrCap());
|
||||||
ASSERT_TRUE(subkey.IsHasSigningCapability());
|
ASSERT_TRUE(subkey.IsHasSignCap());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateSubkeyCV25519Test) {
|
TEST_F(GpgCoreTest, GenerateSubkeyCV25519Test) {
|
||||||
auto main_key = GpgKeyGetter::GetInstance().GetKey(
|
auto p_key = GpgKeyGetter::GetInstance().GetKey(
|
||||||
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
||||||
ASSERT_TRUE(main_key.IsGood());
|
ASSERT_TRUE(p_key.IsGood());
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
|
||||||
subkeygen_info->SetAlgo("cv25519");
|
|
||||||
subkeygen_info->SetNonExpired(true);
|
auto [found, algo] = KeyGenerateInfo::SearchSubKeyAlgo("cv25519");
|
||||||
subkeygen_info->SetNonPassPhrase(true);
|
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)
|
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(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -224,23 +246,28 @@ TEST_F(GpgCoreTest, GenerateSubkeyCV25519Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 255);
|
ASSERT_EQ(subkey.GetKeyLength(), 255);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
|
ASSERT_FALSE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_FALSE(subkey.IsHasSigningCapability());
|
ASSERT_FALSE(subkey.IsHasSignCap());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateSubkeyNISTP256Test) {
|
TEST_F(GpgCoreTest, GenerateSubkeyNISTP256Test) {
|
||||||
auto main_key = GpgKeyGetter::GetInstance().GetKey(
|
auto p_key = GpgKeyGetter::GetInstance().GetKey(
|
||||||
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
||||||
ASSERT_TRUE(main_key.IsGood());
|
ASSERT_TRUE(p_key.IsGood());
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
|
||||||
subkeygen_info->SetAlgo("nistp256");
|
|
||||||
subkeygen_info->SetNonExpired(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)
|
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(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -261,23 +288,28 @@ TEST_F(GpgCoreTest, GenerateSubkeyNISTP256Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
|
ASSERT_FALSE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_FALSE(subkey.IsHasSigningCapability());
|
ASSERT_FALSE(subkey.IsHasSignCap());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateSubkeyBRAINPOOLP256R1Test) {
|
TEST_F(GpgCoreTest, GenerateSubkeyBRAINPOOLP256R1Test) {
|
||||||
auto main_key = GpgKeyGetter::GetInstance().GetKey(
|
auto p_key = GpgKeyGetter::GetInstance().GetKey(
|
||||||
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
||||||
ASSERT_TRUE(main_key.IsGood());
|
ASSERT_TRUE(p_key.IsGood());
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
|
||||||
subkeygen_info->SetAlgo("brainpoolp256r1");
|
|
||||||
subkeygen_info->SetNonExpired(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)
|
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(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -298,23 +330,28 @@ TEST_F(GpgCoreTest, GenerateSubkeyBRAINPOOLP256R1Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
|
ASSERT_FALSE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_FALSE(subkey.IsHasSigningCapability());
|
ASSERT_FALSE(subkey.IsHasSignCap());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateSubkeyX448Test) {
|
TEST_F(GpgCoreTest, GenerateSubkeyX448Test) {
|
||||||
auto main_key = GpgKeyGetter::GetInstance().GetKey(
|
auto p_key = GpgKeyGetter::GetInstance().GetKey(
|
||||||
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
||||||
ASSERT_TRUE(main_key.IsGood());
|
ASSERT_TRUE(p_key.IsGood());
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
|
||||||
subkeygen_info->SetAlgo("x448");
|
|
||||||
subkeygen_info->SetNonExpired(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)
|
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(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -335,23 +372,28 @@ TEST_F(GpgCoreTest, GenerateSubkeyX448Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 448);
|
ASSERT_EQ(subkey.GetKeyLength(), 448);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
|
ASSERT_FALSE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_FALSE(subkey.IsHasSigningCapability());
|
ASSERT_FALSE(subkey.IsHasSignCap());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GpgCoreTest, GenerateSubkeySECP256K1Test) {
|
TEST_F(GpgCoreTest, GenerateSubkeySECP256K1Test) {
|
||||||
auto main_key = GpgKeyGetter::GetInstance().GetKey(
|
auto p_key = GpgKeyGetter::GetInstance().GetKey(
|
||||||
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
"E87C6A2D8D95C818DE93B3AE6A2764F8298DEB29");
|
||||||
ASSERT_TRUE(main_key.IsGood());
|
ASSERT_TRUE(p_key.IsGood());
|
||||||
|
|
||||||
auto subkeygen_info = SecureCreateSharedObject<GenKeyInfo>(true);
|
auto s_info = QSharedPointer<KeyGenerateInfo>::create(true);
|
||||||
subkeygen_info->SetAlgo("secp256k1");
|
|
||||||
subkeygen_info->SetNonExpired(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)
|
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(CheckGpgError(err), GPG_ERR_NO_ERROR);
|
||||||
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
ASSERT_EQ(data_object->GetObjectSize(), 1);
|
||||||
@ -372,10 +414,10 @@ TEST_F(GpgCoreTest, GenerateSubkeySECP256K1Test) {
|
|||||||
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
ASSERT_EQ(subkey.GetKeyLength(), 256);
|
||||||
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
ASSERT_EQ(subkey.GetExpireTime(), QDateTime::fromMSecsSinceEpoch(0));
|
||||||
|
|
||||||
ASSERT_FALSE(subkey.IsHasCertificationCapability());
|
ASSERT_FALSE(subkey.IsHasCertCap());
|
||||||
ASSERT_FALSE(subkey.IsHasAuthenticationCapability());
|
ASSERT_FALSE(subkey.IsHasAuthCap());
|
||||||
ASSERT_TRUE(subkey.IsHasEncryptionCapability());
|
ASSERT_TRUE(subkey.IsHasEncrCap());
|
||||||
ASSERT_FALSE(subkey.IsHasSigningCapability());
|
ASSERT_FALSE(subkey.IsHasSignCap());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace GpgFrontend::Test
|
} // namespace GpgFrontend::Test
|
@ -38,6 +38,7 @@ aux_source_directory(dialog/import_export UI_SOURCE)
|
|||||||
aux_source_directory(dialog/controller UI_SOURCE)
|
aux_source_directory(dialog/controller UI_SOURCE)
|
||||||
aux_source_directory(dialog UI_SOURCE)
|
aux_source_directory(dialog UI_SOURCE)
|
||||||
aux_source_directory(function UI_SOURCE)
|
aux_source_directory(function UI_SOURCE)
|
||||||
|
aux_source_directory(model UI_SOURCE)
|
||||||
|
|
||||||
# define libgpgfrontend_ui
|
# define libgpgfrontend_ui
|
||||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||||
|
@ -127,7 +127,7 @@ void InitGpgFrontendUI(QApplication* /*app*/) {
|
|||||||
// init locale
|
// init locale
|
||||||
InitUITranslations();
|
InitUITranslations();
|
||||||
|
|
||||||
auto settings = GlobalSettingStation::GetInstance().GetSettings();
|
auto settings = GetSettings();
|
||||||
auto theme = settings.value("appearance/theme").toString();
|
auto theme = settings.value("appearance/theme").toString();
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(WIN32)
|
#if defined(_WIN32) || defined(WIN32)
|
||||||
|
@ -75,7 +75,7 @@ class UISignalStation : public QObject {
|
|||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void SignalMainWindowlUpdateBasicalOperaMenu(unsigned int);
|
void SignalMainWindowUpdateBasicOperaMenu(unsigned int);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
@ -51,23 +51,12 @@
|
|||||||
#include "ui/dialog/controller/GnuPGControllerDialog.h"
|
#include "ui/dialog/controller/GnuPGControllerDialog.h"
|
||||||
#include "ui/dialog/import_export/KeyServerImportDialog.h"
|
#include "ui/dialog/import_export/KeyServerImportDialog.h"
|
||||||
#include "ui/struct/settings_object/KeyServerSO.h"
|
#include "ui/struct/settings_object/KeyServerSO.h"
|
||||||
#include "ui/widgets/TextEdit.h"
|
|
||||||
|
|
||||||
namespace GpgFrontend::UI {
|
namespace GpgFrontend::UI {
|
||||||
|
|
||||||
QScopedPointer<CommonUtils> CommonUtils::instance =
|
QScopedPointer<CommonUtils> CommonUtils::instance =
|
||||||
QScopedPointer<CommonUtils>(nullptr);
|
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(
|
void ImportUnknownKeyFromKeyserver(
|
||||||
QWidget *parent, int channel, const GpgVerifyResultAnalyse &verify_result) {
|
QWidget *parent, int channel, const GpgVerifyResultAnalyse &verify_result) {
|
||||||
QMessageBox::StandardButton reply;
|
QMessageBox::StandardButton reply;
|
||||||
@ -80,10 +69,10 @@ void ImportUnknownKeyFromKeyserver(
|
|||||||
QMessageBox::Yes | QMessageBox::No);
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
if (reply == QMessageBox::Yes) {
|
if (reply == QMessageBox::Yes) {
|
||||||
auto dialog = KeyServerImportDialog(channel, parent);
|
auto dialog = KeyServerImportDialog(channel, parent);
|
||||||
auto key_ids = std::make_unique<KeyIdArgsList>();
|
auto key_ids = KeyIdArgsList{};
|
||||||
auto *signature = verify_result.GetSignatures();
|
auto *signature = verify_result.GetSignatures();
|
||||||
while (signature != nullptr) {
|
while (signature != nullptr) {
|
||||||
key_ids->push_back(signature->fpr);
|
key_ids.push_back(signature->fpr);
|
||||||
signature = signature->next;
|
signature = signature->next;
|
||||||
}
|
}
|
||||||
dialog.show();
|
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 * {
|
auto CommonUtils::GetInstance() -> CommonUtils * {
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
instance.reset(new CommonUtils());
|
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) {
|
void CommonUtils::RaiseMessageBox(QWidget *parent, GpgError err) {
|
||||||
GpgErrorDesc desc = DescribeGpgErrCode(err);
|
GpgErrorDesc desc = DescribeGpgErrCode(err);
|
||||||
GpgErrorCode err_code = CheckGpgError2ErrCode(err);
|
GpgErrorCode err_code = CheckGpgError2ErrCode(err);
|
||||||
@ -326,7 +264,7 @@ void CommonUtils::SlotExecuteGpgCommand(
|
|||||||
const QStringList &arguments,
|
const QStringList &arguments,
|
||||||
const std::function<void(QProcess *)> &interact_func) {
|
const std::function<void(QProcess *)> &interact_func) {
|
||||||
QEventLoop looper;
|
QEventLoop looper;
|
||||||
auto *dialog = new WaitingDialog(tr("Processing"), nullptr);
|
auto *dialog = new WaitingDialog(tr("Processing"), false);
|
||||||
dialog->show();
|
dialog->show();
|
||||||
auto *gpg_process = new QProcess(&looper);
|
auto *gpg_process = new QProcess(&looper);
|
||||||
gpg_process->setProcessChannelMode(QProcess::MergedChannels);
|
gpg_process->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
@ -628,7 +566,7 @@ void CommonUtils::ImportKeyFromKeyServer(int channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CommonUtils::ImportKeyByKeyServerSyncModule(QWidget *parent, int channel,
|
void CommonUtils::ImportKeyByKeyServerSyncModule(QWidget *parent, int channel,
|
||||||
const QList<QString> &fprs) {
|
const QStringList &fprs) {
|
||||||
if (!Module::IsModuleActivate(kKeyServerSyncModuleID)) {
|
if (!Module::IsModuleActivate(kKeyServerSyncModuleID)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user