aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/GpgCoreInit.cpp107
-rw-r--r--src/core/function/gpg/GpgCommandExecutor.cpp18
-rw-r--r--src/main.cpp4
-rw-r--r--src/ui/UserInterfaceUtils.cpp10
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.cpp5
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp5
6 files changed, 107 insertions, 42 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 7088e0e1..0aec196a 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -109,6 +109,41 @@ void DestroyGpgFrontendCore() {
ShutdownCoreLoggingSystem();
}
+auto VerifyGpgconfPath(const std::filesystem::path& gnupg_install_fs_path)
+ -> bool {
+ return gnupg_install_fs_path.is_absolute() &&
+ std::filesystem::exists(gnupg_install_fs_path) &&
+ std::filesystem::is_regular_file(gnupg_install_fs_path);
+}
+
+auto VerifyKeyDatabasePath(const std::filesystem::path& key_database_fs_path)
+ -> bool {
+ return key_database_fs_path.is_absolute() &&
+ std::filesystem::exists(key_database_fs_path) &&
+ std::filesystem::is_directory(key_database_fs_path);
+}
+
+auto SearchGpgconfPath(const std::vector<std::string>& candidate_paths)
+ -> std::filesystem::path {
+ for (const auto& path : candidate_paths) {
+ if (VerifyGpgconfPath(std::filesystem::path{path})) {
+ return std::filesystem::path{path};
+ }
+ }
+ return {};
+}
+
+auto SearchKeyDatabasePath(const std::vector<std::string>& candidate_paths)
+ -> std::filesystem::path {
+ for (const auto& path : candidate_paths) {
+ SPDLOG_DEBUG("searh for candidate key database path: {}", path);
+ if (VerifyKeyDatabasePath(std::filesystem::path{path})) {
+ return std::filesystem::path{path};
+ }
+ }
+ return {};
+}
+
auto InitGpgME() -> bool {
// init gpgme subsystem and get gpgme library version
Module::UpsertRTValue("core", "gpgme.version",
@@ -269,39 +304,57 @@ void InitGpgFrontendCore(CoreInitArgs args) {
SPDLOG_DEBUG("core loaded custom key databse path: {}",
custom_key_database_path);
- // check gpgconf path
- std::filesystem::path custom_gnupg_install_fs_path =
- custom_gnupg_install_path;
+ std::filesystem::path gnupg_install_fs_path;
+ // user defined
+ if (!custom_gnupg_install_path.empty()) {
+ // check gpgconf path
+ gnupg_install_fs_path = custom_gnupg_install_path;
#ifdef WINDOWS
- custom_gnupg_install_fs_path /= "gpgconf.exe";
+ custom_gnupg_install_fs_path /= "gpgconf.exe";
#else
- custom_gnupg_install_fs_path /= "gpgconf";
+ gnupg_install_fs_path /= "gpgconf";
#endif
- if (!custom_gnupg_install_fs_path.is_absolute() ||
- !std::filesystem::exists(custom_gnupg_install_fs_path) ||
- !std::filesystem::is_regular_file(
- custom_gnupg_install_fs_path)) {
- use_custom_gnupg_install_path = false;
- SPDLOG_ERROR("core loaded custom gpgconf path is illegal: {}",
- custom_gnupg_install_fs_path.u8string());
+ if (!VerifyGpgconfPath(gnupg_install_fs_path)) {
+ use_custom_gnupg_install_path = false;
+ SPDLOG_ERROR("core loaded custom gpgconf path is illegal: {}",
+ gnupg_install_fs_path.u8string());
+ } else {
+ SPDLOG_DEBUG("core loaded custom gpgconf path: {}",
+ gnupg_install_fs_path.u8string());
+ }
} else {
- SPDLOG_DEBUG("core loaded custom gpgconf path: {}",
- custom_gnupg_install_fs_path.u8string());
+#ifdef MACOS
+ use_custom_gnupg_install_path = true;
+ gnupg_install_fs_path = SearchGpgconfPath(
+ {"/usr/local/bin/gpgconf", "/opt/homebrew/bin/gpgconf"});
+ SPDLOG_DEBUG("core loaded searched gpgconf path: {}",
+ gnupg_install_fs_path.u8string());
+#endif
}
// check key database path
- std::filesystem::path custom_key_database_fs_path =
- custom_key_database_path;
- if (!custom_key_database_fs_path.is_absolute() ||
- !std::filesystem::exists(custom_key_database_fs_path) ||
- !std::filesystem::is_directory(custom_key_database_fs_path)) {
- use_custom_key_database_path = false;
- SPDLOG_ERROR("core loaded custom gpg key database is illegal: {}",
- custom_key_database_fs_path.u8string());
+ std::filesystem::path key_database_fs_path;
+ // user defined
+ if (!custom_key_database_path.empty()) {
+ key_database_fs_path = custom_key_database_path;
+ if (VerifyKeyDatabasePath(key_database_fs_path)) {
+ SPDLOG_ERROR(
+ "core loaded custom gpg key database is illegal: {}",
+ key_database_fs_path.u8string());
+ } else {
+ use_custom_key_database_path = true;
+ SPDLOG_DEBUG("core loaded custom gpg key database path: {}",
+ key_database_fs_path.u8string());
+ }
} else {
- SPDLOG_DEBUG("core loaded custom gpg key database path: {}",
- custom_key_database_fs_path.u8string());
+#ifdef MACOS
+ use_custom_key_database_path = true;
+ key_database_fs_path = SearchKeyDatabasePath(
+ {QDir::home().filesystemPath() / ".gnupg"});
+ SPDLOG_DEBUG("core loaded searched key database path: {}",
+ key_database_fs_path.u8string());
+#endif
}
if (args.load_default_gpg_context) {
@@ -312,15 +365,15 @@ void InitGpgFrontendCore(CoreInitArgs args) {
// set key database path
if (use_custom_key_database_path &&
- !custom_key_database_path.empty()) {
- args.db_path = custom_key_database_path;
+ !key_database_fs_path.empty()) {
+ args.db_path = key_database_fs_path.u8string();
}
// set custom gnupg path
if (use_custom_gnupg_install_path) {
args.custom_gpgconf = true;
args.custom_gpgconf_path =
- custom_gnupg_install_fs_path.u8string();
+ gnupg_install_fs_path.u8string();
}
args.offline_mode = forbid_all_gnupg_connection;
diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp
index 02d22d07..6718d62a 100644
--- a/src/core/function/gpg/GpgCommandExecutor.cpp
+++ b/src/core/function/gpg/GpgCommandExecutor.cpp
@@ -197,13 +197,14 @@ void GpgCommandExecutor::ExecuteSync(ExecuteContext context) {
GpgFrontend::Thread::TaskRunnerGetter::GetInstance().GetTaskRunner(
Thread::TaskRunnerGetter::kTaskRunnerType_External_Process);
}
-
target_task_runner->PostTask(task);
// to arvoid dead lock issue we need to check if current thread is the same as
// target thread. if it is, we can't call exec() because it will block the
// current thread.
- if (QThread::currentThread() != target_task_runner->GetThread()) {
+ if (QThread::currentThread()->currentThreadId() !=
+ target_task_runner->GetThread()->currentThreadId()) {
+ SPDLOG_TRACE("blocking until gpg command finish...");
// block until task finished
// this is to keep reference vaild until task finished
looper.exec();
@@ -233,7 +234,7 @@ void GpgCommandExecutor::ExecuteConcurrentlySync(ExecuteContexts contexts) {
auto remaining_tasks = contexts.size();
Thread::TaskRunnerPtr target_task_runner = nullptr;
- bool need_looper = true;
+ bool need_looper = false;
for (auto &context : contexts) {
const auto &cmd = context.cmd;
@@ -261,15 +262,16 @@ void GpgCommandExecutor::ExecuteConcurrentlySync(ExecuteContexts contexts) {
target_task_runner->PostTask(task);
// to arvoid dead lock issue we need to check if current thread is the same
- // as
- // target thread. if it is, we can't call exec() because it will block the
- // current thread.
- if (QThread::currentThread() == target_task_runner->GetThread()) {
- need_looper = false;
+ // as target thread. if it is, we can't call exec() because it will block
+ // the current thread.
+ if (QThread::currentThread()->currentThreadId() !=
+ target_task_runner->GetThread()->currentThreadId()) {
+ need_looper = true;
}
}
if (need_looper) {
+ SPDLOG_TRACE("blocking until concurrent gpg commands finish...");
// block until task finished
// this is to keep reference vaild until task finished
looper.exec();
diff --git a/src/main.cpp b/src/main.cpp
index 9e9bf091..92ef55ee 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -107,9 +107,11 @@ auto main(int argc, char* argv[]) -> int {
return rtn;
}
+ ctx->gather_external_gnupg_info = true;
+ ctx->load_default_gpg_context = true;
InitGlobalBasicalEnv(ctx, true);
+
rtn = StartApplication(ctx);
ShutdownGlobalBasicalEnv(ctx);
-
return rtn;
}
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 713911e8..838e4fbe 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -233,9 +233,15 @@ void CommonUtils::WaitForOpera(QWidget *parent,
connect(dialog, &QDialog::finished, &looper, &QEventLoop::quit);
connect(dialog, &QDialog::finished, dialog, &QDialog::deleteLater);
- opera([dialog]() { dialog->accept(); });
-
dialog->show();
+
+ opera([dialog]() {
+ SPDLOG_DEBUG("called operating waiting cb, dialog: {}",
+ static_cast<void *>(dialog));
+ dialog->close();
+ dialog->accept();
+ });
+
looper.exec();
}
diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp
index f4c80065..61d07189 100644
--- a/src/ui/dialog/key_generate/KeygenDialog.cpp
+++ b/src/ui/dialog/key_generate/KeygenDialog.cpp
@@ -141,12 +141,13 @@ void KeyGenDialog::slot_key_gen_accept() {
[this, gen_key_info = this->gen_key_info_](const OperaWaitingHd& hd) {
GpgKeyOpera::GetInstance().GenerateKey(
gen_key_info, [this, hd](GpgError err, const DataObjectPtr&) {
- GpgGenKeyResult result;
+ // stop showing waiting dialog
+ hd();
+
CommonUtils::RaiseMessageBox(this, err);
if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
emit SignalKeyGenerated();
}
- hd();
});
});
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index 9a4b9f6d..c0e8b240 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -286,13 +286,14 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
GpgKeyOpera::GetInstance().GenerateSubkey(
key, gen_key_info,
[this, hd](GpgError err, const DataObjectPtr&) {
- GpgGenKeyResult result;
+ // stop showing waiting dialog
+ hd();
+
CommonUtils::RaiseMessageBox(this, err);
if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
emit UISignalStation::GetInstance()
->SignalKeyDatabaseRefresh();
}
- hd();
});
});