diff options
author | saturneric <[email protected]> | 2025-04-19 00:34:18 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-04-19 00:34:18 +0000 |
commit | d6aa4d2e5058bccccb167087a10cc26fced8f561 (patch) | |
tree | e344b0477a9609b7b6820aa603f620b7d0b15d4b /src | |
parent | fix: gpg context will take response of gpg-agent (diff) | |
download | GpgFrontend-d6aa4d2e5058bccccb167087a10cc26fced8f561.tar.gz GpgFrontend-d6aa4d2e5058bccccb167087a10cc26fced8f561.zip |
fix: solve found issues by testing
Diffstat (limited to 'src')
-rw-r--r-- | src/core/function/gpg/GpgAdvancedOperator.cpp | 9 | ||||
-rw-r--r-- | src/core/function/gpg/GpgAdvancedOperator.h | 2 | ||||
-rw-r--r-- | src/core/function/gpg/GpgAssuanHelper.cpp | 35 | ||||
-rw-r--r-- | src/core/function/gpg/GpgAssuanHelper.h | 8 | ||||
-rw-r--r-- | src/core/function/gpg/GpgComponentManager.cpp | 8 | ||||
-rw-r--r-- | src/core/function/gpg/GpgComponentManager.h | 7 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/KeyGenerateDialog.cpp | 1 |
7 files changed, 49 insertions, 21 deletions
diff --git a/src/core/function/gpg/GpgAdvancedOperator.cpp b/src/core/function/gpg/GpgAdvancedOperator.cpp index d6323901..5e43d4d4 100644 --- a/src/core/function/gpg/GpgAdvancedOperator.cpp +++ b/src/core/function/gpg/GpgAdvancedOperator.cpp @@ -36,26 +36,29 @@ namespace GpgFrontend { auto GpgAdvancedOperator::ClearGpgPasswordCache() -> bool { - return info_.ReloadGpgAgent(); + return mgr_.ReloadGpgAgent(); } auto GpgAdvancedOperator::ReloadAllGpgComponents() -> bool { - return info_.ReloadGpgAgent(); + return mgr_.ReloadGpgAgent(); } auto GpgAdvancedOperator::KillAllGpgComponents() -> bool { + mgr_.Reset(); return ctx_.RestartGpgAgent(); } auto GpgAdvancedOperator::ResetConfigures() -> bool { - return info_.ReloadGpgAgent(); + return mgr_.ReloadGpgAgent(); } auto GpgAdvancedOperator::LaunchAllGpgComponents() -> bool { + mgr_.Reset(); return ctx_.RestartGpgAgent(); } auto GpgAdvancedOperator::RestartGpgComponents() -> bool { + mgr_.Reset(); return ctx_.RestartGpgAgent(); } diff --git a/src/core/function/gpg/GpgAdvancedOperator.h b/src/core/function/gpg/GpgAdvancedOperator.h index e6934f42..48a2d755 100644 --- a/src/core/function/gpg/GpgAdvancedOperator.h +++ b/src/core/function/gpg/GpgAdvancedOperator.h @@ -100,7 +100,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator GpgCommandExecutor::GetInstance(SingletonFunctionObject::GetChannel()); GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); - GpgComponentManager& info_ = + GpgComponentManager& mgr_ = GpgComponentManager::GetInstance(SingletonFunctionObject::GetChannel()); }; diff --git a/src/core/function/gpg/GpgAssuanHelper.cpp b/src/core/function/gpg/GpgAssuanHelper.cpp index a83c5655..b9ee63f1 100644 --- a/src/core/function/gpg/GpgAssuanHelper.cpp +++ b/src/core/function/gpg/GpgAssuanHelper.cpp @@ -38,11 +38,7 @@ GpgAssuanHelper::GpgAssuanHelper(int channel) gpgconf_path_(Module::RetrieveRTValueTypedOrDefault<>( "core", "gpgme.ctx.gpgconf_path", QString{})) {} -GpgAssuanHelper::~GpgAssuanHelper() { - for (const auto& ctx : assuan_ctx_) { - assuan_release(ctx); - } -} +GpgAssuanHelper::~GpgAssuanHelper() = default; auto GpgAssuanHelper::ConnectToSocket(GpgComponentType type) -> GpgError { if (assuan_ctx_.contains(type)) return GPG_ERR_NO_ERROR; @@ -70,10 +66,17 @@ auto GpgAssuanHelper::ConnectToSocket(GpgComponentType type) -> GpgError { } assuan_context_t a_ctx; - assuan_new(&a_ctx); + auto err = assuan_new(&a_ctx); + if (err != GPG_ERR_NO_ERROR) { + LOG_E() << "create assuan context failed, err:" << CheckGpgError(err); + return err; + } + + auto pa_ctx = QSharedPointer<struct assuan_context_s>( + a_ctx, [](assuan_context_t p) { assuan_release(p); }); - auto err = assuan_socket_connect(a_ctx, info.absoluteFilePath().toUtf8(), - ASSUAN_INVALID_PID, 0); + err = assuan_socket_connect(pa_ctx.get(), info.absoluteFilePath().toUtf8(), + ASSUAN_INVALID_PID, 0); if (err != GPG_ERR_NO_ERROR) { LOG_W() << "failed to connect to socket:" << info.absoluteFilePath() << "err:" << CheckGpgError(err); @@ -83,14 +86,14 @@ auto GpgAssuanHelper::ConnectToSocket(GpgComponentType type) -> GpgError { LOG_D() << "connected to socket by assuan protocol: " << info.absoluteFilePath() << "channel:" << GetChannel(); - err = assuan_transact(a_ctx, "GETINFO pid", simple_data_callback, nullptr, - nullptr, nullptr, nullptr, nullptr); + err = assuan_transact(pa_ctx.get(), "GETINFO pid", simple_data_callback, + nullptr, nullptr, nullptr, nullptr, nullptr); if (err != GPG_ERR_NO_ERROR) { LOG_W() << "failed to test assuan connection:" << CheckGpgError(err); return err; } - assuan_ctx_[type] = a_ctx; + assuan_ctx_[type] = pa_ctx; return err; } @@ -114,9 +117,10 @@ auto GpgAssuanHelper::SendCommand(GpgComponentType type, const QString& command, LOG_D() << "sending assuan command: " << command; - auto err = assuan_transact( - assuan_ctx_[type], command.toUtf8(), default_data_callback, &context, - default_inquery_callback, &context, default_status_callback, &context); + auto err = + assuan_transact(assuan_ctx_[type].get(), command.toUtf8(), + default_data_callback, &context, default_inquery_callback, + &context, default_status_callback, &context); if (err != GPG_ERR_NO_ERROR) { LOG_W() << "failed to send assuan command:" << CheckGpgError(err); @@ -124,6 +128,7 @@ auto GpgAssuanHelper::SendCommand(GpgComponentType type, const QString& command, // broken pipe error, try reconnect next time if (CheckGpgError(err) == 32877) { assuan_ctx_.remove(type); + return SendCommand(type, command, data_cb, inquery_cb, status_cb); } return err; } @@ -270,4 +275,6 @@ auto GpgAssuanHelper::AssuanCallbackContext::SendData(const QByteArray& b) const -> gpg_error_t { return assuan_send_data(ctx, b.constData(), b.size()); } + +void GpgAssuanHelper::ResetAllConnections() { assuan_ctx_.clear(); } } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/function/gpg/GpgAssuanHelper.h b/src/core/function/gpg/GpgAssuanHelper.h index adf6d0ff..f357ed93 100644 --- a/src/core/function/gpg/GpgAssuanHelper.h +++ b/src/core/function/gpg/GpgAssuanHelper.h @@ -118,10 +118,16 @@ class GPGFRONTEND_CORE_EXPORT GpgAssuanHelper auto SendDataCommand(GpgComponentType type, const QString& command) -> std::tuple<GpgError, QStringList>; + /** + * @brief + * + */ + void ResetAllConnections(); + private: GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); - QMap<GpgComponentType, assuan_context_t> assuan_ctx_; + QMap<GpgComponentType, QSharedPointer<struct assuan_context_s>> assuan_ctx_; QByteArray temp_data_; QString temp_status_; diff --git a/src/core/function/gpg/GpgComponentManager.cpp b/src/core/function/gpg/GpgComponentManager.cpp index 1b302631..56b95aab 100644 --- a/src/core/function/gpg/GpgComponentManager.cpp +++ b/src/core/function/gpg/GpgComponentManager.cpp @@ -68,7 +68,6 @@ auto GpgComponentManager::ReloadGpgAgent() -> bool { LOG_D() << "invalid response of RELOADAGENT: " << s; return false; } - return true; } @@ -79,8 +78,13 @@ auto GpgComponentManager::GpgKillAgent() -> bool { LOG_D() << "invalid response of KILLAGENT: " << s; return false; } - + Reset(); return true; } +void GpgComponentManager::Reset() { + scdaemon_version_.clear(); + gpg_agent_version_.clear(); + assuan_.ResetAllConnections(); +} } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/function/gpg/GpgComponentManager.h b/src/core/function/gpg/GpgComponentManager.h index cfd6a99f..1048793f 100644 --- a/src/core/function/gpg/GpgComponentManager.h +++ b/src/core/function/gpg/GpgComponentManager.h @@ -73,6 +73,13 @@ class GPGFRONTEND_CORE_EXPORT GpgComponentManager */ auto GpgKillAgent() -> bool; + /** + * @brief + * + * @return auto + */ + void Reset(); + private: GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp index df8b5232..c2275a79 100644 --- a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp @@ -88,6 +88,7 @@ KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) ui_->commentLabel->setText(tr("Comment")); ui_->keyDBLabel->setText(tr("Key Database")); ui_->easyAlgoLabel->setText(tr("Algorithm")); + ui_->combinationLabel->setText(tr("Combination")); ui_->easyValidPeriodLabel->setText(tr("Validity Period")); ui_->pAlgoLabel->setText(tr("Algorithm")); |